Loading android/app/src/com/android/bluetooth/a2dp/A2dpService.java +21 −15 Original line number Diff line number Diff line Loading @@ -439,11 +439,9 @@ public class A2dpService extends ProfileService { private void removeActiveDevice(boolean forceStopPlayingAudio) { BluetoothDevice previousActiveDevice = mActiveDevice; synchronized (mStateMachines) { // Clear the active device mActiveDevice = null; // This needs to happen before we inform the audio manager that the device // disconnected. Please see comment in broadcastActiveDevice() for why. broadcastActiveDevice(null); // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why. updateAndBroadcastActiveDevice(null); if (previousActiveDevice == null) { return; Loading Loading @@ -483,10 +481,6 @@ public class A2dpService extends ProfileService { Log.d(TAG, "setActiveDevice(" + device + "): previous is " + previousActiveDevice); } if (previousActiveDevice != null && AvrcpTargetService.get() != null) { AvrcpTargetService.get().storeVolumeForDevice(previousActiveDevice); } if (device == null) { // Remove active device and continue playing audio only if necessary. removeActiveDevice(false); Loading @@ -512,10 +506,9 @@ public class A2dpService extends ProfileService { codecStatus = sm.getCodecStatus(); boolean deviceChanged = !Objects.equals(device, mActiveDevice); mActiveDevice = device; // This needs to happen before we inform the audio manager that the device // disconnected. Please see comment in broadcastActiveDevice() for why. broadcastActiveDevice(mActiveDevice); // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why. updateAndBroadcastActiveDevice(device); if (deviceChanged) { // Send an intent with the active device codec config if (codecStatus != null) { Loading @@ -538,8 +531,6 @@ public class A2dpService extends ProfileService { int rememberedVolume = -1; if (AvrcpTargetService.get() != null) { AvrcpTargetService.get().volumeDeviceSwitched(mActiveDevice); rememberedVolume = AvrcpTargetService.get() .getRememberedVolumeForDevice(mActiveDevice); } Loading Loading @@ -839,9 +830,24 @@ public class A2dpService extends ProfileService { } } private void broadcastActiveDevice(BluetoothDevice device) { // This needs to run before any of the Audio Manager connection functions since // AVRCP needs to be aware that the audio device is changed before the Audio Manager // changes the volume of the output devices. private void updateAndBroadcastActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "broadcastActiveDevice(" + device + ")"); Log.d(TAG, "updateAndBroadcastActiveDevice(" + device + ")"); } synchronized (mStateMachines) { if (AvrcpTargetService.get() != null) { if (mActiveDevice != null) { AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice); } AvrcpTargetService.get().volumeDeviceSwitched(device); } mActiveDevice = device; } Intent intent = new Intent(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED); Loading android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +2 −2 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { volumeMapEditor.apply(); } void storeVolumeForDevice(BluetoothDevice device) { synchronized void storeVolumeForDevice(BluetoothDevice device) { SharedPreferences.Editor pref = getVolumeMap().edit(); int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); Log.i(TAG, "storeVolume: Storing stream volume level for device " + device Loading @@ -128,7 +128,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { pref.apply(); } int getVolume(@NonNull BluetoothDevice device, int defaultValue) { synchronized int getVolume(@NonNull BluetoothDevice device, int defaultValue) { if (!mVolumeMap.containsKey(device)) { Log.w(TAG, "getVolume: Couldn't find volume preference for device: " + device); return defaultValue; Loading Loading
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +21 −15 Original line number Diff line number Diff line Loading @@ -439,11 +439,9 @@ public class A2dpService extends ProfileService { private void removeActiveDevice(boolean forceStopPlayingAudio) { BluetoothDevice previousActiveDevice = mActiveDevice; synchronized (mStateMachines) { // Clear the active device mActiveDevice = null; // This needs to happen before we inform the audio manager that the device // disconnected. Please see comment in broadcastActiveDevice() for why. broadcastActiveDevice(null); // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why. updateAndBroadcastActiveDevice(null); if (previousActiveDevice == null) { return; Loading Loading @@ -483,10 +481,6 @@ public class A2dpService extends ProfileService { Log.d(TAG, "setActiveDevice(" + device + "): previous is " + previousActiveDevice); } if (previousActiveDevice != null && AvrcpTargetService.get() != null) { AvrcpTargetService.get().storeVolumeForDevice(previousActiveDevice); } if (device == null) { // Remove active device and continue playing audio only if necessary. removeActiveDevice(false); Loading @@ -512,10 +506,9 @@ public class A2dpService extends ProfileService { codecStatus = sm.getCodecStatus(); boolean deviceChanged = !Objects.equals(device, mActiveDevice); mActiveDevice = device; // This needs to happen before we inform the audio manager that the device // disconnected. Please see comment in broadcastActiveDevice() for why. broadcastActiveDevice(mActiveDevice); // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why. updateAndBroadcastActiveDevice(device); if (deviceChanged) { // Send an intent with the active device codec config if (codecStatus != null) { Loading @@ -538,8 +531,6 @@ public class A2dpService extends ProfileService { int rememberedVolume = -1; if (AvrcpTargetService.get() != null) { AvrcpTargetService.get().volumeDeviceSwitched(mActiveDevice); rememberedVolume = AvrcpTargetService.get() .getRememberedVolumeForDevice(mActiveDevice); } Loading Loading @@ -839,9 +830,24 @@ public class A2dpService extends ProfileService { } } private void broadcastActiveDevice(BluetoothDevice device) { // This needs to run before any of the Audio Manager connection functions since // AVRCP needs to be aware that the audio device is changed before the Audio Manager // changes the volume of the output devices. private void updateAndBroadcastActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "broadcastActiveDevice(" + device + ")"); Log.d(TAG, "updateAndBroadcastActiveDevice(" + device + ")"); } synchronized (mStateMachines) { if (AvrcpTargetService.get() != null) { if (mActiveDevice != null) { AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice); } AvrcpTargetService.get().volumeDeviceSwitched(device); } mActiveDevice = device; } Intent intent = new Intent(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED); Loading
android/app/src/com/android/bluetooth/avrcp/AvrcpVolumeManager.java +2 −2 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { volumeMapEditor.apply(); } void storeVolumeForDevice(BluetoothDevice device) { synchronized void storeVolumeForDevice(BluetoothDevice device) { SharedPreferences.Editor pref = getVolumeMap().edit(); int storeVolume = mAudioManager.getStreamVolume(STREAM_MUSIC); Log.i(TAG, "storeVolume: Storing stream volume level for device " + device Loading @@ -128,7 +128,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback { pref.apply(); } int getVolume(@NonNull BluetoothDevice device, int defaultValue) { synchronized int getVolume(@NonNull BluetoothDevice device, int defaultValue) { if (!mVolumeMap.containsKey(device)) { Log.w(TAG, "getVolume: Couldn't find volume preference for device: " + device); return defaultValue; Loading