From 452da339bd4737b55915f1c34ac1433330faec62 Mon Sep 17 00:00:00 2001 From: zengjing Date: Fri, 25 May 2018 11:15:20 +0800 Subject: [PATCH] Do not setForceUse when a2dp config without change When device connected with wired headset and without any bluetooth connection, APP may call MediaRouter to setForceUse to set FOR_MEDIA with FORCE_SPEAKER, then sound be output to SPEAKER. In this case, if setBluetoothA2dpOn(false) was called, FOR_MEDIA will be set with FORCE_NONE and sound be output to wird headset. The issue discussed above occurred on our device. We developed an FM radio APP. Beforce work, wired headset must be plugged in to be used as antennas. Then we setForceUse FOR_MEDIA to FORCE_SPEAKER, and audio stream was output to speaker. At this moment, if we play other sound (such as ScreenCapture sound), MediaRouterService will detected audio playbacked state changed. Because FM Audio was not monitor by AudioPlaybackMonitor, there was not any audio playback active. So, restoreBluetoothA2dp was called in the function of onAudioPlayerActiveStateChanged, which call AudioService.setBluetoothA2dpOn(false). As a result sound was switch to headset. There are two solutions to fix our issue. 1) Check a2dp state before setBluetoothA2dpOn in MediaRouterService::restoreBluetoothA2dp, if a2dp state does not change, setBluetoothA2dpOn should not be called 2) Check a2dp state before setForceUse in AudioService::setBluetoothA2dpOn, if a2dp state does not change, setForceUse should not be called Consdering that setBluetoothA2dpOn may be called by other method, we try to fix it with the second one. Test: NA Change-Id: I3a2e64e7d73d9aa9539176fea556feb433cb7211 Signed-off-by: zengjing --- services/core/java/com/android/server/audio/AudioService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 8399ee2107d2f..2fbd58bdb01a0 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -2986,6 +2986,9 @@ public class AudioService extends IAudioService.Stub .append(Binder.getCallingPid()).toString(); synchronized (mBluetoothA2dpEnabledLock) { + if (mBluetoothA2dpEnabled == on) { + return; + } mBluetoothA2dpEnabled = on; sendMsg(mAudioHandler, MSG_SET_FORCE_BT_A2DP_USE, SENDMSG_QUEUE, AudioSystem.FOR_MEDIA,