sdm: Remove libsdmutils dependency on Android.

- Make libsdmutils Android independent.
- Rename debug_android.cpp to debug.cpp.
- Fix compilation errors observed in linux environment.

Change-Id: I19e275939b27f2f47949c5e17559eeadb09bdccf
diff --git a/sdm/include/core/core_interface.h b/sdm/include/core/core_interface.h
index 882d050..e1b38fa 100644
--- a/sdm/include/core/core_interface.h
+++ b/sdm/include/core/core_interface.h
@@ -42,8 +42,7 @@
 #include "display_interface.h"
 #include "sdm_types.h"
 #include "buffer_allocator.h"
-
-class BufferSyncHandler;
+#include "buffer_sync_handler.h"
 
 /*! @brief Display manager interface version.
 
diff --git a/sdm/include/core/debug_interface.h b/sdm/include/core/debug_interface.h
index ca6f81a..f8e80b1 100644
--- a/sdm/include/core/debug_interface.h
+++ b/sdm/include/core/debug_interface.h
@@ -38,7 +38,7 @@
 /*! @brief This enum represents different modules/logical unit tags that a log message may
   be associated with. Client may use this to filter messages for dynamic logging.
 
-  @sa DisplayLogHandler
+  @sa DebugHandler
 */
 enum DebugTag {
   kTagNone,             //!< Debug log is not tagged. This type of logs should always be printed.
@@ -101,6 +101,15 @@
   */
   virtual void EndTrace() = 0;
 
+  /*! @brief Method to get property value corresponding to give string.
+
+    @param[in] property_name name of the property
+    @param[out] value value corresponding to the property name
+
+    @return \link DisplayError \endlink
+`  */
+  virtual DisplayError GetProperty(const char *property_name, int *value) = 0;
+
  protected:
   virtual ~DebugHandler() { }
 };
diff --git a/sdm/include/utils/constants.h b/sdm/include/utils/constants.h
index 75f845b..b68604d 100644
--- a/sdm/include/utils/constants.h
+++ b/sdm/include/utils/constants.h
@@ -26,6 +26,11 @@
 #define __CONSTANTS_H__
 
 #include <stdlib.h>
+#include <inttypes.h>
+
+#ifndef PRIu64
+#define PRIu64 "llu"
+#endif
 
 #define INT(exp) static_cast<int>(exp)
 #define FLOAT(exp) static_cast<float>(exp)
diff --git a/sdm/include/utils/debug.h b/sdm/include/utils/debug.h
index 7f9209e..478f623 100644
--- a/sdm/include/utils/debug.h
+++ b/sdm/include/utils/debug.h
@@ -59,7 +59,6 @@
     debug_.debug_handler_ = debug_handler;
   }
   static inline DebugHandler* Get() { return debug_.debug_handler_; }
-  static inline bool IsVirtualDriver() { return debug_.virtual_driver_; }
   static uint32_t GetSimulationFlag();
   static uint32_t GetHDMIResolution();
   static uint32_t GetIdleTimeoutMs();
@@ -81,11 +80,13 @@
     virtual void BeginTrace(const char */*class_name*/, const char */*function_name*/,
                             const char */*custom_string*/) { }
     virtual void EndTrace() { }
+    virtual DisplayError GetProperty(const char *property_name, int *value) {
+      return kErrorNotSupported;
+    }
   };
 
   DefaultDebugHandler default_debug_handler_;
   DebugHandler *debug_handler_;
-  bool virtual_driver_;
   static Debug debug_;
 };
 
diff --git a/sdm/include/utils/locker.h b/sdm/include/utils/locker.h
index 3bc92d3..bc24ad5 100644
--- a/sdm/include/utils/locker.h
+++ b/sdm/include/utils/locker.h
@@ -27,6 +27,7 @@
 
 #include <stdint.h>
 #include <pthread.h>
+#include <sys/time.h>
 
 #define SCOPE_LOCK(locker) Locker::ScopeLock lock(locker)
 #define SEQUENCE_ENTRY_SCOPE_LOCK(locker) Locker::SequenceEntryScopeLock lock(locker)
