From 287a66e52df65d60e72e8bcee729c6caf2f8f112 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Mon, 9 May 2022 10:47:49 -0700 Subject: [PATCH] Only update the current connected set for selfManaged only Bug: 230668833 Test: Manually tested the behavior on test app Change-Id: I1565a42f3397d706f06a3cfd613226f2f1c30c08 --- .../CompanionDeviceManagerService.java | 11 +++++----- .../CompanionDevicePresenceMonitor.java | 21 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 2a22cac75ae08..9b2554fdbb3c2 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -292,14 +292,13 @@ public class CompanionDeviceManagerService extends SystemService { private boolean onCompanionApplicationBindingDiedInternal( @UserIdInt int userId, @NonNull String packageName) { - // Update the current connected devices sets when binderDied, so that application is able - // to call notifyDeviceAppeared after re-launch the application. for (AssociationInfo ai : mAssociationStore.getAssociationsForPackage(userId, packageName)) { - int id = ai.getId(); - Slog.i(TAG, "Removing association id: " + id + " for package: " - + packageName + " due to binderDied."); - mDevicePresenceMonitor.removeDeviceFromMonitoring(id); + final int associationId = ai.getId(); + if (ai.isSelfManaged() + && mDevicePresenceMonitor.isDevicePresent(associationId)) { + mDevicePresenceMonitor.onSelfManagedDeviceReporterBinderDied(associationId); + } } // TODO(b/218613015): implement. return false; diff --git a/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java b/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java index 37e83697c7874..89ed301eb6611 100644 --- a/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java +++ b/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java @@ -149,6 +149,13 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange onDeviceGone(mReportedSelfManagedDevices, associationId, "application-reported"); } + /** + * Marks a "self-managed" device as disconnected when binderDied. + */ + public void onSelfManagedDeviceReporterBinderDied(int associationId) { + onDeviceGone(mReportedSelfManagedDevices, associationId, "application-reported"); + } + @Override public void onBluetoothCompanionDeviceConnected(int associationId) { onDevicePresent(mConnectedBtDevices, associationId, /* sourceLoggingTag */ "bt"); @@ -258,16 +265,6 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange mCallback.onDeviceDisappeared(goneDeviceAssociationId); } - /** - * Remove the current connected devices by associationId. - */ - public void removeDeviceFromMonitoring(int associationId) { - mConnectedBtDevices.remove(associationId); - mNearbyBleDevices.remove(associationId); - mReportedSelfManagedDevices.remove(associationId); - mSimulated.remove(associationId); - } - /** * Implements * {@link AssociationStore.OnChangeListener#onAssociationRemoved(AssociationInfo)} @@ -280,7 +277,9 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange Log.d(TAG, " > association=" + association); } - removeDeviceFromMonitoring(id); + mConnectedBtDevices.remove(id); + mNearbyBleDevices.remove(id); + mReportedSelfManagedDevices.remove(id); // Do NOT call mCallback.onDeviceDisappeared()! // CompanionDeviceManagerService will know that the association is removed, and will do