HFP: Allow SCO audio to be forcibly connected
* Normally, Android only allows SCO audio to be connected in several
allowed cases (e.g. in call, in ringing, in virtual call state, etc)
* Sometimes, it is necessary to force a SCO audio connection (e.g.
during PTS test)
* This change adds setForceScoAudio(boolean) hidden, system only method
to allow such behaviour
Bug: 38040125
Test: PTS HFP tests
Change-Id: I28f295c98da5bebb837c2a5423c7acde81af73f7
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index 2d25659..c31a9b2 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -767,6 +767,28 @@
}
/**
+ * Force SCO audio to be opened regardless any other restrictions
+ *
+ * @param forced Whether or not SCO audio connection should be forced:
+ * True to force SCO audio
+ * False to use SCO audio in normal manner
+ * @hide
+ */
+ public void setForceScoAudio(boolean forced) {
+ if (VDBG) log("setForceScoAudio " + String.valueOf(forced));
+ if (mService != null && isEnabled()) {
+ try {
+ mService.setForceScoAudio(forced);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString());
+ }
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
+ }
+ }
+
+ /**
* Check if Bluetooth SCO audio is connected.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
diff --git a/core/java/android/bluetooth/IBluetoothHeadset.aidl b/core/java/android/bluetooth/IBluetoothHeadset.aidl
index 6ad442b..6bd0d7f 100755
--- a/core/java/android/bluetooth/IBluetoothHeadset.aidl
+++ b/core/java/android/bluetooth/IBluetoothHeadset.aidl
@@ -52,6 +52,7 @@
boolean disconnectAudio();
void setAudioRouteAllowed(boolean allowed);
boolean getAudioRouteAllowed();
+ void setForceScoAudio(boolean forced);
boolean startScoUsingVirtualVoiceCall(in BluetoothDevice device);
boolean stopScoUsingVirtualVoiceCall(in BluetoothDevice device);
void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type);