蓝牙耳机图标显示过程
来源:互联网 发布:数据分析制图软件 编辑:程序博客网 时间:2024/05/01 22:42
蓝牙耳机图标显示代码路径在:
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/
在PhoneStatusBarPolicy.java中的函数
private final void updateBluetooth(Intent intent) {
inticonId = R.drawable.stat_sys_data_bluetooth;
String contentDescription = null;
String action = intent.getAction();
if(action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,BluetoothAdapter.ERROR);
mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
}else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
BluetoothAdapter.STATE_DISCONNECTED);
if (state == BluetoothAdapter.STATE_CONNECTED) {
iconId = R.drawable.stat_sys_data_bluetooth_connected;
contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
}else {
contentDescription = mContext.getString(
R.string.accessibility_bluetooth_disconnected);
}
}else {
return;
}
mService.setIcon("bluetooth",iconId, 0, contentDescription);
mService.setIconVisibility("bluetooth", mBluetoothEnabled);
}
通过 updateBluetooth这个函数可以看到,蓝牙耳机的图标是根据广播 ACTION_CONNECTION_STATE_CHANGED来判断的。
下面我们来看一看广播ACTION_CONNECTION_STATE_CHANGED是如何发送的,
代码路径在:
packages/apps/Bluetooth/src/com/android/bluetooth/btservice
在AdapterProperties.java中的函数
void sendConnectionStateChange(BluetoothDevicedevice, int profile, int state, int prevState) {
......
synchronized (mObject) {
updateProfileConnectionState(profile,state, prevState);
if (updateCountersAndCheckForConnectionStateChange(state, prevState)) {
setConnectionState(state);
Intent intent = new Intent(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
convertToAdapterState(state));
intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_CONNECTION_STATE,
convertToAdapterState(prevState));
......
}
}
}
通过函数 sendConnectionStateChange来看广播的发送是由 updateCountersAndCheckForConnectionStateChange()函数的返回值决定的。
private booleanupdateCountersAndCheckForConnectionStateChange(int state, int prevState) {
switch (prevState) {
case BluetoothProfile.STATE_CONNECTING:
mProfilesConnecting--;
break;
case BluetoothProfile.STATE_CONNECTED:
mProfilesConnected--;
break;
case BluetoothProfile.STATE_DISCONNECTING:
mProfilesDisconnecting--;
break;
}
switch (state) {
case BluetoothProfile.STATE_CONNECTING:
mProfilesConnecting++;
return (mProfilesConnected == 0 && mProfilesConnecting == 1);
case BluetoothProfile.STATE_CONNECTED:
mProfilesConnected++;
return (mProfilesConnected == 1);
case BluetoothProfile.STATE_DISCONNECTING:
mProfilesDisconnecting++;
return (mProfilesConnected == 0 && mProfilesDisconnecting == 1);
case BluetoothProfile.STATE_DISCONNECTED:
return (mProfilesConnected == 0 && mProfilesConnecting == 0);
default:
return true;
}
}
通过updateCountersAndCheckForConnectionStateChange来看,mProfilesConnecting、mProfilesConnected、mProfilesDisconnecting这三个变量满足一定的条件函数返回才为TRUE。而这三个变量会根据连蓝耳机上次状态和当前状态的进行加减。
蓝牙耳机图标显示过程:
蓝牙耳机的连接分为Headset Profile 和A2DP Profile两个Profile,连接的时候只要有一个连接上就会返回TRUE,发送广播,从而显示蓝牙耳机图标,而断开连接的时候只有两个都断开了才会返回TRUE,发送广播,显示蓝牙普通图标。
- 蓝牙耳机图标显示过程
- 连接蓝牙耳机过程
- 蓝牙耳机电量显示
- Android状态栏显示蓝牙耳机电量
- android2.1状态栏显示耳机图标
- android2.1状态栏显示耳机图标
- Android 7.1.1 插入耳机图标显示
- 蓝牙耳机
- 蓝牙耳机
- 蓝牙耳机
- 蓝牙耳机
- 慢慢插入耳机只显示耳机图标,不显示mic图标
- BugFix 2:状态栏显示耳机插拔图标
- 使用蓝牙耳机
- 蓝牙耳机复位
- 蓝牙耳机录音
- windows10连接蓝牙耳机
- iOS 蓝牙耳机切换
- gettext制作多语言程序之如何确定mo文件的目录名(简体繁体中文、英文、西班牙语言、俄语)
- MyEclipse10安装Svn插件的几种方法
- Android源码解析四大组件系列(三)---Activity启动过程之ActivityThread是如何运行起来的
- C#《飞机大战》游戏开发之细节总结
- centos7装机与基础配置
- 蓝牙耳机图标显示过程
- 基于Docker搭建一个Go-ethereum节点(上)
- mysql报there can be only one auto column的问题原因
- POJ
- 【Mybatis】深入浅出Mybatis(四)——入门程序(查询)
- 五种单例模式
- js实现在字符串中提取数字 和字母
- ThinkPHP项目总结
- 标志FLAG_ACTIVITY_NEW_TASK的解释