Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f07e888 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Fix fallback device selection.

Use LE audio profile to get group id as fallback for non-CSIP device.

Test: manual
Fix: 328820792
Change-Id: Icc453844fad9c70bb259033e55212a337a2fbaf1
parent 7b05e435
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -81,11 +81,13 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
    public static final int BROADCAST_STATE_UNKNOWN = 0;
    public static final int BROADCAST_STATE_ON = 1;
    public static final int BROADCAST_STATE_OFF = 2;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            prefix = {"BROADCAST_STATE_"},
            value = {BROADCAST_STATE_UNKNOWN, BROADCAST_STATE_ON, BROADCAST_STATE_OFF})
    public @interface BroadcastState {}

    private static final String SETTINGS_PKG = "com.android.settings";
    private static final String TAG = "LocalBluetoothLeBroadcast";
    private static final boolean DEBUG = BluetoothUtils.D;
@@ -1068,7 +1070,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
            return;
        }
        int fallbackActiveGroupId = getFallbackActiveGroupId();
        if (targetCachedDevice.getGroupId() == fallbackActiveGroupId) {
        if (getGroupId(targetCachedDevice) == fallbackActiveGroupId) {
            Log.d(
                    TAG,
                    "Skip updateFallbackActiveDeviceIfNeeded, already is fallback: "
@@ -1091,6 +1093,23 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
    }

    private int getGroupId(CachedBluetoothDevice cachedDevice) {
        int groupId = cachedDevice.getGroupId();
        String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress();
        if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
            Log.d(TAG, "getGroupId by CSIP profile for device: " + anonymizedAddress);
            return groupId;
        }
        for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) {
            if (profile instanceof LeAudioProfile) {
                Log.d(TAG, "getGroupId by LEA profile for device: " + anonymizedAddress);
                return ((LeAudioProfile) profile).getGroupId(cachedDevice.getDevice());
            }
        }
        Log.d(TAG, "getGroupId return invalid id for device: " + anonymizedAddress);
        return BluetoothCsipSetCoordinator.GROUP_ID_INVALID;
    }

    private void notifyBroadcastStateChange(@BroadcastState int state) {
        if (!mContext.getPackageName().equals(SETTINGS_PKG)) {
            Log.d(TAG, "Skip notifyBroadcastStateChange, not triggered by Settings.");