Merge "Remove unused BT_STACK_TEST_MODULE_ID" am: 5dd2b50699 am: 27bf3239fa
am: 14cab0e6c0

Change-Id: I3b727ffc25633034cc714b0a28a23da602d364ff
diff --git a/include/hardware/context_hub.h b/include/hardware/context_hub.h
index aaa4274..137cb3e 100644
--- a/include/hardware/context_hub.h
+++ b/include/hardware/context_hub.h
@@ -47,12 +47,13 @@
 /*****************************************************************************/
 
 #define CONTEXT_HUB_HEADER_MAJOR_VERSION          1
-#define CONTEXT_HUB_HEADER_MINOR_VERSION          0
+#define CONTEXT_HUB_HEADER_MINOR_VERSION          1
 #define CONTEXT_HUB_DEVICE_API_VERSION \
      HARDWARE_DEVICE_API_VERSION(CONTEXT_HUB_HEADER_MAJOR_VERSION, \
                                  CONTEXT_HUB_HEADER_MINOR_VERSION)
 
 #define CONTEXT_HUB_DEVICE_API_VERSION_1_0  HARDWARE_DEVICE_API_VERSION(1, 0)
+#define CONTEXT_HUB_DEVICE_API_VERSION_1_1  HARDWARE_DEVICE_API_VERSION(1, 1)
 
 /**
  * The id of this module
@@ -131,9 +132,17 @@
     uint32_t app_version;          // Version of the app
     uint32_t flags;                // Signed, encrypted
     uint64_t hw_hub_type;          // which hub type is this compiled for
-    uint32_t reserved[2];          // Should be all zeroes
-    uint8_t  custom_binary[0];     // start of custom binary data
-};
+
+    // The version of the CHRE API that this nanoapp was compiled against.
+    // If these values are both set to 0, then they must be interpreted the same
+    // as if major version were set to 1, and minor 0 (the first valid CHRE API
+    // version).
+    uint8_t target_chre_api_major_version;
+    uint8_t target_chre_api_minor_version;
+
+    uint8_t reserved[6];           // Should be all zeroes
+    uint8_t custom_binary[0];      // start of custom binary data
+} __attribute__((packed));
 
 struct hub_app_info {
     struct hub_app_name_t app_name;
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
index c9e851f..2f59f3a 100644
--- a/modules/audio_remote_submix/Android.mk
+++ b/modules/audio_remote_submix/Android.mk
@@ -25,10 +25,11 @@
 	frameworks/av/include/ \
 	frameworks/native/include/ \
 	$(call include-path-for, audio-utils)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio
+LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio_mono
 LOCAL_STATIC_LIBRARIES := libmedia_helper
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
+LOCAL_HEADER_LIBRARIES += libhardware_headers
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 6c538ce..5efcdcb 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -24,6 +24,7 @@
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/limits.h>
+#include <unistd.h>
 
 #include <cutils/compiler.h>
 #include <cutils/properties.h>
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index da0f6db..42b4e47 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -23,6 +23,7 @@
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SHARED_LIBRARIES := liblog libEGL
 LOCAL_SRC_FILES := hwcomposer.cpp
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_MODULE := hwcomposer.default
 LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\"
 LOCAL_MODULE_TAGS := optional
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
index cb12964..52b195f 100644
--- a/modules/input/evdev/Android.mk
+++ b/modules/input/evdev/Android.mk
@@ -45,7 +45,6 @@
 
 LOCAL_MODULE := input.evdev.default
 LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
 
 LOCAL_SRC_FILES := \
     EvdevModule.cpp
diff --git a/modules/nfc-nci/Android.bp b/modules/nfc-nci/Android.bp
index f4ef64e..f78b7c5 100644
--- a/modules/nfc-nci/Android.bp
+++ b/modules/nfc-nci/Android.bp
@@ -17,6 +17,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["nfc_nci_example.cpp"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/sensors/Android.bp b/modules/sensors/Android.bp
index 1d15065..1b5f26d 100644
--- a/modules/sensors/Android.bp
+++ b/modules/sensors/Android.bp
@@ -5,6 +5,9 @@
         "multihal.cpp",
         "SensorEventQueue.cpp"
     ],
+    header_libs: [
+        "libhardware_headers",
+    ],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index e5e0c9c..9942d39 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -32,6 +32,9 @@
     multihal.cpp \
     SensorEventQueue.cpp \
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
     libdl \
diff --git a/modules/sensors/dynamic_sensor/Android.mk b/modules/sensors/dynamic_sensor/Android.mk
index 348542a..52809dc 100644
--- a/modules/sensors/dynamic_sensor/Android.mk
+++ b/modules/sensors/dynamic_sensor/Android.mk
@@ -56,6 +56,10 @@
 
 LOCAL_SRC_FILES := $(dynamic_sensor_src)
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+    libstagefright_foundation_headers \
+
 LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
@@ -76,6 +80,10 @@
 
 LOCAL_SRC_FILES := $(dynamic_sensor_src) sensors.cpp
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+    libstagefright_foundation_headers \
+
 LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
diff --git a/modules/sensors/multihal.cpp b/modules/sensors/multihal.cpp
index 1cea7ae..b5360cc 100644
--- a/modules/sensors/multihal.cpp
+++ b/modules/sensors/multihal.cpp
@@ -49,10 +49,11 @@
 static pthread_cond_t data_available_cond = PTHREAD_COND_INITIALIZER;
 bool waiting_for_data = false;
 
-/*
- * Vector of sub modules, whose indexes are referred to in this file as module_index.
- */
-static std::vector<hw_module_t *> *sub_hw_modules = NULL;
+// Vector of sub modules, whose indexes are referred to in this file as module_index.
+static std::vector<hw_module_t *> *sub_hw_modules = nullptr;
+
+// Vector of sub modules shared object handles
+static std::vector<void *> *so_handles = nullptr;
 
 /*
  * Comparable class that globally identifies a sensor, by module index and local handle.
@@ -509,11 +510,26 @@
 
 
 static int device__close(struct hw_device_t *dev) {
+    pthread_mutex_lock(&init_modules_mutex);
     sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
     if (ctx != NULL) {
         int retval = ctx->close();
         delete ctx;
     }
+
+    if (sub_hw_modules != nullptr) {
+        delete sub_hw_modules;
+        sub_hw_modules = nullptr;
+    }
+
+    if (so_handles != nullptr) {
+        for (auto handle : *so_handles) {
+            dlclose(handle);
+        }
+        delete so_handles;
+        so_handles = nullptr;
+    }
+    pthread_mutex_unlock(&init_modules_mutex);
     return 0;
 }
 
@@ -583,7 +599,9 @@
  * Adds valid paths from the config file to the vector passed in.
  * The vector must not be null.
  */
