Fix race condition when entering low persistence mode

The problem is that -

1) When the device enters a VR activity directly from screen off, there
   is a chance the device is not in low persistence mode and ghosting is
   really bad.
2) LocalDisplayAdapter gets to know that the device is in VR mode later
   than PowerManagerService due to scheduling of it's runnable.
3) The call to Lights HAL to change the display mode only is made only
   when there is a brightness change.
4) This opens up a race condition where the PowerManagerService knows device
   is in VR mode and changes the brightness to VR brightness before the
   LocalDisplayAdapter knows about the VR mode change.
5) Since there is no more brightness change to be done, the device is
   not in low persistence mode creating really bad UX.

Fix is to trigger a brightness change call when there is a Display state
change so that LocalDisplayAdapter sets the low persistence mode
correctly always.

Bug: 67114120
Test:

1) Lock and unlock to VR puts the device in low persistence mode
   correctly always.
2) Lock and unlock in normal mode changes brightness correctly.
3) Even with lockscreen, all of the use cases above work correctly.

Change-Id: Ic0e6d92ba145aaa94f86e6d53ab5aa08cbbae10c
Signed-off-by: Karthik Ravi Shankar <karthikrs@google.com>
1 file changed