Update the signature of init function to include whether the device is am: 3e7b35ee18 am: 43e0dd5936

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/libhardware/+/12308134

Change-Id: I4523232636dfbc6e7718af583bcf06c68c64f976
diff --git a/Android.bp b/Android.bp
index 9c5a9cc..e49aa25 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,10 +5,12 @@
     header_libs: [
         "libaudio_system_headers",
         "libsystem_headers",
+        "libcutils_headers",
     ],
     export_header_lib_headers: [
         "libaudio_system_headers",
-        "libsystem_headers"
+        "libsystem_headers",
+        "libcutils_headers",
     ],
 
     export_include_dirs: ["include"],
@@ -31,6 +33,10 @@
     export_header_lib_headers: ["libhardware_headers"],
 
     vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
 }
 
 subdirs = [
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..8d33584
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,5 @@
+eisenbach@google.com
+jpawlowski@google.com
+swillden@google.com
+malchev@google.com
+smoreland@google.com
diff --git a/include/hardware/ble_advertiser.h b/include/hardware/ble_advertiser.h
index 02d553f..5284800 100644
--- a/include/hardware/ble_advertiser.h
+++ b/include/hardware/ble_advertiser.h
@@ -57,7 +57,7 @@
   /** Registers an advertiser with the stack */
   virtual void RegisterAdvertiser(IdStatusCallback) = 0;
 
-  using GetAddressCallback = base::Callback<void(uint8_t /* address_type*/, bt_bdaddr_t /*address*/)>;
+  using GetAddressCallback = base::Callback<void(uint8_t /* address_type*/, RawAddress /*address*/)>;
   virtual void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) = 0;
 
   /* Set the parameters as per spec, user manual specified values */
diff --git a/include/hardware/ble_scanner.h b/include/hardware/ble_scanner.h
index c8f9ec2..2d3ec82 100644
--- a/include/hardware/ble_scanner.h
+++ b/include/hardware/ble_scanner.h
@@ -37,7 +37,7 @@
 
 /** Callback for scan results */
 typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type,
-                                     bt_bdaddr_t *bda, uint8_t primary_phy,
+                                     RawAddress *bda, uint8_t primary_phy,
                                      uint8_t secondary_phy,
                                      uint8_t advertising_sid, int8_t tx_power,
                                      int8_t rssi, uint16_t periodic_adv_int,
@@ -90,7 +90,7 @@
                                    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,
+                                   const RawAddress *bd_addr, char addr_type,
                                    std::vector<uint8_t> data,
                                    std::vector<uint8_t> p_mask,
                                    FilterConfigCallback cb) = 0;
@@ -125,12 +125,12 @@
   using StartSyncCb =
       base::Callback<void(uint8_t status, uint16_t sync_handle,
                           uint8_t advertising_sid, uint8_t address_type,
-                          bt_bdaddr_t address, uint8_t phy, uint16_t interval)>;
+                          RawAddress address, uint8_t phy, uint16_t interval)>;
   using SyncReportCb =
       base::Callback<void(uint16_t sync_handle, int8_t tx_power, int8_t rssi,
                           uint8_t status, std::vector<uint8_t> data)>;
   using SyncLostCb = base::Callback<void(uint16_t sync_handle)>;
-  virtual void StartSync(uint8_t sid, bt_bdaddr_t address, uint16_t skip,
+  virtual void StartSync(uint8_t sid, RawAddress address, uint16_t skip,
                          uint16_t timeout, StartSyncCb start_cb,
                          SyncReportCb report_cb, SyncLostCb lost_cb) = 0;
   virtual void StopSync(uint16_t handle) = 0;
diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h
index bbf2fb2..14c3067 100644
--- a/include/hardware/bluetooth.h
+++ b/include/hardware/bluetooth.h
@@ -24,6 +24,8 @@
 
 #include <hardware/hardware.h>
 
+#include <raw_address.h>
+
 __BEGIN_DECLS
 
 /**
@@ -55,11 +57,6 @@
 /** Bluetooth test interface IDs */
 #define BT_TEST_INTERFACE_MCAP_ID "mcap_test"
 
-/** Bluetooth Address */
-typedef struct {
-    uint8_t address[6];
-} __attribute__((packed))bt_bdaddr_t;
-
 /** Bluetooth Device Name */
 typedef struct {
     uint8_t name[249];
@@ -185,7 +182,7 @@
     /**
      * Description - Bluetooth Device Address
      * Access mode - Only GET.
-     * Data type   - bt_bdaddr_t
+     * Data type   - RawAddress
      */
     BT_PROPERTY_BDADDR,
     /**
@@ -223,7 +220,7 @@
     /**
      * Description - List of bonded devices
      * Access mode - Only GET.
-     * Data type   - Array of bt_bdaddr_t of the bonded remote devices
+     * Data type   - Array of RawAddress of the bonded remote devices
      *               (Array size inferred from property length).
      */
     BT_PROPERTY_ADAPTER_BONDED_DEVICES,
@@ -334,7 +331,7 @@
  * multiple properties - num_properties shall be 1
  */
 typedef void (*remote_device_properties_callback)(bt_status_t status,
-                                                       bt_bdaddr_t *bd_addr,
+                                                       RawAddress *bd_addr,
                                                        int num_properties,
                                                        bt_property_t *properties);
 
@@ -348,7 +345,7 @@
 typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
 
 /** Bluetooth Legacy PinKey Request callback */
-typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
+typedef void (*pin_request_callback)(RawAddress *remote_bd_addr,
                                         bt_bdname_t *bd_name, uint32_t cod, bool min_16_digit);
 
 /** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
@@ -356,7 +353,7 @@
  *  BT_SSP_PAIRING_PASSKEY_ENTRY */
 /* TODO: Passkey request callback shall not be needed for devices with display
  * capability. We still need support this in the stack for completeness */
-typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
+typedef void (*ssp_request_callback)(RawAddress *remote_bd_addr,
                                         bt_bdname_t *bd_name,
                                         uint32_t cod,
                                         bt_ssp_variant_t pairing_variant,
@@ -365,11 +362,11 @@
 /** Bluetooth Bond state changed callback */
 /* Invoked in response to create_bond, cancel_bond or remove_bond */
 typedef void (*bond_state_changed_callback)(bt_status_t status,
-                                               bt_bdaddr_t *remote_bd_addr,
+                                               RawAddress *remote_bd_addr,
                                                bt_bond_state_t state);
 
 /** Bluetooth ACL connection state changed callback */
-typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
+typedef void (*acl_state_changed_callback)(bt_status_t status, RawAddress *remote_bd_addr,
                                             bt_acl_state_t state);
 
 typedef enum {
@@ -490,27 +487,27 @@
 
     /** Set Bluetooth Adapter property of 'type' */
     /* Based on the type, val shall be one of
-     * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
+     * RawAddress or bt_bdname_t or bt_scanmode_t etc
      */
     int (*set_adapter_property)(const bt_property_t *property);
 
     /** Get all Remote Device properties */
-    int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
+    int (*get_remote_device_properties)(RawAddress *remote_addr);
 
     /** Get Remote Device property of 'type' */
-    int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
+    int (*get_remote_device_property)(RawAddress *remote_addr,
                                       bt_property_type_t type);
 
     /** Set Remote Device property of 'type' */
-    int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
+    int (*set_remote_device_property)(RawAddress *remote_addr,
                                       const bt_property_t *property);
 
     /** Get Remote Device's service record  for the given UUID */
-    int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
+    int (*get_remote_service_record)(RawAddress *remote_addr,
                                      bt_uuid_t *uuid);
 
     /** Start SDP to get remote services */
-    int (*get_remote_services)(bt_bdaddr_t *remote_addr);
+    int (*get_remote_services)(RawAddress *remote_addr);
 
     /** Start Discovery */
     int (*start_discovery)(void);
@@ -519,28 +516,28 @@
     int (*cancel_discovery)(void);
 
     /** Create Bluetooth Bonding */
-    int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
+    int (*create_bond)(const RawAddress *bd_addr, int transport);
 
     /** Create Bluetooth Bond using out of band data */
-    int (*create_bond_out_of_band)(const bt_bdaddr_t *bd_addr, int transport,
+    int (*create_bond_out_of_band)(const RawAddress *bd_addr, int transport,
                                    const bt_out_of_band_data_t *oob_data);
 
     /** Remove Bond */
-    int (*remove_bond)(const bt_bdaddr_t *bd_addr);
+    int (*remove_bond)(const RawAddress *bd_addr);
 
     /** Cancel Bond */
-    int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
+    int (*cancel_bond)(const RawAddress *bd_addr);
 
     /**
      * Get the connection status for a given remote device.
      * return value of 0 means the device is not connected,
      * non-zero return status indicates an active connection.
      */
-    int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
+    int (*get_connection_state)(const RawAddress *bd_addr);
 
     /** BT Legacy PinKey Reply */
     /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
-    int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
+    int (*pin_reply)(const RawAddress *bd_addr, uint8_t accept,
                      uint8_t pin_len, bt_pin_code_t *pin_code);
 
     /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
@@ -548,7 +545,7 @@
      * BT_SSP_VARIANT_CONSENT
      * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
      * shall be zero */
-    int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+    int (*ssp_reply)(const RawAddress *bd_addr, bt_ssp_variant_t variant,
                      uint8_t accept, uint32_t passkey);
 
     /** Get Bluetooth profile interface */
@@ -597,7 +594,7 @@
      * first |len| bytes of the its device address match |addr|.
      * NOTE: |feature| has to match an item defined in interop_feature_t (interop.h).
      */
-    void (*interop_database_add)(uint16_t feature, const bt_bdaddr_t *addr, size_t len);
+    void (*interop_database_add)(uint16_t feature, const RawAddress *addr, size_t len);
 } bt_interface_t;
 
 /** TODO: Need to add APIs for Service Discovery, Service authorization and
diff --git a/include/hardware/bt_av.h b/include/hardware/bt_av.h
index 91ae2ac..36722d4 100644
--- a/include/hardware/bt_av.h
+++ b/include/hardware/bt_av.h
@@ -130,13 +130,13 @@
  *  state will have one of the values from btav_connection_state_t
  */
 typedef void (* btav_connection_state_callback)(btav_connection_state_t state,
-                                                    bt_bdaddr_t *bd_addr);
+                                                    RawAddress *bd_addr);
 
 /** Callback for audiopath state change.
  *  state will have one of the values from btav_audio_state_t
  */
 typedef void (* btav_audio_state_callback)(btav_audio_state_t state,
-                                               bt_bdaddr_t *bd_addr);
+                                               RawAddress *bd_addr);
 
 /** Callback for audio configuration change.
  *  Used only for the A2DP Source interface.
@@ -151,7 +151,7 @@
  *  sample_rate: sample rate in Hz
  *  channel_count: number of channels (1 for mono, 2 for stereo)
  */
-typedef void (* btav_audio_sink_config_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btav_audio_sink_config_callback)(RawAddress *bd_addr,
                                                  uint32_t sample_rate,
                                                  uint8_t channel_count);
 
@@ -197,10 +197,10 @@
                 std::vector<btav_a2dp_codec_config_t> codec_priorities);
 
     /** connect to headset */
-    bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*connect)( RawAddress *bd_addr );
 
     /** dis-connect from headset */
