OSDN Git Service

Updating Force Use toggling for Communication use case
authorJohan Gustavsson <johan1.gustavsson.x@sonymobile.com>
Fri, 1 Mar 2013 14:53:30 +0000 (15:53 +0100)
committerEric Laurent <elaurent@google.com>
Wed, 21 Aug 2013 16:35:20 +0000 (09:35 -0700)
setForceUse toggling is shaky when toggling either through
setSpeakerphoneOn and setBluetoothScoOn. Depending on call sequence
an application may unintentionally trigger a routing use case it
does not want.
The main root cause is that neither of these calls take the
previous state into account. A call to setSpeakerPhoneOn will for
example partly disable any active BT SCO routing.

Change-Id: I436ee5a8da2d9ea5a2e4e89eec083c8118a5ff7e

media/java/android/media/AudioService.java

index 3478007..5b6749d 100644 (file)
@@ -1912,7 +1912,16 @@ public class AudioService extends IAudioService.Stub {
         if (!checkAudioSettingsPermission("setSpeakerphoneOn()")) {
             return;
         }
-        mForcedUseForComm = on ? AudioSystem.FORCE_SPEAKER : AudioSystem.FORCE_NONE;
+
+        if (on) {
+            if (mForcedUseForComm == AudioSystem.FORCE_BT_SCO) {
+                    sendMsg(mAudioHandler, MSG_SET_FORCE_USE, SENDMSG_QUEUE,
+                            AudioSystem.FOR_RECORD, AudioSystem.FORCE_NONE, null, 0);
+            }
+            mForcedUseForComm = AudioSystem.FORCE_SPEAKER;
+        } else if (mForcedUseForComm == AudioSystem.FORCE_SPEAKER){
+            mForcedUseForComm = AudioSystem.FORCE_NONE;
+        }
 
         sendMsg(mAudioHandler, MSG_SET_FORCE_USE, SENDMSG_QUEUE,
                 AudioSystem.FOR_COMMUNICATION, mForcedUseForComm, null, 0);
@@ -1928,7 +1937,12 @@ public class AudioService extends IAudioService.Stub {
         if (!checkAudioSettingsPermission("setBluetoothScoOn()")) {
             return;
         }
-        mForcedUseForComm = on ? AudioSystem.FORCE_BT_SCO : AudioSystem.FORCE_NONE;
+
+        if (on) {
+            mForcedUseForComm = AudioSystem.FORCE_BT_SCO;
+        } else if (mForcedUseForComm == AudioSystem.FORCE_BT_SCO) {
+            mForcedUseForComm = AudioSystem.FORCE_NONE;
+        }
 
         sendMsg(mAudioHandler, MSG_SET_FORCE_USE, SENDMSG_QUEUE,
                 AudioSystem.FOR_COMMUNICATION, mForcedUseForComm, null, 0);