summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-11-10 09:02:07 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-11-10 09:02:07 +0000
commit3c29fee689e9fbf0a159d401fe13d8f425de5eda (patch)
tree67aa1c5ad88b16f8322b32af07c12307a35470e6
parentf9fadba02702054b799e8d52942a217cbe0cb46c (diff)
parent2cd1bf6a8db689adbd85797a27089edba936440e (diff)
downloadBluetooth-3c29fee689e9fbf0a159d401fe13d8f425de5eda.tar.gz
Merge "Improve A2DP autoreconnect policy"
-rw-r--r--src/com/android/bluetooth/btservice/PhonePolicy.java4
-rw-r--r--tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java14
2 files changed, 16 insertions, 2 deletions
diff --git a/src/com/android/bluetooth/btservice/PhonePolicy.java b/src/com/android/bluetooth/btservice/PhonePolicy.java
index 44bdd0f95..94a53553f 100644
--- a/src/com/android/bluetooth/btservice/PhonePolicy.java
+++ b/src/com/android/bluetooth/btservice/PhonePolicy.java
@@ -387,7 +387,9 @@ class PhonePolicy {
connectOtherProfile(device);
}
if (nextState == BluetoothProfile.STATE_DISCONNECTED) {
- if (profileId == BluetoothProfile.A2DP) {
+ if (profileId == BluetoothProfile.A2DP
+ && (prevState == BluetoothProfile.STATE_CONNECTING
+ || prevState == BluetoothProfile.STATE_DISCONNECTING)) {
mDatabaseManager.setDisconnection(device);
}
handleAllProfilesDisconnected(device);
diff --git a/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java b/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
index 0b3d2bb5e..557a72023 100644
--- a/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
+++ b/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java
@@ -233,7 +233,7 @@ public class PhonePolicyTest {
verify(mDatabaseManager, never()).setConnection(eq(connectionOrder.get(2)), anyBoolean());
verify(mDatabaseManager, never()).setConnection(eq(connectionOrder.get(3)), anyBoolean());
- // Disconnect a2dp for the device
+ // Disconnect a2dp for the device from previous STATE_CONNECTED
when(mHeadsetService.getConnectionState(connectionOrder.get(1))).thenReturn(
BluetoothProfile.STATE_DISCONNECTED);
intent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
@@ -244,6 +244,18 @@ public class PhonePolicyTest {
mPhonePolicy.getBroadcastReceiver().onReceive(null /* context */, intent);
waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
+ // Verify that we do not call setConnection, nor setDisconnection on disconnect
+ // from previous STATE_CONNECTED
+ verify(mDatabaseManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).setConnection(
+ connectionOrder.get(1), true);
+ verify(mDatabaseManager, never()).setDisconnection(connectionOrder.get(1));
+
+ // Disconnect a2dp for the device from previous STATE_DISCONNECTING
+ intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE,
+ BluetoothProfile.STATE_DISCONNECTING);
+ mPhonePolicy.getBroadcastReceiver().onReceive(null /* context */, intent);
+ waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
+
// Verify that we do not call setConnection, but instead setDisconnection on disconnect
verify(mDatabaseManager, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).setConnection(
connectionOrder.get(1), true);