[LE Audio] Add LE Audio Devices in Sound Settings

- When connected to the LE Audio Device, it will display "Play XXX on
    LEAduioDeviceName" in Sound Settings.

  - When connected to the LE Audio Device, it will display the LE Audio
    device name in the "Take call on" list for you having a active call(Hands Free).

  - Remove the @Ignore annotation for all the tests and make test
    cases pass.

Bug: 240911615
Bug: 243494881
Test: manual test
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AudioOutputSwitchPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=HandsFreeProfileOutputPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=MediaOutputPreferenceControllerTest
Change-Id: I10db59b33623495a9e9933556c78e20d81e405ea
This commit is contained in:
changbetty
2022-10-12 11:02:59 +00:00
parent 50c7cb834e
commit 1096417464
6 changed files with 279 additions and 33 deletions

View File

@@ -53,12 +53,12 @@ import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -74,7 +74,6 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = {
ShadowAudioManager.class,
ShadowBluetoothUtils.class,
@@ -102,6 +101,8 @@ public class AudioOutputSwitchPreferenceControllerTest {
private HeadsetProfile mHeadsetProfile;
@Mock
private HearingAidProfile mHearingAidProfile;
@Mock
private LeAudioProfile mLeAudioProfile;
private Context mContext;
private PreferenceScreen mScreen;
@@ -117,6 +118,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
private AudioSwitchPreferenceController mController;
private List<BluetoothDevice> mProfileConnectedDevices;
private List<BluetoothDevice> mHearingAidActiveDevices;
private List<BluetoothDevice> mLeAudioActiveDevices;
private List<BluetoothDevice> mEmptyDevices;
private ShadowPackageManager mPackageManager;
@@ -136,6 +138,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
mPackageManager = Shadow.extract(mContext.getPackageManager());
mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
@@ -156,6 +159,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
mLeAudioActiveDevices = new ArrayList<>();
mEmptyDevices = new ArrayList<>(2);
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
@@ -391,6 +395,55 @@ public class AudioOutputSwitchPreferenceControllerTest {
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
}
@Test
public void getConnectedLeAudioDevices_connectedLeAudioDevice_shouldAddDeviceToList() {
mEmptyDevices.clear();
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
}
@Test
public void getConnectedLeAudioDevices_disconnectedLeAudioDevice_shouldNotAddDeviceToList() {
BluetoothDevice connectdBtLeAduioDevice =
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
when(connectdBtLeAduioDevice.isConnected()).thenReturn(true);
BluetoothDevice disonnectdBtLeAduioDevice =
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(disonnectdBtLeAduioDevice.isConnected()).thenReturn(false);
mEmptyDevices.clear();
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
mProfileConnectedDevices.add(connectdBtLeAduioDevice);
mProfileConnectedDevices.add(disonnectdBtLeAduioDevice);
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, connectdBtLeAduioDevice);
}
@Test
public void findActiveLeAudioDevice_noActiveDevice_returnNull() {
mLeAudioActiveDevices.clear();
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
assertThat(mController.findActiveLeAudioDevice()).isNull();
}
@Test
public void findActiveLeAudioDevice_withActiveDevice_returnActiveDevice() {
mLeAudioActiveDevices.clear();
mLeAudioActiveDevices.add(mBluetoothDevice);
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
assertThat(mController.findActiveLeAudioDevice()).isEqualTo(mBluetoothDevice);
}
private class AudioSwitchPreferenceControllerTestable extends
AudioSwitchPreferenceController {
AudioSwitchPreferenceControllerTestable(Context context, String key) {