[SurfaceFlinger] Don't persist buffers to HWC when powered off.

This fixes an extremely rare crash, where stale buffer handles were
parceled over to HWC.

The cause was that HWC's command queue is not flushed while the display is
powered off, so buffers handles may become stale while they are sitting in the
command queue. If a layer's buffer goes out of scope in SurfaceFlinger, e.g.
an app continues renderng while the display is powered down, SurfaceFlinger
latches the new buffers, and consequently releases old buffers, then those
buffers will be deallocated while still sending the handles over to HWC
the next time a frame needs to be presented.

The fix prevents buffers from being queued while the display power mode
is OFF, so that buffer handles should never become stale while in the
command queue.

Bug: 141290044
Test: Enabling HWSAN: covering the phone during Hangouts video calling with
speaker-phone disabled to trigger display power down.
Test: libcompositionengine_test

Change-Id: I2592fecbbc17cf1ed70c348df8e53e9c59afb073
(cherry picked from commit 444c254ca0c920df3ad4ff19c262b2cd155caa7c)
3 files changed