summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Pawłowski <jpawlowski@google.com> 2024-03-29 07:26:00 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-03-29 07:26:00 +0000
commit2eae98e51f42b8fb3d40497aafa4eebeec68144b (patch)
tree5faaabfbd27ca6899585fd398f5493954663b335
parenteb97eb0bfb57157c385c7ee34ab783e87df6f370 (diff)
parentc7ec30211550650f43bf68d057337e168397ddb8 (diff)
Merge "LeAudioService: Make device inactive on "no available contexts"" into main
-rw-r--r--android/app/src/com/android/bluetooth/le_audio/LeAudioService.java43
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java85
2 files changed, 120 insertions, 8 deletions
diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java
index a96b53f78b..df4df1db6a 100644
--- a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java
+++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java
@@ -2205,7 +2205,7 @@ public class LeAudioService extends ProfileService {
+ groupId
+ " is inactivated due to blocked media context");
groupDescriptor.mInactivatedDueToContextType = true;
- setActiveGroupWithDevice(null, true);
+ setActiveGroupWithDevice(null, false);
}
}
default:
@@ -2729,16 +2729,45 @@ public class LeAudioService extends ProfileService {
BluetoothLeAudio.GROUP_STATUS_INACTIVE);
}
}
+ boolean availableContextChanged =
+ Integer.bitCount(descriptor.mAvailableContexts)
+ != Integer.bitCount(available_contexts);
+
descriptor.mDirection = direction;
descriptor.mAvailableContexts = available_contexts;
updateInbandRingtoneForTheGroup(groupId);
- boolean mediaIsAvailable =
- ((descriptor.mAvailableContexts & BluetoothLeAudio.CONTEXT_TYPE_MEDIA)
- != 0);
+ if (!availableContextChanged) {
+ Log.d(
+ TAG,
+ " Context did not changed for "
+ + groupId
+ + ": "
+ + descriptor.mAvailableContexts);
+ return;
+ }
+
+ if (descriptor.mAvailableContexts == 0) {
+ if (descriptor.mIsActive) {
+ Log.i(
+ TAG,
+ " Inactivating group "
+ + groupId
+ + " due to unavailable context types");
+ descriptor.mInactivatedDueToContextType = true;
+ setActiveGroupWithDevice(null, false);
+ }
+ return;
+ }
- if (descriptor.mInactivatedDueToContextType && mediaIsAvailable) {
- Log.i(TAG, " Media context type again available for " + groupId);
+ if (descriptor.mInactivatedDueToContextType) {
+ Log.i(
+ TAG,
+ " Some context got available again for "
+ + groupId
+ + ", try it out: "
+ + descriptor.mAvailableContexts);
+ descriptor.mInactivatedDueToContextType = false;
setActiveGroupWithDevice(getLeadDeviceForTheGroup(groupId), true);
}
} else {
@@ -3236,6 +3265,7 @@ public class LeAudioService extends ProfileService {
if (getConnectedPeerDevices(groupId).isEmpty()) {
descriptor.mIsConnected = false;
+ descriptor.mInactivatedDueToContextType = false;
if (descriptor.mIsActive) {
/* Notify Native layer */
removeActiveDevice(hasFallbackDevice);
@@ -3316,6 +3346,7 @@ public class LeAudioService extends ProfileService {
if (getConnectedPeerDevices(deviceDescriptor.mGroupId).isEmpty()) {
descriptor.mIsConnected = false;
+ descriptor.mInactivatedDueToContextType = false;
if (descriptor.mIsActive) {
/* Notify Native layer */
removeActiveDevice(hasFallbackDevice);
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
index 8b8b10056a..1ece09496f 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java
@@ -1250,9 +1250,9 @@ public class LeAudioServiceTest {
doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class));
connectTestDevice(mSingleDevice, testGroupId);
- // Add location support
+ // Add location support
LeAudioStackEvent audioConfChangedEvent =
- new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
+ new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
audioConfChangedEvent.device = mSingleDevice;
audioConfChangedEvent.valueInt1 = direction;
audioConfChangedEvent.valueInt2 = groupId;
@@ -2495,4 +2495,85 @@ public class LeAudioServiceTest {
assertThat(mService.getActiveDevices().contains(mSingleDevice)).isTrue();
assertThat(mService.sendPreferredAudioProfileChangeToAudioFramework()).isEqualTo(2);
}
+
+ @Test
+ public void testInactivateDeviceWhenNoAvailableContextTypes() {
+ int groupId = 1;
+ /* AUDIO_DIRECTION_OUTPUT_BIT = 0x01 */
+ int direction = 1;
+ int snkAudioLocation = 3;
+ int srcAudioLocation = 4;
+ int availableContexts = 5 + BluetoothLeAudio.CONTEXT_TYPE_RINGTONE;
+
+ doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class));
+ connectTestDevice(mLeftDevice, groupId);
+ connectTestDevice(mRightDevice, groupId);
+
+ // Checks group device lists for groupId 1
+ List<BluetoothDevice> groupDevicesById = mService.getGroupDevices(groupId);
+
+ assertThat(groupDevicesById.size()).isEqualTo(2);
+ assertThat(groupDevicesById.contains(mLeftDevice)).isTrue();
+ assertThat(groupDevicesById.contains(mRightDevice)).isTrue();
+
+ // Add location support
+ LeAudioStackEvent audioConfChangedEvent =
+ new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_AUDIO_CONF_CHANGED);
+ audioConfChangedEvent.valueInt1 = direction;
+ audioConfChangedEvent.valueInt2 = groupId;
+ audioConfChangedEvent.valueInt3 = snkAudioLocation;
+ audioConfChangedEvent.valueInt4 = srcAudioLocation;
+ audioConfChangedEvent.valueInt5 = availableContexts;
+ mService.messageFromNative(audioConfChangedEvent);
+
+ assertThat(mService.setActiveDevice(mLeftDevice)).isTrue();
+ verify(mNativeInterface).groupSetActive(groupId);
+
+ // Set group and device as active.
+ injectGroupStatusChange(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);
+ verify(mAudioManager, times(1))
+ .handleBluetoothActiveDeviceChanged(
+ any(BluetoothDevice.class),
+ eq(null),
+ any(BluetoothProfileConnectionInfo.class));
+
+ reset(mAudioManager);
+ reset(mNativeInterface);
+
+ /* Don't expect any change. */
+ mService.messageFromNative(audioConfChangedEvent);
+ verify(mNativeInterface, times(0)).groupSetActive(groupId);
+ reset(mNativeInterface);
+
+ /* Expect device to be incactive */
+ audioConfChangedEvent.valueInt5 = 0;
+ mService.messageFromNative(audioConfChangedEvent);
+
+ verify(mNativeInterface, times(1)).groupSetActive(-1);
+ injectGroupStatusChange(groupId, LeAudioStackEvent.GROUP_STATUS_INACTIVE);
+
+ verify(mAudioManager, times(1))
+ .handleBluetoothActiveDeviceChanged(
+ eq(null),
+ any(BluetoothDevice.class),
+ any(BluetoothProfileConnectionInfo.class));
+
+ reset(mNativeInterface);
+ reset(mAudioManager);
+
+ /* Expect device to be incactive */
+ audioConfChangedEvent.valueInt5 = 1;
+ mService.messageFromNative(audioConfChangedEvent);
+
+ verify(mNativeInterface).groupSetActive(groupId);
+ reset(mNativeInterface);
+
+ // Set group and device as active.
+ injectGroupStatusChange(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);
+ verify(mAudioManager, times(1))
+ .handleBluetoothActiveDeviceChanged(
+ any(BluetoothDevice.class),
+ eq(null),
+ any(BluetoothProfileConnectionInfo.class));
+ }
}