summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java28
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java2
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java52
-rw-r--r--packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java69
4 files changed, 145 insertions, 6 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
index ae9ad958b287..33dcb051d194 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java
@@ -1068,18 +1068,42 @@ public class BluetoothUtils {
/** Get primary device Uri in broadcast. */
@NonNull
public static String getPrimaryGroupIdUriForBroadcast() {
+ // TODO: once API is stable, deprecate SettingsProvider solution
return "bluetooth_le_broadcast_fallback_active_group_id";
}
- /** Get primary device group id in broadcast. */
+ /** Get primary device group id in broadcast from SettingsProvider. */
@WorkerThread
public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver) {
+ // TODO: once API is stable, deprecate SettingsProvider solution
return Settings.Secure.getInt(
contentResolver,
getPrimaryGroupIdUriForBroadcast(),
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
}
+ /**
+ * Get primary device group id in broadcast.
+ *
+ * If Flags.adoptPrimaryGroupManagementApiV2 is enabled, get group id by API,
+ * Otherwise, still get value from SettingsProvider.
+ */
+ @WorkerThread
+ public static int getPrimaryGroupIdForBroadcast(@NonNull ContentResolver contentResolver,
+ @Nullable LocalBluetoothManager manager) {
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ LeAudioProfile leaProfile = manager == null ? null :
+ manager.getProfileManager().getLeAudioProfile();
+ if (leaProfile == null) {
+ Log.d(TAG, "getPrimaryGroupIdForBroadcast: profile is null");
+ return BluetoothCsipSetCoordinator.GROUP_ID_INVALID;
+ }
+ return leaProfile.getBroadcastToUnicastFallbackGroup();
+ } else {
+ return getPrimaryGroupIdForBroadcast(contentResolver);
+ }
+ }
+
/** Get develop option value for audio sharing preview. */
@WorkerThread
public static boolean getAudioSharingPreviewValue(@Nullable ContentResolver contentResolver) {
@@ -1101,7 +1125,7 @@ public class BluetoothUtils {
LocalBluetoothLeBroadcast broadcast =
localBtManager.getProfileManager().getLeAudioBroadcastProfile();
if (broadcast == null || !broadcast.isEnabled(null)) return null;
- int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver);
+ int primaryGroupId = getPrimaryGroupIdForBroadcast(contentResolver, localBtManager);
if (primaryGroupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) return null;
LocalBluetoothLeBroadcastAssistant assistant =
localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile();
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
index 011b2fc15807..914d96266e43 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -1358,7 +1358,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Gets summary for the buds which are in the audio sharing.
int groupId = BluetoothUtils.getGroupId(this);
int primaryGroupId = BluetoothUtils.getPrimaryGroupIdForBroadcast(
- mContext.getContentResolver());
+ mContext.getContentResolver(), mBluetoothManager);
if ((primaryGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID)
? (groupId == primaryGroupId) : isActiveDevice(BluetoothProfile.LE_AUDIO)) {
// The buds are primary buds
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 b7814127b716..8fc4aa81b53f 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
@@ -936,15 +936,60 @@ public class BluetoothUtilsTest {
}
@Test
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getSecondaryDeviceForBroadcast_adoptAPI_noSecondary_returnNull() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDevice.getGroupId()).thenReturn(1);
+ BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
+ when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(state));
+ when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mBluetoothDevice));
+
+ assertThat(
+ BluetoothUtils.getSecondaryDeviceForBroadcast(
+ mContext.getContentResolver(), mLocalBluetoothManager))
+ .isNull();
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getSecondaryDeviceForBroadcast_adoptAPI_returnCorrectDevice() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+ CachedBluetoothDevice cachedBluetoothDevice = mock(CachedBluetoothDevice.class);
+ BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
+ when(cachedBluetoothDevice.getDevice()).thenReturn(bluetoothDevice);
+ when(cachedBluetoothDevice.getGroupId()).thenReturn(1);
+ when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedBluetoothDevice.getGroupId()).thenReturn(2);
+ when(mDeviceManager.findDevice(bluetoothDevice)).thenReturn(cachedBluetoothDevice);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(state.getBisSyncState()).thenReturn(bisSyncState);
+ when(mAssistant.getAllSources(any(BluetoothDevice.class)))
+ .thenReturn(ImmutableList.of(state));
+ when(mAssistant.getAllConnectedDevices())
+ .thenReturn(ImmutableList.of(mBluetoothDevice, bluetoothDevice));
+
+ assertThat(
+ BluetoothUtils.getSecondaryDeviceForBroadcast(
+ mContext.getContentResolver(), mLocalBluetoothManager))
+ .isEqualTo(mCachedBluetoothDevice);
+ }
+
+ @Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getSecondaryDeviceForBroadcast_noSecondary_returnNull() {
Settings.Secure.putInt(
mContext.getContentResolver(),
BluetoothUtils.getPrimaryGroupIdUriForBroadcast(),
1);
when(mBroadcast.isEnabled(any())).thenReturn(true);
- CachedBluetoothDeviceManager deviceManager = mock(CachedBluetoothDeviceManager.class);
- when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(deviceManager);
- when(deviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
+ when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getGroupId()).thenReturn(1);
BluetoothLeBroadcastReceiveState state = mock(BluetoothLeBroadcastReceiveState.class);
@@ -958,6 +1003,7 @@ public class BluetoothUtilsTest {
}
@Test
+ @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getSecondaryDeviceForBroadcast_returnCorrectDevice() {
Settings.Secure.putInt(
mContext.getContentResolver(),
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
index f57ee0c0930e..e29adc151a28 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java
@@ -42,6 +42,8 @@ import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.input.InputManager;
import android.media.AudioManager;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.text.Spannable;
@@ -163,6 +165,7 @@ public class CachedBluetoothDeviceTest {
when(mHidProfile.getProfileId()).thenReturn(BluetoothProfile.HID_HOST);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mProfileManager);
when(mBroadcast.isEnabled(any())).thenReturn(false);
+ when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
when(mProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
when(mProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
mCachedDevice = spy(new CachedBluetoothDevice(mContext, mProfileManager, mDevice));
@@ -2004,6 +2007,70 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastPrimary_fallbackDevice_returnActive() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(1);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
+ }
+
+ @Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastPrimary_activeDevice_returnActive() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(
+ BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(1);
+ when(mCachedDevice.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(mContext.getString(R.string.bluetooth_active_no_battery_level));
+ }
+
+ @Test
+ @EnableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
+ public void getConnectionSummary_adoptAPI_isBroadcastNotPrimary_returnActiveMedia() {
+ when(mBroadcast.isEnabled(any())).thenReturn(true);
+ when(mCachedDevice.getDevice()).thenReturn(mDevice);
+ when(mLeAudioProfile.getBroadcastToUnicastFallbackGroup()).thenReturn(1);
+
+ List<Long> bisSyncState = new ArrayList<>();
+ bisSyncState.add(1L);
+ when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState);
+ List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>();
+ sourceList.add(mLeBroadcastReceiveState);
+ when(mAssistant.getAllSources(any())).thenReturn(sourceList);
+
+ when(mCachedDevice.getGroupId()).thenReturn(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
+
+ assertThat(mCachedDevice.getConnectionSummary(false))
+ .isEqualTo(
+ mContext.getString(R.string.bluetooth_active_media_only_no_battery_level));
+ }
+
+ @Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastPrimary_fallbackDevice_returnActive() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -2026,6 +2093,7 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastPrimary_activeDevice_returnActive() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);
@@ -2049,6 +2117,7 @@ public class CachedBluetoothDeviceTest {
}
@Test
+ @DisableFlags(com.android.settingslib.flags.Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
public void getConnectionSummary_isBroadcastNotPrimary_returnActiveMedia() {
when(mBroadcast.isEnabled(any())).thenReturn(true);
when(mCachedDevice.getDevice()).thenReturn(mDevice);