Merge "Check if SubscriptionManager changes are disabled" into udc-dev am: cedae13bc1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21997672

Change-Id: Ic970cd916ba5d164afaaf9afee32cff33ff6bdf8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ayush Sharma
2023-03-21 17:51:48 +00:00
committed by Automerger Merge Worker
2 changed files with 31 additions and 11 deletions

View File

@@ -225,6 +225,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.ConnectivityManager.PROFILE_NETWORK_PREFERENCE_ENTERPRISE_NO_FALLBACK;
import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK; import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK;
import static android.provider.DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER; 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.Global.PRIVATE_DNS_SPECIFIER;
import static android.provider.Settings.Secure.MANAGED_PROVISIONING_DPC_DOWNLOADED; import static android.provider.Settings.Secure.MANAGED_PROVISIONING_DPC_DOWNLOADED;
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE; import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
@@ -3324,7 +3325,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
onLockSettingsReady(); onLockSettingsReady();
loadAdminDataAsync(); loadAdminDataAsync();
mOwners.systemReady(); mOwners.systemReady();
if (isWorkProfileTelephonyFlagEnabled()) { if (isWorkProfileTelephonyEnabled()) {
applyManagedSubscriptionsPolicyIfRequired(); applyManagedSubscriptionsPolicyIfRequired();
} }
break; break;
@@ -7640,7 +7641,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
mLockSettingsInternal.refreshStrongAuthTimeout(parentId); mLockSettingsInternal.refreshStrongAuthTimeout(parentId);
if (isWorkProfileTelephonyFlagEnabled()) { if (isWorkProfileTelephonyEnabled()) {
clearManagedSubscriptionsPolicy(); clearManagedSubscriptionsPolicy();
clearLauncherShortcutOverrides(); clearLauncherShortcutOverrides();
updateTelephonyCrossProfileIntentFilters(parentId, UserHandle.USER_NULL, false); updateTelephonyCrossProfileIntentFilters(parentId, UserHandle.USER_NULL, false);
@@ -10991,8 +10992,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
synchronized (mSubscriptionsChangedListenerLock) { synchronized (mSubscriptionsChangedListenerLock) {
pw.println("Subscription changed listener : " + mSubscriptionsChangedListener); pw.println("Subscription changed listener : " + mSubscriptionsChangedListener);
} }
pw.println( pw.println("DPM Flag enable_work_profile_telephony : "
"Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled()); + isWorkProfileTelephonyDevicePolicyManagerFlagEnabled());
pw.println("Telephony Flag enable_work_profile_telephony : "
+ isWorkProfileTelephonySubscriptionManagerFlagEnabled());
mHandler.post(() -> handleDump(pw)); mHandler.post(() -> handleDump(pw));
dumpResources(pw); dumpResources(pw);
@@ -22705,11 +22708,24 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
DEFAULT_KEEP_PROFILES_RUNNING_FLAG); DEFAULT_KEEP_PROFILES_RUNNING_FLAG);
} }
private static boolean isWorkProfileTelephonyFlagEnabled() { private boolean isWorkProfileTelephonyEnabled() {
return DeviceConfig.getBoolean( return isWorkProfileTelephonyDevicePolicyManagerFlagEnabled()
NAMESPACE_DEVICE_POLICY_MANAGER, && isWorkProfileTelephonySubscriptionManagerFlagEnabled();
ENABLE_WORK_PROFILE_TELEPHONY_FLAG, }
DEFAULT_WORK_PROFILE_TELEPHONY_FLAG);
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 @Override
@@ -22822,7 +22838,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
@Override @Override
public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() { public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() {
if (isWorkProfileTelephonyFlagEnabled()) { if (isWorkProfileTelephonyEnabled()) {
synchronized (getLockObject()) { synchronized (getLockObject()) {
ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked(); ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked();
if (admin != null && admin.mManagedSubscriptionsPolicy != null) { if (admin != null && admin.mManagedSubscriptionsPolicy != null) {
@@ -22836,7 +22852,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
@Override @Override
public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) { public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) {
if (!isWorkProfileTelephonyFlagEnabled()) { if (!isWorkProfileTelephonyEnabled()) {
throw new UnsupportedOperationException("This api is not enabled"); throw new UnsupportedOperationException("This api is not enabled");
} }
CallerIdentity caller = getCallerIdentity(); CallerIdentity caller = getCallerIdentity();

View File

@@ -5002,6 +5002,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE); configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "true", false); 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 // Even if the caller is the managed profile, the current user is the user 0
when(getServices().iactivityManager.getCurrentUser()) when(getServices().iactivityManager.getCurrentUser())
.thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0)); .thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0));
@@ -5064,6 +5066,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null); verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER, DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false); FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY,
FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false);
} }
@Test @Test