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

Commit b0488cc8 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix StorageController bugs.

1. StorageController was taking the return value of
setStorageNotLowConstraintSatisfied to be the previous value of the
constraint before the change. However, the return value indicates whether
or not the constraint changed. This meant that StorageController would
sometimes notify JobSchedulerService when a constraint hadn't actually
changed and would sometimes not notify JobSchedulerService when a
constraint had changed.

2. The calls to onRunJobNow and onControllerStateChanged both result in
JobSchedulerService iterating through the JobStore to identify jobs to
run. Calling both of them provides no benefit.

3. StorageController was listening for the STORAGE_LOW intent but wasn't
actually updating job statuses so jobs would continue to run after the
storage became low.

Bug: 125531072
Test: atest android.jobscheduler.cts.StorageConstraintTest
Change-Id: I10fa9bae3bdbd2545c15e5cab647a0820b9fbfa7
parent 407761a7
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -81,21 +81,17 @@ public final class StorageController extends StateController {
        synchronized (mLock) {
            for (int i = mTrackedTasks.size() - 1; i >= 0; i--) {
                final JobStatus ts = mTrackedTasks.valueAt(i);
                boolean previous = ts.setStorageNotLowConstraintSatisfied(storageNotLow);
                if (previous != storageNotLow) {
                    reportChange = true;
                }
                reportChange |= ts.setStorageNotLowConstraintSatisfied(storageNotLow);
            }
        }
        if (storageNotLow) {
            // Tell the scheduler that any ready jobs should be flushed.
            mStateChangedListener.onRunJobNow(null);
        } else if (reportChange) {
            // Let the scheduler know that state has changed. This may or may not result in an
            // execution.
        if (reportChange) {
            mStateChangedListener.onControllerStateChanged();
        }
        // Also tell the scheduler that any ready jobs should be flushed.
        if (storageNotLow) {
            mStateChangedListener.onRunJobNow(null);
        }
    }

    public final class StorageTracker extends BroadcastReceiver {
@@ -143,9 +139,10 @@ public final class StorageController extends StateController {
                            + sElapsedRealtimeClock.millis());
                }
                mStorageLow = true;
                maybeReportNewStorageState();
            } else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(action)) {
                if (DEBUG) {
                    Slog.d(TAG, "Available stoage high enough to do work. @ "
                    Slog.d(TAG, "Available storage high enough to do work. @ "
                            + sElapsedRealtimeClock.millis());
                }
                mStorageLow = false;