AVRCP Controller State without Browsing
Some devices do not support Browsing over AVRCP and the playback state
of those devices was inconsistent on disconnection of the Control
channel. This change improves the consistency of the data reported via
the media_session.
Bug: 144013853
Test: atest AvrcpControllerStateMachineTest
Change-Id: I3ce26d76a81422d1e5af8b439d8bc1ab30d320dc
(cherry picked from commit 527da93c0bfa15a95b1de9b93cb9d955885af849)
Merged-In: I3ce26d76a81422d1e5af8b439d8bc1ab30d320dc
Change-Id: I1eeb1d3bd1c4dcb3bd14ba9c2851a9ad4aee6b61
diff --git a/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java b/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java
index ae94a4d..e3abc4d 100644
--- a/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java
+++ b/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java
@@ -223,7 +223,6 @@
mService.sBrowseTree.mRootNode.addChild(mBrowseTree.mRootNode);
BluetoothMediaBrowserService.notifyChanged(mService
.sBrowseTree.mRootNode);
- BluetoothMediaBrowserService.notifyChanged(mAddressedPlayer.getPlaybackState());
mBrowsingConnected = true;
}
@@ -233,12 +232,10 @@
mAddressedPlayer.updateCurrentTrack(null);
mBrowseTree.mNowPlayingNode.setCached(false);
BluetoothMediaBrowserService.notifyChanged(mBrowseTree.mNowPlayingNode);
- BluetoothMediaBrowserService.addressedPlayerChanged(null);
mService.sBrowseTree.mRootNode.removeChild(
mBrowseTree.mRootNode);
BluetoothMediaBrowserService.notifyChanged(mService
.sBrowseTree.mRootNode);
- BluetoothMediaBrowserService.trackChanged(null);
mBrowsingConnected = false;
}
@@ -299,6 +296,7 @@
@Override
public void enter() {
if (mMostRecentState == BluetoothProfile.STATE_CONNECTING) {
+ BluetoothMediaBrowserService.notifyChanged(mAddressedPlayer.getPlaybackState());
broadcastConnectionStateChanged(BluetoothProfile.STATE_CONNECTED);
BluetoothMediaBrowserService.addressedPlayerChanged(mSessionCallbacks);
} else {
@@ -712,6 +710,8 @@
@Override
public void enter() {
onBrowsingDisconnected();
+ BluetoothMediaBrowserService.trackChanged(null);
+ BluetoothMediaBrowserService.addressedPlayerChanged(null);
broadcastConnectionStateChanged(BluetoothProfile.STATE_DISCONNECTING);
transitionTo(mDisconnected);
}
diff --git a/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java b/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
index f8ab6bb..0ca9c2a 100644
--- a/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
+++ b/tests/unit/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachineTest.java
@@ -151,6 +151,10 @@
IsInstanceOf.instanceOf(AvrcpControllerStateMachine.Disconnected.class));
Assert.assertEquals(mAvrcpStateMachine.getState(), BluetoothProfile.STATE_DISCONNECTED);
verify(mAvrcpControllerService).removeStateMachine(eq(mAvrcpStateMachine));
+ MediaControllerCompat.TransportControls transportControls =
+ BluetoothMediaBrowserService.getTransportControls();
+ Assert.assertEquals(PlaybackStateCompat.STATE_ERROR,
+ BluetoothMediaBrowserService.getPlaybackState());
}
/**
@@ -159,6 +163,11 @@
@Test
public void testControlOnly() {
int numBroadcastsSent = setUpConnectedState(true, false);
+ MediaControllerCompat.TransportControls transportControls =
+ BluetoothMediaBrowserService.getTransportControls();
+ Assert.assertNotNull(transportControls);
+ Assert.assertEquals(PlaybackStateCompat.STATE_NONE,
+ BluetoothMediaBrowserService.getPlaybackState());
StackEvent event =
StackEvent.connectionStateChanged(false, false);
mAvrcpStateMachine.disconnect();
@@ -176,6 +185,8 @@
IsInstanceOf.instanceOf(AvrcpControllerStateMachine.Disconnected.class));
Assert.assertEquals(mAvrcpStateMachine.getState(), BluetoothProfile.STATE_DISCONNECTED);
verify(mAvrcpControllerService).removeStateMachine(eq(mAvrcpStateMachine));
+ Assert.assertEquals(PlaybackStateCompat.STATE_ERROR,
+ BluetoothMediaBrowserService.getPlaybackState());
}
/**
@@ -186,6 +197,8 @@
Assert.assertEquals(0, mAvrcpControllerService.sBrowseTree.mRootNode.getChildrenCount());
int numBroadcastsSent = setUpConnectedState(false, true);
Assert.assertEquals(1, mAvrcpControllerService.sBrowseTree.mRootNode.getChildrenCount());
+ Assert.assertEquals(PlaybackStateCompat.STATE_NONE,
+ BluetoothMediaBrowserService.getPlaybackState());
StackEvent event =
StackEvent.connectionStateChanged(false, false);
mAvrcpStateMachine.disconnect();
@@ -203,6 +216,10 @@
IsInstanceOf.instanceOf(AvrcpControllerStateMachine.Disconnected.class));
Assert.assertEquals(mAvrcpStateMachine.getState(), BluetoothProfile.STATE_DISCONNECTED);
verify(mAvrcpControllerService).removeStateMachine(eq(mAvrcpStateMachine));
+ MediaControllerCompat.TransportControls transportControls =
+ BluetoothMediaBrowserService.getTransportControls();
+ Assert.assertEquals(PlaybackStateCompat.STATE_ERROR,
+ BluetoothMediaBrowserService.getPlaybackState());
}
/**