diff --git a/sdm/libs/core/dump_impl.h b/sdm/libs/core/dump_impl.h
index 123c568..68e7584 100644
--- a/sdm/libs/core/dump_impl.h
+++ b/sdm/libs/core/dump_impl.h
@@ -49,7 +49,7 @@
   static DumpImpl *dump_list_[kMaxDumpObjects];
   static uint32_t dump_count_;
 
-  friend DumpInterface;
+  friend class DumpInterface;
 };
 
 }  // namespace sdm
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index b905c31..4c6e5a5 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -31,6 +31,8 @@
 #include <ctype.h>
 #include <math.h>
 #include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -43,23 +45,12 @@
 
 #define __CLASS__ "HWDevice"
 
-#ifdef DISPLAY_CORE_VIRTUAL_DRIVER
-extern int virtual_ioctl(int fd, int cmd, ...);
-extern int virtual_open(const char *file_name, int access, ...);
-extern int virtual_close(int fd);
-extern int virtual_poll(struct pollfd *fds,  nfds_t num, int timeout);
-extern ssize_t virtual_pread(int fd, void *data, size_t count, off_t offset);
-extern ssize_t virtual_pwrite(int fd, const void *data, size_t count, off_t offset);
-extern FILE* virtual_fopen(const char *fname, const char *mode);
-extern int virtual_fclose(FILE* fileptr);
-extern ssize_t virtual_getline(char **lineptr, size_t *linelen, FILE *stream);
-#endif
-
 namespace sdm {
 
 HWDevice::HWDevice(BufferSyncHandler *buffer_sync_handler)
   : fb_node_index_(-1), fb_path_("/sys/devices/virtual/graphics/fb"), hotplug_enabled_(false),
     buffer_sync_handler_(buffer_sync_handler), synchronous_commit_(false) {
+#ifndef SDM_VIRTUAL_DRIVER
   // Pointer to actual driver interfaces.
   ioctl_ = ::ioctl;
   open_ = ::open;
@@ -70,20 +61,27 @@
   fopen_ = ::fopen;
   fclose_ = ::fclose;
   getline_ = ::getline;
+#else
+  // Point to virtual driver interfaces.
+  extern int virtual_ioctl(int fd, int cmd, ...);
+  extern int virtual_open(const char *file_name, int access, ...);
+  extern int virtual_close(int fd);
+  extern int virtual_poll(struct pollfd *fds,  nfds_t num, int timeout);
+  extern ssize_t virtual_pread(int fd, void *data, size_t count, off_t offset);
+  extern ssize_t virtual_pwrite(int fd, const void *data, size_t count, off_t offset);
+  extern FILE* virtual_fopen(const char *fname, const char *mode);
+  extern int virtual_fclose(FILE* fileptr);
+  extern ssize_t virtual_getline(char **lineptr, size_t *linelen, FILE *stream);
 
-#ifdef DISPLAY_CORE_VIRTUAL_DRIVER
-  // If debug property to use virtual driver is set, point to virtual driver interfaces.
-  if (Debug::IsVirtualDriver()) {
-    ioctl_ = virtual_ioctl;
-    open_ = virtual_open;
-    close_ = virtual_close;
-    poll_ = virtual_poll;
-    pread_ = virtual_pread;
-    pwrite_ = virtual_pwrite;
-    fopen_ = virtual_fopen;
-    fclose_ = virtual_fclose;
-    getline_ = virtual_getline;
-  }
+  ioctl_ = virtual_ioctl;
+  open_ = virtual_open;
+  close_ = virtual_close;
+  poll_ = virtual_poll;
+  pread_ = virtual_pread;
+  pwrite_ = virtual_pwrite;
+  fopen_ = virtual_fopen;
+  fclose_ = virtual_fclose;
+  getline_ = virtual_getline;
 #endif
 }
 
diff --git a/sdm/libs/core/fb/hw_hdmi.cpp b/sdm/libs/core/fb/hw_hdmi.cpp
index 1a5c538..3abda13 100644
--- a/sdm/libs/core/fb/hw_hdmi.cpp
+++ b/sdm/libs/core/fb/hw_hdmi.cpp
@@ -27,6 +27,8 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <unistd.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <ctype.h>
 #include <utils/debug.h>
@@ -382,7 +384,7 @@
 void HWHDMI::ReadScanInfo() {
   int scan_info_file = -1;
   ssize_t len = -1;
-  char data[PAGE_SIZE] = {'\0'};
+  char data[4096] = {'\0'};
 
   snprintf(data, sizeof(data), "%s%d/scan_info", fb_path_, fb_node_index_);
   scan_info_file = open_(data, O_RDONLY);
diff --git a/sdm/libs/core/fb/hw_info.cpp b/sdm/libs/core/fb/hw_info.cpp
index b998a46..2b8a49d 100644
--- a/sdm/libs/core/fb/hw_info.cpp
+++ b/sdm/libs/core/fb/hw_info.cpp
@@ -23,6 +23,7 @@
 */
 
 #include "hw_info.h"
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
diff --git a/sdm/libs/core/fb/hw_info.h b/sdm/libs/core/fb/hw_info.h
index 95f669f..350c6ff 100644
--- a/sdm/libs/core/fb/hw_info.h
+++ b/sdm/libs/core/fb/hw_info.h
@@ -25,7 +25,6 @@
 #ifndef __HW_INFO_H__
 #define __HW_INFO_H__
 
-#include <inttypes.h>
 #include <core/sdm_types.h>
 #include <private/hw_info_types.h>
 #include "hw_info_interface.h"
diff --git a/sdm/libs/core/fb/hw_primary.cpp b/sdm/libs/core/fb/hw_primary.cpp
index cb4d8b2..4d1dad1 100644
--- a/sdm/libs/core/fb/hw_primary.cpp
+++ b/sdm/libs/core/fb/hw_primary.cpp
@@ -27,11 +27,14 @@
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+#include <fcntl.h>
 #include <sys/prctl.h>
 #include <sys/ioctl.h>
-#include <pthread.h>
+#include <sys/time.h>
 #include <sys/resource.h>
-#include <fcntl.h>
 #include <utils/debug.h>
 #include "hw_primary.h"
 
diff --git a/sdm/libs/hwc/hwc_debugger.cpp b/sdm/libs/hwc/hwc_debugger.cpp
index ab9309e..6cbce3e 100644
--- a/sdm/libs/hwc/hwc_debugger.cpp
+++ b/sdm/libs/hwc/hwc_debugger.cpp
@@ -28,6 +28,7 @@
 */
 
 #include <utils/constants.h>
+#include <cutils/properties.h>
 
 #include "hwc_debugger.h"
 
@@ -123,5 +124,16 @@
   atrace_end(ATRACE_TAG);
 }
 
+DisplayError HWCDebugHandler::GetProperty(const char *property_name, int *value) {
+  char property[PROPERTY_VALUE_MAX];
+
+  if (property_get(property_name, property, NULL) > 0) {
+    *value = atoi(property);
+    return kErrorNone;
+  }
+
+  return kErrorNotSupported;
+}
+
 }  // namespace sdm
 
