Merge "implemented enumerate method in fingerprintservice fixes bug 35358801 Test: ran enumeration in template with 1) more fingerprints in fingerprintd 2) more fingerprints in framework 3) no fingerprints in fingerprintd, but fingerprints in framework 4) no fingerprints in framework, but fingerprints in fingerprintd"
diff --git a/include/hardware/ble_advertiser.h b/include/hardware/ble_advertiser.h
index 45282aa..013e426 100644
--- a/include/hardware/ble_advertiser.h
+++ b/include/hardware/ble_advertiser.h
@@ -34,41 +34,71 @@
   uint8_t scan_request_notification_enable;
 };
 
+struct PeriodicAdvertisingParameters {
+  uint8_t enable;
+  uint16_t min_interval;
+  uint16_t max_interval;
+  uint16_t periodic_advertising_properties;
+};
+
 class BleAdvertiserInterface {
  public:
   virtual ~BleAdvertiserInterface() = default;
 
   /** Callback invoked when multi-adv operation has completed */
-  using Callback = base::Callback<void(uint8_t /* status */)>;
+  using StatusCallback = base::Callback<void(uint8_t /* status */)>;
+  using IdStatusCallback =
+      base::Callback<void(uint8_t /* advertiser_id */, uint8_t /* status */)>;
+  using IdTxPowerStatusCallback =
+      base::Callback<void(uint8_t /* advertiser_id */, int8_t /* tx_power */, uint8_t /* status */)>;
+  using ParametersCallback =
+      base::Callback<void(uint8_t /* status */, int8_t /* tx_power */)>;
 
   /** Registers an advertiser with the stack */
-  virtual void RegisterAdvertiser(
-      base::Callback<void(uint8_t /* advertiser_id */,
-                          uint8_t /* status */)>) = 0;
+  virtual void RegisterAdvertiser(IdStatusCallback) = 0;
 
   /* Set the parameters as per spec, user manual specified values */
-  virtual void SetParameters(
-      uint8_t advertiser_id, uint16_t advertising_event_properties,
-      uint32_t min_interval, uint32_t max_interval, int chnl_map, int tx_power,
-      uint8_t primary_advertising_phy, uint8_t secondary_advertising_phy,
-      uint8_t scan_request_notification_enable, Callback cb) = 0;
+  virtual void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
+                             ParametersCallback cb) = 0;
 
   /* Setup the data */
   virtual void SetData(int advertiser_id, bool set_scan_rsp,
-                       std::vector<uint8_t> data, Callback cb) = 0;
+                       std::vector<uint8_t> data, StatusCallback cb) = 0;
 
   /* Enable the advertising instance */
-  virtual void Enable(uint8_t advertiser_id, bool enable, Callback cb,
-                      int timeout_s, Callback timeout_cb) = 0;
+  virtual void Enable(uint8_t advertiser_id, bool enable, StatusCallback cb,
+                      int timeout_s, StatusCallback timeout_cb) = 0;
 
   /*  Unregisters an advertiser */
   virtual void Unregister(uint8_t advertiser_id) = 0;
 
-  virtual void StartAdvertising(uint8_t advertiser_id, Callback cb,
+  virtual void StartAdvertising(uint8_t advertiser_id, StatusCallback cb,
                                 AdvertiseParameters params,
                                 std::vector<uint8_t> advertise_data,
                                 std::vector<uint8_t> scan_response_data,
-                                int timeout_s, Callback timeout_cb) = 0;
+                                int timeout_s, StatusCallback timeout_cb) = 0;
+
+  /** Start the advertising set. This include registering, setting all
+   * parameters and data, and enabling it. |register_cb| is called when the set
+   * is advertising. |timeout_cb| is called when the timeout_s have passed */
+  virtual void StartAdvertisingSet(
+      IdTxPowerStatusCallback register_cb, AdvertiseParameters params,
+      std::vector<uint8_t> advertise_data,
+      std::vector<uint8_t> scan_response_data,
+      PeriodicAdvertisingParameters periodic_params,
+      std::vector<uint8_t> periodic_data, int timeout_s,
+      IdStatusCallback timeout_cb) = 0;
+
+  virtual void SetPeriodicAdvertisingParameters(
+      int advertiser_id, PeriodicAdvertisingParameters parameters,
+      StatusCallback cb) = 0;
+
+  virtual void SetPeriodicAdvertisingData(int advertiser_id,
+                                          std::vector<uint8_t> data,
+                                          StatusCallback cb) = 0;
+
+  virtual void SetPeriodicAdvertisingEnable(int advertiser_id, bool enable,
+                                            StatusCallback cb) = 0;
 };
 
 #endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */
diff --git a/include/hardware/ble_scanner.h b/include/hardware/ble_scanner.h
index 20b36fd..4ab0a77 100644
--- a/include/hardware/ble_scanner.h
+++ b/include/hardware/ble_scanner.h
@@ -23,13 +23,6 @@
 #include "bt_gatt_client.h"
 #include "bt_gatt_types.h"
 
-/** Callback invoked when batchscan storage config operation has completed */
-typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
-
-/** Callback invoked when batchscan enable / disable operation has completed */
-typedef void (*batchscan_enable_disable_callback)(int action, int client_if,
-                                                  int status);
-
 /** Callback invoked when batchscan reports are obtained */
 typedef void (*batchscan_reports_callback)(int client_if, int status,
                                            int report_format, int num_records,
@@ -42,37 +35,19 @@
 typedef void (*track_adv_event_callback)(
     btgatt_track_adv_info_t *p_track_adv_info);
 
-/** Callback invoked when scan parameter setup has completed */
-typedef void (*scan_parameter_setup_completed_callback)(int client_if,
-                                                        btgattc_error_t status);
-
 /** Callback for scan results */
-typedef void (*scan_result_callback)(bt_bdaddr_t *bda, int rssi,
+typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type,
+                                     bt_bdaddr_t *bda, uint8_t primary_phy,
+                                     uint8_t secondary_phy,
+                                     uint8_t advertising_sid, int8_t tx_power,
+                                     int8_t rssi, uint16_t periodic_adv_int,
                                      std::vector<uint8_t> adv_data);
 
-/** Callback invoked when a scan filter configuration command has completed */
-typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status,
-                                         int filt_type, int avbl_space);
-
-/** Callback invoked when scan param has been added, cleared, or deleted */
-typedef void (*scan_filter_param_callback)(int action, int client_if,
-                                           int status, int avbl_space);
-
-/** Callback invoked when a scan filter configuration command has completed */
-typedef void (*scan_filter_status_callback)(int enable, int client_if,
-                                            int status);
-
 typedef struct {
   scan_result_callback scan_result_cb;
-  batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
-  batchscan_enable_disable_callback batchscan_enb_disable_cb;
   batchscan_reports_callback batchscan_reports_cb;
   batchscan_threshold_callback batchscan_threshold_cb;
   track_adv_event_callback track_adv_event_cb;
-  scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb;
-  scan_filter_cfg_callback scan_filter_cfg_cb;
-  scan_filter_param_callback scan_filter_param_cb;
-  scan_filter_status_callback scan_filter_status_cb;
 } btgatt_scanner_callbacks_t;
 
 class BleScannerInterface {
@@ -82,6 +57,19 @@
   using RegisterCallback =
       base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>;
 
+  using Callback = base::Callback<void(uint8_t /* status */)>;
+
+  using EnableCallback =
+      base::Callback<void(uint8_t /* action */, uint8_t /* status */)>;
+
+  using FilterParamSetupCallback =
+      base::Callback<void(uint8_t /* avbl_space */, uint8_t /* action_type */,
+                          uint8_t /* status */)>;
+
+  using FilterConfigCallback =
+      base::Callback<void(uint8_t /* filt_type */, uint8_t /* avbl_space */,
+                          uint8_t /* action */, uint8_t /* status */)>;
+
   /** Registers a scanner with the stack */
   virtual void RegisterScanner(RegisterCallback) = 0;
 
@@ -94,39 +82,42 @@
   /** Setup scan filter params */
   virtual void ScanFilterParamSetup(
       uint8_t client_if, uint8_t action, uint8_t filt_index,
-      std::unique_ptr<btgatt_filt_param_setup_t> filt_param) = 0;
+      std::unique_ptr<btgatt_filt_param_setup_t> filt_param,
+      FilterParamSetupCallback cb) = 0;
 
   /** Configure a scan filter condition  */
