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

Commit ba22887a authored by Kweku Adams's avatar Kweku Adams
Browse files

Avoid relocking.

Acquire the lock once when loading persisted jobs instead of for each
separate file.

Bug: 259342534
Test: Reboot device and confirm jobs are loaded
Change-Id: Ice30194a1a6e34380483dc8f932054fb516cec4e
parent 404b7181
Loading
Loading
Loading
Loading
+29 −27
Original line number Original line Diff line number Diff line
@@ -1033,10 +1033,10 @@ public final class JobStore {
            }
            }
            boolean needFileMigration = false;
            boolean needFileMigration = false;
            long nowElapsed = sElapsedRealtimeClock.millis();
            long nowElapsed = sElapsedRealtimeClock.millis();
            synchronized (mLock) {
                for (File file : files) {
                for (File file : files) {
                    final AtomicFile aFile = createJobFile(file);
                    final AtomicFile aFile = createJobFile(file);
                    try (FileInputStream fis = aFile.openRead()) {
                    try (FileInputStream fis = aFile.openRead()) {
                    synchronized (mLock) {
                        jobs = readJobMapImpl(fis, rtcGood, nowElapsed);
                        jobs = readJobMapImpl(fis, rtcGood, nowElapsed);
                        if (jobs != null) {
                        if (jobs != null) {
                            for (int i = 0; i < jobs.size(); i++) {
                            for (int i = 0; i < jobs.size(); i++) {
@@ -1054,26 +1054,27 @@ public final class JobStore {
                                }
                                }
                            }
                            }
                        }
                        }
                    }
                    } catch (FileNotFoundException e) {
                    } catch (FileNotFoundException e) {
                        // mJobFileDirectory.listFiles() gave us this file...why can't we find it???
                        // mJobFileDirectory.listFiles() gave us this file...why can't we find it???
                        Slog.e(TAG, "Could not find jobs file: " + file.getName());
                        Slog.e(TAG, "Could not find jobs file: " + file.getName());
                    } catch (XmlPullParserException | IOException e) {
                    } catch (XmlPullParserException | IOException e) {
                        Slog.wtf(TAG, "Error in " + file.getName(), e);
                        Slog.wtf(TAG, "Error in " + file.getName(), e);
                    } catch (Exception e) {
                    } catch (Exception e) {
                    // Crashing at this point would result in a boot loop, so live with a general
                        // Crashing at this point would result in a boot loop, so live with a
                    // Exception for system stability's sake.
                        // generic Exception for system stability's sake.
                        Slog.wtf(TAG, "Unexpected exception", e);
                        Slog.wtf(TAG, "Unexpected exception", e);
                    }
                    }
                    if (mUseSplitFiles) {
                    if (mUseSplitFiles) {
                        if (!file.getName().startsWith(JOB_FILE_SPLIT_PREFIX)) {
                        if (!file.getName().startsWith(JOB_FILE_SPLIT_PREFIX)) {
                        // We're supposed to be using the split file architecture, but we still have
                            // We're supposed to be using the split file architecture,
                            // but we still have
                            // the old job file around. Fully migrate and remove the old file.
                            // the old job file around. Fully migrate and remove the old file.
                            needFileMigration = true;
                            needFileMigration = true;
                        }
                        }
                    } else if (file.getName().startsWith(JOB_FILE_SPLIT_PREFIX)) {
                    } else if (file.getName().startsWith(JOB_FILE_SPLIT_PREFIX)) {
                    // We're supposed to be using the legacy single file architecture, but we still
                        // We're supposed to be using the legacy single file architecture,
                    // have some job split files around. Fully migrate and remove the split files.
                        // but we still have some job split files around. Fully migrate
                        // and remove the split files.
                        needFileMigration = true;
                        needFileMigration = true;
                    }
                    }
                }
                }
@@ -1082,6 +1083,7 @@ public final class JobStore {
                    mPersistInfo.countSystemServerJobsLoaded = numSystemJobs;
                    mPersistInfo.countSystemServerJobsLoaded = numSystemJobs;
                    mPersistInfo.countSystemSyncManagerJobsLoaded = numSyncJobs;
                    mPersistInfo.countSystemSyncManagerJobsLoaded = numSyncJobs;
                }
                }
            }
            Slog.i(TAG, "Read " + numJobs + " jobs");
            Slog.i(TAG, "Read " + numJobs + " jobs");
            if (needFileMigration) {
            if (needFileMigration) {
                migrateJobFilesAsync();
                migrateJobFilesAsync();