网络平台建站,软文代发代理,如何备份网站,郑州公司网页DeviceProperties、AdapterProperties、StorageModule、以及 bt_config.conf 是 AOSP Bluetooth 栈中 设备属性管理与持久化系统 的核心组成部分#xff0c;它们之间关系紧密#xff0c;但职责各有不同。
下面我将依次讲解它们的区别与联系.
注意:
在代码里面 还有 Blueto…DeviceProperties、AdapterProperties、StorageModule、以及 bt_config.conf 是 AOSP Bluetooth 栈中 设备属性管理与持久化系统 的核心组成部分它们之间关系紧密但职责各有不同。
下面我将依次讲解它们的区别与联系.
注意:
在代码里面 还有 BluetoothProperties 他是管理 蓝牙相关的系统属性的 和本文讨论的 DeviceProperties、AdapterProperties 不是同一个话题。有兴趣可以参看 【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】 1. 核心组件职责概览
模块职责管理对象是否与存储直接交互AdapterProperties管理本地蓝牙适配器的属性如名称、可发现性、IO能力本地适配器✅ 是会调用 StorageModuleDeviceProperties管理单个远程设备的属性如名称、RSSI、UUID、版本信息等每个远程设备一套✅ 是会调用 StorageModuleStorageModule抽象了属性的持久化与加载逻辑负责读写 bt_config.conf存储本地和远程设备属性✅ 是底层对 bt_config.conf 读写bt_config.conf配置文件持久化存储蓝牙设备属性ini 格式适配器/已配对的远程设备✅ 是由 StorageModule 管理 2. 各模块职责与交互细节
1. AdapterProperties 对应的是本地蓝牙适配器的属性如 本地蓝牙名 (BT_PROPERTY_BDNAME) 适配器地址 (BT_PROPERTY_BDADDR) 可发现性 (BT_PROPERTY_ADAPTER_SCAN_MODE) LE 特性等 存储方式 初始化时从 StorageModule 读取对应项 修改时如用户改蓝牙名通过 StorageModule 写入 bt_config.conf 的 [Adapter] 节 2. DeviceProperties 对应每一个远程设备配对或曾连接的属性如 名称、RSSI、UUID、版本、是否支持某功能等 这些属性通过扫描、配对、连接等过程获得 管理方式 每个远程设备维护一个 DeviceProperties 实例以地址为 key 当发现设备、连接、配对或服务发现后更新属性 写入存储 只有绑定/配对成功的设备才会写入 如果一个设备只是在扫描时被发现会创建一个 临时的 DeviceProperties保存在内存中。 掉电或者开关蓝牙时将丢失。 这些属性会保存到 bt_config.conf 的 [RemoteDevice] 节例如
[RemoteDevice00:11:22:33:44:55]
NameMyHeadphones
DevType1
Service180A 112D ...
3. StorageModule 提供统一接口负责蓝牙配置的持久化与读取。 核心功能 加载/保存本地适配器属性 加载/保存配对设备属性 支持迁移、同步、回写等操作 底层调用 config.cc 进行 ini 格式文件操作。
我之前写过一篇 关于 StorageModule 模块的文章需要 可以查阅
【android bluetooth 框架分析 02】【Module详解 6】【StorageModule 模块介绍】 4. bt_config.conf 文件 位置/data/misc/bluedroid/bt_config.conf 权限系统组件访问普通 APP 不可读 结构
[Adapter]
Address00:11:22:33:AA:BB
NameCarBluetooth
ScanMode1
DiscoverableTimeout120[RemoteDevice11:22:33:44:55:66]
NamePhone
DevType1
Service110A 110B
3. 关键问题扫描到的未配对设备会写入 bt_config.conf 吗
扫描到的未配对设备会写入 bt_config.conf 吗
不会 当仅仅是扫描inquiry/discovery到一个设备时系统可能会临时创建该设备的 DeviceProperties 实例但不会写入 bt_config.conf。 只有以下情形会触发写入 配对成功 某些属性需要持久化如用户手动设置了设备名等 有实际连接历史 存储条件满足具体由 DeviceManager::Add 判断
1. 临时设备属性的生命周期 临时创建的 DeviceProperties 保存在内存中 断电或重启后不保留 若用户未配对该设备这些属性不会持久化 4. 模块关系图示意
-----------------
| AdapterProperties (本地适配器属性)
-----------------|v
-----------------
| StorageModule | ------- bt_config.conf (持久化存储)
-----------------^|
------------------
| DeviceProperties (远程设备属性)
| -- 每个设备一套 --
------------------
5. 我们 源码里面都定义了那些属性呢
1. java 侧的属性表
android/app/src/com/android/bluetooth/btservice/AbstractionLayer.java static final int BT_PROPERTY_BDNAME 0x01;static final int BT_PROPERTY_BDADDR 0x02;static final int BT_PROPERTY_UUIDS 0x03;static final int BT_PROPERTY_CLASS_OF_DEVICE 0x04;static final int BT_PROPERTY_TYPE_OF_DEVICE 0x05;static final int BT_PROPERTY_SERVICE_RECORD 0x06;static final int BT_PROPERTY_ADAPTER_SCAN_MODE 0x07;static final int BT_PROPERTY_ADAPTER_BONDED_DEVICES 0x08;static final int BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT 0x09;static final int BT_PROPERTY_REMOTE_FRIENDLY_NAME 0x0A;static final int BT_PROPERTY_REMOTE_RSSI 0x0B;static final int BT_PROPERTY_REMOTE_VERSION_INFO 0x0C;static final int BT_PROPERTY_LOCAL_LE_FEATURES 0x0D;static final int BT_PROPERTY_LOCAL_IO_CAPS 0x0e;static final int BT_PROPERTY_LOCAL_IO_CAPS_BLE 0x0f;static final int BT_PROPERTY_DYNAMIC_AUDIO_BUFFER 0x10;static final int BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER 0x11;2. native 属性表
bt_property_type_t
system/include/hardware/bluetooth.h
/* Bluetooth Adapter and Remote Device property types */
typedef enum {/* Properties common to both adapter and remote device *//*** Description - Bluetooth Device Name* Access mode - Adapter name can be GET/SET. Remote device can be GET* Data type - bt_bdname_t*/BT_PROPERTY_BDNAME 0x1,/*** Description - Bluetooth Device Address* Access mode - Only GET.* Data type - RawAddress*/BT_PROPERTY_BDADDR,/*** Description - Bluetooth Service 128-bit UUIDs* Access mode - Only GET.* Data type - Array of bluetooth::Uuid (Array size inferred from property* length).*/BT_PROPERTY_UUIDS,/*** Description - Bluetooth Class of Device as found in Assigned Numbers* Access mode - Only GET.* Data type - uint32_t.*/BT_PROPERTY_CLASS_OF_DEVICE,/*** Description - Device Type - BREDR, BLE or DUAL Mode* Access mode - Only GET.* Data type - bt_device_type_t*/BT_PROPERTY_TYPE_OF_DEVICE,/*** Description - Bluetooth Service Record* Access mode - Only GET.* Data type - bt_service_record_t*/BT_PROPERTY_SERVICE_RECORD,/* Properties unique to adapter *//*** Description - Bluetooth Adapter scan mode* Access mode - GET and SET* Data type - bt_scan_mode_t.*/BT_PROPERTY_ADAPTER_SCAN_MODE,/*** Description - List of bonded devices* Access mode - Only GET.* Data type - Array of RawAddress of the bonded remote devices* (Array size inferred from property length).*/BT_PROPERTY_ADAPTER_BONDED_DEVICES,/*** Description - Bluetooth Adapter Discoverable timeout (in seconds)* Access mode - GET and SET* Data type - uint32_t*/BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT,/* Properties unique to remote device *//*** Description - User defined friendly name of the remote device* Access mode - GET and SET* Data type - bt_bdname_t.*/BT_PROPERTY_REMOTE_FRIENDLY_NAME,/*** Description - RSSI value of the inquired remote device* Access mode - Only GET.* Data type - int8_t.*/BT_PROPERTY_REMOTE_RSSI,/*** Description - Remote version info* Access mode - SET/GET.* Data type - bt_remote_version_t.*/BT_PROPERTY_REMOTE_VERSION_INFO,/*** Description - Local LE features* Access mode - GET.* Data type - bt_local_le_features_t.*/BT_PROPERTY_LOCAL_LE_FEATURES,/*** Description - Local Input/Output Capabilities for classic Bluetooth* Access mode - GET and SET* Data Type - bt_io_cap_t.*/BT_PROPERTY_LOCAL_IO_CAPS,/*** Description - Local Input/Output Capabilities for BLE* Access mode - GET and SET* Data Type - bt_io_cap_t.*/BT_PROPERTY_LOCAL_IO_CAPS_BLE,BT_PROPERTY_DYNAMIC_AUDIO_BUFFER,/*** Description - True if Remote is a Member of a Coordinated Set.* Access mode - GET.* Data Type - bool.*/BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER,BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP 0xFF,
} bt_property_type_t;3. 属性使用场景介绍
1. AdapterProperties 和 DeviceProperties 共同使用
枚举常量说明使用范围数据类型访问权限 适用于 Adapter 和 Remote DeviceBT_PROPERTY_BDNAME设备名称Adapter: 读/写Remote Device: 只读bt_bdname_tGET / SETAdapterGETRemoteBT_PROPERTY_BDADDR设备地址Adapter Remote DeviceRawAddressGETBT_PROPERTY_UUIDS支持的服务 UUID 列表Remote Devicebluetooth::Uuid[]GETBT_PROPERTY_CLASS_OF_DEVICE类别码Remote Deviceuint32_tGETBT_PROPERTY_TYPE_OF_DEVICE设备类型BR/EDR/LERemote Devicebt_device_type_tGETBT_PROPERTY_SERVICE_RECORD服务记录Remote Devicebt_service_record_tGET
2. 仅 AdapterProperties 使用
枚举常量说明使用范围数据类型访问权限 仅适用于 Adapter本地适配器BT_PROPERTY_ADAPTER_SCAN_MODE扫描模式可发现性Adapterbt_scan_mode_tGET / SETBT_PROPERTY_ADAPTER_BONDED_DEVICES已绑定设备地址列表AdapterRawAddress[]GETBT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT可发现超时时间Adapteruint32_tGET / SETBT_PROPERTY_LOCAL_LE_FEATURES本地 LE 特性Adapterbt_local_le_features_tGETBT_PROPERTY_LOCAL_IO_CAPS本地 IO 能力经典蓝牙Adapterbt_io_cap_tGET / SETBT_PROPERTY_LOCAL_IO_CAPS_BLE本地 IO 能力BLEAdapterbt_io_cap_tGET / SETBT_PROPERTY_DYNAMIC_AUDIO_BUFFER音频缓冲设置动态Adapter自定义类型未明确
3. 仅 DeviceProperties 使用
枚举常量说明使用范围数据类型访问权限 仅适用于 Remote Device远程设备BT_PROPERTY_REMOTE_FRIENDLY_NAME远程设备名称用户设定Remote Devicebt_bdname_tGET / SETBT_PROPERTY_REMOTE_RSSI远程设备 RSSIRemote Deviceint8_tGETBT_PROPERTY_REMOTE_VERSION_INFO远程设备协议版本信息Remote Devicebt_remote_version_tGET / SETBT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER是否是协同设备成员Remote DeviceboolGETBT_PROPERTY_REMOTE_DEVICE_TIMESTAMP属性刷新时间戳Remote Deviceint64_t或自定义GET
4. 小结
分类枚举项Adapter 专属属性ADAPTER_SCAN_MODE, ADAPTER_BONDED_DEVICES, ADAPTER_DISCOVERABLE_TIMEOUT, LOCAL_LE_FEATURES, LOCAL_IO_CAPS, LOCAL_IO_CAPS_BLE, DYNAMIC_AUDIO_BUFFERRemote Device 专属属性REMOTE_FRIENDLY_NAME, REMOTE_RSSI, REMOTE_VERSION_INFO, REMOTE_IS_COORDINATED_SET_MEMBER, REMOTE_DEVICE_TIMESTAMP, CLASS_OF_DEVICE, TYPE_OF_DEVICE, SERVICE_RECORD, UUIDSAdapter 与 Remote 共用属性BDNAME, BDADDR
6. 总结重点
关键点说明AdapterProperties管理本地适配器的属性初始化时加载并可写入 bt_config.confDeviceProperties管理远程设备属性仅在配对后写入 bt_config.confStorageModule所有属性存储的中间桥梁bt_config.conf存储持久化蓝牙信息的文件位于 /data/misc/bluedroid扫描行为是否写入文件❌ 不会只有绑定/配对设备才写入
接下来我会出单独的文章来总结 DeviceProperties、AdapterProperties.
敬请期待!!! 文章转载自: http://www.morning.xqnzn.cn.gov.cn.xqnzn.cn http://www.morning.hengqilan.cn.gov.cn.hengqilan.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn http://www.morning.wqpb.cn.gov.cn.wqpb.cn http://www.morning.bkpbm.cn.gov.cn.bkpbm.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.dhyzr.cn.gov.cn.dhyzr.cn http://www.morning.bhwz.cn.gov.cn.bhwz.cn http://www.morning.klyyd.cn.gov.cn.klyyd.cn http://www.morning.wqbfd.cn.gov.cn.wqbfd.cn http://www.morning.knscf.cn.gov.cn.knscf.cn http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.tsmcc.cn.gov.cn.tsmcc.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.lxmks.cn.gov.cn.lxmks.cn http://www.morning.lxlfr.cn.gov.cn.lxlfr.cn http://www.morning.gwdmj.cn.gov.cn.gwdmj.cn http://www.morning.tcpnp.cn.gov.cn.tcpnp.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.lmmyl.cn.gov.cn.lmmyl.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.jksgy.cn.gov.cn.jksgy.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.hrdx.cn.gov.cn.hrdx.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.dhrbj.cn.gov.cn.dhrbj.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.cqrenli.com.gov.cn.cqrenli.com http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.hcwlq.cn.gov.cn.hcwlq.cn http://www.morning.dthyq.cn.gov.cn.dthyq.cn http://www.morning.wptrm.cn.gov.cn.wptrm.cn http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.dnvhfh.cn.gov.cn.dnvhfh.cn http://www.morning.hyyxsc.cn.gov.cn.hyyxsc.cn http://www.morning.kaylyea.com.gov.cn.kaylyea.com http://www.morning.slwfy.cn.gov.cn.slwfy.cn http://www.morning.hyjpl.cn.gov.cn.hyjpl.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.rgksz.cn.gov.cn.rgksz.cn http://www.morning.wjrtg.cn.gov.cn.wjrtg.cn http://www.morning.cklgf.cn.gov.cn.cklgf.cn http://www.morning.smcfk.cn.gov.cn.smcfk.cn http://www.morning.fwjfh.cn.gov.cn.fwjfh.cn http://www.morning.kqbjy.cn.gov.cn.kqbjy.cn http://www.morning.yrjhr.cn.gov.cn.yrjhr.cn http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.rdxp.cn.gov.cn.rdxp.cn http://www.morning.xnltz.cn.gov.cn.xnltz.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.kskpx.cn.gov.cn.kskpx.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.cybch.cn.gov.cn.cybch.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.ykrkb.cn.gov.cn.ykrkb.cn http://www.morning.wkkqw.cn.gov.cn.wkkqw.cn http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn http://www.morning.hxlch.cn.gov.cn.hxlch.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.bttph.cn.gov.cn.bttph.cn http://www.morning.nqwkn.cn.gov.cn.nqwkn.cn http://www.morning.trtdg.cn.gov.cn.trtdg.cn http://www.morning.clpfd.cn.gov.cn.clpfd.cn http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn http://www.morning.vattx.cn.gov.cn.vattx.cn http://www.morning.ghzfx.cn.gov.cn.ghzfx.cn http://www.morning.gthwz.cn.gov.cn.gthwz.cn http://www.morning.wgqtj.cn.gov.cn.wgqtj.cn http://www.morning.ymhjb.cn.gov.cn.ymhjb.cn http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.mrttc.cn.gov.cn.mrttc.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn