FR55512: Support for multiple A2DP Streams
Change the active device management policy when multi-A2DP
streams feature is enabled.
Disable the Absolute Volume feature dynamically when
multi-A2DP streams are ongoing.
CRs-Fixed: 2541910
Change-Id: I4f829f42a7e9724408332ad58425ebaa732d3bf9
Signed-off-by: Liuliu Zhao <liulzhao@codeaurora.org>
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java
index fd23784..b232568 100755
--- a/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -72,6 +72,7 @@
private static A2dpService sA2dpService;
private static A2dpSinkService sA2dpSinkService;
private static boolean mA2dpSrcSnkConcurrency;
+ private static boolean a2dpMulticast = false;
private AdapterService mAdapterService;
private HandlerThread mStateMachinesThread;
@@ -285,6 +286,10 @@
if (DBG) {
Log.d(TAG, "A2DP concurrency mode set to " + mA2dpSrcSnkConcurrency);
}
+ a2dpMulticast = SystemProperties.getBoolean("persist.vendor.service.bt.a2dp_multicast_enable", false);
+ if (DBG) {
+ Log.d(TAG, "A2DP Multicast flag set to " + a2dpMulticast);
+ }
return true;
}
@@ -978,8 +983,11 @@
Log.e(TAG,"adapterService is null");
}
}
- if (mAvrcp_ext != null && !tws_switch) {
- mAvrcp_ext.setAbsVolumeFlag(device);
+ // Don't update the absVolume flags when disconnect one device in multicast mode
+ if (!a2dpMulticast || previousActiveDevice == null) {
+ if (mAvrcp_ext != null && !tws_switch) {
+ mAvrcp_ext.setAbsVolumeFlag(device);
+ }
}
tws_switch = false;
return true;
@@ -1072,6 +1080,18 @@
}
}
+ public void storeDeviceAudioVolume(BluetoothDevice device) {
+ if (device != null)
+ {
+ if (AvrcpTargetService.get() != null) {
+ AvrcpTargetService.get().storeVolumeForDevice(device);
+ } else if (mAvrcp_ext != null) {
+ //store volume in multi-a2dp for the device doesn't set as active
+ mAvrcp_ext.storeVolumeForDevice(device);
+ }
+ }
+ }
+
public void resetAvrcpBlacklist(BluetoothDevice device) {
synchronized(mBtAvrcpLock) {
if (mAvrcp_ext != null) {
diff --git a/src/com/android/bluetooth/btservice/ActiveDeviceManager.java b/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
old mode 100644
new mode 100755
index da9cb11..17b9100
--- a/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
+++ b/src/com/android/bluetooth/btservice/ActiveDeviceManager.java
@@ -33,6 +33,7 @@
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
+import android.os.SystemProperties;
import android.util.Log;
import com.android.bluetooth.a2dp.A2dpService;
@@ -125,6 +126,8 @@
private BluetoothDevice mHfpActiveDevice = null;
private BluetoothDevice mHearingAidActiveDevice = null;
private boolean mTwsPlusSwitch = false;
+ private static boolean a2dpMulticast = false;
+
// Broadcast receiver for all changes
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@@ -214,8 +217,19 @@
mA2dpConnectedDevices.add(device);
if (mHearingAidActiveDevice == null) {
// New connected device: select it as active
- setA2dpActiveDevice(device);
- break;
+ if (!a2dpMulticast) {
+ setA2dpActiveDevice(device);
+ }
+ else {
+ if (mA2dpActiveDevice == null) {
+ setA2dpActiveDevice(device);
+ }
+ else {
+ // store the volume for the new added device
+ final A2dpService a2dpService = mFactory.getA2dpService();
+ a2dpService.storeDeviceAudioVolume(device);
+ }
+ }
}
break;
}
@@ -245,8 +259,18 @@
Log.d(TAG, "Resetting mTwsPlusSwitch");
mTwsPlusSwitch = false;
}
+ else if (a2dpMulticast && !mA2dpConnectedDevices.isEmpty()) {
+ for (BluetoothDevice connected_device: mA2dpConnectedDevices) {
+ if (mA2dpService.getConnectionState(connected_device) ==
+ BluetoothProfile.STATE_CONNECTED) {
+ Log.d(TAG, "a2dp Multicast calling set a2dp Active dev: " + connected_device);
+ mDevice = connected_device;
+ break;
+ }
+ }
+ }
if (!setA2dpActiveDevice(mDevice) && (mDevice != null) &&
- mAdapterService.isTwsPlusDevice(mDevice)) {
+ (mAdapterService.isTwsPlusDevice(mDevice) || a2dpMulticast)) {
Log.w(TAG, "Switch A2dp active device to peer earbud failed");
setA2dpActiveDevice(null);
}
@@ -292,7 +316,7 @@
break; // The device is already connected
}
mHfpConnectedDevices.add(device);
- if (mHearingAidActiveDevice == null) {
+ if ((!a2dpMulticast || mHfpActiveDevice == null) && mHearingAidActiveDevice == null) {
// New connected device: select it as active
setHfpActiveDevice(device);
break;
@@ -332,7 +356,23 @@
"as there is no Connected TWS+ peer");
setHfpActiveDevice(null);
}
- } else {
+ } else if (a2dpMulticast && !mHfpConnectedDevices.isEmpty()) {
+ if (hfpService == null) {
+ Log.e(TAG, "no headsetService, FATAL");
+ return;
+ }
+ for (BluetoothDevice connected_device: mHfpConnectedDevices) {
+ if (hfpService.getConnectionState(connected_device) ==
+ BluetoothProfile.STATE_CONNECTED) {
+ Log.d(TAG, "a2dp Multicast calling set HFP Active dev: " + connected_device);
+ if (!setHfpActiveDevice(connected_device)) {
+ setHfpActiveDevice(null);
+ }
+ break;
+ }
+ }
+ }
+ else {
setHfpActiveDevice(null);
}
}
@@ -442,6 +482,7 @@
mAdapterService.registerReceiver(mReceiver, filter);
mAudioManager.registerAudioDeviceCallback(mAudioManagerAudioDeviceCallback, mHandler);
+ a2dpMulticast = SystemProperties.getBoolean("persist.vendor.service.bt.a2dp_multicast_enable", false);
}
void cleanup() {