le_audio: Replace temporary context policy with direction for group
Patch replaces temporary context policy with group direction for LE
Audio devices.
Bug: 238143026
Tag: #feature
Test: atest BluetoothInstrumentationTests
Change-Id: Id36312ac3cb9743a6409a358564fcd93ac3655bb
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 c6d3b0f..fde3e07 100644
--- a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java
+++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java
@@ -93,6 +93,11 @@
private static LeAudioService sLeAudioService;
/**
+ * Indicates group audio support for none direction
+ */
+ private static final int AUDIO_DIRECTION_NONE = 0x00;
+
+ /**
* Indicates group audio support for input direction
*/
private static final int AUDIO_DIRECTION_INPUT_BIT = 0x01;
@@ -102,11 +107,6 @@
*/
private static final int AUDIO_DIRECTION_OUTPUT_BIT = 0x02;
- /*
- * Indicates no active contexts
- */
- private static final int ACTIVE_CONTEXTS_NONE = 0;
-
private AdapterService mAdapterService;
private DatabaseManager mDatabaseManager;
private HandlerThread mStateMachinesThread;
@@ -137,14 +137,14 @@
LeAudioGroupDescriptor() {
mIsConnected = false;
mIsActive = false;
- mActiveContexts = ACTIVE_CONTEXTS_NONE;
+ mDirection = AUDIO_DIRECTION_NONE;
mCodecStatus = null;
mLostLeadDeviceWhileStreaming = null;
}
public Boolean mIsConnected;
public Boolean mIsActive;
- public Integer mActiveContexts;
+ public Integer mDirection;
public BluetoothLeAudioCodecStatus mCodecStatus;
/* This can be non empty only for the streaming time */
BluetoothDevice mLostLeadDeviceWhileStreaming;
@@ -161,21 +161,6 @@
private final Map<BluetoothDevice, Integer> mDeviceGroupIdMap = new ConcurrentHashMap<>();
private final Map<BluetoothDevice, Integer> mDeviceAudioLocationMap = new ConcurrentHashMap<>();
- private final int mContextSupportingInputAudio = BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL
- | BluetoothLeAudio.CONTEXT_TYPE_VOICE_ASSISTANTS;
-
- private final int mContextSupportingOutputAudio = BluetoothLeAudio.CONTEXT_TYPE_CONVERSATIONAL
- | BluetoothLeAudio.CONTEXT_TYPE_MEDIA
- | BluetoothLeAudio.CONTEXT_TYPE_GAME
- | BluetoothLeAudio.CONTEXT_TYPE_INSTRUCTIONAL
- | BluetoothLeAudio.CONTEXT_TYPE_VOICE_ASSISTANTS
- | BluetoothLeAudio.CONTEXT_TYPE_LIVE
- | BluetoothLeAudio.CONTEXT_TYPE_SOUND_EFFECTS
- | BluetoothLeAudio.CONTEXT_TYPE_NOTIFICATIONS
- | BluetoothLeAudio.CONTEXT_TYPE_RINGTONE
- | BluetoothLeAudio.CONTEXT_TYPE_ALERTS
- | BluetoothLeAudio.CONTEXT_TYPE_EMERGENCY_ALARM;
-
private BroadcastReceiver mBondStateChangedReceiver;
private BroadcastReceiver mConnectionStateChangedReceiver;
private BroadcastReceiver mMuteStateChangedReceiver;
@@ -320,8 +305,8 @@
Integer group_id = entry.getKey();
if (descriptor.mIsActive) {
descriptor.mIsActive = false;
- updateActiveDevices(group_id, descriptor.mActiveContexts,
- ACTIVE_CONTEXTS_NONE, descriptor.mIsActive);
+ updateActiveDevices(group_id, descriptor.mDirection, AUDIO_DIRECTION_NONE,
+ descriptor.mIsActive);
break;
}
}
@@ -624,32 +609,6 @@
return result;
}
- /**
- * Get supported group audio direction from available context.
- *
- * @param activeContexts bitset of active context to be matched with possible audio direction
- * support.
- * @return matched possible audio direction support masked bitset
- * {@link #AUDIO_DIRECTION_INPUT_BIT} if input audio is supported
- * {@link #AUDIO_DIRECTION_OUTPUT_BIT} if output audio is supported
- */
- private Integer getAudioDirectionsFromActiveContextsMap(Integer activeContexts) {
- Integer supportedAudioDirections = 0;
-
- if (((activeContexts & mContextSupportingInputAudio) != 0)
- || (Utils.isPtsTestMode()
- && (activeContexts
- & (BluetoothLeAudio.CONTEXT_TYPE_RINGTONE
- | BluetoothLeAudio.CONTEXT_TYPE_MEDIA)) != 0)) {
- supportedAudioDirections |= AUDIO_DIRECTION_INPUT_BIT;
- }
- if ((activeContexts & mContextSupportingOutputAudio) != 0) {
- supportedAudioDirections |= AUDIO_DIRECTION_OUTPUT_BIT;
- }
-
- return supportedAudioDirections;
- }
-
private Integer getActiveGroupId() {
synchronized (mGroupLock) {
for (Map.Entry<Integer, LeAudioGroupDescriptor> entry : mGroupDescriptors.entrySet()) {
@@ -801,12 +760,7 @@
}
private boolean updateActiveInDevice(BluetoothDevice device, Integer groupId,
- Integer oldActiveContexts, Integer newActiveContexts) {
- Integer oldSupportedAudioDirections =
- getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
- Integer newSupportedAudioDirections =
- getAudioDirectionsFromActiveContextsMap(newActiveContexts);
-
+ Integer oldSupportedAudioDirections, Integer newSupportedAudioDirections) {
boolean oldSupportedByDeviceInput = (oldSupportedAudioDirections
& AUDIO_DIRECTION_INPUT_BIT) != 0;
boolean newSupportedByDeviceInput = (newSupportedAudioDirections
@@ -866,12 +820,7 @@
}
private boolean updateActiveOutDevice(BluetoothDevice device, Integer groupId,
- Integer oldActiveContexts, Integer newActiveContexts) {
- Integer oldSupportedAudioDirections =
- getAudioDirectionsFromActiveContextsMap(oldActiveContexts);
- Integer newSupportedAudioDirections =
- getAudioDirectionsFromActiveContextsMap(newActiveContexts);
-
+ Integer oldSupportedAudioDirections, Integer newSupportedAudioDirections) {
boolean oldSupportedByDeviceOutput = (oldSupportedAudioDirections
& AUDIO_DIRECTION_OUTPUT_BIT) != 0;
boolean newSupportedByDeviceOutput = (newSupportedAudioDirections
@@ -941,13 +890,13 @@
/**
* Report the active devices change to the active device manager and the media framework.
* @param groupId id of group which devices should be updated
- * @param newActiveContexts new active contexts for group of devices
- * @param oldActiveContexts old active contexts for group of devices
+ * @param newSupportedAudioDirections new supported audio directions for group of devices
+ * @param oldSupportedAudioDirections old supported audio directions for group of devices
* @param isActive if there is new active group
* @return true if group is active after change false otherwise.
*/
- private boolean updateActiveDevices(Integer groupId, Integer oldActiveContexts,
- Integer newActiveContexts, boolean isActive) {
+ private boolean updateActiveDevices(Integer groupId, Integer oldSupportedAudioDirections,
+ Integer newSupportedAudioDirections, boolean isActive) {
BluetoothDevice device = null;
if (isActive) {
@@ -955,9 +904,11 @@
}
boolean outReplaced =
- updateActiveOutDevice(device, groupId, oldActiveContexts, newActiveContexts);
+ updateActiveOutDevice(device, groupId, oldSupportedAudioDirections,
+ newSupportedAudioDirections);
boolean inReplaced =
- updateActiveInDevice(device, groupId, oldActiveContexts, newActiveContexts);
+ updateActiveInDevice(device, groupId, oldSupportedAudioDirections,
+ newSupportedAudioDirections);
if (outReplaced || inReplaced) {
Intent intent = new Intent(BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED);
@@ -1149,8 +1100,8 @@
return;
}
- descriptor.mIsActive = updateActiveDevices(groupId,
- ACTIVE_CONTEXTS_NONE, descriptor.mActiveContexts, true);
+ descriptor.mIsActive = updateActiveDevices(groupId, AUDIO_DIRECTION_NONE,
+ descriptor.mDirection, true);
if (descriptor.mIsActive) {
notifyGroupStatusChanged(groupId, LeAudioStackEvent.GROUP_STATUS_ACTIVE);
@@ -1167,8 +1118,8 @@
}
descriptor.mIsActive = false;
- updateActiveDevices(groupId, descriptor.mActiveContexts,
- ACTIVE_CONTEXTS_NONE, descriptor.mIsActive);
+ updateActiveDevices(groupId, descriptor.mDirection, AUDIO_DIRECTION_NONE,
+ descriptor.mIsActive);
/* Clear lost devices */
if (DBG) Log.d(TAG, "Clear for group: " + groupId);
clearLostDevicesWhileStreaming(descriptor);
@@ -1342,13 +1293,13 @@
if (descriptor != null) {
if (descriptor.mIsActive) {
descriptor.mIsActive =
- updateActiveDevices(groupId, descriptor.mActiveContexts,
- available_contexts, descriptor.mIsActive);
+ updateActiveDevices(groupId, descriptor.mDirection, direction,
+ descriptor.mIsActive);
if (!descriptor.mIsActive) {
notifyGroupStatusChanged(groupId, BluetoothLeAudio.GROUP_STATUS_INACTIVE);
}
}
- descriptor.mActiveContexts = available_contexts;
+ descriptor.mDirection = direction;
} else {
Log.e(TAG, "no descriptors for group: " + groupId);
}
@@ -1669,8 +1620,8 @@
descriptor.mIsActive = false;
/* Update audio framework */
updateActiveDevices(myGroupId,
- descriptor.mActiveContexts,
- descriptor.mActiveContexts,
+ descriptor.mDirection,
+ descriptor.mDirection,
descriptor.mIsActive);
return;
}
@@ -1678,8 +1629,8 @@
if (descriptor.mIsActive) {
updateActiveDevices(myGroupId,
- descriptor.mActiveContexts,
- descriptor.mActiveContexts,
+ descriptor.mDirection,
+ descriptor.mDirection,
descriptor.mIsActive);
}
}
@@ -2796,7 +2747,7 @@
ProfileService.println(sb, " Group: " + groupId);
ProfileService.println(sb, " isActive: " + descriptor.mIsActive);
ProfileService.println(sb, " isConnected: " + descriptor.mIsConnected);
- ProfileService.println(sb, " mActiveContexts: " + descriptor.mActiveContexts);
+ ProfileService.println(sb, " mDirection: " + descriptor.mDirection);
ProfileService.println(sb, " group lead: " + getConnectedGroupLeadDevice(groupId));
ProfileService.println(sb, " first device: " + getFirstDeviceFromGroup(groupId));
ProfileService.println(sb, " lost lead device: "