From 2057a5de5c88b94b743c23eb118e3ac2e00998c1 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Tue, 14 Mar 2023 12:38:23 +0000 Subject: Check if SubscriptionManager changes are disabled If telephony changes for work profile telephony are disabled we should throw exception from DevicePolicyManager apis, as we can't do anything meaningful otherwise. Bug: 266676629 Test: NA Change-Id: Ief771c2e0f80e5bdded6f67a54e8b3f883a71c77 --- .../devicepolicy/DevicePolicyManagerService.java | 38 +++++++++++++++------- .../devicepolicy/DevicePolicyManagerTest.java | 4 +++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index a1789b2b125d..e82e05cead3a 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -223,6 +223,7 @@ import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPR import static android.net.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK; import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK; import static android.provider.DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER; +import static android.provider.DeviceConfig.NAMESPACE_TELEPHONY; import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER; import static android.provider.Settings.Secure.MANAGED_PROVISIONING_DPC_DOWNLOADED; import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; @@ -3322,7 +3323,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { onLockSettingsReady(); loadAdminDataAsync(); mOwners.systemReady(); - if (isWorkProfileTelephonyFlagEnabled()) { + if (isWorkProfileTelephonyEnabled()) { applyManagedSubscriptionsPolicyIfRequired(); } break; @@ -7636,7 +7637,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } mLockSettingsInternal.refreshStrongAuthTimeout(parentId); - if (isWorkProfileTelephonyFlagEnabled()) { + if (isWorkProfileTelephonyEnabled()) { clearManagedSubscriptionsPolicy(); clearLauncherShortcutOverrides(); updateTelephonyCrossProfileIntentFilters(parentId, UserHandle.USER_NULL, false); @@ -10987,8 +10988,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { synchronized (mSubscriptionsChangedListenerLock) { pw.println("Subscription changed listener : " + mSubscriptionsChangedListener); } - pw.println( - "Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled()); + pw.println("DPM Flag enable_work_profile_telephony : " + + isWorkProfileTelephonyDevicePolicyManagerFlagEnabled()); + pw.println("Telephony Flag enable_work_profile_telephony : " + + isWorkProfileTelephonySubscriptionManagerFlagEnabled()); mHandler.post(() -> handleDump(pw)); dumpResources(pw); @@ -22590,11 +22593,24 @@ 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); + private boolean isWorkProfileTelephonyEnabled() { + return isWorkProfileTelephonyDevicePolicyManagerFlagEnabled() + && isWorkProfileTelephonySubscriptionManagerFlagEnabled(); + } + + private boolean isWorkProfileTelephonyDevicePolicyManagerFlagEnabled() { + return DeviceConfig.getBoolean(NAMESPACE_DEVICE_POLICY_MANAGER, + ENABLE_WORK_PROFILE_TELEPHONY_FLAG, DEFAULT_WORK_PROFILE_TELEPHONY_FLAG); + } + + private boolean isWorkProfileTelephonySubscriptionManagerFlagEnabled() { + final long ident = mInjector.binderClearCallingIdentity(); + try { + return DeviceConfig.getBoolean(NAMESPACE_TELEPHONY, ENABLE_WORK_PROFILE_TELEPHONY_FLAG, + false); + } finally { + mInjector.binderRestoreCallingIdentity(ident); + } } @Override @@ -22707,7 +22723,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() { - if (isWorkProfileTelephonyFlagEnabled()) { + if (isWorkProfileTelephonyEnabled()) { synchronized (getLockObject()) { ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); if (admin != null && admin.mManagedSubscriptionsPolicy != null) { @@ -22721,7 +22737,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) { - if (!isWorkProfileTelephonyFlagEnabled()) { + if (!isWorkProfileTelephonyEnabled()) { throw new UnsupportedOperationException("This api is not enabled"); } CallerIdentity caller = getCallerIdentity(); 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 aaabb286589c..4f74ef8b5f70 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -5002,6 +5002,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "true", false); + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY, + 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)); @@ -5064,6 +5066,8 @@ public class DevicePolicyManagerTest extends DpmTestBase { verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null); DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false); + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY, + FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false); } @Test -- cgit v1.2.3-59-g8ed1b