Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3d2ada2 authored by Zimuzo's avatar Zimuzo
Browse files

Fix taking actions without considering pending health checks

Now, we consider if we are expecting a health check result before
taking the following actions:
1. Requesting explicit health checks: Otherwise if a package has
failed health checks, we would keep requesting unnecessary health
checks from the health check service
2. Scheduling next sync: Otherwise, even after a package has passed or
failed health checks, we could keep scheduling shorter syncs than
required

Test: atest PackageWatchdogTest
Bug: 132168914
Change-Id: I817e14b6d4fa563d1c22af6ffb0461f3693a49b4
parent 3415499a
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -529,8 +529,7 @@ public class PackageWatchdog {
            while (pit.hasNext()) {
                MonitoredPackage monitoredPackage = pit.next();
                String packageName = monitoredPackage.getName();
                if (monitoredPackage.getHealthCheckStateLocked()
                        != MonitoredPackage.STATE_PASSED) {
                if (monitoredPackage.isPendingHealthChecksLocked()) {
                    packages.add(packageName);
                }
            }
@@ -1093,7 +1092,10 @@ public class PackageWatchdog {
         */
        @GuardedBy("mLock")
        public long getShortestScheduleDurationMsLocked() {
            return Math.min(toPositive(mDurationMs), toPositive(mHealthCheckDurationMs));
            // Consider health check duration only if #isPendingHealthChecksLocked is true
            return Math.min(toPositive(mDurationMs),
                    isPendingHealthChecksLocked()
                    ? toPositive(mHealthCheckDurationMs) : Long.MAX_VALUE);
        }

        /**
@@ -1105,6 +1107,15 @@ public class PackageWatchdog {
            return mDurationMs <= 0;
        }

        /**
         * Returns {@code true} if the package, {@link #getName} is expecting health check results
         * {@code false} otherwise.
         */
        @GuardedBy("mLock")
        public boolean isPendingHealthChecksLocked() {
            return mHealthCheckState == STATE_ACTIVE || mHealthCheckState == STATE_INACTIVE;
        }

        /**
         * Updates the health check state based on {@link #mHasPassedHealthCheck}
         * and {@link #mHealthCheckDurationMs}.