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

Commit b82add27 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Clean up any restrictions files that shouldn't be there.

Partially fixes the mess that was caused by #9681399

Change-Id: Iaabe15c87d1b002f0b2210b34adcc31b8fb4329c
parent e969964c
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -822,6 +822,11 @@ public class UserManagerService extends IUserManager.Stub {
                pinState.failedAttempts = failedAttempts;
                pinState.lastAttemptTime = lastAttemptTime;
            }
            // If this is not a restricted profile and there is no restrictions pin, clean up
            // any restrictions files that might have been left behind.
            if (!userInfo.isRestricted() && salt == 0) {
                cleanAppRestrictions(id);
            }
            return userInfo;

        } catch (IOException ioe) {
@@ -873,6 +878,26 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    /**
     * Removes all the restrictions files (res_<packagename>) for a given user.
     * Does not do any permissions checking.
     */
    private void cleanAppRestrictions(int userId) {
        synchronized (mPackagesLock) {
            File dir = Environment.getUserSystemDirectory(userId);
            String[] files = dir.list();
            if (files == null) return;
            for (String fileName : files) {
                if (fileName.startsWith(RESTRICTIONS_FILE_PREFIX)) {
                    File resFile = new File(dir, fileName);
                    if (resFile.exists()) {
                        resFile.delete();
                    }
                }
            }
        }
    }

    @Override
    public UserInfo createUser(String name, int flags) {
        checkManageUsersPermission("Only the system can create users");