diff --git a/sdm/libs/hwc/hwc_debugger.h b/sdm/libs/hwc/hwc_debugger.h
index 61a1b6f..480db22 100644
--- a/sdm/libs/hwc/hwc_debugger.h
+++ b/sdm/libs/hwc/hwc_debugger.h
@@ -68,6 +68,7 @@
   virtual void BeginTrace(const char *class_name, const char *function_name,
                           const char *custom_string);
   virtual void EndTrace();
+  virtual DisplayError GetProperty(const char *property_name, int *value);
 
  private:
   static HWCDebugHandler debug_handler_;
diff --git a/sdm/libs/utils/Android.mk b/sdm/libs/utils/Android.mk
index 57c2088..9de5c07 100644
--- a/sdm/libs/utils/Android.mk
+++ b/sdm/libs/utils/Android.mk
@@ -7,7 +7,6 @@
 LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
                                  -Wconversion -Wall -Werror \
                                  -DLOG_TAG=\"SDM\"
-LOCAL_SHARED_LIBRARIES        := libcutils
-LOCAL_SRC_FILES               := debug_android.cpp rect.cpp
+LOCAL_SRC_FILES               := debug.cpp rect.cpp
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/sdm/libs/utils/debug.cpp b/sdm/libs/utils/debug.cpp
new file mode 100644
index 0000000..cce8174
--- /dev/null
+++ b/sdm/libs/utils/debug.cpp
@@ -0,0 +1,84 @@
+/*
+* Copyright (c) 2014 - 2015, 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:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above
+*       copyright notice, this list of conditions and the following
+*       disclaimer in the documentation and/or other materials provided
+*       with the distribution.
+*     * Neither the name of The Linux Foundation nor the names of its
+*       contributors may be used to endorse or promote products derived
+*       from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdlib.h>
+#include <utils/debug.h>
+#include <utils/constants.h>
+
+namespace sdm {
+
+Debug Debug::debug_;
+
+Debug::Debug() : debug_handler_(&default_debug_handler_) {
+}
+
+uint32_t Debug::GetSimulationFlag() {
+  int value = 0;
+  debug_.debug_handler_->GetProperty("debug.hwc.simulate", &value);
+
+  return value;
+}
+
+uint32_t Debug::GetHDMIResolution() {
+  int value = 0;
+  debug_.debug_handler_->GetProperty("hw.hdmi.resolution", &value);
+
+  return value;
+}
+
+uint32_t Debug::GetIdleTimeoutMs() {
+  int value = IDLE_TIMEOUT_DEFAULT_MS;
+  debug_.debug_handler_->GetProperty("debug.mdpcomp.idletime", &value);
+
+  return value;
+}
+
+bool Debug::IsRotatorDownScaleDisabled() {
+  int value = 0;
+  debug_.debug_handler_->GetProperty("sdm.disable_rotator_downscaling", &value);
+
+  return (value == 1);
+}
+
+bool Debug::IsDecimationDisabled() {
+  int value = 0;
+  debug_.debug_handler_->GetProperty("sdm.disable_decimation", &value);
+
+  return (value == 1);
+}
+
+bool Debug::IsPartialUpdateEnabled() {
+  int value = 0;
+  debug_.debug_handler_->GetProperty("sdm.hwc.partial_update", &value);
+
+  return (value == 1);
+}
+
+}  // namespace sdm
+
diff --git a/sdm/libs/utils/debug_android.cpp b/sdm/libs/utils/debug_android.cpp
deleted file mode 100644
index f57d04d..0000000
--- a/sdm/libs/utils/debug_android.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
-* Copyright (c) 2014 - 2015, 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:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above
-*       copyright notice, this list of conditions and the following
-*       disclaimer in the documentation and/or other materials provided
-*       with the distribution.
-*     * Neither the name of The Linux Foundation nor the names of its
-*       contributors may be used to endorse or promote products derived
-*       from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include <stdlib.h>
-#include <utils/debug.h>
-#include <utils/constants.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-namespace sdm {
-
-Debug Debug::debug_;
-
-Debug::Debug() : debug_handler_(&default_debug_handler_), virtual_driver_(false) {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("displaycore.virtualdriver", property, NULL) > 0) {
-    virtual_driver_ = (atoi(property) == 1);
-  }
-}
-
-uint32_t Debug::GetSimulationFlag() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("debug.hwc.simulate", property, NULL) > 0) {
-    return atoi(property);
-  }
-
-  return 0;
-}
-
-uint32_t Debug::GetHDMIResolution() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("hw.hdmi.resolution", property, NULL) > 0) {
-    return atoi(property);
-  }
-
-  return 0;
-}
-
-uint32_t Debug::GetIdleTimeoutMs() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("debug.mdpcomp.idletime", property, NULL) > 0) {
-    return atoi(property);
-  }
-
-  return IDLE_TIMEOUT_DEFAULT_MS;
-}
-
-bool Debug::IsRotatorDownScaleDisabled() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("sdm.disable_rotator_downscaling", property, NULL) > 0) {
-    return (atoi(property) ? 0 : false, true);
-  }
-
-  return false;
-}
-
-bool Debug::IsDecimationDisabled() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("sdm.disable_decimation", property, NULL) > 0) {
-    return (atoi(property) ? 0 : false, true);
-  }
-
-  return false;
-}
-
-// This property serves to disable/enable partial update
-bool Debug::IsPartialUpdateEnabled() {
-  char property[PROPERTY_VALUE_MAX];
-  if (property_get("sdm.hwc.partial_update", property, NULL) > 0) {
-    return (atoi(property) ? 1 : true, false);
-  }
-
-  return false;
-}
-
-}  // namespace sdm
-