BLE OOB Pairing - parse address type (2/5)
am: 93bd76b16a

Change-Id: Id4bd387a47a4be9445ff00e4283c16a7dc14a2dd
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..f093c56
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,18 @@
+// Copyright 2006 The Android Open Source Project
+
+cc_library_shared {
+    name: "libhardware",
+
+    srcs: ["hardware.c"],
+    shared_libs: [
+        "libcutils",
+        "liblog",
+        "libdl",
+    ],
+    cflags: ["-DQEMU_HARDWARE"],
+}
+
+subdirs = [
+    "modules/*",
+    "tests/*",
+]
diff --git a/Android.mk b/Android.mk
index aec6781..8744f46 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,24 +1,3 @@
 # Copyright 2006 The Android Open Source Project
 
-# Setting LOCAL_PATH will mess up all-subdir-makefiles, so do it beforehand.
-SUBDIR_MAKEFILES := $(call all-named-subdir-makefiles,modules tests)
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SHARED_LIBRARIES := libcutils liblog
-
-LOCAL_INCLUDES += $(LOCAL_PATH)
-
-LOCAL_CFLAGS  += -DQEMU_HARDWARE
-QEMU_HARDWARE := true
-
-LOCAL_SHARED_LIBRARIES += libdl
-
-LOCAL_SRC_FILES += hardware.c
-
-LOCAL_MODULE:= libhardware
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(SUBDIR_MAKEFILES)
+include $(call all-named-subdir-makefiles,modules tests)
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index ec7fd4b..c95ad09 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -679,7 +679,7 @@
                                        struct audio_hw_device** device)
 {
     return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
-                                 (struct hw_device_t**)device);
+                                 TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int audio_hw_device_close(struct audio_hw_device* device)
diff --git a/include/hardware/audio_effect.h b/include/hardware/audio_effect.h
index e49980d..8a88414 100644
--- a/include/hardware/audio_effect.h
+++ b/include/hardware/audio_effect.h
@@ -911,6 +911,9 @@
     char        data[];     // Start of Parameter + Value data
 } effect_param_t;
 
+// Maximum effect_param_t size
+#define EFFECT_PARAM_SIZE_MAX       65536
+
 // structure used by EFFECT_CMD_OFFLOAD command
 typedef struct effect_offload_param_s {
     bool isOffload;         // true if the playback thread the effect is attached to is offloaded
diff --git a/include/hardware/ble_advertiser.h b/include/hardware/ble_advertiser.h
new file mode 100644
index 0000000..a474ce1
--- /dev/null
+++ b/include/hardware/ble_advertiser.h
@@ -0,0 +1,69 @@
+/*
+ * 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 ANDROID_INCLUDE_BLE_ADVERTISER_H
+#define ANDROID_INCLUDE_BLE_ADVERTISER_H
+
+#include <base/callback_forward.h>
+#include <stdint.h>
+#include <vector>
+#include "bt_common_types.h"
+#include "bt_gatt_types.h"
+
+struct AdvertiseParameters {
+  uint16_t min_interval;
+  uint16_t max_interval;
+  uint8_t adv_type;
+  uint8_t channel_map;
+  uint8_t tx_power;
+};
+
+class BleAdvertiserInterface {
+ public:
+  virtual ~BleAdvertiserInterface() = default;
+
+  /** Callback invoked when multi-adv operation has completed */
+  using Callback = base::Callback<void(uint8_t /* status */)>;
+
+  /** Registers an advertiser with the stack */
+  virtual void RegisterAdvertiser(
+      base::Callback<void(uint8_t /* advertiser_id */,
+                          uint8_t /* status */)>) = 0;
+
+  /* Set the parameters as per spec, user manual specified values */
+  virtual void SetParameters(int advertiser_id, int min_interval,
+                             int max_interval, int adv_type, int chnl_map,
+                             int tx_power, Callback cb) = 0;
+
+  /* Setup the data */
+  virtual void SetData(int advertiser_id, bool set_scan_rsp,
+                       std::vector<uint8_t> data, Callback cb) = 0;
+
+  /* Enable the advertising instance */
+  virtual void Enable(uint8_t advertiser_id, bool enable, Callback cb,
+                      int timeout_s, Callback timeout_cb) = 0;
+
+  /*  Unregisters an advertiser */
+  virtual void Unregister(uint8_t advertiser_id) = 0;
+
+  virtual void StartAdvertising(uint8_t advertiser_id, Callback cb,
+                                AdvertiseParameters params,
+                                std::vector<uint8_t> advertise_data,
+                                std::vector<uint8_t> scan_response_data,
+                                int timeout_s, Callback timeout_cb) = 0;
+};
+
+#endif /* ANDROID_INCLUDE_BLE_ADVERTISER_H */
diff --git a/include/hardware/ble_scanner.h b/include/hardware/ble_scanner.h
new file mode 100644
index 0000000..dca7e43
--- /dev/null
+++ b/include/hardware/ble_scanner.h
@@ -0,0 +1,125 @@
+/*
+ * 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 ANDROID_INCLUDE_BLE_SCANNER_H
+#define ANDROID_INCLUDE_BLE_SCANNER_H
+
+#include <stdint.h>
+#include <vector>
+#include "bt_gatt_types.h"
+#include "bt_common_types.h"
+#include "bt_gatt_client.h"
+
+/** Callback invoked in response to register_scanner */
+typedef void (*register_scanner_callback)(int status, int scanner_id,
+                bt_uuid_t *app_uuid);
+
+/** 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, std::vector<uint8_t> data);
+
+/** Callback invoked when batchscan storage threshold limit is crossed */
+typedef void (*batchscan_threshold_callback)(int client_if);
+
+/** Track ADV VSE callback invoked when tracked device is found or lost */
+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, 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 {
+    register_scanner_callback           register_scanner_cb;
+    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;
+
+typedef struct {
+    /** Registers a scanner with the stack */
+    bt_status_t (*register_scanner)( bt_uuid_t *uuid );
+
+    /** Unregister a scanner from the stack */
+    bt_status_t (*unregister_scanner)(int scanner_id );
+
+    /** Start or stop LE device scanning */
+    bt_status_t (*scan)( bool start );
+
+    /** Setup scan filter params */
+    bt_status_t (*scan_filter_param_setup)(btgatt_filt_param_setup_t filt_param);
+
+
+    /** Configure a scan filter condition  */
+    bt_status_t (*scan_filter_add_remove)(int client_if, 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);
+
+    /** Clear all scan filter conditions for specific filter index*/
+    bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
+
+    /** Enable / disable scan filter feature*/
+    bt_status_t (*scan_filter_enable)(int client_if, bool enable);
+
+    /** Sets the LE scan interval and window in units of N*0.625 msec */
+    bt_status_t (*set_scan_parameters)(int client_if, int scan_interval, int scan_window);
+
+    /* Configure the batchscan storage */
+    bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
+        int batch_scan_trunc_max, int batch_scan_notify_threshold);
+
+    /* Enable batchscan */
+    bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
+        int scan_interval, int scan_window, int addr_type, int discard_rule);
+
+    /* Disable batchscan */
+    bt_status_t (*batchscan_dis_batch_scan)(int client_if);
+
+    /* Read out batchscan reports */
+    bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
+
+} btgatt_scanner_interface_t;
+
+#endif /* ANDROID_INCLUDE_BLE_SCANNER_H */
\ No newline at end of file
diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h
index dd5ea8a..125a95b 100644
--- a/include/hardware/bluetooth.h
+++ b/include/hardware/bluetooth.h
@@ -273,7 +273,7 @@
    uint8_t c256[16]; /* Simple Pairing Hash C-256 */
    uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */
    uint8_t sm_tk[16]; /* Security Manager TK Value */
-   uint8_t le_sc_c[16]; /* LE Secure Connections Random Value */
+   uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */
    uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */
 } bt_out_of_band_data_t;
 
diff --git a/include/hardware/bt_common_types.h b/include/hardware/bt_common_types.h
index 01b5256..1e6be6b 100644
--- a/include/hardware/bt_common_types.h
+++ b/include/hardware/bt_common_types.h
@@ -70,6 +70,7 @@
      * the characteristic.
      */
     uint8_t             properties;
+    uint16_t            permissions;
 } btgatt_db_element_t;
 
 #endif  /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */
diff --git a/include/hardware/bt_gatt.h b/include/hardware/bt_gatt.h
index 42e14c2..414d3e4 100644
--- a/include/hardware/bt_gatt.h
+++ b/include/hardware/bt_gatt.h
@@ -19,6 +19,8 @@
 #define ANDROID_INCLUDE_BT_GATT_H
 
 #include <stdint.h>
+#include "ble_advertiser.h"
+#include "ble_scanner.h"
 #include "bt_gatt_client.h"
 #include "bt_gatt_server.h"
 
@@ -34,6 +36,9 @@
 
     /** GATT Server callbacks */
     const btgatt_server_callbacks_t* server;
+
+    /** LE scanner callbacks */
+    const btgatt_scanner_callbacks_t* scanner;
 } btgatt_callbacks_t;
 
 /** Represents the standard Bluetooth GATT interface. */
@@ -54,6 +59,12 @@
 
     /** Pointer to the GATT server interface methods.*/
     const btgatt_server_interface_t* server;
+
+    /** Pointer to the LE scanner interface methods.*/
+    const btgatt_scanner_interface_t* scanner;
+
+    /** Pointer to the advertiser interface methods.*/
+    BleAdvertiserInterface* advertiser;
 } btgatt_interface_t;
 
 __END_DECLS
diff --git a/include/hardware/bt_gatt_client.h b/include/hardware/bt_gatt_client.h
index e2c8a92..6c5a85e 100644
--- a/include/hardware/bt_gatt_client.h
+++ b/include/hardware/bt_gatt_client.h
@@ -19,9 +19,12 @@
 #define ANDROID_INCLUDE_BT_GATT_CLIENT_H
 
 #include <stdint.h>
+#include <vector>
 #include "bt_gatt_types.h"
 #include "bt_common_types.h"
 
+using std::vector;
+
 __BEGIN_DECLS
 
 /**
@@ -118,9 +121,6 @@
 typedef void (*register_client_callback)(int status, int client_if,
                 bt_uuid_t *app_uuid);
 
-/** Callback for scan results */
-typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, uint8_t* adv_data);
-
 /** GATT open callback invoked in response to open */
 typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
 
@@ -165,36 +165,9 @@
 typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
                                           int rssi, int status);
 
-/**
- * Callback indicating the status of a listen() operation
- */
-typedef void (*listen_callback)(int status, int server_if);
-
 /** Callback invoked when the MTU for a given connection changes */
 typedef void (*configure_mtu_callback)(int conn_id, int status, int mtu);
 
-/** 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);
-
-/** Callback invoked when multi-adv enable operation has completed */
-typedef void (*multi_adv_enable_callback)(int client_if, int status);
-
-/** Callback invoked when multi-adv param update operation has completed */
-typedef void (*multi_adv_update_callback)(int client_if, int status);
-
-/** Callback invoked when multi-adv instance data set operation has completed */
-typedef void (*multi_adv_data_callback)(int client_if, int status);
-
-/** Callback invoked when multi-adv disable operation has completed */
-typedef void (*multi_adv_disable_callback)(int client_if, int status);
 
 /**
  * Callback notifying an application that a remote device connection is currently congested
@@ -202,25 +175,6 @@
  * a further callback is received indicating the congestion status has been cleared.
  */
 typedef void (*congestion_callback)(int conn_id, bool congested);
-/** 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, int data_len, uint8_t* rep_data);
-
-/** Callback invoked when batchscan storage threshold limit is crossed */
-typedef void (*batchscan_threshold_callback)(int client_if);
-
-/** Track ADV VSE callback invoked when tracked device is found or lost */
-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);
 
 /** GATT get database callback */
 typedef void (*get_gatt_db_callback)(int conn_id, btgatt_db_element_t *db, int count);
@@ -233,7 +187,6 @@
 
 typedef struct {
     register_client_callback            register_client_cb;
-    scan_result_callback                scan_result_cb;
     connect_callback                    open_cb;
     disconnect_callback                 close_cb;
     search_complete_callback            search_complete_cb;
@@ -245,22 +198,8 @@
     write_descriptor_callback           write_descriptor_cb;
     execute_write_callback              execute_write_cb;
     read_remote_rssi_callback           read_remote_rssi_cb;
-    listen_callback                     listen_cb;
     configure_mtu_callback              configure_mtu_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;
-    multi_adv_enable_callback           multi_adv_enable_cb;
-    multi_adv_update_callback           multi_adv_update_cb;
-    multi_adv_data_callback             multi_adv_data_cb;
-    multi_adv_disable_callback          multi_adv_disable_cb;
     congestion_callback                 congestion_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;
     get_gatt_db_callback                get_gatt_db_cb;
     services_removed_callback           services_removed_cb;
     services_added_callback             services_added_cb;
@@ -275,9 +214,6 @@
     /** Unregister a client application from the stack */
     bt_status_t (*unregister_client)(int client_if );
 
-    /** Start or stop LE device scanning */
-    bt_status_t (*scan)( bool start );
-
     /** Create a connection to a remote LE or dual-mode device */
     bt_status_t (*connect)( int client_if, const bt_bdaddr_t *bd_addr,
                          bool is_direct, int transport );
@@ -286,9 +222,6 @@
     bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
                     int conn_id);
 
-    /** Start or stop advertisements to listen for incoming connections */
-    bt_status_t (*listen)(int client_if, bool start);
-
     /** Clear the attribute cache for a given device */
     bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
 
@@ -304,16 +237,15 @@
 
     /** Write a remote characteristic */
     bt_status_t (*write_characteristic)(int conn_id, uint16_t handle,
-                    int write_type, int len, int auth_req,
-                    char* p_value);
+                    int write_type, int auth_req,
+                    vector<uint8_t> value);
 
     /** Read the descriptor for a given characteristic */
     bt_status_t (*read_descriptor)(int conn_id, uint16_t handle, int auth_req);
 
     /** Write a remote descriptor for a given characteristic */
     bt_status_t (*write_descriptor)( int conn_id, uint16_t handle,
-                    int write_type, int len,
-                    int auth_req, char* p_value);
+                    int auth_req, vector<uint8_t> value);
 
     /** Execute a prepared write operation */
     bt_status_t (*execute_write)(int conn_id, int execute);
@@ -332,34 +264,9 @@
     /** Request RSSI for a given remote device */
     bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
 
-    /** Setup scan filter params */
-    bt_status_t (*scan_filter_param_setup)(btgatt_filt_param_setup_t filt_param);
-
-
-    /** Configure a scan filter condition  */
-    bt_status_t (*scan_filter_add_remove)(int client_if, 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, int data_len, char* p_data, int mask_len,
-                                   char* p_mask);
-
-    /** Clear all scan filter conditions for specific filter index*/
-    bt_status_t (*scan_filter_clear)(int client_if, int filt_index);
-
-    /** Enable / disable scan filter feature*/
-    bt_status_t (*scan_filter_enable)(int client_if, bool enable);
-
     /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
     int (*get_device_type)( const bt_bdaddr_t *bd_addr );
 
-    /** Set the advertising data or scan response data */
-    bt_status_t (*set_adv_data)(int client_if, bool set_scan_rsp, bool include_name,
-                    bool include_txpower, int min_interval, int max_interval, int appearance,
-                    uint16_t manufacturer_len, char* manufacturer_data,
-                    uint16_t service_data_len, char* service_data,
-                    uint16_t service_uuid_len, char* service_uuid);
-
     /** Configure the MTU for a given connection */
     bt_status_t (*configure_mtu)(int conn_id, int mtu);
 
@@ -367,40 +274,6 @@
     bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
                     int max_interval, int latency, int timeout);
 
