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

Commit 93179f14 authored by Chung Tang's avatar Chung Tang Committed by Android (Google) Code Review
Browse files

Merge "[OutputSwitcher] Fix audio resume on headset after selecting phone speaker" into main

parents 21e7eb73 b209257c
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -328,7 +328,7 @@ import java.util.concurrent.CopyOnWriteArrayList;

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

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

    private void stopBroadcastIfCurrentlySelected(long requestId) {
    private void stopBroadcastForTransferIfCurrentlySelected(long requestId) {
        if (!currentOutputIsBLEBroadcast()) {
            return;
        }

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

    @RequiresPermission(
+8 −0
Original line number Diff line number Diff line
@@ -301,6 +301,14 @@ import java.util.stream.Collectors;
        mBluetoothProfileMonitor.stopBroadcast();
    }

    /**
     * Trigger {@link BluetoothProfileMonitor} to stop the broadcast, optionally making a new BT
     * device active.
     */
    protected void stopBroadcast(@Nullable String routeId) {
        mBluetoothProfileMonitor.stopBroadcast(routeId);
    }

    /**
     * Obtains a list of selected bluetooth route infos.
     *
+31 −4
Original line number Diff line number Diff line
@@ -237,13 +237,40 @@ import java.util.concurrent.ThreadLocalRandom;
        mBroadcastProfile.startBroadcast(settings);
    }

    /** Stops the broadcast. */
    /** Stops the broadcast */
    public synchronized void stopBroadcast() {
        if (mBroadcastProfile != null) {
        if (mBroadcastProfile == null) {
            Slog.e(TAG, "Fail to stop broadcast, LeBroadcast is null");
            return;
        }
        mBroadcastProfile.stopBroadcast(mBroadcastId);
        } else {
    }

    /**
     * Stops the broadcast, optionally making a new BT device active.
     *
     * <p>This method is expected to use this ID to determine which unicast fallback group should be
     * set 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.
     */
    public synchronized void stopBroadcast(@Nullable String routeId) {
        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);
            }
        }
        mBroadcastProfile.stopBroadcast(mBroadcastId);
    }

    /**