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

Commit 56e0d800 authored by Alexandra Gherghina's avatar Alexandra Gherghina Committed by Android (Google) Code Review
Browse files

Merge "Clean up deleted users in DevicePolicyManagerService"

parents cb0462d3 22745f4c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -1227,6 +1227,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            loadSettingsLocked(getUserData(UserHandle.USER_OWNER), UserHandle.USER_OWNER);
            loadDeviceOwner();
        }
        cleanUpOldUsers();
        mAppOpsService = IAppOpsService.Stub.asInterface(
                ServiceManager.getService(Context.APP_OPS_SERVICE));
        if (mDeviceOwner != null) {
@@ -1247,6 +1248,32 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
    }

    private void cleanUpOldUsers() {
        // This is needed in case the broadcast {@link Intent.ACTION_USER_REMOVED} was not handled
        // before reboot
        Set<Integer> usersWithProfileOwners;
        Set<Integer> usersWithData;
        synchronized(this) {
            usersWithProfileOwners = mDeviceOwner != null
                    ? mDeviceOwner.getProfileOwnerKeys() : new HashSet<Integer>();
            usersWithData = new HashSet<Integer>();
            for (int i = 0; i < mUserData.size(); i++) {
                usersWithData.add(mUserData.keyAt(i));
            }
        }
        List<UserInfo> allUsers = mUserManager.getUsers();

        Set<Integer> deletedUsers = new HashSet<Integer>();
        deletedUsers.addAll(usersWithProfileOwners);
        deletedUsers.addAll(usersWithData);
        for (UserInfo userInfo : allUsers) {
            deletedUsers.remove(userInfo.id);
        }
        for (Integer userId : deletedUsers) {
            removeUserData(userId);
        }
    }

    private void handlePasswordExpirationNotification(int userHandle) {
        synchronized (this) {
            final long now = System.currentTimeMillis();