-    /** Sets the LE scan interval and window in units of N*0.625 msec */
-    bt_status_t (*set_scan_parameters)(int client_if, int scan_interval, int scan_window);
-
-    /* Setup the parameters as per spec, user manual specified values and enable multi ADV */
-    bt_status_t (*multi_adv_enable)(int client_if, int min_interval,int max_interval,int adv_type,
-                 int chnl_map, int tx_power, int timeout_s);
-
-    /* Update the parameters as per spec, user manual specified values and restart multi ADV */
-    bt_status_t (*multi_adv_update)(int client_if, int min_interval,int max_interval,int adv_type,
-                 int chnl_map, int tx_power, int timeout_s);
-
-    /* Setup the data for the specified instance */
-    bt_status_t (*multi_adv_set_inst_data)(int client_if, bool set_scan_rsp, bool include_name,
-                    bool incl_txpower, int appearance, int manufacturer_len,
-                    char* manufacturer_data, int service_data_len,
-                    char* service_data, int service_uuid_len, char* service_uuid);
-
-    /* Disable the multi adv instance */
-    bt_status_t (*multi_adv_disable)(int client_if);
-
-    /* Configure the batchscan storage */
-    bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max,
-        int batch_scan_trunc_max, int batch_scan_notify_threshold);
-
-    /* Enable batchscan */
-    bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode,
-        int scan_interval, int scan_window, int addr_type, int discard_rule);
-
-    /* Disable batchscan */
-    bt_status_t (*batchscan_dis_batch_scan)(int client_if);
-
-    /* Read out batchscan reports */
-    bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode);
-
     /** Test mode interface */
     bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
 
diff --git a/include/hardware/bt_gatt_server.h b/include/hardware/bt_gatt_server.h
index 0d6cc1e..92af285 100644
--- a/include/hardware/bt_gatt_server.h
+++ b/include/hardware/bt_gatt_server.h
@@ -19,9 +19,12 @@
 #define ANDROID_INCLUDE_BT_GATT_SERVER_H
 
 #include <stdint.h>
+#include <vector>
 
 #include "bt_gatt_types.h"
 
+using std::vector;
+
 __BEGIN_DECLS
 
 /** GATT value type used in response to remote read requests */
@@ -53,23 +56,7 @@
 
 /** Callback invoked in response to create_service */
 typedef void (*service_added_callback)(int status, int server_if,
-                btgatt_srvc_id_t *srvc_id, int srvc_handle);
-
-/** Callback indicating that an included service has been added to a service */
-typedef void (*included_service_added_callback)(int status, int server_if,
-                int srvc_handle, int incl_srvc_handle);
-
-/** Callback invoked when a characteristic has been added to a service */
-typedef void (*characteristic_added_callback)(int status, int server_if,
-                bt_uuid_t *uuid, int srvc_handle, int char_handle);
-
-/** Callback invoked when a descriptor has been added to a characteristic */
-typedef void (*descriptor_added_callback)(int status, int server_if,
-                bt_uuid_t *uuid, int srvc_handle, int descr_handle);
-
-/** Callback invoked in response to start_service */
-typedef void (*service_started_callback)(int status, int server_if,
-                                         int srvc_handle);
+                                       vector<btgatt_db_element_t> service);
 
 /** Callback invoked in response to stop_service */
 typedef void (*service_stopped_callback)(int status, int server_if,
@@ -91,8 +78,8 @@
  * characteristic or descriptor.
  */
 typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
-                                       int attr_handle, int offset, int length,
-                                       bool need_rsp, bool is_prep, uint8_t* value);
+                                       int attr_handle, int offset, bool need_rsp,
+                                       bool is_prep, vector<uint8_t> value);
 
 /** Callback invoked when a previously prepared write is to be executed */
 typedef void (*request_exec_write_callback)(int conn_id, int trans_id,
@@ -124,14 +111,12 @@
     register_server_callback        register_server_cb;
     connection_callback             connection_cb;
     service_added_callback          service_added_cb;
-    included_service_added_callback included_service_added_cb;
-    characteristic_added_callback   characteristic_added_cb;
-    descriptor_added_callback       descriptor_added_cb;
-    service_started_callback        service_started_cb;
     service_stopped_callback        service_stopped_cb;
     service_deleted_callback        service_deleted_cb;
-    request_read_callback           request_read_cb;
-    request_write_callback          request_write_cb;
+    request_read_callback           request_read_characteristic_cb;
+    request_read_callback           request_read_descriptor_cb;
+    request_write_callback          request_write_characteristic_cb;
+    request_write_callback          request_write_descriptor_cb;
     request_exec_write_callback     request_exec_write_cb;
     response_confirmation_callback  response_confirmation_cb;
     indication_sent_callback        indication_sent_cb;
@@ -156,23 +141,7 @@
                     int conn_id );
 
     /** Create a new service */
-    bt_status_t (*add_service)( int server_if, btgatt_srvc_id_t *srvc_id, int num_handles);
-
-    /** Assign an included service to it's parent service */
-    bt_status_t (*add_included_service)( int server_if, int service_handle, int included_handle);
-
-    /** Add a characteristic to a service */
-    bt_status_t (*add_characteristic)( int server_if,
-                    int service_handle, bt_uuid_t *uuid,
-                    int properties, int permissions);
-
-    /** Add a descriptor to a given service */
-    bt_status_t (*add_descriptor)(int server_if, int service_handle,
-                                  bt_uuid_t *uuid, int permissions);
-
-    /** Starts a local service */
-    bt_status_t (*start_service)(int server_if, int service_handle,
-                                 int transport);
+    bt_status_t (*add_service)(int server_if, vector<btgatt_db_element_t> service);
 
     /** Stops a local service */
     bt_status_t (*stop_service)(int server_if, int service_handle);
@@ -182,8 +151,8 @@
 
     /** Send value indication to a remote device */
     bt_status_t (*send_indication)(int server_if, int attribute_handle,
-                                   int conn_id, int len, int confirm,
-                                   char* p_value);
+                                   int conn_id, int confirm,
+                                   vector<uint8_t> value);
 
     /** Send a response to a read/write operation */
     bt_status_t (*send_response)(int conn_id, int trans_id,
diff --git a/include/hardware/bt_hf_client.h b/include/hardware/bt_hf_client.h
index 8acf1b2..b728be3 100644
--- a/include/hardware/bt_hf_client.h
+++ b/include/hardware/bt_hf_client.h
@@ -167,104 +167,120 @@
  *  state will have one of the values from BtHfConnectionState
  *  peer/chld_features are valid only for BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state
  */
-typedef void (* bthf_client_connection_state_callback)(bthf_client_connection_state_t state,
+typedef void (* bthf_client_connection_state_callback)(const bt_bdaddr_t *bd_addr,
+                                                       bthf_client_connection_state_t state,
                                                        unsigned int peer_feat,
-                                                       unsigned int chld_feat,
-                                                       bt_bdaddr_t *bd_addr);
+                                                       unsigned int chld_feat);
 
 /** Callback for audio connection state change.
  *  state will have one of the values from BtHfAudioState
  */
-typedef void (* bthf_client_audio_state_callback)(bthf_client_audio_state_t state,
-                                                  bt_bdaddr_t *bd_addr);
+typedef void (* bthf_client_audio_state_callback)(const bt_bdaddr_t *bd_addr,
+                                                  bthf_client_audio_state_t state);
 
 /** Callback for VR connection state change.
  *  state will have one of the values from BtHfVRState
  */
-typedef void (* bthf_client_vr_cmd_callback)(bthf_client_vr_state_t state);
+typedef void (* bthf_client_vr_cmd_callback)(const bt_bdaddr_t *bd_addr, bthf_client_vr_state_t state);
 
 /** Callback for network state change
  */
-typedef void (* bthf_client_network_state_callback) (bthf_client_network_state_t state);
+typedef void (* bthf_client_network_state_callback) (const bt_bdaddr_t *bd_addr,
+                                                     bthf_client_network_state_t state);
 
 /** Callback for network roaming status change
  */
-typedef void (* bthf_client_network_roaming_callback) (bthf_client_service_type_t type);
+typedef void (* bthf_client_network_roaming_callback) (const bt_bdaddr_t *bd_addr,
+                                                       bthf_client_service_type_t type);
 
 /** Callback for signal strength indication
  */
-typedef void (* bthf_client_network_signal_callback) (int signal_strength);
+typedef void (* bthf_client_network_signal_callback) (const bt_bdaddr_t *bd_addr,
+                                                      int signal_strength);
 
 /** Callback for battery level indication
  */
-typedef void (* bthf_client_battery_level_callback) (int battery_level);
+typedef void (* bthf_client_battery_level_callback) (const bt_bdaddr_t *bd_addr,
+                                                     int battery_level);
 
 /** Callback for current operator name
  */
-typedef void (* bthf_client_current_operator_callback) (const char *name);
+typedef void (* bthf_client_current_operator_callback) (const bt_bdaddr_t *bd_addr,
+                                                        const char *name);
 
 /** Callback for call indicator
  */
-typedef void (* bthf_client_call_callback) (bthf_client_call_t call);
+typedef void (* bthf_client_call_callback) (const bt_bdaddr_t *bd_addr, bthf_client_call_t call);
 
 /** Callback for callsetup indicator
  */
-typedef void (* bthf_client_callsetup_callback) (bthf_client_callsetup_t callsetup);
+typedef void (* bthf_client_callsetup_callback) (const bt_bdaddr_t *bd_addr,
+                                                 bthf_client_callsetup_t callsetup);
 
 /** Callback for callheld indicator
  */
-typedef void (* bthf_client_callheld_callback) (bthf_client_callheld_t callheld);
+typedef void (* bthf_client_callheld_callback) (const bt_bdaddr_t *bd_addr,
+                                                bthf_client_callheld_t callheld);
 
 /** Callback for response and hold
  */
-typedef void (* bthf_client_resp_and_hold_callback) (bthf_client_resp_and_hold_t resp_and_hold);
+typedef void (* bthf_client_resp_and_hold_callback) (const bt_bdaddr_t *bd_addr,
+                                                     bthf_client_resp_and_hold_t resp_and_hold);
 
 /** Callback for Calling Line Identification notification
  *  Will be called only when there is an incoming call and number is provided.
  */
-typedef void (* bthf_client_clip_callback) (const char *number);
+typedef void (* bthf_client_clip_callback) (const bt_bdaddr_t *bd_addr, const char *number);
 
 /**
  * Callback for Call Waiting notification
  */
-typedef void (* bthf_client_call_waiting_callback) (const char *number);
+typedef void (* bthf_client_call_waiting_callback) (const bt_bdaddr_t *bd_addr, const char *number);
 
 /**
  *  Callback for listing current calls. Can be called multiple time.
  *  If number is unknown NULL is passed.
  */
-typedef void (*bthf_client_current_calls) (int index, bthf_client_call_direction_t dir,
+typedef void (*bthf_client_current_calls) (const bt_bdaddr_t *bd_addr, int index,
+                                           bthf_client_call_direction_t dir,
                                            bthf_client_call_state_t state,
                                            bthf_client_call_mpty_type_t mpty,
                                            const char *number);
 
 /** Callback for audio volume change
  */
-typedef void (*bthf_client_volume_change_callback) (bthf_client_volume_type_t type, int volume);
+typedef void (*bthf_client_volume_change_callback) (const bt_bdaddr_t *bd_addr,
+                                                    bthf_client_volume_type_t type,
+                                                    int volume);
 
 /** Callback for command complete event
  *  cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type
  */
-typedef void (*bthf_client_cmd_complete_callback) (bthf_client_cmd_complete_t type, int cme);
+typedef void (*bthf_client_cmd_complete_callback) (const bt_bdaddr_t *bd_addr,
+                                                   bthf_client_cmd_complete_t type,
+                                                   int cme);
 
 /** Callback for subscriber information
  */
-typedef void (* bthf_client_subscriber_info_callback) (const char *name,
+typedef void (* bthf_client_subscriber_info_callback) (const bt_bdaddr_t *bd_addr,
+                                                       const char *name,
                                                        bthf_client_subscriber_service_type_t type);
 
 /** Callback for in-band ring tone settings
  */
-typedef void (* bthf_client_in_band_ring_tone_callback) (bthf_client_in_band_ring_state_t state);
+typedef void (* bthf_client_in_band_ring_tone_callback) (const bt_bdaddr_t *bd_addr,
+                                                         bthf_client_in_band_ring_state_t state);
 
 /**
  * Callback for requested number from AG
  */
-typedef void (* bthf_client_last_voice_tag_number_callback) (const char *number);
+typedef void (* bthf_client_last_voice_tag_number_callback) (const bt_bdaddr_t *bd_addr,
+                                                             const char *number);
 
 /**
  * Callback for sending ring indication to app
  */
-typedef void (* bthf_client_ring_indication_callback) (void);
+typedef void (* bthf_client_ring_indication_callback) (const bt_bdaddr_t *bd_addr);
 
 /** BT-HF callback structure. */
 typedef struct {
@@ -307,55 +323,59 @@
     bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
 
     /** disconnect from audio gateway */
-    bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);
 
     /** create an audio connection */
-    bt_status_t (*connect_audio)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*connect_audio)(const bt_bdaddr_t *bd_addr);
 
     /** close the audio connection */
-    bt_status_t (*disconnect_audio)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*disconnect_audio)(const bt_bdaddr_t *bd_addr);
 
     /** start voice recognition */
-    bt_status_t (*start_voice_recognition)(void);
+    bt_status_t (*start_voice_recognition)(const bt_bdaddr_t *bd_addr);
 
     /** stop voice recognition */
-    bt_status_t (*stop_voice_recognition)(void);
+    bt_status_t (*stop_voice_recognition)(const bt_bdaddr_t *bd_addr);
 
     /** volume control */
-    bt_status_t (*volume_control) (bthf_client_volume_type_t type, int volume);
+    bt_status_t (*volume_control) (const bt_bdaddr_t *bd_addr,
+                                   bthf_client_volume_type_t type,
+                                   int volume);
 
     /** place a call with number a number
      * if number is NULL last called number is called (aka re-dial)*/
-    bt_status_t (*dial) (const char *number);
+    bt_status_t (*dial) (const bt_bdaddr_t *bd_addr, const char *number);
 
     /** place a call with number specified by location (speed dial) */
-    bt_status_t (*dial_memory) (int location);
+    bt_status_t (*dial_memory) (const bt_bdaddr_t *bd_addr, int location);
 
     /** perform specified call related action
      * idx is limited only for enhanced call control related action
      */
-    bt_status_t (*handle_call_action) (bthf_client_call_action_t action, int idx);
+    bt_status_t (*handle_call_action) (const bt_bdaddr_t *bd_addr,
+                                       bthf_client_call_action_t action,
+                                       int idx);
 
     /** query list of current calls */
-    bt_status_t (*query_current_calls) (void);
+    bt_status_t (*query_current_calls) (const bt_bdaddr_t *bd_addr);
 
     /** query name of current selected operator */
-    bt_status_t (*query_current_operator_name) (void);
+    bt_status_t (*query_current_operator_name) (const bt_bdaddr_t *bd_addr);
 
     /** Retrieve subscriber information */
-    bt_status_t (*retrieve_subscriber_info) (void);
+    bt_status_t (*retrieve_subscriber_info) (const bt_bdaddr_t *bd_addr);
 
     /** Send DTMF code*/
-    bt_status_t (*send_dtmf) (char code);
+    bt_status_t (*send_dtmf) (const bt_bdaddr_t *bd_addr, char code);
 
     /** Request a phone number from AG corresponding to last voice tag recorded */
-    bt_status_t (*request_last_voice_tag_number) (void);
+    bt_status_t (*request_last_voice_tag_number) (const bt_bdaddr_t *bd_addr);
 
     /** Closes the interface. */
     void (*cleanup)(void);
 
     /** Send AT Command. */
-    bt_status_t (*send_at_cmd) (int cmd, int val1, int val2, const char *arg);
+    bt_status_t (*send_at_cmd) (const bt_bdaddr_t *bd_addr, int cmd, int val1, int val2, const char *arg);
 } bthf_client_interface_t;
 
 __END_DECLS