-  virtual void ScanFilterAddRemove(int client_if, int action, int filt_type,
-                                   int filt_index, int company_id,
-                                   int company_id_mask, const bt_uuid_t *p_uuid,
+  virtual void ScanFilterAddRemove(int action, int filt_type, int filt_index,
+                                   int company_id, int company_id_mask,
+                                   const bt_uuid_t *p_uuid,
                                    const bt_uuid_t *p_uuid_mask,
                                    const bt_bdaddr_t *bd_addr, char addr_type,
                                    std::vector<uint8_t> data,
-                                   std::vector<uint8_t> p_mask) = 0;
+                                   std::vector<uint8_t> p_mask,
+                                   FilterConfigCallback cb) = 0;
 
   /** Clear all scan filter conditions for specific filter index*/
-  virtual void ScanFilterClear(int client_if, int filt_index) = 0;
+  virtual void ScanFilterClear(int filt_index, FilterConfigCallback cb) = 0;
 
   /** Enable / disable scan filter feature*/
-  virtual void ScanFilterEnable(int client_if, bool enable) = 0;
+  virtual void ScanFilterEnable(bool enable, EnableCallback cb) = 0;
 
   /** Sets the LE scan interval and window in units of N*0.625 msec */
-  virtual void SetScanParameters(int client_if, int scan_interval,
-                                 int scan_window) = 0;
+  virtual void SetScanParameters(int scan_interval, int scan_window,
+                                 Callback cb) = 0;
 
   /* Configure the batchscan storage */
   virtual void BatchscanConfigStorage(int client_if, int batch_scan_full_max,
                                       int batch_scan_trunc_max,
-                                      int batch_scan_notify_threshold) = 0;
+                                      int batch_scan_notify_threshold,
+                                      Callback cb) = 0;
 
   /* Enable batchscan */
-  virtual void BatchscanEnable(int client_if, int scan_mode, int scan_interval,
-                               int scan_window, int addr_type,
-                               int discard_rule) = 0;
+  virtual void BatchscanEnable(int scan_mode, int scan_interval,
+                               int scan_window, int addr_type, int discard_rule,
+                               Callback cb) = 0;
 
   /* Disable batchscan */
-  virtual void BatchscanDisable(int client_if) = 0;
+  virtual void BatchscanDisable(Callback cb) = 0;
 
   /* Read out batchscan reports */
   virtual void BatchscanReadReports(int client_if, int scan_mode) = 0;
diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h
index 9870913..5d69ab3 100644
--- a/include/hardware/bluetooth.h
+++ b/include/hardware/bluetooth.h
@@ -163,6 +163,11 @@
     uint16_t total_trackable_advertisers;
     bool extended_scan_support;
     bool debug_logging_supported;
+    bool le_2m_phy_supported;
+    bool le_coded_phy_supported;
+    bool le_extended_advertising_supported;
+    bool le_periodic_advertising_supported;
+    uint16_t le_maximum_advertising_data_length;
 }bt_local_le_features_t;
 
 /* Bluetooth Adapter and Remote Device property types */
diff --git a/include/hardware/bt_av.h b/include/hardware/bt_av.h
index 66a8643..91ae2ac 100644
--- a/include/hardware/bt_av.h
+++ b/include/hardware/bt_av.h
@@ -69,7 +69,15 @@
 } btav_a2dp_codec_index_t;
 
 typedef enum {
+  // Disable the codec.
+  // NOTE: This value can be used only during initialization when
+  // function btav_source_interface_t::init() is called.
+  BTAV_A2DP_CODEC_PRIORITY_DISABLED = -1,
+
+  // Reset the codec priority to its default value.
   BTAV_A2DP_CODEC_PRIORITY_DEFAULT = 0,
+
+  // Highest codec priority.
   BTAV_A2DP_CODEC_PRIORITY_HIGHEST = 1000 * 1000
 } btav_a2dp_codec_priority_t;
 
@@ -156,7 +164,7 @@
     btav_audio_source_config_callback audio_config_cb;
 } btav_source_callbacks_t;
 
