Merge "display-config: Add a soong namespace for display commonsys"
diff --git a/gralloc/QtiGralloc.cpp b/gralloc/QtiGralloc.cpp
index 903ccba..5172ad5 100644
--- a/gralloc/QtiGralloc.cpp
+++ b/gralloc/QtiGralloc.cpp
@@ -387,8 +387,10 @@
 
   if (IS_VENDOR_METADATA_TYPE(type)) {
     return metadata_set[GET_VENDOR_METADATA_STATUS_INDEX(type)];
-  } else {
+  } else if (GET_STANDARD_METADATA_STATUS_INDEX(type) < METADATA_SET_SIZE) {
     return metadata_set[GET_STANDARD_METADATA_STATUS_INDEX(type)];
+  } else {
+    return -1;
   }
 }
 
diff --git a/include/display_extn_intf.h b/include/display_extn_intf.h
index 84cd508..ac79cd8 100644
--- a/include/display_extn_intf.h
+++ b/include/display_extn_intf.h
@@ -35,6 +35,12 @@
 class DisplayExtnIntf {
  public:
   virtual int SetContentFps(uint32_t fps) = 0;
+  virtual void RegisterDisplay(uint32_t display_id) = 0;
+  virtual void UnregisterDisplay(uint32_t display_id) = 0;
+  virtual int SetActiveConfig(uint32_t display_id, uint32_t config_id) = 0;
+  virtual int NotifyEarlyWakeUp(bool gpu, bool display) = 0;
+  virtual int NotifyDisplayEarlyWakeUp(uint32_t display_id) = 0;
+
  protected:
   virtual ~DisplayExtnIntf() { }
 };
diff --git a/services/config/config_defs.h b/services/config/config_defs.h
index c4181b8..4f4ef92 100644
--- a/services/config/config_defs.h
+++ b/services/config/config_defs.h
@@ -295,6 +295,7 @@
   virtual int IsRotatorSupportedFormat(int hal_format, bool ubwc, bool *supported) DEFAULT_RET
   virtual int ControlQsyncCallback(bool enable) DEFAULT_RET
   virtual int SendTUIEvent(DisplayType dpy, TUIEventType event_type) DEFAULT_RET
+  virtual int GetDisplayHwId(uint32_t disp_id, uint32_t *display_hw_id) DEFAULT_RET
 
   // deprecated APIs
   virtual int GetDebugProperty(const std::string prop_name, std::string value) DEFAULT_RET
diff --git a/services/config/src/client_impl.cpp b/services/config/src/client_impl.cpp
index 0e1cdab..d3c3075 100644
--- a/services/config/src/client_impl.cpp
+++ b/services/config/src/client_impl.cpp
@@ -842,6 +842,29 @@
   return error;
 }
 
+int ClientImpl::GetDisplayHwId(uint32_t disp_id, uint32_t *display_hw_id) {
+  ByteStream input_params;
+  input_params.setToExternal(reinterpret_cast<uint8_t*>(&disp_id), sizeof(uint32_t));
+  ByteStream output_params;
+
+  int error = 0;
+  auto hidl_cb = [&error, &output_params] (int32_t err, ByteStream params, HandleStream handles) {
+    error = err;
+    output_params = params;
+  };
+
+  display_config_->perform(client_handle_, kGetDisplayHwId, input_params, {}, hidl_cb);
+
+  const uint8_t *data = output_params.data();
+  const uint32_t *output = reinterpret_cast<const uint32_t*>(data);
+
+  if (!error) {
+    *display_hw_id = *output;
+  }
+
+  return error;
+}
+
 void ClientCallback::ParseNotifyCWBBufferDone(const ByteStream &input_params,
                                               const HandleStream &input_handles) {
   const int *error;
diff --git a/services/config/src/client_impl.h b/services/config/src/client_impl.h
index a76d3de..677fedf 100644
--- a/services/config/src/client_impl.h
+++ b/services/config/src/client_impl.h
@@ -115,6 +115,7 @@
   virtual int IsRotatorSupportedFormat(int hal_format, bool ubwc, bool *supported);
   virtual int ControlQsyncCallback(bool enable);
   virtual int SendTUIEvent(DisplayType dpy, TUIEventType event_type);
+  virtual int GetDisplayHwId(uint32_t disp_id, uint32_t *display_hw_id);
 
  private:
   android::sp<IDisplayConfig> display_config_ = nullptr;
diff --git a/services/config/src/device_impl.cpp b/services/config/src/device_impl.cpp
index 5a590a8..a6304cc 100644
--- a/services/config/src/device_impl.cpp
+++ b/services/config/src/device_impl.cpp
@@ -723,6 +723,19 @@
   _hidl_cb(0, {}, {});
 }
 
+void DeviceImpl::DeviceClientContext::ParseGetDisplayHwId(const ByteStream &input_params,
+                                                          perform_cb _hidl_cb) {
+  uint32_t disp_hw_id = 0;
+  ByteStream output_params;
+
+  const uint8_t *data = input_params.data();
+  const uint32_t *disp_id = reinterpret_cast<const uint32_t*>(data);
+  int32_t error = intf_->GetDisplayHwId(*disp_id, &disp_hw_id);
+  output_params.setToExternal(reinterpret_cast<uint8_t*>(&disp_hw_id), sizeof(uint32_t));
+
+  _hidl_cb(error, output_params, {});
+}
+
 Return<void> DeviceImpl::perform(uint64_t client_handle, uint32_t op_code,
                                  const ByteStream &input_params, const HandleStream &input_handles,
                                  perform_cb _hidl_cb) {
@@ -873,6 +886,9 @@
     case kDestroy:
       ParseDestroy(client_handle, _hidl_cb);
       break;
+    case kGetDisplayHwId:
+      client->ParseGetDisplayHwId(input_params, _hidl_cb);
+      break;
     default:
       break;
   }
diff --git a/services/config/src/device_impl.h b/services/config/src/device_impl.h
index 39b7587..85a31c5 100644
--- a/services/config/src/device_impl.h
+++ b/services/config/src/device_impl.h
@@ -117,6 +117,7 @@
     void ParseControlQsyncCallback(uint64_t client_handle, const ByteStream &input_params,
                                    perform_cb _hidl_cb);
     void ParseSendTUIEvent(const ByteStream &input_params, perform_cb _hidl_cb);
+    void ParseGetDisplayHwId(const ByteStream &input_params, perform_cb _hidl_cb);
 
    private:
     ConfigInterface *intf_ = nullptr;
diff --git a/services/config/src/opcode_types.h b/services/config/src/opcode_types.h
index b589d8a..6e0c5b7 100644
--- a/services/config/src/opcode_types.h
+++ b/services/config/src/opcode_types.h
@@ -76,6 +76,7 @@
   kIsRotatorSupportedFormat = 40,
   kControlQsyncCallback = 41,
   kSendTUIEvent = 42,
+  kGetDisplayHwId = 43,
 
   kDestroy = 0xFFFF, // Destroy sequence execution
 };