From c109e7477fd469ddf9587d8a30c01c303a61cc18 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Fri, 3 Mar 2023 23:06:56 +0000 Subject: [PATCH] Should call deviceGone for all the association Make sure clean up all the state by calling deviceGone for all the associaitons that associate with the package. Also enbale logs in CompanionDevicepresenceMonitor class. Fix: 271121491 Test: CTS Change-Id: Ibc2bebea378757e022038ec8e06cb4d03786dd9b --- .../CompanionApplicationController.java | 14 ++++++------- .../CompanionDevicePresenceMonitor.java | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/services/companion/java/com/android/server/companion/CompanionApplicationController.java b/services/companion/java/com/android/server/companion/CompanionApplicationController.java index 3814591dfce6b..5a9c4704aa7dc 100644 --- a/services/companion/java/com/android/server/companion/CompanionApplicationController.java +++ b/services/companion/java/com/android/server/companion/CompanionApplicationController.java @@ -346,31 +346,31 @@ public class CompanionApplicationController { // Make sure do not schedule rebind for the case ServiceConnector still gets callback after // app is uninstalled. boolean stillAssociated = false; + // Make sure to clean up the state for all the associations + // that associate with this package. + boolean shouldScheduleRebind = false; for (AssociationInfo ai : mAssociationStore.getAssociationsForPackage(userId, packageName)) { final int associationId = ai.getId(); stillAssociated = true; - if (ai.isSelfManaged()) { // Do not rebind if primary one is died for selfManaged application. if (isPrimary && mDevicePresenceMonitor.isDevicePresent(associationId)) { mDevicePresenceMonitor.onSelfManagedDeviceReporterBinderDied(associationId); - return false; + shouldScheduleRebind = false; } // Do not rebind if both primary and secondary services are died for // selfManaged application. - if (!isCompanionApplicationBound(userId, packageName)) { - return false; - } + shouldScheduleRebind = isCompanionApplicationBound(userId, packageName); } else if (ai.isNotifyOnDeviceNearby()) { // Always rebind for non-selfManaged devices. - return true; + shouldScheduleRebind = true; } } - return stillAssociated; + return stillAssociated && shouldScheduleRebind; } private class CompanionServicesRegister extends PerUser>> { 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 d7a77cd071167..4010be922b2c4 100644 --- a/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java +++ b/services/companion/java/com/android/server/companion/presence/CompanionDevicePresenceMonitor.java @@ -232,11 +232,14 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange } final boolean alreadyPresent = isDevicePresent(newDeviceAssociationId); - if (DEBUG && alreadyPresent) Log.i(TAG, "Device is already present."); + if (alreadyPresent) { + Log.i(TAG, "Device" + "id (" + newDeviceAssociationId + ") already present."); + } final boolean added = presentDevicesForSource.add(newDeviceAssociationId); - if (DEBUG && !added) { - Log.w(TAG, "Association with id " + newDeviceAssociationId + " is ALREADY reported as " + if (!added) { + Log.w(TAG, "Association with id " + + newDeviceAssociationId + " is ALREADY reported as " + "present by this source (" + sourceLoggingTag + ")"); } @@ -256,16 +259,17 @@ public class CompanionDevicePresenceMonitor implements AssociationStore.OnChange final boolean removed = presentDevicesForSource.remove(goneDeviceAssociationId); if (!removed) { - if (DEBUG) { - Log.w(TAG, "Association with id " + goneDeviceAssociationId + " was NOT reported " - + "as present by this source (" + sourceLoggingTag + ")"); - } + Log.w(TAG, "Association with id " + goneDeviceAssociationId + " was NOT reported " + + "as present by this source (" + sourceLoggingTag + ")"); + return; } final boolean stillPresent = isDevicePresent(goneDeviceAssociationId); if (stillPresent) { - if (DEBUG) Log.i(TAG, " Device is still present."); + if (DEBUG) { + Log.i(TAG, " Device id (" + goneDeviceAssociationId + ") is still present."); + } return; }