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

Commit 7ef490fa authored by Shreyas Basarge's avatar Shreyas Basarge
Browse files

Fix for non persisted jobs being persisted

Bug: 25905179
Change-Id: I5e836f9894089aa8acc1bde382674e29402f0a60
parent b3958d76
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.
     */