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

Commit 9b4ec7c8 authored by Kweku Adams's avatar Kweku Adams
Browse files

Avoid loading duplicate jobs.

If the persisted files have somehow accumulated duplicate versions of
the same job (identified by uid-namespace-jobId), then drop the
duplicates and only keep one.

Bug: 289062813
Bug: 296890885
Test: atest JobStoreTest
Change-Id: I3179261309031801f0506cf905206376e59af1fe
(cherry picked from commit c8fbd937)
Merged-In: I3179261309031801f0506cf905206376e59af1fe
parent ef2cbcd7
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1118,6 +1118,7 @@ public final class JobStore {
            }
            boolean needFileMigration = false;
            long nowElapsed = sElapsedRealtimeClock.millis();
            int numDuplicates = 0;
            synchronized (mLock) {
                for (File file : files) {
                    final AtomicFile aFile = createJobFile(file);
@@ -1126,6 +1127,16 @@ public final class JobStore {
                        if (jobs != null) {
                            for (int i = 0; i < jobs.size(); i++) {
                                JobStatus js = jobs.get(i);
                                final JobStatus existingJob = this.jobSet.get(
                                        js.getUid(), js.getNamespace(), js.getJobId());
                                if (existingJob != null) {
                                    numDuplicates++;
                                    // Jobs are meant to have unique uid-namespace-jobId
                                    // combinations, but we've somehow read multiple jobs with the
                                    // combination. Drop the latter one since keeping both will
                                    // result in other issues.
                                    continue;
                                }
                                js.prepareLocked();
                                js.enqueueTime = nowElapsed;
                                this.jobSet.add(js);
@@ -1174,6 +1185,10 @@ public final class JobStore {
                migrateJobFilesAsync();
            }

            if (numDuplicates > 0) {
                Slog.wtf(TAG, "Encountered " + numDuplicates + " duplicate persisted jobs");
            }

            // Log the count immediately after loading from boot.
            mCurrentJobSetSize = numJobs;
            mScheduledJob30MinHighWaterMark = mCurrentJobSetSize;