-    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*disconnect)( RawAddress *bd_addr );
 
     /** configure the codecs settings preferences */
     bt_status_t (*config_codec)(std::vector<btav_a2dp_codec_config_t> codec_preferences);
@@ -222,10 +222,10 @@
     bt_status_t (*init)( btav_sink_callbacks_t* callbacks );
 
     /** connect to headset */
-    bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*connect)( RawAddress *bd_addr );
 
     /** dis-connect from headset */
-    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*disconnect)( RawAddress *bd_addr );
 
     /** Closes the interface. */
     void  (*cleanup)( void );
diff --git a/include/hardware/bt_common_types.h b/include/hardware/bt_common_types.h
index cff3072..8d13ed4 100644
--- a/include/hardware/bt_common_types.h
+++ b/include/hardware/bt_common_types.h
@@ -34,7 +34,7 @@
     uint8_t  tx_power;
     int8_t  rssi_value;
     uint16_t time_stamp;
-    bt_bdaddr_t bd_addr;
+    RawAddress bd_addr;
     uint8_t  adv_pkt_len;
     uint8_t  *p_adv_pkt_data;
     uint8_t  scan_rsp_len;
diff --git a/include/hardware/bt_gatt_client.h b/include/hardware/bt_gatt_client.h
index c40fa6b..cafc2da 100644
--- a/include/hardware/bt_gatt_client.h
+++ b/include/hardware/bt_gatt_client.h
@@ -60,7 +60,7 @@
 typedef struct
 {
     uint8_t             value[BTGATT_MAX_ATTR_LEN];
-    bt_bdaddr_t         bda;
+    RawAddress         bda;
     uint16_t            handle;
     uint16_t            len;
     uint8_t             is_notify;
@@ -68,7 +68,7 @@
 
 typedef struct
 {
-    bt_bdaddr_t        *bda1;
+    RawAddress        *bda1;
     bt_uuid_t          *uuid1;
     uint16_t            u1;
     uint16_t            u2;
@@ -99,15 +99,14 @@
 /** BT-GATT Client callback structure. */
 
 /** Callback invoked in response to register_client */
-typedef void (*register_client_callback)(int status, int client_if,
-                bt_uuid_t *app_uuid);
+typedef void (*register_client_callback)(int status, int client_if, const bt_uuid_t& app_uuid);
 
 /** GATT open callback invoked in response to open */
-typedef void (*connect_callback)(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
+typedef void (*connect_callback)(int conn_id, int status, int client_if, const RawAddress& bda);
 
 /** Callback invoked in response to close */
 typedef void (*disconnect_callback)(int conn_id, int status,
-                int client_if, bt_bdaddr_t* bda);
+                int client_if, const RawAddress& bda);
 
 /**
  * Invoked in response to search_service when the GATT service search
@@ -123,7 +122,7 @@
  * Remote device notification callback, invoked when a remote device sends
  * a notification or indication that a client has registered for.
  */
-typedef void (*notify_callback)(int conn_id, btgatt_notify_params_t *p_data);
+typedef void (*notify_callback)(int conn_id, const btgatt_notify_params_t& p_data);
 
 /** Reports result of a GATT read operation */
 typedef void (*read_characteristic_callback)(int conn_id, int status,
@@ -137,13 +136,13 @@
 
 /** Callback invoked in response to read_descriptor */
 typedef void (*read_descriptor_callback)(int conn_id, int status,
-                btgatt_read_params_t *p_data);
+                const btgatt_read_params_t& p_data);
 
 /** Callback invoked in response to write_descriptor */
 typedef void (*write_descriptor_callback)(int conn_id, int status, uint16_t handle);
 
 /** Callback triggered in response to read_remote_rssi */
-typedef void (*read_remote_rssi_callback)(int client_if, bt_bdaddr_t* bda,
+typedef void (*read_remote_rssi_callback)(int client_if, const RawAddress& bda,
                                           int rssi, int status);
 
 /** Callback invoked when the MTU for a given connection changes */
@@ -158,13 +157,13 @@
 typedef void (*congestion_callback)(int conn_id, bool congested);
 
 /** GATT get database callback */
-typedef void (*get_gatt_db_callback)(int conn_id, btgatt_db_element_t *db, int count);
+typedef void (*get_gatt_db_callback)(int conn_id, const btgatt_db_element_t* db, int count);
 
 /** GATT services between start_handle and end_handle were removed */
 typedef void (*services_removed_callback)(int conn_id, uint16_t start_handle, uint16_t end_handle);
 
 /** GATT services were added */
-typedef void (*services_added_callback)(int conn_id, btgatt_db_element_t *added, int added_count);
+typedef void (*services_added_callback)(int conn_id, const btgatt_db_element_t& added, int added_count);
 
 /** Callback invoked when the PHY for a given connection changes */
 typedef void (*phy_updated_callback)(int conn_id, uint8_t tx_phy,
@@ -201,33 +200,33 @@
 
 typedef struct {
     /** Registers a GATT client application with the stack */
-    bt_status_t (*register_client)( bt_uuid_t *uuid );
+    bt_status_t (*register_client)(const bt_uuid_t& uuid);
 
     /** Unregister a client application from the stack */
-    bt_status_t (*unregister_client)(int client_if );
+    bt_status_t (*unregister_client)(int client_if);
 
     /** Create a connection to a remote LE or dual-mode device */
-    bt_status_t (*connect)(int client_if, const bt_bdaddr_t *bd_addr,
+    bt_status_t (*connect)(int client_if, const RawAddress& bd_addr,
                            bool is_direct, int transport, bool opportunistic,
                            int initiating_phys);
 
     /** Disconnect a remote device or cancel a pending connection */
-    bt_status_t (*disconnect)( int client_if, const bt_bdaddr_t *bd_addr,
+    bt_status_t (*disconnect)( int client_if, const RawAddress& bd_addr,
                     int conn_id);
 
     /** Clear the attribute cache for a given device */
-    bt_status_t (*refresh)( int client_if, const bt_bdaddr_t *bd_addr );
+    bt_status_t (*refresh)( int client_if, const RawAddress& bd_addr);
 
     /**
      * Enumerate all GATT services on a connected device.
      * Optionally, the results can be filtered for a given UUID.
      */
-    bt_status_t (*search_service)(int conn_id, bt_uuid_t *filter_uuid );
+    bt_status_t (*search_service)(int conn_id, const bt_uuid_t *filter_uuid);
 
     /**
      * Sead "Find service by UUID" request. Used only for PTS tests.
      */
-    void (*btif_gattc_discover_service_by_uuid)(int conn_id, bt_uuid_t *uuid);
+    void (*btif_gattc_discover_service_by_uuid)(int conn_id, const bt_uuid_t& uuid);
 
     /** Read a characteristic on a remote device */
     bt_status_t (*read_characteristic)(int conn_id, uint16_t handle,
@@ -235,7 +234,7 @@
 
     /** Read a characteristic on a remote device */
     bt_status_t (*read_using_characteristic_uuid)(
-        int conn_id, bt_uuid_t *uuid, uint16_t s_handle,
+        int conn_id, const bt_uuid_t& uuid, uint16_t s_handle,
         uint16_t e_handle, int auth_req);
 
     /** Write a remote characteristic */
@@ -258,35 +257,35 @@
      * characteristic
      */
     bt_status_t (*register_for_notification)( int client_if,
-                    const bt_bdaddr_t *bd_addr, uint16_t handle);
+                    const RawAddress& bd_addr, uint16_t handle);
 
     /** Deregister a previous request for notifications/indications */
     bt_status_t (*deregister_for_notification)( int client_if,
-                    const bt_bdaddr_t *bd_addr, uint16_t handle);
+                    const RawAddress& bd_addr, uint16_t handle);
 
     /** Request RSSI for a given remote device */
-    bt_status_t (*read_remote_rssi)( int client_if, const bt_bdaddr_t *bd_addr);
+    bt_status_t (*read_remote_rssi)(int client_if, const RawAddress& bd_addr);
 
     /** Determine the type of the remote device (LE, BR/EDR, Dual-mode) */
-    int (*get_device_type)( const bt_bdaddr_t *bd_addr );
+    int (*get_device_type)(const RawAddress &bd_addr);
 
     /** Configure the MTU for a given connection */
     bt_status_t (*configure_mtu)(int conn_id, int mtu);
 
     /** Request a connection parameter update */
-    bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
+    bt_status_t (*conn_parameter_update)(const RawAddress& bd_addr, int min_interval,
                     int max_interval, int latency, int timeout);
 
-    bt_status_t (*set_preferred_phy)(int conn_id, uint8_t tx_phy,
+    bt_status_t (*set_preferred_phy)(const RawAddress& bd_addr, uint8_t tx_phy,
                                      uint8_t rx_phy, uint16_t phy_options);
 
     bt_status_t (*read_phy)(
-        int conn_id,
+        const RawAddress& bd_addr,
         base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)>
             cb);
 
     /** Test mode interface */
-    bt_status_t (*test_command)( int command, btgatt_test_params_t* params);
+    bt_status_t (*test_command)( int command, const btgatt_test_params_t& params);
 
     /** Get gatt db content */
     bt_status_t (*get_gatt_db)( int conn_id);
diff --git a/include/hardware/bt_gatt_server.h b/include/hardware/bt_gatt_server.h
index 36259a1..93ecc02 100644
--- a/include/hardware/bt_gatt_server.h
+++ b/include/hardware/bt_gatt_server.h
@@ -46,11 +46,11 @@
 
 /** Callback invoked in response to register_server */
 typedef void (*register_server_callback)(int status, int server_if,
-                bt_uuid_t *app_uuid);
+                const bt_uuid_t& app_uuid);
 
 /** Callback indicating that a remote device has connected or been disconnected */
 typedef void (*connection_callback)(int conn_id, int server_if, int connected,
-                                    bt_bdaddr_t *bda);
+                                    const RawAddress& bda);
 
 /** Callback invoked in response to create_service */
 typedef void (*service_added_callback)(int status, int server_if,
@@ -68,20 +68,20 @@
  * Callback invoked when a remote device has requested to read a characteristic
  * or descriptor. The application must respond by calling send_response
  */
-typedef void (*request_read_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
+typedef void (*request_read_callback)(int conn_id, int trans_id, const RawAddress& bda,
                                       int attr_handle, int offset, bool is_long);
 
 /**
  * Callback invoked when a remote device has requested to write to a
  * characteristic or descriptor.
  */
-typedef void (*request_write_callback)(int conn_id, int trans_id, bt_bdaddr_t *bda,
+typedef void (*request_write_callback)(int conn_id, int trans_id, const RawAddress& bda,
                                        int attr_handle, int offset, bool need_rsp,
                                        bool is_prep, std::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,
-                                            bt_bdaddr_t *bda, int exec_write);
+                                            const RawAddress& bda, int exec_write);
 
 /**
  * Callback triggered in response to send_response if the remote device
@@ -135,17 +135,17 @@
 /** Represents the standard BT-GATT server interface. */
 typedef struct {
     /** Registers a GATT server application with the stack */
-    bt_status_t (*register_server)( bt_uuid_t *uuid );
+    bt_status_t (*register_server)(const bt_uuid_t& uuid);
 
     /** Unregister a server application from the stack */
     bt_status_t (*unregister_server)(int server_if );
 
     /** Create a connection to a remote peripheral */
-    bt_status_t (*connect)(int server_if, const bt_bdaddr_t *bd_addr,
+    bt_status_t (*connect)(int server_if, const RawAddress& bd_addr,
                             bool is_direct, int transport);
 
     /** Disconnect an established connection or cancel a pending one */
-    bt_status_t (*disconnect)(int server_if, const bt_bdaddr_t *bd_addr,
+    bt_status_t (*disconnect)(int server_if, const RawAddress& bd_addr,
                     int conn_id );
 
     /** Create a new service */
@@ -164,13 +164,13 @@
 
     /** Send a response to a read/write operation */
     bt_status_t (*send_response)(int conn_id, int trans_id,
-                                 int status, btgatt_response_t *response);
+                                 int status, const btgatt_response_t& response);
 
-    bt_status_t (*set_preferred_phy)(int conn_id, uint8_t tx_phy,
+    bt_status_t (*set_preferred_phy)(const RawAddress& bd_addr, uint8_t tx_phy,
                                      uint8_t rx_phy, uint16_t phy_options);
 
     bt_status_t (*read_phy)(
-        int conn_id,
+        const RawAddress& bd_addr,
         base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)>
             cb);
 
diff --git a/include/hardware/bt_hd.h b/include/hardware/bt_hd.h
index 263f29f..c99ab24 100644
--- a/include/hardware/bt_hd.h
+++ b/include/hardware/bt_hd.h
@@ -65,8 +65,8 @@
     uint32_t delay_variation;
 } bthd_qos_param_t;
 
-typedef void (* bthd_application_state_callback)(bt_bdaddr_t *bd_addr, bthd_application_state_t state);
-typedef void (* bthd_connection_state_callback)(bt_bdaddr_t *bd_addr, bthd_connection_state_t state);
+typedef void (* bthd_application_state_callback)(RawAddress *bd_addr, bthd_application_state_t state);
+typedef void (* bthd_connection_state_callback)(RawAddress *bd_addr, bthd_connection_state_t state);
 typedef void (* bthd_get_report_callback)(uint8_t type, uint8_t id, uint16_t buffer_size);
 typedef void (* bthd_set_report_callback)(uint8_t type, uint8_t id, uint16_t len, uint8_t *p_data);
 typedef void (* bthd_set_protocol_callback)(uint8_t protocol);
@@ -105,7 +105,7 @@
     bt_status_t (*unregister_app)(void);
 
     /** connects to host with virtual cable */
-    bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*connect)(RawAddress *bd_addr);
 
     /** disconnects from currently connected host */
     bt_status_t (*disconnect)(void);
diff --git a/include/hardware/bt_hf.h b/include/hardware/bt_hf.h
index 892fbdb..1f6f6eb 100644
--- a/include/hardware/bt_hf.h
+++ b/include/hardware/bt_hf.h
@@ -91,89 +91,89 @@
 /** Callback for connection state change.
  *  state will have one of the values from BtHfConnectionState
  */
-typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_connection_state_callback)(bthf_connection_state_t state, RawAddress *bd_addr);
 
 /** Callback for audio connection state change.
  *  state will have one of the values from BtHfAudioState
  */
-typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_audio_state_callback)(bthf_audio_state_t state, RawAddress *bd_addr);
 
 /** Callback for VR connection state change.
  *  state will have one of the values from BtHfVRState
  */
-typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_vr_cmd_callback)(bthf_vr_state_t state, RawAddress *bd_addr);
 
 /** Callback for answer incoming call (ATA)
  */
-typedef void (* bthf_answer_call_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_answer_call_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for disconnect call (AT+CHUP)
  */
-typedef void (* bthf_hangup_call_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_hangup_call_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for disconnect call (AT+CHUP)
  *  type will denote Speaker/Mic gain (BtHfVolumeControl).
  */
-typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_volume_cmd_callback)(bthf_volume_type_t type, int volume, RawAddress *bd_addr);
 
 /** Callback for dialing an outgoing call
  *  If number is NULL, redial
  */
-typedef void (* bthf_dial_call_cmd_callback)(char *number, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_dial_call_cmd_callback)(char *number, RawAddress *bd_addr);
 
 /** Callback for sending DTMF tones
  *  tone contains the dtmf character to be sent
  */
-typedef void (* bthf_dtmf_cmd_callback)(char tone, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_dtmf_cmd_callback)(char tone, RawAddress *bd_addr);
 
 /** Callback for enabling/disabling noise reduction/echo cancellation
  *  value will be 1 to enable, 0 to disable
  */
-typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_nrec_cmd_callback)(bthf_nrec_t nrec, RawAddress *bd_addr);
 
 /** Callback for AT+BCS and event from BAC
  *  WBS enable, WBS disable
  */
-typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_wbs_callback)(bthf_wbs_config_t wbs, RawAddress *bd_addr);
 
 /** Callback for call hold handling (AT+CHLD)
  *  value will contain the call hold command (0, 1, 2, 3)
  */
-typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_chld_cmd_callback)(bthf_chld_type_t chld, RawAddress *bd_addr);
 
 /** Callback for CNUM (subscriber number)
  */
-typedef void (* bthf_cnum_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_cnum_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for indicators (CIND)
  */
-typedef void (* bthf_cind_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_cind_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for operator selection (COPS)
  */
-typedef void (* bthf_cops_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_cops_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for call list (AT+CLCC)
  */
-typedef void (* bthf_clcc_cmd_callback) (bt_bdaddr_t *bd_addr);
+typedef void (* bthf_clcc_cmd_callback) (RawAddress *bd_addr);
 
 /** Callback for unknown AT command recd from HF
  *  at_string will contain the unparsed AT string
  */
-typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_unknown_at_cmd_callback)(char *at_string, RawAddress *bd_addr);
 
 /** Callback for keypressed (HSP) event.
  */
-typedef void (* bthf_key_pressed_cmd_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* bthf_key_pressed_cmd_callback)(RawAddress *bd_addr);
 
 /** Callback for BIND. Pass the remote HF Indicators supported.
  */
-typedef void (* bthf_bind_cmd_callback)(char *at_string, bt_bdaddr_t *bd_addr);
+typedef void (* bthf_bind_cmd_callback)(char *at_string, RawAddress *bd_addr);
 
 /** Callback for BIEV. Pass the change in the Remote HF indicator values
  */
 typedef void (* bthf_biev_cmd_callback)(bthf_hf_ind_type_t ind_id, int ind_value,
-                                        bt_bdaddr_t *bd_addr);
+                                        RawAddress *bd_addr);
 
 /** BT-HF callback structure. */
 typedef struct {
@@ -255,45 +255,45 @@
     bt_status_t (*init)( bthf_callbacks_t* callbacks, int max_hf_clients, bool inband_ringing_supported);
 
     /** connect to headset */
-    bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*connect)( RawAddress *bd_addr );
 
     /** dis-connect from headset */
-    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*disconnect)( RawAddress *bd_addr );
 
     /** create an audio connection */
-    bt_status_t (*connect_audio)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*connect_audio)( RawAddress *bd_addr );
 
     /** close the audio connection */
