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

Commit 114d85ce authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Update fallback when receive synced state

Test: manual
Bug: 305620450
Change-Id: I9166d7faca1a08ea50e70afb8e5970e6c6992604
parent 411b67e8
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -292,7 +292,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                        + ", sourceId = "
                                        + sourceId);
                    }
                    updateFallbackActiveDeviceIfNeeded();
                }

                @Override
@@ -314,7 +313,18 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                public void onSourceAddFailed(
                        @NonNull BluetoothDevice sink,
                        @NonNull BluetoothLeBroadcastMetadata source,
                        int reason) {}
                        int reason) {
                    if (DEBUG) {
                        Log.d(
                                TAG,
                                "onSourceAddFailed(), sink = "
                                        + sink
                                        + ", reason = "
                                        + reason
                                        + ", source = "
                                        + source);
                    }
                }

                @Override
                public void onSourceModified(
@@ -369,6 +379,9 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                        + ", state = "
                                        + state);
                    }
                    if (BluetoothUtils.isConnected(state)) {
                        updateFallbackActiveDeviceIfNeeded();
                    }
                }
            };

@@ -1056,7 +1069,9 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                    List<BluetoothLeBroadcastReceiveState> sourceList =
                                            mServiceBroadcastAssistant.getAllSources(
                                                    bluetoothDevice);
                                    return !sourceList.isEmpty();
                                    return !sourceList.isEmpty()
                                            && sourceList.stream()
                                                    .anyMatch(BluetoothUtils::isConnected);
                                })
                        .collect(Collectors.toList());
        if (devicesInSharing.isEmpty()) {
@@ -1091,7 +1106,8 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
            return;
        }
        int fallbackActiveGroupId = getFallbackActiveGroupId();
        if (getGroupId(targetCachedDevice) == fallbackActiveGroupId) {
        if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
                && getGroupId(targetCachedDevice) == fallbackActiveGroupId) {
            Log.d(
                    TAG,
                    "Skip updateFallbackActiveDeviceIfNeeded, already is fallback: "
@@ -1101,12 +1117,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
        targetCachedDevice.setActive();
    }

    private boolean isDecryptedSource(BluetoothLeBroadcastReceiveState state) {
        return state.getPaSyncState() == BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_SYNCHRONIZED
                && state.getBigEncryptionState()
                        == BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_DECRYPTING;
    }

    private int getFallbackActiveGroupId() {
        return Settings.Secure.getInt(
                mContext.getContentResolver(),