hwc2: Update secure display layer on active built in display

1. Add support to handle secure display layer on secondary display
2. Update secure display layer on active builtin display.
3. Add display config API to get the display attributes of the active
   builtin display.

Change-Id: Ia70dff316265c9364b060fe4fae591a9599e16e9
CRs-Fixed: 2375587
diff --git a/common.mk b/common.mk
index 0d81828..e2f3c4c 100644
--- a/common.mk
+++ b/common.mk
@@ -3,8 +3,13 @@
 
 #Get the highest display config version available
 display_config_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.8" ];\
+    then echo DISPLAY_CONFIG_1_8; fi)
+ifeq ($(display_config_version),)
+display_config_version := $(shell \
     if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.7" ];\
     then echo DISPLAY_CONFIG_1_7; fi)
+endif
 ifeq ($(display_config_version),)
 display_config_version := $(shell \
     if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.6" ];\
@@ -71,6 +76,11 @@
     common_flags += -DDISPLAY_CONFIG_1_6 -DDISPLAY_CONFIG_1_5 -DDISPLAY_CONFIG_1_4
     common_flags += -DDISPLAY_CONFIG_1_3 -DDISPLAY_CONFIG_1_2 -DDISPLAY_CONFIG_1_1
 endif
+ifeq ($(display_config_version), DISPLAY_CONFIG_1_8)
+    common_flags += -DDISPLAY_CONFIG_1_1 -DDISPLAY_CONFIG_1_2 -DDISPLAY_CONFIG_1_3
+    common_flags += -DDISPLAY_CONFIG_1_4 -DDISPLAY_CONFIG_1_5 -DDISPLAY_CONFIG_1_6
+    common_flags += -DDISPLAY_CONFIG_1_7 -DDISPLAY_CONFIG_1_8
+endif
 
 ifeq ($(TARGET_USES_COLOR_METADATA), true)
     common_flags += -DUSE_COLOR_METADATA
diff --git a/sdm/libs/hwc2/Android.mk b/sdm/libs/hwc2/Android.mk
index 411d2f0..dfcd80e 100644
--- a/sdm/libs/hwc2/Android.mk
+++ b/sdm/libs/hwc2/Android.mk
@@ -69,7 +69,16 @@
 LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.6
 LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.7
 endif
-
+ifeq ($(display_config_version), DISPLAY_CONFIG_1_8)
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.1
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.2
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.3
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.4
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.5
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.6
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.7
+LOCAL_SHARED_LIBRARIES        += vendor.display.config@1.8
+endif
 
 LOCAL_SRC_FILES               := hwc_session.cpp \
                                  hwc_session_services.cpp \
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index 8c65e59..623473a 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -1844,11 +1844,6 @@
       return -EINVAL;
   }
 
-  if (display_status == kDisplayStatusResume || display_status == kDisplayStatusPause) {
-    callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
-    validated_ = false;
-  }
-
   return status;
 }
 
diff --git a/sdm/libs/hwc2/hwc_display_builtin.cpp b/sdm/libs/hwc2/hwc_display_builtin.cpp
index 4007754..7a8f262 100644
--- a/sdm/libs/hwc2/hwc_display_builtin.cpp
+++ b/sdm/libs/hwc2/hwc_display_builtin.cpp
@@ -287,7 +287,7 @@
     DLOGE("failed for mode = %d intent = %d", mode, intent);
     return status;
   }
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
   validated_ = false;
   return status;
 }
@@ -299,7 +299,7 @@
     return status;
   }
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
   validated_ = false;
 
   return status;
@@ -331,7 +331,7 @@
     return status;
   }
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
 
   return status;
 }
@@ -349,7 +349,7 @@
     return status;
   }
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
   color_tranform_failed_ = false;
   validated_ = false;
 
@@ -459,7 +459,7 @@
   if (error)
     return HWC2::Error::BadConfig;
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
 
   return HWC2::Error::None;
 }
