Android's device management and default app assignments rely on two distinct but complementary services: RoleManager for mapping default apps, and DevicePolicyManager for enforcing enterprise policies.
RoleManager: Assigning Default App Roles
Introduced in Android 10, RoleManager replaced the older default app settings mechanism. It grants apps specific "roles", which automatically come with pre-defined privileges.
Roles are defined in roles.xml and include categories like ROLE_BROWSER, ROLE_DIALER, and ROLE_SMS. When an application holds a role, it automatically receives certain permissions without prompting the user. For instance, the app holding ROLE_SMS automatically gets RECEIVE_SMS and SEND_SMS.
The core logic is implemented in RoleManagerService.java, which coordinates with PackageManagerService to grant runtime permissions to the role holder.
// Example of an app requesting a role
RoleManager roleManager = context.getSystemService(RoleManager.class);
if (roleManager.isRoleAvailable(RoleManager.ROLE_DIALER)) {
if (!roleManager.isRoleHeld(RoleManager.ROLE_DIALER)) {
Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_DIALER);
startActivityForResult(intent, REQUEST_CODE_DIALER);
}
}
DevicePolicyManager: Enterprise MDM APIs
DevicePolicyManager (DPM) is the entry point for Mobile Device Management (MDM). It allows enterprise IT administrators to enforce security rules via DevicePolicyManagerService (DPMS).
When an app calls a DPM API (e.g., setCameraDisabled()), DPMS checks if the calling app is the active admin, verifies its privileges, saves the policy to an XML file (/data/system/device_policies.xml), and notifies other system services (like CameraService or UserManagerService) to enforce the new rule.
Device Admin, Profile Owner, Device Owner
Android defines three levels of management capability:
- Device Admin: The legacy management model. It grants basic policies (like enforcing a screen lock PIN). Mostly deprecated in modern Android in favor of Profile/Device Owners.
- Profile Owner: Manages a Work Profile. It has full control over the apps and data within that specific profile, but no control over the rest of the device.
- Device Owner: Has full control over the entire device. It can wipe the device, disable hardware features (like USB data or the camera), and install apps silently. Device Owners can only be provisioned on a factory-reset device.
Policy Enforcement Mechanism
Policies are often enforced not by DPMS itself, but by the respective system services consulting DPMS. For example, when a user tries to use the camera, the CameraService queries the DevicePolicyManagerService via Binder to check the KEYGUARD_DISABLE_FEATURES and setCameraDisabled flags. If the policy restricts the camera, CameraService rejects the connection attempt.
You can inspect the active device policies via adb:
adb shell dumpsys device_policy