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

Commit 796c571a authored by Ayush Sharma's avatar Ayush Sharma Committed by Android (Google) Code Review
Browse files

Merge "Add work profile telephony feature flag"

parents d02d538a e0b71d04
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line 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
     * @throws SecurityException     if the caller is not a profile owner on an organization-owned
     *                               managed profile.
     *                               managed profile.
     * @throws IllegalStateException if called after the device setup has been completed.
     * @throws IllegalStateException if called after the device setup has been completed.
     * @throws UnsupportedOperationException if the api is not enabled.
     * @see ManagedSubscriptionsPolicy
     * @see ManagedSubscriptionsPolicy
     */
     */
    public void setManagedSubscriptionsPolicy(@Nullable ManagedSubscriptionsPolicy policy) {
    public void setManagedSubscriptionsPolicy(@Nullable ManagedSubscriptionsPolicy policy) {
+31 −8
Original line number Original line Diff line number Diff line
@@ -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 String KEEP_PROFILES_RUNNING_FLAG = "enable_keep_profiles_running";
    private static final boolean DEFAULT_KEEP_PROFILES_RUNNING_FLAG = false;
    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.
    // TODO(b/261999445) remove the flag after rollout.
    private static final String HEADLESS_FLAG = "headless";
    private static final String HEADLESS_FLAG = "headless";
    private static final boolean DEFAULT_HEADLESS_FLAG = true;
    private static final boolean DEFAULT_HEADLESS_FLAG = true;
@@ -3100,7 +3104,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                onLockSettingsReady();
                onLockSettingsReady();
                loadAdminDataAsync();
                loadAdminDataAsync();
                mOwners.systemReady();
                mOwners.systemReady();
                if (isWorkProfileTelephonyFlagEnabled()) {
                    applyManagedSubscriptionsPolicyIfRequired();
                    applyManagedSubscriptionsPolicyIfRequired();
                }
                break;
                break;
            case SystemService.PHASE_ACTIVITY_MANAGER_READY:
            case SystemService.PHASE_ACTIVITY_MANAGER_READY:
                synchronized (getLockObject()) {
                synchronized (getLockObject()) {
@@ -7014,8 +7020,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
        }
        mLockSettingsInternal.refreshStrongAuthTimeout(parentId);
        mLockSettingsInternal.refreshStrongAuthTimeout(parentId);
        if (isWorkProfileTelephonyFlagEnabled()) {
            clearManagedSubscriptionsPolicy();
            clearManagedSubscriptionsPolicy();
        }
        Slogf.i(LOG_TAG, "Cleaning up device-wide policies done.");
        Slogf.i(LOG_TAG, "Cleaning up device-wide policies done.");
    }
    }
@@ -10128,6 +10135,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            synchronized (mSubscriptionsChangedListenerLock) {
            synchronized (mSubscriptionsChangedListenerLock) {
                pw.println("Subscription changed listener : " + mSubscriptionsChangedListener);
                pw.println("Subscription changed listener : " + mSubscriptionsChangedListener);
            }
            }
            pw.println(
                    "Flag enable_work_profile_telephony : " + isWorkProfileTelephonyFlagEnabled());
            mHandler.post(() -> handleDump(pw));
            mHandler.post(() -> handleDump(pw));
            dumpResources(pw);
            dumpResources(pw);
        }
        }
@@ -20100,6 +20110,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                DEFAULT_KEEP_PROFILES_RUNNING_FLAG);
                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
    @Override
    public void setMtePolicy(int flags) {
    public void setMtePolicy(int flags) {
        final Set<Integer> allowedModes =
        final Set<Integer> allowedModes =
@@ -20180,21 +20197,27 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    @Override
    public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() {
    public ManagedSubscriptionsPolicy getManagedSubscriptionsPolicy() {
        if (isWorkProfileTelephonyFlagEnabled()) {
            synchronized (getLockObject()) {
            synchronized (getLockObject()) {
                ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked();
                ActiveAdmin admin = getProfileOwnerOfOrganizationOwnedDeviceLocked();
                if (admin != null && admin.mManagedSubscriptionsPolicy != null) {
                if (admin != null && admin.mManagedSubscriptionsPolicy != null) {
                    return admin.mManagedSubscriptionsPolicy;
                    return admin.mManagedSubscriptionsPolicy;
                }
                }
            }
            }
        }
        return new ManagedSubscriptionsPolicy(
        return new ManagedSubscriptionsPolicy(
                ManagedSubscriptionsPolicy.TYPE_ALL_PERSONAL_SUBSCRIPTIONS);
                ManagedSubscriptionsPolicy.TYPE_ALL_PERSONAL_SUBSCRIPTIONS);
    }
    }
    @Override
    @Override
    public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) {
    public void setManagedSubscriptionsPolicy(ManagedSubscriptionsPolicy policy) {
        if (!isWorkProfileTelephonyFlagEnabled()) {
            throw new UnsupportedOperationException("This api is not enabled");
        }
        CallerIdentity caller = getCallerIdentity();
        CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(isProfileOwnerOfOrganizationOwnedDevice(caller),
        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()) {
        synchronized (getLockObject()) {
            final ActiveAdmin admin = getProfileOwnerLocked(caller.getUserId());
            final ActiveAdmin admin = getProfileOwnerLocked(caller.getUserId());
+7 −1
Original line number Original line Diff line number Diff line
@@ -134,6 +134,7 @@ import android.os.Process;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Settings;
import android.security.KeyChain;
import android.security.KeyChain;
import android.security.keystore.AttestationUtils;
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_TITLE = "suspension_title";
    private static final String PROFILE_OFF_SUSPENSION_TEXT = "suspension_text";
    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 PROFILE_OFF_SUSPENSION_SOON_TEXT = "suspension_tomorrow_text";
    private static final String FLAG_ENABLE_WORK_PROFILE_TELEPHONY =
            "enable_work_profile_telephony";


    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
@@ -4982,7 +4985,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    public void testWipeDataManagedProfileOnOrganizationOwnedDevice() throws Exception {
    public void testWipeDataManagedProfileOnOrganizationOwnedDevice() throws Exception {
        setupProfileOwner();
        setupProfileOwner();
        configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
        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
        // 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));
@@ -5043,6 +5047,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        verify(getServices().packageManagerInternal)
        verify(getServices().packageManagerInternal)
                .unsuspendForSuspendingPackage(PLATFORM_PACKAGE_NAME, UserHandle.USER_SYSTEM);
                .unsuspendForSuspendingPackage(PLATFORM_PACKAGE_NAME, UserHandle.USER_SYSTEM);
        verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null);
        verify(getServices().subscriptionManager).setSubscriptionUserHandle(0, null);
        DeviceConfig.setProperty(DeviceConfig.NAMESPACE_DEVICE_POLICY_MANAGER,
                FLAG_ENABLE_WORK_PROFILE_TELEPHONY, "false", false);
    }
    }


    @Test
    @Test