修改bt默认设备名
蓝牙设备名称在external/bluetooth/bluedroid/btif/src/btif_dm.c中,
使用BTM_DEF_LOCAL_NAME的定义,如果没有定义,则使用ro.product.model。
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;
}
一般会定义BTM_DEF_LOCAL_NAME,在external/bluetooth/bluedroid/include/bt_target.h中
#ifndef BTM_DEF_LOCAL_NAME
#define BTM_DEF_LOCAL_NAME ""
#endif
不过高通平台在device/qcom/common/bdroid_buildcfg.h中定义了
#define BTM_DEF_LOCAL_NAME "QCOM-BTD"
所以,需要修改这个宏定义的值,或者为了区分项目调用不同的bdroid_buildcfg.h
在device/qcom/common/base.mk中修改
#Modify for customize bluetooth hostname
ifeq ($(TARGET_PRODUCT), l932)
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/qcom/l932/bluetooth
else
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/qcom/common
endif
更好的办法:
因为在定义
bt/include/bt_target.h:551:#ifndef BTM_DEF_LOCAL_NAME
bt/include/bt_target.h:552:#define BTM_DEF_LOCAL_NAME ""
在system/bt/btif/src/btif_dm.c中用到,可以在这里定义:
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;
}