HWComposer: setPowerMode to DOZE even if support is unknown

If a display has not been turned on since boot, we do not know whether
it supports doze. Rather than treating this as not supported, make
Display::supportsDoze return an error if the capabilities have not been
queried yet. If supportsDoze returns this error, try to set the mode to
DOZE(_SUSPEND) anyway. This allows properly waking from AOD.

If the call to Display::setPowerMode fails, this means it truly is not
supported, so fallback to the old behavior of turning it ON.

Fixes: 274722476
Test: manual
Test: GraphicsComposerAidlTest#SetPowerModeUnsupported
Change-Id: Ia88603565713ea4b6ec5142b693d2df1302131ea
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index aaf2523..0c2b77d 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -311,6 +311,14 @@
 }
 
 Error Display::supportsDoze(bool* outSupport) const {
+    {
+        std::scoped_lock lock(mDisplayCapabilitiesMutex);
+        if (!mDisplayCapabilities) {
+            // The display has not turned on since boot, so DOZE support is unknown.
+            ALOGW("%s: haven't queried capabilities yet!", __func__);
+            return Error::NO_RESOURCES;
+        }
+    }
     *outSupport = hasCapability(DisplayCapability::DOZE);
     return Error::NONE;
 }