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

Commit 93b3a8b6 authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[MR2] Handle transfer to LEA device during broadcast" into main

parents 4f6752ee 76de438f
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -325,7 +325,7 @@ import java.util.concurrent.CopyOnWriteArrayList;

        if (com.android.media.flags.Flags.enableOutputSwitcherPersonalAudioSharing()) {
            // We need to stop broadcast when we transfer to another route
            stopBroadcastForTransferIfCurrentlySelected();
            stopBroadcastForTransferIfCurrentlySelected(routeId);
        }

        MediaRoute2InfoHolder mediaRoute2InfoHolder;
@@ -387,13 +387,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
        mHandler.post(() -> mBluetoothRouteController.removeRouteFromBroadcast(routeId));
    }

    private void stopBroadcastForTransferIfCurrentlySelected() {
    private void stopBroadcastForTransferIfCurrentlySelected(@NonNull String routeId) {
        if (!currentOutputIsBLEBroadcast()) {
            return;
        }

        // TODO: b/430200199 - Setting a correct routeId
        mHandler.post(() -> mBluetoothRouteController.stopBroadcast(/* routeId= */ null));
        mHandler.post(() -> mBluetoothRouteController.stopBroadcast(routeId));
    }

    @RequiresPermission(
+10 −2
Original line number Diff line number Diff line
@@ -302,11 +302,19 @@ import java.util.stream.Collectors;
    }

    /**
     * Trigger {@link BluetoothProfileMonitor} to stop the broadcast, optionally making a new BT
     * Trigger {@link BluetoothProfileMonitor} to stop the broadcast, optionally making a new LEA
     * device active.
     *
     * @param routeId id of the LEA Bluetooth route to be set as active after broadcast stops.
     */
    protected void stopBroadcast(@Nullable String routeId) {
        mBluetoothProfileMonitor.stopBroadcast(routeId);
        BluetoothDevice bluetoothDevice =
                mBluetoothRoutes.values().stream()
                        .filter(routeInfo -> routeInfo.mRoute.getId().equals(routeId))
                        .findFirst()
                        .map(routeInfo -> routeInfo.mBtDevice)
                        .orElse(null);
        mBluetoothProfileMonitor.stopBroadcast(bluetoothDevice);
    }

    /**
+16 −15
Original line number Diff line number Diff line
@@ -247,28 +247,29 @@ import java.util.concurrent.ThreadLocalRandom;
    }

    /**
     * Stops the broadcast, optionally making a new BT device active.
     * Stops the broadcast, optionally making a new LEA BT device active.
     *
     * <p>This method is expected to use this ID to determine which unicast fallback group should be
     * set the broadcast stops.
     * <p>This method is expected to use the given device to determine which unicast fallback group
     * should be set when the broadcast stops.
     *
     * @param routeId id of the bluetooth route that should become active once the broadcast stops,
     *     or null if no BT route should become active once broadcast stops.
     * @param device LEA device that should become active once the broadcast stops, or null if no
     *     LEA device should become active once broadcast stops.
     */
    public synchronized void stopBroadcast(@Nullable String routeId) {
    public synchronized void stopBroadcast(@Nullable BluetoothDevice device) {
        if (mBroadcastProfile == null) {
            Slog.e(TAG, "Fail to stop broadcast, LeBroadcast is null");
            return;
        }
        if (routeId == null) {
        if (mLeAudioProfile == null) {
            Slog.e(TAG, "Fail to set fall back group, LeProfile is null");
        } else {
                // TODO: b/430200199 - Map the route id to group id if not null, so that
                // the target BT route becomes active.
                mLeAudioProfile.setBroadcastToUnicastFallbackGroup(
                        BluetoothLeAudio.GROUP_ID_INVALID);
            }
            // if no valid group id, set the fallback to -1, no LEA BT device should become active
            // once broadcast stops
            int groupId =
                    (device == null || !isProfileSupported(BluetoothProfile.LE_AUDIO, device))
                            ? BluetoothLeAudio.GROUP_ID_INVALID
                            : (int) getGroupId(BluetoothProfile.LE_AUDIO, device);
            mLeAudioProfile.setBroadcastToUnicastFallbackGroup(groupId);
        }
        mBroadcastProfile.stopBroadcast(mBroadcastId);
    }