Introduce a function to derive a more meaningful state for the UI from `BluetoothLeBroadcastReceiveState`.
Test: atest
Bug: 308368124
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: I08be93310f6e5bc0624259879239a8f8a6b40caf
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java
index 5bcdcc0..d9e79fa 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java
@@ -52,6 +52,14 @@
* BluetoothLeBroadcastAssistant.Callback} to get the result callback.
*/
public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile {
+ /** A derived source state based on {@link BluetoothLeBroadcastReceiveState}. */
+ public enum LocalBluetoothLeBroadcastSourceState {
+ UNKNOWN,
+ STREAMING,
+ DECRYPTION_FAILED,
+ PAUSED,
+ }
+
private static final String TAG = "LocalBluetoothLeBroadcastAssistant";
private static final int UNKNOWN_VALUE_PLACEHOLDER = -1;
private static final boolean DEBUG = BluetoothUtils.D;
@@ -59,6 +67,13 @@
static final String NAME = "LE_AUDIO_BROADCAST_ASSISTANT";
// Order of this profile in device profiles list
private static final int ORDINAL = 1;
+ // Referring to Broadcast Audio Scan Service 1.0
+ // Table 3.9: Broadcast Receive State characteristic format
+ // 0x00000000: 0b0 = Not synchronized to BIS_index[x]
+ // 0xFFFFFFFF: Failed to sync to BIG
+ private static final long BIS_SYNC_NOT_SYNC_TO_BIS = 0x00000000L;
+ private static final long BIS_SYNC_FAILED_SYNC_TO_BIG = 0xFFFFFFFFL;
+ private static final String EMPTY_DEVICE_ADDRESS = "00:00:00:00:00:00";
private LocalBluetoothProfileManager mProfileManager;
private BluetoothLeBroadcastAssistant mService;
@@ -558,4 +573,30 @@
}
}
}
+
+ /** Checks the source connection status based on the provided broadcast receive state. */
+ public static LocalBluetoothLeBroadcastSourceState getLocalSourceState(
+ BluetoothLeBroadcastReceiveState state) {
+ // Source is actively streaming
+ if (state.getBisSyncState().stream()
+ .anyMatch(
+ bitmap ->
+ (bitmap != BIS_SYNC_NOT_SYNC_TO_BIS
+ && bitmap != BIS_SYNC_FAILED_SYNC_TO_BIG))) {
+ return LocalBluetoothLeBroadcastSourceState.STREAMING;
+ }
+ // Wrong password is used for the source
+ if (state.getPaSyncState() == BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_SYNCHRONIZED
+ && state.getBigEncryptionState()
+ == BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_BAD_CODE) {
+ return LocalBluetoothLeBroadcastSourceState.DECRYPTION_FAILED;
+ }
+ // Source in hysteresis mode
+ if (!state.getSourceDevice().getAddress().equals(EMPTY_DEVICE_ADDRESS)) {
+ // Referring to Broadcast Audio Scan Service 1.0
+ // All zero address means no source on the sink device
+ return LocalBluetoothLeBroadcastSourceState.PAUSED;
+ }
+ return LocalBluetoothLeBroadcastSourceState.UNKNOWN;
+ }
}