Merge "tune command execute time to resolve FPE_INTDIV error"
diff --git a/Android.bp b/Android.bp
index 739cb6d..f6aacd2 100644
--- a/Android.bp
+++ b/Android.bp
@@ -2,6 +2,15 @@
 
 cc_library_headers {
     name: "libhardware_headers",
+    header_libs: [
+        "libaudio_system_headers",
+        "libsystem_headers",
+    ],
+    export_header_lib_headers: [
+        "libaudio_system_headers",
+        "libsystem_headers"
+    ],
+
     export_include_dirs: ["include"],
     vendor_available: true,
 }
@@ -15,9 +24,11 @@
         "liblog",
         "libdl",
     ],
-    header_libs: ["libsystem_headers"],
     cflags: ["-DQEMU_HARDWARE"],
-    export_include_dirs: ["include"],
+
+    header_libs: ["libhardware_headers"],
+    export_header_lib_headers: ["libhardware_headers"],
+
     vendor_available: true,
 }
 
diff --git a/include/hardware/ble_advertiser.h b/include/hardware/ble_advertiser.h
index 8abca00..02d553f 100644
--- a/include/hardware/ble_advertiser.h
+++ b/include/hardware/ble_advertiser.h
@@ -57,6 +57,9 @@
   /** Registers an advertiser with the stack */
   virtual void RegisterAdvertiser(IdStatusCallback) = 0;
 
+  using GetAddressCallback = base::Callback<void(uint8_t /* address_type*/, bt_bdaddr_t /*address*/)>;
+  virtual void GetOwnAddress(uint8_t advertiser_id, GetAddressCallback cb) = 0;
+
   /* Set the parameters as per spec, user manual specified values */
   virtual void SetParameters(uint8_t advertiser_id, AdvertiseParameters params,
                              ParametersCallback cb) = 0;
diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h
index 5d69ab3..6e287e6 100644
--- a/include/hardware/bluetooth.h
+++ b/include/hardware/bluetooth.h
@@ -35,7 +35,7 @@
 #define BT_STACK_TEST_MODULE_ID "bluetooth_test"
 
 
-/* Bluetooth profile interface IDs */
+/** Bluetooth profile interface IDs */
 
 #define BT_PROFILE_HANDSFREE_ID "handsfree"
 #define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
@@ -52,6 +52,9 @@
 #define BT_PROFILE_AV_RC_ID "avrcp"
 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
 
