客户在需要 蓝牙名字固定前缀加随机数后缀时可以采用该补丁
如果要变更前缀以3368平台为例 修改bdroid_buildcfg.h 中BTM_DEF_LOCAL_NAME 定义即可
device/rockchip/rk3368/bluetooth/bdroid_buildcfg.h
上补丁
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
old mode 100644
new mode 100755
index 4930017..2cfba9d
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -29,11 +29,15 @@
#include <unistd.h>
#include <hardware/bluetooth.h>
-
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include <utils/Log.h>
#include <cutils/properties.h>
#include "gki.h"
#include "btu.h"
+#include<time.h>
+#include<stdlib.h>
#include "bd.h"
#include "bta_api.h"
#include "btif_api.h"
@@ -1567,6 +1571,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
{
case BTA_DM_ENABLE_EVT:
{
+ BTIF_TRACE_EVENT("%s %d",__func__,__LINE__);
BD_NAME bdname;
bt_status_t status;
bt_property_t prop;
@@ -1579,6 +1584,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
{
/* A name exists in the storage. Make this the device name */
BTA_DmSetDeviceName((char*)prop.val);
+ btif_storage_set_adapter_property(&prop);
}
else
{
@@ -1615,6 +1621,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
btif_storage_load_autopair_device_list();
btif_enable_bluetooth_evt(p_data->enable.status, p_data->enable.bd_addr);
+ BTIF_TRACE_EVENT("%s %d",__func__,__LINE__);
}
break;
@@ -2966,7 +2973,9 @@ void btif_dm_save_ble_bonding_keys(void)
BTIF_DM_LE_KEY_LCSRK,
sizeof(btif_dm_ble_lcsrk_keys_t));
}
-
+ /// add flush config to file
+ BTIF_TRACE_DEBUG("%s try to call btif_config_flush ",__FUNCTION__);
+ btif_config_flush();
}
@@ -3134,7 +3143,34 @@ void btif_dm_on_disable()
btif_dm_cancel_bond(&bd_addr);
}
}
-
+static int random_number(int min, int max)
+{
+ static int dev_random_fd = -1;
+ char *next_random_byte;
+ int bytes_to_read;
+ unsigned random_value;
+ if (dev_random_fd == -1)
+ {
+ dev_random_fd = open("/dev/random", O_RDONLY);
+ }
+ if(dev_random_fd !=-1) {
+ BTIF_TRACE_DEBUG("access kernel rand pool sucess");
+ next_random_byte = (char *)&random_value;
+ bytes_to_read = sizeof(random_value);
+ do
+ {
+ int bytes_read;
+ bytes_read = read(dev_random_fd, next_random_byte, bytes_to_read);
+ bytes_to_read -= bytes_read;
+ next_random_byte += bytes_read;
+ }while(bytes_to_read > 0);
+ return min + (random_value % (max - min + 1));
+ } else {
+ BTIF_TRACE_DEBUG("acess kernel rand pool faiture ,I will try to use stdlib");
+ srand((int)time(0));
+ return rand()%(max - min + 1);
+ }
+}
/*******************************************************************************
**
** Function btif_dm_read_energy_info
@@ -3165,6 +3201,12 @@ static char* btif_get_default_local_name() {
property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
strncpy(btif_default_local_name, prop_model, max_len);
}
+
+#if 0
+ sprintf(btif_default_local_name,"ICBC-UKEY-NM%04d",rand()%10000);
+#else
+ sprintf(btif_default_local_name,"%s%04d",BTM_DEF_LOCAL_NAME,random_number(1,9999));
+#endif
btif_default_local_name[max_len] = '\0';
}
return btif_default_local_name;
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
old mode 100644
new mode 100755
index 5b1bf96..3fa86bd
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -254,6 +254,7 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop)
btif_config_set_str("Remote", bdstr, BTIF_STORAGE_PATH_REMOTE_ALIASE, value);
/* save friendly name immediately */
btif_config_save();
+ btif_config_flush();
break;
case BT_PROPERTY_ADAPTER_SCAN_MODE:
btif_config_set_int("Local", "Adapter",
@@ -1181,7 +1182,7 @@ bt_status_t btif_in_fetch_bonded_ble_device(char *remote_bd_addr,int add, btif_b
if(!btif_config_get_int("Remote", remote_bd_addr,"DevType", &device_type))
return BT_STATUS_FAIL;
- if(device_type == BT_DEVICE_TYPE_BLE)
+ if ((device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE)
{
BTIF_TRACE_DEBUG("%s %s found a BLE device", __FUNCTION__,remote_bd_addr);
str2bd(remote_bd_addr, &bd_addr);
diff --git a/bluetooth.te b/bluetooth.te
index 2b108a9..f64d44c 100644
--- a/bluetooth.te
+++ b/bluetooth.te
@@ -16,7 +16,7 @@ r_dir_file(bluetooth, bluetooth_efs_file)
# Device accesses.
allow bluetooth { tun_device uhid_device hci_attach_dev }:chr_file rw_file_perms;
-
+allow bluetooth urandom_device:chr_file rw_file_perms;
# Other domains that can create and use bluetooth sockets.
# SELinux does not presently define a specific socket class for
# bluetooth sockets, nor does it distinguish among the bluetooth protocols.
技术交流群: 微信号