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

Commit cda01bf5 authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "Don't persist dynamic constraints."

parents 11f5edcb 959db93d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -832,8 +832,8 @@ public final class JobStore {
        private void writeConstraintsToXml(TypedXmlSerializer out, JobStatus jobStatus)
                throws IOException {
            out.startTag(null, XML_TAG_PARAMS_CONSTRAINTS);
            if (jobStatus.hasConnectivityConstraint()) {
            final JobInfo job = jobStatus.getJob();
            if (jobStatus.hasConnectivityConstraint()) {
                final NetworkRequest network = jobStatus.getJob().getRequiredNetwork();
                out.attribute(null, "net-capabilities-csv", intArrayToString(
                        network.getCapabilities()));
@@ -854,16 +854,16 @@ public final class JobStore {
                            job.getMinimumNetworkChunkBytes());
                }
            }
            if (jobStatus.hasIdleConstraint()) {
            if (job.isRequireDeviceIdle()) {
                out.attribute(null, "idle", Boolean.toString(true));
            }
            if (jobStatus.hasChargingConstraint()) {
            if (job.isRequireCharging()) {
                out.attribute(null, "charging", Boolean.toString(true));
            }
            if (jobStatus.hasBatteryNotLowConstraint()) {
            if (job.isRequireBatteryNotLow()) {
                out.attribute(null, "battery-not-low", Boolean.toString(true));
            }
            if (jobStatus.hasStorageNotLowConstraint()) {
            if (job.isRequireStorageNotLow()) {
                out.attribute(null, "storage-not-low", Boolean.toString(true));
            }
            out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS);
+12 −5
Original line number Diff line number Diff line
@@ -96,10 +96,16 @@ public final class JobStatus {
    public static final long NO_LATEST_RUNTIME = Long.MAX_VALUE;
    public static final long NO_EARLIEST_RUNTIME = 0L;

    static final int CONSTRAINT_CHARGING = JobInfo.CONSTRAINT_FLAG_CHARGING; // 1 < 0
    static final int CONSTRAINT_IDLE = JobInfo.CONSTRAINT_FLAG_DEVICE_IDLE;  // 1 << 2
    static final int CONSTRAINT_BATTERY_NOT_LOW = JobInfo.CONSTRAINT_FLAG_BATTERY_NOT_LOW; // 1 << 1
    static final int CONSTRAINT_STORAGE_NOT_LOW = JobInfo.CONSTRAINT_FLAG_STORAGE_NOT_LOW; // 1 << 3
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public static final int CONSTRAINT_CHARGING = JobInfo.CONSTRAINT_FLAG_CHARGING; // 1 < 0
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public static final int CONSTRAINT_IDLE = JobInfo.CONSTRAINT_FLAG_DEVICE_IDLE;  // 1 << 2
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public static final int CONSTRAINT_BATTERY_NOT_LOW =
            JobInfo.CONSTRAINT_FLAG_BATTERY_NOT_LOW; // 1 << 1
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public static final int CONSTRAINT_STORAGE_NOT_LOW =
            JobInfo.CONSTRAINT_FLAG_STORAGE_NOT_LOW; // 1 << 3
    public static final int CONSTRAINT_TIMING_DELAY = 1 << 31;
    public static final int CONSTRAINT_DEADLINE = 1 << 30;
    public static final int CONSTRAINT_CONNECTIVITY = 1 << 28;
@@ -1820,7 +1826,8 @@ public final class JobStatus {
     * separately from the job's explicitly requested constraints and MUST be satisfied before
     * the job can run if the app doesn't have quota.
     */
    private void addDynamicConstraints(int constraints) {
    @VisibleForTesting
    public void addDynamicConstraints(int constraints) {
        if ((constraints & CONSTRAINT_WITHIN_QUOTA) != 0) {
            // Quota should never be used as a dynamic constraint.
            Slog.wtf(TAG, "Tried to set quota as a dynamic constraint");
+29 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import static android.net.NetworkCapabilities.TRANSPORT_WIFI;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
@@ -208,6 +209,34 @@ public class JobStoreTest {
        assertEquals("Incorrect # of persisted tasks.", 0, jobStatusSet.size());
    }

    /**
     * Test that dynamic constraints aren't written to disk.
     */
    @Test
    public void testDynamicConstraintsNotPersisted() throws Exception {
        JobInfo.Builder b = new Builder(42, mComponent).setPersisted(true);
        JobStatus js = JobStatus.createFromJobInfo(b.build(), SOME_UID, null, -1, null, null);
        js.addDynamicConstraints(JobStatus.CONSTRAINT_BATTERY_NOT_LOW
                | JobStatus.CONSTRAINT_CHARGING
                | JobStatus.CONSTRAINT_IDLE
                | JobStatus.CONSTRAINT_STORAGE_NOT_LOW);
        assertTrue(js.hasBatteryNotLowConstraint());
        assertTrue(js.hasChargingConstraint());
        assertTrue(js.hasIdleConstraint());
        assertTrue(js.hasStorageNotLowConstraint());
        mTaskStoreUnderTest.add(js);
        waitForPendingIo();

        final JobSet jobStatusSet = new JobSet();
        mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet, true);
        assertEquals("Job count is incorrect.", 1, jobStatusSet.size());
        JobStatus loaded = jobStatusSet.getAllJobs().iterator().next();
        assertFalse(loaded.hasBatteryNotLowConstraint());
        assertFalse(loaded.hasChargingConstraint());
        assertFalse(loaded.hasIdleConstraint());
        assertFalse(loaded.hasStorageNotLowConstraint());
    }

    @Test
    public void testExtractUidFromJobFileName() {
        File file = new File(mTestContext.getFilesDir(), "randomName");