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

Commit 350962ca authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Remove restrictions PIN for all users

Bug: 10200097
Change-Id: I4d95cd49a21e8f4f6b2c141d1205f81622c395b5
parent 3d38fa30
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -116,7 +116,7 @@ public class UserManagerService extends IUserManager.Stub {


    private static final int MIN_USER_ID = 10;
    private static final int MIN_USER_ID = 10;


    private static final int USER_VERSION = 2;
    private static final int USER_VERSION = 3;


    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms


@@ -425,6 +425,7 @@ public class UserManagerService extends IUserManager.Stub {
                    && restrictions.getBoolean(UserManager.DISALLOW_APP_RESTRICTIONS, false)) {
                    && restrictions.getBoolean(UserManager.DISALLOW_APP_RESTRICTIONS, false)) {
                restrictions.putBoolean(UserManager.DISALLOW_APP_RESTRICTIONS, false);
                restrictions.putBoolean(UserManager.DISALLOW_APP_RESTRICTIONS, false);
            }
            }
            mUserRestrictions.get(userId).clear();
            mUserRestrictions.get(userId).putAll(restrictions);
            mUserRestrictions.get(userId).putAll(restrictions);
            writeUserLocked(mUsers.get(userId));
            writeUserLocked(mUsers.get(userId));
        }
        }
@@ -555,7 +556,7 @@ public class UserManagerService extends IUserManager.Stub {
                }
                }
            }
            }
            updateUserIdsLocked();
            updateUserIdsLocked();
            upgradeIfNecessary();
            upgradeIfNecessaryLocked();
        } catch (IOException ioe) {
        } catch (IOException ioe) {
            fallbackToSingleUserLocked();
            fallbackToSingleUserLocked();
        } catch (XmlPullParserException pe) {
        } catch (XmlPullParserException pe) {
@@ -573,7 +574,7 @@ public class UserManagerService extends IUserManager.Stub {
    /**
    /**
     * Upgrade steps between versions, either for fixing bugs or changing the data format.
     * Upgrade steps between versions, either for fixing bugs or changing the data format.
     */
     */
    private void upgradeIfNecessary() {
    private void upgradeIfNecessaryLocked() {
        int userVersion = mUserVersion;
        int userVersion = mUserVersion;
        if (userVersion < 1) {
        if (userVersion < 1) {
            // Assign a proper name for the owner, if not initialized correctly before
            // Assign a proper name for the owner, if not initialized correctly before
@@ -595,6 +596,18 @@ public class UserManagerService extends IUserManager.Stub {
            userVersion = 2;
            userVersion = 2;
        }
        }


        if (userVersion < 3) {
            // Remove restrictions PIN for all users
            for (int i = 0; i < mRestrictionsPinStates.size(); i++) {
                int userId = mRestrictionsPinStates.keyAt(i);
                RestrictionsPinState state = mRestrictionsPinStates.valueAt(i);
                if (state.salt != 0 && state.pinHash != null) {
                    removeRestrictionsForUser(userId);
                }
            }
            userVersion = 3;
        }

        if (userVersion < USER_VERSION) {
        if (userVersion < USER_VERSION) {
            Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
            Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
                    + USER_VERSION);
                    + USER_VERSION);
@@ -1221,6 +1234,10 @@ public class UserManagerService extends IUserManager.Stub {
    public void removeRestrictions() {
    public void removeRestrictions() {
        checkManageUsersPermission("Only system can remove restrictions");
        checkManageUsersPermission("Only system can remove restrictions");
        final int userHandle = UserHandle.getCallingUserId();
        final int userHandle = UserHandle.getCallingUserId();
        removeRestrictionsForUser(userHandle);
    }

    private void removeRestrictionsForUser(final int userHandle) {
        synchronized (mPackagesLock) {
        synchronized (mPackagesLock) {
            // Remove all user restrictions
            // Remove all user restrictions
            setUserRestrictions(new Bundle(), userHandle);
            setUserRestrictions(new Bundle(), userHandle);