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

Commit 3c4b8141 authored by kholoud mohamed's avatar kholoud mohamed
Browse files

Allow forceUpdateUserSetupComplete on user builds

This fixes some failing cts tests running on user builds.

Test: atest android.devicepolicy.cts.DevicePolicyManagerTest
Fixes: 181567444
Change-Id: I07c3a98fcbe79d41fb224967569b877eefbc593c
parent ed23887b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11769,7 +11769,7 @@ public class DevicePolicyManager {
    /**
     * @hide
     * Force update user setup completed status. This API has no effect on user build.
     * Force update user setup completed status.
     * @throws {@link SecurityException} if the caller has no
     *         {@code android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS} or the caller is
     *         not {@link UserHandle#SYSTEM_USER}
+0 −4
Original line number Diff line number Diff line
@@ -14101,10 +14101,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                hasCallingOrSelfPermission(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
        enforceCallerSystemUserHandle();
        // no effect if it's called from user build
        if (!mInjector.isBuildDebuggable()) {
            return;
        }
        final int userId = UserHandle.USER_SYSTEM;
        boolean isUserCompleted = mInjector.settingsSecureGetIntForUser(
                Settings.Secure.USER_SETUP_COMPLETE, 0, userId) != 0;
+1 −29
Original line number Diff line number Diff line
@@ -3875,7 +3875,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
    }

    @Test
    public void testForceUpdateUserSetupComplete_userbuild() {
    public void testForceUpdateUserSetupComplete_forcesUpdate() {
        mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;

@@ -3888,34 +3888,6 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        userData.mUserSetupComplete = true;
        dpms.mUserData.put(UserHandle.USER_SYSTEM, userData);

        // GIVEN it's user build
        getServices().buildMock.isDebuggable = false;

        assertThat(dpms.hasUserSetupCompleted()).isTrue();

        dpm.forceUpdateUserSetupComplete();

        // THEN the state in dpms is not changed
        assertThat(dpms.hasUserSetupCompleted()).isTrue();
    }

    @Test
    public void testForceUpdateUserSetupComplete_userDebugbuild() {
        mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
        mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;

        final int userId = UserHandle.USER_SYSTEM;
        // GIVEN userComplete is false in SettingsProvider
        setUserSetupCompleteForUser(false, userId);

        // GIVEN userComplete is true in DPM
        DevicePolicyData userData = new DevicePolicyData(userId);
        userData.mUserSetupComplete = true;
        dpms.mUserData.put(UserHandle.USER_SYSTEM, userData);

        // GIVEN it's userdebug build
        getServices().buildMock.isDebuggable = true;

        assertThat(dpms.hasUserSetupCompleted()).isTrue();

        dpm.forceUpdateUserSetupComplete();