diff --git a/include/hardware/bt_rc.h b/include/hardware/bt_rc.h
index 1e2c293..71a8901 100644
--- a/include/hardware/bt_rc.h
+++ b/include/hardware/bt_rc.h
@@ -19,17 +19,69 @@
 
 __BEGIN_DECLS
 
+/* Change this macro to use multiple RC */
+#define BT_RC_NUM_APP 1
+
 /* Macros */
-#define BTRC_MAX_ATTR_STR_LEN       255
+#define BTRC_MAX_ATTR_STR_LEN       (1 << 16)
 #define BTRC_UID_SIZE               8
 #define BTRC_MAX_APP_SETTINGS       8
 #define BTRC_MAX_FOLDER_DEPTH       4
 #define BTRC_MAX_APP_ATTR_SIZE      16
-#define BTRC_MAX_ELEM_ATTR_SIZE     7
+#define BTRC_MAX_ELEM_ATTR_SIZE     8
+#define BTRC_FEATURE_BIT_MASK_SIZE 16
+
+/* Macros for valid scopes in get_folder_items */
+#define BTRC_SCOPE_PLAYER_LIST  0x00 /* Media Player List */
+#define BTRC_SCOPE_FILE_SYSTEM  0x01 /* Virtual File System */
+#define BTRC_SCOPE_SEARCH  0x02 /* Search */
+#define BTRC_SCOPE_NOW_PLAYING   0x03 /* Now Playing */
+
+/* Macros for supported character encoding */
+#define BTRC_CHARSET_ID_UTF8  0x006A
+
+/* Macros for item types */
+#define BTRC_ITEM_PLAYER  0x01 /* Media Player */
+#define BTRC_ITEM_FOLDER  0x02 /* Folder */
+#define BTRC_ITEM_MEDIA   0x03 /* Media File */
+
+/* Macros for media attribute IDs */
+#define BTRC_MEDIA_ATTR_ID_INVALID               -1
+#define BTRC_MEDIA_ATTR_ID_TITLE                 0x00000001
+#define BTRC_MEDIA_ATTR_ID_ARTIST                0x00000002
+#define BTRC_MEDIA_ATTR_ID_ALBUM                 0x00000003
+#define BTRC_MEDIA_ATTR_ID_TRACK_NUM             0x00000004
+#define BTRC_MEDIA_ATTR_ID_NUM_TRACKS            0x00000005
+#define BTRC_MEDIA_ATTR_ID_GENRE                 0x00000006
+#define BTRC_MEDIA_ATTR_ID_PLAYING_TIME          0x00000007        /* in miliseconds */
+
+/* Macros for folder types */
+#define BTRC_FOLDER_TYPE_MIXED      0x00
+#define BTRC_FOLDER_TYPE_TITLES     0x01
+#define BTRC_FOLDER_TYPE_ALBUMS     0x02
+#define BTRC_FOLDER_TYPE_ARTISTS    0x03
+#define BTRC_FOLDER_TYPE_GENRES     0x04
+#define BTRC_FOLDER_TYPE_PLAYLISTS  0x05
+#define BTRC_FOLDER_TYPE_YEARS      0x06
+
+/* Macros for media types */
+#define BTRC_MEDIA_TYPE_AUDIO  0x00 /* audio */
+#define BTRC_MEDIA_TYPE_VIDEO  0x01 /* video */
+
+/* Macros for num attributes */
+#define BTRC_NUM_ATTR_NONE 0xFF /* No attributes required */
+#define BTRC_NUM_ATTR_ALL  0X00 /* All attributes required */
+
+#define BTRC_HANDLE_NONE 0xFF
 
 typedef uint8_t btrc_uid_t[BTRC_UID_SIZE];
 
 typedef enum {
+    BTRC_CONNECTION_STATE_DISCONNECTED = 0,
+    BTRC_CONNECTION_STATE_CONNECTED
+} btrc_connection_state_t;
+
+typedef enum {
     BTRC_FEAT_NONE = 0x00,    /* AVRCP 1.0 */
     BTRC_FEAT_METADATA = 0x01,    /* AVRCP 1.3 */
     BTRC_FEAT_ABSOLUTE_VOLUME = 0x02,    /* Supports TG role and volume sync */
@@ -52,6 +104,11 @@
     BTRC_EVT_TRACK_REACHED_START = 0x04,
     BTRC_EVT_PLAY_POS_CHANGED = 0x05,
     BTRC_EVT_APP_SETTINGS_CHANGED = 0x08,
+    BTRC_EVT_NOW_PLAYING_CONTENT_CHANGED = 0x09,
+    BTRC_EVT_AVAL_PLAYER_CHANGE = 0x0a,
+    BTRC_EVT_ADDR_PLAYER_CHANGE = 0x0b,
+    BTRC_EVT_UIDS_CHANGED = 0x0c,
+    BTRC_EVT_VOL_CHANGED = 0x0d,
 } btrc_event_id_t;
 
 typedef enum {
@@ -94,10 +151,33 @@
     BTRC_STS_BAD_PARAM      = 0x01, /* Invalid parameter */
     BTRC_STS_NOT_FOUND      = 0x02, /* Specified parameter is wrong or not found */
     BTRC_STS_INTERNAL_ERR   = 0x03, /* Internal Error */
-    BTRC_STS_NO_ERROR       = 0x04  /* Operation Success */
+    BTRC_STS_NO_ERROR       = 0x04, /* Operation Success */
+    BTRC_STS_UID_CHANGED    = 0x05, /* UIDs changed */
+    BTRC_STS_RESERVED       = 0x06, /* Reserved */
+    BTRC_STS_INV_DIRN       = 0x07, /* Invalid direction */
+    BTRC_STS_INV_DIRECTORY  = 0x08, /* Invalid directory */
+    BTRC_STS_INV_ITEM       = 0x09, /* Invalid Item */
+    BTRC_STS_INV_SCOPE      = 0x0a, /* Invalid scope */
+    BTRC_STS_INV_RANGE      = 0x0b, /* Invalid range */
+    BTRC_STS_DIRECTORY      = 0x0c, /* UID is a directory */
+    BTRC_STS_MEDIA_IN_USE   = 0x0d, /* Media in use */
+    BTRC_STS_PLAY_LIST_FULL = 0x0e, /* Playing list full */
+    BTRC_STS_SRCH_NOT_SPRTD = 0x0f, /* Search not supported */
+    BTRC_STS_SRCH_IN_PROG   = 0x10, /* Search in progress */
+    BTRC_STS_INV_PLAYER     = 0x11, /* Invalid player */
+    BTRC_STS_PLAY_NOT_BROW  = 0x12, /* Player not browsable */
+    BTRC_STS_PLAY_NOT_ADDR  = 0x13, /* Player not addressed */
+    BTRC_STS_INV_RESULTS    = 0x14, /* Invalid results */
+    BTRC_STS_NO_AVBL_PLAY   = 0x15, /* No available players */
+    BTRC_STS_ADDR_PLAY_CHGD = 0x16, /* Addressed player changed */
 } btrc_status_t;
 
 typedef struct {
+    uint16_t player_id;
+    uint16_t uid_counter;
+} btrc_addr_player_changed_t;
+
+typedef struct {
     uint8_t num_attr;
     uint8_t attr_ids[BTRC_MAX_APP_SETTINGS];
     uint8_t attr_values[BTRC_MAX_APP_SETTINGS];
@@ -133,12 +213,25 @@
     uint8_t  attr_count;
 } btrc_getfolderitem_t;
 
+typedef struct {
+    uint16_t type;
+    uint16_t uid_counter;
+} btrc_uids_changed_t;
+
+typedef struct {
+    uint16_t type;
+} btrc_now_playing_changed_t;
+
 typedef union
 {
     btrc_play_status_t play_status;
     btrc_uid_t track; /* queue position in NowPlaying */
     uint32_t song_pos;
+    uint16_t uid_counter;
     btrc_player_settings_t player_setting;
+    btrc_addr_player_changed_t addr_player_changed;
+    btrc_uids_changed_t uids_changed;
+    btrc_now_playing_changed_t now_playing_changed;
 } btrc_register_notification_t;
 
 typedef struct {
@@ -151,55 +244,215 @@
     uint8_t text[BTRC_MAX_ATTR_STR_LEN];
 } btrc_element_attr_val_t;
 
+typedef struct {
+    uint16_t  player_id;
+    uint8_t   major_type;
+    uint32_t  sub_type;
+    uint8_t   play_status;
+    uint8_t   features[BTRC_FEATURE_BIT_MASK_SIZE];
+    uint16_t  charset_id;
+    uint8_t   name[BTRC_MAX_ATTR_STR_LEN];
+} btrc_item_player_t;
+
+typedef struct {
+    uint8_t   uid[BTRC_UID_SIZE];
+    uint8_t   type;
+    uint8_t   playable;
+    uint16_t  charset_id;
+    uint8_t   name[BTRC_MAX_ATTR_STR_LEN];
+} btrc_item_folder_t;
+
+typedef struct {
+    uint8_t  uid[BTRC_UID_SIZE];
+    uint8_t  type;
+    uint16_t charset_id;
+    uint8_t  name[BTRC_MAX_ATTR_STR_LEN];
+    int      num_attrs;
+    btrc_element_attr_val_t* p_attrs;
+} btrc_item_media_t;
+
+typedef struct {
+    uint8_t item_type;
+    union
+    {
+        btrc_item_player_t player;
+        btrc_item_folder_t folder;
+        btrc_item_media_t  media;
+    };
+} btrc_folder_items_t;
+
+typedef struct {
+    uint16_t  str_len;
+    uint8_t   p_str[BTRC_MAX_ATTR_STR_LEN];
+} btrc_br_folder_name_t;
+
 /** Callback for the controller's supported feautres */
 typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
                                                       btrc_remote_features_t features);
 
 /** Callback for play status request */
-typedef void (* btrc_get_play_status_callback)();
+typedef void (* btrc_get_play_status_callback)(bt_bdaddr_t *bd_addr);
 
 /** Callback for list player application attributes (Shuffle, Repeat,...) */
-typedef void (* btrc_list_player_app_attr_callback)();
+typedef void (* btrc_list_player_app_attr_callback)(bt_bdaddr_t *bd_addr);
 
 /** Callback for list player application attributes (Shuffle, Repeat,...) */
-typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id);
+typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id,
+    bt_bdaddr_t *bd_addr);
 
 /** Callback for getting the current player application settings value
 **  num_attr: specifies the number of attribute ids contained in p_attrs
 */
-typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
+typedef void (* btrc_get_player_app_value_callback) (uint8_t num_attr,
+    btrc_player_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
 
 /** Callback for getting the player application settings attributes' text
 **  num_attr: specifies the number of attribute ids contained in p_attrs
 */
-typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr, btrc_player_attr_t *p_attrs);
+typedef void (* btrc_get_player_app_attrs_text_callback) (uint8_t num_attr,
+    btrc_player_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
 
 /** Callback for getting the player application settings values' text
 **  num_attr: specifies the number of value ids contained in p_vals
 */
-typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val, uint8_t *p_vals);
+typedef void (* btrc_get_player_app_values_text_callback) (uint8_t attr_id, uint8_t num_val,
+    uint8_t *p_vals, bt_bdaddr_t *bd_addr);
 
 /** Callback for setting the player application settings values */
-typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals);
+typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals,
+    bt_bdaddr_t *bd_addr);
 
 /** Callback to fetch the get element attributes of the current song
 **  num_attr: specifies the number of attributes requested in p_attrs
 */
-typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs);
+typedef void (* btrc_get_element_attr_callback) (uint8_t num_attr, btrc_media_attr_t *p_attrs,
+    bt_bdaddr_t *bd_addr);
 
 /** Callback for register notification (Play state change/track change/...)
 **  param: Is only valid if event_id is BTRC_EVT_PLAY_POS_CHANGED
 */
-typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param);
+typedef void (* btrc_register_notification_callback) (btrc_event_id_t event_id, uint32_t param,
+    bt_bdaddr_t *bd_addr);
 
 /* AVRCP 1.4 Enhancements */
 /** Callback for volume change on CT
 **  volume: Current volume setting on the CT (0-127)
 */
-typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype);
+typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype, bt_bdaddr_t *bd_addr);
 
 /** Callback for passthrough commands */
-typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state);
+typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+**  num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+              uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+                uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+**  num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+                uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+                uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+                uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+                uint8_t* uid, uint16_t  uid_counter, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+**  num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+              uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+                uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+**  num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+                uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+                uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+                uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+                uint8_t* uid, uint16_t  uid_counter, bt_bdaddr_t *bd_addr);
+
+/** Callback for set addressed player response on TG **/
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for set browsed player response on TG **/
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, bt_bdaddr_t *bd_addr);
+
+/** Callback for get folder items on TG
+**  num_attr: specifies the number of attributes requested in p_attr_ids
+*/
+typedef void (* btrc_get_folder_items_callback) (uint8_t scope, uint32_t start_item,
+              uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, bt_bdaddr_t *bd_addr);
+
+/** Callback for changing browsed path on TG **/
+typedef void (* btrc_change_path_callback) (uint8_t direction,
+                uint8_t* folder_uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch the get item attributes of the media item
+**  num_attr: specifies the number of attributes requested in p_attrs
+*/
+typedef void (* btrc_get_item_attr_callback) (uint8_t scope, uint8_t* uid, uint16_t uid_counter,
+                uint8_t num_attr, btrc_media_attr_t *p_attrs, bt_bdaddr_t *bd_addr);
+
+/** Callback for play request for the media item indicated by an identifier */
+typedef void (* btrc_play_item_callback) (uint8_t scope,
+                uint16_t uid_counter, uint8_t* uid, bt_bdaddr_t *bd_addr);
+
+/** Callback to fetch total number of items from a folder **/
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, bt_bdaddr_t *bd_addr);
+
+/** Callback for conducting recursive search on a current browsed path for a specified string */
+typedef void (* btrc_search_callback) (uint16_t charset_id,
+                uint16_t str_len, uint8_t* p_str, bt_bdaddr_t *bd_addr);
+
+/** Callback to add a specified media item indicated by an identifier to now playing queue. */
+typedef void (* btrc_add_to_now_playing_callback) (uint8_t scope,
+                uint8_t* uid, uint16_t  uid_counter, bt_bdaddr_t *bd_addr);
 
 /** BT-RC Target callback structure. */
 typedef struct {
@@ -217,6 +470,15 @@
     btrc_register_notification_callback         register_notification_cb;
     btrc_volume_change_callback                 volume_change_cb;
     btrc_passthrough_cmd_callback               passthrough_cmd_cb;
+    btrc_set_addressed_player_callback          set_addressed_player_cb;
+    btrc_set_browsed_player_callback            set_browsed_player_cb;
+    btrc_get_folder_items_callback              get_folder_items_cb;
+    btrc_change_path_callback                   change_path_cb;
+    btrc_get_item_attr_callback                 get_item_attr_cb;
+    btrc_play_item_callback                     play_item_cb;
+    btrc_get_total_num_of_items_callback        get_total_num_of_items_cb;
+    btrc_search_callback                        search_cb;
+    btrc_add_to_now_playing_callback            add_to_now_playing_cb;
 } btrc_callbacks_t;
 
 /** Represents the standard BT-RC AVRCP Target interface. */
@@ -234,40 +496,45 @@
     **  2. Song duration/length
     **  3. Song position
     */
