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

Commit 7499b8a6 authored by chelseahao's avatar chelseahao
Browse files

Notify private broadcast source data with selected channel index.

Flag: com.android.settingslib.flags.audio_stream_play_pause_by_modify_source
Test: atest
Bug: 384976631
Change-Id: I9fc3aff2e00fbffd23c0535c5350526bddc7729c
parent c89dafe5
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import static android.bluetooth.BluetoothProfile.CONNECTION_POLICY_FORBIDDEN;
import static com.android.settingslib.Utils.isAudioModeOngoingCall;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.DECRYPTION_FAILED;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.PAUSED;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.PAUSED_BY_RECEIVER;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.STREAMING;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.getLocalSourceStateWithSelectedChannel;

import static java.util.stream.Collectors.toList;

@@ -144,6 +146,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
            };
    private final Context mContext;
    private final CachedBluetoothDeviceManager mDeviceManager;
    private final LocalBluetoothProfileManager mProfileManager;
    private final boolean mHysteresisModeFixAvailable;
    private final boolean mIsWorkProfile;
    private BluetoothLeBroadcast mServiceBroadcast;
@@ -426,6 +429,12 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                        Log.d(TAG, "Skip notifyPrivateBroadcastReceived for work profile.");
                        return;
                    }
                    String packageName = mContext.getPackageName();
                    if (!packageName.equals(SYSUI_PKG)) {
                        Log.d(TAG,
                                "Skip notifyPrivateBroadcastReceived, not triggered by SystemUI.");
                        return;
                    }
                    if (state.getBroadcastId() == mBroadcastId
                            || !mLocalSinksPendingSourceRemoval.isEmpty()) {
                        Log.d(TAG,
@@ -433,9 +442,14 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                        + "triggered by personal audio sharing.");
                        return;
                    }
                    var sourceState = LocalBluetoothLeBroadcastAssistant.getLocalSourceState(state);
                    var sourceStateAndSelectedChannel = getLocalSourceStateWithSelectedChannel(
                            mProfileManager, sink, sourceId, state);
                    var sourceState = sourceStateAndSelectedChannel.first;
                    var selectedChannel = sourceStateAndSelectedChannel.second;
                    if (sourceState == STREAMING || sourceState == DECRYPTION_FAILED
                            || (mHysteresisModeFixAvailable && sourceState == PAUSED)) {
                            || (mHysteresisModeFixAvailable && sourceState == PAUSED) ||
                            (Flags.audioStreamPlayPauseByModifySource()
                                    && sourceState == PAUSED_BY_RECEIVER)) {
                        List<BluetoothLeAudioContentMetadata> subgroupMetadata =
                                state.getSubgroupMetadata();
                        String programInfo = subgroupMetadata.isEmpty() ? ""
@@ -445,7 +459,8 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                                sourceId,
                                state.getBroadcastId(),
                                programInfo == null ? "" : programInfo,
                                sourceState);
                                sourceState,
                                selectedChannel);
                    }
                }
            };
@@ -462,9 +477,11 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
        }
    }

    LocalBluetoothLeBroadcast(Context context, CachedBluetoothDeviceManager deviceManager) {
    LocalBluetoothLeBroadcast(Context context, CachedBluetoothDeviceManager deviceManager,
            LocalBluetoothProfileManager profileManager) {
        mContext = context;
        mDeviceManager = deviceManager;
        mProfileManager = profileManager;
        mExecutor = Executors.newSingleThreadExecutor();
        mBuilder = new BluetoothLeAudioContentMetadata.Builder();
        mContentResolver = context.getContentResolver();
@@ -1340,20 +1357,17 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {

    private void notifyPrivateBroadcastReceived(BluetoothDevice sink, int sourceId, int broadcastId,
            String programInfo,
            LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState state) {
        String packageName = mContext.getPackageName();
        if (!packageName.equals(SYSUI_PKG)) {
            Log.d(TAG, "Skip notifyPrivateBroadcastReceived, not triggered by SystemUI.");
            return;
        }
        var data = new PrivateBroadcastReceiveData(sink, sourceId, broadcastId, programInfo, state);
            LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState state,
            Set<Integer> selectedChannelIndex) {
        var data = new PrivateBroadcastReceiveData(sink, sourceId, broadcastId, programInfo, state,
                selectedChannelIndex);
        Intent intent = new Intent(ACTION_LE_AUDIO_PRIVATE_BROADCAST_RECEIVED);
        intent.putExtra(EXTRA_PRIVATE_BROADCAST_RECEIVE_DATA, data);
        intent.setPackage(SETTINGS_PKG);
        Log.d(TAG,
                "notifyPrivateBroadcastReceived for sink = " + sink + " with sourceId = " + sourceId
                        + " state = " + state
                        + " programInfo =" + programInfo
                        + " state = " + state + " selectedChannelIndex = "
                        + selectedChannelIndex + " programInfo = " + programInfo
                        + " broadcastId = " + broadcastId);
        mContext.sendBroadcast(intent);
    }
+1 −1
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ public class LocalBluetoothProfileManager {
            if (DEBUG) {
                Log.d(TAG, "Adding local LE_AUDIO_BROADCAST profile");
            }
            mLeAudioBroadcast = new LocalBluetoothLeBroadcast(mContext, mDeviceManager);
            mLeAudioBroadcast = new LocalBluetoothLeBroadcast(mContext, mDeviceManager, this);
            // no event handler for the LE boradcast.
            mProfileNameMap.put(LocalBluetoothLeBroadcast.NAME, mLeAudioBroadcast);
        }