hwc2: Clean-up asynchronous power mode set

* Avoid blocking wait when checking for secure session.
* Add power state to dummy display.
* Restore exact power mode on ending secure session.

Change-Id: I74fab8fadb8528a15e32aa96b0362ad386bd30cc
CRs-Fixed: 2449460
diff --git a/composer/hwc_display_builtin.cpp b/composer/hwc_display_builtin.cpp
index 40a3ac3..d3e8785 100644
--- a/composer/hwc_display_builtin.cpp
+++ b/composer/hwc_display_builtin.cpp
@@ -127,6 +127,8 @@
     DLOGI("Drop redundant drawcycles %d", id_);
   }
 
+  is_primary_ = display_intf_->IsPrimaryDisplay();
+
   return status;
 }
 
@@ -136,7 +138,7 @@
 
   DTRACE_SCOPED();
 
-  if (display_paused_) {
+  if (display_paused_ || (!is_primary_ && active_secure_sessions_[kSecureDisplay])) {
     MarkLayersForGPUBypass();
     return status;
   }
@@ -244,7 +246,10 @@
   auto status = HWC2::Error::None;
 
   DTRACE_SCOPED();
-  if (display_paused_) {
+
+  if (!is_primary_ && active_secure_sessions_[kSecureDisplay]) {
+      return status;
+  } else if (display_paused_) {
     DisplayError error = display_intf_->Flush(&layer_stack_);
     validated_ = false;
     if (error != kErrorNone) {
@@ -594,6 +599,10 @@
     return -EINVAL;
   }
 
+  if (!is_primary_) {
+    return HWCDisplay::HandleSecureSession(secure_sessions, power_on_pending);
+  }
+
   if (current_power_mode_ != HWC2::PowerMode::On) {
     return 0;
   }
@@ -607,9 +616,9 @@
       return err;
     }
 
-    DLOGI("SecureDisplay state changed from %d to %d for display %d",
+    DLOGI("SecureDisplay state changed from %d to %d for display %d-%d",
           active_secure_sessions_.test(kSecureDisplay), secure_sessions.test(kSecureDisplay),
-          type_);
+          id_, type_);
   }
   active_secure_sessions_ = secure_sessions;
   *power_on_pending = false;