-    bt_status_t (*get_play_status_rsp)( btrc_play_status_t play_status, uint32_t song_len, uint32_t song_pos);
+    bt_status_t (*get_play_status_rsp)( bt_bdaddr_t *bd_addr, btrc_play_status_t play_status,
+        uint32_t song_len, uint32_t song_pos);
 
     /** Lists the support player application attributes (Shuffle/Repeat/...)
     **  num_attr: Specifies the number of attributes contained in the pointer p_attrs
     */
-    bt_status_t (*list_player_app_attr_rsp)( int num_attr, btrc_player_attr_t *p_attrs);
+    bt_status_t (*list_player_app_attr_rsp)( bt_bdaddr_t *bd_addr, int num_attr,
+        btrc_player_attr_t *p_attrs);
 
     /** Lists the support player application attributes (Shuffle Off/On/Group)
     **  num_val: Specifies the number of values contained in the pointer p_vals
     */
-    bt_status_t (*list_player_app_value_rsp)( int num_val, uint8_t *p_vals);
+    bt_status_t (*list_player_app_value_rsp)( bt_bdaddr_t *bd_addr, int num_val, uint8_t *p_vals);
 
     /** Returns the current application attribute values for each of the specified attr_id */
-    bt_status_t (*get_player_app_value_rsp)( btrc_player_settings_t *p_vals);
+    bt_status_t (*get_player_app_value_rsp)( bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals);
 
     /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
     **  num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
     */
-    bt_status_t (*get_player_app_attr_text_rsp)( int num_attr, btrc_player_setting_text_t *p_attrs);
+    bt_status_t (*get_player_app_attr_text_rsp)( bt_bdaddr_t *bd_addr, int num_attr,
+        btrc_player_setting_text_t *p_attrs);
 
     /** Returns the application attributes text ("Shuffle"/"Repeat"/...)
     **  num_attr: Specifies the number of attribute values' text contained in the pointer p_vals
     */
-    bt_status_t (*get_player_app_value_text_rsp)( int num_val, btrc_player_setting_text_t *p_vals);
+    bt_status_t (*get_player_app_value_text_rsp)( bt_bdaddr_t *bd_addr, int num_val,
+        btrc_player_setting_text_t *p_vals);
 
     /** Returns the current songs' element attributes text ("Title"/"Album"/"Artist")
     **  num_attr: Specifies the number of attributes' text contained in the pointer p_attrs
     */