-static void get_so_paths(std::vector<std::string> *so_paths) {
+static std::vector<std::string> get_so_paths() {
+    std::vector<std::string> so_paths;
+
     const std::vector<const char *> config_path_list(
             { MULTI_HAL_CONFIG_FILE_PATH, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH });
 
@@ -599,7 +617,7 @@
     }
     if(!stream) {
         ALOGW("No multihal config file found");
-        return;
+        return so_paths;
     }
 
     ALOGE_IF(strcmp(path, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH) == 0,
@@ -611,8 +629,9 @@
     std::string line;
     while (std::getline(stream, line)) {
         ALOGV("config file line: '%s'", line.c_str());
-        so_paths->push_back(line);
+        so_paths.push_back(line);
     }
+    return so_paths;
 }
 
 /*
@@ -625,15 +644,15 @@
         pthread_mutex_unlock(&init_modules_mutex);
         return;
     }
-    std::vector<std::string> *so_paths = new std::vector<std::string>();
-    get_so_paths(so_paths);
+    std::vector<std::string> so_paths(get_so_paths());
 
     // dlopen the module files and cache their module symbols in sub_hw_modules
     sub_hw_modules = new std::vector<hw_module_t *>();
+    so_handles = new std::vector<void *>();
     dlerror(); // clear any old errors
     const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
-    for (std::vector<std::string>::iterator it = so_paths->begin(); it != so_paths->end(); it++) {
-        const char* path = it->c_str();
+    for (const auto &s : so_paths) {
+        const char* path = s.c_str();
         void* lib_handle = dlopen(path, RTLD_LAZY);
         if (lib_handle == NULL) {
             ALOGW("dlerror(): %s", dlerror());
@@ -651,8 +670,13 @@
             } else {
                 ALOGV("Loaded symbols from \"%s\"", sym);
                 sub_hw_modules->push_back(module);
+                so_handles->push_back(lib_handle);
+                lib_handle = nullptr;
             }
         }
+        if (lib_handle != nullptr) {
+            dlclose(lib_handle);
+        }
     }
     pthread_mutex_unlock(&init_modules_mutex);
 }
diff --git a/modules/thermal/Android.mk b/modules/thermal/Android.mk
index ff51145..1ad55d8 100644
--- a/modules/thermal/Android.mk
+++ b/modules/thermal/Android.mk
@@ -20,7 +20,8 @@
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := thermal.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index b36bf9f..6c8a98f 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -29,5 +29,6 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
+LOCAL_HEADER_LIBRARIES += libhardware_headers
 include $(BUILD_SHARED_LIBRARY)