Loading android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +76 −42 Original line number Diff line number Diff line Loading @@ -255,9 +255,27 @@ class ActiveDeviceManager { // Lazy active A2DP if it is not being used. // This will prevent the deactivation of LE audio // earlier than the activation of HFP. if (!isMediaMode(mAudioManager.getMode()) && mHfpActiveDevice == null) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: break; case AudioManager.MODE_RINGTONE: { HeadsetService headsetService = mFactory.getHeadsetService(); if (mHfpActiveDevice == null && headsetService != null && headsetService.isInbandRingingEnabled()) { mPendingA2dpActiveDevice = device; } break; } case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: { if (mHfpActiveDevice == null) { mPendingA2dpActiveDevice = device; } } } if (mPendingA2dpActiveDevice == null) { // select the device as active if not lazy active setA2dpActiveDevice(device); Loading Loading @@ -328,9 +346,21 @@ class ActiveDeviceManager { // Lazy active HFP if it is not being used. // This will prevent the deactivation of LE audio // earlier than the activation of A2DP. if (isMediaMode(mAudioManager.getMode()) && mA2dpActiveDevice == null) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: if (mA2dpActiveDevice == null) { mPendingHfpActiveDevice = device; } break; case AudioManager.MODE_RINGTONE: { HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService == null || !headsetService.isInbandRingingEnabled()) { mPendingHfpActiveDevice = device; } break; } } if (mPendingHfpActiveDevice == null) { // select the device as active if not lazy active setHfpActiveDevice(device); Loading Loading @@ -592,16 +622,34 @@ class ActiveDeviceManager { private class AudioManagerOnModeChangedListener implements AudioManager.OnModeChangedListener { public void onModeChanged(int mode) { if (isMediaMode(mode)) { switch (mode) { case AudioManager.MODE_NORMAL: { if (mPendingA2dpActiveDevice != null) { setA2dpActiveDevice(mPendingA2dpActiveDevice); setLeAudioActiveDevice(null, true); } } else { break; } case AudioManager.MODE_RINGTONE: { final HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService != null && headsetService.isInbandRingingEnabled() && mPendingHfpActiveDevice != null) { setHfpActiveDevice(mPendingHfpActiveDevice); setLeAudioActiveDevice(null); } break; } case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: { if (mPendingHfpActiveDevice != null) { setHfpActiveDevice(mPendingHfpActiveDevice); setLeAudioActiveDevice(null); } break; } } } } Loading Loading @@ -809,25 +857,6 @@ class ActiveDeviceManager { } } private boolean isMediaMode(int mode) { switch (mode) { case AudioManager.MODE_RINGTONE: final HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService != null && headsetService.isInbandRingingEnabled()) { return false; } return true; case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: return false; default: return true; } } private boolean setFallbackDeviceActive() { if (DBG) { Log.d(TAG, "setFallbackDeviceActive"); Loading Loading @@ -882,20 +911,25 @@ class ActiveDeviceManager { List<BluetoothDevice> connectedDevices = new ArrayList<>(); connectedDevices.addAll(mLeAudioConnectedDevices); boolean isMediaMode = isMediaMode(mAudioManager.getMode()); if (isMediaMode) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: if (a2dpFallbackDevice != null) { connectedDevices.add(a2dpFallbackDevice); } } else { break; case AudioManager.MODE_RINGTONE: if (headsetFallbackDevice != null && headsetService.isInbandRingingEnabled()) { connectedDevices.add(headsetFallbackDevice); } break; default: if (headsetFallbackDevice != null) { connectedDevices.add(headsetFallbackDevice); } } BluetoothDevice device = dbManager.getMostRecentlyConnectedDevicesInList(connectedDevices); if (device != null) { if (isMediaMode) { if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) { if (Objects.equals(a2dpFallbackDevice, device)) { if (DBG) { Log.d(TAG, "set A2DP device active: " + device); Loading Loading
android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +76 −42 Original line number Diff line number Diff line Loading @@ -255,9 +255,27 @@ class ActiveDeviceManager { // Lazy active A2DP if it is not being used. // This will prevent the deactivation of LE audio // earlier than the activation of HFP. if (!isMediaMode(mAudioManager.getMode()) && mHfpActiveDevice == null) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: break; case AudioManager.MODE_RINGTONE: { HeadsetService headsetService = mFactory.getHeadsetService(); if (mHfpActiveDevice == null && headsetService != null && headsetService.isInbandRingingEnabled()) { mPendingA2dpActiveDevice = device; } break; } case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: { if (mHfpActiveDevice == null) { mPendingA2dpActiveDevice = device; } } } if (mPendingA2dpActiveDevice == null) { // select the device as active if not lazy active setA2dpActiveDevice(device); Loading Loading @@ -328,9 +346,21 @@ class ActiveDeviceManager { // Lazy active HFP if it is not being used. // This will prevent the deactivation of LE audio // earlier than the activation of A2DP. if (isMediaMode(mAudioManager.getMode()) && mA2dpActiveDevice == null) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: if (mA2dpActiveDevice == null) { mPendingHfpActiveDevice = device; } break; case AudioManager.MODE_RINGTONE: { HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService == null || !headsetService.isInbandRingingEnabled()) { mPendingHfpActiveDevice = device; } break; } } if (mPendingHfpActiveDevice == null) { // select the device as active if not lazy active setHfpActiveDevice(device); Loading Loading @@ -592,16 +622,34 @@ class ActiveDeviceManager { private class AudioManagerOnModeChangedListener implements AudioManager.OnModeChangedListener { public void onModeChanged(int mode) { if (isMediaMode(mode)) { switch (mode) { case AudioManager.MODE_NORMAL: { if (mPendingA2dpActiveDevice != null) { setA2dpActiveDevice(mPendingA2dpActiveDevice); setLeAudioActiveDevice(null, true); } } else { break; } case AudioManager.MODE_RINGTONE: { final HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService != null && headsetService.isInbandRingingEnabled() && mPendingHfpActiveDevice != null) { setHfpActiveDevice(mPendingHfpActiveDevice); setLeAudioActiveDevice(null); } break; } case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: { if (mPendingHfpActiveDevice != null) { setHfpActiveDevice(mPendingHfpActiveDevice); setLeAudioActiveDevice(null); } break; } } } } Loading Loading @@ -809,25 +857,6 @@ class ActiveDeviceManager { } } private boolean isMediaMode(int mode) { switch (mode) { case AudioManager.MODE_RINGTONE: final HeadsetService headsetService = mFactory.getHeadsetService(); if (headsetService != null && headsetService.isInbandRingingEnabled()) { return false; } return true; case AudioManager.MODE_IN_CALL: case AudioManager.MODE_IN_COMMUNICATION: case AudioManager.MODE_CALL_SCREENING: case AudioManager.MODE_CALL_REDIRECT: case AudioManager.MODE_COMMUNICATION_REDIRECT: return false; default: return true; } } private boolean setFallbackDeviceActive() { if (DBG) { Log.d(TAG, "setFallbackDeviceActive"); Loading Loading @@ -882,20 +911,25 @@ class ActiveDeviceManager { List<BluetoothDevice> connectedDevices = new ArrayList<>(); connectedDevices.addAll(mLeAudioConnectedDevices); boolean isMediaMode = isMediaMode(mAudioManager.getMode()); if (isMediaMode) { switch (mAudioManager.getMode()) { case AudioManager.MODE_NORMAL: if (a2dpFallbackDevice != null) { connectedDevices.add(a2dpFallbackDevice); } } else { break; case AudioManager.MODE_RINGTONE: if (headsetFallbackDevice != null && headsetService.isInbandRingingEnabled()) { connectedDevices.add(headsetFallbackDevice); } break; default: if (headsetFallbackDevice != null) { connectedDevices.add(headsetFallbackDevice); } } BluetoothDevice device = dbManager.getMostRecentlyConnectedDevicesInList(connectedDevices); if (device != null) { if (isMediaMode) { if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) { if (Objects.equals(a2dpFallbackDevice, device)) { if (DBG) { Log.d(TAG, "set A2DP device active: " + device); Loading