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

Commit a1703c21 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid loading duplicate jobs." into udc-qpr-dev

parents 010805ee b74d32fa
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;