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

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

Merge "[Audiosharing] Modify util functions" into main

parents 8130b080 dcb5af87
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -835,9 +836,9 @@ public class BluetoothUtils {

    /** Get primary device group id in broadcast. */
    @WorkerThread
    public static int getPrimaryGroupIdForBroadcast(@NonNull Context context) {
    public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver) {
        return Settings.Secure.getInt(
                context.getContentResolver(),
                contentResolver,
                getPrimaryGroupIdUriForBroadcast(),
                BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
    }
@@ -846,9 +847,13 @@ public class BluetoothUtils {
    @Nullable
    @WorkerThread
    public static CachedBluetoothDevice getSecondaryDeviceForBroadcast(
            @NonNull Context context, @Nullable LocalBluetoothManager localBtManager) {
            @NonNull ContentResolver contentResolver,
            @Nullable LocalBluetoothManager localBtManager) {
        if (localBtManager == null) return null;
        int primaryGroupId = getPrimaryGroupIdForBroadcast(context);
        LocalBluetoothLeBroadcast broadcast =
                localBtManager.getProfileManager().getLeAudioBroadcastProfile();
        if (!broadcast.isEnabled(null)) return null;
        int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver);
        if (primaryGroupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) return null;
        LocalBluetoothLeBroadcastAssistant assistant =
                localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
+6 −3
Original line number Diff line number Diff line
@@ -589,7 +589,8 @@ public class BluetoothUtilsTest {

    @Test
    public void getSecondaryDeviceForBroadcast_errorState_returnNull() {
        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext, mLocalBluetoothManager))
        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext.getContentResolver(),
                mLocalBluetoothManager))
                .isNull();
    }

@@ -608,7 +609,8 @@ public class BluetoothUtilsTest {
        when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(state));
        when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mBluetoothDevice));

        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext, mLocalBluetoothManager))
        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext.getContentResolver(),
                mLocalBluetoothManager))
                .isNull();
    }

@@ -637,7 +639,8 @@ public class BluetoothUtilsTest {
        when(mAssistant.getAllConnectedDevices())
                .thenReturn(ImmutableList.of(mBluetoothDevice, bluetoothDevice));

        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext, mLocalBluetoothManager))
        assertThat(BluetoothUtils.getSecondaryDeviceForBroadcast(mContext.getContentResolver(),
                mLocalBluetoothManager))
                .isEqualTo(mCachedBluetoothDevice);
    }
}