diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsController.java b/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsController.java index 73360f13a88..272d142e3e8 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsController.java @@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.UserHandle; import android.provider.DeviceConfig; import android.text.TextUtils; import android.util.Log; @@ -126,8 +127,8 @@ public class BluetoothDetailsCompanionAppsController extends BluetoothDetailsCon try { java.util.Objects.requireNonNull(ICompanionDeviceManager.Stub.asInterface( ServiceManager.getService( - Context.COMPANION_DEVICE_SERVICE))).disassociate( - address, packageName); + Context.COMPANION_DEVICE_SERVICE))).legacyDisassociate( + address, packageName, UserHandle.myUserId()); } catch (RemoteException e) { throw new RuntimeException(e); } diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 1af8867acd5..cae3cae9286 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -54,6 +54,7 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; +import com.android.internal.util.CollectionUtils; import com.android.settingslib.R; import com.android.settingslib.Utils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; @@ -159,7 +160,9 @@ public class NotificationBackend { StringBuilder sb = new StringBuilder(); try { - List associatedMacAddrs = cdm.getAssociations(pkg, userId); + List associatedMacAddrs = CollectionUtils.mapNotNull( + cdm.getAssociations(pkg, userId), + a -> a.isSelfManaged() ? null : a.getDeviceMacAddress().toString()); if (associatedMacAddrs != null) { for (String assocMac : associatedMacAddrs) { final Collection cachedDevices = diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsControllerTest.java index 1d5aa549ac5..0f7bf20b9f7 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsControllerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsCompanionAppsControllerTest.java @@ -24,9 +24,9 @@ import static org.mockito.Mockito.when; import android.companion.AssociationInfo; import android.companion.CompanionDeviceManager; -import android.companion.DeviceId; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.net.MacAddress; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -100,15 +100,14 @@ public class BluetoothDetailsCompanionAppsControllerTest extends setupFakeLabelAndInfo(packageName, appName); final int associationId = mAssociations.size() + 1; - final DeviceId deviceId = - new DeviceId(DeviceId.TYPE_MAC_ADDRESS, mCachedDevice.getAddress()); final AssociationInfo association = new AssociationInfo( associationId, /* userId */ 0, packageName, - Arrays.asList(deviceId), + MacAddress.fromString(mCachedDevice.getAddress()), + /* displayName */ null, /* deviceProfile */ "", - /* managedByCompanionApp */ false, + /* selfManaged */ false, /* notifyOnDeviceNearby */ true, /* timeApprovedMs */ System.currentTimeMillis()); diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java index 063be35fe77..71fab426e9d 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java @@ -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 macs = ImmutableList.of("00:00:00:00:00:10", "00:00:00:00:00:20"); - when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(macs); + List 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 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 associations = mockAssociations(macs); + when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(associations); Collection 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 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 associations = mockAssociations(macs); + when(mCdm.getAssociations(mCn.getPackageName(), 0)).thenReturn(associations); Collection 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 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); + } }