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

Commit 22745f4c authored by Alexandra Gherghina's avatar Alexandra Gherghina
Browse files

Clean up deleted users in DevicePolicyManagerService

Bug: 15405715
Change-Id: Icd958fe9378deb92f25622b341e0502d865b742f
parent a578ab00
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();