Andorid 13 原生系统,蓝牙默认名称是设备型号 PRODUCT_MODEL
。
修改蓝牙默认名称,
找到对应产品的 device.mk ,添加如下
#custom bluetooth name
PRODUCT_PROPERTY_OVERRIDES += \
bluetooth.device.default_name="Cus_bt_name"
追踪到 packages/modules/Bluetooth/system/btif/src/btif_dm.cc
#define NUM_TIMEOUT_RETRIES 5
#ifndef PROPERTY_DEFAULT_DEVICE_NAME
#define PROPERTY_DEFAULT_DEVICE_NAME "bluetooth.device.default_name"
#endif
#ifndef PROPERTY_PRODUCT_MODEL
#define PROPERTY_PRODUCT_MODEL "ro.product.model"
#endif
#define DEFAULT_LOCAL_NAME_MAX 31
#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
#error "default btif local name size exceeds stack supported length"
#endif
static const char* btif_get_default_local_name() {
if (btif_default_local_name[0] == '\0') {
int max_len = sizeof(btif_default_local_name) - 1;
// Use the stable sysprop on Android devices, otherwise use osi_property_get
#ifdef OS_ANDROID
std::optional<std::string> default_local_name =
android::sysprop::BluetoothProperties::getDefaultDeviceName();//1
if (default_local_name.has_value() && default_local_name.value() != "") {
strncpy(btif_default_local_name, default_local_name.value().c_str(),
max_len);
}
#else
char prop_name[PROPERTY_VALUE_MAX];
osi_property_get(PROPERTY_DEFAULT_DEVICE_NAME, prop_name, "");//2
strncpy(btif_default_local_name, prop_name, max_len);
#endif
// If no value was placed in the btif_default_local_name then use model name
if (btif_default_local_name[0] == '\0') {
char prop_model[PROPERTY_VALUE_MAX];
osi_property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");//3
strncpy(btif_default_local_name, prop_model, max_len);
}
btif_default_local_name[max_len] = '\0';
}
return btif_default_local_name;
}
从三个地方取值,
-
注释1 :getDefaultDeviceName 找到
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
,private String getDefaultDeviceName() { return mContext.getResources().getString(R.string.def_device_name_simple, Build.MODEL); }
Build.MODEL
就是 ro.product.model
- 注释2 :读取
bluetooth.device.default_name
属性值。 - 注释3 :读取
ro.product.model
属性值,即产品目录里的PRODUCT_MODEL
。