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

Commit 235e817c authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

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

parents 525b7c02 b82add27
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");