TWS_AVRCP: Fix for safe volume not sent to earbud
When multiple devices are connected along with TWS+ earbuds, and
streaming over earbuds with volume above threshold. One of the
earbuds is disconnected while still streaming to earubds or it is
disconnected after switching streaming to other headset. Upon
reconnection of disconnected earbud, this fix ensures stream
volume to be switched to threshold volume.
Change-Id: I5968be68ecf3e78ae2020aa330921536512ab61f
diff --git a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
index 77ad9fc..444f94d 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
@@ -363,7 +363,7 @@
private int mBlackListVolume;
private int mLastPassthroughcmd;
private int mReportedPlayerID;
-
+ private boolean mTwsPairDisconnected;
public DeviceDependentFeature(Context context) {
mContext = context;
mCurrentDevice = null;
@@ -406,6 +406,7 @@
mLastRspPlayStatus = -1;
mLastPassthroughcmd = KeyEvent.KEYCODE_UNKNOWN;
mReportedPlayerID = NO_PLAYER_ID;
+ mTwsPairDisconnected = false;
}
};
DeviceDependentFeature[] deviceFeatures;
@@ -1156,11 +1157,19 @@
if (i != deviceIndex && deviceFeatures[i].mCurrentDevice != null &&
deviceFeatures[i].mInitialRemoteVolume != -1 &&
isTwsPlusPair(conn_dev, device)) {
- Log.v(TAG,"volume already set for tws pair");
- deviceFeatures[deviceIndex].mInitialRemoteVolume = absVol;
- deviceFeatures[deviceIndex].mRemoteVolume = absVol;
- deviceFeatures[deviceIndex].mLocalVolume = convertToAudioStreamVolume(absVol);
- break;
+ Log.v(TAG,"TWS+ pair found at index " + i +
+ "mTwsPairDisconnected = " + deviceFeatures[i].mTwsPairDisconnected);
+ if (deviceFeatures[i].mTwsPairDisconnected) {
+ Log.v(TAG,"TWS+ pair was disconnected earlier");
+ Log.v(TAG,"TWS+ store this volume");
+ deviceFeatures[i].mTwsPairDisconnected = false;
+ } else {
+ Log.v(TAG,"volume already set for tws pair");
+ deviceFeatures[deviceIndex].mInitialRemoteVolume = absVol;
+ deviceFeatures[deviceIndex].mRemoteVolume = absVol;
+ deviceFeatures[deviceIndex].mLocalVolume = convertToAudioStreamVolume(absVol);
+ break;
+ }
}
}
}
@@ -3307,6 +3316,8 @@
isTwsPlusPair(device,deviceFeatures[i].mCurrentDevice )) {
Log.i(TAG,"TWS+ pair got disconnected,update absVolume");
updateAbsVolume = true;
+ Log.i(TAG,"TWS+ pair disconnected, set mTwsPairDisconnected for index " + i);
+ deviceFeatures[i].mTwsPairDisconnected = true;
}
}
}
@@ -5005,12 +5016,22 @@
}
public void setActiveDevice(BluetoothDevice device) {
+ boolean tws_switch = false;
if (device == null) {
for (int i = 0; i < maxAvrcpConnections; i++) {
deviceFeatures[i].isActiveDevice = false;
}
return;
}
+ if (device != null && device.isTwsPlusDevice()) {
+ for (int i = 0; i < maxAvrcpConnections; i++) {
+ if (deviceFeatures[i].mCurrentDevice != null &&
+ deviceFeatures[i].isActiveDevice &&
+ deviceFeatures[i].mCurrentDevice.isTwsPlusDevice()) {
+ tws_switch = true;
+ }
+ }
+ }
int deviceIndex = getIndexForDevice(device);
if (deviceIndex == INVALID_DEVICE_INDEX) {
Log.e(TAG,"Invalid device index for setActiveDevice");
@@ -5038,6 +5059,10 @@
updateAbsVolume = false;
}
}
+ if (device.isTwsPlusDevice() && !tws_switch) {
+ Log.d(TAG,"Restting mTwsPairDisconnected at index " + deviceIndex);
+ deviceFeatures[deviceIndex].mTwsPairDisconnected = false;
+ }
if (maxAvrcpConnections > 1) {
for (int i = 0; i < maxAvrcpConnections; i++) {
if (deviceIndex != i && deviceFeatures[i].mCurrentDevice != null &&