summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}
}