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 <zengjing@xiaomi.com>
1 file changed