Loading core/java/android/app/admin/DevicePolicyManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -11049,6 +11049,7 @@ public class DevicePolicyManager { * @throws SecurityException if the caller is not a profile owner on an organization-owned * managed profile. * @throws IllegalStateException if called after the device setup has been completed. * @throws UnsupportedOperationException if the api is not enabled. * @see ManagedSubscriptionsPolicy */ public void setManagedSubscriptionsPolicy(@Nullable ManagedSubscriptionsPolicy policy) { Loading services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +31 −8 Original line number Diff line number Diff line Loading @@ -740,6 +740,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running"; private static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false; private static final String ENABLE_WORK_PROFILE_TELEPHONY_FLAG = "enable_work_profile_telephony"; private static final boolean DEFAULT_WORK_PROFILE_TELEPHONY_FLAG = false; // TODO(b/261999445) remove the flag after rollout. private static final String HEADLESS_FLAG = "headless"; private static final boolean DEFAULT_HEADLESS_FLAG = true; Loading Loading @@ -3100,7 +3104,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { onLockSettingsReady(); loadAdminDataAsync(); mOwners.systemReady(); if (isWorkProfileTelephonyFlagEnabled()) { applyManagedSubscriptionsPolicyIfRequired(); } break; case SystemService.PHASE_ACTIVITY_MANAGER_READY: synchronized (getLockObject()) { Loading Loading @@ -7014,8 +7020,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mLockSettingsInternal.refreshStrongAuthTimeout(parentId); if (isWorkProfileTelephonyFlagEnabled()) { clearManagedSubscriptionsPolicy(); } Slogf.i(LOG_TAG, "Cleaning up device-wide policies done."); } Loading Loading @@ -10128,6 +10135,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { synchronized (mSubscriptionsChangedListenerLock) { pw.println("Subscription changed listener : " + mSubscriptionsChangedListener); } pw.println( "Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled()); mHandler.post(() -> handleDump(pw)); dumpResources(pw); } Loading Loading @@ -20100,6 +20110,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { DEFAULT_KEEP_PROFILES_RUNNING_FLAG); } private static boolean isWorkProfileTelephonyFlagEnabled() { return DeviceConfig.getBoolean( NAMESPACE_DEVICE_POLICY_MANAGER, ENABLE_WORK_PROFILE_TELEPHONY_FLAG, DEFAULT_WORK_PROFILE_TELEPHONY_FLAG); } @Override public void setMtePolicy(int flags) { final Set<Integer> allowedModes = Loading Loading @@ -20180,21 +20197,27 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() { if (isWorkProfileTelephonyFlagEnabled()) { synchronized (getLockObject()) { ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); if (admin != null && admin.mManagedSubscriptionsPolicy != null) { return admin.mManagedSubscriptionsPolicy; } } } return new ManagedSubscriptionsPolicy( ManagedSubscriptionsPolicy.TYPE_ALL_PERSONAL_SUBSCRIPTIONS); } @Override public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) { if (!isWorkProfileTelephonyFlagEnabled()) { throw new UnsupportedOperationException("This api is not enabled"); } CallerIdentity caller = getCallerIdentity(); Preconditions.checkCallAuthorization(isProfileOwnerOfOrganizationOwnedDevice(caller), "This policy can only be set by a profile owner on an organization-owned device."); "This policy can only be set by a profile owner on an organization-owned " + "device."); synchronized (getLockObject()) { final ActiveAdmin admin = getProfileOwnerLocked(caller.getUserId()); services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ import android.os.Process; import android.os.UserHandle; import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.provider.DeviceConfig; import android.provider.Settings; import android.security.KeyChain; import android.security.keystore.AttestationUtils; Loading Loading @@ -259,6 +260,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { private static final String PROFILE_OFF_SUSPENSION_TITLE = "suspension_title"; private static final String PROFILE_OFF_SUSPENSION_TEXT = "suspension_text"; private static final String PROFILE_OFF_SUSPENSION_SOON_TEXT = "suspension_tomorrow_text"; private static final String FLAG_ENABLE_WORK_PROFILE_TELEPHONY = "enable_work_profile_telephony"; @Before public void setUp() throws Exception { Loading Loading @@ -4982,7 +4985,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { public void testWipeDataManagedProfileOnOrganizationOwnedDevice() throws Exception { setupProfileOwner(); configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "true", false); // Even if the caller is the managed profile, the current user is the user 0 when(getServices().iactivityManager.getCurrentUser()) .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0)); Loading Loading @@ -5043,6 +5047,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { verify(getServices().packageManagerInternal) .unsuspendForSuspendingPackage(PLATFORM_PACKAGE_NAME, UserHandle.USER_SYSTEM); verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false); } @Test Loading Loading
core/java/android/app/admin/DevicePolicyManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -11049,6 +11049,7 @@ public class DevicePolicyManager { * @throws SecurityException if the caller is not a profile owner on an organization-owned * managed profile. * @throws IllegalStateException if called after the device setup has been completed. * @throws UnsupportedOperationException if the api is not enabled. * @see ManagedSubscriptionsPolicy */ public void setManagedSubscriptionsPolicy(@Nullable ManagedSubscriptionsPolicy policy) { Loading
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +31 −8 Original line number Diff line number Diff line Loading @@ -740,6 +740,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running"; private static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false; private static final String ENABLE_WORK_PROFILE_TELEPHONY_FLAG = "enable_work_profile_telephony"; private static final boolean DEFAULT_WORK_PROFILE_TELEPHONY_FLAG = false; // TODO(b/261999445) remove the flag after rollout. private static final String HEADLESS_FLAG = "headless"; private static final boolean DEFAULT_HEADLESS_FLAG = true; Loading Loading @@ -3100,7 +3104,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { onLockSettingsReady(); loadAdminDataAsync(); mOwners.systemReady(); if (isWorkProfileTelephonyFlagEnabled()) { applyManagedSubscriptionsPolicyIfRequired(); } break; case SystemService.PHASE_ACTIVITY_MANAGER_READY: synchronized (getLockObject()) { Loading Loading @@ -7014,8 +7020,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mLockSettingsInternal.refreshStrongAuthTimeout(parentId); if (isWorkProfileTelephonyFlagEnabled()) { clearManagedSubscriptionsPolicy(); } Slogf.i(LOG_TAG, "Cleaning up device-wide policies done."); } Loading Loading @@ -10128,6 +10135,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { synchronized (mSubscriptionsChangedListenerLock) { pw.println("Subscription changed listener : " + mSubscriptionsChangedListener); } pw.println( "Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled()); mHandler.post(() -> handleDump(pw)); dumpResources(pw); } Loading Loading @@ -20100,6 +20110,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { DEFAULT_KEEP_PROFILES_RUNNING_FLAG); } private static boolean isWorkProfileTelephonyFlagEnabled() { return DeviceConfig.getBoolean( NAMESPACE_DEVICE_POLICY_MANAGER, ENABLE_WORK_PROFILE_TELEPHONY_FLAG, DEFAULT_WORK_PROFILE_TELEPHONY_FLAG); } @Override public void setMtePolicy(int flags) { final Set<Integer> allowedModes = Loading Loading @@ -20180,21 +20197,27 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() { if (isWorkProfileTelephonyFlagEnabled()) { synchronized (getLockObject()) { ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); if (admin != null && admin.mManagedSubscriptionsPolicy != null) { return admin.mManagedSubscriptionsPolicy; } } } return new ManagedSubscriptionsPolicy( ManagedSubscriptionsPolicy.TYPE_ALL_PERSONAL_SUBSCRIPTIONS); } @Override public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) { if (!isWorkProfileTelephonyFlagEnabled()) { throw new UnsupportedOperationException("This api is not enabled"); } CallerIdentity caller = getCallerIdentity(); Preconditions.checkCallAuthorization(isProfileOwnerOfOrganizationOwnedDevice(caller), "This policy can only be set by a profile owner on an organization-owned device."); "This policy can only be set by a profile owner on an organization-owned " + "device."); synchronized (getLockObject()) { final ActiveAdmin admin = getProfileOwnerLocked(caller.getUserId());
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +7 −1 Original line number Diff line number Diff line Loading @@ -134,6 +134,7 @@ import android.os.Process; import android.os.UserHandle; import android.os.UserManager; import android.platform.test.annotations.Presubmit; import android.provider.DeviceConfig; import android.provider.Settings; import android.security.KeyChain; import android.security.keystore.AttestationUtils; Loading Loading @@ -259,6 +260,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { private static final String PROFILE_OFF_SUSPENSION_TITLE = "suspension_title"; private static final String PROFILE_OFF_SUSPENSION_TEXT = "suspension_text"; private static final String PROFILE_OFF_SUSPENSION_SOON_TEXT = "suspension_tomorrow_text"; private static final String FLAG_ENABLE_WORK_PROFILE_TELEPHONY = "enable_work_profile_telephony"; @Before public void setUp() throws Exception { Loading Loading @@ -4982,7 +4985,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { public void testWipeDataManagedProfileOnOrganizationOwnedDevice() throws Exception { setupProfileOwner(); configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "true", false); // Even if the caller is the managed profile, the current user is the user 0 when(getServices().iactivityManager.getCurrentUser()) .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0)); Loading Loading @@ -5043,6 +5047,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { verify(getServices().packageManagerInternal) .unsuspendForSuspendingPackage(PLATFORM_PACKAGE_NAME, UserHandle.USER_SYSTEM); verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false); } @Test Loading