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

Commit bd3630d4 authored by Chun-Wei Wang's avatar Chun-Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix PackageWatchdog::syncRequestsAsync and related code."

parents a5369e31 1b85ccef
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -131,6 +131,10 @@ public class PackageWatchdog {
    @GuardedBy("mLock")
    private long mUptimeAtLastStateSync;

    private final Runnable mSyncRequests = this::syncRequests;
    private final Runnable mSyncStateWithScheduledReason = this::syncStateWithScheduledReason;
    private final Runnable mSaveToFile = this::saveToFile;

    private PackageWatchdog(Context context) {
        // Needs to be constructed inline
        this(context, new AtomicFile(
@@ -349,7 +353,7 @@ public class PackageWatchdog {
            // Must only run synchronous tasks as this runs on the ShutdownThread and no other
            // thread is guaranteed to run during shutdown.
            if (!mAllObservers.isEmpty()) {
                mLongTaskHandler.removeCallbacks(this::saveToFileAsync);
                mLongTaskHandler.removeCallbacks(mSaveToFile);
                pruneObserversLocked();
                saveToFile();
                Slog.i(TAG, "Last write to update package durations");
@@ -424,8 +428,8 @@ public class PackageWatchdog {
     * Serializes and syncs health check requests with the {@link ExplicitHealthCheckController}.
     */
    private void syncRequestsAsync() {
        mShortTaskHandler.removeCallbacks(this::syncRequests);
        mShortTaskHandler.post(this::syncRequests);
        mShortTaskHandler.removeCallbacks(mSyncRequests);
        mShortTaskHandler.post(mSyncRequests);
    }

    /**
@@ -569,14 +573,14 @@ public class PackageWatchdog {
    @GuardedBy("mLock")
    private void scheduleNextSyncStateLocked() {
        long durationMs = getNextStateSyncMillisLocked();
        mShortTaskHandler.removeCallbacks(this::syncStateWithScheduledReason);
        mShortTaskHandler.removeCallbacks(mSyncStateWithScheduledReason);
        if (durationMs == Long.MAX_VALUE) {
            Slog.i(TAG, "Cancelling state sync, nothing to sync");
            mUptimeAtLastStateSync = 0;
        } else {
            Slog.i(TAG, "Scheduling next state sync in " + durationMs + "ms");
            mUptimeAtLastStateSync = SystemClock.uptimeMillis();
            mShortTaskHandler.postDelayed(this::syncStateWithScheduledReason, durationMs);
            mShortTaskHandler.postDelayed(mSyncStateWithScheduledReason, durationMs);
        }
    }

@@ -802,8 +806,8 @@ public class PackageWatchdog {
    }

    private void saveToFileAsync() {
        if (!mLongTaskHandler.hasCallbacks(this::saveToFile)) {
            mLongTaskHandler.post(this::saveToFile);
        if (!mLongTaskHandler.hasCallbacks(mSaveToFile)) {
            mLongTaskHandler.post(mSaveToFile);
        }
    }