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
This commit is contained in:
Gavin Corkery
2020-05-27 13:02:58 +01:00
parent ff779f6d8e
commit 553c94bcab
2 changed files with 2 additions and 6 deletions

View File

@@ -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<String> 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;
}
}

View File

@@ -1113,6 +1113,7 @@ public class PackageWatchdogTest {
mTestLooper.dispatchAll();
List<Set> expectedSyncRequests = List.of(
Set.of(),
Set.of(APP_A),
Set.of(APP_A, APP_B),
Set.of(APP_A, APP_B, APP_C),