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

Commit e0b71d04 authored by Ayush Sharma's avatar Ayush Sharma
Browse files

Add work profile telephony feature flag

Bug: 258821753
Test: atest DevicePolicyManagerTest#testWipeDataManagedProfileOnOrganizationOwnedDevice
atest android.devicepolicy.cts.ManagedSubscriptionsPolicyTest

Change-Id: I897d52acde4056b796eceea56f3446cf70806f02
parent ee82a8c9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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) {
+31 −8
Original line number Diff line number Diff line
@@ -739,6 +739,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    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 BaseIDevicePolicyManager {
                onLockSettingsReady();
                loadAdminDataAsync();
                mOwners.systemReady();
                if (isWorkProfileTelephonyFlagEnabled()) {
                    applyManagedSubscriptionsPolicyIfRequired();
                }
                break;
            case SystemService.PHASE_ACTIVITY_MANAGER_READY:
                synchronized (getLockObject()) {
@@ -7018,8 +7024,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        mLockSettingsInternal.refreshStrongAuthTimeout(parentId);
        if (isWorkProfileTelephonyFlagEnabled()) {
            clearManagedSubscriptionsPolicy();
        }
        Slogf.i(LOG_TAG, "Cleaning up device-wide policies done.");
    }
@@ -10132,6 +10139,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            synchronized (mSubscriptionsChangedListenerLock) {
                pw.println("Subscription changed listener : " + mSubscriptionsChangedListener);
            }
            pw.println(
                    "Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled());
            mHandler.post(() -> handleDump(pw));
            dumpResources(pw);
        }
@@ -20104,6 +20114,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                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 =
@@ -20184,21 +20201,27 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @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());
+7 −1
Original line number Diff line number Diff line
@@ -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