androidandroid-for-workandroid-enterprise

Android managed configurations provider


The overview section of Set up Managed Configurations page states the following:

Apps define the managed configuration options that can be remotely set by an administrator. These are arbitrary settings that can be changed by a managed configuration provider.
[...]
The managed configurations provider is another app running on the same device.

Then the page describes how to set up the managed app, but there's no any further information about the: "managed configurations provider app" - the app that, if I understood correctly, is responsible for sending the ACTION_APPLICATION_RESTRICTIONS_CHANGED when a configuration changed.

My question is what kind of app is this "provider app"? Are there any Android API this app should implement in order to act as a configurations provider? How does this companion app hooks the configuration changes into the RestrictionsManager, so that the managed app to be able to retrieve them?

I am asking this here because unfortunately I did not find any reference in the Android docs.


Solution

  • What kind of app is this "provider app"?

    The configurations provider app is another app running on the device. This app is typically controlled by an administrator. The administrator communicates the configuration changes to the provider app, and this app, in turn, changes the configurations on the managed app.

    Take a look at the BasicManagedProfile sample: https://github.com/googlesamples/android-BasicManagedProfile. This is exactly this kind of app.

    Are there any Android API this app should implement in order to act as a configurations provider?

    Yes, this app should ask for provisioning the managed profile:

    Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE);
    intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME,
                            activity.getApplicationContext().getPackageName());
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
        activity.finish();
    } else {
        Toast.makeText(activity, "Device provisioning is not enabled. Stopping.",
                                                      Toast.LENGTH_SHORT).show();
    }
    

    How does this companion app hooks the configuration changes into the RestrictionsManager, so that the managed app to be able to retrieve them?

    It uses the DevicePolicyManager to enforce restrictions on the managed app:

    DevicePolicyManager manager = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
    
    Bundle settings = new Bundle();
    settings.putBoolean("downloadOnCellular", true);
    
    manager.setApplicationRestrictions(
            BasicDeviceAdminReceiver.getComponentName(getActivity()),
            PACKAGE_NAME_MANAGED_APP, settings);
    

    Again, take a look at how this is done in the sample project.