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

Commit d8349052 authored by Robin Lee's avatar Robin Lee
Browse files

Make TvInputManagerService robust against user race conditions

If USER_REMOVED was received by the broadcastreceiver before
USER_SWITCHED was processed, TvInputManagerService before this
change would null pointer and bring down the whole system server.

Change-Id: I004d549572e17aba05d0a8f3cf5c08d14391789d
Test: atest --iterations 20 WindowStateTests StartActivityAsUserTests
Fix: 149013745
parent e7566acd
Loading
Loading
Loading
Loading
+31 −25
Original line number Diff line number Diff line
@@ -383,6 +383,7 @@ public final class TvInputManagerService extends SystemService {
            if (mCurrentUserId == userId) {
                return;
            }
            if (mUserStates.contains(mCurrentUserId)) {
                UserState userState = mUserStates.get(mCurrentUserId);
                List<SessionState> sessionStatesToRelease = new ArrayList<>();
                for (SessionState sessionState : userState.sessionStateMap.values()) {
@@ -415,6 +416,7 @@ public final class TvInputManagerService extends SystemService {
                        it.remove();
                    }
                }
            }

            mCurrentUserId = userId;
            getOrCreateUserStateLocked(userId);
@@ -490,6 +492,10 @@ public final class TvInputManagerService extends SystemService {
            userState.mainSessionToken = null;

            mUserStates.remove(userId);

            if (userId == mCurrentUserId) {
                switchUser(UserHandle.USER_SYSTEM);
            }
        }
    }