Loading android/app/src/com/android/bluetooth/a2dp/A2dpService.java +42 −25 Original line number Diff line number Diff line Loading @@ -166,8 +166,13 @@ public class A2dpService extends ProfileService { return true; } // Step 9: Clear active device setActiveDevice(null); // Step 10: Store volume if there is an active device if (mActiveDevice != null && AvrcpTargetService.get() != null) { AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice); } // Step 9: Clear active device and stop playing audio removeActiveDevice(true); // Step 8: Mark service as stopped setA2dpService(null); Loading Loading @@ -425,6 +430,39 @@ 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); if (previousActiveDevice == null) { return; } // Make sure the Audio Manager knows the previous Active device is disconnected. // However, if A2DP is still connected and not forcing stop audio for that remote // device, the user has explicitly switched the output to the local device and music // should continue playing. Otherwise, the remote device has been indeed disconnected // and audio should be suspended before switching the output to the local device. boolean suppressNoisyIntent = !forceStopPlayingAudio && (getConnectionState(previousActiveDevice) == BluetoothProfile.STATE_CONNECTED); Log.i(TAG, "removeActiveDevice: suppressNoisyIntent=" + suppressNoisyIntent); mAudioManager.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent( previousActiveDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP, suppressNoisyIntent, -1); // Make sure the Active device in native layer is set to null and audio is off if (!mA2dpNativeInterface.setActiveDevice(null)) { Log.w(TAG, "setActiveDevice(null): Cannot remove active device in native " + "layer"); } } } /** * Set the active device. * Loading @@ -444,29 +482,8 @@ public class A2dpService extends ProfileService { } if (device == null) { // 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); if (previousActiveDevice != null) { // Make sure the Audio Manager knows the previous Active device is disconnected. // However, if A2DP is still connected for that remote device, the user has // explicitly switched the output to the local device and music should // continue playing. Otherwise, the remote device has been indeed disconnected, // and audio should be suspended before switching the output to the local // device. mAudioManager.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent( previousActiveDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP, getConnectionState(previousActiveDevice) == BluetoothProfile.STATE_CONNECTED, -1); // Make sure the Active device in native layer is set to null and audio is off if (!mA2dpNativeInterface.setActiveDevice(null)) { Log.w(TAG, "setActiveDevice(null): Cannot remove active device in native " + "layer"); } } // Remove active device and continue playing audio only if necessary. removeActiveDevice(false); return true; } Loading Loading
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +42 −25 Original line number Diff line number Diff line Loading @@ -166,8 +166,13 @@ public class A2dpService extends ProfileService { return true; } // Step 9: Clear active device setActiveDevice(null); // Step 10: Store volume if there is an active device if (mActiveDevice != null && AvrcpTargetService.get() != null) { AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice); } // Step 9: Clear active device and stop playing audio removeActiveDevice(true); // Step 8: Mark service as stopped setA2dpService(null); Loading Loading @@ -425,6 +430,39 @@ 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); if (previousActiveDevice == null) { return; } // Make sure the Audio Manager knows the previous Active device is disconnected. // However, if A2DP is still connected and not forcing stop audio for that remote // device, the user has explicitly switched the output to the local device and music // should continue playing. Otherwise, the remote device has been indeed disconnected // and audio should be suspended before switching the output to the local device. boolean suppressNoisyIntent = !forceStopPlayingAudio && (getConnectionState(previousActiveDevice) == BluetoothProfile.STATE_CONNECTED); Log.i(TAG, "removeActiveDevice: suppressNoisyIntent=" + suppressNoisyIntent); mAudioManager.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent( previousActiveDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP, suppressNoisyIntent, -1); // Make sure the Active device in native layer is set to null and audio is off if (!mA2dpNativeInterface.setActiveDevice(null)) { Log.w(TAG, "setActiveDevice(null): Cannot remove active device in native " + "layer"); } } } /** * Set the active device. * Loading @@ -444,29 +482,8 @@ public class A2dpService extends ProfileService { } if (device == null) { // 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); if (previousActiveDevice != null) { // Make sure the Audio Manager knows the previous Active device is disconnected. // However, if A2DP is still connected for that remote device, the user has // explicitly switched the output to the local device and music should // continue playing. Otherwise, the remote device has been indeed disconnected, // and audio should be suspended before switching the output to the local // device. mAudioManager.setBluetoothA2dpDeviceConnectionStateSuppressNoisyIntent( previousActiveDevice, BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP, getConnectionState(previousActiveDevice) == BluetoothProfile.STATE_CONNECTED, -1); // Make sure the Active device in native layer is set to null and audio is off if (!mA2dpNativeInterface.setActiveDevice(null)) { Log.w(TAG, "setActiveDevice(null): Cannot remove active device in native " + "layer"); } } // Remove active device and continue playing audio only if necessary. removeActiveDevice(false); return true; } Loading