-    bt_status_t (*disconnect_audio)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*disconnect_audio)( RawAddress *bd_addr );
 
     /** start voice recognition */
-    bt_status_t (*start_voice_recognition)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*start_voice_recognition)( RawAddress *bd_addr );
 
     /** stop voice recognition */
-    bt_status_t (*stop_voice_recognition)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*stop_voice_recognition)( RawAddress *bd_addr );
 
     /** volume control */
-    bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, bt_bdaddr_t *bd_addr );
+    bt_status_t (*volume_control) (bthf_volume_type_t type, int volume, RawAddress *bd_addr );
 
     /** Combined device status change notification */
     bt_status_t (*device_status_notification)(bthf_network_state_t ntk_state, bthf_service_type_t svc_type, int signal,
                            int batt_chg);
 
     /** Response for COPS command */
-    bt_status_t (*cops_response)(const char *cops, bt_bdaddr_t *bd_addr );
+    bt_status_t (*cops_response)(const char *cops, RawAddress *bd_addr );
 
     /** Response for CIND command */
     bt_status_t (*cind_response)(int svc, int num_active, int num_held, bthf_call_state_t call_setup_state,
-                                 int signal, int roam, int batt_chg, bt_bdaddr_t *bd_addr );
+                                 int signal, int roam, int batt_chg, RawAddress *bd_addr );
 
     /** Pre-formatted AT response, typically in response to unknown AT cmd */
