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

Commit bfb96ce3 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Allow persistent observers to define packages they care about

If a persistent observer does not explicitly declare
that Package Watchdog should watch a package, it may
still start observing a failing package. Add a
method to the PackageHealthObserver interface that
allows an observer to define the conditions for which
it will start observing a package.

Test: n/a since no observers are currently persistent,
      current test pass
Bug: 136135457

Change-Id: I849d60e037248f0bbcd71b90b6c0cc3e6a68e5dc
parent 3ee1b172
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -448,6 +448,17 @@ public class PackageWatchdog {
        default boolean isPersistent() {
            return false;
        }

        /**
         * Returns {@code true} if this observer wishes to observe the given package, {@code false}
         * otherwise
         *
         * <p> A persistent observer may choose to start observing certain failing packages, even if
         * it has not explicitly asked to watch the package with {@link #startObservingHealth}.
         */
        default boolean mayObservePackage(String packageName) {
            return false;
        }
    }

    long getTriggerFailureCount() {
@@ -937,6 +948,11 @@ public class PackageWatchdog {
         */
        @GuardedBy("mLock")
        public boolean onPackageFailureLocked(String packageName) {
            if (packages.get(packageName) == null && registeredObserver.isPersistent()
                    && registeredObserver.mayObservePackage(packageName)) {
                packages.put(packageName, sPackageWatchdog.newMonitoredPackage(
                        packageName, DEFAULT_OBSERVING_DURATION_MS, false));
            }
            MonitoredPackage p = packages.get(packageName);
            if (p != null) {
                return p.onFailureLocked();