[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:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.sound;
|
||||
|
||||
import static android.media.AudioSystem.DEVICE_OUT_BLE_HEADSET;
|
||||
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
|
||||
import static android.media.AudioSystem.DEVICE_OUT_EARPIECE;
|
||||
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
|
||||
@@ -56,13 +57,13 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||
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 com.android.settingslib.media.MediaOutputConstants;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -79,7 +80,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Ignore
|
||||
@Config(shadows = {
|
||||
ShadowAudioManager.class,
|
||||
ShadowBluetoothUtils.class,
|
||||
@@ -91,10 +91,12 @@ public class MediaOutputPreferenceControllerTest {
|
||||
private static final String TEST_DEVICE_NAME_2 = "Test_A2DP_BT_Device_NAME_2";
|
||||
private static final String TEST_HAP_DEVICE_NAME_1 = "Test_HAP_BT_Device_NAME_1";
|
||||
private static final String TEST_HAP_DEVICE_NAME_2 = "Test_HAP_BT_Device_NAME_2";
|
||||
private static final String TEST_LE_AUDIO_DEVICE_NAME_1 = "Test_LE_AUDIO_Device_NAME_1";
|
||||
private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
|
||||
private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
|
||||
private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
|
||||
private static final String TEST_DEVICE_ADDRESS_4 = "00:D4:D4:D4:D4:D4";
|
||||
private static final String TEST_DEVICE_ADDRESS_5 = "00:E5:E5:E5:E5:E5";
|
||||
private static final String TEST_PACKAGE_NAME = "com.test.packagename";
|
||||
private static final String TEST_APPLICATION_LABEL = "APP Test Label";
|
||||
|
||||
@@ -109,6 +111,8 @@ public class MediaOutputPreferenceControllerTest {
|
||||
@Mock
|
||||
private HearingAidProfile mHearingAidProfile;
|
||||
@Mock
|
||||
private LeAudioProfile mLeAudioProfile;
|
||||
@Mock
|
||||
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
|
||||
@Mock
|
||||
private MediaSessionManager mMediaSessionManager;
|
||||
@@ -130,6 +134,7 @@ public class MediaOutputPreferenceControllerTest {
|
||||
private MediaOutputPreferenceController mController;
|
||||
private List<BluetoothDevice> mProfileConnectedDevices;
|
||||
private List<BluetoothDevice> mHearingAidActiveDevices;
|
||||
private List<BluetoothDevice> mLeAudioActiveDevices;
|
||||
private List<MediaController> mMediaControllers = new ArrayList<>();
|
||||
private MediaController.PlaybackInfo mPlaybackInfo;
|
||||
private PlaybackState mPlaybackState;
|
||||
@@ -170,12 +175,14 @@ public class MediaOutputPreferenceControllerTest {
|
||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
||||
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
||||
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
|
||||
|
||||
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||
|
||||
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
||||
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
|
||||
when(mBluetoothDevice.isConnected()).thenReturn(true);
|
||||
|
||||
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
|
||||
@@ -184,6 +191,7 @@ public class MediaOutputPreferenceControllerTest {
|
||||
|
||||
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
|
||||
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
|
||||
when(mLeftBluetoothHapDevice.getAlias()).thenReturn(TEST_HAP_DEVICE_NAME_1);
|
||||
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
|
||||
|
||||
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
|
||||
@@ -195,6 +203,7 @@ public class MediaOutputPreferenceControllerTest {
|
||||
mPreference = new Preference(mContext);
|
||||
mProfileConnectedDevices = new ArrayList<>();
|
||||
mHearingAidActiveDevices = new ArrayList<>(2);
|
||||
mLeAudioActiveDevices = new ArrayList<>();
|
||||
|
||||
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
|
||||
when(mScreen.getContext()).thenReturn(mContext);
|
||||
@@ -234,7 +243,6 @@ public class MediaOutputPreferenceControllerTest {
|
||||
* Preference summary should be device's name
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void updateState_withActiveBtDevice_setActivatedDeviceName() {
|
||||
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
@@ -254,7 +262,6 @@ public class MediaOutputPreferenceControllerTest {
|
||||
* Preference summary should be device's name
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
public void updateState_withActiveHADevice_setActivatedDeviceName() {
|
||||
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
@@ -269,6 +276,24 @@ public class MediaOutputPreferenceControllerTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_withActiveLeAudioDevice_setActivatedDeviceName() {
|
||||
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||
mProfileConnectedDevices.clear();
|
||||
mProfileConnectedDevices.add(mBluetoothDevice);
|
||||
mProfileConnectedDevices.add(mSecondBluetoothDevice);
|
||||
mLeAudioActiveDevices.clear();
|
||||
mLeAudioActiveDevices.add(mBluetoothDevice);
|
||||
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
|
||||
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
|
||||
|
||||
assertThat(mPreference.getSummary()).isNull();
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_noActiveLocalPlayback_noTitle() {
|
||||
mPlaybackState = new PlaybackState.Builder()
|
||||
@@ -350,6 +375,49 @@ public class MediaOutputPreferenceControllerTest {
|
||||
assertThat(mController.findActiveDevice()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findActiveDevice_allProfilesWithActiveDevice_returnHADevice() {
|
||||
BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
|
||||
when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||
mLeAudioActiveDevices.clear();
|
||||
mLeAudioActiveDevices.add(btLeDevice);
|
||||
mHearingAidActiveDevices.clear();
|
||||
mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
|
||||
when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
|
||||
when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
|
||||
|
||||
assertThat(mController.findActiveDevice()).isEqualTo(mLeftBluetoothHapDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findActiveDevice_a2dpDeviceAndLeAudioDeviceActive_returnLeAudioDevice() {
|
||||
BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
|
||||
when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||
mLeAudioActiveDevices.clear();
|
||||
mLeAudioActiveDevices.add(btLeDevice);
|
||||
mHearingAidActiveDevices.clear();
|
||||
when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
|
||||
when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
|
||||
|
||||
assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findActiveDevice_onlyLeAudioDeviceActive_returnLeAudioDevice() {
|
||||
BluetoothDevice btLeDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_5));
|
||||
when(btLeDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||
mLeAudioActiveDevices.clear();
|
||||
mLeAudioActiveDevices.add(btLeDevice);
|
||||
mHearingAidActiveDevices.clear();
|
||||
when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
|
||||
when(mA2dpProfile.getActiveDevice()).thenReturn(null);
|
||||
when(mLeAudioProfile.getActiveDevices()).thenReturn(mLeAudioActiveDevices);
|
||||
|
||||
assertThat(mController.findActiveDevice()).isEqualTo(btLeDevice);
|
||||
}
|
||||
|
||||
private void initPackage() {
|
||||
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||
mAppInfo = new ApplicationInfo();
|
||||
|
Reference in New Issue
Block a user