Merge "sdm: Remove LayerCache from HWC" into display.lnx.3.0-dev
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 0eee65e..2284633 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -136,11 +136,6 @@
             flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
         }
 
-        ColorSpace_t colorSpace = ITU_R_601;
-        if (usage & GRALLOC_USAGE_HW_CAMERA_MASK) {
-            colorSpace = ITU_R_601_FR;
-        }
-
         if (usage & (GRALLOC_USAGE_HW_VIDEO_ENCODER |
                 GRALLOC_USAGE_HW_CAMERA_WRITE |
                 GRALLOC_USAGE_HW_RENDER |
@@ -165,6 +160,7 @@
         hnd->offset = data.offset;
         hnd->base = (uint64_t)(data.base) + data.offset;
         hnd->gpuaddr = 0;
+        ColorSpace_t colorSpace = ITU_R_601_FR;
         setMetaData(hnd, UPDATE_COLOR_SPACE, (void*) &colorSpace);
 
         *pHandle = hnd;
diff --git a/libqservice/IQService.cpp b/libqservice/IQService.cpp
index e4aee7a..6545427 100644
--- a/libqservice/IQService.cpp
+++ b/libqservice/IQService.cpp
@@ -79,8 +79,6 @@
 
 // ----------------------------------------------------------------------
 
-static void getProcName(int pid, char *buf, int size);
-
 status_t BnQService::onTransact(
     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
 {
@@ -89,10 +87,6 @@
     IPCThreadState* ipc = IPCThreadState::self();
     const int callerPid = ipc->getCallingPid();
     const int callerUid = ipc->getCallingUid();
-    const int MAX_BUF_SIZE = 1024;
-    char callingProcName[MAX_BUF_SIZE] = {0};
-
-    getProcName(callerPid, callingProcName, MAX_BUF_SIZE);
 
     const bool permission = (callerUid == AID_MEDIA ||
             callerUid == AID_GRAPHICS ||
@@ -102,9 +96,8 @@
     if (code == CONNECT_HWC_CLIENT) {
         CHECK_INTERFACE(IQService, data, reply);
         if(callerUid != AID_GRAPHICS) {
-            ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: \
-                    pid=%d uid=%d process=%s",
-                    callerPid, callerUid, callingProcName);
+            ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d",
+                   callerPid, callerUid);
             return PERMISSION_DENIED;
         }
         sp<IQClient> client =
@@ -114,9 +107,8 @@
     } else if(code == CONNECT_HDMI_CLIENT) {
         CHECK_INTERFACE(IQService, data, reply);
         if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) {
-            ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: \
-                    pid=%d uid=%d process=%s",
-                    callerPid, callerUid, callingProcName);
+            ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d",
+                   callerPid, callerUid);
             return PERMISSION_DENIED;
         }
         sp<IQHDMIClient> client =
@@ -125,9 +117,8 @@
         return NO_ERROR;
     } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) {
         if(!permission) {
-            ALOGE("display.qservice access denied: command=%d\
-                  pid=%d uid=%d process=%s", code, callerPid,
-                  callerUid, callingProcName);
+            ALOGE("display.qservice access denied: command=%d pid=%d uid=%d",
+                   code, callerPid, callerUid);
             return PERMISSION_DENIED;
         }
         CHECK_INTERFACE(IQService, data, reply);
@@ -138,20 +129,4 @@
     }
 }
 
-//Helper
-static void getProcName(int pid, char *buf, int size) {
-    int fd = -1;
-    snprintf(buf, size, "/proc/%d/cmdline", pid);
-    fd = open(buf, O_RDONLY);
-    if (fd < 0) {
-        strlcpy(buf, "Unknown", size);
-    } else {
-        ssize_t len = read(fd, buf, size - 1);
-        if (len >= 0)
-           buf[len] = 0;
-
-        close(fd);
-    }
-}
-
 }; // namespace qService
diff --git a/sdm/include/core/debug_interface.h b/sdm/include/core/debug_interface.h
index 67a38be..f4e3fc3 100644
--- a/sdm/include/core/debug_interface.h
+++ b/sdm/include/core/debug_interface.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+* Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -127,6 +127,15 @@
   */
   virtual DisplayError GetProperty(const char *property_name, char *value) = 0;
 
