问题点:蓝牙耳机听音乐过程,插入再拔出有线耳机,音乐不从蓝牙耳机发出
代码路径:
packages/apps/Bluetooth/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
a/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
+++ b/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
@@ -110,12 +110,13 @@ class ActiveDeviceManager {
private static final int MESSAGE_HFP_ACTION_CONNECTION_STATE_CHANGED = 4;
private static final int MESSAGE_HFP_ACTION_ACTIVE_DEVICE_CHANGED = 5;
private static final int MESSAGE_HEARING_AID_ACTION_ACTIVE_DEVICE_CHANGED = 6;
-
+ private static final int MESSAGE_DELAY_ENTER_A2DP_ACTIVE_DEVICE= 7;
private final AdapterService mAdapterService;
private final ServiceFactory mFactory;
private HandlerThread mHandlerThread = null;
private Handler mHandler = null;
private final AudioManager mAudioManager;
+ private int volume ;
private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback;
private final List<BluetoothDevice> mA2dpConnectedDevices = new LinkedList<>();
@@ -320,6 +321,13 @@ class ActiveDeviceManager {
}
}
break;
+ case MESSAGE_DELAY_ENTER_A2DP_ACTIVE_DEVICE: {
+ Log.d(TAG, "MESSAGE_DELAY_ENTER_A2DP_ACTIVE_DEVICE ");
+ setA2dpActiveDevice();
+ mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
+ }
+ break;
+
}
}
}
@@ -361,6 +369,21 @@ class ActiveDeviceManager {
@Override
public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
+ Log.d(TAG, "onAudioDevicesRemoved() isWiredHeadsetOn " +mAudioManager.isWiredHeadsetOn());
+ if (mAudioManager.isWiredHeadsetOn()) {
+ return;
+ }
+
+ for (AudioDeviceInfo device : removedDevices) {
+ Log.d(TAG, "onAudioDevicesRemoved: removedDevices: " + device.getType()+" isWiredAudioHeadset "+ isWiredAudioHeadset(devi
ce));
+ if (isWiredAudioHeadset(device)) {
+ volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
+ mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
+ mHandler.removeMessages(MESSAGE_DELAY_ENTER_A2DP_ACTIVE_DEVICE);
+ mHandler.sendEmptyMessageDelayed(MESSAGE_DELAY_ENTER_A2DP_ACTIVE_DEVICE,1000);
+ break;
+ }
+ }
}
}
@@ -368,6 +391,7 @@ class ActiveDeviceManager {
mAdapterService = service;
mFactory = factory;
mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
+ volume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mAudioManagerAudioDeviceCallback = new AudioManagerAudioDeviceCallback();
}
@@ -433,6 +457,15 @@ class ActiveDeviceManager {
}
mA2dpActiveDevice = device;
}
+
+ private void setA2dpActiveDevice() {
+ Log.d(TAG, "setA2dpActiveDevice()");
+ if (mA2dpActiveDevice == null && !mA2dpConnectedDevices.isEmpty()) {
+ int prevActiveDeviceIndex = mA2dpConnectedDevices.size() - 1;
+ BluetoothDevice prevActiveDevice = mA2dpConnectedDevices.get(prevActiveDeviceIndex);
+ setA2dpActiveDevice(prevActiveDevice);
+ }
+ }
private void setHfpActiveDevice(BluetoothDevice device) {
原文地址:https://blog.csdn.net/wq892373445/article/details/125113108
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_15881.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。