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

Commit d19c5c14 authored by Shreyas Basarge's avatar Shreyas Basarge Committed by Android (Google) Code Review
Browse files

Merge "Fix for non persisted jobs being persisted"

parents a51878d3 7ef490fa
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -278,6 +278,11 @@ public class JobStore {
                // Copy over the jobs so we can release the lock before writing.
                for (int i=0; i<mJobSet.size(); i++) {
                    JobStatus jobStatus = mJobSet.valueAt(i);

                    if (!jobStatus.isPersisted()){
                        continue;
                    }

                    JobStatus copy = new JobStatus(jobStatus.getJob(), jobStatus.getUid(),
                            jobStatus.getEarliestRunTime(), jobStatus.getLatestRunTimeElapsed());
                    mStoreCopy.add(copy);
+22 −0
Original line number Diff line number Diff line
@@ -182,6 +182,28 @@ public class JobStoreTest extends AndroidTestCase {
                loaded.getEarliestRunTime() <= newNowElapsed + TEN_SECONDS*2);
    }

    /**
     * Test that non persisted job is not written to disk.
     */
    public void testNonPersistedTaskIsNotPersisted() throws Exception {
        JobInfo.Builder b = new Builder(42, mComponent)
                .setOverrideDeadline(10000)
                .setPersisted(false);
        JobStatus jsNonPersisted = new JobStatus(b.build(), SOME_UID);
        mTaskStoreUnderTest.add(jsNonPersisted);
        b = new Builder(43, mComponent)
                .setOverrideDeadline(10000)
                .setPersisted(true);
        JobStatus jsPersisted = new JobStatus(b.build(), SOME_UID);
        mTaskStoreUnderTest.add(jsPersisted);
        Thread.sleep(IO_WAIT);
        final ArraySet<JobStatus> jobStatusSet = new ArraySet<JobStatus>();
        mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
        assertEquals("Job count is incorrect.", 1, jobStatusSet.size());
        JobStatus jobStatus = jobStatusSet.iterator().next();
        assertEquals("Wrong job persisted.", 43, jobStatus.getJobId());
    }

    /**
     * Helper function to throw an error if the provided task and TaskStatus objects are not equal.
     */