+  /*! @brief Method to set a property to a given string value.
+
+   @param[in] property_name name of the property
+   @param[in] value new value of the property name
+
+   @return \link DisplayError \endlink
+  */
+  virtual DisplayError SetProperty(const char *property_name, const char *value) = 0;
+
  protected:
   virtual ~DebugHandler() { }
 };
diff --git a/sdm/include/utils/debug.h b/sdm/include/utils/debug.h
index 5ac2319..6f6b3e6 100644
--- a/sdm/include/utils/debug.h
+++ b/sdm/include/utils/debug.h
@@ -74,6 +74,7 @@
   static bool IsScalarDisabled();
   static bool IsUbwcTiledFrameBuffer();
   static bool GetProperty(const char *property_name, char *value);
+  static bool SetProperty(const char *property_name, const char *value);
 
  private:
   Debug();
@@ -96,6 +97,9 @@
     virtual DisplayError GetProperty(const char */*property_name*/, char */*value*/) {
       return kErrorNotSupported;
     }
+    virtual DisplayError SetProperty(const char */*property_name*/, const char */*value*/) {
+      return kErrorNotSupported;
+    }
   };
 
   DefaultDebugHandler default_debug_handler_;
diff --git a/sdm/include/utils/locker.h b/sdm/include/utils/locker.h
index bc24ad5..fffe634 100644
--- a/sdm/include/utils/locker.h
+++ b/sdm/include/utils/locker.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2014 - 2015, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met:
@@ -89,7 +89,7 @@
     explicit SequenceWaitScopeLock(Locker& locker) : locker_(locker), error_(false) {
       locker_.Lock();
 
-      if (locker_.sequence_wait_ == 1) {
+      while (locker_.sequence_wait_ == 1) {
         locker_.Wait();
         error_ = (locker_.sequence_wait_ == -1);
       }
diff --git a/sdm/libs/hwc/hwc_debugger.cpp b/sdm/libs/hwc/hwc_debugger.cpp
index 7c8bbfd..c3c8707 100644
--- a/sdm/libs/hwc/hwc_debugger.cpp
+++ b/sdm/libs/hwc/hwc_debugger.cpp
@@ -181,5 +181,13 @@
   return kErrorNotSupported;
 }
 
+DisplayError HWCDebugHandler::SetProperty(const char *property_name, const char *value) {
+  if (property_set(property_name, value) == 0) {
+    return kErrorNone;
+  }
+
+  return kErrorNotSupported;
+}
+
 }  // namespace sdm
 
diff --git a/sdm/libs/hwc/hwc_debugger.h b/sdm/libs/hwc/hwc_debugger.h
index 68f95d9..f91338e 100644
--- a/sdm/libs/hwc/hwc_debugger.h
+++ b/sdm/libs/hwc/hwc_debugger.h
@@ -62,6 +62,7 @@
   virtual void EndTrace();
   virtual DisplayError GetProperty(const char *property_name, int *value);
   virtual DisplayError GetProperty(const char *property_name, char *value);
+  virtual DisplayError SetProperty(const char *property_name, const char *value);
 
  private:
   static HWCDebugHandler debug_handler_;
diff --git a/sdm/libs/hwc/hwc_session.cpp b/sdm/libs/hwc/hwc_session.cpp
index 9632d71..8e1dd24 100644
--- a/sdm/libs/hwc/hwc_session.cpp
+++ b/sdm/libs/hwc/hwc_session.cpp
@@ -154,6 +154,7 @@
     if (hw_disp_info.type == kHDMI) {
       // HDMI is primary display. If already connected, then create it and store in
       // primary display slot. If not connected, create a NULL display for now.
+      HWCDebugHandler::Get()->SetProperty("persist.sys.is_hdmi_primary", "1");
       if (hw_disp_info.is_connected) {
         status = HWCDisplayExternal::Create(core_intf_, &hwc_procs_, qservice_,
                                             &hwc_display_[HWC_DISPLAY_PRIMARY]);
diff --git a/sdm/libs/utils/debug.cpp b/sdm/libs/utils/debug.cpp
index 7082421..b91cdf4 100644
--- a/sdm/libs/utils/debug.cpp
+++ b/sdm/libs/utils/debug.cpp
@@ -148,5 +148,13 @@
   return true;
 }
 
+bool Debug::SetProperty(const char* property_name, const char* value) {
+  if (debug_.debug_handler_->SetProperty(property_name, value) != kErrorNone) {
+    return false;
+  }
+
+  return true;
+}
+
 }  // namespace sdm