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

Commit cde84302 authored by Alex Salo's avatar Alex Salo
Browse files

Update AttentionManagerService

1. Change from onStopUser to onSwitchUser since onStopUser will actually
never be called.
2. Add some checks in the cancelAttentionCheck()

Bug: 111939367
Test: manually
Change-Id: I155a3acb20ef7fcad693a0a319b097cf50a474d1
parent 23258296
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -73,7 +73,6 @@ public class AttentionManagerService extends SystemService {

    private final Context mContext;
    private final PowerManager mPowerManager;
    private final ActivityManager mActivityManager;
    private final Object mLock;
    @GuardedBy("mLock")
    private final SparseArray<UserState> mUserStates = new SparseArray<>();
@@ -85,7 +84,6 @@ public class AttentionManagerService extends SystemService {
        super(context);
        mContext = Preconditions.checkNotNull(context);
        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        mLock = new Object();
        mAttentionHandler = new AttentionHandler();
    }
@@ -96,7 +94,7 @@ public class AttentionManagerService extends SystemService {
    }

    @Override
    public void onStopUser(int userId) {
    public void onSwitchUser(int userId) {
        cancelAndUnbindLocked(peekUserStateLocked(userId),
                AttentionService.ATTENTION_FAILURE_UNKNOWN);
    }
@@ -201,13 +199,22 @@ public class AttentionManagerService extends SystemService {

    /** Cancels the specified attention check. */
    public void cancelAttentionCheck(int requestCode) {
        synchronized (mLock) {
            final UserState userState = getOrCreateCurrentUserStateLocked();
            if (userState.mService == null) {
                if (userState.mPendingAttentionCheck != null
                        && userState.mPendingAttentionCheck.mRequestCode == requestCode) {
                    userState.mPendingAttentionCheck = null;
                }
                return;
            }
            try {
                userState.mService.cancelAttentionCheck(requestCode);
            } catch (RemoteException e) {
                Slog.e(LOG_TAG, "Cannot call into the AttentionService");
            }
        }
    }

    @GuardedBy("mLock")
    private void unbindAfterTimeoutLocked() {
@@ -224,7 +231,7 @@ public class AttentionManagerService extends SystemService {

    @GuardedBy("mLock")
    private UserState getOrCreateCurrentUserStateLocked() {
        return getOrCreateUserStateLocked(mActivityManager.getCurrentUser());
        return getOrCreateUserStateLocked(ActivityManager.getCurrentUser());
    }

    @GuardedBy("mLock")
@@ -239,7 +246,7 @@ public class AttentionManagerService extends SystemService {

    @GuardedBy("mLock")
    UserState peekCurrentUserStateLocked() {
        return peekUserStateLocked(mActivityManager.getCurrentUser());
        return peekUserStateLocked(ActivityManager.getCurrentUser());
    }

    @GuardedBy("mLock")