Android BluetoothHeadset

一、BluetoothHeadset介绍

用于控制蓝牙头戴式耳机服务。这包括蓝牙耳机和免提(HFP),主要实现拨打、接听、挂断电话(AG侧、HF侧)、切换声道功能。

AG(Audio Gate)音频网关—音频设备输入输出网关 。

HF(Hands Free)免提—该设备作为音频网关的远程音频输入/输出机制,并可提供若干遥控功能。

在车载蓝牙中,手机侧是AG,车载蓝牙侧是HF,在android源代码中,将AG侧称为HFP/AG,将HF侧称为HFPClient/HF。

HFP(Hands-Free Profile)是一种蓝牙协议,它允许蓝牙设备(如手机)与车载音响等设备进行通信,从而实现免提通话。HFP协议定义了一组指令和过程,用于在蓝牙设备之间建立语音通信。HFP协议支持多种语音编解码器,包括CVSD(连续可变斜率差分编码)和mSBC(分帧逐次逼近编码)。HFP协议还支持来电显示、呼叫转移、通话保持和多路通话等功能。在HFP协议中,有两种角色:Hands-Free(HF)和Audio Gateway(AG)。HF是指支持免提通话的设备,如车载音响;AG是指支持蓝牙通信的设备,如手机。当HF和AG之间建立蓝牙连接时,它们会协商使用哪种语音编解码器,并且HF可以向AG发送指令,如呼叫、接听、挂断等。总之,HFP协议是一种非常实用的蓝牙协议,它使得人们可以在驾驶时更加安全地进行通话。

BluetoothHeadset构造图

如下为Bluetooth HFP构造图:

BluetoothHeadset协议栈

如下为Bluetooth HFP协议栈

二、Bluetooth HFP相关接口

IBluetoothHeadset

API for Bluetooth Headset service

IBluetoothHeadset代码位于:

packages/modules/Bluetooth/system/binder/android/bluetooth/IBluetoothHeadset.aidl

IBluetoothHeadset的定义:

interface IBluetoothHeadset {}

IBluetoothHeadset API:

List<BluetoothDevice> getConnectedDevices();
oneway void getConnectedDevicesWithAttribution(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
int getConnectionState(in BluetoothDevice device); 
oneway void getConnectionStateWithAttribution(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void startVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void stopVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void isAudioConnected(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void sendVendorSpecificResultCode(in BluetoothDevice device, in String command, in String arg, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
boolean connect(in BluetoothDevice device);
oneway void connectWithAttribution(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
boolean disconnect(in BluetoothDevice device);
oneway void disconnectWithAttribution(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void getAudioState(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void isAudioOn(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void connectAudio(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void disconnectAudio(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void setAudioRouteAllowed(boolean allowed, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void getAudioRouteAllowed(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void setForceScoAudio(boolean forced, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void startScoUsingVirtualVoiceCall(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void stopScoUsingVirtualVoiceCall(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type, String name, in AttributionSource attributionSource);
oneway void clccResponse(int index, int direction, int status, int mode, boolean mpty, String number, int type, in AttributionSource attributionSource, in SynchronousResultReceiver receiver
oneway void setActiveDevice(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void getActiveDevice(in AttributionSource attributionSource, in SynchronousResultReceiver receiver)
oneway void isInbandRingingEnabled(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void isNoiseReductionSupported(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
oneway void isVoiceRecognitionSupported(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);

IBluetoothHeadsetClient

API for Bluetooth Headset Client service (HFP HF Role)

蓝牙头戴式耳机客户端服务的 API(HFP HF 角色)

IBluetoothHeadsetClient代码位于:

packages/modules/Bluetooth/system/binder/android/bluetooth/IBluetoothHeadsetClient.aidl

IBluetoothHeadsetClient的定义:

oneway interface IBluetoothHeadsetClient {}

IBluetoothHeadsetClient API:

void connect(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void disconnect(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getConnectedDevices(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void startVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void stopVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getCurrentCalls(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getCurrentAgEvents(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void acceptCall(in BluetoothDevice device, int flag, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void holdCall(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void rejectCall(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void terminateCall(in BluetoothDevice device, in BluetoothHeadsetClientCall call, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void enterPrivateMode(in BluetoothDevice device, int index, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void explicitCallTransfer(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void dial(in BluetoothDevice device, String number, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void sendDTMF(in BluetoothDevice device, byte code, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getLastVoiceTagNumber(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getAudioState(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void connectAudio(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void disconnectAudio(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void setAudioRouteAllowed(in BluetoothDevice device, boolean allowed, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getAudioRouteAllowed(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void sendVendorAtCommand(in BluetoothDevice device, int vendorId, String atCommand, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);
void getCurrentAgFeatures(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver);

三、Bluetooth HFP相关类

BluetoothInCallService

BluetoothInCallService是一个系统级别的服务,它负责管理蓝牙电话的呼叫状态。它提供了一个接口,允许其他应用程序与蓝牙电话进行交互。当蓝牙电话的呼叫状态发生变化时,BluetoothInCallService会向HeadSetService发送通知,以便HeadSetService可以更新其状态并通知蓝牙设备。在引用中,BluetoothHeadsetBinder是HeadSetService的内部Binder接口的本地实现,它负责接收外部的调用信息,包括来自BluetoothInCallService的通话状态改变的通知。在引用中,如果蓝牙电话的呼叫状态发生变化,BluetoothInCallService会调用mBluetoothHeadset.phoneStateChanged()方法,传入更新后的参数值,以便HeadSetService可以更新其状态并通知蓝牙设备。

BluetoothInCallService代码位于:

packages/modules/Bluetooth/android/app/srv/com/android/bluetooth/telephony/BluetoothInCallService.java

BluetoothInCallService的定义:

public class BluetoothInCallService extends InCallService {
    public class BluetoothAdapterReceiver extends BroadcastReceiver {}
    public class CallStateCallback extends Call.Callback {}
}

BluetoothHeadset

Public API for controlling the Bluetooth Headset Service. This includes both Bluetooth Headset and Handsfree (v1.5) profiles.

用于控制蓝牙头戴式耳机服务的公共 API。这包括蓝牙耳机和免提 (v1.5) 配置文件。

BluetoothHeadset代码位于:

packages/modules/Bluetooth/framework/java/android/bluetooth/BluetoothHeadset.java

BluetoothHeadset的定义:

public final class BluetoothHeadset implements BluetoothProfile {}

如下为BluetoothHeadset常用API:

boolean connect(BluetoothDevice device):连接
boolean disconnect(BluetoothDevice device):断开
public boolean setPriority(BluetoothDevice device, int priority) :设置权限
boolean setConnectionPolicy(@NonNull BluetoothDevice device, @ConnectionPolicy int connectionPolicy):设置连接策略
int getPriority(BluetoothDevice device):获取权限
@ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device):设置协议连接策略
List<BluetoothDevice> getConnectedDevices():获取此连接设备列表,可以获取连接了HFP协议的当前设备实例
int getConnectionState(BluetoothDevice device):获取当前连接状态
@GetAudioStateReturnValues int getAudioState(@NonNull BluetoothDevice device):获取当前音频状态
List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states):获取匹配任何给定连接状态的设备列表

BluetoothHeadsetClient

BluetoothHeadsetClient用于控制HFP客户端(蓝牙电话端)的公共API。简单而言,它是电话的操作代理,可以控制蓝牙HFP协议的连接断开、配置信息的查询、执行HFP协议特有操作等。

BluetoothHeadsetClient代码位于:

packages/modules/Bluetooth/framework/java/android/bluetooth/BluetoothHeadsetClient.java

BluetoothHeadsetClient的定义:

public final class BluetoothHeadsetClient implements BluetoothProfile, AutoCloseable {}

如下为BluetoothHeadsetClient常用API:

public boolean connect(BluetoothDevice device):连接
public boolean disconnect(BluetoothDevice device):断开
public @NonNull List<BluetoothDevice> getConnectedDevices() :获取连接设备列表,可以获取连接了HFP协议的当前设备实例
public @BtProfileState int getConnectionState(@NonNull BluetoothDevice device):获取当前HFP协议连接状态。
状态包括BluetoothPrifile.STATE_CONNECTED、BluetoothPrifile.STATE_CONNECTING、BluetoothPrifile.STATE_DISCONNECTED、BluetoothPrifile.STATE_DISCONNECTING四种。
public boolean setPriority(BluetoothDevice device, int priority) :设置权限。入参为需要设置的远端设备实例以及权限能力。
权限为 BluetoothHeadsetClient.PRIORITY_ON和BluetoothHeadsetClient.PRIORITY_OFF中的一种。
PRIORITY_ON:可以连接HFP。
PRIORITY_OFF:不可连接HFP。
public boolean setConnectionPolicy(@NonNull BluetoothDevice device, @ConnectionPolicy int connectionPolicy) :设置协议连接策略。入参为需设置的设备及连接策略。
连接策略为BluetoothProfile.CONNECTION_POLICY_ALLOWED, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN, BluetoothProfile.CONNECTION_POLICY_UNKNOWN中的一种。
CONNECTION_POLICY_ALLOWED:默认连接HFP
CONNECTION_POLICY_FORBIDDEN:默认不连接HFP
CONNECTION_POLICY_UNKNOWN:连接策略未知(设备没设置或设备未配对)
public List<BluetoothHeadsetClientCall> getCurrentCalls(BluetoothDevice device):获取当前正在通话的参数实例(封装在BluetoothHeadsetClientCall中)。由于可能存在多路通话,所以此处返回一个List。
public boolean sendVendorAtCommand(BluetoothDevice device, int vendorId, String atCommand) :发送供应商AT指令
public BluetoothHeadsetClientCall dial(BluetoothDevice device, String number):拨号方法。入参为设备实例以及有效的电话号码。
public boolean acceptCall(BluetoothDevice device, int flag) :蓝牙电话端接听电话方法。入参为连接的设备实例与接听时的操作策略标志。
BluetoothHeadsetClient.CALL_ACCEPT_NONE:正常接听(单路通话)
BluetoothHeadsetClient.CALL_ACCEPT_HOLD:应答且挂起(多路通话)
BluetoothHeadsetClient.CALL_ACCEPT_TERMINATE:接听且挂断(多路通话)
public boolean holdCall(BluetoothDevice device) :挂起当前通话(多路通话使用)。入参为设备实例
public boolean rejectCall(BluetoothDevice device) :拒接电话。入参为设备实例。仅当响铃状态是可拒接。拖已接听,需使用terminateCall方法来挂断电话。
public boolean terminateCall(BluetoothDevice device, BluetoothHeadsetClientCall call) :挂断电话。入参为设备实例与要挂断的电话参数实例(BluetoothHeadsetClientCall)。
仅当通话时使用该方法有效,若是响铃状态,则应使用rejectCall方法。电话参数实例传null则为挂断全部进行中的通话。
public boolean connectAudio(BluetoothDevice device):连接音频通道。入参为设备实例。
若音频通道连接,则通话时发声端为蓝牙电话端。若音频通道断开,则通话时发声端为手机端。
public boolean disconnectAudio(BluetoothDevice device) :断开音频通道。入参为设备实例。
若音频通道连接,则通话时发声端为蓝牙电话端。若音频通道断开,则通话时发声端为手机端。
public int getConnectionPolicy(@NonNull BluetoothDevice device):获取连接策略
public int getPriority(BluetoothDevice device):获取权限
public void setAudioRouteAllowed(BluetoothDevice device, boolean allowed):设置是否允许音频路由。
public Bundle getCurrentAgEvents(BluetoothDevice device) :获取信号强度

BluetoothHeadsetClientCall

BluetoothHeadsetClientCall用于表示蓝牙通话的状态和信息。它包含以下几个属性:

  1. state:通话状态,包括STATE_ACTIVE、STATE_HELD、STATE_DIALING、STATE_ALERTING、STATE_INCOMING、STATE_WAITING等。

  2. number:电话号码。

  3. type:电话类型,包括TYPE_VOICE、TYPE_FAX、TYPE_MODEM、TYPE_UNKNOWN等。

  4. name:电话名称。

  5. time:通话时间。

BluetoothHeadsetClientCall代码位于:

packages/modules/Bluetooth/framework/java/android/bluetooth/BluetoothHeadsetClientCall.java

BluetoothHeadsetClientCall的定义:

public final class BluetoothHeadsetClientCall implements Parcelable, Attributable {}

HeadsetService

HeadsetService是整个HeadsetProfile的核心所在,它继承自ProfileService,作为一个后台服务在一直运行。在本进程内,连接HeadSetNativeInterface和HeadsetStateMachine;对外部进程,通过实现Binder的本地接口,提供远程服务。它的主要作用是处理来自HeadSetNativeInterface的消息,并将其传递给HeadsetStateMachine进行处理。同时,它还实现了一个Binder接口,用于接收外部的调用信息。其中,BluetoothHeadsetBinder是HeadsetService内部Binder接口的本地实现,负责接收外部的调用信息。当接收到BluetoothInCallService发过来的通话状态改变的通知时,HeadsetService会调用phoneStateChanged()方法进行处理。

HeadsetService代码位于:

packages/modules/Bluetooth/android/app/srv/com/android/bluetooth/hfp/HeadsetService.java

HeadsetService的定义:

public class HeadsetService extends ProfileService {
    private static class BluetoothHeadsetBinder extends IBluetoothHeadset.Stub implements  IProfileServiceBinder {}
    class DialingOutTimeoutEvent implements Runnable {}
    class VoiceRecognitionTimeoutEvent implements Runnable {}
}

HeadsetClientService

HeadsetClientService是一个Android系统中的服务,它提供了与蓝牙耳机通信的功能。充当了BluetoothHeadsetClientBinder和HeadsetClientStateMachine之间的桥梁,将来自BluetoothHeadsetClientBinder的请求传递给HeadsetClientStateMachine进行处理,并将来自HeadsetClientStateMachine的响应传递回BluetoothHeadsetClientBinder。HeadsetClientService还提供了一些其他的功能,例如处理来自蓝牙耳机的电话呼叫和音频流等。

HeadsetService代码位于:

packages/modules/Bluetooth/android/app/src/com/android/bluetooth/hfp/HeadsetService.java

HeadsetService的定义:

public class HeadsetClientService extends ProfileService {
    private static class BluetoothHeadsetClientBinder extends IBluetoothHeadsetClient.Stub  implements IProfileServiceBinder {}
}

HeadsetStateMachine

HeadsetStateMachine是一个状态机,用于管理耳机设备的连接状态。它包含多个状态,例如连接中、已连接、断开连接等,并且可以根据不同的状态进行相应的操作。在状态机中,每个状态都有对应的处理方法,当状态发生变化时,状态机会自动调用相应的处理方法。通过这种方式,HeadsetStateMachine可以实现耳机设备的自动连接和断开连接等功能。

具体来说,HeadsetStateMachine是一个Android框架中的类,它继承自StateMachine类。在HeadsetStateMachine中,可以通过定义不同的状态和状态转换来实现不同的功能。例如,在连接耳机设备时,可以将状态设置为连接中,然后等待设备连接成功后再将状态设置为已连接。在断开连接时,可以将状态设置为断开连接中,然后等待设备断开连接后再将状态设置为已断开连接。

HeadsetStateMachine代码位于:

packages/modules/Bluetooth/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java

HeadsetStateMachine的定义:

public class HeadsetStateMachine extends StateMachine {
    class Disconnected extends HeadsetStateBase {}
    class Connecting extends HeadsetStateBase {}
    class Disconnecting extends HeadsetStateBase {}
    private abstract class ConnectedBase extends HeadsetStateBase {}
    class Connected extends ConnectedBase {}
    class AudioConnecting extends ConnectedBase {}
    class MyAudioServerStateCallback extends AudioManager.AudioServerStateCallback {}
    class AudioOn extends ConnectedBase {}
    class AudioDisconnecting extends ConnectedBase {}
}

HeadsetClientStateMachine

HeadsetClientStateMachine是一个状态机,它是Android中蓝牙耳机客户端的状态机。负责处理与蓝牙耳机相关的所有事件和状态转换。HeadsetClientStateMachine的状态转换是由BluetoothHeadsetClientService和BluetoothHeadsetClientBinder触发的。HeadsetClientStateMachine的状态转换是由BluetoothHeadsetClientService和BluetoothHeadsetClientBinder触发的。在状态转换期间,HeadsetClientStateMachine将调用不同的方法来处理不同的事件。例如,在Connected状态下,当收到StackEvent.EVENT_TYPE_CURRENT_CALLS事件时,HeadsetClientStateMachine将调用queryCallsUpdate()方法来处理此事件。

HeadsetClientStateMachine有如下子状态:

Disconnected:未连接状态

Connecting:连接中状态

Connected:连接状态

AudioOn:音频On状态

HeadsetClientStateMachine 代码位于:

packages/modules/Bluetooth/android/app/srv/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java

HeadsetClientStateMachine 的定义:

public class HeadsetClientStateMachine extends StateMachine {
    class Disconnected extends State {}
    class Connecting extends State {}
    class Connected extends State {}
    class AudioOn extends State {}
}

HeadsetClientHalConstants

HeadsetClientHalConstants代码位于:

packages/modules/Bluetooth/android/app/src/com/android/bluetooth/hfpclient/HeadsetClientHalConstants.java

HeadsetClientHalConstants的定义:

public final class HeadsetClientHalConstants {}

HfpClientCall

HfpClientCall是一个电话实体类信息。该类包含了电话的各种信息,例如电话号码、呼叫状态、通话时间等等。通过调用HfpClientCall的方法,可以获取相关信息。

HfpClientCall代码位于:

packages/modules/Bluetooth/android/app/src/com/android/bluetooth/hfpclient/connserv/HfpClientCall.java

HfpClientCall的定义:

public final class HfpClientCall implements Parcelable {}

HfpClientCall方法:

public void setState(int state):Sets call's state.
public void setNumber(String number):Sets call's number.
public void setMultiParty(boolean multiParty) :Sets this call as multi party call.
public BluetoothDevice getDevice() :Gets call's device.
public int getId() :Gets call's Id.
public UUID getUUID() :Gets call's UUID.
public int getState() :Gets call's current state.
public String getNumber() :Gets call's number.
public long getCreationElapsedMilli() :Gets call's creation time in millis since epoch.
public boolean isMultiParty() :Checks if call is an active call in a conference mode (aka multi party).
public boolean isOutgoing() :Checks if this call is an outgoing call.
public boolean isInBandRing() :Checks if the ringtone will be generated by the connected phone

NativeInterface

Defines native calls that are used by state machine/service to either send or receive messages to/from the native stack. This file is registered for the native methods in corresponding CPP file.

定义状态机/服务用于向蓝牙协议栈发送消息或从蓝牙协议栈接收消息的回调,是BT Framework与BT stack的沟通桥梁。

NativeInterface代码位于:

packages/modules/Bluetooth/android/app/srv/com/android/bluetooth/hfpclient/NativeInterface.java

NativeInterface的定义:

public class NativeInterface {}

方法如下:

public static NativeInterface getInstance():This class is a singleton because native library should only be loaded once
public void initialize():Initialize native stack
public void cleanup():Close and clean up native stack
public boolean connect(BluetoothDevice device):Connect to the specified paired device
public boolean disconnect(BluetoothDevice device) :Disconnect from the specified paired device
public boolean connectAudio(BluetoothDevice device):Initiate audio connection to the specified paired device
public boolean disconnectAudio(BluetoothDevice device) :Close audio connection from the specified paired device
public boolean startVoiceRecognition(BluetoothDevice device) :Initiate voice recognition to the specified paired device
public boolean stopVoiceRecognition(BluetoothDevice device) :Close voice recognition to the specified paired device
public boolean setVolume(BluetoothDevice device, int volumeType, int volume):Set volume to the specified paired device
public boolean dial(BluetoothDevice device, String number):dial number from the specified paired device
public boolean dialMemory(BluetoothDevice device, int location):Memory dialing from the specified paired device
public boolean handleCallAction(BluetoothDevice device, int action, int index):Apply action to call
public boolean queryCurrentCalls(BluetoothDevice device):Query current call status from the specified paired device
public boolean queryCurrentOperatorName(BluetoothDevice device) :Query operator name from the specified paired device
public  boolean retrieveSubscriberInfo(BluetoothDevice device) :Retrieve subscriber number from the specified paired device
public boolean sendDtmf(BluetoothDevice device, byte code) :Transmit DTMF code
public boolean requestLastVoiceTagNumber(BluetoothDevice device):Request last voice tag
public boolean sendATCmd(BluetoothDevice device, int atCmd, int val1, int val2, String arg):Send an AT command
private void onConnectionStateChanged(int state, int peerFeat, int chldFeat, byte[] address) 
private void onAudioStateChanged(int state, byte[] address)
private void onVrStateChanged(int state, byte[] address) 
private void onNetworkState(int state, byte[] address)
private void onNetworkRoaming(int state, byte[] address)
private void onNetworkSignal(int signal, byte[] address) 
private void onBatteryLevel(int level, byte[] address)
private void onCurrentOperator(String name, byte[] address)
private void onCall(int call, byte[] address)
private void onCallSetup(int callsetup, byte[] address):CIEV (Call indicators) notifying if call(s) are getting set up
private void onCallHeld(int callheld, byte[] address) :CIEV (Call indicators) notifying call held states.
private void onRespAndHold(int respAndHold, byte[] address) 
private void onClip(String number, byte[] address) 
private void onCallWaiting(String number, byte[] address)
private void onCurrentCalls(int index, int dir, int state, int mparty, String number, byte[] address) 
private void onVolumeChange(int type, int volume, byte[] address)
private void onCmdResult(int type, int cme, byte[] address) 
private void onSubscriberInfo(String number, int type, byte[] address) 
private void onInBandRing(int inBand, byte[] address) 
private void onLastVoiceTagNumber(String number, byte[] address)
private void onRingIndication(byte[] address)
private void onUnknownEvent(String eventString, byte[] address)

StackEvent

Defines an event that is sent via a callback from JNI -> Java.

定义通过 JNI -> Java 的回调发送的事件。

StackEvent代码位于:

packages/modules/Bluetooth/android/app/srv/com/android/bluetooth/hfpclient/StackEvent.java

StackEvent的定义:

public class StackEvent {}

回调事件如下:

public static final int EVENT_TYPE_NONE = 0;
public static final int EVENT_TYPE_CONNECTION_STATE_CHANGED = 1;
public static final int EVENT_TYPE_AUDIO_STATE_CHANGED = 2;
public static final int EVENT_TYPE_VR_STATE_CHANGED = 3;
public static final int EVENT_TYPE_NETWORK_STATE = 4;
public static final int EVENT_TYPE_ROAMING_STATE = 5;
public static final int EVENT_TYPE_NETWORK_SIGNAL = 6;
public static final int EVENT_TYPE_BATTERY_LEVEL = 7;
public static final int EVENT_TYPE_OPERATOR_NAME = 8;
public static final int EVENT_TYPE_CALL = 9;
public static final int EVENT_TYPE_CALLSETUP = 10;
public static final int EVENT_TYPE_CALLHELD = 11;
public static final int EVENT_TYPE_RESP_AND_HOLD = 12;
public static final int EVENT_TYPE_CLIP = 13;
public static final int EVENT_TYPE_CALL_WAITING = 14;
public static final int EVENT_TYPE_CURRENT_CALLS = 15;
public static final int EVENT_TYPE_VOLUME_CHANGED = 16;
public static final int EVENT_TYPE_CMD_RESULT = 17;
public static final int EVENT_TYPE_SUBSCRIBER_INFO = 18;
public static final int EVENT_TYPE_IN_BAND_RINGTONE = 19;
public static final int EVENT_TYPE_RING_INDICATION = 21;
public static final int EVENT_TYPE_UNKNOWN_EVENT = 22;

四、BluetoothHeadset流程分析

BluetoothHeadsetClient connect流程分析  

Android13 BluetoothHeadsetClient connect流程分析-CSDN博客

BluetoothHeadsetClient disconnect流程分析

Android13 BluetoothHeadsetClient disconnect流程分析-CSDN博客

BluetoothHeadsetClient dial流程分析

Android13 BluetoothHeadsetClient dial流程分析-CSDN博客

BluetoothHeadsetClient acceptCall流程分析

Android13 BluetoothHeadsetClient acceptCall流程分析-CSDN博客

BluetoothHeadsetClient rejectCall流程分析

Android13 BluetoothHeadsetClient rejectCall流程分析-CSDN博客

BluetoothHeadsetClient terminateCall流程分析

Android13 BluetoothHeadsetClient terminateCall流程分析-CSDN博客

BluetoothHeadset connectAudio流程分析

Android13 BluetoothHeadset connectAudio流程分析-CSDN博客

BluetoothHeadset disconnectAudio流程分析

Android13 BluetoothHeadset disconnectAudio流程分析-CSDN博客

  • 16
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值