-/** BT-AV A2DP Source callback structure. */
+/** BT-AV A2DP Sink callback structure. */
 typedef struct {
     /** set to sizeof(btav_sink_callbacks_t) */
     size_t      size;
@@ -183,9 +191,10 @@
     /** set to sizeof(btav_source_interface_t) */
     size_t          size;
     /**
-     * Register the BtAv callbacks
+     * Register the BtAv callbacks.
      */
-    bt_status_t (*init)( btav_source_callbacks_t* callbacks );
+    bt_status_t (*init)(btav_source_callbacks_t* callbacks,
+                std::vector<btav_a2dp_codec_config_t> codec_priorities);
 
     /** connect to headset */
     bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
diff --git a/include/hardware/camera3.h b/include/hardware/camera3.h
index a7df0ee..cec2ab3 100644
--- a/include/hardware/camera3.h
+++ b/include/hardware/camera3.h
@@ -1479,6 +1479,13 @@
      *      android.lens.opticalStabilizationMode (if it is supported)
      *      android.scaler.cropRegion
      *      android.statistics.faceDetectMode (if it is supported)
+     *   6. To reduce the amount of data passed across process boundaries at
+     *      high frame rate, within one batch, camera framework only propagates
+     *      the last shutter notify and the last capture results (including partial
+     *      results and final result) to the app. The shutter notifies and capture
+     *      results for the other requests in the batch are derived by
+     *      the camera framework. As a result, the HAL can return empty metadata
+     *      except for the last result in the batch.
      *
      * For more details about high speed stream requirements, see
      * android.control.availableHighSpeedVideoConfigurations and CONSTRAINED_HIGH_SPEED_VIDEO
@@ -1597,6 +1604,13 @@
      *   value of this is 0.
      *   For all streams passed via configure_streams(), the HAL must write
      *   over this field with its usage flags.
+     *
+     *   From Android O, the usage flag for an output stream may be bitwise
+     *   combination of usage flags for multiple consumers, for the purpose of
+     *   sharing one camera stream between those consumers. The HAL must fail
+     *   configure_streams call with -EINVAL if the combined flags cannot be
+     *   supported due to imcompatible buffer format, dataSpace, or other hardware
+     *   limitations.
      */
     uint32_t usage;
 
diff --git a/include/hardware/gnss-base.h b/include/hardware/gnss-base.h
index afeb834..e56020d 100644
--- a/include/hardware/gnss-base.h
+++ b/include/hardware/gnss-base.h
@@ -1,5 +1,6 @@
 // This file is autogenerated by hidl-gen. Do not edit manually.
 // Source: android.hardware.gnss@1.0
+// Root: android.hardware:hardware/interfaces
 
 #ifndef HIDL_GENERATED_ANDROID_HARDWARE_GNSS_V1_0_EXPORTED_CONSTANTS_H_
 #define HIDL_GENERATED_ANDROID_HARDWARE_GNSS_V1_0_EXPORTED_CONSTANTS_H_
@@ -27,7 +28,10 @@
     GPS_LOCATION_HAS_ALTITUDE = 2, // 0x0002
     GPS_LOCATION_HAS_SPEED = 4, // 0x0004
     GPS_LOCATION_HAS_BEARING = 8, // 0x0008
-    GPS_LOCATION_HAS_ACCURACY = 16, // 0x0010
+    GPS_LOCATION_HAS_HORIZONTAL_ACCURACY = 16, // 0x0010
+    GPS_LOCATION_HAS_VERTICAL_ACCURACY = 32, // 0x0020
+    GPS_LOCATION_HAS_SPEED_ACCURACY = 64, // 0x0040
+    GPS_LOCATION_HAS_BEARING_ACCURACY = 128, // 0x0080
 };
 
 enum {
@@ -132,6 +136,7 @@
     GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA = 1, // (1 << 0)
     GNSS_SV_FLAGS_HAS_ALMANAC_DATA = 2, // (1 << 1)
     GNSS_SV_FLAGS_USED_IN_FIX = 4, // (1 << 2)
+    GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY = 8, // (1 << 3)
 };
 
 enum {
@@ -176,6 +181,7 @@
     GNSS_MEASUREMENT_HAS_CARRIER_CYCLES = 1024u, // (1 << 10)
     GNSS_MEASUREMENT_HAS_CARRIER_PHASE = 2048u, // (1 << 11)
     GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY = 4096u, // (1 << 12)
+    GNSS_MEASUREMENT_HAS_AUTOMATIC_GAIN_CONTROL = 8192u, // (1 << 13)
 };
 
 enum {
@@ -200,6 +206,8 @@
     GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK = 2048u, // (1 << 11)
     GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC = 4096u, // (1 << 12)
     GNSS_MEASUREMENT_STATE_SBAS_SYNC = 8192u, // (1 << 13)
+    GNSS_MEASUREMENT_STATE_TOW_KNOWN = 16384u, // (1 << 14)
+    GNSS_MEASUREMENT_STATE_GLO_TOD_KNOWN = 32768u, // (1 << 15)
 };
 
 enum {
diff --git a/include/hardware/gps.h b/include/hardware/gps.h
index 2f719ce..4e108b3 100644
--- a/include/hardware/gps.h
+++ b/include/hardware/gps.h
@@ -60,6 +60,7 @@
 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L2CNAV GNSS_NAVIGATION_MESSAGE_TYPE_GNSS_L2CNAV
 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_L5CNAV GNSS_NAVIGATION_MESSAGE_TYPE_GNSS_L5CNAV
 #define GNSS_NAVIGATION_MESSAGE_TYPE_GPS_CNAV2 GNSS_NAVIGATION_MESSAGE_TYPE_GNSS_CNAV2
+#define GPS_LOCATION_HAS_ACCURACY GPS_LOCATION_HAS_HORIZONTAL_ACCURACY
 
 /**
  * The id of this module
diff --git a/include/hardware/keymaster_defs.h b/include/hardware/keymaster_defs.h
index 5800019..7d1b348 100644
--- a/include/hardware/keymaster_defs.h
+++ b/include/hardware/keymaster_defs.h
@@ -150,6 +150,11 @@
                                                       included in attestation */
     KM_TAG_ATTESTATION_ID_MEID = KM_BYTES | 715,   /* Used to provide the device's MEID to be
                                                       included in attestation */
+    KM_TAG_ATTESTATION_ID_MANUFACTURER = KM_BYTES | 716, /* Used to provide the device's
+                                                            manufacturer name to be included in
+                                                            attestation */
+    KM_TAG_ATTESTATION_ID_MODEL = KM_BYTES | 717,  /* Used to provide the device's model name to be
+                                                      included in attestation */
 
     /* Tags used only to provide data to or receive data from operations */
     KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
@@ -291,7 +296,6 @@
     KM_PURPOSE_SIGN = 2,       /* Usable with RSA, EC and HMAC keys. */
     KM_PURPOSE_VERIFY = 3,     /* Usable with RSA, EC and HMAC keys. */
     KM_PURPOSE_DERIVE_KEY = 4, /* Usable with EC keys. */
-    KM_PURPOSE_WRAP_KEY = 5,   /* Usable with wrapping keys. */
 } keymaster_purpose_t;
 
 typedef struct {
diff --git a/include/hardware/nfc-base.h b/include/hardware/nfc-base.h
index c9ae962..6b63ad2 100644
--- a/include/hardware/nfc-base.h
+++ b/include/hardware/nfc-base.h
@@ -1,5 +1,6 @@
 // This file is autogenerated by hidl-gen. Do not edit manually.
 // Source: android.hardware.nfc@1.0
+// Root: android.hardware:hardware/interfaces
 
 #ifndef HIDL_GENERATED_ANDROID_HARDWARE_NFC_V1_0_EXPORTED_CONSTANTS_H_
 #define HIDL_GENERATED_ANDROID_HARDWARE_NFC_V1_0_EXPORTED_CONSTANTS_H_
diff --git a/include/hardware/sensors-base.h b/include/hardware/sensors-base.h
index 80ea3a7..b0f6223 100644
--- a/include/hardware/sensors-base.h
+++ b/include/hardware/sensors-base.h
@@ -1,5 +1,6 @@
 // This file is autogenerated by hidl-gen. Do not edit manually.
 // Source: android.hardware.sensors@1.0
+// Root: android.hardware:hardware/interfaces
 
 #ifndef HIDL_GENERATED_ANDROID_HARDWARE_SENSORS_V1_0_EXPORTED_CONSTANTS_H_
 #define HIDL_GENERATED_ANDROID_HARDWARE_SENSORS_V1_0_EXPORTED_CONSTANTS_H_
diff --git a/modules/Android.mk b/modules/Android.mk
index 2a58b3e..462081d 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,4 +1,14 @@
-hardware_modules := gralloc hwcomposer \
-	usbaudio audio_remote_submix camera usbcamera sensors \
-	input vehicle thermal vr
+hardware_modules := \
+    audio_remote_submix \
+    camera \
+    gralloc \
+    hwcomposer \
+    input \
+    radio \
+    sensors \
+    thermal \
+    usbaudio \
+    usbcamera \
+    vehicle \
+    vr
 include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/README.android b/modules/README.android
index 57abb72..7ffc0f4 100644
--- a/modules/README.android
+++ b/modules/README.android
@@ -4,13 +4,13 @@
 libhardware.so eventually should contain *just* the HAL hub
 (hardware.c), everything in it should be rewritten as modules.
 
-Modules are .so in /system/libs/hw/ and have a well defined naming
+Modules are .so in /vendor/lib/hw/ and have a well defined naming
 convention:
 
-    /system/libs/hw/<*_HARDWARE_MODULE_ID>.<ro.product.board>.so
-    /system/libs/hw/<*_HARDWARE_MODULE_ID>.<ro.board.platform>.so
-    /system/libs/hw/<*_HARDWARE_MODULE_ID>.<ro.arch>.so
-    /system/libs/hw/<*_HARDWARE_MODULE_ID>.default.so
+    /vendor/lib/hw/<*_HARDWARE_MODULE_ID>.<ro.product.board>.so
+    /vendor/lib/hw/<*_HARDWARE_MODULE_ID>.<ro.board.platform>.so
+    /vendor/lib/hw/<*_HARDWARE_MODULE_ID>.<ro.arch>.so
+    /vendor/lib/hw/<*_HARDWARE_MODULE_ID>.default.so
 
 They also have a well defined interface which lives in include/hardware/.
 
diff --git a/modules/audio/Android.bp b/modules/audio/Android.bp
index 69e99f9..bd23b03 100644
--- a/modules/audio/Android.bp
+++ b/modules/audio/Android.bp
@@ -21,6 +21,7 @@
 cc_library_shared {
     name: "audio.primary.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["audio_hw.c"],
     shared_libs: [
         "liblog",
@@ -38,6 +39,7 @@
 cc_library_shared {
     name: "audio.stub.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["audio_hw.c"],
     shared_libs: [
         "liblog",
@@ -51,6 +53,7 @@
 cc_library_shared {
     name: "audio_policy.stub",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["audio_policy.c"],
     shared_libs: [
         "liblog",
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
index d0c8ffc..c9e851f 100644
--- a/modules/audio_remote_submix/Android.mk
+++ b/modules/audio_remote_submix/Android.mk
@@ -18,6 +18,7 @@
 
 LOCAL_MODULE := audio.r_submix.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := \
 	audio_hw.cpp
 LOCAL_C_INCLUDES += \
diff --git a/modules/consumerir/Android.bp b/modules/consumerir/Android.bp
index bbce6b1..2bbdc04 100644
--- a/modules/consumerir/Android.bp
+++ b/modules/consumerir/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "consumerir.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["consumerir.c"],
     shared_libs: [
         "liblog",
diff --git a/modules/fingerprint/Android.bp b/modules/fingerprint/Android.bp
index a66f9f9..ba749e4 100644
--- a/modules/fingerprint/Android.bp
+++ b/modules/fingerprint/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "fingerprint.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["fingerprint.c"],
     shared_libs: ["liblog"],
 }
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
index 092e851..cdd8d07 100644
--- a/modules/gralloc/Android.mk
+++ b/modules/gralloc/Android.mk
@@ -20,6 +20,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SHARED_LIBRARIES := liblog libcutils
 
 LOCAL_SRC_FILES := 	\
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index 35c0fae..da0f6db 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -20,6 +20,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SHARED_LIBRARIES := liblog libEGL
 LOCAL_SRC_FILES := hwcomposer.cpp
 LOCAL_MODULE := hwcomposer.default
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
index 9a5d092..be4db6b 100644
--- a/modules/input/evdev/Android.mk
+++ b/modules/input/evdev/Android.mk
@@ -45,6 +45,7 @@
 
 LOCAL_MODULE := input.evdev.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 
 LOCAL_SRC_FILES := \
     EvdevModule.cpp
diff --git a/modules/local_time/Android.bp b/modules/local_time/Android.bp
index df32325..643afa5 100644
--- a/modules/local_time/Android.bp
+++ b/modules/local_time/Android.bp
@@ -24,6 +24,7 @@
 cc_library_shared {
     name: "local_time.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["local_time_hw.c"],
     shared_libs: [
         "liblog",
diff --git a/modules/nfc-nci/Android.bp b/modules/nfc-nci/Android.bp
index fc73761..90d2a28 100644
--- a/modules/nfc-nci/Android.bp
+++ b/modules/nfc-nci/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "nfc_nci.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["nfc_nci_example.c"],
     shared_libs: [
         "liblog",
diff --git a/modules/nfc/Android.bp b/modules/nfc/Android.bp
index bd93bb5..5f174f4 100644
--- a/modules/nfc/Android.bp
+++ b/modules/nfc/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "nfc.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["nfc_pn544_example.c"],
     shared_libs: [
         "liblog",
diff --git a/modules/power/Android.bp b/modules/power/Android.bp
index 2b86c8b..f4c74ce 100644
--- a/modules/power/Android.bp
+++ b/modules/power/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "power.default",
     relative_install_path: "hw",
+    proprietary: true,
     srcs: ["power.c"],
     shared_libs: ["liblog"],
 }
diff --git a/modules/radio/Android.mk b/modules/radio/Android.mk
index 221424f..6f11169 100644
--- a/modules/radio/Android.mk
+++ b/modules/radio/Android.mk
@@ -21,6 +21,7 @@
 
 LOCAL_MODULE := radio.fm.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := radio_hw.c
 LOCAL_SHARED_LIBRARIES := liblog libcutils libradio_metadata
 LOCAL_MODULE_TAGS := optional
diff --git a/modules/radio/radio_hw.c b/modules/radio/radio_hw.c
index 150d173..4010507 100644
--- a/modules/radio/radio_hw.c
+++ b/modules/radio/radio_hw.c
@@ -501,6 +501,10 @@
         status = -EINVAL;
         goto exit;
     }
+    if (config->lower_limit > config->upper_limit) {
+        status = -EINVAL;
+        goto exit;
+    }
     send_command_l(stub_tuner, CMD_CANCEL, 0, NULL);
     send_command_l(stub_tuner, CMD_CONFIG, 500, (void *)config);
 
@@ -613,7 +617,12 @@
     metadata = info->metadata;
     *info = stub_tuner->program;
     info->metadata = metadata;
-    if (metadata != NULL && stub_tuner->program.metadata != NULL)
+    if (metadata == NULL) {
+        ALOGE("%s metadata is a nullptr", __func__);
+        status = -EINVAL;
+        goto exit;
+    }
+    if (stub_tuner->program.metadata != NULL)
         radio_metadata_add_metadata(&info->metadata, stub_tuner->program.metadata);
 
 exit:
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index 534e6e9..ca277e6 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -23,6 +23,7 @@
 LOCAL_MODULE := sensors.$(TARGET_DEVICE)
 
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 
 LOCAL_CFLAGS := -DLOG_TAG=\"MultiHal\"
 
diff --git a/modules/sensors/dynamic_sensor/Android.mk b/modules/sensors/dynamic_sensor/Android.mk
new file mode 100644
index 0000000..07bc5e8
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/Android.mk
@@ -0,0 +1,77 @@
+# Copyright (C) 2017 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.
+
+LOCAL_PATH := $(call my-dir)
+COMMON_CFLAGS := -Wall -Werror -Wextra
+
+#
+# There are two ways to utilize the dynamic sensor module:
+#   1. Use as an extension in an existing hal: declare dependency on libdynamic_sensor_ext shared
+#      library in existing sensor hal.
+#   2. Use as a standalone sensor HAL and configure multihal to combine it with sensor hal that
+#      hosts other sensors: add dependency on sensors.dynamic_sensor_hal in device level makefile and
+#      write multihal configuration file accordingly.
+#
+# Please take only one of these two options to avoid conflict over hardware resource.
+#
+
+#
+# Option 1: sensor extension module
+#
+include $(CLEAR_VARS)
+LOCAL_MODULE := libdynamic_sensor_ext
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_OWNER := google
+
+LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorExt\"
+
+LOCAL_SRC_FILES := \
+    BaseSensorObject.cpp \
+    DynamicSensorManager.cpp \
+    RingBuffer.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+    libcutils \
+    libutils \
+    liblog
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+
+include $(BUILD_SHARED_LIBRARY)
+
+#
+# Option 2: independent sensor hal
+#
+include $(CLEAR_VARS)
+LOCAL_MODULE := sensors.dynamic_sensor_hal
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_OWNER := google
+
+LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorHal\"
+
+LOCAL_SRC_FILES := \
+    BaseSensorObject.cpp \
+    DynamicSensorManager.cpp \
+    RingBuffer.cpp \
+    sensors.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+    libcutils \
+    libutils \
+    liblog \
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/sensors/dynamic_sensor/BaseDynamicSensorDaemon.h b/modules/sensors/dynamic_sensor/BaseDynamicSensorDaemon.h
new file mode 100644
index 0000000..29cf7a4
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/BaseDynamicSensorDaemon.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 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 ANDROID_SENSORHAL_EXT_BASE_DYNAMIC_SENSOR_DAEMON_H
+#define ANDROID_SENSORHAL_EXT_BASE_DYNAMIC_SENSOR_DAEMON_H
+
+#include <utils/RefBase.h>
+
+namespace android {
+namespace SensorHalExt {
+
+class DynamicSensorManager;
+
+class BaseDynamicSensorDaemon : public RefBase {
+public:
+    BaseDynamicSensorDaemon(DynamicSensorManager& manager) : mManager(manager) {}
+    virtual ~BaseDynamicSensorDaemon() = default;
+protected:
+    DynamicSensorManager& mManager;
+};
+
+} // namespace SensorHalExt
+} // namespace android
+
+#endif // ANDROID_SENSORHAL_EXT_BASE_DYNAMIC_SENSOR_DAEMON_H
+
diff --git a/modules/sensors/dynamic_sensor/BaseSensorObject.cpp b/modules/sensors/dynamic_sensor/BaseSensorObject.cpp
new file mode 100644
index 0000000..189e87f
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/BaseSensorObject.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "BaseSensorObject.h"
+#include "SensorEventCallback.h"
+
+#include <utils/Log.h>
+#include <cstring>
+
+namespace android {
+namespace SensorHalExt {
+
+BaseSensorObject::BaseSensorObject() : mCallback(nullptr) {
+}
+
+bool BaseSensorObject::setEventCallback(SensorEventCallback* callback) {
+    if (mCallback != nullptr) {
+        ALOGE("callback is already assigned, cannot change.");
+        return false;
+    }
+    mCallback = callback;
+    return true;
+}
+
+void BaseSensorObject::getUuid(uint8_t* uuid) const {
+    // default uuid denoting uuid feature is not supported on this sensor.
+    memset(uuid, 0, 16);
+}
+
+int BaseSensorObject::flush() {
+    static const sensors_event_t event = {
+        .type = SENSOR_TYPE_META_DATA,
+        .timestamp = TIMESTAMP_AUTO_FILL  // timestamp will be filled at dispatcher
+    };
+    generateEvent(event);
+    return 0;
+}
+
+void BaseSensorObject::generateEvent(const sensors_event_t &e) {
+    if (mCallback) {
+        mCallback->submitEvent(this, e);
+    }
+}
+
+} // namespace SensorHalExt
+} // namespace android
+
diff --git a/modules/sensors/dynamic_sensor/BaseSensorObject.h b/modules/sensors/dynamic_sensor/BaseSensorObject.h
new file mode 100644
index 0000000..326e138
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/BaseSensorObject.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
+#define ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
+
+#include <utils/RefBase.h>
+#include <utils/Timers.h> // for nsecs_t
+#include <cstdint>
+
+struct sensor_t;
+struct sensors_event_t;
+
+namespace android {
+namespace SensorHalExt {
+
+class SensorEventCallback;
+
+class BaseSensorObject : virtual public RefBase {
+public:
+    BaseSensorObject();
+    virtual ~BaseSensorObject() = default;
+
+    // always called by DynamicSensorManager, callback must point to
+    // valid object throughout life cycle of BaseSensorObject
+    bool setEventCallback(SensorEventCallback* callback);
+
+    // virtual functions to get sensor information and operate sensor
+    virtual const sensor_t* getSensor() const = 0;
+
+    // get uuid of sensor, default implementation set it to all zero, means does not have a uuid.
+    virtual void getUuid(uint8_t* uuid) const;
+
+    // enable sensor
+    virtual int enable(bool enable) = 0;
+
+    // set sample period and batching period of sensor.
+    virtual int batch(nsecs_t samplePeriod, nsecs_t batchPeriod) = 0;
+
+    // flush sensor, default implementation will send a flush complete event back.
+    virtual int flush();
+
+protected:
+    // utility function for sub-class
+    void generateEvent(const sensors_event_t &e);
+private:
+    SensorEventCallback* mCallback;
+};
+
+} // namespace SensorHalExt
+} // namespace android
+
+#endif // ANDROID_SENSORHAL_BASE_SENSOR_OBJECT_H
+
diff --git a/modules/sensors/dynamic_sensor/DynamicSensorManager.cpp b/modules/sensors/dynamic_sensor/DynamicSensorManager.cpp
new file mode 100644
index 0000000..d33650c
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/DynamicSensorManager.cpp
@@ -0,0 +1,283 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "BaseDynamicSensorDaemon.h"
+#include "BaseSensorObject.h"
+#include "DynamicSensorManager.h"
+
+#include <utils/Log.h>
+#include <utils/SystemClock.h>
+
+#include <cassert>
+
+namespace android {
+namespace SensorHalExt {
+
+DynamicSensorManager* DynamicSensorManager::createInstance(
+        int handleBase, int handleCount, SensorEventCallback *callback) {
+    auto m = new DynamicSensorManager(handleBase, handleBase + handleCount - 1, callback);
+    return m;
+}
+
+DynamicSensorManager::DynamicSensorManager(
+        int handleBase, int handleMax, SensorEventCallback* callback) :
+        mHandleRange(handleBase, handleMax),
+        mCallback(callback),
+        mFifo(callback ? 0 : kFifoSize),
+        mNextHandle(handleBase+1) {
+    assert(handleBase > 0 && handleMax > handleBase + 1); // handleBase is reserved
+
+    mMetaSensor = (const sensor_t) {
+        "Dynamic Sensor Manager",
+        "Google",
+        1,                                          // version
+        handleBase,                                 // handle
+        SENSOR_TYPE_DYNAMIC_SENSOR_META,
+        1,                                          // maxRange
+        1,                                          // resolution
+        1e-6f,                                      // power, very small number instead of 0
+                                                    // to avoid sigularity in app
+        (int32_t)(1000),                            // minDelay
+        0,                                          // fifoReservedEventCount
+        0,                                          // fifoMaxEventCount
+        SENSOR_STRING_TYPE_DYNAMIC_SENSOR_META,
+        "",                                         // requiredPermission
+        (long)(1000),                               // maxDelay
+        SENSOR_FLAG_SPECIAL_REPORTING_MODE | SENSOR_FLAG_WAKE_UP,
+        { NULL, NULL }
+    };
+}
+
+DynamicSensorManager::~DynamicSensorManager() {
+    // free all daemons first
+    mDaemonVector.clear();
+}
+
+bool DynamicSensorManager::owns(int handle) const {
+    return handle >= mHandleRange.first && handle < mHandleRange.second;
+}
+
+int DynamicSensorManager::activate(int handle, bool enable) {
+    if (handle == mHandleRange.first) {
+        // ignored
+        return 0;
+    }
+
+    // in case there is a pending report, now it is time to remove it as it is no longer necessary.
+    {
+        std::lock_guard<std::mutex> lk(mLock);
+        mPendingReport.erase(handle);
+    }
+
+    return operateSensor(handle,
+            [&enable] (sp<BaseSensorObject> s)->int {
+                return s->enable(enable);
+            });
+}
+
+int DynamicSensorManager::batch(int handle, nsecs_t sample_period, nsecs_t batch_period) {
+    if (handle == mHandleRange.first) {
+        // ignored
+        return 0;
+    }
+    return operateSensor(handle,
+            [&sample_period, &batch_period] (sp<BaseSensorObject> s)->int {
+                return s->batch(sample_period, batch_period);
+            });
+}
+
+int DynamicSensorManager::setDelay(int handle, nsecs_t sample_period) {
+    return batch(handle, sample_period, 0);
+}
+
+int DynamicSensorManager::flush(int handle) {
+    if (handle == mHandleRange.first) {
+        // TODO: submit a flush complete here
+        static const sensors_event_t event = {
+            .type = SENSOR_TYPE_META_DATA,
+            .sensor = mHandleRange.first,
+            .timestamp = TIMESTAMP_AUTO_FILL,  // timestamp will be filled at dispatcher
+        };
+        submitEvent(nullptr, event);
+        return 0;
+    }
+    return operateSensor(handle, [] (sp<BaseSensorObject> s)->int {return s->flush();});
+}
+
+int DynamicSensorManager::poll(sensors_event_t * data, int count) {
+    assert(mCallback == nullptr);
+    std::lock_guard<std::mutex> lk(mFifoLock);
+    return mFifo.read(data, count);
+}
+
+bool DynamicSensorManager::registerSensor(sp<BaseSensorObject> sensor) {
+    std::lock_guard<std::mutex> lk(mLock);
+    if (mReverseMap.find(sensor.get()) != mReverseMap.end()) {
+        ALOGE("trying to add the same sensor twice, ignore");
+        return false;
+    }
+    int handle = getNextAvailableHandle();
+    if (handle < 0) {
+        ALOGE("Running out of handle, quit.");
+        return false;
+    }
+
+    // these emplace will always be successful
+    mMap.emplace(handle, sensor);
+    mReverseMap.emplace(sensor.get(), handle);
+    sensor->setEventCallback(this);
+
+    auto entry = mPendingReport.emplace(
+            std::piecewise_construct,
+            std::forward_as_tuple(handle),
+            std::forward_as_tuple(handle, sensor));
+    if (entry.second) {
+        submitEvent(nullptr, entry.first->second.generateConnectionEvent(mHandleRange.first));
+    }
+    return entry.second;
+}
+
+void DynamicSensorManager::unregisterSensor(sp<BaseSensorObject> sensor) {
+    std::lock_guard<std::mutex> lk(mLock);
+    auto i = mReverseMap.find(sensor.get());
+    if (i == mReverseMap.end()) {
+        ALOGE("cannot remove a non-exist sensor");
+        return;
+    }
+    int handle = i->second;
+    mReverseMap.erase(i);
+    mMap.erase(handle);
+
+    // will not clean up mPendingReport here, it will be cleaned up when at first activate call.
+    // sensorservice is guranteed to call activate upon arrival of dynamic sensor meta connection
+    // event.
+
+    // send disconnection event
+    sensors_event_t event;
+    ConnectionReport::fillDisconnectionEvent(&event, mHandleRange.first, handle);
+    submitEvent(nullptr, event);
+}
+
+int DynamicSensorManager::submitEvent(sp<BaseSensorObject> source, const sensors_event_t &e) {
+    int handle;
+    if (source == nullptr) {
+        handle = mHandleRange.first;
+    } else {
+        std::lock_guard<std::mutex> lk(mLock);
+        auto i = mReverseMap.find(source.get());
+        if (i == mReverseMap.end()) {
+            ALOGE("cannot submit event for sensor that has not been registered");
+            return NAME_NOT_FOUND;
+        }
+        handle = i->second;
+    }
+
+    // making a copy of events, prepare for editing
+    sensors_event_t event = e;
+    event.version = sizeof(event);
+
+    // special case of flush complete
+    if (event.type == SENSOR_TYPE_META_DATA) {
+        event.sensor = 0;
+        event.meta_data.sensor = handle;
+    } else {
+        event.sensor = handle;
+    }
+
+    // set timestamp if it is default value
+    if (event.timestamp == TIMESTAMP_AUTO_FILL) {
+        event.timestamp = elapsedRealtimeNano();
+    }
+
+    if (mCallback) {
+        // extention mode, calling callback directly
+        int ret;
+
+        ret = mCallback->submitEvent(nullptr, event);
+        if (ret < 0) {
+            ALOGE("DynamicSensorManager callback failed, ret: %d", ret);
+        }
+    } else {
+        // standalone mode, add event to internal buffer for poll() to pick up
+        std::lock_guard<std::mutex> lk(mFifoLock);
+        if (mFifo.write(&event, 1) < 0) {
+            ALOGE("DynamicSensorManager fifo full");
+        }
+    }
+    return 0;
+}
+
+int DynamicSensorManager::getNextAvailableHandle() {
+    if (mNextHandle == mHandleRange.second) {
+        return -1;
+    }
+    return mNextHandle++;
+}
+
+const sensor_t& DynamicSensorManager::getDynamicMetaSensor() const {
+    return mMetaSensor;
+}
+
+DynamicSensorManager::ConnectionReport::ConnectionReport(
+        int handle, sp<BaseSensorObject> sensor) :
+        mSensor(*(sensor->getSensor())),
+        mName(mSensor.name),
+        mVendor(mSensor.vendor),
+        mPermission(mSensor.requiredPermission),
+        mStringType(mSensor.stringType),
+        mGenerated(false) {
+    mSensor.name = mName.c_str();
+    mSensor.vendor = mVendor.c_str();
+    mSensor.requiredPermission = mPermission.c_str();
+    mSensor.stringType = mStringType.c_str();
+    mSensor.handle = handle;
+    memset(&mEvent, 0, sizeof(mEvent));
+    mEvent.version = sizeof(mEvent);
+    sensor->getUuid(mUuid);
+    ALOGV("Connection report init: name = %s, handle = %d", mSensor.name, mSensor.handle);
+}
+
+DynamicSensorManager::ConnectionReport::~ConnectionReport() {
+    ALOGV("Connection report dtor: name = %s, handle = %d", mSensor.name, mSensor.handle);
+}
+
+const sensors_event_t& DynamicSensorManager::ConnectionReport::
+        generateConnectionEvent(int metaHandle) {
+    if (!mGenerated) {
+        mEvent.sensor = metaHandle;
+        mEvent.type = SENSOR_TYPE_DYNAMIC_SENSOR_META;
+        mEvent.timestamp = elapsedRealtimeNano();
+        mEvent.dynamic_sensor_meta =
+                (dynamic_sensor_meta_event_t) {true, mSensor.handle, &mSensor, {0}};
+        memcpy(&mEvent.dynamic_sensor_meta.uuid, &mUuid, sizeof(mEvent.dynamic_sensor_meta.uuid));
+        mGenerated = true;
+    }
+    return mEvent;
+}
+
+void DynamicSensorManager::ConnectionReport::
+        fillDisconnectionEvent(sensors_event_t* event, int metaHandle, int handle) {
+    memset(event, 0, sizeof(sensors_event_t));
+    event->version = sizeof(sensors_event_t);
+    event->sensor = metaHandle;
+    event->type = SENSOR_TYPE_DYNAMIC_SENSOR_META;
+    event->timestamp = elapsedRealtimeNano();
+    event->dynamic_sensor_meta.connected = false;
+    event->dynamic_sensor_meta.handle = handle;
+}
+
+} // namespace SensorHalExt
+} // namespace android
diff --git a/modules/sensors/dynamic_sensor/DynamicSensorManager.h b/modules/sensors/dynamic_sensor/DynamicSensorManager.h
new file mode 100644
index 0000000..b8fd472
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/DynamicSensorManager.h
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2017 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 ANDROID_SENSORHAL_EXT_DYNAMIC_SENSOR_MANAGER_H
+#define ANDROID_SENSORHAL_EXT_DYNAMIC_SENSOR_MANAGER_H
+
+#include "SensorEventCallback.h"
+#include "RingBuffer.h"
+#include <hardware/sensors.h>
+#include <utils/RefBase.h>
+
+#include <mutex>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+namespace android {
+namespace SensorHalExt {
+
+class BaseDynamicSensorDaemon;
+
+class DynamicSensorManager : public SensorEventCallback {
+public:
+    // handleBase is reserved for the dynamic sensor meta sensor.
+    // handleMax must be greater than handleBase + 1.
+    // This class has two operation mode depending on callback: 1) extension, 2) stand-alone.
+    // In extension mode, callback must not be nullptr. Sensor event generated will be submitted to
+    // buffer of primary sensor HAL implementation. In stand-alone mode, callback must be nullptr.
+    // Generated sensor events will be added into internal buffer waiting for poll() function to
+    // pick up.
+    //
+    static DynamicSensorManager* createInstance(
+            int handleBase, int handleCount, SensorEventCallback *callback);
+    virtual ~DynamicSensorManager();
+
+    // calls to add or remove sensor, called from sensor daemon
+    bool registerSensor(sp<BaseSensorObject> sensor);
+    void unregisterSensor(sp<BaseSensorObject> sensor);
+
+    // Determine if a sensor handle is in the range defined in constructor.
+    // It does not test if sensor handle is valid.
+    bool owns(int handle) const;
+
+    // handles sensor hal requests.
+    int activate(int handle, bool enable);
+    int batch(int handle, nsecs_t sample_period, nsecs_t batch_period);
+    int setDelay(int handle, nsecs_t sample_period);
+    int flush(int handle);
+    int poll(sensors_event_t * data, int count);
+
+    // SensorEventCallback
+    virtual int submitEvent(sp<BaseSensorObject>, const sensors_event_t &e) override;
+
+    // get meta sensor struct
+    const sensor_t& getDynamicMetaSensor() const;
+protected:
+    DynamicSensorManager(int handleBase, int handleMax, SensorEventCallback* callback);
+private:
+    // a helper class used for generate connection and disconnection report
+    class ConnectionReport {
+    public:
+        ConnectionReport() {}
+        ConnectionReport(int handle, sp<BaseSensorObject> sensor);
+        ~ConnectionReport();
+        const sensors_event_t& generateConnectionEvent(int metaHandle);
+        static void fillDisconnectionEvent(sensors_event_t* event, int metaHandle, int handle);
+    private:
+        sensor_t mSensor;
+        std::string mName;
+        std::string mVendor;
+        std::string mPermission;
+        std::string mStringType;
+        sensors_event_t mEvent;
+        uint8_t mUuid[16];
+        bool mGenerated;
+        DISALLOW_EVIL_CONSTRUCTORS(ConnectionReport);
+    };
+
+    // returns next available handle to use upon a new sensor connection, or -1 if we run out.
+    int getNextAvailableHandle();
+
+    // TF:  int foo(sp<BaseSensorObject> obj);
+    template <typename TF>
+    int operateSensor(int handle, TF f) const {
+        std::lock_guard<std::mutex> lk(mLock);
+        const auto i = mMap.find(handle);
+        if (i == mMap.end()) {
+            return BAD_VALUE;
+        }
+        sp<BaseSensorObject> s = i->second.promote();
+        if (s == nullptr) {
+            // sensor object is already gone
+            return BAD_VALUE;
+        }
+        return f(s);
+    }
+
+    // available sensor handle space
+    const std::pair<int, int> mHandleRange;
+    sensor_t mMetaSensor;
+
+    // immutable pointer to event callback, used in extention mode.
+    SensorEventCallback * const mCallback;
+
+    // RingBuffer used in standalone mode
+    static constexpr size_t kFifoSize = 4096; //4K events
+    mutable std::mutex mFifoLock;
+    RingBuffer mFifo;
+
+    // mapping between handle and SensorObjects
+    mutable std::mutex mLock;
+    int mNextHandle;
+    std::unordered_map<int, wp<BaseSensorObject> > mMap;
+    std::unordered_map<void *, int> mReverseMap;
+    mutable std::unordered_map<int, ConnectionReport> mPendingReport;
+
+    // daemons
+    std::vector<sp<BaseDynamicSensorDaemon>> mDaemonVector;
+};
+
+} // namespace SensorHalExt
+} // namespace android
+
+#endif // ANDROID_SENSORHAL_EXT_DYNAMIC_SENSOR_MANAGER_H
diff --git a/modules/sensors/dynamic_sensor/RingBuffer.cpp b/modules/sensors/dynamic_sensor/RingBuffer.cpp
new file mode 100644
index 0000000..5857a7c
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/RingBuffer.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "RingBuffer.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+namespace android {
+
+RingBuffer::RingBuffer(size_t size)
+    : mSize(size),
+      mData((sensors_event_t *)malloc(sizeof(sensors_event_t) * mSize)),
+      mReadPos(0),
+      mWritePos(0) {
+}
+
+RingBuffer::~RingBuffer() {
+    free(mData);
+    mData = NULL;
+}
+
+ssize_t RingBuffer::write(const sensors_event_t *ev, size_t size) {
+    Mutex::Autolock autoLock(mLock);
+
+    size_t numAvailableToRead = mWritePos - mReadPos;
+    size_t numAvailableToWrite = mSize - numAvailableToRead;
+
+    if (size > numAvailableToWrite) {
+        size = numAvailableToWrite;
+    }
+
+    size_t writePos = (mWritePos % mSize);
+    size_t copy = mSize - writePos;
+
+    if (copy > size) {
+        copy = size;
+    }
+
+    memcpy(&mData[writePos], ev, copy * sizeof(sensors_event_t));
+
+    if (size > copy) {
+        memcpy(mData, &ev[copy], (size - copy) * sizeof(sensors_event_t));
+    }
+
+    mWritePos += size;
+
+    if (numAvailableToRead == 0 && size > 0) {
+        mNotEmptyCondition.broadcast();
+    }
+
+    return size;
+}
+
+ssize_t RingBuffer::read(sensors_event_t *ev, size_t size) {
+    Mutex::Autolock autoLock(mLock);
+
+    size_t numAvailableToRead;
+    for (;;) {
+        numAvailableToRead = mWritePos - mReadPos;
+        if (numAvailableToRead > 0) {
+            break;
+        }
+
+        mNotEmptyCondition.wait(mLock);
+    }
+
+    if (size > numAvailableToRead) {
+        size = numAvailableToRead;
+    }
+
+    size_t readPos = (mReadPos % mSize);
+    size_t copy = mSize - readPos;
+
+    if (copy > size) {
+        copy = size;
+    }
+
+    memcpy(ev, &mData[readPos], copy * sizeof(sensors_event_t));
+
+    if (size > copy) {
+        memcpy(&ev[copy], mData, (size - copy) * sizeof(sensors_event_t));
+    }
+
+    mReadPos += size;
+
+    return size;
+}
+
+}  // namespace android
+
diff --git a/modules/sensors/dynamic_sensor/RingBuffer.h b/modules/sensors/dynamic_sensor/RingBuffer.h
new file mode 100644
index 0000000..aa6b8c9
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/RingBuffer.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 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 RING_BUFFER_H_
+
+#define RING_BUFFER_H_
+
+#include <media/stagefright/foundation/ABase.h>
+
+#include <hardware/sensors.h>
+#include <utils/threads.h>
+
+namespace android {
+
+class RingBuffer {
+public:
+    explicit RingBuffer(size_t size);
+    ~RingBuffer();
+
+    ssize_t write(const sensors_event_t *ev, size_t size);
+    ssize_t read(sensors_event_t *ev, size_t size);
+
+private:
+    Mutex mLock;
+    Condition mNotEmptyCondition;
+
+    size_t mSize;
+    sensors_event_t *mData;
+    size_t mReadPos, mWritePos;
+
+    DISALLOW_EVIL_CONSTRUCTORS(RingBuffer);
+};
+
+}  // namespace android
+
+#endif  // RING_BUFFER_H_
diff --git a/modules/sensors/dynamic_sensor/SensorEventCallback.h b/modules/sensors/dynamic_sensor/SensorEventCallback.h
new file mode 100644
index 0000000..b98cd7f
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/SensorEventCallback.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 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 ANDROID_SENSORHAL_DSE_SENSOR_EVENT_CALLBACK_H
+#define ANDROID_SENSORHAL_DSE_SENSOR_EVENT_CALLBACK_H
+
+#include <hardware/sensors.h>
+#include <utils/RefBase.h>
+
+namespace android {
+namespace SensorHalExt {
+
+class BaseSensorObject;
+
+// if timestamp in sensors_event_t has this value, it will be filled at dispatcher.
+constexpr int64_t TIMESTAMP_AUTO_FILL = -1;
+
+class SensorEventCallback {
+public:
+    virtual int submitEvent(sp<BaseSensorObject> sensor, const sensors_event_t &e) = 0;
+    virtual ~SensorEventCallback() = default;
+};
+
+} // namespace SensorHalExt
+} // namespace android
+
+#endif // ANDROID_SENSORHAL_DSE_SENSOR_EVENT_CALLBACK_H
diff --git a/modules/sensors/dynamic_sensor/sensors.cpp b/modules/sensors/dynamic_sensor/sensors.cpp
new file mode 100644
index 0000000..7c203b2
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/sensors.cpp
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+
+#include "DynamicSensorManager.h"
+#include "sensors.h"
+
+#include <cutils/properties.h>
+#include <media/stagefright/foundation/ADebug.h>
+#include <utils/Log.h>
+
+#include <errno.h>
+#include <string.h>
+using namespace android;
+
+////////////////////////////////////////////////////////////////////////////////
+
+SensorContext::SensorContext(const struct hw_module_t *module) {
+    memset(&device, 0, sizeof(device));
+
+    device.common.tag = HARDWARE_DEVICE_TAG;
+    device.common.version = SENSORS_DEVICE_API_VERSION_1_3;
+    device.common.module = const_cast<hw_module_t *>(module);
+    device.common.close = CloseWrapper;
+    device.activate = ActivateWrapper;
+    device.setDelay = SetDelayWrapper;
+    device.poll = PollWrapper;
+    device.batch = BatchWrapper;
+    device.flush = FlushWrapper;
+
+    // initialize dynamic sensor manager
+    int32_t base = property_get_int32("sensor.dynamic_sensor_hal.handle_base", kDynamicHandleBase);
+    int32_t count =
+            property_get_int32("sensor.dynamic_sensor_hal.handle_count", kMaxDynamicHandleCount);
+    mDynamicSensorManager.reset(DynamicSensorManager::createInstance(base, count, nullptr));
+}
+
+int SensorContext::close() {
+    delete this;
+    return 0;
+}
+
+int SensorContext::activate(int handle, int enabled) {
+    return mDynamicSensorManager->activate(handle, enabled);
+}
+
+int SensorContext::setDelay(int handle, int64_t delayNs) {
+    return mDynamicSensorManager->setDelay(handle, delayNs);
+}
+
+int SensorContext::poll(sensors_event_t *data, int count) {
+    return mDynamicSensorManager->poll(data, count);
+}
+
+int SensorContext::batch(
+        int handle,
+        int64_t sampling_period_ns,
+        int64_t max_report_latency_ns) {
+    return mDynamicSensorManager->batch(handle, sampling_period_ns, max_report_latency_ns);
+}
+
+int SensorContext::flush(int handle) {
+    return mDynamicSensorManager->flush(handle);
+}
+
+// static
+int SensorContext::CloseWrapper(struct hw_device_t *dev) {
+    return reinterpret_cast<SensorContext *>(dev)->close();
+}
+
+// static
+int SensorContext::ActivateWrapper(
+        struct sensors_poll_device_t *dev, int handle, int enabled) {
+    return reinterpret_cast<SensorContext *>(dev)->activate(handle, enabled);
+}
+
+// static
+int SensorContext::SetDelayWrapper(
+        struct sensors_poll_device_t *dev, int handle, int64_t delayNs) {
+    return reinterpret_cast<SensorContext *>(dev)->setDelay(handle, delayNs);
+}
+
+// static
+int SensorContext::PollWrapper(
+        struct sensors_poll_device_t *dev, sensors_event_t *data, int count) {
+    return reinterpret_cast<SensorContext *>(dev)->poll(data, count);
+}
+
+// static
+int SensorContext::BatchWrapper(
+        struct sensors_poll_device_1 *dev,
+        int handle,
+        int flags,
+        int64_t sampling_period_ns,
+        int64_t max_report_latency_ns) {
+    (void) flags;
+    return reinterpret_cast<SensorContext *>(dev)->batch(
+            handle, sampling_period_ns, max_report_latency_ns);
+}
+
+// static
+int SensorContext::FlushWrapper(struct sensors_poll_device_1 *dev, int handle) {
+    return reinterpret_cast<SensorContext *>(dev)->flush(handle);
+}
+
+size_t SensorContext::getSensorList(sensor_t const **list) {
+    *list = &(mDynamicSensorManager->getDynamicMetaSensor());
+    return 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+static sensor_t const *sensor_list;
+
+static int open_sensors(
+        const struct hw_module_t *module,
+        const char *,
+        struct hw_device_t **dev) {
+    SensorContext *ctx = new SensorContext(module);
+    ctx->getSensorList(&sensor_list);
+    *dev = &ctx->device.common;
+    return 0;
+}
+
+static struct hw_module_methods_t sensors_module_methods = {
+    .open = open_sensors
+};
+
+static int get_sensors_list(
+        struct sensors_module_t *,
+        struct sensor_t const **list) {
+    *list = sensor_list;
+    return 1;
+}
+
+static int set_operation_mode(unsigned int mode) {
+    return (mode) ? -EINVAL : 0;
+}
+
+struct sensors_module_t HAL_MODULE_INFO_SYM = {
+    .common = {
+            .tag = HARDWARE_MODULE_TAG,
+            .version_major = 1,
+            .version_minor = 0,
+            .id = SENSORS_HARDWARE_MODULE_ID,
+            .name = "Google Dynamic Sensor Manager",
+            .author = "Google",
+            .methods = &sensors_module_methods,
+            .dso  = NULL,
+            .reserved = {0},
+    },
+    .get_sensors_list = get_sensors_list,
+    .set_operation_mode = set_operation_mode,
+};
diff --git a/modules/sensors/dynamic_sensor/sensors.h b/modules/sensors/dynamic_sensor/sensors.h
new file mode 100644
index 0000000..be42b67
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/sensors.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2015 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 SENSORS_H_
+#define SENSORS_H_
+
+#include <hardware/hardware.h>
+#include <hardware/sensors.h>
+#include <media/stagefright/foundation/ABase.h>
+#include <utils/RefBase.h>
+
+#include <memory>
+#include <unordered_set>
+#include <vector>
+
+namespace android {
+    namespace SensorHalExt {
+        class DynamicSensorManager;
+    } // namespace BaseSensorObject
+} // namespace android
+
+using android::SensorHalExt::DynamicSensorManager;
+
+class SensorContext {
+public:
+    struct sensors_poll_device_1 device;
+
+    explicit SensorContext(const struct hw_module_t *module);
+
+    size_t getSensorList(sensor_t const **list);
+
+private:
+
+    int close();
+    int activate(int handle, int enabled);
+    int setDelay(int handle, int64_t delayNs);
+    int poll(sensors_event_t *data, int count);
+
+    int batch(int handle, int64_t sampling_period_ns,
+              int64_t max_report_latency_ns);
+
+    int flush(int handle);
+
+    // static wrappers
+    static int CloseWrapper(struct hw_device_t *dev);
+
+    static int ActivateWrapper(
+            struct sensors_poll_device_t *dev, int handle, int enabled);
+
+    static int SetDelayWrapper(
+            struct sensors_poll_device_t *dev, int handle, int64_t delayNs);
+
+    static int PollWrapper(
+            struct sensors_poll_device_t *dev, sensors_event_t *data, int count);
+
+    static int BatchWrapper(
+            struct sensors_poll_device_1 *dev,
+            int handle,
+            int flags,
+            int64_t sampling_period_ns,
+            int64_t max_report_latency_ns);
+
+    static int FlushWrapper(struct sensors_poll_device_1 *dev, int handle);
+
+    // default ~16 million handles for dynamic sensor use, can be overriden by system property
+    static constexpr int32_t kDynamicHandleBase = 0x10000;
+    static constexpr int32_t kDynamicHandleEnd = 0x1000000;
+    static constexpr int32_t kMaxDynamicHandleCount = kDynamicHandleEnd - kDynamicHandleBase;
+
+    std::unique_ptr<DynamicSensorManager> mDynamicSensorManager;
+
+    DISALLOW_EVIL_CONSTRUCTORS(SensorContext);
+};
+
+#endif  // SENSORS_H_
diff --git a/modules/soundtrigger/Android.mk b/modules/soundtrigger/Android.mk
index bb58053..8250f9b 100644
--- a/modules/soundtrigger/Android.mk
+++ b/modules/soundtrigger/Android.mk
@@ -19,6 +19,7 @@
 
 LOCAL_MODULE := sound_trigger.stub.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := sound_trigger_hw.c
 LOCAL_SHARED_LIBRARIES := liblog libcutils
 LOCAL_MODULE_TAGS := optional
diff --git a/modules/thermal/Android.mk b/modules/thermal/Android.mk
index 80ad78a..ff51145 100644
--- a/modules/thermal/Android.mk
+++ b/modules/thermal/Android.mk
@@ -18,6 +18,7 @@
 
 LOCAL_MODULE := thermal.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := thermal.c
 LOCAL_SHARED_LIBRARIES := liblog libcutils
 LOCAL_MODULE_TAGS := optional
diff --git a/modules/tv_input/Android.bp b/modules/tv_input/Android.bp
index beac132..509198d 100644
--- a/modules/tv_input/Android.bp
+++ b/modules/tv_input/Android.bp
@@ -15,6 +15,7 @@
 cc_library_shared {
     name: "tv_input.default",
     relative_install_path: "hw",
+    proprietary: true,
     shared_libs: [
         "libcutils",
         "liblog",
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index 9df1e79..b36bf9f 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -18,6 +18,7 @@
 
 LOCAL_MODULE := audio.usb.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := \
 	audio_hal.c
 LOCAL_C_INCLUDES += \
diff --git a/modules/vehicle/Android.mk b/modules/vehicle/Android.mk
index a666bc6..9fd49da 100644
--- a/modules/vehicle/Android.mk
+++ b/modules/vehicle/Android.mk
@@ -19,6 +19,7 @@
 LOCAL_MODULE := vehicle.default
 
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_C_INCLUDES := hardware/libhardware
 LOCAL_SRC_FILES := vehicle.c timeUtil.cpp
 LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
diff --git a/modules/vibrator/Android.bp b/modules/vibrator/Android.bp
index f9afd45..3c4aebf 100644
--- a/modules/vibrator/Android.bp
+++ b/modules/vibrator/Android.bp
@@ -18,6 +18,7 @@
     // HAL module implementation stored in
     // hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
     relative_install_path: "hw",
+    proprietary: true,
     include_dirs: ["hardware/libhardware"],
     srcs: ["vibrator.c"],
     shared_libs: ["liblog"],
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
index c3c2951..92c46e2 100644
--- a/modules/vibrator/vibrator.c
+++ b/modules/vibrator/vibrator.c
@@ -32,16 +32,20 @@
 
 static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable";
 
-static int vibra_exists() {
+static bool device_exists(const char *file) {
     int fd;
 
-    fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+    fd = TEMP_FAILURE_RETRY(open(file, O_RDWR));
     if(fd < 0) {
-        return 0;
+        return false;
     }
 
     close(fd);
-    return 1;
+    return true;
+}
+
+static bool vibra_exists() {
+    return device_exists(THE_DEVICE);
 }
 
 static int write_value(const char *file, const char *value)
@@ -102,9 +106,13 @@
     return write_value(file_str, value);
 }
 
-static int vibra_led_exists()
+static bool vibra_led_exists()
 {
-    return !write_led_file("trigger", "transient");
+    int fd;
+    char file_str[50];
+
+    snprintf(file_str, sizeof(file_str), "%s/%s", LED_DEVICE, "activate");
+    return device_exists(file_str);
 }
 
 static int vibra_led_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
diff --git a/modules/vr/Android.mk b/modules/vr/Android.mk
index 43c8e92..e04c0da 100644
--- a/modules/vr/Android.mk
+++ b/modules/vr/Android.mk
@@ -18,6 +18,7 @@
 
 LOCAL_MODULE := vr.default
 LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := vr.c
 LOCAL_SHARED_LIBRARIES := libcutils
 LOCAL_MODULE_TAGS := optional
diff --git a/tests/vehicle/README b/tests/vehicle/README
index b8fc7d4..42d2210 100644
--- a/tests/vehicle/README
+++ b/tests/vehicle/README
@@ -49,13 +49,13 @@
 $ mmm hardware/libhardware
 
 This will generate the following binaries that we care about:
-i) out/target/product/XXX/system/lib/hw/vehicle.default.so
+i) out/target/product/XXX/vendor/lib/hw/vehicle.default.so
 ii) out/target/product/XXX/data/nativetest/vehicle_tests
 iii) out/target/product/XXX/system/bin/vehicle-hal-tool
 
 The location for the first shared library would be:
-$ adb push out/target/product/XXX/system/lib/hw/vehicle.default.so
-/system/lib/hw
+$ adb push out/target/product/XXX/vendor/lib/hw/vehicle.default.so
+/vendor/lib/hw
 You can also use 'adb sync' if you like, although this is the easiest least
 hassle way of putting it in place.