Fix usage of the updated CDM APIs
Bug: 194301022 Test: make Change-Id: I70633f43d37fdeec8329e0c58f7cffa402dba689
This commit is contained in:
@@ -31,11 +31,13 @@ import android.app.INotificationManager;
|
||||
import android.app.role.RoleManager;
|
||||
import android.app.usage.UsageEvents;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.companion.AssociationInfo;
|
||||
import android.companion.ICompanionDeviceManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.MacAddress;
|
||||
import android.os.Parcel;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -234,8 +236,9 @@ public class NotificationBackendTest {
|
||||
|
||||
@Test
|
||||
public void getDeviceList_associationsButNoDevice() throws Exception {
|
||||
List<String> macs = ImmutableList.of("00:00:00:00:00:10", "00:00:00:00:00:20");
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(macs);
|
||||
List<AssociationInfo> associations =
|
||||
mockAssociations("00:00:00:00:00:10", "00:00:00:00:00:20");
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(associations);
|
||||
|
||||
when(mCbm.getCachedDevicesCopy()).thenReturn(new ArrayList<>());
|
||||
|
||||
@@ -245,12 +248,13 @@ public class NotificationBackendTest {
|
||||
|
||||
@Test
|
||||
public void getDeviceList_singleDevice() throws Exception {
|
||||
List<String> macs = ImmutableList.of("00:00:00:00:00:10", "00:00:00:00:00:20");
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(macs);
|
||||
String[] macs = { "00:00:00:00:00:10", "00:00:00:00:00:20" };
|
||||
List<AssociationInfo> associations = mockAssociations(macs);
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(associations);
|
||||
|
||||
Collection<CachedBluetoothDevice> cachedDevices = new ArrayList<>();
|
||||
CachedBluetoothDevice cbd1 = mock(CachedBluetoothDevice.class);
|
||||
when(cbd1.getAddress()).thenReturn(macs.get(0));
|
||||
when(cbd1.getAddress()).thenReturn(macs[0]);
|
||||
when(cbd1.getName()).thenReturn("Device 1");
|
||||
cachedDevices.add(cbd1);
|
||||
when(mCbm.getCachedDevicesCopy()).thenReturn(cachedDevices);
|
||||
@@ -261,17 +265,18 @@ public class NotificationBackendTest {
|
||||
|
||||
@Test
|
||||
public void getDeviceList_multipleDevices() throws Exception {
|
||||
List<String> macs = ImmutableList.of("00:00:00:00:00:10", "00:00:00:00:00:20");
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(macs);
|
||||
String[] macs = { "00:00:00:00:00:10", "00:00:00:00:00:20" };
|
||||
List<AssociationInfo> associations = mockAssociations(macs);
|
||||
when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(associations);
|
||||
|
||||
Collection<CachedBluetoothDevice> cachedDevices = new ArrayList<>();
|
||||
CachedBluetoothDevice cbd1 = mock(CachedBluetoothDevice.class);
|
||||
when(cbd1.getAddress()).thenReturn(macs.get(0));
|
||||
when(cbd1.getAddress()).thenReturn(macs[0]);
|
||||
when(cbd1.getName()).thenReturn("Device 1");
|
||||
cachedDevices.add(cbd1);
|
||||
|
||||
CachedBluetoothDevice cbd2 = mock(CachedBluetoothDevice.class);
|
||||
when(cbd2.getAddress()).thenReturn(macs.get(1));
|
||||
when(cbd2.getAddress()).thenReturn(macs[1]);
|
||||
when(cbd2.getName()).thenReturn("Device 2");
|
||||
cachedDevices.add(cbd2);
|
||||
when(mCbm.getCachedDevicesCopy()).thenReturn(cachedDevices);
|
||||
@@ -279,4 +284,16 @@ public class NotificationBackendTest {
|
||||
assertThat(new NotificationBackend().getDeviceList(
|
||||
mCdm, mBm, mCn.getPackageName(), 0).toString()).isEqualTo("Device 1, Device 2");
|
||||
}
|
||||
|
||||
private ImmutableList<AssociationInfo> mockAssociations(String... macAddresses) {
|
||||
final AssociationInfo[] associations = new AssociationInfo[macAddresses.length];
|
||||
for (int index = 0; index < macAddresses.length; index++) {
|
||||
final AssociationInfo association = mock(AssociationInfo.class);
|
||||
when(association.isSelfManaged()).thenReturn(false);
|
||||
when(association.getDeviceMacAddress())
|
||||
.thenReturn(MacAddress.fromString(macAddresses[index]));
|
||||
associations[index] = association;
|
||||
}
|
||||
return ImmutableList.copyOf(associations);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user