@@ -560,6 +560,10 @@
     return -EINVAL;
   }
 
+  if (current_power_mode_ != HWC2::PowerMode::On) {
+    return 0;
+  }
+
   if (active_secure_sessions_[kSecureDisplay] != secure_sessions[kSecureDisplay]) {
     SecureEvent secure_event =
         secure_sessions.test(kSecureDisplay) ? kSecureDisplayStart : kSecureDisplayEnd;
@@ -587,7 +591,7 @@
 
   force_refresh_rate_ = refresh_rate;
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
 
   return;
 }
@@ -605,7 +609,7 @@
 DisplayError HWCDisplayBuiltIn::Refresh() {
   DisplayError error = kErrorNone;
 
-  callbacks_->Refresh(HWC_DISPLAY_PRIMARY);
+  callbacks_->Refresh(id_);
 
   return error;
 }
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index bdcb6ab..9640d67 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -449,15 +449,15 @@
     return HWC2_ERROR_BAD_DISPLAY;
   }
 
-  Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
   auto *hwc_session = static_cast<HWCSession *>(device);
+  hwc2_display_t active_builtin_disp_id = hwc_session->GetActiveBuiltinDisplay();
 
-  if (hwc_session->hwc_display_[HWC_DISPLAY_PRIMARY]) {
+  if (active_builtin_disp_id < kNumDisplays) {
+    Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
     std::bitset<kSecureMax> secure_sessions = 0;
-    hwc_session->hwc_display_[HWC_DISPLAY_PRIMARY]->GetActiveSecureSession(&secure_sessions);
+    hwc_session->hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
     if (secure_sessions.any()) {
-      DLOGI("Destroying virtual display id:%" PRIu64, display);
-      DLOGW("Secure session is active, deferring destruction of virtual display");
+      DLOGW("Secure session is active, defer destruction of virtual display id:%" PRIu64, display);
       hwc_session->destroy_virtual_disp_pending_ = true;
       return HWC2_ERROR_NONE;
     }
@@ -682,7 +682,7 @@
     return HWC2_ERROR_BAD_DISPLAY;
   }
 
-  hwc_session->HandleSecureSession(display);
+  hwc_session->HandleSecureSession();
   {
     SEQUENCE_EXIT_SCOPE_LOCK(locker_[display]);
     if (!hwc_session->hwc_display_[display]) {
@@ -1003,7 +1003,7 @@
   HWCSession *hwc_session = static_cast<HWCSession *>(device);
   // TODO(user): Handle secure session, handle QDCM solid fill
   auto status = HWC2::Error::BadDisplay;
-  hwc_session->HandleSecureSession(display);
+  hwc_session->HandleSecureSession();
   {
     SEQUENCE_ENTRY_SCOPE_LOCK(locker_[display]);
     if (power_on_pending_[display]) {
@@ -1160,10 +1160,13 @@
     return HWC2::Error::NoResources;
   }
 
-  SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
-  if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (active_builtin_disp_id < kNumDisplays) {
+    SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
     std::bitset<kSecureMax> secure_sessions = 0;
-    hwc_display_[HWC_DISPLAY_PRIMARY]->GetActiveSecureSession(&secure_sessions);
+    if (hwc_display_[active_builtin_disp_id]) {
+      hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
+    }
     if (secure_sessions.any()) {
       DLOGE("Secure session is active, cannot create virtual display.");
       return HWC2::Error::Unsupported;
@@ -1224,7 +1227,10 @@
     }
   }
 
-  hwc_display_[HWC_DISPLAY_PRIMARY]->ResetValidation();
+  if (active_builtin_disp_id < kNumDisplays) {
+    SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
+    hwc_display_[active_builtin_disp_id]->ResetValidation();
+  }
 
   return HWC2::Error::None;
 }
@@ -2223,9 +2229,10 @@
         (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
 
     std::bitset<kSecureMax> secure_sessions = 0;
-    {
-      Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
-      hwc_display_[HWC_DISPLAY_PRIMARY]->GetActiveSecureSession(&secure_sessions);
+    hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+    if (active_builtin_disp_id < kNumDisplays) {
+      Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
+      hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
     }
     if (secure_sessions[kSecureDisplay] || hwc_display_[virtual_display_index]) {
       // Defer hotplug events.
@@ -2556,20 +2563,23 @@
     return status;
   }
 
-  // Primary display needs revalidation
-  {
-    SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
-    hwc_display_[HWC_DISPLAY_PRIMARY]->ResetValidation();
-  }
+  // Active builtin display needs revalidation
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (active_builtin_disp_id < kNumDisplays) {
+    {
+      SCOPE_LOCK(locker_[active_builtin_disp_id]);
+      hwc_display_[active_builtin_disp_id]->ResetValidation();
+    }
 
-  if (client_connected_) {
-    Refresh(HWC_DISPLAY_PRIMARY);
-  }
+    if (client_connected_) {
+      Refresh(active_builtin_disp_id);
+    }
 
-  // Do not sleep if this method is called from client thread.
-  if (delay_hotplug) {
-    // wait sufficient time to ensure resources are available for new display connection.
-    usleep(UINT32(GetVsyncPeriod(HWC_DISPLAY_PRIMARY)) * 2 / 1000);
+    // Do not sleep if this method is called from client thread.
+    if (delay_hotplug) {
+      // wait sufficient time to ensure resources are available for new display connection.
+      usleep(UINT32(GetVsyncPeriod(INT32(active_builtin_disp_id))) * 2 / 1000);
+    }
   }
 
   for (auto client_id : pending_hotplugs) {
@@ -2761,16 +2771,18 @@
   Refresh(HWC_DISPLAY_PRIMARY);
 }
 
-void HWCSession::HandleSecureSession(hwc2_display_t disp_id) {
+void HWCSession::HandleSecureSession() {
   std::bitset<kSecureMax> secure_sessions = 0;
   {
-    Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
-    if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
-      hwc_display_[HWC_DISPLAY_PRIMARY]->GetActiveSecureSession(&secure_sessions);
+    hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+    if (active_builtin_disp_id >= kNumDisplays) {
+      return;
     }
+    Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
+    hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
   }
 
-  // If it is called during primary prepare/commit, we need to pause any onging commit on
+  // If it is called during primary prepare/commit, we need to pause any ongoing commit on
   // external/virtual display.
   for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; display < kNumDisplays; display++) {
     Locker::ScopeLock lock_d(locker_[display]);
@@ -2781,17 +2793,20 @@
 }
 
 void HWCSession::HandlePowerOnPending(hwc2_display_t disp_id, int retire_fence) {
-  if (disp_id != HWC_DISPLAY_PRIMARY) {
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (disp_id != active_builtin_disp_id) {
     return;
   }
 
-  Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
+  Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
   bool power_on_pending = false;
-  for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; display < kNumDisplays; display++) {
-    Locker::ScopeLock lock_d(locker_[display]);
-    if (power_on_pending_[display]) {
-      power_on_pending = true;
-      break;
+  for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; display < kNumDisplays; display++) {
+    if (display != active_builtin_disp_id) {
+      Locker::ScopeLock lock_d(locker_[display]);
+      if (power_on_pending_[display]) {
+        power_on_pending = true;
+        break;
+      }
     }
   }
   if (power_on_pending) {
@@ -2809,56 +2824,59 @@
     return;
   }
 
-  for (hwc2_display_t display = HWC_DISPLAY_PRIMARY + 1; display < kNumDisplays; display++) {
-    Locker::ScopeLock lock_d(locker_[display]);
-    if (power_on_pending_[display] && hwc_display_[display]) {
-      HWC2::Error status =
+  for (hwc2_display_t display = HWC_DISPLAY_PRIMARY; display < kNumDisplays; display++) {
+    if (display != active_builtin_disp_id) {
+      Locker::ScopeLock lock_d(locker_[display]);
+      if (power_on_pending_[display] && hwc_display_[display]) {
+        HWC2::Error status =
           hwc_display_[display]->SetPowerMode(HWC2::PowerMode::On, false /* teardown */);
-      if (status == HWC2::Error::None) {
-        power_on_pending_[display] = false;
+        if (status == HWC2::Error::None) {
+          power_on_pending_[display] = false;
+        }
       }
     }
   }
 }
 
 void HWCSession::HandleHotplugPending(hwc2_display_t disp_id, int retire_fence) {
-  if (disp_id != HWC_DISPLAY_PRIMARY ||
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (disp_id != active_builtin_disp_id ||
       (kHotPlugNone == hotplug_pending_event_ && !destroy_virtual_disp_pending_)) {
     return;
   }
 
   std :: bitset < kSecureMax > secure_sessions = 0;
-  {
-    Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
-    if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
-      if (!hwc_display_[HWC_DISPLAY_PRIMARY]->IsDisplayCommandMode()) {
-        if (destroy_virtual_disp_pending_ || kHotPlugEvent == hotplug_pending_event_) {
-          if (retire_fence >= 0) {
-            int error = sync_wait(retire_fence, 1000);
-            if (error < 0) {
-              DLOGE("sync_wait error errno = %d, desc = %s", errno,  strerror(errno));
-            }
-          }
-        }
+  if (active_builtin_disp_id < kNumDisplays) {
+    Locker::ScopeLock lock_a(locker_[active_builtin_disp_id]);
+    hwc_display_[active_builtin_disp_id]->GetActiveSecureSession(&secure_sessions);
+  }
+
+  if (secure_sessions.any() || active_builtin_disp_id == kNumDisplays) {
+    return;
+  }
+
+  if (destroy_virtual_disp_pending_ || kHotPlugEvent == hotplug_pending_event_) {
+    if (retire_fence >= 0) {
+      int error = sync_wait(retire_fence, 1000);
+      if (error < 0) {
+        DLOGE("sync_wait error errno = %d, desc = %s", errno,  strerror(errno));
       }
-      hwc_display_[HWC_DISPLAY_PRIMARY]->GetActiveSecureSession(&secure_sessions);
     }
-  }
-  // Destroy the pending virtual display if secure session not present.
-  if (!secure_sessions.any() && destroy_virtual_disp_pending_) {
-    for (auto &map_info : map_info_virtual_) {
-      DestroyDisplay(&map_info);
-      destroy_virtual_disp_pending_ = false;
+    // Destroy the pending virtual display if secure session not present.
+    if (destroy_virtual_disp_pending_) {
+      for (auto &map_info : map_info_virtual_) {
+        DestroyDisplay(&map_info);
+        destroy_virtual_disp_pending_ = false;
+      }
     }
-  }
-  // Handle connect/disconnect hotplugs if secure session is not present.
-  hwc2_display_t virtual_display_index = (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
-  if (!secure_sessions.any() && !hwc_display_[virtual_display_index] &&
-      kHotPlugEvent == hotplug_pending_event_) {
-    if (HandlePluggableDisplays(true)) {
-      DLOGE("Could not handle hotplug. Event dropped.");
+    // Handle connect/disconnect hotplugs if secure session is not present.
+    hwc2_display_t virtual_display_idx = (hwc2_display_t)GetDisplayIndex(qdutils::DISPLAY_VIRTUAL);
+    if (!hwc_display_[virtual_display_idx] && kHotPlugEvent == hotplug_pending_event_) {
+      if (HandlePluggableDisplays(true)) {
+        DLOGE("Could not handle hotplug. Event dropped.");
+      }
+      hotplug_pending_event_ = kHotPlugNone;
     }
-    hotplug_pending_event_ = kHotPlugNone;
   }
 }
 
@@ -3029,18 +3047,23 @@
   return static_cast<android::status_t>(controlIdlePowerCollapse(enable, synchronous));
 #else
   {
-    SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
-    if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
+    hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+    if (active_builtin_disp_id >= kNumDisplays) {
+      DLOGE("No active displays");
+      return -EINVAL;
+    }
+    SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
+    if (hwc_display_[active_builtin_disp_id]) {
       DLOGE("Primary display is not ready");
       return -EINVAL;
     }
-    auto error = hwc_display_[HWC_DISPLAY_PRIMARY]->ControlIdlePowerCollapse(enable, synchronous);
-    if (error != kErrorNone) {
-      return (error == kErrorNotSupported) ? 0 : -EINVAL;
+    auto err = hwc_display_[active_builtin_disp_id]->ControlIdlePowerCollapse(enable, synchronous);
+    if (err != kErrorNone) {
+      return (err == kErrorNotSupported) ? 0 : -EINVAL;
     }
     if (!enable) {
-      Refresh(HWC_DISPLAY_PRIMARY);
-      int32_t error = locker_[HWC_DISPLAY_PRIMARY].WaitFinite(kCommitDoneTimeoutMs);
+      Refresh(active_builtin_disp_id);
+      int32_t error = locker_[active_builtin_disp_id].WaitFinite(kCommitDoneTimeoutMs);
       if (error == ETIMEDOUT) {
         DLOGE("Timed out!! Next frame commit done event not received!!");
         return error;
@@ -3052,4 +3075,18 @@
 #endif
 }
 
+hwc2_display_t HWCSession::GetActiveBuiltinDisplay() {
+  hwc2_display_t disp_id = kNumDisplays;
+  Locker::ScopeLock lock_p(locker_[HWC_DISPLAY_PRIMARY]);
+  Locker::ScopeLock lock_b2(locker_[HWC_DISPLAY_BUILTIN_2]);
+  if (hwc_display_[HWC_DISPLAY_PRIMARY] &&
+      hwc_display_[HWC_DISPLAY_PRIMARY]->GetCurrentPowerMode() == HWC2::PowerMode::On) {
+    disp_id = HWC_DISPLAY_PRIMARY;
+  } else if (hwc_display_[HWC_DISPLAY_BUILTIN_2] &&
+      hwc_display_[HWC_DISPLAY_BUILTIN_2]->GetCurrentPowerMode() == HWC2::PowerMode::On) {
+    disp_id = HWC_DISPLAY_BUILTIN_2;
+  }
+  return disp_id;
+}
+
 }  // namespace sdm
diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h
index 794cf08..3c56470 100644
--- a/sdm/libs/hwc2/hwc_session.h
+++ b/sdm/libs/hwc2/hwc_session.h
@@ -20,7 +20,9 @@
 #ifndef __HWC_SESSION_H__
 #define __HWC_SESSION_H__
 
-#ifdef DISPLAY_CONFIG_1_7
+#ifdef DISPLAY_CONFIG_1_8
+#include <vendor/display/config/1.8/IDisplayConfig.h>
+#elif DISPLAY_CONFIG_1_7
 #include <vendor/display/config/1.7/IDisplayConfig.h>
 #elif DISPLAY_CONFIG_1_6
 #include <vendor/display/config/1.6/IDisplayConfig.h>
@@ -59,7 +61,9 @@
 
 namespace sdm {
 
-#ifdef DISPLAY_CONFIG_1_7
+#ifdef DISPLAY_CONFIG_1_8
+using vendor::display::config::V1_8::IDisplayConfig;
+#elif DISPLAY_CONFIG_1_7
 using vendor::display::config::V1_7::IDisplayConfig;
 #elif DISPLAY_CONFIG_1_6
 using vendor::display::config::V1_6::IDisplayConfig;
@@ -344,6 +348,10 @@
                                 getDebugProperty_cb _hidl_cb) override;
 #endif
 
+#ifdef DISPLAY_CONFIG_1_8
+  Return<void> getActiveBuiltinDisplayAttributes(getDisplayAttributes_cb _hidl_cb) override;
+#endif
+
   // QClient methods
   virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel,
                                            android::Parcel *output_parcel);
@@ -385,13 +393,14 @@
   HWC2::Error ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types,
                                       uint32_t *out_num_requests);
   HWC2::Error PresentDisplayInternal(hwc2_display_t display, int32_t *out_retire_fence);
-  void HandleSecureSession(hwc2_display_t display);
+  void HandleSecureSession();
   void HandlePowerOnPending(hwc2_display_t display, int retire_fence);
   void HandleHotplugPending(hwc2_display_t disp_id, int retire_fence);
   void UpdateVsyncSource();
   hwc2_display_t GetNextVsyncSource();
   DisplayClass GetDisplayClass(hwc2_display_t display_id);
   bool IsPluggableDisplayConnected();
+  hwc2_display_t GetActiveBuiltinDisplay();
 
   CoreInterface *core_intf_ = nullptr;
   HWCDisplay *hwc_display_[kNumDisplays] = {nullptr};
diff --git a/sdm/libs/hwc2/hwc_session_services.cpp b/sdm/libs/hwc2/hwc_session_services.cpp
index 940a55c..30a0863 100644
--- a/sdm/libs/hwc2/hwc_session_services.cpp
+++ b/sdm/libs/hwc2/hwc_session_services.cpp
@@ -126,7 +126,21 @@
   } else if (!hwc_display_[disp_idx]) {
     DLOGW("Display is not connected");
   } else {
-    return hwc_display_[disp_idx]->SetDisplayStatus(status);
+    int err = hwc_display_[disp_idx]->SetDisplayStatus(status);
+    if (err != 0) {
+      return err;
+    }
+
+    if (status == HWCDisplay::kDisplayStatusResume || status == HWCDisplay::kDisplayStatusPause) {
+      hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+      if (active_builtin_disp_id < kNumDisplays) {
+        {
+          SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
+          hwc_display_[active_builtin_disp_id]->ResetValidation();
+        }
+        callbacks_.Refresh(active_builtin_disp_id);
+      }
+    }
   }
 
   return -EINVAL;
@@ -465,7 +479,12 @@
 }
 
 Return<int32_t> HWCSession::setCameraLaunchStatus(uint32_t on) {
-  SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (active_builtin_disp_id >= kNumDisplays) {
+    DLOGE("No active displays");
+    return -EINVAL;
+  }
+  SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
 
   if (null_display_mode_) {
     return 0;
@@ -476,15 +495,15 @@
     return -ENOENT;
   }
 
-  if (!hwc_display_[HWC_DISPLAY_PRIMARY]) {
-    DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY);
+  if (!hwc_display_[active_builtin_disp_id]) {
+    DLOGW("Display = %d is not connected.", active_builtin_disp_id);
     return -ENODEV;
   }
 
   HWBwModes mode = on > 0 ? kBwCamera : kBwDefault;
 
   // trigger invalidate to apply new bw caps.
-  Refresh(HWC_DISPLAY_PRIMARY);
+  Refresh(active_builtin_disp_id);
 
   if (core_intf_->SetMaxBandwidthMode(mode) != kErrorNone) {
     return -EINVAL;
@@ -492,7 +511,7 @@
 
   new_bw_mode_ = true;
   need_invalidate_ = true;
-  hwc_display_[HWC_DISPLAY_PRIMARY]->ResetValidation();
+  hwc_display_[active_builtin_disp_id]->ResetValidation();
 
   return 0;
 }
@@ -597,17 +616,23 @@
 
 #ifdef DISPLAY_CONFIG_1_3
 Return<int32_t> HWCSession::controlIdlePowerCollapse(bool enable, bool synchronous) {
-  SEQUENCE_WAIT_SCOPE_LOCK(locker_[HWC_DISPLAY_PRIMARY]);
+  hwc2_display_t active_builtin_disp_id = GetActiveBuiltinDisplay();
+  if (active_builtin_disp_id >= kNumDisplays) {
+    DLOGE("No active displays");
+    return -EINVAL;
+  }
+  SEQUENCE_WAIT_SCOPE_LOCK(locker_[active_builtin_disp_id]);
 
-  if (hwc_display_[HWC_DISPLAY_PRIMARY]) {
+  if (hwc_display_[active_builtin_disp_id]) {
     if (!enable) {
       if (!idle_pc_ref_cnt_) {
-        auto err = hwc_display_[HWC_DISPLAY_PRIMARY]->ControlIdlePowerCollapse(enable, synchronous);
+        auto err = hwc_display_[active_builtin_disp_id]->ControlIdlePowerCollapse(enable,
+                                                                                  synchronous);
         if (err != kErrorNone) {
           return (err == kErrorNotSupported) ? 0 : -EINVAL;
         }
-        Refresh(HWC_DISPLAY_PRIMARY);
-        int32_t error = locker_[HWC_DISPLAY_PRIMARY].WaitFinite(kCommitDoneTimeoutMs);
+        Refresh(active_builtin_disp_id);
+        int32_t error = locker_[active_builtin_disp_id].WaitFinite(kCommitDoneTimeoutMs);
         if (error == ETIMEDOUT) {
           DLOGE("Timed out!! Next frame commit done event not received!!");
           return error;
@@ -617,7 +642,8 @@
       idle_pc_ref_cnt_++;
     } else if (idle_pc_ref_cnt_ > 0) {
       if (!(idle_pc_ref_cnt_ - 1)) {
-        auto err = hwc_display_[HWC_DISPLAY_PRIMARY]->ControlIdlePowerCollapse(enable, synchronous);
+        auto err = hwc_display_[active_builtin_disp_id]->ControlIdlePowerCollapse(enable,
+                                                                                  synchronous);
         if (err != kErrorNone) {
           return (err == kErrorNotSupported) ? 0 : -EINVAL;
         }
@@ -628,7 +654,7 @@
     return 0;
   }
 
-  DLOGW("Display = %d is not connected.", HWC_DISPLAY_PRIMARY);
+  DLOGW("Display = %d is not connected.", active_builtin_disp_id);
   return -ENODEV;
 }
 #endif  // DISPLAY_CONFIG_1_3
@@ -742,4 +768,41 @@
 }
 #endif
 
+#ifdef DISPLAY_CONFIG_1_8
+Return<void> HWCSession::getActiveBuiltinDisplayAttributes(
+                                          getDisplayAttributes_cb _hidl_cb) {
+  int32_t error = -EINVAL;
+  IDisplayConfig::DisplayAttributes display_attributes = {};
+  hwc2_display_t disp_id = GetActiveBuiltinDisplay();
+
+  if (disp_id >= kNumDisplays) {
+    DLOGE("Invalid display = %d", disp_id);
+  } else {
+    if (hwc_display_[disp_id]) {
+      uint32_t config_index = 0;
+      HWC2::Error ret = hwc_display_[disp_id]->GetActiveConfig(&config_index);
+      if (ret != HWC2::Error::None) {
+        goto err;
+      }
+      DisplayConfigVariableInfo var_info;
+      error = hwc_display_[disp_id]->GetDisplayAttributesForConfig(INT(config_index), &var_info);
+      if (!error) {
+        display_attributes.vsyncPeriod = var_info.vsync_period_ns;
+        display_attributes.xRes = var_info.x_pixels;
+        display_attributes.yRes = var_info.y_pixels;
+        display_attributes.xDpi = var_info.x_dpi;
+        display_attributes.yDpi = var_info.y_dpi;
+        display_attributes.panelType = IDisplayConfig::DisplayPortType::DISPLAY_PORT_DEFAULT;
+        display_attributes.isYuv = var_info.is_yuv;
+      }
+    }
+  }
+
+err:
+  _hidl_cb(error, display_attributes);
+
+  return Void();
+}
+#endif  // DISPLAY_CONFIG_1_8
+
 }  // namespace sdm