Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2057a5de authored by Ayush Sharma's avatar Ayush Sharma
Browse files

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
parent cc10548a
Loading
Loading
Loading
Loading
+27 −11
Original line number Diff line number Diff line
@@ -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();
+4 −0
Original line number Diff line number Diff line
@@ -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