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

Commit 5d2afb94 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid locking in getCurrentUser when there is no user switch"

parents abc1753c dcb26bbf
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -123,12 +123,13 @@ final class UserController {
    private final Injector mInjector;
    private final Handler mHandler;

    // Holds the current foreground user's id
    // Holds the current foreground user's id. Use mLock when updating
    @GuardedBy("mLock")
    private int mCurrentUserId = UserHandle.USER_SYSTEM;
    // Holds the target user's id during a user switch
    private volatile int mCurrentUserId = UserHandle.USER_SYSTEM;
    // Holds the target user's id during a user switch. The value of mCurrentUserId will be updated
    // once target user goes into the foreground. Use mLock when updating
    @GuardedBy("mLock")
    private int mTargetUserId = UserHandle.USER_NULL;
    private volatile int mTargetUserId = UserHandle.USER_NULL;

    /**
     * Which users have been started, so are allowed to run code.
@@ -1505,6 +1506,11 @@ final class UserController {
            Slog.w(TAG, msg);
            throw new SecurityException(msg);
        }

        // Optimization - if there is no pending user switch, return current id
        if (mTargetUserId == UserHandle.USER_NULL) {
            return getUserInfo(mCurrentUserId);
        }
        synchronized (mLock) {
            return getCurrentUserLocked();
        }