Make meaning of PowerManager.isScreenOn() more consistent.

The power manager sends SCREEN_ON and SCREEN_OFF broadcasts
purely based on the current wakefulness state.  In particular,
when the system is awake, we consider the screen to be on even
if the screen may actually be off due to the proximity sensor
or some other condition.  Likewise when the system is dozing
or asleep, we consider the screen to be off although technically
it may still be on and dozing.

This behavior is maintained for compatibility with applications
that interpret screen on / off as an indicator of user presence.

As it happened, the value of PowerManager.isScreenOn() did not
always match the state indicated by the broadcasts under certain
situations.  Instead, it was based on the desired screen state.
These states used to be closely correlated but the addition
of doze mode causes them to diverge in meaning.

One consequence is that wake events from input devices might not
always wake the device from sleep unless the display's power
state was actually DOZING or OFF even if the power manager's
wakefulness was already DOZING or ASLEEP.  This is now fixed.

Change-Id: Ie819c6d2c5a9ffaaf3101c5dee93ff72e9bc9f30
1 file changed