summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yiyi Shen <yiyishen@google.com> 2024-07-23 14:59:09 +0800
committer Yiyi Shen <yiyishen@google.com> 2024-07-23 14:59:09 +0800
commitdcb5af87b8420fb1f0a01ed68fe2e4ae24b7da9d (patch)
tree58f358761e935c98a44200365ca4222c92f52516
parent1b1fcd1708929e6cab0d6af611c3b0e60ab7670a (diff)
[Audiosharing] Modify util functions
Test: atest Bug: 336716411 Flag: com.android.settingslib.flags.volume_dialog_audio_sharing_fix Change-Id: I44b7b6cd69184aab8f17bb3d6ef6de59c93f88d9
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java15
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java9
2 files changed, 16 insertions, 8 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index 53441c08776f..4b9511e217fe 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -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();
@@ -866,4 +871,4 @@ public class BluetoothUtils {
}
return null;
}
-}
+} \ No newline at end of file
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
index 28bf34882365..a42dd0da99f8 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java
@@ -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);
}
}