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

Commit 9bfc65f3 authored by Victor Chang's avatar Victor Chang
Browse files

Add api to update user_setup_completed flag to allow e2e testing in ManagedProvisioning

Bug:30031808
Change-Id: Idd4b230931718a6d10f0fc41cdcf9bccb5c6354c
parent ccd3de69
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -6465,6 +6465,18 @@ public class DevicePolicyManager {
        }
    }

    /**
     * @hide
     * Force update user setup completed status
     */
    public void forceUpdateUserSetupComplete() {
        try {
            mService.forceUpdateUserSetupComplete();
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    private void throwIfParentInstance(String functionName) {
        if (mParentInstance) {
            throw new SecurityException(functionName + " cannot be called on the parent instance");
+2 −0
Original line number Diff line number Diff line
@@ -305,4 +305,6 @@ interface IDevicePolicyManager {
    boolean isDeviceProvisioned();
    boolean isDeviceProvisioningConfigApplied();
    void setDeviceProvisioningConfigApplied();

    void forceUpdateUserSetupComplete();
}
+24 −0
Original line number Diff line number Diff line
@@ -9131,4 +9131,28 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            return policy.mDeviceProvisioningConfigApplied;
        }
    }

    /**
     * Force update internal persistent state from Settings.Secure.USER_SETUP_COMPLETE.
     *
     * It's added for testing only. Please use this API carefully if it's used by other system app
     * and bare in mind Settings.Secure.USER_SETUP_COMPLETE can be modified by user and other system
     * apps.
     */
    @Override
    public void forceUpdateUserSetupComplete() {
        enforceCanManageProfileAndDeviceOwners();
        List<UserInfo> users = mUserManager.getUsers(true);
        final int N = users.size();
        for (int i = 0; i < N; i++) {
            int userHandle = users.get(i).id;
            boolean isUserCompleted = mInjector.settingsSecureGetIntForUser(
                    Settings.Secure.USER_SETUP_COMPLETE, 0, userHandle) != 0;
            DevicePolicyData policy = getUserData(userHandle);
            policy.mUserSetupComplete = isUserCompleted;
            synchronized (this) {
                saveSettingsLocked(userHandle);
            }
        }
    }
}