From 1e5109b5cbf49810abd0c94c413ce07db52caaca Mon Sep 17 00:00:00 2001 From: Matthew Xie Date: Fri, 9 Nov 2012 18:26:26 -0800 Subject: [PATCH] Use product model as default bluetooth name if not defined bug 7441329 Change-Id: I6afe54a8a0c4d1120e96eb808cf9fc4bf5b37fdb --- btif/src/btif_dm.c | 47 ++++++++++++++++++++++++++++++++++++++--------- include/bt_target.h | 9 +++------ stack/btm/btm_devctl.c | 5 ----- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c index 360942069..db3589c0a 100644 --- a/btif/src/btif_dm.c +++ b/btif/src/btif_dm.c @@ -64,6 +64,11 @@ #define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10 #define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2 +#define PROPERTY_PRODUCT_MODEL "ro.product.model" +#define DEFAULT_LOCAL_NAME_MAX 15 +#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN) + #error "default btif local name size exceeds stack supported length" +#endif typedef struct { @@ -115,6 +120,11 @@ typedef struct /* This flag will be true if HCI_Inquiry is in progress */ static BOOLEAN btif_dm_inquiry_in_progress = FALSE; +/************************************************************************************ +** Static variables +************************************************************************************/ +static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'}; + /****************************************************************************** ** Static functions ******************************************************************************/ @@ -131,6 +141,7 @@ static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif); static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl); static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req); #endif +static char* btif_get_default_local_name(); /****************************************************************************** ** Externs ******************************************************************************/ @@ -1276,18 +1287,17 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) prop.val = (void*)bdname; status = btif_storage_get_adapter_property(&prop); - /* Storage does not have a name yet. - ** Use the default name and write it to the chip - */ - if (status != BT_STATUS_SUCCESS) + if (status == BT_STATUS_SUCCESS) { - BTA_DmSetDeviceName((char *)BTM_DEF_LOCAL_NAME); - /* Hmmm...Should we store this too??? */ + /* A name exists in the storage. Make this the device name */ + BTA_DmSetDeviceName((char*)prop.val); } else { - /* A name exists in the storage. Make this the device name */ - BTA_DmSetDeviceName((char*)prop.val); + /* Storage does not have a name yet. + * Use the default name and write it to the chip + */ + BTA_DmSetDeviceName(btif_get_default_local_name()); } /* for each of the enabled services in the mask, trigger the profile @@ -2033,7 +2043,7 @@ bt_status_t btif_dm_get_adapter_property(bt_property_t *prop) case BT_PROPERTY_BDNAME: { bt_bdname_t *bd_name = (bt_bdname_t*)prop->val; - strcpy((char *)bd_name->name, (char *)BTM_DEF_LOCAL_NAME); + strcpy((char *)bd_name->name, btif_get_default_local_name()); prop->len = strlen((char *)bd_name->name); } break; @@ -2582,3 +2592,22 @@ void btif_dm_on_disable() btif_dm_cancel_bond(&bd_addr); } } + +static char* btif_get_default_local_name() { + if (btif_default_local_name[0] == '\0') + { + int max_len = sizeof(btif_default_local_name) - 1; + if (BTM_DEF_LOCAL_NAME[0] != '\0') + { + strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len); + } + else + { + char prop_model[PROPERTY_VALUE_MAX]; + property_get(PROPERTY_PRODUCT_MODEL, prop_model, ""); + strncpy(btif_default_local_name, prop_model, max_len); + } + btif_default_local_name[max_len] = '\0'; + } + return btif_default_local_name; +} diff --git a/include/bt_target.h b/include/bt_target.h index 036e5f906..6f3df8a23 100644 --- a/include/bt_target.h +++ b/include/bt_target.h @@ -1057,12 +1057,9 @@ and USER_HW_DISABLE_API macros */ #define BTM_MAX_LOC_BD_NAME_LEN 248 #endif -/* TRUE if default string is used, FALSE if device name is set in the application */ -#ifndef BTM_USE_DEF_LOCAL_NAME -#define BTM_USE_DEF_LOCAL_NAME TRUE -#endif - -/* Fixed Default String (Ignored if BTM_USE_DEF_LOCAL_NAME is FALSE) */ +/* Fixed Default String. When this is defined as null string, the device's + * product model name is used as the default local name. + */ #ifndef BTM_DEF_LOCAL_NAME #define BTM_DEF_LOCAL_NAME "" #endif diff --git a/stack/btm/btm_devctl.c b/stack/btm/btm_devctl.c index 7f56d2c28..49e05b472 100644 --- a/stack/btm/btm_devctl.c +++ b/stack/btm/btm_devctl.c @@ -144,9 +144,6 @@ void btm_dev_init (void) /* Initialize nonzero defaults */ #if (BTM_MAX_LOC_BD_NAME_LEN > 0) memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME)); -#if (BTM_USE_DEF_LOCAL_NAME == TRUE) - BCM_STRNCPY_S(btm_cb.cfg.bd_name, sizeof(btm_cb.cfg.bd_name), BTM_DEF_LOCAL_NAME, BTM_MAX_LOC_BD_NAME_LEN); -#endif #endif btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET; @@ -688,8 +685,6 @@ void btm_continue_reset (void) #if (BTM_MAX_LOC_BD_NAME_LEN > 0) && (BTM_SET_DEV_NAME_UPON_RESET == TRUE) BTM_SetLocalDeviceName(btm_cb.cfg.bd_name); -#elif BTM_USE_DEF_LOCAL_NAME == TRUE - BTM_SetLocalDeviceName(BTM_DEF_LOCAL_NAME); #endif BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len); -- 2.11.0