Merge "[Temp bonding] Block users to select temp bond device as primary device for call in "Call audio" under "Audio sharing" page" into main
This commit is contained in:
@@ -52,6 +52,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.flags.Flags;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -63,6 +64,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** PreferenceController to control the dialog to choose the active device for calls and alarms */
|
||||
public class AudioSharingCallAudioPreferenceController extends AudioSharingBasePreferenceController
|
||||
@@ -379,11 +381,21 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
|
||||
|
||||
private void updateDeviceItemsInSharingSession() {
|
||||
mGroupedConnectedDevices = AudioSharingUtils.fetchConnectedDevicesByGroupId(mBtManager);
|
||||
if (Flags.enableTemporaryBondDevicesUi()) {
|
||||
mGroupedConnectedDevices =
|
||||
mGroupedConnectedDevices.entrySet().stream()
|
||||
.filter(entry -> !anyTemporaryBondDevice(entry.getValue()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
mDeviceItemsInSharingSession =
|
||||
AudioSharingUtils.buildOrderedConnectedLeadAudioSharingDeviceItem(
|
||||
mBtManager, mGroupedConnectedDevices, /* filterByInSharing= */ true);
|
||||
}
|
||||
|
||||
private boolean anyTemporaryBondDevice(List<BluetoothDevice> connectedDevices) {
|
||||
return connectedDevices.stream().anyMatch(BluetoothUtils::isTemporaryBondDevice);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Pair<Integer, AudioSharingDeviceItem> getActiveItemWithIndex() {
|
||||
List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(mDeviceItemsInSharingSession);
|
||||
|
@@ -42,6 +42,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Looper;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
@@ -107,8 +108,11 @@ public class AudioSharingCallAudioPreferenceControllerTest {
|
||||
private static final String PREF_KEY = "calls_and_alarms";
|
||||
private static final String TEST_DEVICE_NAME1 = "test1";
|
||||
private static final String TEST_DEVICE_NAME2 = "test2";
|
||||
private static final String TEMP_BOND_METADATA =
|
||||
"<TEMP_BOND_TYPE>le_audio_sharing</TEMP_BOND_TYPE>";
|
||||
private static final int TEST_DEVICE_GROUP_ID1 = 1;
|
||||
private static final int TEST_DEVICE_GROUP_ID2 = 2;
|
||||
private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
|
||||
|
||||
private static final String TEST_SETTINGS_KEY =
|
||||
"bluetooth_le_broadcast_fallback_active_group_id";
|
||||
@@ -440,6 +444,23 @@ public class AudioSharingCallAudioPreferenceControllerTest {
|
||||
assertThat(mPreference.getSummary().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI)
|
||||
public void displayPreference_hasTemporaryBondDevice_doNotShow() {
|
||||
Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1);
|
||||
when(mCachedDevice1.isActiveDevice(BluetoothProfile.LE_AUDIO)).thenReturn(true);
|
||||
when(mBroadcast.isEnabled(any())).thenReturn(true);
|
||||
when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2));
|
||||
when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState));
|
||||
when(mDevice2.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS)).thenReturn(
|
||||
TEMP_BOND_METADATA.getBytes());
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
assertThat(mController.mGroupedConnectedDevices).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_clickToShowCorrectDialog() {
|
||||
AlertDialog latestAlertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
|
Reference in New Issue
Block a user