From 553c94bcabce0fb449a97da502969b20d1cffd16 Mon Sep 17 00:00:00 2001 From: Gavin Corkery Date: Wed, 27 May 2020 13:02:58 +0100 Subject: [PATCH] Ensure that health check controller is unbound correctly Explicitly call into the health check controller if there are no more packages to check. This is due to the fact that the ExplicitHealthCheckController will unbind itself in this case. If this call is not made, the controller will continue running in the foreground and will not be killed by lmkd. Test: atest PackageWatchdogTest Test: check logcat to see that the service is unbound Bug: 156323728 Change-Id: I0044d0832178ee90043d5e64e406df07ee2c36a2 --- services/core/java/com/android/server/PackageWatchdog.java | 7 +------ .../src/com/android/server/PackageWatchdogTest.java | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/PackageWatchdog.java b/services/core/java/com/android/server/PackageWatchdog.java index e77458cc955a1..e303f0d002143 100644 --- a/services/core/java/com/android/server/PackageWatchdog.java +++ b/services/core/java/com/android/server/PackageWatchdog.java @@ -177,9 +177,6 @@ public class PackageWatchdog { // 0 if no prune is scheduled. @GuardedBy("mLock") private long mUptimeAtLastStateSync; - // If true, sync explicit health check packages with the ExplicitHealthCheckController. - @GuardedBy("mLock") - private boolean mSyncRequired = false; @FunctionalInterface @VisibleForTesting @@ -255,7 +252,6 @@ public class PackageWatchdog { */ public void registerHealthObserver(PackageHealthObserver observer) { synchronized (mLock) { - mSyncRequired = true; ObserverInternal internalObserver = mAllObservers.get(observer.getName()); if (internalObserver != null) { internalObserver.registeredObserver = observer; @@ -642,7 +638,7 @@ public class PackageWatchdog { synchronized (mLock) { if (mIsPackagesReady) { Set packages = getPackagesPendingHealthChecksLocked(); - if (!packages.equals(mRequestedHealthCheckPackages) || mSyncRequired) { + if (!packages.equals(mRequestedHealthCheckPackages) || packages.isEmpty()) { syncRequired = true; mRequestedHealthCheckPackages = packages; } @@ -654,7 +650,6 @@ public class PackageWatchdog { Slog.i(TAG, "Syncing health check requests for packages: " + mRequestedHealthCheckPackages); mHealthCheckController.syncRequests(mRequestedHealthCheckPackages); - mSyncRequired = false; } } diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java index d011dbbbe5dba..ae93a81f274ea 100644 --- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java +++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java @@ -1113,6 +1113,7 @@ public class PackageWatchdogTest { mTestLooper.dispatchAll(); List expectedSyncRequests = List.of( + Set.of(), Set.of(APP_A), Set.of(APP_A, APP_B), Set.of(APP_A, APP_B, APP_C),