Fix ArrayIndexOutOfBoundsException in ScreenTimeoutPolicyListenersContainer
Guards access to mLastReportedState with mLock.
We had two usages without using mLock and on different threads:
- onCallbackDied on binder thread calls mLastReportedState.remove()
- notifyListenerIfNeeded reads/writes the map (on single thread), but as it could be also updated from a binder thread & it's not synchronized on a lock & the collection is not thread safe, we might get inconsistent state
Practically, I think right now this issue might likely happen only
when SystemUI crashes which causes onCallbackDied to be invoked
(SystemUI is the only current remote client, and we never call
removeScreenTimeoutPolicyListener). The current bugreports contain SystemUI crash before this.
Also made mScreenTimeoutPolicy non-volatile as it is not needed anymore
(accessed only under mLock).
Test: atest NotifierTest
Flag: com.android.server.power.feature.flags.enable_screen_timeout_policy_listener_api
Bug: 414978378
Change-Id: Id32073b6e61c9104339e2fccc3006c5ff776e889
1 file changed