-    bt_status_t (*formatted_at_response)(const char *rsp, bt_bdaddr_t *bd_addr );
+    bt_status_t (*formatted_at_response)(const char *rsp, RawAddress *bd_addr );
 
     /** ok/error response
      *  ERROR (0)
      *  OK    (1)
      */
-    bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, bt_bdaddr_t *bd_addr );
+    bt_status_t (*at_response) (bthf_at_response_t response_code, int error_code, RawAddress *bd_addr );
 
     /** response for CLCC command
      *  Can be iteratively called for each call index
@@ -302,7 +302,7 @@
     bt_status_t (*clcc_response) (int index, bthf_call_direction_t dir,
                                 bthf_call_state_t state, bthf_call_mode_t mode,
                                 bthf_call_mpty_type_t mpty, const char *number,
-                                bthf_call_addrtype_t type, bt_bdaddr_t *bd_addr );
+                                bthf_call_addrtype_t type, RawAddress *bd_addr );
 
     /** notify of a call state change
      *  Each update notifies
@@ -318,11 +318,14 @@
     void  (*cleanup)( void );
 
     /** configuration for the SCO codec */
-    bt_status_t (*configure_wbs)( bt_bdaddr_t *bd_addr ,bthf_wbs_config_t config );
+    bt_status_t (*configure_wbs)( RawAddress *bd_addr ,bthf_wbs_config_t config );
 
     /** Response for HF Indicator change (+BIND) */
     bt_status_t (*bind_response)(bthf_hf_ind_type_t ind_id, bthf_hf_ind_status_t ind_status,
-                                 bt_bdaddr_t *bd_addr);
+                                 RawAddress *bd_addr);
+
+    /** Whether we will initiate SCO or not **/
+    bt_status_t (*set_sco_allowed)(bool value);
 } bthf_interface_t;
 
 __END_DECLS
diff --git a/include/hardware/bt_hf_client.h b/include/hardware/bt_hf_client.h
index b728be3..5207296 100644
--- a/include/hardware/bt_hf_client.h
+++ b/include/hardware/bt_hf_client.h
@@ -167,7 +167,7 @@
  *  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)(const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_connection_state_callback)(const RawAddress *bd_addr,
                                                        bthf_client_connection_state_t state,
                                                        unsigned int peer_feat,
                                                        unsigned int chld_feat);
@@ -175,73 +175,73 @@
 /** Callback for audio connection state change.
  *  state will have one of the values from BtHfAudioState
  */
-typedef void (* bthf_client_audio_state_callback)(const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_audio_state_callback)(const RawAddress *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)(const bt_bdaddr_t *bd_addr, bthf_client_vr_state_t state);
+typedef void (* bthf_client_vr_cmd_callback)(const RawAddress *bd_addr, bthf_client_vr_state_t state);
 
 /** Callback for network state change
  */
-typedef void (* bthf_client_network_state_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_network_state_callback) (const RawAddress *bd_addr,
                                                      bthf_client_network_state_t state);
 
 /** Callback for network roaming status change
  */
-typedef void (* bthf_client_network_roaming_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_network_roaming_callback) (const RawAddress *bd_addr,
                                                        bthf_client_service_type_t type);
 
 /** Callback for signal strength indication
  */
-typedef void (* bthf_client_network_signal_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_network_signal_callback) (const RawAddress *bd_addr,
                                                       int signal_strength);
 
 /** Callback for battery level indication
  */
-typedef void (* bthf_client_battery_level_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_battery_level_callback) (const RawAddress *bd_addr,
                                                      int battery_level);
 
 /** Callback for current operator name
  */
-typedef void (* bthf_client_current_operator_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_current_operator_callback) (const RawAddress *bd_addr,
                                                         const char *name);
 
 /** Callback for call indicator
  */
-typedef void (* bthf_client_call_callback) (const bt_bdaddr_t *bd_addr, bthf_client_call_t call);
+typedef void (* bthf_client_call_callback) (const RawAddress *bd_addr, bthf_client_call_t call);
 
 /** Callback for callsetup indicator
  */
-typedef void (* bthf_client_callsetup_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_callsetup_callback) (const RawAddress *bd_addr,
                                                  bthf_client_callsetup_t callsetup);
 
 /** Callback for callheld indicator
  */
-typedef void (* bthf_client_callheld_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_callheld_callback) (const RawAddress *bd_addr,
                                                 bthf_client_callheld_t callheld);
 
 /** Callback for response and hold
  */
-typedef void (* bthf_client_resp_and_hold_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_resp_and_hold_callback) (const RawAddress *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 bt_bdaddr_t *bd_addr, const char *number);
+typedef void (* bthf_client_clip_callback) (const RawAddress *bd_addr, const char *number);
 
 /**
  * Callback for Call Waiting notification
  */
-typedef void (* bthf_client_call_waiting_callback) (const bt_bdaddr_t *bd_addr, const char *number);
+typedef void (* bthf_client_call_waiting_callback) (const RawAddress *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) (const bt_bdaddr_t *bd_addr, int index,
+typedef void (*bthf_client_current_calls) (const RawAddress *bd_addr, int index,
                                            bthf_client_call_direction_t dir,
                                            bthf_client_call_state_t state,
                                            bthf_client_call_mpty_type_t mpty,
@@ -249,38 +249,38 @@
 
 /** Callback for audio volume change
  */
-typedef void (*bthf_client_volume_change_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (*bthf_client_volume_change_callback) (const RawAddress *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) (const bt_bdaddr_t *bd_addr,
+typedef void (*bthf_client_cmd_complete_callback) (const RawAddress *bd_addr,
                                                    bthf_client_cmd_complete_t type,
                                                    int cme);
 
 /** Callback for subscriber information
  */
-typedef void (* bthf_client_subscriber_info_callback) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_subscriber_info_callback) (const RawAddress *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) (const bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_in_band_ring_tone_callback) (const RawAddress *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 bt_bdaddr_t *bd_addr,
+typedef void (* bthf_client_last_voice_tag_number_callback) (const RawAddress *bd_addr,
                                                              const char *number);
 
 /**
  * Callback for sending ring indication to app
  */
-typedef void (* bthf_client_ring_indication_callback) (const bt_bdaddr_t *bd_addr);
+typedef void (* bthf_client_ring_indication_callback) (const RawAddress *bd_addr);
 
 /** BT-HF callback structure. */
 typedef struct {
@@ -320,62 +320,62 @@
     bt_status_t (*init)(bthf_client_callbacks_t* callbacks);
 
     /** connect to audio gateway */
-    bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*connect)(RawAddress *bd_addr);
 
     /** disconnect from audio gateway */
-    bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*disconnect)(const RawAddress *bd_addr);
 
     /** create an audio connection */
-    bt_status_t (*connect_audio)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*connect_audio)(const RawAddress *bd_addr);
 
     /** close the audio connection */
-    bt_status_t (*disconnect_audio)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*disconnect_audio)(const RawAddress *bd_addr);
 
     /** start voice recognition */
-    bt_status_t (*start_voice_recognition)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*start_voice_recognition)(const RawAddress *bd_addr);
 
     /** stop voice recognition */
-    bt_status_t (*stop_voice_recognition)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*stop_voice_recognition)(const RawAddress *bd_addr);
 
     /** volume control */
