diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 7e5523a26f47d..9843c8f2624f0 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -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) { diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 67ec36c5fbf87..3470b04c9e4f3 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -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; @@ -3100,7 +3104,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { onLockSettingsReady(); loadAdminDataAsync(); mOwners.systemReady(); - applyManagedSubscriptionsPolicyIfRequired(); + if (isWorkProfileTelephonyFlagEnabled()) { + applyManagedSubscriptionsPolicyIfRequired(); + } break; case SystemService.PHASE_ACTIVITY_MANAGER_READY: synchronized (getLockObject()) { @@ -7014,8 +7020,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mLockSettingsInternal.refreshStrongAuthTimeout(parentId); - clearManagedSubscriptionsPolicy(); - + if (isWorkProfileTelephonyFlagEnabled()) { + clearManagedSubscriptionsPolicy(); + } Slogf.i(LOG_TAG, "Cleaning up device-wide policies done."); } @@ -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); } @@ -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 allowedModes = @@ -20180,10 +20197,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() { - synchronized (getLockObject()) { - ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); - if (admin != null && admin.mManagedSubscriptionsPolicy != null) { - return admin.mManagedSubscriptionsPolicy; + if (isWorkProfileTelephonyFlagEnabled()) { + synchronized (getLockObject()) { + ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); + if (admin != null && admin.mManagedSubscriptionsPolicy != null) { + return admin.mManagedSubscriptionsPolicy; + } } } return new ManagedSubscriptionsPolicy( @@ -20192,9 +20211,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @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()); diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index 4998a6c20e633..60483f11a479a 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -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; @@ -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 { @@ -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)); @@ -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