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

Commit 0f55997e authored by Chung Tang's avatar Chung Tang
Browse files

[OutputSwitcher] Add "Share audio" button and click to open settings

"Share audio" button is displayed when it is available to start audio sharing, "Sharing audio" button is displayed when doing audio sharing. Clicking the button will open the audio sharing settings page.

Bug: 423772889
Test: atest MediaSwitchingControllerTest / BluetoothUtilsTest
Flag: com.android.systemui.enable_output_switcher_audio_sharing_button

Change-Id: Ie6b30c11ee61d8725eb815f2df84c1839f83e787
parent 388f0cd6
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -1390,4 +1390,25 @@ public class BluetoothUtils {
                + " updatedMetadata = " + updated);
        assistant.modifySource(sink, sourceId, updated);
    }

    /**
     * Checks if the Bluetooth LE Audio Broadcast Assistant profile is available and at least one
     * device is currently connected to it.
     *
     * @param bluetoothManager The {@link LocalBluetoothManager} instance to query.
     * @return {@code true} if at least one device is connected to the LE Audio Broadcast Assistant
     *     profile, {@code false} otherwise.
     */
    public static boolean hasConnectedBroadcastAssistantDevice(
            @NonNull LocalBluetoothManager bluetoothManager) {
        LocalBluetoothLeBroadcastAssistant assistantProfile =
                bluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile();

        // assistantProfile can be null if the profile is not supported or available.
        if (assistantProfile == null) {
            return false;
        }

        return !assistantProfile.getAllConnectedDevices().isEmpty();
    }
}
+30 −0
Original line number Diff line number Diff line
@@ -1737,6 +1737,36 @@ public class BluetoothUtilsTest {
        assertTrue(updatedChannels.get(2).isSelected());
    }

    @Test
    public void hasConnectedBroadcastAssistantDevice_assistantProfileNull_returnFalse() {
        when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(null);

        boolean isAssistantConnected =
                BluetoothUtils.hasConnectedBroadcastAssistantDevice(mLocalBluetoothManager);

        assertThat(isAssistantConnected).isFalse();
    }

    @Test
    public void hasConnectedBroadcastAssistantDevice_noConnectedDevice_returnFalse() {
        when(mAssistant.getAllConnectedDevices()).thenReturn(List.of());

        boolean isAssistantConnected =
                BluetoothUtils.hasConnectedBroadcastAssistantDevice(mLocalBluetoothManager);

        assertThat(isAssistantConnected).isFalse();
    }

    @Test
    public void hasConnectedBroadcastAssistantDevice_hasConnectedDevice_returnFalse() {
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mBluetoothDevice));

        boolean isAssistantConnected =
                BluetoothUtils.hasConnectedBroadcastAssistantDevice(mLocalBluetoothManager);

        assertThat(isAssistantConnected).isTrue();
    }

    private BluetoothLeBroadcastMetadata createMetadataWithChannels(
            BluetoothLeBroadcastChannel... channels) {
        BluetoothLeBroadcastMetadata mockMetadata = mock(BluetoothLeBroadcastMetadata.class);
+11 −0
Original line number Diff line number Diff line
@@ -81,6 +81,17 @@
        android:layout_height="wrap_content"
        android:visibility="gone">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/audio_sharing"
            style="@style/MediaOutput.Dialog.QuickAccessButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:text="@string/media_output_dialog_button_share_audio"
            android:visibility="gone"
            app:icon="@drawable/ic_bt_le_audio_sharing" />

        <com.google.android.material.button.MaterialButton
            android:id="@+id/connect_device"
            app:icon="@drawable/ic_add"
+4 −0
Original line number Diff line number Diff line
@@ -3515,6 +3515,10 @@
    <string name="media_output_end_session_dialog_stop">Stop</string>
    <!-- Button text for stopping sharing [CHAR LIMIT=60] -->
    <string name="media_output_dialog_button_stop_sharing">Stop sharing</string>
    <!-- Button text when doing audio sharing. [CHAR LIMIT=60] -->
    <string name="media_output_dialog_button_sharing_audio">Sharing audio</string>
    <!-- Button text for triggering audio sharing. [CHAR LIMIT=60] -->
    <string name="media_output_dialog_button_share_audio">Share audio</string>

    <!-- Label for clip data when copying the build number off QS [CHAR LIMIT=NONE]-->
    <string name="build_number_clip_data_label">Build number</string>
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.media.dialog

import androidx.annotation.StringRes

data class AudioSharingButtonState(@StringRes val resId: Int, val isActive: Boolean)
Loading