summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTyler Freeman <fuego@google.com>2017-07-27 18:21:18 -0700
committerTyler Freeman <fuego@google.com>2017-07-31 21:16:15 +0000
commitfead72d1241d17908034828cc1035fc02eeb80d5 (patch)
tree9855cb1bc2097c7b309e7c23033873755c61fe31
parent33f4a8065e07cac265ebe532d0eeaecaac0eff26 (diff)
downloadandroid_system_bt-fead72d1241d17908034828cc1035fc02eeb80d5.tar.gz
android_system_bt-fead72d1241d17908034828cc1035fc02eeb80d5.tar.bz2
android_system_bt-fead72d1241d17908034828cc1035fc02eeb80d5.zip
DO NOT MERGE ANYWHERE Allow the Bluetooth MAC address to be updated asynchronously (3/3)
There are intermittent issues where either the returned Bluetooth MAC address to Java framework is uninitialized or this address update arrives too late. This fix will do 2 things: (1) Returns error when MAC address is unavailable in the native code. (2) Updates the MAC address later by adding a new broadcast event. Test: Check address for these cases: factory reset, system reboot, and Bluetooth re-enable. Bug: 36709382 (cherry picked from commit 7dc0525365025e17e289869288b1b7d5146306cc) Merged-In: I7b1c526ee227897c003ac921078f317f96b92604 Change-Id: I9810484a136c69d487a4b415c9265913db6c5cce
-rw-r--r--btif/src/btif_core.c9
-rw-r--r--btif/src/btif_storage.c36
2 files changed, 34 insertions, 11 deletions
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index c74c6ddd2..7dc93c4cf 100644
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -709,13 +709,18 @@ static bt_status_t btif_in_get_adapter_properties(void)
uint32_t disc_timeout;
bt_bdaddr_t bonded_devices[BTM_SEC_MAX_DEVICE_RECORDS];
bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
+ bt_status_t status;
num_props = 0;
/* BD_ADDR */
BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDADDR,
sizeof(addr), &addr);
- btif_storage_get_adapter_property(&properties[num_props]);
- num_props++;
+ status = btif_storage_get_adapter_property(&properties[num_props]);
+ // Add BT_PROPERTY_BDADDR property into list only when successful.
+ // Otherwise, skip this property entry.
+ if (status == BT_STATUS_SUCCESS) {
+ num_props++;
+ }
/* BD_NAME */
BTIF_STORAGE_FILL_PROPERTY(&properties[num_props], BT_PROPERTY_BDNAME,
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 83dcc8c47..cd21bcf15 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -52,6 +52,8 @@
#include "osi/include/log.h"
#include "osi/include/osi.h"
+#include "device/include/controller.h"
+
/************************************************************************************
** Constants & Macros
************************************************************************************/
@@ -80,9 +82,11 @@
/* This is a local property to add a device found */
#define BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF
-#define BTIF_STORAGE_GET_ADAPTER_PROP(t,v,l,p) \
- {p.type=t;p.val=v;p.len=l; btif_storage_get_adapter_property(&p);}
+// TODO: This macro should be converted to a function
+#define BTIF_STORAGE_GET_ADAPTER_PROP(s, t,v,l,p) \
+ {p.type=t;p.val=v;p.len=l; s = btif_storage_get_adapter_property(&p);}
+// TODO: This macro should be converted to a function
#define BTIF_STORAGE_GET_REMOTE_PROP(b,t,v,l,p) \
{p.type=t;p.val=v;p.len=l;btif_storage_get_remote_device_property(b,&p);}
@@ -583,8 +587,17 @@ bt_status_t btif_storage_get_adapter_property(bt_property_t *property)
if (property->type == BT_PROPERTY_BDADDR)
{
bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)property->val;
- /* This has been cached in btif. Just fetch it from there */
- memcpy(bd_addr, &btif_local_bd_addr, sizeof(bt_bdaddr_t));
+ /* Fetch the local BD ADDR */
+ const controller_t* controller = controller_get_interface();
+ if (controller->get_is_ready() == false) {
+ BTIF_TRACE_DEBUG("%s: Controller not ready! Unable to return Bluetooth Address",
+ __FUNCTION__);
+ memset(bd_addr, 0, sizeof(bt_bdaddr_t));
+ return BT_STATUS_FAIL;
+ } else {
+ BTIF_TRACE_DEBUG("%s: Controller ready!", __FUNCTION__);
+ memcpy(bd_addr, controller->get_address(), sizeof(bt_bdaddr_t));
+ }
property->len = sizeof(bt_bdaddr_t);
return BT_STATUS_SUCCESS;
}
@@ -854,6 +867,7 @@ bt_status_t btif_storage_load_bonded_devices(void)
uint32_t disc_timeout;
bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
bt_uuid_t remote_uuids[BT_MAX_NUM_UUIDS];
+ bt_status_t status;
btif_in_fetch_bonded_devices(&bonded_devices, 1);
@@ -862,12 +876,16 @@ bt_status_t btif_storage_load_bonded_devices(void)
memset(adapter_props, 0, sizeof(adapter_props));
/* BD_ADDR */
- BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDADDR, &addr, sizeof(addr),
+ BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDADDR, &addr, sizeof(addr),
adapter_props[num_props]);
- num_props++;
+ // Add BT_PROPERTY_BDADDR property into list only when successful.
+ // Otherwise, skip this property entry.
+ if (status == BT_STATUS_SUCCESS) {
+ num_props++;
+ }
/* BD_NAME */
- BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_BDNAME, &name, sizeof(name),
+ BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_BDNAME, &name, sizeof(name),
adapter_props[num_props]);
num_props++;
@@ -883,7 +901,7 @@ bt_status_t btif_storage_load_bonded_devices(void)
num_props++;
/* DISC_TIMEOUT */
- BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+ BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
&disc_timeout, sizeof(disc_timeout),
adapter_props[num_props]);
num_props++;
@@ -901,7 +919,7 @@ bt_status_t btif_storage_load_bonded_devices(void)
num_props++;
/* LOCAL UUIDs */
- BTIF_STORAGE_GET_ADAPTER_PROP(BT_PROPERTY_UUIDS,
+ BTIF_STORAGE_GET_ADAPTER_PROP(status, BT_PROPERTY_UUIDS,
local_uuids, sizeof(local_uuids),
adapter_props[num_props]);
num_props++;