-    bt_status_t (*volume_control) (const bt_bdaddr_t *bd_addr,
+    bt_status_t (*volume_control) (const RawAddress *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 bt_bdaddr_t *bd_addr, const char *number);
+    bt_status_t (*dial) (const RawAddress *bd_addr, const char *number);
 
     /** place a call with number specified by location (speed dial) */
-    bt_status_t (*dial_memory) (const bt_bdaddr_t *bd_addr, int location);
+    bt_status_t (*dial_memory) (const RawAddress *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) (const bt_bdaddr_t *bd_addr,
+    bt_status_t (*handle_call_action) (const RawAddress *bd_addr,
                                        bthf_client_call_action_t action,
                                        int idx);
 
     /** query list of current calls */
-    bt_status_t (*query_current_calls) (const bt_bdaddr_t *bd_addr);
+    bt_status_t (*query_current_calls) (const RawAddress *bd_addr);
 
     /** query name of current selected operator */
-    bt_status_t (*query_current_operator_name) (const bt_bdaddr_t *bd_addr);
+    bt_status_t (*query_current_operator_name) (const RawAddress *bd_addr);
 
     /** Retrieve subscriber information */
-    bt_status_t (*retrieve_subscriber_info) (const bt_bdaddr_t *bd_addr);
+    bt_status_t (*retrieve_subscriber_info) (const RawAddress *bd_addr);
 
     /** Send DTMF code*/
-    bt_status_t (*send_dtmf) (const bt_bdaddr_t *bd_addr, char code);
+    bt_status_t (*send_dtmf) (const RawAddress *bd_addr, char code);
 
     /** Request a phone number from AG corresponding to last voice tag recorded */
-    bt_status_t (*request_last_voice_tag_number) (const bt_bdaddr_t *bd_addr);
+    bt_status_t (*request_last_voice_tag_number) (const RawAddress *bd_addr);
 
     /** Closes the interface. */
     void (*cleanup)(void);
 
     /** Send AT Command. */
-    bt_status_t (*send_at_cmd) (const bt_bdaddr_t *bd_addr, int cmd, int val1, int val2, const char *arg);
+    bt_status_t (*send_at_cmd) (const RawAddress *bd_addr, int cmd, int val1, int val2, const char *arg);
 } bthf_client_interface_t;
 
 __END_DECLS
diff --git a/include/hardware/bt_hh.h b/include/hardware/bt_hh.h
index ece3c11..c39e3e5 100644
--- a/include/hardware/bt_hh.h
+++ b/include/hardware/bt_hh.h
@@ -87,37 +87,37 @@
 /** Callback for connection state change.
  *  state will have one of the values from bthh_connection_state_t
  */
-typedef void (* bthh_connection_state_callback)(bt_bdaddr_t *bd_addr, bthh_connection_state_t state);
+typedef void (* bthh_connection_state_callback)(RawAddress *bd_addr, bthh_connection_state_t state);
 
 /** Callback for vitual unplug api.
  *  the status of the vitual unplug
  */
-typedef void (* bthh_virtual_unplug_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
+typedef void (* bthh_virtual_unplug_callback)(RawAddress *bd_addr, bthh_status_t hh_status);
 
 /** Callback for get hid info
  *  hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, version, ctry_code, len
  */
-typedef void (* bthh_hid_info_callback)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info);
+typedef void (* bthh_hid_info_callback)(RawAddress *bd_addr, bthh_hid_info_t hid_info);
 
 /** Callback for get protocol api.
  *  the protocol mode is one of the value from bthh_protocol_mode_t
  */
-typedef void (* bthh_protocol_mode_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
+typedef void (* bthh_protocol_mode_callback)(RawAddress *bd_addr, bthh_status_t hh_status, bthh_protocol_mode_t mode);
 
 /** Callback for get/set_idle_time api.
  */
-typedef void (* bthh_idle_time_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, int idle_rate);
+typedef void (* bthh_idle_time_callback)(RawAddress *bd_addr, bthh_status_t hh_status, int idle_rate);
 
 
 /** Callback for get report api.
  *  if staus is ok rpt_data contains the report data
  */
-typedef void (* bthh_get_report_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
+typedef void (* bthh_get_report_callback)(RawAddress *bd_addr, bthh_status_t hh_status, uint8_t* rpt_data, int rpt_size);
 
 /** Callback for set_report/set_protocol api and if error
  *  occurs for get_report/get_protocol api.
  */
-typedef void (* bthh_handshake_callback)(bt_bdaddr_t *bd_addr, bthh_status_t hh_status);
+typedef void (* bthh_handshake_callback)(RawAddress *bd_addr, bthh_status_t hh_status);
 
 
 /** BT-HH callback structure. */
@@ -148,37 +148,37 @@
     bt_status_t (*init)( bthh_callbacks_t* callbacks );
 
     /** connect to hid device */
-    bt_status_t (*connect)( bt_bdaddr_t *bd_addr);
+    bt_status_t (*connect)( RawAddress *bd_addr);
 
     /** dis-connect from hid device */
-    bt_status_t (*disconnect)( bt_bdaddr_t *bd_addr );
+    bt_status_t (*disconnect)( RawAddress *bd_addr );
 
     /** Virtual UnPlug (VUP) the specified HID device */
-    bt_status_t (*virtual_unplug)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*virtual_unplug)(RawAddress *bd_addr);
 
     /** Set the HID device descriptor for the specified HID device. */
-    bt_status_t (*set_info)(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info );
+    bt_status_t (*set_info)(RawAddress *bd_addr, bthh_hid_info_t hid_info );
 
     /** Get the HID proto mode. */
-    bt_status_t (*get_protocol) (bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
+    bt_status_t (*get_protocol) (RawAddress *bd_addr, bthh_protocol_mode_t protocolMode);
 
     /** Set the HID proto mode. */
-    bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
+    bt_status_t (*set_protocol)(RawAddress *bd_addr, bthh_protocol_mode_t protocolMode);
 
     /** Get the HID Idle Time */
-    bt_status_t (*get_idle_time)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*get_idle_time)(RawAddress *bd_addr);
 
     /** Set the HID Idle Time */
-    bt_status_t (*set_idle_time)(bt_bdaddr_t *bd_addr, uint8_t idleTime);
+    bt_status_t (*set_idle_time)(RawAddress *bd_addr, uint8_t idleTime);
 
     /** Send a GET_REPORT to HID device. */
-    bt_status_t (*get_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
+    bt_status_t (*get_report)(RawAddress *bd_addr, bthh_report_type_t reportType, uint8_t reportId, int bufferSize);
 
     /** Send a SET_REPORT to HID device. */
-    bt_status_t (*set_report)(bt_bdaddr_t *bd_addr, bthh_report_type_t reportType, char* report);
+    bt_status_t (*set_report)(RawAddress *bd_addr, bthh_report_type_t reportType, char* report);
 
     /** Send data to HID device. */
-    bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
+    bt_status_t (*send_data)(RawAddress *bd_addr, char* data);
 
     /** Closes the interface. */
     void  (*cleanup)( void );
diff --git a/include/hardware/bt_hl.h b/include/hardware/bt_hl.h
index bd29e3a..6d909fb 100644
--- a/include/hardware/bt_hl.h
+++ b/include/hardware/bt_hl.h
@@ -78,7 +78,7 @@
  *  state will have one of the values from
  *  bthl_connection_state_t and fd (file descriptor)
  */
-typedef void (* bthl_channel_state_callback)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int channel_id, bthl_channel_state_t state, int fd);
+typedef void (* bthl_channel_state_callback)(int app_id, RawAddress *bd_addr, int mdep_cfg_index, int channel_id, bthl_channel_state_t state, int fd);
 
 /** BT-HL callback structure. */
 typedef struct {
@@ -107,7 +107,7 @@
     bt_status_t (*unregister_application) (int app_id);
 
     /** connect channel */
-    bt_status_t (*connect_channel)(int app_id, bt_bdaddr_t *bd_addr, int mdep_cfg_index, int *channel_id);
+    bt_status_t (*connect_channel)(int app_id, RawAddress *bd_addr, int mdep_cfg_index, int *channel_id);
 
     /** destroy channel */
     bt_status_t (*destroy_channel)(int channel_id);
diff --git a/include/hardware/bt_mce.h b/include/hardware/bt_mce.h
index 5d159b3..406a26a 100644
--- a/include/hardware/bt_mce.h
+++ b/include/hardware/bt_mce.h
@@ -29,7 +29,7 @@
 } btmce_mas_instance_t;
 
 /** callback for get_remote_mas_instances */
-typedef void (*btmce_remote_mas_instances_callback)(bt_status_t status, bt_bdaddr_t *bd_addr,
+typedef void (*btmce_remote_mas_instances_callback)(bt_status_t status, RawAddress *bd_addr,
                                                     int num_instances, btmce_mas_instance_t *instances);
 
 typedef struct {
@@ -46,7 +46,7 @@
     bt_status_t (*init)(btmce_callbacks_t *callbacks);
 
     /** search for MAS instances on remote device */
-    bt_status_t (*get_remote_mas_instances)(bt_bdaddr_t *bd_addr);
+    bt_status_t (*get_remote_mas_instances)(RawAddress *bd_addr);
 } btmce_interface_t;
 
 __END_DECLS
diff --git a/include/hardware/bt_pan.h b/include/hardware/bt_pan.h
index 83e7949..2f2e2e5 100644
--- a/include/hardware/bt_pan.h
+++ b/include/hardware/bt_pan.h
@@ -39,7 +39,7 @@
 * Callback for pan connection state
 */
 typedef void (*btpan_connection_state_callback)(btpan_connection_state_t state, bt_status_t error,
-                                                const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
+                                                const RawAddress *bd_addr, int local_role, int remote_role);
 typedef void (*btpan_control_state_callback)(btpan_control_state_t state, int local_role,
                                             bt_status_t error, const char* ifname);
 
@@ -69,11 +69,11 @@
      * start bluetooth pan connection to the remote device by specified pan role. The result state will be
      * returned by btpan_connection_state_callback
      */
-    bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, int local_role, int remote_role);
+    bt_status_t (*connect)(const RawAddress *bd_addr, int local_role, int remote_role);
     /**
      * stop bluetooth pan connection. The result state will be returned by btpan_connection_state_callback
      */
-    bt_status_t (*disconnect)(const bt_bdaddr_t *bd_addr);
+    bt_status_t (*disconnect)(const RawAddress *bd_addr);
 
     /**
      * Cleanup the pan interface
diff --git a/include/hardware/bt_rc.h b/include/hardware/bt_rc.h
index ee99d91..93fb32f 100644
--- a/include/hardware/bt_rc.h
+++ b/include/hardware/bt_rc.h
@@ -287,98 +287,98 @@
 } btrc_br_folder_name_t;
 
 /** Callback for the controller's supported feautres */
-typedef void (* btrc_remote_features_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_remote_features_callback)(RawAddress *bd_addr,
                                                       btrc_remote_features_t features);
 
 /** Callback for play status request */
-typedef void (* btrc_get_play_status_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* btrc_get_play_status_callback)(RawAddress *bd_addr);
 
 /** Callback for list player application attributes (Shuffle, Repeat,...) */
-typedef void (* btrc_list_player_app_attr_callback)(bt_bdaddr_t *bd_addr);
+typedef void (* btrc_list_player_app_attr_callback)(RawAddress *bd_addr);
 
 /** Callback for list player application attributes (Shuffle, Repeat,...) */
 typedef void (* btrc_list_player_app_values_callback)(btrc_player_attr_t attr_id,
-    bt_bdaddr_t *bd_addr);
+    RawAddress *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, bt_bdaddr_t *bd_addr);
+    btrc_player_attr_t *p_attrs, RawAddress *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, bt_bdaddr_t *bd_addr);
+    btrc_player_attr_t *p_attrs, RawAddress *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, bt_bdaddr_t *bd_addr);
+    uint8_t *p_vals, RawAddress *bd_addr);
 
 /** Callback for setting the player application settings values */
 typedef void (* btrc_set_player_app_value_callback) (btrc_player_settings_t *p_vals,
-    bt_bdaddr_t *bd_addr);
+    RawAddress *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,
-    bt_bdaddr_t *bd_addr);
+    RawAddress *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,
-    bt_bdaddr_t *bd_addr);
+    RawAddress *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, bt_bdaddr_t *bd_addr);
+typedef void (* btrc_volume_change_callback) (uint8_t volume, uint8_t ctype, RawAddress *bd_addr);
 
 /** Callback for passthrough commands */
-typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state, bt_bdaddr_t *bd_addr);
+typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state, RawAddress *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);
+typedef void (* btrc_set_addressed_player_callback) (uint16_t player_id, RawAddress *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);
+typedef void (* btrc_set_browsed_player_callback) (uint16_t player_id, RawAddress *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);
+              uint32_t end_item, uint8_t num_attr, uint32_t *p_attr_ids, RawAddress *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);
+                uint8_t* folder_uid, RawAddress *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);
+                uint8_t num_attr, btrc_media_attr_t *p_attrs, RawAddress *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);
+                uint16_t uid_counter, uint8_t* uid, RawAddress *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);
+typedef void (* btrc_get_total_num_of_items_callback) (uint8_t scope, RawAddress *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);
+                uint16_t str_len, uint8_t* p_str, RawAddress *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);
+                uint8_t* uid, uint16_t  uid_counter, RawAddress *bd_addr);
 
 /** BT-RC Target callback structure. */
 typedef struct {
@@ -422,45 +422,45 @@
     **  2. Song duration/length
     **  3. Song position
     */
-    bt_status_t (*get_play_status_rsp)( bt_bdaddr_t *bd_addr, btrc_play_status_t play_status,
+    bt_status_t (*get_play_status_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, int num_attr,
+    bt_status_t (*list_player_app_attr_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, int num_val, uint8_t *p_vals);
+    bt_status_t (*list_player_app_value_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, btrc_player_settings_t *p_vals);
+    bt_status_t (*get_player_app_value_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, int num_attr,
+    bt_status_t (*get_player_app_attr_text_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, int num_val,
+    bt_status_t (*get_player_app_value_text_rsp)( RawAddress *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)( bt_bdaddr_t *bd_addr, uint8_t num_attr,
+    bt_status_t (*get_element_attr_rsp)( RawAddress *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)(bt_bdaddr_t *bd_addr, btrc_status_t rsp_status);
+    bt_status_t (*set_player_app_value_rsp)(RawAddress *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
@@ -481,89 +481,89 @@
     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);
+    bt_status_t (*set_addressed_player_rsp)(RawAddress *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,
+    bt_status_t (*set_browsed_player_rsp)(RawAddress *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,
+     bt_status_t (*get_folder_items_list_rsp)(RawAddress *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,
+    bt_status_t (*change_path_rsp)(RawAddress *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,
+    bt_status_t (*get_item_attr_rsp)(RawAddress *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);
+    bt_status_t (*play_item_rsp)(RawAddress *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,
+    bt_status_t (*get_total_num_of_items_rsp)(RawAddress *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,
+    bt_status_t (*search_rsp)(RawAddress *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);
+    bt_status_t (*add_to_now_playing_rsp)(RawAddress *bd_addr, btrc_status_t rsp_status);
 
     /** Closes the interface. */
     void  (*cleanup)( void );
 } btrc_interface_t;
 
-typedef void (* btrc_passthrough_rsp_callback) (bt_bdaddr_t *bd_addr, int id, int key_state);
+typedef void (* btrc_passthrough_rsp_callback) (RawAddress *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 rc_connect, bool bt_connect, bt_bdaddr_t *bd_addr);
+    bool rc_connect, bool bt_connect, RawAddress *bd_addr);
 
-typedef void (* btrc_ctrl_getrcfeatures_callback) (bt_bdaddr_t *bd_addr, int features);
+typedef void (* btrc_ctrl_getrcfeatures_callback) (RawAddress *bd_addr, int features);
 
-typedef void (* btrc_ctrl_setabsvol_cmd_callback) (bt_bdaddr_t *bd_addr, uint8_t abs_vol, uint8_t label);
+typedef void (* btrc_ctrl_setabsvol_cmd_callback) (RawAddress *bd_addr, uint8_t abs_vol, uint8_t label);
 
-typedef void (* btrc_ctrl_registernotification_abs_vol_callback) (bt_bdaddr_t *bd_addr, uint8_t label);
+typedef void (* btrc_ctrl_registernotification_abs_vol_callback) (RawAddress *bd_addr, uint8_t label);
 
-typedef void (* btrc_ctrl_setplayerapplicationsetting_rsp_callback) (bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_setplayerapplicationsetting_rsp_callback) (RawAddress *bd_addr,
                                                                           uint8_t accepted);
 
-typedef void (* btrc_ctrl_playerapplicationsetting_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_playerapplicationsetting_callback)(RawAddress *bd_addr,
                                                                  uint8_t num_attr,
                                                                  btrc_player_app_attr_t *app_attrs,
                                                                  uint8_t num_ext_attr,
                                                                  btrc_player_app_ext_attr_t *ext_attrs);
 
-typedef void (* btrc_ctrl_playerapplicationsetting_changed_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_playerapplicationsetting_changed_callback)(RawAddress *bd_addr,
                                                                           btrc_player_settings_t *p_vals);
 
-typedef void (* btrc_ctrl_track_changed_callback)(bt_bdaddr_t *bd_addr, uint8_t num_attr,
+typedef void (* btrc_ctrl_track_changed_callback)(RawAddress *bd_addr, uint8_t num_attr,
                                                      btrc_element_attr_val_t *p_attrs);
 
-typedef void (* btrc_ctrl_play_position_changed_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_play_position_changed_callback)(RawAddress *bd_addr,
                                                               uint32_t song_len, uint32_t song_pos);
 
-typedef void (* btrc_ctrl_play_status_changed_callback)(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_play_status_changed_callback)(RawAddress *bd_addr,
                                                             btrc_play_status_t play_status);
 
-typedef void (* btrc_ctrl_get_folder_items_callback )(bt_bdaddr_t *bd_addr,
+typedef void (* btrc_ctrl_get_folder_items_callback )(RawAddress *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_change_path_callback)(RawAddress *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);
+    RawAddress *bd_addr, uint8_t num_items, uint8_t depth);
+typedef void (* btrc_ctrl_set_addressed_player_callback)(RawAddress *bd_addr, uint8_t status);
 /** BT-RC Controller callback structure. */
 typedef struct {
     /** set to sizeof(BtRcCallbacks) */
@@ -597,47 +597,47 @@
     bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
 
     /** send pass through command to target */
-    bt_status_t (*send_pass_through_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
+    bt_status_t (*send_pass_through_cmd) (RawAddress *bd_addr, uint8_t key_code,
             uint8_t key_state );
 
     /** send group navigation command to target */
-    bt_status_t (*send_group_navigation_cmd) (bt_bdaddr_t *bd_addr, uint8_t key_code,
+    bt_status_t (*send_group_navigation_cmd) (RawAddress *bd_addr, uint8_t key_code,
             uint8_t key_state );
 
     /** send command to set player applicaiton setting attributes to target */
-    bt_status_t (*set_player_app_setting_cmd) (bt_bdaddr_t *bd_addr, uint8_t num_attrib,
+    bt_status_t (*set_player_app_setting_cmd) (RawAddress *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);
+        RawAddress *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);
+    bt_status_t (*get_playback_state_cmd) (RawAddress *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);
+    bt_status_t (*get_now_playing_list_cmd) (RawAddress *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);
+    bt_status_t (*get_folder_list_cmd) (RawAddress *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);
+    bt_status_t (*get_player_list_cmd) (RawAddress *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);
+    bt_status_t (*change_folder_path_cmd) (RawAddress *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);
+    bt_status_t (*set_browsed_player_cmd) (RawAddress *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);
+    bt_status_t (*set_addressed_player_cmd) (RawAddress *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);
+    bt_status_t (*set_volume_rsp) (RawAddress *bd_addr, uint8_t abs_vol, uint8_t label);
 
     /** send notificaiton rsp for abs vol to target */
-    bt_status_t (*register_abs_vol_rsp) (bt_bdaddr_t *bd_addr, btrc_notification_type_t rsp_type,
+    bt_status_t (*register_abs_vol_rsp) (RawAddress *bd_addr, btrc_notification_type_t rsp_type,
             uint8_t abs_vol, uint8_t label);
 
     /** Closes the interface. */
diff --git a/include/hardware/bt_sdp.h b/include/hardware/bt_sdp.h
index 8f39bc5..76cb579 100644
--- a/include/hardware/bt_sdp.h
+++ b/include/hardware/bt_sdp.h
@@ -109,7 +109,7 @@
 
 
 /** Callback for SDP search */
-typedef void (*btsdp_search_callback)(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
+typedef void (*btsdp_search_callback)(bt_status_t status, RawAddress *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
 
 typedef struct {
     /** Set to sizeof(btsdp_callbacks_t) */
@@ -128,7 +128,7 @@
     bt_status_t (*deinit)();
 
     /** Search for SDP records with specific uuid on remote device */
-    bt_status_t (*sdp_search)(bt_bdaddr_t *bd_addr,  const uint8_t* uuid);
+    bt_status_t (*sdp_search)(RawAddress *bd_addr,  const uint8_t* uuid);
 
     /**
      * Use listen in the socket interface to create rfcomm and/or l2cap PSM channels,
diff --git a/include/hardware/bt_sock.h b/include/hardware/bt_sock.h
index 8d1a9e0..4c098f1 100644
--- a/include/hardware/bt_sock.h
+++ b/include/hardware/bt_sock.h
@@ -33,7 +33,7 @@
 /** Represents the standard BT SOCKET interface. */
 typedef struct {
     short size;
-    bt_bdaddr_t bd_addr;
+    RawAddress bd_addr;
     int channel;
     int status;
 
@@ -68,7 +68,7 @@
      * The callingUid is the UID of the application which is requesting the socket. This is
      * used for traffic accounting purposes.
      */
-    bt_status_t (*connect)(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid,
+    bt_status_t (*connect)(const RawAddress *bd_addr, btsock_type_t type, const uint8_t* uuid,
             int channel, int* sock_fd, int flags, int callingUid);
 } btsock_interface_t;
 
diff --git a/include/hardware/context_hub.h b/include/hardware/context_hub.h
index aaa4274..137cb3e 100644
--- a/include/hardware/context_hub.h
+++ b/include/hardware/context_hub.h
@@ -47,12 +47,13 @@
 /*****************************************************************************/
 
 #define CONTEXT_HUB_HEADER_MAJOR_VERSION          1
-#define CONTEXT_HUB_HEADER_MINOR_VERSION          0
+#define CONTEXT_HUB_HEADER_MINOR_VERSION          1
 #define CONTEXT_HUB_DEVICE_API_VERSION \
      HARDWARE_DEVICE_API_VERSION(CONTEXT_HUB_HEADER_MAJOR_VERSION, \
                                  CONTEXT_HUB_HEADER_MINOR_VERSION)
 
 #define CONTEXT_HUB_DEVICE_API_VERSION_1_0  HARDWARE_DEVICE_API_VERSION(1, 0)
+#define CONTEXT_HUB_DEVICE_API_VERSION_1_1  HARDWARE_DEVICE_API_VERSION(1, 1)
 
 /**
  * The id of this module
@@ -131,9 +132,17 @@
     uint32_t app_version;          // Version of the app
     uint32_t flags;                // Signed, encrypted
     uint64_t hw_hub_type;          // which hub type is this compiled for
-    uint32_t reserved[2];          // Should be all zeroes
-    uint8_t  custom_binary[0];     // start of custom binary data
-};
+
+    // The version of the CHRE API that this nanoapp was compiled against.
+    // If these values are both set to 0, then they must be interpreted the same
+    // as if major version were set to 1, and minor 0 (the first valid CHRE API
+    // version).
+    uint8_t target_chre_api_major_version;
+    uint8_t target_chre_api_minor_version;
+
+    uint8_t reserved[6];           // Should be all zeroes
+    uint8_t custom_binary[0];      // start of custom binary data
+} __attribute__((packed));
 
 struct hub_app_info {
     struct hub_app_name_t app_name;
diff --git a/include/hardware/thermal.h b/include/hardware/thermal.h
index b5b6e1d..5db6ee0 100644
--- a/include/hardware/thermal.h
+++ b/include/hardware/thermal.h
@@ -19,6 +19,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <float.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
diff --git a/modules/audio/Android.bp b/modules/audio/Android.bp
index 84daead..a7467c2 100644
--- a/modules/audio/Android.bp
+++ b/modules/audio/Android.bp
@@ -23,6 +23,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["audio_hw.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
@@ -40,6 +41,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["audio_hw.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
@@ -53,6 +55,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["audio_policy.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
index c9e851f..2f59f3a 100644
--- a/modules/audio_remote_submix/Android.mk
+++ b/modules/audio_remote_submix/Android.mk
@@ -25,10 +25,11 @@
 	frameworks/av/include/ \
 	frameworks/native/include/ \
 	$(call include-path-for, audio-utils)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio
+LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio_mono
 LOCAL_STATIC_LIBRARIES := libmedia_helper
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
+LOCAL_HEADER_LIBRARIES += libhardware_headers
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index 6c538ce..5efcdcb 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -24,6 +24,7 @@
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/limits.h>
+#include <unistd.h>
 
 #include <cutils/compiler.h>
 #include <cutils/properties.h>
diff --git a/modules/consumerir/Android.bp b/modules/consumerir/Android.bp
index b139492..6ba37b6 100644
--- a/modules/consumerir/Android.bp
+++ b/modules/consumerir/Android.bp
@@ -17,6 +17,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["consumerir.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
diff --git a/modules/fingerprint/Android.bp b/modules/fingerprint/Android.bp
index ba749e4..a824608 100644
--- a/modules/fingerprint/Android.bp
+++ b/modules/fingerprint/Android.bp
@@ -17,5 +17,6 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["fingerprint.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: ["liblog"],
 }
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index da0f6db..42b4e47 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -23,6 +23,7 @@
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SHARED_LIBRARIES := liblog libEGL
 LOCAL_SRC_FILES := hwcomposer.cpp
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_MODULE := hwcomposer.default
 LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\"
 LOCAL_MODULE_TAGS := optional
diff --git a/modules/hwcomposer/hwcomposer.cpp b/modules/hwcomposer/hwcomposer.cpp
index fd4e90d..31e362a 100644
--- a/modules/hwcomposer/hwcomposer.cpp
+++ b/modules/hwcomposer/hwcomposer.cpp
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <malloc.h>
+#include <string.h>
 
 #include <cutils/atomic.h>
 #include <log/log.h>
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
index be4db6b..9a5d092 100644
--- a/modules/input/evdev/Android.mk
+++ b/modules/input/evdev/Android.mk
@@ -45,7 +45,6 @@
 
 LOCAL_MODULE := input.evdev.default
 LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
 
 LOCAL_SRC_FILES := \
     EvdevModule.cpp
diff --git a/modules/local_time/Android.bp b/modules/local_time/Android.bp
index 643afa5..153b7e4 100644
--- a/modules/local_time/Android.bp
+++ b/modules/local_time/Android.bp
@@ -26,6 +26,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["local_time_hw.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/local_time/local_time_hw.c b/modules/local_time/local_time_hw.c
index b38d8a5..a2d1a9e 100644
--- a/modules/local_time/local_time_hw.c
+++ b/modules/local_time/local_time_hw.c
@@ -21,7 +21,7 @@
 #include <malloc.h>
 #include <stdint.h>
 #include <string.h>
-#include <sys/time.h>
+#include <time.h>
 
 #include <log/log.h>
 
diff --git a/modules/nfc-nci/Android.bp b/modules/nfc-nci/Android.bp
index f4ef64e..f78b7c5 100644
--- a/modules/nfc-nci/Android.bp
+++ b/modules/nfc-nci/Android.bp
@@ -17,6 +17,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["nfc_nci_example.cpp"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/nfc/Android.bp b/modules/nfc/Android.bp
index 10dc2c1..b4bc9b1 100644
--- a/modules/nfc/Android.bp
+++ b/modules/nfc/Android.bp
@@ -17,6 +17,7 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["nfc_pn544_example.c"],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
     ],
diff --git a/modules/power/Android.bp b/modules/power/Android.bp
index f4c74ce..41ac45c 100644
--- a/modules/power/Android.bp
+++ b/modules/power/Android.bp
@@ -17,5 +17,9 @@
     relative_install_path: "hw",
     proprietary: true,
     srcs: ["power.c"],
+    header_libs: [
+        "libhardware_headers",
+        "libutils_headers",
+    ],
     shared_libs: ["liblog"],
 }
diff --git a/modules/radio/Android.bp b/modules/radio/Android.bp
index 01dc035..7f98f0d 100644
--- a/modules/radio/Android.bp
+++ b/modules/radio/Android.bp
@@ -23,6 +23,7 @@
         "-Wno-unused-parameter",
         "-Werror",
     ],
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/radio/radio_hw.c b/modules/radio/radio_hw.c
index 29204df..93b8c88 100644
--- a/modules/radio/radio_hw.c
+++ b/modules/radio/radio_hw.c
@@ -114,8 +114,19 @@
     CMD_CANCEL,
     CMD_METADATA,
     CMD_ANNOUNCEMENTS,
+    CMD_NUM
 } thread_cmd_type_t;
 
+uint32_t thread_cmd_delay_ms[CMD_NUM] = {
+    [CMD_EXIT]          = 0,
+    [CMD_CONFIG]        = 50,
+    [CMD_STEP]          = 100,
+    [CMD_SCAN]          = 200,
+    [CMD_TUNE]          = 150,
+    [CMD_CANCEL]        = 0,
+    [CMD_METADATA]      = 1000,
+    [CMD_ANNOUNCEMENTS] = 1000
+};
 struct thread_command {
     struct listnode node;
     thread_cmd_type_t type;
@@ -401,7 +412,7 @@
                                                 (tuner->config.spacings[0] * 5)) % 2;
 
                     if (tuner->program.tuned) {
-                        send_command_l(tuner, CMD_ANNOUNCEMENTS, 1000, NULL);
+                        send_command_l(tuner, CMD_ANNOUNCEMENTS, thread_cmd_delay_ms[CMD_ANNOUNCEMENTS], NULL);
                     }
                     tuner->program.signal_strength = 100;
                     if (tuner->config.type == RADIO_BAND_FM)
@@ -481,7 +492,7 @@
                     free(cmd);
                 }
             }
-            send_command_l(tuner, CMD_METADATA, 1000, NULL);
+            send_command_l(tuner, CMD_METADATA, thread_cmd_delay_ms[CMD_METADATA], NULL);
         }
     }
 
@@ -510,8 +521,8 @@
         status = -EINVAL;
         goto exit;
     }
-    send_command_l(stub_tuner, CMD_CANCEL, 0, NULL);
-    send_command_l(stub_tuner, CMD_CONFIG, 500, (void *)config);
+    send_command_l(stub_tuner, CMD_CANCEL, thread_cmd_delay_ms[CMD_CANCEL], NULL);
+    send_command_l(stub_tuner, CMD_CONFIG, thread_cmd_delay_ms[CMD_CONFIG], (void *)config);
 
 exit:
     pthread_mutex_unlock(&stub_tuner->lock);
@@ -556,7 +567,7 @@
           __func__, stub_tuner, direction, skip_sub_channel);
 
     pthread_mutex_lock(&stub_tuner->lock);
-    send_command_l(stub_tuner, CMD_STEP, 20, &direction);
+    send_command_l(stub_tuner, CMD_STEP, thread_cmd_delay_ms[CMD_STEP], &direction);
     pthread_mutex_unlock(&stub_tuner->lock);
     return 0;
 }
@@ -570,7 +581,7 @@
           __func__, stub_tuner, direction, skip_sub_channel);
 
     pthread_mutex_lock(&stub_tuner->lock);
-    send_command_l(stub_tuner, CMD_SCAN, 200, &direction);
+    send_command_l(stub_tuner, CMD_SCAN, thread_cmd_delay_ms[CMD_SCAN], &direction);
     pthread_mutex_unlock(&stub_tuner->lock);
     return 0;
 }
@@ -589,7 +600,7 @@
         ALOGI("%s channel out of range", __func__);
         return -EINVAL;
     }
-    send_command_l(stub_tuner, CMD_TUNE, 100, &channel);
+    send_command_l(stub_tuner, CMD_TUNE, thread_cmd_delay_ms[CMD_TUNE], &channel);
     pthread_mutex_unlock(&stub_tuner->lock);
     return 0;
 }
@@ -601,7 +612,7 @@
     ALOGI("%s stub_tuner %p", __func__, stub_tuner);
 
     pthread_mutex_lock(&stub_tuner->lock);
-    send_command_l(stub_tuner, CMD_CANCEL, 0, NULL);
+    send_command_l(stub_tuner, CMD_CANCEL, thread_cmd_delay_ms[CMD_CANCEL], NULL);
     pthread_mutex_unlock(&stub_tuner->lock);
     return 0;
 }
@@ -696,7 +707,7 @@
     list_init(&rdev->tuner->command_list);
 
     pthread_mutex_lock(&rdev->tuner->lock);
-    send_command_l(rdev->tuner, CMD_CONFIG, 500, (void *)config);
+    send_command_l(rdev->tuner, CMD_CONFIG, thread_cmd_delay_ms[CMD_CONFIG], (void *)config);
     pthread_mutex_unlock(&rdev->tuner->lock);
 
     *tuner = &rdev->tuner->interface;
@@ -724,7 +735,7 @@
 
     pthread_mutex_lock(&stub_tuner->lock);
     stub_tuner->callback = NULL;
-    send_command_l(stub_tuner, CMD_EXIT, 0, NULL);
+    send_command_l(stub_tuner, CMD_EXIT, thread_cmd_delay_ms[CMD_EXIT], NULL);
     pthread_mutex_unlock(&stub_tuner->lock);
     pthread_join(stub_tuner->callback_thread, (void **) NULL);
 
diff --git a/modules/sensors/Android.bp b/modules/sensors/Android.bp
index 1d15065..1b5f26d 100644
--- a/modules/sensors/Android.bp
+++ b/modules/sensors/Android.bp
@@ -5,6 +5,9 @@
         "multihal.cpp",
         "SensorEventQueue.cpp"
     ],
+    header_libs: [
+        "libhardware_headers",
+    ],
     shared_libs: [
         "liblog",
         "libcutils",
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index e5e0c9c..9942d39 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -32,6 +32,9 @@
     multihal.cpp \
     SensorEventQueue.cpp \
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
     libdl \
diff --git a/modules/sensors/dynamic_sensor/Android.mk b/modules/sensors/dynamic_sensor/Android.mk
index 348542a..52809dc 100644
--- a/modules/sensors/dynamic_sensor/Android.mk
+++ b/modules/sensors/dynamic_sensor/Android.mk
@@ -56,6 +56,10 @@
 
 LOCAL_SRC_FILES := $(dynamic_sensor_src)
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+    libstagefright_foundation_headers \
+
 LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
@@ -76,6 +80,10 @@
 
 LOCAL_SRC_FILES := $(dynamic_sensor_src) sensors.cpp
 
+LOCAL_HEADER_LIBRARIES := \
+    libhardware_headers \
+    libstagefright_foundation_headers \
+
 LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
diff --git a/modules/sensors/multihal.cpp b/modules/sensors/multihal.cpp
index 1cea7ae..b5360cc 100644
--- a/modules/sensors/multihal.cpp
+++ b/modules/sensors/multihal.cpp
@@ -49,10 +49,11 @@
 static pthread_cond_t data_available_cond = PTHREAD_COND_INITIALIZER;
 bool waiting_for_data = false;
 
-/*
- * Vector of sub modules, whose indexes are referred to in this file as module_index.
- */
-static std::vector<hw_module_t *> *sub_hw_modules = NULL;
+// Vector of sub modules, whose indexes are referred to in this file as module_index.
+static std::vector<hw_module_t *> *sub_hw_modules = nullptr;
+
+// Vector of sub modules shared object handles
+static std::vector<void *> *so_handles = nullptr;
 
 /*
  * Comparable class that globally identifies a sensor, by module index and local handle.
@@ -509,11 +510,26 @@
 
 
 static int device__close(struct hw_device_t *dev) {
+    pthread_mutex_lock(&init_modules_mutex);
     sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev;
     if (ctx != NULL) {
         int retval = ctx->close();
         delete ctx;
     }
+
+    if (sub_hw_modules != nullptr) {
+        delete sub_hw_modules;
+        sub_hw_modules = nullptr;
+    }
+
+    if (so_handles != nullptr) {
+        for (auto handle : *so_handles) {
+            dlclose(handle);
+        }
+        delete so_handles;
+        so_handles = nullptr;
+    }
+    pthread_mutex_unlock(&init_modules_mutex);
     return 0;
 }
 
@@ -583,7 +599,9 @@
  * Adds valid paths from the config file to the vector passed in.
  * The vector must not be null.
  */
-static void get_so_paths(std::vector<std::string> *so_paths) {
+static std::vector<std::string> get_so_paths() {
+    std::vector<std::string> so_paths;
+
     const std::vector<const char *> config_path_list(
             { MULTI_HAL_CONFIG_FILE_PATH, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH });
 
@@ -599,7 +617,7 @@
     }
     if(!stream) {
         ALOGW("No multihal config file found");
-        return;
+        return so_paths;
     }
 
     ALOGE_IF(strcmp(path, DEPRECATED_MULTI_HAL_CONFIG_FILE_PATH) == 0,
@@ -611,8 +629,9 @@
     std::string line;
     while (std::getline(stream, line)) {
         ALOGV("config file line: '%s'", line.c_str());
-        so_paths->push_back(line);
+        so_paths.push_back(line);
     }
+    return so_paths;
 }
 
 /*
@@ -625,15 +644,15 @@
         pthread_mutex_unlock(&init_modules_mutex);
         return;
     }
-    std::vector<std::string> *so_paths = new std::vector<std::string>();
-    get_so_paths(so_paths);
+    std::vector<std::string> so_paths(get_so_paths());
 
     // dlopen the module files and cache their module symbols in sub_hw_modules
     sub_hw_modules = new std::vector<hw_module_t *>();
+    so_handles = new std::vector<void *>();
     dlerror(); // clear any old errors
     const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
-    for (std::vector<std::string>::iterator it = so_paths->begin(); it != so_paths->end(); it++) {
-        const char* path = it->c_str();
+    for (const auto &s : so_paths) {
+        const char* path = s.c_str();
         void* lib_handle = dlopen(path, RTLD_LAZY);
         if (lib_handle == NULL) {
             ALOGW("dlerror(): %s", dlerror());
@@ -651,8 +670,13 @@
             } else {
                 ALOGV("Loaded symbols from \"%s\"", sym);
                 sub_hw_modules->push_back(module);
+                so_handles->push_back(lib_handle);
+                lib_handle = nullptr;
             }
         }
+        if (lib_handle != nullptr) {
+            dlclose(lib_handle);
+        }
     }
     pthread_mutex_unlock(&init_modules_mutex);
 }
diff --git a/modules/thermal/Android.mk b/modules/thermal/Android.mk
index ff51145..1ad55d8 100644
--- a/modules/thermal/Android.mk
+++ b/modules/thermal/Android.mk
@@ -20,7 +20,8 @@
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := thermal.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
diff --git a/modules/tv_input/Android.bp b/modules/tv_input/Android.bp
index 509198d..4d2369e 100644
--- a/modules/tv_input/Android.bp
+++ b/modules/tv_input/Android.bp
@@ -16,6 +16,7 @@
     name: "tv_input.default",
     relative_install_path: "hw",
     proprietary: true,
+    header_libs: ["libhardware_headers"],
     shared_libs: [
         "libcutils",
         "liblog",
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index b36bf9f..6c8a98f 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -29,5 +29,6 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
+LOCAL_HEADER_LIBRARIES += libhardware_headers
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/modules/usbaudio/audio_hal.c b/modules/usbaudio/audio_hal.c
index df4bc0f..e93396f 100644
--- a/modules/usbaudio/audio_hal.c
+++ b/modules/usbaudio/audio_hal.c
@@ -23,6 +23,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <unistd.h>
 
 #include <log/log.h>
 #include <cutils/list.h>
diff --git a/modules/vehicle/Android.mk b/modules/vehicle/Android.mk
index 9fd49da..34c943c 100644
--- a/modules/vehicle/Android.mk
+++ b/modules/vehicle/Android.mk
@@ -20,8 +20,8 @@
 
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_PROPRIETARY_MODULE := true
-LOCAL_C_INCLUDES := hardware/libhardware
 LOCAL_SRC_FILES := vehicle.c timeUtil.cpp
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
 LOCAL_MODULE_TAGS := optional
 
diff --git a/modules/vibrator/Android.bp b/modules/vibrator/Android.bp
index 3c4aebf..fdbfd61 100644
--- a/modules/vibrator/Android.bp
+++ b/modules/vibrator/Android.bp
@@ -19,7 +19,7 @@
     // hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
     relative_install_path: "hw",
     proprietary: true,
-    include_dirs: ["hardware/libhardware"],
+    header_libs: ["libhardware_headers"],
     srcs: ["vibrator.c"],
     shared_libs: ["liblog"],
 }
diff --git a/modules/vr/Android.mk b/modules/vr/Android.mk
index e04c0da..0305745 100644
--- a/modules/vr/Android.mk
+++ b/modules/vr/Android.mk
@@ -20,6 +20,7 @@
 LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_PROPRIETARY_MODULE := true
 LOCAL_SRC_FILES := vr.c
+LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_SHARED_LIBRARIES := libcutils
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS += -Wno-unused-parameter
diff --git a/tests/keymaster/keymaster_test.cpp b/tests/keymaster/keymaster_test.cpp
index 3040a5c..e8fa990 100644
--- a/tests/keymaster/keymaster_test.cpp
+++ b/tests/keymaster/keymaster_test.cpp
@@ -33,7 +33,7 @@
 #define LOG_TAG "keymaster_test"
 #include <utils/Log.h>
 
-#include <UniquePtr.h>
+#include <nativehelper/UniquePtr.h>
 
 #include <hardware/keymaster0.h>