Merge "[LE Audio] Only add main device for LE Audio devices in Take call on list" into tm-qpr-dev am: 3030e61265
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/20265111 Change-Id: Ieb9cdefc4fd9f58c0fa75185986e5d71f9a5f495 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -53,6 +53,7 @@ import com.android.settingslib.core.lifecycle.events.OnStart;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
@@ -227,13 +228,29 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
|
|||||||
}
|
}
|
||||||
final List<BluetoothDevice> devices = leAudioProfile.getConnectedDevices();
|
final List<BluetoothDevice> devices = leAudioProfile.getConnectedDevices();
|
||||||
for (BluetoothDevice device : devices) {
|
for (BluetoothDevice device : devices) {
|
||||||
if (device.isConnected()) {
|
if (device.isConnected() && isDeviceInCachedList(device)) {
|
||||||
connectedDevices.add(device);
|
connectedDevices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return connectedDevices;
|
return connectedDevices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Confirm if the device exists in the cached devices list. If return true, it means
|
||||||
|
* the device is main device in the LE Audio device group. Otherwise, the device is the member
|
||||||
|
* device in the group.
|
||||||
|
*/
|
||||||
|
protected boolean isDeviceInCachedList(BluetoothDevice device) {
|
||||||
|
Collection<CachedBluetoothDevice> cachedDevices =
|
||||||
|
mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
|
||||||
|
for (CachedBluetoothDevice cachedDevice : cachedDevices) {
|
||||||
|
if (cachedDevice.getDevice().equals(device)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get hearing aid profile connected device, exclude other devices with same hiSyncId.
|
* get hearing aid profile connected device, exclude other devices with same hiSyncId.
|
||||||
*/
|
*/
|
||||||
|
@@ -51,6 +51,8 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
|||||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||||
import com.android.settingslib.bluetooth.HeadsetProfile;
|
import com.android.settingslib.bluetooth.HeadsetProfile;
|
||||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||||
@@ -71,6 +73,7 @@ import org.robolectric.shadows.ShadowBluetoothDevice;
|
|||||||
import org.robolectric.shadows.ShadowPackageManager;
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -103,6 +106,12 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
private HearingAidProfile mHearingAidProfile;
|
private HearingAidProfile mHearingAidProfile;
|
||||||
@Mock
|
@Mock
|
||||||
private LeAudioProfile mLeAudioProfile;
|
private LeAudioProfile mLeAudioProfile;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceL;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceR;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@@ -121,6 +130,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
private List<BluetoothDevice> mLeAudioActiveDevices;
|
private List<BluetoothDevice> mLeAudioActiveDevices;
|
||||||
private List<BluetoothDevice> mEmptyDevices;
|
private List<BluetoothDevice> mEmptyDevices;
|
||||||
private ShadowPackageManager mPackageManager;
|
private ShadowPackageManager mPackageManager;
|
||||||
|
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -135,6 +145,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
||||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||||
|
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||||
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
||||||
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
||||||
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
||||||
@@ -145,6 +156,11 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
||||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||||
|
|
||||||
|
mCachedDevices = new ArrayList<>();
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceL);
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceR);
|
||||||
|
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
|
||||||
|
|
||||||
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
||||||
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
||||||
when(mBluetoothDevice.isConnected()).thenReturn(true);
|
when(mBluetoothDevice.isConnected()).thenReturn(true);
|
||||||
@@ -397,6 +413,7 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedLeAudioDevices_connectedLeAudioDevice_shouldAddDeviceToList() {
|
public void getConnectedLeAudioDevices_connectedLeAudioDevice_shouldAddDeviceToList() {
|
||||||
|
when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
mEmptyDevices.clear();
|
mEmptyDevices.clear();
|
||||||
mProfileConnectedDevices.clear();
|
mProfileConnectedDevices.clear();
|
||||||
mProfileConnectedDevices.add(mBluetoothDevice);
|
mProfileConnectedDevices.add(mBluetoothDevice);
|
||||||
@@ -409,22 +426,45 @@ public class AudioOutputSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConnectedLeAudioDevices_disconnectedLeAudioDevice_shouldNotAddDeviceToList() {
|
public void getConnectedLeAudioDevices_disconnectedLeAudioDevice_shouldNotAddDeviceToList() {
|
||||||
BluetoothDevice connectdBtLeAduioDevice =
|
BluetoothDevice connectedBtLeAduioDevice =
|
||||||
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
|
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
|
||||||
when(connectdBtLeAduioDevice.isConnected()).thenReturn(true);
|
when(connectedBtLeAduioDevice.isConnected()).thenReturn(true);
|
||||||
BluetoothDevice disonnectdBtLeAduioDevice =
|
BluetoothDevice disconnectedBtLeAduioDevice =
|
||||||
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
|
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
|
||||||
when(disonnectdBtLeAduioDevice.isConnected()).thenReturn(false);
|
when(disconnectedBtLeAduioDevice.isConnected()).thenReturn(false);
|
||||||
|
when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
|
when(mCachedBluetoothDeviceR.getDevice()).thenReturn(connectedBtLeAduioDevice);
|
||||||
mEmptyDevices.clear();
|
mEmptyDevices.clear();
|
||||||
mProfileConnectedDevices.clear();
|
mProfileConnectedDevices.clear();
|
||||||
mProfileConnectedDevices.add(mBluetoothDevice);
|
mProfileConnectedDevices.add(mBluetoothDevice);
|
||||||
mProfileConnectedDevices.add(connectdBtLeAduioDevice);
|
mProfileConnectedDevices.add(connectedBtLeAduioDevice);
|
||||||
mProfileConnectedDevices.add(disonnectdBtLeAduioDevice);
|
mProfileConnectedDevices.add(disconnectedBtLeAduioDevice);
|
||||||
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
|
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
|
||||||
|
|
||||||
mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
|
mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
|
||||||
|
|
||||||
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, connectdBtLeAduioDevice);
|
assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, connectedBtLeAduioDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getConnectedLeAudioDevices_notInCachedDeviceList_shouldNotAddDeviceToList() {
|
||||||
|
BluetoothDevice connectedBtLeAduioDevice1 =
|
||||||
|
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
|
||||||
|
when(connectedBtLeAduioDevice1.isConnected()).thenReturn(true);
|
||||||
|
BluetoothDevice connectedBtLeAduioDevice2 =
|
||||||
|
spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
|
||||||
|
when(connectedBtLeAduioDevice2.isConnected()).thenReturn(true);
|
||||||
|
when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
|
when(mCachedBluetoothDeviceR.getDevice()).thenReturn(connectedBtLeAduioDevice1);
|
||||||
|
mEmptyDevices.clear();
|
||||||
|
mProfileConnectedDevices.clear();
|
||||||
|
mProfileConnectedDevices.add(connectedBtLeAduioDevice1);
|
||||||
|
mProfileConnectedDevices.add(connectedBtLeAduioDevice2);
|
||||||
|
when(mLeAudioProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
|
||||||
|
|
||||||
|
mEmptyDevices.addAll(mController.getConnectedLeAudioDevices());
|
||||||
|
|
||||||
|
assertThat(mEmptyDevices).containsExactly(connectedBtLeAduioDevice1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -45,6 +45,8 @@ import com.android.settings.bluetooth.Utils;
|
|||||||
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||||
import com.android.settingslib.bluetooth.HeadsetProfile;
|
import com.android.settingslib.bluetooth.HeadsetProfile;
|
||||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||||
@@ -63,6 +65,7 @@ import org.robolectric.annotation.Config;
|
|||||||
import org.robolectric.shadows.ShadowBluetoothDevice;
|
import org.robolectric.shadows.ShadowBluetoothDevice;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -100,6 +103,12 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
private LeAudioProfile mLeAudioProfile;
|
private LeAudioProfile mLeAudioProfile;
|
||||||
@Mock
|
@Mock
|
||||||
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
|
private AudioSwitchPreferenceController.AudioSwitchCallback mAudioSwitchPreferenceCallback;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceL;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceR;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@@ -117,6 +126,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
private List<BluetoothDevice> mProfileConnectedDevices;
|
private List<BluetoothDevice> mProfileConnectedDevices;
|
||||||
private List<BluetoothDevice> mHearingAidActiveDevices;
|
private List<BluetoothDevice> mHearingAidActiveDevices;
|
||||||
private List<BluetoothDevice> mLeAudioActiveDevices;
|
private List<BluetoothDevice> mLeAudioActiveDevices;
|
||||||
|
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -131,6 +141,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
|
|
||||||
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
||||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||||
|
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||||
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
|
||||||
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
||||||
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
|
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
|
||||||
@@ -138,6 +149,11 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
||||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||||
|
|
||||||
|
mCachedDevices = new ArrayList<>();
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceL);
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceR);
|
||||||
|
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
|
||||||
|
|
||||||
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
||||||
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
||||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
|
when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
|
||||||
@@ -480,6 +496,7 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
|
|||||||
public void updateState_leAudioDeviceActive_shouldSetActivatedDeviceName() {
|
public void updateState_leAudioDeviceActive_shouldSetActivatedDeviceName() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
|
||||||
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
|
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
|
||||||
|
when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
when(mBluetoothDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
when(mBluetoothDevice.getName()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||||
mProfileConnectedDevices.clear();
|
mProfileConnectedDevices.clear();
|
||||||
|
@@ -56,6 +56,8 @@ import com.android.settings.testutils.shadow.ShadowAudioManager;
|
|||||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||||
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
import com.android.settingslib.bluetooth.BluetoothEventManager;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
|
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||||
import com.android.settingslib.bluetooth.HearingAidProfile;
|
import com.android.settingslib.bluetooth.HearingAidProfile;
|
||||||
import com.android.settingslib.bluetooth.LeAudioProfile;
|
import com.android.settingslib.bluetooth.LeAudioProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
@@ -77,6 +79,7 @@ import org.robolectric.shadows.ShadowBluetoothDevice;
|
|||||||
import org.robolectric.shadows.ShadowPackageManager;
|
import org.robolectric.shadows.ShadowPackageManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -118,6 +121,12 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
private MediaSessionManager mMediaSessionManager;
|
private MediaSessionManager mMediaSessionManager;
|
||||||
@Mock
|
@Mock
|
||||||
private MediaController mMediaController;
|
private MediaController mMediaController;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceL;
|
||||||
|
@Mock
|
||||||
|
private CachedBluetoothDevice mCachedBluetoothDeviceR;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@@ -142,6 +151,7 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
private ApplicationInfo mAppInfo;
|
private ApplicationInfo mAppInfo;
|
||||||
private PackageInfo mPackageInfo;
|
private PackageInfo mPackageInfo;
|
||||||
private PackageStats mPackageStats;
|
private PackageStats mPackageStats;
|
||||||
|
private Collection<CachedBluetoothDevice> mCachedDevices;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -173,6 +183,7 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
|
|
||||||
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
|
||||||
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
|
||||||
|
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||||
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
|
||||||
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
|
||||||
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
|
when(mLocalBluetoothProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile);
|
||||||
@@ -180,6 +191,11 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
mBluetoothManager = mContext.getSystemService(BluetoothManager.class);
|
||||||
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
mBluetoothAdapter = mBluetoothManager.getAdapter();
|
||||||
|
|
||||||
|
mCachedDevices = new ArrayList<>();
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceL);
|
||||||
|
mCachedDevices.add(mCachedBluetoothDeviceR);
|
||||||
|
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
|
||||||
|
|
||||||
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
|
||||||
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
|
||||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
|
when(mBluetoothDevice.getAlias()).thenReturn(TEST_DEVICE_NAME_1);
|
||||||
@@ -280,6 +296,8 @@ public class MediaOutputPreferenceControllerTest {
|
|||||||
public void updateState_withActiveLeAudioDevice_setActivatedDeviceName() {
|
public void updateState_withActiveLeAudioDevice_setActivatedDeviceName() {
|
||||||
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
|
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLE_HEADSET);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
|
when(mCachedBluetoothDeviceL.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
|
when(mCachedBluetoothDeviceR.getDevice()).thenReturn(mSecondBluetoothDevice);
|
||||||
when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
when(mBluetoothDevice.getAlias()).thenReturn(TEST_LE_AUDIO_DEVICE_NAME_1);
|
||||||
mProfileConnectedDevices.clear();
|
mProfileConnectedDevices.clear();
|
||||||
mProfileConnectedDevices.add(mBluetoothDevice);
|
mProfileConnectedDevices.add(mBluetoothDevice);
|
||||||
|
Reference in New Issue
Block a user