119e95205Sopenharmony_ci## Profile测试使用说明文档 219e95205Sopenharmony_ci 319e95205Sopenharmony_ci 本文档主要介绍了蓝牙专项测试程序的Profile测试模块的功能使用说明。 419e95205Sopenharmony_ci 519e95205Sopenharmony_ci 619e95205Sopenharmony_ci 719e95205Sopenharmony_ci### Profile测试界面 819e95205Sopenharmony_ci 919e95205Sopenharmony_ci 1019e95205Sopenharmony_ci 1119e95205Sopenharmony_ci 1219e95205Sopenharmony_ci 1319e95205Sopenharmony_ci#### Profile的主要接口(ohos.bluetooth.d.ts) 1419e95205Sopenharmony_ci 1519e95205Sopenharmony_ci| method名称 | API名称 | 所需参数 | 返回值 | 备注 | 1619e95205Sopenharmony_ci| :----------: | :------------------: | :--------------: | :----------------------------: | :--: | 1719e95205Sopenharmony_ci| 获取连接状态 | getConnectionDevices | () | Array<string> | Base | 1819e95205Sopenharmony_ci| 获取设备状态 | getDeviceState | (device: string) | ProfileConnectionState(枚举) | Base | 1919e95205Sopenharmony_ci| 连接 | connect | (device: string) | boolean | | 2019e95205Sopenharmony_ci| 取消连接 | disconnect | (device: string) | boolean | | 2119e95205Sopenharmony_ci| 获取播放状态 | getPlayingState | (device: string) | PlayingState(枚举) | | 2219e95205Sopenharmony_ci 2319e95205Sopenharmony_ci>enum ProfileConnectionState { 2419e95205Sopenharmony_ci> 2519e95205Sopenharmony_ci> /** the current profile is disconnected */ 2619e95205Sopenharmony_ci> 2719e95205Sopenharmony_ci> STATE_DISCONNECTED = 0, 2819e95205Sopenharmony_ci> 2919e95205Sopenharmony_ci> /** the current profile is being connected */ 3019e95205Sopenharmony_ci> 3119e95205Sopenharmony_ci> STATE_CONNECTING = 1, 3219e95205Sopenharmony_ci> 3319e95205Sopenharmony_ci> /** the current profile is connected */ 3419e95205Sopenharmony_ci> 3519e95205Sopenharmony_ci> STATE_CONNECTED = 2, 3619e95205Sopenharmony_ci> 3719e95205Sopenharmony_ci> /** the current profile is being disconnected */ 3819e95205Sopenharmony_ci> 3919e95205Sopenharmony_ci> STATE_DISCONNECTING = 3 4019e95205Sopenharmony_ci> 4119e95205Sopenharmony_ci>} 4219e95205Sopenharmony_ci> 4319e95205Sopenharmony_ci> 4419e95205Sopenharmony_ci> 4519e95205Sopenharmony_ci>enum PlayingState { 4619e95205Sopenharmony_ci> 4719e95205Sopenharmony_ci> STATE_NOT_PLAYING, 4819e95205Sopenharmony_ci> 4919e95205Sopenharmony_ci> STATE_PLAYING, 5019e95205Sopenharmony_ci> 5119e95205Sopenharmony_ci>} 5219e95205Sopenharmony_ci 5319e95205Sopenharmony_ci#### 验证工具 5419e95205Sopenharmony_ci 5519e95205Sopenharmony_ci使用蓝牙音箱或键盘,连接后可以播放声音,查看显示信息。 5619e95205Sopenharmony_ci 5719e95205Sopenharmony_ci#### 补充 5819e95205Sopenharmony_ci 5919e95205Sopenharmony_ci1. A2DP(Advanced Audio Distribution Profile) 高级音频分发模式 6019e95205Sopenharmony_ci - Source(源)(SRC)–当设备用作数字音频流的源时,即为SRC,该数字音频流被传送到微微网的SNK。 6119e95205Sopenharmony_ci - Sink(槽)(SNK)–当设备充当同一微微网上从SRC传送的数字音频流的接收器时,它就是SNK。 6219e95205Sopenharmony_ci 6319e95205Sopenharmony_ci2. AVRCP(audio vidoe remote control protocol) 协议,用于远程控制音视频设备. 底层传输基于AVCTP传输协议,在蓝牙中,主要用于蓝牙音乐的控制,比如播放/暂停/下一曲/上一曲,以及获取播放状态、音乐信息等。 AVRCP有两个角色CT(contorl devices),TG(target devices).CT通过指令控制TG播放音乐,比如蓝牙耳机是CT,而手机是TG。 6419e95205Sopenharmony_ci 6519e95205Sopenharmony_ci注:AVRCP子协议的作用是支持CT控制TG,具体来说如果手机和一个蓝牙音箱设备连接上了,那么音箱可以控制手机播放/暂停/切歌以及获得手机上播放歌曲的信息,如专辑,歌名,歌手,时长等信息。 6619e95205Sopenharmony_ci 6719e95205Sopenharmony_ci3. 音频网关(AG)–这是作为音频网关的设备,用于输入和输出。作为音频网关的典型设备是手机。 6819e95205Sopenharmony_ci 6919e95205Sopenharmony_ci 免提单元(HF)–这是用作音频网关的远程音频输入和输出机制的设备。它还提供了一些远程控制手段 7019e95205Sopenharmony_ci 7119e95205Sopenharmony_ci4. HFP(Hands-Free Profile),通俗点翻译就是免提协议,说白了就是蓝牙电话协议,可以让蓝牙设备通过协议定义好的AT command控制电话,如接听、挂断、拒接、语音拨号等。 7219e95205Sopenharmony_ci 7319e95205Sopenharmony_ci5. HID定义了蓝牙在人机接口设备中的协议、特征和使用规程。典型的应用包括蓝牙鼠标、蓝牙键盘、蓝牙游戏手柄等。 7419e95205Sopenharmony_ci 7519e95205Sopenharmony_ci6. 其他功能暂未实现 7619e95205Sopenharmony_ci 7719e95205Sopenharmony_ci#### 功能 7819e95205Sopenharmony_ci 7919e95205Sopenharmony_ciBaseProfile:基础通用协议 8019e95205Sopenharmony_ci 8119e95205Sopenharmony_ci- getConnectionDevices 8219e95205Sopenharmony_ci - 使用指导:获取配置文件的已连接设备列表,返回值为已连接设备列表的地址。 8319e95205Sopenharmony_ci - 限制条件:必须有已连接的设备。 8419e95205Sopenharmony_ci - 验证方法:查看返回值。 8519e95205Sopenharmony_ci 8619e95205Sopenharmony_ci- getDeviceState 8719e95205Sopenharmony_ci - 使用指导:获取设备的配置文件状态,device为蓝牙设备的地址,返回值为{连接配置文件的连接状态} 8819e95205Sopenharmony_ci - 限制条件:有连接的配置文件 8919e95205Sopenharmony_ci - 验证方法:查看返回值。 9019e95205Sopenharmony_ci 9119e95205Sopenharmony_ci#### A2dpSource配置 9219e95205Sopenharmony_ci 9319e95205Sopenharmony_ci未开启蓝牙时: 9419e95205Sopenharmony_ci 9519e95205Sopenharmony_ci 9619e95205Sopenharmony_ci 9719e95205Sopenharmony_ci开启蓝牙时: 9819e95205Sopenharmony_ci 9919e95205Sopenharmony_ci 10019e95205Sopenharmony_ci 10119e95205Sopenharmony_ci- connect 10219e95205Sopenharmony_ci 10319e95205Sopenharmony_ci - 使用指导:使用a2dp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 10419e95205Sopenharmony_ci 10519e95205Sopenharmony_ci 10619e95205Sopenharmony_ci - 限制条件:之前未成功连接。 10719e95205Sopenharmony_ci 10819e95205Sopenharmony_ci - 验证方法:查看连接的播放设备是否正常使用。 10919e95205Sopenharmony_ci 11019e95205Sopenharmony_ci- disconnect 11119e95205Sopenharmony_ci 11219e95205Sopenharmony_ci - 使用指导:用a2dp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 11319e95205Sopenharmony_ci 11419e95205Sopenharmony_ci - 限制条件:已成功连接。 11519e95205Sopenharmony_ci 11619e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否还可以使用。 11719e95205Sopenharmony_ci 11819e95205Sopenharmony_ci- getPlayingState 11919e95205Sopenharmony_ci 12019e95205Sopenharmony_ci - 使用指导:获取设备的播放状态。device为远程设备的地址。返回值为远程设备的播放状态。 12119e95205Sopenharmony_ci 12219e95205Sopenharmony_ci - 限制条件:已成功连接。 12319e95205Sopenharmony_ci 12419e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否正常播放。 12519e95205Sopenharmony_ci 12619e95205Sopenharmony_ci#### HandsFreeAudioGateway配置 12719e95205Sopenharmony_ci 12819e95205Sopenharmony_ci未开启蓝牙时: 12919e95205Sopenharmony_ci 13019e95205Sopenharmony_ci 13119e95205Sopenharmony_ci 13219e95205Sopenharmony_ci开启蓝牙时: 13319e95205Sopenharmony_ci 13419e95205Sopenharmony_ci 13519e95205Sopenharmony_ci 13619e95205Sopenharmony_ci- connect: 13719e95205Sopenharmony_ci 13819e95205Sopenharmony_ci - 使用指导:使用hfp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 13919e95205Sopenharmony_ci 14019e95205Sopenharmony_ci - 限制条件:之前未成功连接。 14119e95205Sopenharmony_ci 14219e95205Sopenharmony_ci - 验证方法:查看连接的播放设备是否正常使用。 14319e95205Sopenharmony_ci 14419e95205Sopenharmony_ci- disconnect 14519e95205Sopenharmony_ci 14619e95205Sopenharmony_ci - 使用指导:用hfp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 14719e95205Sopenharmony_ci 14819e95205Sopenharmony_ci - 限制条件:已成功连接。 14919e95205Sopenharmony_ci 15019e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否还可以使用。 15119e95205Sopenharmony_ci 15219e95205Sopenharmony_ci#### HidHost配置 15319e95205Sopenharmony_ci 15419e95205Sopenharmony_ci未开启蓝牙时: 15519e95205Sopenharmony_ci 15619e95205Sopenharmony_ci 15719e95205Sopenharmony_ci 15819e95205Sopenharmony_ci开启蓝牙时: 15919e95205Sopenharmony_ci 16019e95205Sopenharmony_ci 16119e95205Sopenharmony_ci 16219e95205Sopenharmony_ci- connect 16319e95205Sopenharmony_ci 16419e95205Sopenharmony_ci - 使用指导:使用HitHost连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 16519e95205Sopenharmony_ci 16619e95205Sopenharmony_ci - 限制条件:之前未成功连接。 16719e95205Sopenharmony_ci 16819e95205Sopenharmony_ci - 验证方法:查看连接的播放设备是否正常使用。 16919e95205Sopenharmony_ci 17019e95205Sopenharmony_ci- disconnect 17119e95205Sopenharmony_ci 17219e95205Sopenharmony_ci - 使用指导:用HitHost断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 17319e95205Sopenharmony_ci 17419e95205Sopenharmony_ci - 限制条件:已成功连接。 17519e95205Sopenharmony_ci 17619e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否还可以使用。 17719e95205Sopenharmony_ci 17819e95205Sopenharmony_ci#### PanNetwork配置 17919e95205Sopenharmony_ci 18019e95205Sopenharmony_ci未开启蓝牙时: 18119e95205Sopenharmony_ci 18219e95205Sopenharmony_ci 18319e95205Sopenharmony_ci 18419e95205Sopenharmony_ci开启蓝牙时: 18519e95205Sopenharmony_ci 18619e95205Sopenharmony_ci 18719e95205Sopenharmony_ci 18819e95205Sopenharmony_ci- disconnect 18919e95205Sopenharmony_ci 19019e95205Sopenharmony_ci - 使用指导:用PanNetwork断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 19119e95205Sopenharmony_ci 19219e95205Sopenharmony_ci - 限制条件:已成功连接。 19319e95205Sopenharmony_ci 19419e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否还可以使用。 19519e95205Sopenharmony_ci 19619e95205Sopenharmony_ci 19719e95205Sopenharmony_ci 19819e95205Sopenharmony_ci#### ProfileManager的主要接口(ohos.bluetoothManager.d.ts) 19919e95205Sopenharmony_ci 20019e95205Sopenharmony_ci| method名称 | API名称 | 所需参数 | 返回值 | 备注 | 20119e95205Sopenharmony_ci| :----------: | :------------------: | :--------------: | :----------------------------: | :--: | 20219e95205Sopenharmony_ci| 获取连接状态 | getConnectionDevices | () | Array<string> | Base | 20319e95205Sopenharmony_ci| 获取设备状态 | getDeviceState | (device: string) | ProfileConnectionState(枚举) | Base | 20419e95205Sopenharmony_ci| 连接 | connect | (device: string) | boolean | | 20519e95205Sopenharmony_ci| 取消连接 | disconnect | (device: string) | boolean | | 20619e95205Sopenharmony_ci| 获取播放状态 | getPlayingState | (device: string) | PlayingState(枚举) | | 20719e95205Sopenharmony_ci 20819e95205Sopenharmony_ci>配置: 20919e95205Sopenharmony_ci> 21019e95205Sopenharmony_ci>#### ProfileConnectionState 枚举,蓝牙设备的profile连接状态 21119e95205Sopenharmony_ci> 21219e95205Sopenharmony_ci>| 名称 | 值 | 说明 | 21319e95205Sopenharmony_ci>| :------------------ | :--- | :-------------------- | 21419e95205Sopenharmony_ci>| STATE_DISCONNECTED | 0 | 表示profile已断连。 | 21519e95205Sopenharmony_ci>| STATE_CONNECTING | 1 | 表示profile正在连接。 | 21619e95205Sopenharmony_ci>| STATE_CONNECTED | 2 | 表示profile已连接。 | 21719e95205Sopenharmony_ci>| STATE_DISCONNECTING | 3 | 表示profile正在断连。 | 21819e95205Sopenharmony_ci> 21919e95205Sopenharmony_ci> 22019e95205Sopenharmony_ci> 22119e95205Sopenharmony_ci>#### ProfileId 蓝牙profile枚举,API9新增PROFILE_HID_HOST,PROFILE_PAN_NETWORK。 22219e95205Sopenharmony_ci> 22319e95205Sopenharmony_ci>| 名称 | 值 | 说明 | 22419e95205Sopenharmony_ci>| :------------------------------- | :--- | :----------------- | 22519e95205Sopenharmony_ci>| PROFILE_A2DP_SOURCE | 1 | 表示A2DP profile。 | 22619e95205Sopenharmony_ci>| PROFILE_HANDS_FREE_AUDIO_GATEWAY | 4 | 表示HFP profile。 | 22719e95205Sopenharmony_ci>| PROFILE_HID_HOST | 6 | 表示HID profile。 | 22819e95205Sopenharmony_ci>| PROFILE_PAN_NETWORK | 7 | 表示PAN profile。 | 22919e95205Sopenharmony_ci 23019e95205Sopenharmony_ci 23119e95205Sopenharmony_ci 23219e95205Sopenharmony_ci#### 功能 23319e95205Sopenharmony_ci 23419e95205Sopenharmony_ciBaseProfile:基础通用协议 23519e95205Sopenharmony_ci 23619e95205Sopenharmony_ci- getConnectionDevices 23719e95205Sopenharmony_ci 23819e95205Sopenharmony_ci - 使用指导:获取配置文件的已连接设备列表,返回值为已连接设备列表的地址。 23919e95205Sopenharmony_ci 24019e95205Sopenharmony_ci - 限制条件: 24119e95205Sopenharmony_ci 24219e95205Sopenharmony_ci - 必须有已连接的设备。 24319e95205Sopenharmony_ci - @throws { BusinessError } 201 - Permission denied. 24419e95205Sopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 24519e95205Sopenharmony_ci * @throws { BusinessError } 2900001 - Service stopped. 24619e95205Sopenharmony_ci * @throws { BusinessError } 2900003 - Bluetooth switch is off. 24719e95205Sopenharmony_ci * @throws { BusinessError } 2900004 - Profile is not supported. 24819e95205Sopenharmony_ci - @throws { BusinessError } 2900099 - Operation failed. 24919e95205Sopenharmony_ci 25019e95205Sopenharmony_ci - 验证方法:查看返回值。 25119e95205Sopenharmony_ci 25219e95205Sopenharmony_ci 25319e95205Sopenharmony_ci 25419e95205Sopenharmony_ci- getDeviceState 25519e95205Sopenharmony_ci 25619e95205Sopenharmony_ci - 使用指导:获取设备的配置文件状态,device为蓝牙设备的地址,返回值为{连接配置文件的连接状态} 25719e95205Sopenharmony_ci 25819e95205Sopenharmony_ci - 限制条件: 25919e95205Sopenharmony_ci 26019e95205Sopenharmony_ci - 有连接的配置文件 26119e95205Sopenharmony_ci - @throws { BusinessError } 201 - Permission denied. 26219e95205Sopenharmony_ci - @throws { BusinessError } 401 - Invalid parameter. 26319e95205Sopenharmony_ci - @throws { BusinessError } 801 - Capability not supported. 26419e95205Sopenharmony_ci - @throws { BusinessError } 2900001 - Service stopped. 26519e95205Sopenharmony_ci - @throws { BusinessError } 2900003 - Bluetooth switch is off. 26619e95205Sopenharmony_ci - @throws { BusinessError } 2900004 - Profile is not supported. 26719e95205Sopenharmony_ci - @throws { BusinessError } 2900099 - Operation failed. 26819e95205Sopenharmony_ci 26919e95205Sopenharmony_ci - 验证方法:查看返回值。 27019e95205Sopenharmony_ci 27119e95205Sopenharmony_ci 27219e95205Sopenharmony_ci 27319e95205Sopenharmony_ci- connect 27419e95205Sopenharmony_ci 27519e95205Sopenharmony_ci - 使用指导:使用a2dp连接到设备。device为要连接的远程设备的地址。如果连接正在进行,返回值为true;否则返回 false。 27619e95205Sopenharmony_ci 27719e95205Sopenharmony_ci 27819e95205Sopenharmony_ci - 限制条件: 27919e95205Sopenharmony_ci 28019e95205Sopenharmony_ci - 之前未成功连接。 28119e95205Sopenharmony_ci - @throws { BusinessError } 201 - Permission denied. 28219e95205Sopenharmony_ci * @throws { BusinessError } 401 - Invalid parameter. 28319e95205Sopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 28419e95205Sopenharmony_ci * @throws { BusinessError } 2900001 - Service stopped. 28519e95205Sopenharmony_ci * @throws { BusinessError } 2900003 - Bluetooth switch is off. 28619e95205Sopenharmony_ci * @throws { BusinessError } 2900004 - Profile is not supported. 28719e95205Sopenharmony_ci - @throws { BusinessError } 2900099 - Operation failed. 28819e95205Sopenharmony_ci 28919e95205Sopenharmony_ci 29019e95205Sopenharmony_ci - 验证方法:查看连接的播放设备是否正常使用。 29119e95205Sopenharmony_ci 29219e95205Sopenharmony_ci 29319e95205Sopenharmony_ci 29419e95205Sopenharmony_ci 29519e95205Sopenharmony_ci- disconnect 29619e95205Sopenharmony_ci 29719e95205Sopenharmony_ci - 使用指导:用a2dp断开与设备的连接。device为要断开连接的远程设备的地址。如果正在断开连接,则返回true;否则返回 false。 29819e95205Sopenharmony_ci 29919e95205Sopenharmony_ci - 限制条件: 30019e95205Sopenharmony_ci 30119e95205Sopenharmony_ci - 已成功连接。 30219e95205Sopenharmony_ci - @throws { BusinessError } 201 - Permission denied. 30319e95205Sopenharmony_ci * @throws { BusinessError } 401 - Invalid parameter. 30419e95205Sopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 30519e95205Sopenharmony_ci * @throws { BusinessError } 2900001 - Service stopped. 30619e95205Sopenharmony_ci * @throws { BusinessError } 2900003 - Bluetooth switch is off. 30719e95205Sopenharmony_ci * @throws { BusinessError } 2900004 - Profile is not supported. 30819e95205Sopenharmony_ci * @throws { BusinessError } 2900099 - Operation failed. 30919e95205Sopenharmony_ci 31019e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否还可以使用。 31119e95205Sopenharmony_ci 31219e95205Sopenharmony_ci 31319e95205Sopenharmony_ci 31419e95205Sopenharmony_ci- getPlayingState 31519e95205Sopenharmony_ci 31619e95205Sopenharmony_ci - 使用指导:获取设备的播放状态。device为远程设备的地址。返回值为远程设备的播放状态。 31719e95205Sopenharmony_ci - 限制条件: 31819e95205Sopenharmony_ci - 已成功连接。 31919e95205Sopenharmony_ci - @throws { BusinessError } 401 - Invalid parameter. 32019e95205Sopenharmony_ci * @throws { BusinessError } 801 - Capability not supported. 32119e95205Sopenharmony_ci * @throws { BusinessError } 2900001 - Service stopped. 32219e95205Sopenharmony_ci * @throws { BusinessError } 2900003 - Bluetooth switch is off. 32319e95205Sopenharmony_ci * @throws { BusinessError } 2900004 - Profile is not supported. 32419e95205Sopenharmony_ci * @throws { BusinessError } 2900099 - Operation failed. 32519e95205Sopenharmony_ci - 验证方法:查看之前连接的播放设备是否正常播放。 326