Avoid race of checking screen states and sleep token
The callback *GoingToSleep and screenTurn* run on different threads,
so there could be a race if screen on/off in a short time and the
thread has some delays:
Thread1 gets isScreenOnEarly==false
Thread2 modifies isScreenOnEarly=true
Thread2 releases sleep-token
Thread1 acquire sleep-token
Then the final state is screen on but sleep-token is still acquired.
This change moves the fail-safe check from startedGoingToSleep
to finishedGoingToSleep>setAwake(false) and reuse the existing
SleepTokenAcquirer, so it is easier to acquire/release in
DisplayPolicy inside a lock. Now the check of isScreenOnEarly and
sleep-token in screenTurningOn and setAwake are synchronized.
Bug: 364760760
Flag: EXEMPT bugfix
Test: PhoneWindowManagerTests
Change-Id: I5c47b4a745fcd369d3ec825c41a7c1d35ce9feca
11 files changed