Snap for 5044688 from 50b092aa40692512c67823ee142efa52f59fd945 to pi-qpr2-release

Change-Id: I2574b386c7c753e672be78b0f48431bf083c0315
diff --git a/Makefile b/Makefile
index 54a1a19..fc24e67 100644
--- a/Makefile
+++ b/Makefile
@@ -81,6 +81,8 @@
 include $(CHRE_PREFIX)/build/variant/google_hexagonv60_slpi.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv62_slpi.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv62_slpi-uimg.mk
+include $(CHRE_PREFIX)/build/variant/google_hexagonv65_adsp-see.mk
+include $(CHRE_PREFIX)/build/variant/google_hexagonv65_adsp-see-uimg.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv65_slpi-see.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv65_slpi-see-uimg.mk
 include $(CHRE_PREFIX)/build/variant/google_x86_linux.mk
diff --git a/build/arch/hexagon.mk b/build/arch/hexagon.mk
index ea35293..cc39488 100644
--- a/build/arch/hexagon.mk
+++ b/build/arch/hexagon.mk
@@ -29,7 +29,7 @@
 # Hexagon Compiler Flags #######################################################
 
 # Define CUST_H to allow including the customer header file.
-TARGET_CFLAGS += -DCUST_H
+TARGET_CFLAGS += -DCUST_H='"custaaaaaaaaq.h"'
 
 # Add Hexagon compiler flags
 TARGET_CFLAGS += $(HEXAGON_CFLAGS)
diff --git a/build/build_template.mk b/build/build_template.mk
index aab0238..9c7bbb7 100644
--- a/build/build_template.mk
+++ b/build/build_template.mk
@@ -255,8 +255,10 @@
 
 # Template Invocation ##########################################################
 
