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

Commit 36084b10 authored by Kevin Han's avatar Kevin Han Committed by Android (Google) Code Review
Browse files

Merge "Lock before checking if user state is null"

parents 93ee38ec 5348e683
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -223,10 +223,10 @@ public final class AppHibernationService extends SystemService {
                android.Manifest.permission.MANAGE_APP_HIBERNATION,
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        userId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
            if (!checkUserStatesExist(userId, methodName)) {
                return false;
            }
        synchronized (mLock) {
            final Map<String, UserLevelState> packageStates = mUserStates.get(userId);
            final UserLevelState pkgState = packageStates.get(packageName);
            if (pkgState == null) {
@@ -278,10 +278,10 @@ public final class AppHibernationService extends SystemService {
                android.Manifest.permission.MANAGE_APP_HIBERNATION,
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        final int realUserId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
            if (!checkUserStatesExist(realUserId, methodName)) {
                return;
            }
        synchronized (mLock) {
            final Map<String, UserLevelState> packageStates = mUserStates.get(realUserId);
            final UserLevelState pkgState = packageStates.get(packageName);
            if (pkgState == null) {
@@ -365,10 +365,10 @@ public final class AppHibernationService extends SystemService {
                android.Manifest.permission.MANAGE_APP_HIBERNATION,
                "Caller does not have MANAGE_APP_HIBERNATION permission.");
        userId = handleIncomingUser(userId, methodName);
        synchronized (mLock) {
            if (!checkUserStatesExist(userId, methodName)) {
                return hibernatingPackages;
            }
        synchronized (mLock) {
            Map<String, UserLevelState> userStates = mUserStates.get(userId);
            for (UserLevelState state : userStates.values()) {
                if (state.hibernated) {
@@ -658,6 +658,14 @@ public final class AppHibernationService extends SystemService {
        }
    }

    /**
     * Check that user states exist.
     *
     * @param userId user to check
     * @param methodName method name that is calling. Used for logging purposes.
     * @return true if user states exist
     */
    @GuardedBy("mLock")
    private boolean checkUserStatesExist(int userId, String methodName) {
        if (!mUserManager.isUserUnlockingOrUnlocked(userId)) {
            Slog.e(TAG, String.format(