-    bt_status_t (*get_element_attr_rsp)( uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
+    bt_status_t (*get_element_attr_rsp)( bt_bdaddr_t *bd_addr, uint8_t num_attr,
+        btrc_element_attr_val_t *p_attrs);
 
     /** Response to set player attribute request ("Shuffle"/"Repeat")
     **  rsp_status: Status of setting the player attributes for the current media player
     */
-    bt_status_t (*set_player_app_value_rsp)(btrc_status_t rsp_status);
+    bt_status_t (*set_player_app_value_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
 
     /* Response to the register notification request (Play state change/track change/...).
     ** event_id: Refers to the event_id this notification change corresponds too
@@ -287,16 +554,52 @@
     */
     bt_status_t (*set_volume)(uint8_t volume);
 
+    /* Set addressed player response from TG to CT */
+    bt_status_t (*set_addressed_player_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+    /* Set browsed player response from TG to CT */
+    bt_status_t (*set_browsed_player_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+        uint32_t num_items, uint16_t charset_id, uint8_t folder_depth,
+        btrc_br_folder_name_t *p_folders);
+
+    /* Get folder item list response from TG to CT */
+     bt_status_t (*get_folder_items_list_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+        uint16_t uid_counter, uint8_t num_items, btrc_folder_items_t *p_items);
+
+    /* Change path response from TG to CT */
+    bt_status_t (*change_path_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+        uint32_t num_items);
+
+    /** Returns the element's attributes num_attr: Specifies the number of attributes' text
+     * contained in the pointer p_attrs
+     */
+    bt_status_t (*get_item_attr_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+        uint8_t num_attr, btrc_element_attr_val_t *p_attrs);
+
+    /* play media item response from TG to CT */
+    bt_status_t (*play_item_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
+    /* get total number of items response from TG to CT*/
+    bt_status_t (*get_total_num_of_items_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status,
+        uint32_t uid_counter, uint32_t num_items);
+
+    /* Search VFS response from TG to CT */
+    bt_status_t (*search_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status, uint32_t uid_counter,
+        uint32_t num_items);
+
+    /* add_to_now playing list response from TG to CT */
+    bt_status_t (*add_to_now_playing_rsp)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+
     /** Closes the interface. */
     void  (*cleanup)( void );
 } btrc_interface_t;
 
-
-typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
+typedef void (* btrc_passthrough_rsp_callback) (bt_bdaddr_t *bd_addr, int id, int key_state);
 
 typedef void (* btrc_groupnavigation_rsp_callback) (int id, int key_state);
 
-typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
+typedef void (* btrc_connection_state_callback) (
+    bool rc_connect, bool bt_connect, bt_bdaddr_t *bd_addr);
 
 typedef void (* btrc_ctrl_getrcfeatures_callback) (bt_bdaddr_t *bd_addr, int features);
 
@@ -325,6 +628,16 @@
 typedef void (* btrc_ctrl_play_status_changed_callback)(bt_bdaddr_t *bd_addr,
                                                             btrc_play_status_t play_status);
 
+typedef void (* btrc_ctrl_get_folder_items_callback )(bt_bdaddr_t *bd_addr,
+                                                            btrc_status_t status,
+                                                            const btrc_folder_items_t *folder_items,
+                                                            uint8_t count);
+
+typedef void (* btrc_ctrl_change_path_callback)(bt_bdaddr_t *bd_addr, uint8_t count);
+
+typedef void (* btrc_ctrl_set_browsed_player_callback )(
+    bt_bdaddr_t *bd_addr, uint8_t num_items, uint8_t depth);
+typedef void (* btrc_ctrl_set_addressed_player_callback)(bt_bdaddr_t *bd_addr, uint8_t status);
 /** BT-RC Controller callback structure. */
 typedef struct {
     /** set to sizeof(BtRcCallbacks) */
@@ -341,6 +654,10 @@
     btrc_ctrl_track_changed_callback                            track_changed_cb;
     btrc_ctrl_play_position_changed_callback                    play_position_changed_cb;
     btrc_ctrl_play_status_changed_callback                      play_status_changed_cb;
+    btrc_ctrl_get_folder_items_callback                         get_folder_items_cb;
+    btrc_ctrl_change_path_callback                              change_folder_path_cb;
+    btrc_ctrl_set_browsed_player_callback                       set_browsed_player_cb;
+    btrc_ctrl_set_addressed_player_callback                     set_addressed_player_cb;
 } btrc_ctrl_callbacks_t;
 
 /** Represents the standard BT-RC AVRCP Controller interface. */
@@ -365,6 +682,31 @@
     bt_status_t (*set_player_app_setting_cmd) (bt_bdaddr_t *bd_addr, uint8_t num_attrib,
             uint8_t* attrib_ids, uint8_t* attrib_vals);
 
+    /** send command to play a particular item */
+    bt_status_t (*play_item_cmd) (
+        bt_bdaddr_t *bd_addr, uint8_t scope, uint8_t *uid, uint16_t uid_counter);
+
+    /** get the playback state */
+    bt_status_t (*get_playback_state_cmd) (bt_bdaddr_t *bd_addr);
+
+    /** get the now playing list */
+    bt_status_t (*get_now_playing_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+    /** get the folder list */
+    bt_status_t (*get_folder_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+    /** get the folder list */
+    bt_status_t (*get_player_list_cmd) (bt_bdaddr_t *bd_addr, uint8_t start, uint8_t items);
+
+    /** get the folder list */
+    bt_status_t (*change_folder_path_cmd) (bt_bdaddr_t *bd_addr, uint8_t direction, uint8_t * uid);
+
+    /** set browsed player */
+    bt_status_t (*set_browsed_player_cmd) (bt_bdaddr_t *bd_addr, uint16_t player_id);
+
+    /** set addressed player */
+    bt_status_t (*set_addressed_player_cmd) (bt_bdaddr_t *bd_addr, uint16_t player_id);
+
     /** send rsp to set_abs_vol received from target */
     bt_status_t (*set_volume_rsp) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
 
diff --git a/include/hardware/camera2.h b/include/hardware/camera2.h
index 2b7add0..547a1d7 100644
--- a/include/hardware/camera2.h
+++ b/include/hardware/camera2.h
@@ -146,7 +146,7 @@
 typedef struct camera2_jpeg_blob {
     uint16_t jpeg_blob_id;
     uint32_t jpeg_size;
-};
+} camera2_jpeg_blob_t;
 
 enum {
     CAMERA2_JPEG_BLOB_ID = 0x00FF
diff --git a/include/hardware/context_hub.h b/include/hardware/context_hub.h
index 828f2dd..aaa4274 100644
--- a/include/hardware/context_hub.h
+++ b/include/hardware/context_hub.h
@@ -78,17 +78,17 @@
 #define NANOAPP_VENDOR_ALL_APPS       0x0000000000FFFFFFULL
 
 #define NANOAPP_VENDOR(name) \
-    (((uint64_t)name[0] << 56) | \
-    ((uint64_t)name[1] << 48) | \
-    ((uint64_t)name[2] << 40) | \
-    ((uint64_t)name[3] << 32) | \
-    ((uint64_t)name[4] << 24))
+    (((uint64_t)(name)[0] << 56) | \
+    ((uint64_t)(name)[1] << 48) | \
+    ((uint64_t)(name)[2] << 40) | \
+    ((uint64_t)(name)[3] << 32) | \
+    ((uint64_t)(name)[4] << 24))
 
 /*
  * generates the NANOAPP ID from vendor id and app seq# id
  */
 #define NANO_APP_ID(vendor, seq_id) \
-	(((uint64_t)vendor & NANOAPP_VENDORS_ALL) | ((uint64_t)seq_id & NANOAPP_VENDOR_ALL_APPS))
+	(((uint64_t)(vendor) & NANOAPP_VENDORS_ALL) | ((uint64_t)(seq_id) & NANOAPP_VENDOR_ALL_APPS))
 
 struct hub_app_name_t {
     uint64_t id;
diff --git a/include/hardware/fb.h b/include/hardware/fb.h
index 9df9416..65720a3 100644
--- a/include/hardware/fb.h
+++ b/include/hardware/fb.h
@@ -160,7 +160,7 @@
 static inline int framebuffer_open(const struct hw_module_t* module,
         struct framebuffer_device_t** device) {
     return module->methods->open(module,
-            GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
+            GRALLOC_HARDWARE_FB0, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int framebuffer_close(struct framebuffer_device_t* device) {
diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h
index 779915c..1b06ebf 100644
--- a/include/hardware/gralloc.h
+++ b/include/hardware/gralloc.h
@@ -68,69 +68,69 @@
 
 enum {
     /* buffer is never read in software */
-    GRALLOC_USAGE_SW_READ_NEVER         = 0x00000000,
+    GRALLOC_USAGE_SW_READ_NEVER         = 0x00000000U,
     /* buffer is rarely read in software */
-    GRALLOC_USAGE_SW_READ_RARELY        = 0x00000002,
+    GRALLOC_USAGE_SW_READ_RARELY        = 0x00000002U,
     /* buffer is often read in software */
-    GRALLOC_USAGE_SW_READ_OFTEN         = 0x00000003,
+    GRALLOC_USAGE_SW_READ_OFTEN         = 0x00000003U,
     /* mask for the software read values */
-    GRALLOC_USAGE_SW_READ_MASK          = 0x0000000F,
+    GRALLOC_USAGE_SW_READ_MASK          = 0x0000000FU,
 
     /* buffer is never written in software */
-    GRALLOC_USAGE_SW_WRITE_NEVER        = 0x00000000,
+    GRALLOC_USAGE_SW_WRITE_NEVER        = 0x00000000U,
     /* buffer is rarely written in software */
-    GRALLOC_USAGE_SW_WRITE_RARELY       = 0x00000020,
+    GRALLOC_USAGE_SW_WRITE_RARELY       = 0x00000020U,
     /* buffer is often written in software */
-    GRALLOC_USAGE_SW_WRITE_OFTEN        = 0x00000030,
+    GRALLOC_USAGE_SW_WRITE_OFTEN        = 0x00000030U,
     /* mask for the software write values */
-    GRALLOC_USAGE_SW_WRITE_MASK         = 0x000000F0,
+    GRALLOC_USAGE_SW_WRITE_MASK         = 0x000000F0U,
 
     /* buffer will be used as an OpenGL ES texture */
-    GRALLOC_USAGE_HW_TEXTURE            = 0x00000100,
+    GRALLOC_USAGE_HW_TEXTURE            = 0x00000100U,
     /* buffer will be used as an OpenGL ES render target */
-    GRALLOC_USAGE_HW_RENDER             = 0x00000200,
+    GRALLOC_USAGE_HW_RENDER             = 0x00000200U,
     /* buffer will be used by the 2D hardware blitter */
-    GRALLOC_USAGE_HW_2D                 = 0x00000400,
+    GRALLOC_USAGE_HW_2D                 = 0x00000400U,
     /* buffer will be used by the HWComposer HAL module */
-    GRALLOC_USAGE_HW_COMPOSER           = 0x00000800,
+    GRALLOC_USAGE_HW_COMPOSER           = 0x00000800U,
     /* buffer will be used with the framebuffer device */
-    GRALLOC_USAGE_HW_FB                 = 0x00001000,
+    GRALLOC_USAGE_HW_FB                 = 0x00001000U,
 
     /* buffer should be displayed full-screen on an external display when
      * possible */
-    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000,
+    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000U,
 
     /* Must have a hardware-protected path to external display sink for
      * this buffer.  If a hardware-protected path is not available, then
      * either don't composite only this buffer (preferred) to the
      * external sink, or (less desirable) do not route the entire
      * composition to the external sink.  */
-    GRALLOC_USAGE_PROTECTED             = 0x00004000,
+    GRALLOC_USAGE_PROTECTED             = 0x00004000U,
 
     /* buffer may be used as a cursor */
-    GRALLOC_USAGE_CURSOR                = 0x00008000,
+    GRALLOC_USAGE_CURSOR                = 0x00008000U,
 
     /* buffer will be used with the HW video encoder */
-    GRALLOC_USAGE_HW_VIDEO_ENCODER      = 0x00010000,
+    GRALLOC_USAGE_HW_VIDEO_ENCODER      = 0x00010000U,
     /* buffer will be written by the HW camera pipeline */
-    GRALLOC_USAGE_HW_CAMERA_WRITE       = 0x00020000,
+    GRALLOC_USAGE_HW_CAMERA_WRITE       = 0x00020000U,
     /* buffer will be read by the HW camera pipeline */
-    GRALLOC_USAGE_HW_CAMERA_READ        = 0x00040000,
+    GRALLOC_USAGE_HW_CAMERA_READ        = 0x00040000U,
     /* buffer will be used as part of zero-shutter-lag queue */
-    GRALLOC_USAGE_HW_CAMERA_ZSL         = 0x00060000,
+    GRALLOC_USAGE_HW_CAMERA_ZSL         = 0x00060000U,
     /* mask for the camera access values */
-    GRALLOC_USAGE_HW_CAMERA_MASK        = 0x00060000,
+    GRALLOC_USAGE_HW_CAMERA_MASK        = 0x00060000U,
     /* mask for the software usage bit-mask */
-    GRALLOC_USAGE_HW_MASK               = 0x00071F00,
+    GRALLOC_USAGE_HW_MASK               = 0x00071F00U,
 
     /* buffer will be used as a RenderScript Allocation */
-    GRALLOC_USAGE_RENDERSCRIPT          = 0x00100000,
+    GRALLOC_USAGE_RENDERSCRIPT          = 0x00100000U,
 
     /* Set by the consumer to indicate to the producer that they may attach a
      * buffer that they did not detach from the BufferQueue. Will be filtered
      * out by GRALLOC_USAGE_ALLOC_MASK, so gralloc modules will not need to
      * handle this flag. */
-    GRALLOC_USAGE_FOREIGN_BUFFERS       = 0x00200000,
+    GRALLOC_USAGE_FOREIGN_BUFFERS       = 0x00200000U,
 
     /* Mask of all flags which could be passed to a gralloc module for buffer
      * allocation. Any flags not in this mask do not need to be handled by
@@ -138,11 +138,11 @@
     GRALLOC_USAGE_ALLOC_MASK            = ~(GRALLOC_USAGE_FOREIGN_BUFFERS),
 
     /* implementation-specific private usage flags */
-    GRALLOC_USAGE_PRIVATE_0             = 0x10000000,
-    GRALLOC_USAGE_PRIVATE_1             = 0x20000000,
-    GRALLOC_USAGE_PRIVATE_2             = 0x40000000,
-    GRALLOC_USAGE_PRIVATE_3             = 0x80000000,
-    GRALLOC_USAGE_PRIVATE_MASK          = 0xF0000000,
+    GRALLOC_USAGE_PRIVATE_0             = 0x10000000U,
+    GRALLOC_USAGE_PRIVATE_1             = 0x20000000U,
+    GRALLOC_USAGE_PRIVATE_2             = 0x40000000U,
+    GRALLOC_USAGE_PRIVATE_3             = 0x80000000U,
+    GRALLOC_USAGE_PRIVATE_MASK          = 0xF0000000U,
 };
 
 /*****************************************************************************/
@@ -372,7 +372,7 @@
 static inline int gralloc_open(const struct hw_module_t* module, 
         struct alloc_device_t** device) {
     return module->methods->open(module, 
-            GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
+            GRALLOC_HARDWARE_GPU0, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int gralloc_close(struct alloc_device_t* device) {
diff --git a/include/hardware/gralloc1.h b/include/hardware/gralloc1.h
index 58c0e33..a1a2d69 100644
--- a/include/hardware/gralloc1.h
+++ b/include/hardware/gralloc1.h
@@ -290,7 +290,7 @@
 static inline int gralloc1_open(const struct hw_module_t* module,
         gralloc1_device_t** device) {
     return module->methods->open(module, GRALLOC_HARDWARE_MODULE_ID,
-            (struct hw_device_t**) device);
+            TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int gralloc1_close(gralloc1_device_t* device) {
diff --git a/include/hardware/hardware.h b/include/hardware/hardware.h
index 74f57aa..5ba37e9 100644
--- a/include/hardware/hardware.h
+++ b/include/hardware/hardware.h
@@ -20,8 +20,10 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#ifndef _HW_DONT_INCLUDE_CORE_
 #include <cutils/native_handle.h>
 #include <system/graphics.h>
+#endif // _HW_DONT_INCLUDE_CORE_
 
 __BEGIN_DECLS
 
@@ -201,6 +203,12 @@
 
 } hw_device_t;
 
+#ifdef __cplusplus
+#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x)
+#else
+#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x)
+#endif
+
 /**
  * Name of the hal_module_info
  */
diff --git a/include/hardware/hdmi_cec.h b/include/hardware/hdmi_cec.h
index ab70f92..aa06384 100644
--- a/include/hardware/hdmi_cec.h
+++ b/include/hardware/hdmi_cec.h
@@ -417,7 +417,7 @@
 static inline int hdmi_cec_open(const struct hw_module_t* module,
         struct hdmi_cec_device** device) {
     return module->methods->open(module,
-            HDMI_CEC_HARDWARE_INTERFACE, (struct hw_device_t**)device);
+            HDMI_CEC_HARDWARE_INTERFACE, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int hdmi_cec_close(struct hdmi_cec_device* device) {
diff --git a/include/hardware/hw_auth_token.h b/include/hardware/hw_auth_token.h
index f471d1a..d84ea48 100644
--- a/include/hardware/hw_auth_token.h
+++ b/include/hardware/hw_auth_token.h
@@ -23,7 +23,7 @@
 extern "C" {
 #endif  // __cplusplus
 
-const uint8_t HW_AUTH_TOKEN_VERSION = 0;
+static const uint8_t HW_AUTH_TOKEN_VERSION = 0;
 
 typedef enum {
     HW_AUTH_NONE = 0,
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h
index 61218bb..7eca7c1 100644
--- a/include/hardware/hwcomposer.h
+++ b/include/hardware/hwcomposer.h
@@ -783,7 +783,7 @@
 static inline int hwc_open_1(const struct hw_module_t* module,
         hwc_composer_device_1_t** device) {
     return module->methods->open(module,
-            HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
+            HWC_HARDWARE_COMPOSER, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int hwc_close_1(hwc_composer_device_1_t* device) {
diff --git a/include/hardware/hwcomposer2.h b/include/hardware/hwcomposer2.h
index 6973603..35eedb0 100644
--- a/include/hardware/hwcomposer2.h
+++ b/include/hardware/hwcomposer2.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_HARDWARE_HWCOMPOSER2_H
 #define ANDROID_HARDWARE_HWCOMPOSER2_H
 
+#include <sys/cdefs.h>
+
 #include <hardware/hardware.h>
 
 #include "hwcomposer_defs.h"
@@ -360,7 +362,7 @@
 
 static inline const char* getDisplayRequestName(
         hwc2_display_request_t request) {
-    switch (request) {
+    switch (__BIONIC_CAST(static_cast, int, request)) {
         case 0: return "None";
         case HWC2_DISPLAY_REQUEST_FLIP_CLIENT_TARGET: return "FlipClientTarget";
         case HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT:
@@ -459,7 +461,7 @@
 }
 
 static inline const char* getLayerRequestName(hwc2_layer_request_t request) {
-    switch (request) {
+    switch (__BIONIC_CAST(static_cast, int, request)) {
         case 0: return "None";
         case HWC2_LAYER_REQUEST_CLEAR_CLIENT_TARGET: return "ClearClientTarget";
         default: return "Unknown";
@@ -477,7 +479,7 @@
 }
 
 static inline const char* getTransformName(hwc_transform_t transform) {
-    switch (transform) {
+    switch (__BIONIC_CAST(static_cast, int, transform)) {
         case 0: return "None";
         case HWC_TRANSFORM_FLIP_H: return "FlipH";
         case HWC_TRANSFORM_FLIP_V: return "FlipV";
@@ -738,7 +740,7 @@
 static inline int hwc2_open(const struct hw_module_t* module,
         hwc2_device_t** device) {
     return module->methods->open(module, HWC_HARDWARE_COMPOSER,
-            (struct hw_device_t**) device);
+            TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int hwc2_close(hwc2_device_t* device) {
diff --git a/include/hardware/keymaster0.h b/include/hardware/keymaster0.h
index f020e5b..52ac64b 100644
--- a/include/hardware/keymaster0.h
+++ b/include/hardware/keymaster0.h
@@ -134,7 +134,7 @@
         keymaster0_device_t** device)
 {
     int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
-            (struct hw_device_t**) device);
+            TO_HW_DEVICE_T_OPEN(device));
 
     return rc;
 }
diff --git a/include/hardware/keymaster1.h b/include/hardware/keymaster1.h
index afd202c..9969380 100644
--- a/include/hardware/keymaster1.h
+++ b/include/hardware/keymaster1.h
@@ -536,7 +536,7 @@
 /* Convenience API for opening and closing keymaster devices */
 
 static inline int keymaster1_open(const struct hw_module_t* module, keymaster1_device_t** device) {
-    return module->methods->open(module, KEYSTORE_KEYMASTER, (struct hw_device_t**)device);
+    return module->methods->open(module, KEYSTORE_KEYMASTER, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int keymaster1_close(keymaster1_device_t* device) {
diff --git a/include/hardware/keymaster2.h b/include/hardware/keymaster2.h
index 565ad2e..f1993f8 100644
--- a/include/hardware/keymaster2.h
+++ b/include/hardware/keymaster2.h
@@ -420,7 +420,7 @@
 /* Convenience API for opening and closing keymaster devices */
 
 static inline int keymaster2_open(const struct hw_module_t* module, keymaster2_device_t** device) {
-    return module->methods->open(module, KEYSTORE_KEYMASTER, (struct hw_device_t**)device);
+    return module->methods->open(module, KEYSTORE_KEYMASTER, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int keymaster2_close(keymaster2_device_t* device) {
diff --git a/include/hardware/local_time_hal.h b/include/hardware/local_time_hal.h
index 946e799..1bbbf11 100644
--- a/include/hardware/local_time_hal.h
+++ b/include/hardware/local_time_hal.h
@@ -109,7 +109,7 @@
         struct local_time_hw_device** device)
 {
     return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE,
-                                 (struct hw_device_t**)device);
+                                 TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int local_time_hw_device_close(struct local_time_hw_device* device)
diff --git a/include/hardware/nfc-base.h b/include/hardware/nfc-base.h
new file mode 100644
index 0000000..d53e759
--- /dev/null
+++ b/include/hardware/nfc-base.h
@@ -0,0 +1,32 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+#ifndef HIDL_GENERATED_android_hardware_nfc_V1_0__EXPORTED_CONSTANTS_H_
+#define HIDL_GENERATED_android_hardware_nfc_V1_0__EXPORTED_CONSTANTS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {
+    HAL_NFC_OPEN_CPLT_EVT = 0,
+    HAL_NFC_CLOSE_CPLT_EVT = 1,
+    HAL_NFC_POST_INIT_CPLT_EVT = 2,
+    HAL_NFC_PRE_DISCOVER_CPLT_EVT = 3,
+    HAL_NFC_REQUEST_CONTROL_EVT = 4,
+    HAL_NFC_RELEASE_CONTROL_EVT = 5,
+    HAL_NFC_ERROR_EVT = 6,
+};
+
+enum {
+    HAL_NFC_STATUS_OK = 0,
+    HAL_NFC_STATUS_FAILED = 1,
+    HAL_NFC_STATUS_ERR_TRANSPORT = 2,
+    HAL_NFC_STATUS_ERR_CMD_TIMEOUT = 3,
+    HAL_NFC_STATUS_REFUSED = 4,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // HIDL_GENERATED_android_hardware_nfc_V1_0__EXPORTED_CONSTANTS_H_
diff --git a/include/hardware/nfc.h b/include/hardware/nfc.h
index 58d33d9..fdd79a5 100644
--- a/include/hardware/nfc.h
+++ b/include/hardware/nfc.h
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 
 #include <hardware/hardware.h>
+#include "nfc-base.h"
 
 __BEGIN_DECLS
 
@@ -69,34 +70,9 @@
     struct hw_module_t common;
 } nfc_nci_module_t;
 
-/*
- * HAL events that can be passed back to the stack
- */
 typedef uint8_t nfc_event_t;
-
-enum {
-    HAL_NFC_OPEN_CPLT_EVT           = 0x00,
-    HAL_NFC_CLOSE_CPLT_EVT          = 0x01,
-    HAL_NFC_POST_INIT_CPLT_EVT      = 0x02,
-    HAL_NFC_PRE_DISCOVER_CPLT_EVT   = 0x03,
-    HAL_NFC_REQUEST_CONTROL_EVT     = 0x04,
-    HAL_NFC_RELEASE_CONTROL_EVT     = 0x05,
-    HAL_NFC_ERROR_EVT               = 0x06
-};
-
-/*
- * Allowed status return values for each of the HAL methods
- */
 typedef uint8_t nfc_status_t;
 
-enum {
-    HAL_NFC_STATUS_OK               = 0x00,
-    HAL_NFC_STATUS_FAILED           = 0x01,
-    HAL_NFC_STATUS_ERR_TRANSPORT    = 0x02,
-    HAL_NFC_STATUS_ERR_CMD_TIMEOUT  = 0x03,
-    HAL_NFC_STATUS_REFUSED          = 0x04
-};
-
 /*
  * The callback passed in from the NFC stack that the HAL
  * can use to pass events back to the stack.
diff --git a/include/hardware/nvram.h b/include/hardware/nvram.h
index a1868b5..0654afe 100644
--- a/include/hardware/nvram.h
+++ b/include/hardware/nvram.h
@@ -21,6 +21,7 @@
 #include <sys/cdefs.h>
 
 #include <hardware/hardware.h>
+#include <hardware/nvram_defs.h>
 
 __BEGIN_DECLS
 
@@ -30,30 +31,7 @@
 
 /* The version of this module. */
 #define NVRAM_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
-#define NVRAM_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
-
-/* Values returned by nvram_device methods. */
-typedef uint32_t nvram_result_t;
-
-const nvram_result_t NV_RESULT_SUCCESS = 0;
-const nvram_result_t NV_RESULT_INTERNAL_ERROR = 1;
-const nvram_result_t NV_RESULT_ACCESS_DENIED = 2;
-const nvram_result_t NV_RESULT_INVALID_PARAMETER = 3;
-const nvram_result_t NV_RESULT_SPACE_DOES_NOT_EXIST = 4;
-const nvram_result_t NV_RESULT_SPACE_ALREADY_EXISTS = 5;
-const nvram_result_t NV_RESULT_OPERATION_DISABLED = 6;
-
-/* Values describing available access controls. */
-typedef uint32_t nvram_control_t;
-
-const nvram_control_t NV_CONTROL_PERSISTENT_WRITE_LOCK = 1;
-const nvram_control_t NV_CONTROL_BOOT_WRITE_LOCK = 2;
-const nvram_control_t NV_CONTROL_BOOT_READ_LOCK = 3;
-const nvram_control_t NV_CONTROL_WRITE_AUTHORIZATION = 4;
-const nvram_control_t NV_CONTROL_READ_AUTHORIZATION = 5;
-const nvram_control_t NV_CONTROL_WRITE_EXTEND = 6;
-
-const uint32_t NV_UNLIMITED_SPACES = 0xFFFFFFFF;
+#define NVRAM_DEVICE_API_VERSION_1_1 HARDWARE_DEVICE_API_VERSION(1, 1)
 
 struct nvram_module {
     /**
@@ -99,6 +77,17 @@
         const struct nvram_device* device, uint64_t* available_size);
 
     /**
+     * Outputs the maximum number of bytes that can be allocated for a single
+     * space. This will always be at least 32. If an implementation does not
+     * limit the maximum size it may provide the total size.
+     *
+     *   device - The nvram_device instance.
+     *   max_space_size - Receives the output. Cannot be NULL.
+     */
+    nvram_result_t (*get_max_space_size_in_bytes)(
+        const struct nvram_device* device, uint64_t* max_space_size);
+
+    /**
      * Outputs the maximum total number of spaces that may be allocated.
      * This will always be at least 8. Outputs NV_UNLIMITED_SPACES if any
      * number of spaces are supported (limited only to available NVRAM
@@ -337,7 +326,7 @@
 static inline int nvram_open(const struct hw_module_t* module,
                              nvram_device_t** device) {
     return module->methods->open(module, NVRAM_HARDWARE_DEVICE_ID,
-                                 (struct hw_device_t**)device);
+                                 TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int nvram_close(nvram_device_t* device) {
diff --git a/include/hardware/nvram_defs.h b/include/hardware/nvram_defs.h
new file mode 100644
index 0000000..0256a3c
--- /dev/null
+++ b/include/hardware/nvram_defs.h
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+/*
+ * This file contains data type definitions and constants that are useful to
+ * code interacting with and implementing the NVRAM HAL, even though it doesn't
+ * use the actual NVRAM HAL module interface. Keeping this in a separate file
+ * simplifies inclusion in low-level code which can't easily include the heavier
+ * hardware.h due to lacking standard headers.
+ */
+
+#ifndef ANDROID_HARDWARE_NVRAM_DEFS_H
+#define ANDROID_HARDWARE_NVRAM_DEFS_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif  // __cplusplus
+
+/* Values returned by nvram_device methods. */
+typedef uint32_t nvram_result_t;
+
+const nvram_result_t NV_RESULT_SUCCESS = 0;
+const nvram_result_t NV_RESULT_INTERNAL_ERROR = 1;
+const nvram_result_t NV_RESULT_ACCESS_DENIED = 2;
+const nvram_result_t NV_RESULT_INVALID_PARAMETER = 3;
+const nvram_result_t NV_RESULT_SPACE_DOES_NOT_EXIST = 4;
+const nvram_result_t NV_RESULT_SPACE_ALREADY_EXISTS = 5;
+const nvram_result_t NV_RESULT_OPERATION_DISABLED = 6;
+
+/* Values describing available access controls. */
+typedef uint32_t nvram_control_t;
+
+const nvram_control_t NV_CONTROL_PERSISTENT_WRITE_LOCK = 1;
+const nvram_control_t NV_CONTROL_BOOT_WRITE_LOCK = 2;
+const nvram_control_t NV_CONTROL_BOOT_READ_LOCK = 3;
+const nvram_control_t NV_CONTROL_WRITE_AUTHORIZATION = 4;
+const nvram_control_t NV_CONTROL_READ_AUTHORIZATION = 5;
+const nvram_control_t NV_CONTROL_WRITE_EXTEND = 6;
+
+const uint32_t NV_UNLIMITED_SPACES = 0xFFFFFFFF;
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif  // __cplusplus
+
+#endif  // ANDROID_HARDWARE_NVRAM_DEFS_H
diff --git a/include/hardware/qemu_pipe.h b/include/hardware/qemu_pipe.h
deleted file mode 100644
index 53aec97..0000000
--- a/include/hardware/qemu_pipe.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2011 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_INCLUDE_HARDWARE_QEMU_PIPE_H
-#define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
-
-#include <sys/cdefs.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <pthread.h>  /* for pthread_once() */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-
-#ifndef D
-#  define  D(...)   do{}while(0)
-#endif
-
-/* Try to open a new Qemu fast-pipe. This function returns a file descriptor
- * that can be used to communicate with a named service managed by the
- * emulator.
- *
- * This file descriptor can be used as a standard pipe/socket descriptor.
- *
- * 'pipeName' is the name of the emulator service you want to connect to.
- * E.g. 'opengles' or 'camera'.
- *
- * On success, return a valid file descriptor
- * Returns -1 on error, and errno gives the error code, e.g.:
- *
- *    EINVAL  -> unknown/unsupported pipeName
- *    ENOSYS  -> fast pipes not available in this system.
- *
- * ENOSYS should never happen, except if you're trying to run within a
- * misconfigured emulator.
- *
- * You should be able to open several pipes to the same pipe service,
- * except for a few special cases (e.g. GSM modem), where EBUSY will be
- * returned if more than one client tries to connect to it.
- */
-static __inline__ int
-qemu_pipe_open(const char*  pipeName)
-{
-    char  buff[256];
-    int   buffLen;
-    int   fd, ret;
-
-    if (pipeName == NULL || pipeName[0] == '\0') {
-        errno = EINVAL;
-        return -1;
-    }
-
-    snprintf(buff, sizeof buff, "pipe:%s", pipeName);
-
-    fd = open("/dev/qemu_pipe", O_RDWR);
-    if (fd < 0 && errno == ENOENT)
-        fd = open("/dev/goldfish_pipe", O_RDWR);
-    if (fd < 0) {
-        D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno));
-        //errno = ENOSYS;
-        return -1;
-    }
-
-    buffLen = strlen(buff);
-
-    ret = TEMP_FAILURE_RETRY(write(fd, buff, buffLen+1));
-    if (ret != buffLen+1) {
-        D("%s: Could not connect to %s pipe service: %s", __FUNCTION__, pipeName, strerror(errno));
-        if (ret == 0) {
-            errno = ECONNRESET;
-        } else if (ret > 0) {
-            errno = EINVAL;
-        }
-        return -1;
-    }
-
-    return fd;
-}
-
-#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */
diff --git a/include/hardware/qemud.h b/include/hardware/qemud.h
deleted file mode 100644
index 5c39f9c..0000000
--- a/include/hardware/qemud.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2008 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_INCLUDE_HARDWARE_QEMUD_H
-#define ANDROID_INCLUDE_HARDWARE_QEMUD_H
-
-#include <cutils/sockets.h>
-#include "qemu_pipe.h"
-
-/* the following is helper code that is used by the QEMU-specific
- * hardware HAL modules to communicate with the emulator program
- * through the 'qemud' multiplexing daemon, or through the qemud
- * pipe.
- *
- * see the documentation comments for details in
- * development/emulator/qemud/qemud.c
- *
- * all definitions here are built into the HAL module to avoid
- * having to write a tiny shared library for this.
- */
-
-/* we expect the D macro to be defined to a function macro
- * that sends its formatted string argument(s) to the log.
- * If not, ignore the traces.
- */
-#ifndef D
-#  define  D(...)  ((void)0)
-#endif
-
-static __inline__ int
-qemud_fd_write(int  fd, const void*  buff, int  len)
-{
-    int  len2;
-    do {
-        len2 = write(fd, buff, len);
-    } while (len2 < 0 && errno == EINTR);
-    return len2;
-}
-
-static __inline__ int
-qemud_fd_read(int  fd, void*  buff, int  len)
-{
-    int  len2;
-    do {
-        len2 = read(fd, buff, len);
-    } while (len2 < 0 && errno == EINTR);
-    return len2;
-}
-
-static __inline__ int
-qemud_channel_open(const char*  name)
-{
-    int  fd;
-    int  namelen = strlen(name);
-    char answer[2];
-    char pipe_name[256];
-
-    /* First, try to connect to the pipe. */
-    snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", name);
-    fd = qemu_pipe_open(pipe_name);
-    if (fd < 0) {
-        D("QEMUD pipe is not available for %s: %s", name, strerror(errno));
-        /* If pipe is not available, connect to qemud control socket */
-        fd = socket_local_client( "qemud",
-                                  ANDROID_SOCKET_NAMESPACE_RESERVED,
-                                  SOCK_STREAM );
-        if (fd < 0) {
-            D("no qemud control socket: %s", strerror(errno));
-            return -1;
-        }
-
-        /* send service name to connect */
-        if (qemud_fd_write(fd, name, namelen) != namelen) {
-            D("can't send service name to qemud: %s",
-               strerror(errno));
-            close(fd);
-            return -1;
-        }
-
-        /* read answer from daemon */
-        if (qemud_fd_read(fd, answer, 2) != 2 ||
-            answer[0] != 'O' || answer[1] != 'K') {
-            D("cant' connect to %s service through qemud", name);
-            close(fd);
-            return -1;
-        }
-    }
-    return fd;
-}
-
-static __inline__ int
-qemud_channel_send(int  fd, const void*  msg, int  msglen)
-{
-    char  header[5];
-
-    if (msglen < 0)
-        msglen = strlen((const char*)msg);
-
-    if (msglen == 0)
-        return 0;
-
-    snprintf(header, sizeof header, "%04x", msglen);
-    if (qemud_fd_write(fd, header, 4) != 4) {
-        D("can't write qemud frame header: %s", strerror(errno));
-        return -1;
-    }
-
-    if (qemud_fd_write(fd, msg, msglen) != msglen) {
-        D("can4t write qemud frame payload: %s", strerror(errno));
-        return -1;
-    }
-    return 0;
-}
-
-static __inline__ int
-qemud_channel_recv(int  fd, void*  msg, int  msgsize)
-{
-    char  header[5];
-    int   size, avail;
-
-    if (qemud_fd_read(fd, header, 4) != 4) {
-        D("can't read qemud frame header: %s", strerror(errno));
-        return -1;
-    }
-    header[4] = 0;
-    if (sscanf(header, "%04x", &size) != 1) {
-        D("malformed qemud frame header: '%.*s'", 4, header);
-        return -1;
-    }
-    if (size > msgsize)
-        return -1;
-
-    if (qemud_fd_read(fd, msg, size) != size) {
-        D("can't read qemud frame payload: %s", strerror(errno));
-        return -1;
-    }
-    return size;
-}
-
-#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_H */
diff --git a/include/hardware/radio.h b/include/hardware/radio.h
index 145deb5..413f413 100644
--- a/include/hardware/radio.h
+++ b/include/hardware/radio.h
@@ -285,7 +285,7 @@
                                        struct radio_hw_device** device)
 {
     return module->methods->open(module, RADIO_HARDWARE_DEVICE,
-                                 (struct hw_device_t**)device);
+                                 TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int radio_hw_device_close(const struct radio_hw_device* device)
diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h
index 1d73c31..c872d8e 100644
--- a/include/hardware/sensors.h
+++ b/include/hardware/sensors.h
@@ -1151,7 +1151,7 @@
 
     /**
      * Enumerate all available sensors. The list is returned in "list".
-     * @return number of sensors in the list
+     * return number of sensors in the list
      */
     int (*get_sensors_list)(struct sensors_module_t* module,
             struct sensor_t const** list);
@@ -1162,7 +1162,7 @@
      *  0 - Normal operation. Default state of the module.
      *  1 - Loopback mode. Data is injected for the supported
      *      sensors by the sensor service in this mode.
-     * @return 0 on success
+     * return 0 on success
      *         -EINVAL if requested mode is not supported
      *         -EPERM if operation is not allowed
      */
@@ -1308,11 +1308,16 @@
         struct {
             struct hw_device_t common;
 
-            /* Activate/de-activate one sensor. Return 0 on success, negative
+            /* Activate/de-activate one sensor.
              *
              * sensor_handle is the handle of the sensor to change.
              * enabled set to 1 to enable, or 0 to disable the sensor.
              *
+             * After sensor de-activation, existing sensor events that have not
+             * been picked up by poll() should be abandoned immediately so that
+             * subsequent activation will not get stale sensor events (events
+             * that is generated prior to the latter activation).
+             *
              * Return 0 on success, negative errno code otherwise.
              */
             int (*activate)(struct sensors_poll_device_t *dev,
@@ -1367,7 +1372,7 @@
     /*
      * Inject a single sensor sample to be to this device.
      * data points to the sensor event to be injected
-     * @return 0 on success
+     * return 0 on success
      *         -EPERM if operation is not allowed
      *         -EINVAL if sensor event cannot be injected
      */
@@ -1383,7 +1388,7 @@
 static inline int sensors_open(const struct hw_module_t* module,
         struct sensors_poll_device_t** device) {
     return module->methods->open(module,
-            SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
+            SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int sensors_close(struct sensors_poll_device_t* device) {
@@ -1393,7 +1398,7 @@
 static inline int sensors_open_1(const struct hw_module_t* module,
         sensors_poll_device_1_t** device) {
     return module->methods->open(module,
-            SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
+            SENSORS_HARDWARE_POLL, TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int sensors_close_1(sensors_poll_device_1_t* device) {
diff --git a/include/hardware/sound_trigger.h b/include/hardware/sound_trigger.h
index e1abbc9..d7828ac 100644
--- a/include/hardware/sound_trigger.h
+++ b/include/hardware/sound_trigger.h
@@ -124,7 +124,7 @@
                                        struct sound_trigger_hw_device** device)
 {
     return module->methods->open(module, SOUND_TRIGGER_HARDWARE_INTERFACE,
-                                 (struct hw_device_t**)device);
+                                 TO_HW_DEVICE_T_OPEN(device));
 }
 
 static inline int sound_trigger_hw_device_close(struct sound_trigger_hw_device* device)
diff --git a/include/hardware/vibrator.h b/include/hardware/vibrator.h
index 200adf0..361085f 100644
--- a/include/hardware/vibrator.h
+++ b/include/hardware/vibrator.h
@@ -65,7 +65,7 @@
 
 static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device)
 {
-    return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device);
+    return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, TO_HW_DEVICE_T_OPEN(device));
 }
 
 __END_DECLS
diff --git a/modules/Android.mk b/modules/Android.mk
index 3bd0943..2a58b3e 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,4 +1,4 @@
-hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \
-	power usbaudio audio_remote_submix camera usbcamera consumerir sensors vibrator \
-	tv_input fingerprint input vehicle thermal vr
+hardware_modules := gralloc hwcomposer \
+	usbaudio audio_remote_submix camera usbcamera sensors \
+	input vehicle thermal vr
 include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/Android.bp b/modules/audio/Android.bp
new file mode 100644
index 0000000..02da2b3
--- /dev/null
+++ b/modules/audio/Android.bp
@@ -0,0 +1,60 @@
+// Copyright (C) 2011 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.
+
+// The default audio HAL module, which is a stub, that is loaded if no other
+// device specific modules are present. The exact load order can be seen in
+// libhardware/hardware.c
+//
+// The format of the name is audio.<type>.<hardware/etc>.so where the only
+// required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+cc_library_shared {
+    name: "audio.primary.default",
+    relative_install_path: "hw",
+    srcs: ["audio_hw.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+    cflags: ["-Wno-unused-parameter"],
+}
+
+// The stub audio HAL module, identical to the default audio hal, but with
+// different name to be loaded concurrently with other audio HALs if necessary.
+// This can also be used as skeleton for new implementations
+//
+// The format of the name is audio.<type>.<hardware/etc>.so where the only
+// required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
+cc_library_shared {
+    name: "audio.stub.default",
+    relative_install_path: "hw",
+    srcs: ["audio_hw.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+    cflags: ["-Wno-unused-parameter"],
+}
+
+// The stub audio policy HAL module that can be used as a skeleton for
+// new implementations.
+cc_library_shared {
+    name: "audio_policy.stub",
+    relative_install_path: "hw",
+    srcs: ["audio_policy.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+    cflags: ["-Wno-unused-parameter"],
+}
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
deleted file mode 100644
index ef4b8f5..0000000
--- a/modules/audio/Android.mk
+++ /dev/null
@@ -1,62 +0,0 @@
-# Copyright (C) 2011 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)
-
-# The default audio HAL module, which is a stub, that is loaded if no other
-# device specific modules are present. The exact load order can be seen in
-# libhardware/hardware.c
-#
-# The format of the name is audio.<type>.<hardware/etc>.so where the only
-# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := audio.primary.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := audio_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-include $(BUILD_SHARED_LIBRARY)
-
-# The stub audio HAL module, identical to the default audio hal, but with
-# different name to be loaded concurrently with other audio HALs if necessary.
-# This can also be used as skeleton for new implementations
-#
-# The format of the name is audio.<type>.<hardware/etc>.so where the only
-# required type is 'primary'. Other possibilites are 'a2dp', 'usb', etc.
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := audio.stub.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := audio_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-include $(BUILD_SHARED_LIBRARY)
-
-# The stub audio policy HAL module that can be used as a skeleton for
-# new implementations.
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := audio_policy.stub
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := audio_policy.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index 68b0d3a..35901e4 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -119,7 +119,7 @@
 static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
                          size_t bytes)
 {
-    ALOGV("out_write: bytes: %d", bytes);
+    ALOGV("out_write: bytes: %zu", bytes);
 
     /* XXX: fake timing for audio output */
     struct stub_stream_out *out = (struct stub_stream_out *)stream;
@@ -242,7 +242,7 @@
 static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
                        size_t bytes)
 {
-    ALOGV("in_read: bytes %d", bytes);
+    ALOGV("in_read: bytes %zu", bytes);
 
     /* XXX: fake timing for audio input */
     struct stub_stream_in *in = (struct stub_stream_in *)stream;
diff --git a/modules/camera/Camera.h b/modules/camera/Camera.h
index 0ceaf25..072de35 100644
--- a/modules/camera/Camera.h
+++ b/modules/camera/Camera.h
@@ -34,7 +34,7 @@
     public:
         // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
         // module is a handle to the HAL module, used when the device is opened.
-        Camera(int id);
+        explicit Camera(int id);
         virtual ~Camera();
 
         // Common Camera Device Operations (see <hardware/camera_common.h>)
diff --git a/modules/camera/CameraHAL.cpp b/modules/camera/CameraHAL.cpp
index 62ee6d4..e395ce5 100644
--- a/modules/camera/CameraHAL.cpp
+++ b/modules/camera/CameraHAL.cpp
@@ -165,29 +165,29 @@
 }
 
 static hw_module_methods_t gCameraModuleMethods = {
-    open : open_dev
+    .open = open_dev
 };
 
 camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
-    common : {
-        tag                : HARDWARE_MODULE_TAG,
-        module_api_version : CAMERA_MODULE_API_VERSION_2_2,
-        hal_api_version    : HARDWARE_HAL_API_VERSION,
-        id                 : CAMERA_HARDWARE_MODULE_ID,
-        name               : "Default Camera HAL",
-        author             : "The Android Open Source Project",
-        methods            : &gCameraModuleMethods,
-        dso                : NULL,
-        reserved           : {0},
+    .common = {
+        .tag                = HARDWARE_MODULE_TAG,
+        .module_api_version = CAMERA_MODULE_API_VERSION_2_2,
+        .hal_api_version    = HARDWARE_HAL_API_VERSION,
+        .id                 = CAMERA_HARDWARE_MODULE_ID,
+        .name               = "Default Camera HAL",
+        .author             = "The Android Open Source Project",
+        .methods            = &gCameraModuleMethods,
+        .dso                = NULL,
+        .reserved           = {0},
     },
-    get_number_of_cameras : get_number_of_cameras,
-    get_camera_info       : get_camera_info,
-    set_callbacks         : set_callbacks,
-    get_vendor_tag_ops    : get_vendor_tag_ops,
-    open_legacy           : NULL,
-    set_torch_mode        : NULL,
-    init                  : NULL,
-    reserved              : {0},
+    .get_number_of_cameras = get_number_of_cameras,
+    .get_camera_info       = get_camera_info,
+    .set_callbacks         = set_callbacks,
+    .get_vendor_tag_ops    = get_vendor_tag_ops,
+    .open_legacy           = NULL,
+    .set_torch_mode        = NULL,
+    .init                  = NULL,
+    .reserved              = {0},
 };
 } // extern "C"
 
diff --git a/modules/camera/CameraHAL.h b/modules/camera/CameraHAL.h
index 00c74e5..74a70a6 100644
--- a/modules/camera/CameraHAL.h
+++ b/modules/camera/CameraHAL.h
@@ -29,7 +29,7 @@
 // camera device.
 class CameraHAL {
     public:
-        CameraHAL(int num_cameras);
+        explicit CameraHAL(int num_cameras);
         ~CameraHAL();
 
         // Camera Module Interface (see <hardware/camera_common.h>)
diff --git a/modules/camera/ExampleCamera.cpp b/modules/camera/ExampleCamera.cpp
index d873321..d060d35 100644
--- a/modules/camera/ExampleCamera.cpp
+++ b/modules/camera/ExampleCamera.cpp
@@ -26,7 +26,7 @@
 
 #include "ExampleCamera.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 namespace default_camera_hal {
 
@@ -264,7 +264,8 @@
     return setTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG, m.get());
 }
 
-bool ExampleCamera::isValidCaptureSettings(const camera_metadata_t* settings)
+bool ExampleCamera::isValidCaptureSettings(
+        const camera_metadata_t* /*settings*/)
 {
     // TODO: reject settings that cannot be captured
     return true;
diff --git a/modules/camera/ExampleCamera.h b/modules/camera/ExampleCamera.h
index 45c4a94..44eac76 100644
--- a/modules/camera/ExampleCamera.h
+++ b/modules/camera/ExampleCamera.h
@@ -27,7 +27,7 @@
 // metadata and logic about that device.
 class ExampleCamera : public Camera {
     public:
-        ExampleCamera(int id);
+        explicit ExampleCamera(int id);
         ~ExampleCamera();
 
     private:
diff --git a/modules/camera/VendorTags.cpp b/modules/camera/VendorTags.cpp
index 2c54648..48c1a46 100644
--- a/modules/camera/VendorTags.cpp
+++ b/modules/camera/VendorTags.cpp
@@ -136,12 +136,13 @@
 {
 }
 
-int VendorTags::getTagCount(const vendor_tag_ops_t* ops)
+int VendorTags::getTagCount(const vendor_tag_ops_t* /*ops*/)
 {
     return mTagCount;
 }
 
-void VendorTags::getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array)
+void VendorTags::getAllTags(const vendor_tag_ops_t* /*ops*/,
+        uint32_t* tag_array)
 {
     if (tag_array == NULL) {
         ALOGE("%s: NULL tag_array", __func__);
@@ -156,7 +157,8 @@
     }
 }
 
-const char* VendorTags::getSectionName(const vendor_tag_ops_t* ops, uint32_t tag)
+const char* VendorTags::getSectionName(const vendor_tag_ops_t* /*ops*/,
+        uint32_t tag)
 {
     const Section* section = getSection(tag);
 
@@ -166,7 +168,8 @@
     return section->name;
 }
 
-const char* VendorTags::getTagName(const vendor_tag_ops_t* ops, uint32_t tag)
+const char* VendorTags::getTagName(const vendor_tag_ops_t* /*ops*/,
+        uint32_t tag)
 {
     const Entry* entry = getEntry(tag);
 
@@ -176,7 +179,7 @@
     return entry->name;
 }
 
-int VendorTags::getTagType(const vendor_tag_ops_t* ops, uint32_t tag)
+int VendorTags::getTagType(const vendor_tag_ops_t* /*ops*/, uint32_t tag)
 {
     const Entry* entry = getEntry(tag);
 
diff --git a/modules/consumerir/Android.bp b/modules/consumerir/Android.bp
new file mode 100644
index 0000000..bbce6b1
--- /dev/null
+++ b/modules/consumerir/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2013 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.
+
+cc_library_shared {
+    name: "consumerir.default",
+    relative_install_path: "hw",
+    srcs: ["consumerir.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+}
diff --git a/modules/consumerir/Android.mk b/modules/consumerir/Android.mk
deleted file mode 100644
index b881572..0000000
--- a/modules/consumerir/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (C) 2013 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := consumerir.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := consumerir.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/consumerir/consumerir.c b/modules/consumerir/consumerir.c
index f3eac0b..b0ff940 100644
--- a/modules/consumerir/consumerir.c
+++ b/modules/consumerir/consumerir.c
@@ -22,7 +22,7 @@
 #include <hardware/hardware.h>
 #include <hardware/consumerir.h>
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 static const consumerir_freq_range_t consumerir_freqs[] = {
     {.min = 30000, .max = 30000},
diff --git a/modules/fingerprint/Android.bp b/modules/fingerprint/Android.bp
new file mode 100644
index 0000000..a66f9f9
--- /dev/null
+++ b/modules/fingerprint/Android.bp
@@ -0,0 +1,20 @@
+// Copyright (C) 2013 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.
+
+cc_library_shared {
+    name: "fingerprint.default",
+    relative_install_path: "hw",
+    srcs: ["fingerprint.c"],
+    shared_libs: ["liblog"],
+}
diff --git a/modules/fingerprint/Android.mk b/modules/fingerprint/Android.mk
deleted file mode 100644
index 58c0a83..0000000
--- a/modules/fingerprint/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (C) 2013 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := fingerprint.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := fingerprint.c
-LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/gralloc/gr.h b/modules/gralloc/gr.h
index 732b6bc..ac7e967 100644
--- a/modules/gralloc/gr.h
+++ b/modules/gralloc/gr.h
@@ -48,7 +48,7 @@
     class Autolock {
         Locker& locker;
     public:
-        inline Autolock(Locker& locker) : locker(locker) {  locker.lock(); }
+        inline explicit Autolock(Locker& locker) : locker(locker) {  locker.lock(); }
         inline ~Autolock() { locker.unlock(); }
     };
     inline Locker()        { pthread_mutex_init(&mutex, 0); }
diff --git a/modules/local_time/Android.bp b/modules/local_time/Android.bp
new file mode 100644
index 0000000..df32325
--- /dev/null
+++ b/modules/local_time/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2011 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.
+
+// The default local time HAL module.  The default module simply uses the
+// system's clock_gettime(CLOCK_MONOTONIC) and does not support HW slewing.
+// Devices which use the default implementation should take care to ensure that
+// the oscillator backing the CLOCK_MONOTONIC implementation is phase locked to
+// the audio and video output hardware.  This default implementation is loaded
+// if no other device specific modules are present. The exact load order can be
+// seen in libhardware/hardware.c
+//
+// The format of the name is local_time.<hardware>.so
+cc_library_shared {
+    name: "local_time.default",
+    relative_install_path: "hw",
+    srcs: ["local_time_hw.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+}
diff --git a/modules/local_time/Android.mk b/modules/local_time/Android.mk
deleted file mode 100644
index 91885aa..0000000
--- a/modules/local_time/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright (C) 2011 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)
-
-# The default local time HAL module.  The default module simply uses the
-# system's clock_gettime(CLOCK_MONOTONIC) and does not support HW slewing.
-# Devices which use the default implementation should take care to ensure that
-# the oscillator backing the CLOCK_MONOTONIC implementation is phase locked to
-# the audio and video output hardware.  This default implementation is loaded
-# if no other device specific modules are present. The exact load order can be
-# seen in libhardware/hardware.c
-#
-# The format of the name is local_time.<hardware>.so
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := local_time.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := local_time_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/nfc-nci/Android.bp b/modules/nfc-nci/Android.bp
new file mode 100644
index 0000000..fc73761
--- /dev/null
+++ b/modules/nfc-nci/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2011 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.
+
+cc_library_shared {
+    name: "nfc_nci.default",
+    relative_install_path: "hw",
+    srcs: ["nfc_nci_example.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+}
diff --git a/modules/nfc-nci/Android.mk b/modules/nfc-nci/Android.mk
deleted file mode 100644
index c1f679a..0000000
--- a/modules/nfc-nci/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (C) 2011 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := nfc_nci.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := nfc_nci_example.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/nfc/Android.bp b/modules/nfc/Android.bp
new file mode 100644
index 0000000..bd93bb5
--- /dev/null
+++ b/modules/nfc/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2011 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.
+
+cc_library_shared {
+    name: "nfc.default",
+    relative_install_path: "hw",
+    srcs: ["nfc_pn544_example.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+}
diff --git a/modules/nfc/Android.mk b/modules/nfc/Android.mk
deleted file mode 100644
index 29b239c..0000000
--- a/modules/nfc/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (C) 2011 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := nfc.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := nfc_pn544_example.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/power/Android.bp b/modules/power/Android.bp
new file mode 100644
index 0000000..2b86c8b
--- /dev/null
+++ b/modules/power/Android.bp
@@ -0,0 +1,20 @@
+// Copyright (C) 2011 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.
+
+cc_library_shared {
+    name: "power.default",
+    relative_install_path: "hw",
+    srcs: ["power.c"],
+    shared_libs: ["liblog"],
+}
diff --git a/modules/power/Android.mk b/modules/power/Android.mk
deleted file mode 100644
index c868ded..0000000
--- a/modules/power/Android.mk
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (C) 2011 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := power.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := power.c
-LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/power/power.c b/modules/power/power.c
index 7cacc09..15d7ba2 100644
--- a/modules/power/power.c
+++ b/modules/power/power.c
@@ -25,16 +25,21 @@
 #include <hardware/hardware.h>
 #include <hardware/power.h>
 
-static void power_init(struct power_module *module)
+// We only support clang and g++.
+#define UNUSED_ARGUMENT __attribute((unused))
+
+static void power_init(struct power_module *module UNUSED_ARGUMENT)
 {
 }
 
-static void power_set_interactive(struct power_module *module, int on)
+static void power_set_interactive(struct power_module *module UNUSED_ARGUMENT,
+                                  int on UNUSED_ARGUMENT)
 {
 }
 
-static void power_hint(struct power_module *module, power_hint_t hint,
-                       void *data) {
+static void power_hint(struct power_module *module UNUSED_ARGUMENT,
+                       power_hint_t hint,
+                       void *data UNUSED_ARGUMENT) {
     switch (hint) {
     default:
         break;
diff --git a/modules/sensors/SensorEventQueue.h b/modules/sensors/SensorEventQueue.h
index 11e1f41..9778e93 100644
--- a/modules/sensors/SensorEventQueue.h
+++ b/modules/sensors/SensorEventQueue.h
@@ -38,7 +38,7 @@
     pthread_cond_t mSpaceAvailableCondition;
 
 public:
-    SensorEventQueue(int capacity);
+    explicit SensorEventQueue(int capacity);
     ~SensorEventQueue();
 
     // Returns length of region, between zero and min(capacity, requestedLength). If there is any
diff --git a/modules/thermal/thermal.c b/modules/thermal/thermal.c
index 6ba5845..7f4de3b 100644
--- a/modules/thermal/thermal.c
+++ b/modules/thermal/thermal.c
@@ -138,8 +138,9 @@
             fclose(file);
             fclose(cpu_file);
             return errno ? -errno : -EIO;
+        } else {
+            fclose(cpu_file);
         }
-        fclose(cpu_file);
 
         if (list != NULL) {
             list[size] = (cpu_usage_t) {
diff --git a/modules/tv_input/Android.bp b/modules/tv_input/Android.bp
new file mode 100644
index 0000000..beac132
--- /dev/null
+++ b/modules/tv_input/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2014 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.
+
+cc_library_shared {
+    name: "tv_input.default",
+    relative_install_path: "hw",
+    shared_libs: [
+        "libcutils",
+        "liblog",
+    ],
+    srcs: ["tv_input.cpp"],
+}
diff --git a/modules/tv_input/Android.mk b/modules/tv_input/Android.mk
deleted file mode 100644
index e8aa7fc..0000000
--- a/modules/tv_input/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright (C) 2014 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SHARED_LIBRARIES := libcutils liblog
-LOCAL_SRC_FILES := tv_input.cpp
-LOCAL_MODULE := tv_input.default
-LOCAL_MODULE_TAGS := optional
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/usbcamera/Camera.h b/modules/usbcamera/Camera.h
index 6419c7d..4051345 100644
--- a/modules/usbcamera/Camera.h
+++ b/modules/usbcamera/Camera.h
@@ -38,7 +38,7 @@
     public:
         // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
         // module is a handle to the HAL module, used when the device is opened.
-        Camera(int id);
+        explicit Camera(int id);
         virtual ~Camera();
 
         // Common Camera Device Operations (see <hardware/camera_common.h>)
diff --git a/modules/usbcamera/HotplugThread.h b/modules/usbcamera/HotplugThread.h
index a13adb7..625dcb4 100644
--- a/modules/usbcamera/HotplugThread.h
+++ b/modules/usbcamera/HotplugThread.h
@@ -36,7 +36,7 @@
 class HotplugThread : public android::Thread {
 
     public:
-        HotplugThread(CameraHAL *hal);
+        explicit HotplugThread(CameraHAL *hal);
         ~HotplugThread();
 
         // Override below two methods for proper cleanup.
diff --git a/modules/usbcamera/UsbCamera.cpp b/modules/usbcamera/UsbCamera.cpp
index 82a1145..d0aaded 100644
--- a/modules/usbcamera/UsbCamera.cpp
+++ b/modules/usbcamera/UsbCamera.cpp
@@ -26,7 +26,7 @@
 #include "Camera.h"
 #include "UsbCamera.h"
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 namespace usb_camera_hal {
 
diff --git a/modules/usbcamera/UsbCamera.h b/modules/usbcamera/UsbCamera.h
index fe52ade..57017fe 100644
--- a/modules/usbcamera/UsbCamera.h
+++ b/modules/usbcamera/UsbCamera.h
@@ -28,7 +28,7 @@
  */
 class UsbCamera : public Camera {
     public:
-        UsbCamera(int id);
+        explicit UsbCamera(int id);
         ~UsbCamera();
 
     private:
diff --git a/modules/vibrator/Android.bp b/modules/vibrator/Android.bp
new file mode 100644
index 0000000..f9afd45
--- /dev/null
+++ b/modules/vibrator/Android.bp
@@ -0,0 +1,24 @@
+// Copyright (C) 2012 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.
+
+cc_library_shared {
+    name: "vibrator.default",
+
+    // HAL module implementation stored in
+    // hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
+    relative_install_path: "hw",
+    include_dirs: ["hardware/libhardware"],
+    srcs: ["vibrator.c"],
+    shared_libs: ["liblog"],
+}
diff --git a/modules/vibrator/Android.mk b/modules/vibrator/Android.mk
deleted file mode 100644
index b6b480c..0000000
--- a/modules/vibrator/Android.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright (C) 2012 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)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := vibrator.default
-
-# HAL module implementation stored in
-# hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_C_INCLUDES := hardware/libhardware
-LOCAL_SRC_FILES := vibrator.c
-LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
index 6b3ce57..c3c2951 100644
--- a/modules/vibrator/vibrator.c
+++ b/modules/vibrator/vibrator.c
@@ -21,11 +21,15 @@
 
 #include <malloc.h>
 #include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <math.h>
 
+#define TIMEOUT_STR_LEN         20
+
 static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable";
 
 static int vibra_exists() {
@@ -33,7 +37,6 @@
 
     fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
     if(fd < 0) {
-        ALOGE("Vibrator file does not exist : %d", fd);
         return 0;
     }
 
@@ -41,27 +44,24 @@
     return 1;
 }
 
-static int sendit(unsigned int timeout_ms)
+static int write_value(const char *file, const char *value)
 {
     int to_write, written, ret, fd;
 
-    char value[20]; /* large enough for millions of years */
-
-    fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
-    if(fd < 0) {
+    fd = TEMP_FAILURE_RETRY(open(file, O_WRONLY));
+    if (fd < 0) {
         return -errno;
     }
 
-    to_write = snprintf(value, sizeof(value), "%u\n", timeout_ms);
+    to_write = strlen(value) + 1;
     written = TEMP_FAILURE_RETRY(write(fd, value, to_write));
-
     if (written == -1) {
         ret = -errno;
     } else if (written != to_write) {
         /* even though EAGAIN is an errno value that could be set
            by write() in some cases, none of them apply here.  So, this return
            value can be clearly identified when debugging and suggests the
-           caller that it may try to call vibraror_on() again */
+           caller that it may try to call vibrator_on() again */
         ret = -EAGAIN;
     } else {
         ret = 0;
@@ -73,6 +73,14 @@
     return ret;
 }
 
+static int sendit(unsigned int timeout_ms)
+{
+    char value[TIMEOUT_STR_LEN]; /* large enough for millions of years */
+
+    snprintf(value, sizeof(value), "%u", timeout_ms);
+    return write_value(THE_DEVICE, value);
+}
+
 static int vibra_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
 {
     /* constant on, up to maximum allowed time */
@@ -84,6 +92,43 @@
     return sendit(0);
 }
 
+static const char LED_DEVICE[] = "/sys/class/leds/vibrator";
+
+static int write_led_file(const char *file, const char *value)
+{
+    char file_str[50];
+
+    snprintf(file_str, sizeof(file_str), "%s/%s", LED_DEVICE, file);
+    return write_value(file_str, value);
+}
+
+static int vibra_led_exists()
+{
+    return !write_led_file("trigger", "transient");
+}
+
+static int vibra_led_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
+{
+    int ret;
+    char value[TIMEOUT_STR_LEN]; /* large enough for millions of years */
+
+    ret = write_led_file("state", "1");
+    if (ret)
+        return ret;
+
+    snprintf(value, sizeof(value), "%u\n", timeout_ms);
+    ret = write_led_file("duration", value);
+    if (ret)
+        return ret;
+
+    return write_led_file("activate", "1");
+}
+
+static int vibra_led_off(vibrator_device_t* vibradev __unused)
+{
+    return write_led_file("activate", "0");
+}
+
 static int vibra_close(hw_device_t *device)
 {
     free(device);
@@ -92,7 +137,15 @@
 
 static int vibra_open(const hw_module_t* module, const char* id __unused,
                       hw_device_t** device __unused) {
-    if (!vibra_exists()) {
+    bool use_led;
+
+    if (vibra_exists()) {
+        ALOGD("Vibrator using timed_output");
+        use_led = false;
+    } else if (vibra_led_exists()) {
+        ALOGD("Vibrator using LED trigger");
+        use_led = true;
+    } else {
         ALOGE("Vibrator device does not exist. Cannot start vibrator");
         return -ENODEV;
     }
@@ -109,8 +162,13 @@
     vibradev->common.version = HARDWARE_DEVICE_API_VERSION(1,0);
     vibradev->common.close = vibra_close;
 
-    vibradev->vibrator_on = vibra_on;
-    vibradev->vibrator_off = vibra_off;
+    if (use_led) {
+        vibradev->vibrator_on = vibra_led_on;
+        vibradev->vibrator_off = vibra_led_off;
+    } else {
+        vibradev->vibrator_on = vibra_on;
+        vibradev->vibrator_off = vibra_off;
+    }
 
     *device = (hw_device_t *) vibradev;
 
diff --git a/tests/camera2/CameraModuleFixture.h b/tests/camera2/CameraModuleFixture.h
index 661c693..25513af 100644
--- a/tests/camera2/CameraModuleFixture.h
+++ b/tests/camera2/CameraModuleFixture.h
@@ -35,7 +35,7 @@
 template <bool InfoQuirk = false>
 struct CameraModuleFixture {
 
-    CameraModuleFixture(int CameraID = -1) {
+    explicit CameraModuleFixture(int CameraID = -1) {
         TEST_EXTENSION_FORKING_CONSTRUCTOR;
 
         mCameraID = CameraID;
diff --git a/tests/camera2/CameraMultiStreamTests.cpp b/tests/camera2/CameraMultiStreamTests.cpp
index eb64db1..f4aeab7 100644
--- a/tests/camera2/CameraMultiStreamTests.cpp
+++ b/tests/camera2/CameraMultiStreamTests.cpp
@@ -334,7 +334,7 @@
             int height,
             const sp<CameraDeviceBase>& device,
             CameraStreamParams param = DEFAULT_STREAM_PARAMETERS,
-            sp<Surface> surface = NULL,
+            const sp<Surface>& surface = NULL,
             bool useCpuConsumer = true) {
         param.mFormat = MapAutoFormat(param.mFormat);
         return new CameraStream(width, height, device,
diff --git a/tests/camera2/CameraStreamFixture.h b/tests/camera2/CameraStreamFixture.h
index bf7fb42..92ff05b 100644
--- a/tests/camera2/CameraStreamFixture.h
+++ b/tests/camera2/CameraStreamFixture.h
@@ -71,7 +71,7 @@
     : public CameraModuleFixture</*InfoQuirk*/true> {
 
 public:
-    CameraStreamFixture(CameraStreamParams p)
+    explicit CameraStreamFixture(CameraStreamParams p)
     : CameraModuleFixture(TestSettings::DeviceId()) {
         TEST_EXTENSION_FORKING_CONSTRUCTOR;
 
diff --git a/tests/camera2/camera2_utils.cpp b/tests/camera2/camera2_utils.cpp
index c63c32a..dab0ae9 100644
--- a/tests/camera2/camera2_utils.cpp
+++ b/tests/camera2/camera2_utils.cpp
@@ -176,7 +176,7 @@
 }
 
 status_t MetadataQueue::freeBuffers(List<camera_metadata_t*>::iterator start,
-                                    List<camera_metadata_t*>::iterator end) {
+                                    const List<camera_metadata_t*>::iterator& end) {
     while (start != end) {
         free_camera_metadata(*start);
         start = mStreamSlot.erase(start);
diff --git a/tests/camera2/camera2_utils.h b/tests/camera2/camera2_utils.h
index ab1fcfb..274ee76 100644
--- a/tests/camera2/camera2_utils.h
+++ b/tests/camera2/camera2_utils.h
@@ -65,7 +65,7 @@
 
   private:
     status_t freeBuffers(List<camera_metadata_t*>::iterator start,
-                         List<camera_metadata_t*>::iterator end);
+                         const List<camera_metadata_t*>::iterator& end);
 
     camera2_device_t *mDevice;
 
@@ -166,7 +166,7 @@
  */
 class StreamAdapter: public camera2_stream_ops {
   public:
-    StreamAdapter(sp<IGraphicBufferProducer> consumer);
+    explicit StreamAdapter(sp<IGraphicBufferProducer> consumer);
 
     ~StreamAdapter();
 
diff --git a/tests/fingerprint/Android.bp b/tests/fingerprint/Android.bp
new file mode 100644
index 0000000..7de3dee
--- /dev/null
+++ b/tests/fingerprint/Android.bp
@@ -0,0 +1,14 @@
+cc_test {
+    name: "fingerprint_tests",
+    srcs: ["fingerprint_tests.cpp"],
+
+    shared_libs: [
+        "liblog",
+        "libhardware",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+    ],
+}
diff --git a/tests/fingerprint/Android.mk b/tests/fingerprint/Android.mk
deleted file mode 100644
index 4f03c39..0000000
--- a/tests/fingerprint/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    fingerprint_tests.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-    libhardware \
-
-#LOCAL_C_INCLUDES += \
-#    system/media/camera/include \
-
-LOCAL_CFLAGS += -Wall -Wextra
-
-LOCAL_MODULE:= fingerprint_tests
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_NATIVE_TEST)
diff --git a/tests/hardware/Android.bp b/tests/hardware/Android.bp
new file mode 100644
index 0000000..668e28f
--- /dev/null
+++ b/tests/hardware/Android.bp
@@ -0,0 +1,15 @@
+cc_library_static {
+    name: "static-hal-check",
+    srcs: [
+        "struct-size.cpp",
+        "struct-offset.cpp",
+        "struct-last.cpp",
+    ],
+    shared_libs: ["libhardware"],
+    cflags: [
+        "-std=gnu++11",
+        "-O0",
+    ],
+
+    include_dirs: ["system/media/camera/include"],
+}
diff --git a/tests/hardware/Android.mk b/tests/hardware/Android.mk
deleted file mode 100644
index 02540c9..0000000
--- a/tests/hardware/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := static-hal-check
-LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp struct-last.cpp
-LOCAL_SHARED_LIBRARIES := libhardware
-LOCAL_CFLAGS := -std=gnu++11 -O0
-
-LOCAL_C_INCLUDES += \
-    system/media/camera/include
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/tests/hwc/cnativewindow.c b/tests/hwc/cnativewindow.c
index 5c16afb..5b1d78e 100644
--- a/tests/hwc/cnativewindow.c
+++ b/tests/hwc/cnativewindow.c
@@ -37,7 +37,7 @@
 static int trace_level = 1;
 
 #define _TRACE(n,fmt...) \
-	do { if (trace_level >= n) fprintf(stderr, "CNW: " fmt); } while (0)
+	do { if (trace_level >= (n)) fprintf(stderr, "CNW: " fmt); } while (0)
 
 #define ERROR(fmt...) _TRACE(0, fmt)
 #define INFO(fmt...) _TRACE(1, fmt)
diff --git a/tests/input/evdev/Android.mk b/tests/input/evdev/Android.mk
index 3aeb2f8..b892a7f 100644
--- a/tests/input/evdev/Android.mk
+++ b/tests/input/evdev/Android.mk
@@ -2,7 +2,6 @@
 include $(CLEAR_VARS)
 
 LOCAL_C_INCLUDES += hardware/libhardware/modules/input/evdev
-LOCAL_C_INCLUDES += $(TOP)/external/gmock/include
 
 LOCAL_SRC_FILES:= \
     BitUtils_test.cpp \
diff --git a/tests/input/evdev/InputHub_test.cpp b/tests/input/evdev/InputHub_test.cpp
index 64671ff..3d62152 100644
--- a/tests/input/evdev/InputHub_test.cpp
+++ b/tests/input/evdev/InputHub_test.cpp
@@ -50,9 +50,9 @@
         mInputCb(kNoopInputCb), mDeviceAddedCb(kNoopDeviceCb), mDeviceRemovedCb(kNoopDeviceCb) {}
     virtual ~TestInputCallback() = default;
 
-    void setInputCallback(InputCbFunc cb) { mInputCb = cb; }
-    void setDeviceAddedCallback(DeviceCbFunc cb) { mDeviceAddedCb = cb; }
-    void setDeviceRemovedCallback(DeviceCbFunc cb) { mDeviceRemovedCb = cb; }
+    void setInputCallback(const InputCbFunc& cb) { mInputCb = cb; }
+    void setDeviceAddedCallback(const DeviceCbFunc& cb) { mDeviceAddedCb = cb; }
+    void setDeviceRemovedCallback(const DeviceCbFunc& cb) { mDeviceRemovedCb = cb; }
 
     virtual void onInputEvent(const std::shared_ptr<InputDeviceNode>& node, InputEvent& event,
             nsecs_t event_time) override {
diff --git a/tests/input/evdev/TestHelpers.h b/tests/input/evdev/TestHelpers.h
index 461db04..d26adfb 100644
--- a/tests/input/evdev/TestHelpers.h
+++ b/tests/input/evdev/TestHelpers.h
@@ -42,7 +42,7 @@
  */
 class TempFile {
 public:
-    TempFile(const char* path);
+    explicit TempFile(const char* path);
     ~TempFile();
 
     // No copy or assign
diff --git a/tests/keymaster/keymaster_test.cpp b/tests/keymaster/keymaster_test.cpp
index 6266d40..3040a5c 100644
--- a/tests/keymaster/keymaster_test.cpp
+++ b/tests/keymaster/keymaster_test.cpp
@@ -41,7 +41,7 @@
 
 class UniqueBlob : public UniquePtr<uint8_t[]> {
 public:
-    UniqueBlob(size_t length) :
+    explicit UniqueBlob(size_t length) :
             mLength(length) {
     }
 
diff --git a/tests/nusensors/Android.bp b/tests/nusensors/Android.bp
new file mode 100644
index 0000000..e923468
--- /dev/null
+++ b/tests/nusensors/Android.bp
@@ -0,0 +1,10 @@
+cc_binary {
+    name: "test-nusensors",
+
+    srcs: ["nusensors.cpp"],
+
+    shared_libs: [
+        "libcutils",
+        "libhardware",
+    ],
+}
diff --git a/tests/nusensors/Android.mk b/tests/nusensors/Android.mk
deleted file mode 100644
index ef49096..0000000
--- a/tests/nusensors/Android.mk
+++ /dev/null
@@ -1,14 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	nusensors.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils libhardware
-
-LOCAL_MODULE:= test-nusensors
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_EXECUTABLE)
diff --git a/tests/vehicle/vehicle-hal-tool.c b/tests/vehicle/vehicle-hal-tool.c
index c93790a..e85df62 100755
--- a/tests/vehicle/vehicle-hal-tool.c
+++ b/tests/vehicle/vehicle-hal-tool.c
@@ -98,6 +98,7 @@
             memcpy(ascii_out, data->value.str_value.data, data->value.str_value.len);
             ascii_out[data->value.str_value.len] = '\0';
             printf("Value Type: STRING %s\n", ascii_out);
+            free(ascii_out);
             break;
         case VEHICLE_VALUE_TYPE_BYTES:
             printf("Value type: BYTES\n Size: %d", data->value.bytes_value.len);