+TARGET_CFLAGS_LOCAL = $(TARGET_CFLAGS)
+TARGET_CFLAGS_LOCAL += -DCHRE_PLATFORM_ID=$(TARGET_PLATFORM_ID)
 $(eval $(call BUILD_TEMPLATE, $(TARGET_NAME), \
-                              $(COMMON_CFLAGS) $(TARGET_CFLAGS), \
+                              $(COMMON_CFLAGS) $(TARGET_CFLAGS_LOCAL), \
                               $(TARGET_CC), \
                               $(TARGET_SO_LDFLAGS), \
                               $(TARGET_LD), \
@@ -273,7 +275,7 @@
 
 $(eval $(call BUILD_TEMPLATE, $(TARGET_NAME)_debug, \
                               $(COMMON_CFLAGS) $(COMMON_DEBUG_CFLAGS) \
-                                  $(TARGET_CFLAGS) $(TARGET_DEBUG_CFLAGS), \
+                                  $(TARGET_CFLAGS_LOCAL) $(TARGET_DEBUG_CFLAGS), \
                               $(TARGET_CC), \
                               $(TARGET_SO_LDFLAGS), \
                               $(TARGET_LD), \
diff --git a/build/nanoapp/app.mk b/build/nanoapp/app.mk
index 1ac1041..3d0526b 100644
--- a/build/nanoapp/app.mk
+++ b/build/nanoapp/app.mk
@@ -88,6 +88,8 @@
 GOOGLE_HEXAGONV60_SLPI_SRCS += $(DSO_SUPPORT_LIB_SRCS)
 GOOGLE_HEXAGONV62_SLPI_SRCS += $(DSO_SUPPORT_LIB_SRCS)
 GOOGLE_HEXAGONV62_SLPI-UIMG_SRCS += $(DSO_SUPPORT_LIB_SRCS)
+GOOGLE_HEXAGONV65_ADSP-SEE_SRCS += $(DSO_SUPPORT_LIB_SRCS)
+GOOGLE_HEXAGONV65_ADSP-SEE-UIMG_SRCS += $(DSO_SUPPORT_LIB_SRCS)
 GOOGLE_HEXAGONV65_SLPI-SEE_SRCS += $(DSO_SUPPORT_LIB_SRCS)
 GOOGLE_HEXAGONV65_SLPI-SEE-UIMG_SRCS += $(DSO_SUPPORT_LIB_SRCS)
 GOOGLE_ARM64_ANDROID_SRCS += $(DSO_SUPPORT_LIB_SRCS)
@@ -111,6 +113,8 @@
 include $(CHRE_PREFIX)/build/variant/google_hexagonv60_slpi.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv62_slpi.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv62_slpi-uimg.mk
+include $(CHRE_PREFIX)/build/variant/google_hexagonv65_adsp-see.mk
+include $(CHRE_PREFIX)/build/variant/google_hexagonv65_adsp-see-uimg.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv65_slpi-see.mk
 include $(CHRE_PREFIX)/build/variant/google_hexagonv65_slpi-see-uimg.mk
 include $(CHRE_PREFIX)/build/variant/google_x86_linux.mk
diff --git a/build/variant/google_hexagonv65_adsp-see-uimg.mk b/build/variant/google_hexagonv65_adsp-see-uimg.mk
new file mode 100644
index 0000000..b823f30
--- /dev/null
+++ b/build/variant/google_hexagonv65_adsp-see-uimg.mk
@@ -0,0 +1,41 @@
+#
+# Google CHRE Reference Implementation for Hexagon v65 Architecture on ADSP
+#
+
+include $(CHRE_PREFIX)/build/clean_build_template_args.mk
+
+TARGET_NAME = google_hexagonv65_adsp-see-uimg
+# Sized based on the buffer allocated in the host daemon (4096 bytes), minus
+# FlatBuffer overhead (max 80 bytes), minus some extra space to make a nice
+# round number and allow for addition of new fields to the FlatBuffer
+TARGET_CFLAGS = -DCHRE_MESSAGE_TO_HOST_MAX_SIZE=4000
+TARGET_CFLAGS += -DUIMG_DL_VER_MAJOR=2
+TARGET_CFLAGS += -DCHRE_ADSP_UIMG_ENABLED
+TARGET_CFLAGS += $(GOOGLE_HEXAGONV65_ADSP-SEE-UIMG_CFLAGS)
+TARGET_VARIANT_SRCS = $(GOOGLE_HEXAGONV65_ADSP-SEE-UIMG_SRCS)
+TARGET_SO_LATE_LIBS = $(GOOGLE_HEXAGONV65_ADSP-SEE-UIMG_LATE_LIBS)
+TARGET_PLATFORM_ID = 0x476f6f676c000006
+HEXAGON_ARCH = v65
+
+TARGET_CFLAGS += $(SLPI_CFLAGS)
+TARGET_VARIANT_SRCS += $(SLPI_SRCS)
+
+# Add SLPI/SEE-specific compiler flags and source files
+TARGET_CFLAGS += $(SLPI_SEE_CFLAGS)
+TARGET_CFLAGS += $(SLPI_SEE_QSK_CFLAGS)
+TARGET_VARIANT_SRCS += $(SLPI_SEE_SRCS)
+TARGET_VARIANT_SRCS += $(SLPI_SEE_QSK_SRCS)
+
+# Enable uImage support.
+TARGET_VARIANT_SRCS += $(SYS_SUPPORT_PATH)/qcom/uimg_dl_ver.c
+TARGET_SO_LDFLAGS += --script=$(SYS_SUPPORT_PATH)/qcom/uimage_v2.lcs
+
+ifneq ($(filter $(TARGET_NAME)% all, $(MAKECMDGOALS)),)
+ifneq ($(IS_NANOAPP_BUILD),)
+TARGET_SO_LATE_LIBS += $(CHRE_PREFIX)/build/app_support/google_slpi/libchre_slpi_skel.so
+include $(CHRE_PREFIX)/build/nanoapp/google_slpi.mk
+endif
+
+include $(CHRE_PREFIX)/build/arch/hexagon.mk
+include $(CHRE_PREFIX)/build/build_template.mk
+endif
diff --git a/build/variant/google_hexagonv65_adsp-see.mk b/build/variant/google_hexagonv65_adsp-see.mk
new file mode 100644
index 0000000..78f18ad
--- /dev/null
+++ b/build/variant/google_hexagonv65_adsp-see.mk
@@ -0,0 +1,35 @@
+#
+# Google CHRE Reference Implementation for Hexagon v65 Architecture on ADSP
+#
+
+include $(CHRE_PREFIX)/build/clean_build_template_args.mk
+
+TARGET_NAME = google_hexagonv65_adsp-see
+# Sized based on the buffer allocated in the host daemon (4096 bytes), minus
+# FlatBuffer overhead (max 80 bytes), minus some extra space to make a nice
+# round number and allow for addition of new fields to the FlatBuffer
+TARGET_CFLAGS = -DCHRE_MESSAGE_TO_HOST_MAX_SIZE=4000
+TARGET_CFLAGS += $(GOOGLE_HEXAGONV65_ADSP-SEE_CFLAGS)
+TARGET_VARIANT_SRCS = $(GOOGLE_HEXAGONV65_ADSP-SEE_SRCS)
+TARGET_SO_LATE_LIBS = $(GOOGLE_HEXAGONV65_ADSP-SEE_LATE_LIBS)
+TARGET_PLATFORM_ID = 0x476f6f676c000006
+HEXAGON_ARCH = v65
+
+TARGET_CFLAGS += $(SLPI_CFLAGS)
+TARGET_VARIANT_SRCS += $(SLPI_SRCS)
+
+# Add SLPI/SEE-specific compiler flags and source files
+TARGET_CFLAGS += $(SLPI_SEE_CFLAGS)
+TARGET_CFLAGS += $(SLPI_SEE_QMI_CFLAGS)
+TARGET_VARIANT_SRCS += $(SLPI_SEE_SRCS)
+TARGET_VARIANT_SRCS += $(SLPI_SEE_QMI_SRCS)
+
+ifneq ($(filter $(TARGET_NAME)% all, $(MAKECMDGOALS)),)
+ifneq ($(IS_NANOAPP_BUILD),)
+TARGET_SO_LATE_LIBS += $(CHRE_PREFIX)/build/app_support/google_slpi/libchre_slpi_skel.so
+include $(CHRE_PREFIX)/build/nanoapp/google_slpi.mk
+endif
+
+include $(CHRE_PREFIX)/build/arch/hexagon.mk
+include $(CHRE_PREFIX)/build/build_template.mk
+endif
diff --git a/build/variant/google_hexagonv65_slpi-see.mk b/build/variant/google_hexagonv65_slpi-see.mk
index 979a29f..a8bca40 100644
--- a/build/variant/google_hexagonv65_slpi-see.mk
+++ b/build/variant/google_hexagonv65_slpi-see.mk
@@ -20,9 +20,9 @@
 
 # Add SLPI/SEE-specific compiler flags and source files
 TARGET_CFLAGS += $(SLPI_SEE_CFLAGS)
-TARGET_CFLAGS += $(SLPI_SEE_QSK_CFLAGS)
+TARGET_CFLAGS += $(SLPI_SEE_QMI_CFLAGS)
 TARGET_VARIANT_SRCS += $(SLPI_SEE_SRCS)
-TARGET_VARIANT_SRCS += $(SLPI_SEE_QSK_SRCS)
+TARGET_VARIANT_SRCS += $(SLPI_SEE_QMI_SRCS)
 
 ifneq ($(filter $(TARGET_NAME)% all, $(MAKECMDGOALS)),)
 ifneq ($(IS_NANOAPP_BUILD),)
diff --git a/host/msm/daemon/chre_daemon.cc b/host/msm/daemon/chre_daemon.cc
index f2f2921..462e654 100644
--- a/host/msm/daemon/chre_daemon.cc
+++ b/host/msm/daemon/chre_daemon.cc
@@ -61,6 +61,12 @@
 
 #include <utils/SystemClock.h>
 
+#ifdef ADSPRPC
+#include "remote.h"
+
+#define ITRANSPORT_PREFIX "'\":;./\\"
+#endif  // ADSPRPC
+
 //! The format string to use for logs from the CHRE implementation.
 #define HUB_LOG_FORMAT_STR "Hub (t=%.6f): %s"
 
@@ -696,6 +702,17 @@
   struct reverse_monitor_thread_data reverse_monitor;
   ::android::chre::SocketServer server;
 
+#ifdef ADSPRPC
+  remote_handle remote_handle_fd = 0xFFFFFFFF;
+  LOGD("Attaching to ADSP sensors PD");
+  if (remote_handle_open(ITRANSPORT_PREFIX "createstaticpd:sensorspd",
+                         &remote_handle_fd)) {
+    LOGE("Failed to open remote handle for sensorspd");
+  } else {
+    LOGV("Successfully opened remote handle for sensorspd");
+  }
+#endif  // ADSPRPC
+
 #ifdef CHRE_DAEMON_LPMA_ENABLED
   initWakeLockFds();
 #endif  // CHRE_DAEMON_LPMA_ENABLED
diff --git a/platform/include/chre/platform/platform_id.h b/platform/include/chre/platform/platform_id.h
deleted file mode 100644
index c4c7ce8..0000000
--- a/platform/include/chre/platform/platform_id.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file
- * Provides platform IDs and versions for implementations of CHRE.
- */
-
-#ifndef CHRE_PLATFORM_PLATFORM_ID_H_
-#define CHRE_PLATFORM_PLATFORM_ID_H_
-
-#include "chre/util/id_from_string.h"
-
-#include <stdint.h>
-
-namespace chre {
-
-//! The vendor ID for Google.
-constexpr uint64_t kVendorIdGoogle = createIdFromString("Googl");
-
-//! The vendor platform ID of the Linux variant is one. All other
-//  Google implementations will be greater than one. Zero is reserved.
-constexpr uint32_t kGoogleLinuxPlatformId = 0x001;
-
-//! The vendor platform ID of the Qualcomm SLPI variant.
-constexpr uint32_t kGoogleSlpiPlatformId = 0x002;
-
-//! Patch level of the current CHRE implementation, defined by the build system
-//! and reported in chreGetVersion().
-constexpr uint16_t kPatchVersion = CHRE_PATCH_VERSION;
-static_assert(CHRE_PATCH_VERSION <= UINT16_MAX,
-              "Patch version must fit in 16 bits");
-
-}  // namespace chre
-
-#include "chre/target_platform/platform_id_impl.h"
-
-#endif  // CHRE_PLATFORM_PLATFORM_ID_H_
diff --git a/platform/linux/include/chre/target_platform/platform_id_impl.h b/platform/linux/include/chre/target_platform/platform_id_impl.h
deleted file mode 100644
index cb7e7cd..0000000
--- a/platform/linux/include/chre/target_platform/platform_id_impl.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CHRE_PLATFORM_LINUX_PLATFORM_ID_IMPL_H_
-#define CHRE_PLATFORM_LINUX_PLATFORM_ID_IMPL_H_
-
-#include "chre/platform/platform_id.h"
-
-namespace chre {
-
-//! The vendor ID of the Google-provided SLPI platform.
-constexpr uint64_t kVendorId = kVendorIdGoogle;
-
-//! The platform ID of the Google-provided SLPI platform.
-constexpr uint32_t kPlatformId = kGoogleLinuxPlatformId;
-
-}  // namespace chre
-
-#endif  // CHRE_PLATFORM_LINUX_PLATFORM_ID_IMPL_H_
diff --git a/platform/shared/chre_api_version.cc b/platform/shared/chre_api_version.cc
index 83cfe5e..d39704a 100644
--- a/platform/shared/chre_api_version.cc
+++ b/platform/shared/chre_api_version.cc
@@ -16,18 +16,25 @@
 
 #include "chre_api/chre/version.h"
 
-#include "chre/platform/platform_id.h"
 #include "chre/util/macros.h"
 
+static_assert(CHRE_API_VERSION <= UINT32_MAX,
+              "API version must fit in 32 bits");
+
+static_assert(CHRE_PATCH_VERSION <= UINT16_MAX,
+              "Patch version must fit in 16 bits");
+
+static_assert(CHRE_PLATFORM_ID <= UINT64_MAX,
+              "Platform ID must fit in 64 bits");
+
 DLL_EXPORT uint32_t chreGetApiVersion(void) {
   return CHRE_API_VERSION;
 }
 
 DLL_EXPORT uint32_t chreGetVersion(void) {
-  return chreGetApiVersion() | chre::kPatchVersion;
+  return chreGetApiVersion() | CHRE_PATCH_VERSION;
 }
 
 DLL_EXPORT uint64_t chreGetPlatformId(void) {
-  return chre::createPlatformIdFromVendorPlatform(chre::kVendorId,
-                                                  chre::kPlatformId);
+  return CHRE_PLATFORM_ID;
 }
diff --git a/platform/slpi/include/chre/target_platform/platform_id_impl.h b/platform/slpi/include/chre/target_platform/platform_id_impl.h
deleted file mode 100644
index 55d0d52..0000000
--- a/platform/slpi/include/chre/target_platform/platform_id_impl.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CHRE_PLATFORM_SLPI_PLATFORM_ID_IMPL_H_
-#define CHRE_PLATFORM_SLPI_PLATFORM_ID_IMPL_H_
-
-#include "chre/platform/platform_id.h"
-
-namespace chre {
-
-//! The vendor ID of the Google-provided SLPI platform.
-constexpr uint64_t kVendorId = kVendorIdGoogle;
-
-//! The platform ID of the Google-provided SLPI platform.
-constexpr uint32_t kPlatformId = kGoogleSlpiPlatformId;
-
-}  // namespace chre
-
-#endif  // CHRE_PLATFORM_SLPI_PLATFORM_ID_IMPL_H_
diff --git a/util/include/chre/util/id_from_string.h b/util/include/chre/util/id_from_string.h
deleted file mode 100644
index 5529cd6..0000000
--- a/util/include/chre/util/id_from_string.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CHRE_UTIL_ID_FROM_STRING_H_
-#define CHRE_UTIL_ID_FROM_STRING_H_
-
-namespace chre {
-
-/**
- * Formats a string into a CHRE platform version uint64_t.
- *
- * @param str the string to format
- * @return the formatted platform version id
- */
-constexpr uint64_t createIdFromString(const char str[5]);
-
-/**
- * Formats a vendor ID and platform ID into one platform ID value. This function
- * does not handle bit shifting. It is expected that the vendor ID be in the
- * correct position as created by the  createIdFromString function.
- *
- * @param vendorId The vendor ID of the platform.
- * @param platformId The platform ID of the platform.
- */
-constexpr uint64_t createPlatformIdFromVendorPlatform(uint64_t vendorId,
-                                                      uint32_t platformId);
-
-}  // namespace chre
-
-#include "chre/util/id_from_string_impl.h"
-
-#endif  // CHRE_UTIL_ID_FROM_STRING_H_
diff --git a/util/include/chre/util/id_from_string_impl.h b/util/include/chre/util/id_from_string_impl.h
deleted file mode 100644
index 9fdfe04..0000000
--- a/util/include/chre/util/id_from_string_impl.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CHRE_UTIL_ID_FROM_STRING_IMPL_H_
-#define CHRE_UTIL_ID_FROM_STRING_IMPL_H_
-
-#include "chre/util/id_from_string.h"
-
-namespace chre {
-
-constexpr uint64_t createIdFromString(const char str[5]) {
-  return (static_cast<uint64_t>(str[0]) << 56)
-      | (static_cast<uint64_t>(str[1]) << 48)
-      | (static_cast<uint64_t>(str[2]) << 40)
-      | (static_cast<uint64_t>(str[3]) << 32)
-      | (static_cast<uint64_t>(str[4]) << 24);
-}
-
-constexpr uint64_t createPlatformIdFromVendorPlatform(uint64_t vendorId,
-                                                      uint32_t platformId) {
-  // Ensure that only the vendor ID can occupy the top 5 bytes and the
-  // platform ID can only occupy the bottom 3 bytes.
-  return (vendorId & 0xffffffffff000000) | (platformId & 0xffffff);
-}
-
-}  // namespace chre
-
-#endif  // CHRE_UTIL_ID_FROM_STRING_IMPL_H_