+/** Bluetooth test interface IDs */
+#define BT_TEST_INTERFACE_MCAP_ID "mcap_test"
+
 /** Bluetooth Address */
 typedef struct {
     uint8_t address[6];
@@ -560,9 +563,6 @@
     /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
     int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
 
-    /* enable or disable bluetooth HCI snoop log */
-    int (*config_hci_snoop_log)(uint8_t enable);
-
     /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
       * This should be called immediately after a successful |init|.
       */
diff --git a/include/hardware/bt_gatt_client.h b/include/hardware/bt_gatt_client.h
index ec8dd16..154cb09 100644
--- a/include/hardware/bt_gatt_client.h
+++ b/include/hardware/bt_gatt_client.h
@@ -223,9 +223,19 @@
      */
     bt_status_t (*search_service)(int conn_id, 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);
+
     /** Read a characteristic on a remote device */
-    bt_status_t (*read_characteristic)( int conn_id, uint16_t handle,
-                    int auth_req );
+    bt_status_t (*read_characteristic)(int conn_id, uint16_t handle,
+                                       int auth_req);
+
+    /** 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,
+        uint16_t e_handle, int auth_req);
 
     /** Write a remote characteristic */
     bt_status_t (*write_characteristic)(int conn_id, uint16_t handle,
diff --git a/include/hardware/bt_hf.h b/include/hardware/bt_hf.h
index 892fbdb..2b89c91 100644
--- a/include/hardware/bt_hf.h
+++ b/include/hardware/bt_hf.h
@@ -323,6 +323,9 @@
     /** 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);
+
+    /** 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_hh.h b/include/hardware/bt_hh.h
index dad9586..ece3c11 100644
--- a/include/hardware/bt_hh.h
+++ b/include/hardware/bt_hh.h
@@ -165,6 +165,12 @@
     /** Set the HID proto mode. */
     bt_status_t (*set_protocol)(bt_bdaddr_t *bd_addr, bthh_protocol_mode_t protocolMode);
 
+    /** Get the HID Idle Time */
+    bt_status_t (*get_idle_time)(bt_bdaddr_t *bd_addr);
+
+    /** Set the HID Idle Time */
+    bt_status_t (*set_idle_time)(bt_bdaddr_t *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);
 
@@ -174,7 +180,7 @@
     /** Send data to HID device. */
     bt_status_t (*send_data)(bt_bdaddr_t *bd_addr, char* data);
 
-	/** Closes the interface. */
+    /** Closes the interface. */
     void  (*cleanup)( void );
 
 } bthh_interface_t;
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
index 092e851..6b6e60d 100644
--- a/modules/gralloc/Android.mk
+++ b/modules/gralloc/Android.mk
@@ -27,6 +27,8 @@
 	framebuffer.cpp \
 	mapper.cpp
 
+LOCAL_HEADER_LIBRARIES := libhardware_headers
+
 LOCAL_MODULE := gralloc.default
 LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -Wno-missing-field-initializers
 ifeq ($(TARGET_USE_PAN_DISPLAY),true)
diff --git a/modules/input/evdev/InputHub.cpp b/modules/input/evdev/InputHub.cpp
index 389955d..e2c65fa 100644
--- a/modules/input/evdev/InputHub.cpp
+++ b/modules/input/evdev/InputHub.cpp
@@ -610,7 +610,7 @@
             for (;;) {
                 ssize_t readSize = TEMP_FAILURE_RETRY(read(inputFd, ievs, sizeof(ievs)));
                 if (readSize == 0 || (readSize < 0 && errno == ENODEV)) {
-                    ALOGW("could not get event, removed? (fd: %d, size: %d errno: %d)",
+                    ALOGW("could not get event, removed? (fd: %d, size: %zd errno: %d)",
                             inputFd, readSize, errno);
 
                     removedDeviceFds.push_back(inputFd);
@@ -621,7 +621,7 @@
                     }
                     break;
                 } else if (readSize % sizeof(input_event) != 0) {
-                    ALOGE("could not get event. wrong size=%d", readSize);
+                    ALOGE("could not get event. wrong size=%zd", readSize);
                     break;
                 } else {
                     size_t count = static_cast<size_t>(readSize) / sizeof(struct input_event);
@@ -702,7 +702,7 @@
             if (event->mask & IN_CREATE) {
                 auto deviceNode = openNode(path);
                 if (deviceNode == nullptr) {
-                    ALOGE("could not open device node %s. err=%d", path.c_str(), res);
+                    ALOGE("could not open device node %s. err=%zd", path.c_str(), res);
                 } else {
                     mInputCallback->onDeviceAdded(deviceNode);
                 }
diff --git a/modules/nfc/Android.bp b/modules/nfc/Android.bp
index bd93bb5..53ab309 100644
--- a/modules/nfc/Android.bp
+++ b/modules/nfc/Android.bp
@@ -18,6 +18,5 @@
     srcs: ["nfc_pn544_example.c"],
     shared_libs: [
         "liblog",
-        "libcutils",
     ],
 }
diff --git a/modules/radio/Android.bp b/modules/radio/Android.bp
new file mode 100644
index 0000000..01dc035
--- /dev/null
+++ b/modules/radio/Android.bp
@@ -0,0 +1,48 @@
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Stub radio HAL module, used for tests
+cc_library_shared {
+    name: "radio.fm.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["radio_hw.c"],
+    cflags: [
+        "-Wall",
+        "-Wno-unused-parameter",
+        "-Werror",
+    ],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libradio_metadata",
+    ],
+}
+
+// Stub radio tool that can be run in native.
+cc_binary {
+    name: "radio_hal_tool",
+    srcs: ["radio_hal_tool.c"],
+    cflags: [
+        "-Wall",
+        "-Wno-unused-parameter",
+        "-Werror",
+    ],
+    shared_libs: [
+        "libcutils",
+        "libhardware",
+        "liblog",
+        "libradio_metadata",
+    ],
+}
diff --git a/modules/radio/Android.mk b/modules/radio/Android.mk
deleted file mode 100644
index 221424f..0000000
--- a/modules/radio/Android.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright (C) 2015 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH := $(call my-dir)
-
-# Stub radio HAL module, used for tests
-include $(CLEAR_VARS)
-
-LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB)
-
-LOCAL_MODULE := radio.fm.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_SRC_FILES := radio_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils libradio_metadata
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-# Stub radio tool that can be run in native.
-include $(CLEAR_VARS)
-
-LOCAL_MULTILIB := $(AUDIOSERVER_MULTILIB)
-
-LOCAL_MODULE := radio_hal_tool
-LOCAL_SRC_FILES := radio_hal_tool.c
-LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror
-LOCAL_SHARED_LIBRARIES := libcutils libhardware liblog libradio_metadata
-
-include $(BUILD_EXECUTABLE)
diff --git a/modules/radio/radio_hw.c b/modules/radio/radio_hw.c
index 1630695..cf47e3c 100644
--- a/modules/radio/radio_hw.c
+++ b/modules/radio/radio_hw.c
@@ -640,8 +640,6 @@
 static int rdev_get_properties(const struct radio_hw_device *dev,
                                 radio_hal_properties_t *properties)
 {
-    struct stub_radio_device *rdev = (struct stub_radio_device *)dev;
-
     ALOGI("%s", __func__);
     if (properties == NULL)
         return -EINVAL;
@@ -756,7 +754,6 @@
                      hw_device_t** device)
 {
     struct stub_radio_device *rdev;
-    int ret;
 
     if (strcmp(name, RADIO_HARDWARE_DEVICE) != 0)
         return -EINVAL;