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

Commit 48e93165 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Avoid potential reboot loop due to package cache

Bug: 64295061

Test: Boot (write package cache) and reboot (read package cache)
Change-Id: I5de712c9666bac71ff6121001163ebc90c4b62d0
parent fac2141f
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -1120,12 +1120,12 @@ public class PackageParser {
        final String cacheKey = getCacheKey(packageFile, flags);
        final File cacheFile = new File(mCacheDir, cacheKey);

        try {
            // If the cache is not up to date, return null.
            if (!isCacheUpToDate(packageFile, cacheFile)) {
                return null;
            }

        try {
            final byte[] bytes = IoUtils.readFileAsByteArray(cacheFile.getAbsolutePath());
            Package p = fromCacheEntry(bytes);
            if (mCallback != null) {
@@ -1140,7 +1140,7 @@ public class PackageParser {
                }
            }
            return p;
        } catch (Exception e) {
        } catch (Throwable e) {
            Slog.w(TAG, "Error reading package cache: ", e);

            // If something went wrong while reading the cache entry, delete the cache file
@@ -1158,6 +1158,7 @@ public class PackageParser {
            return;
        }

        try {
            final String cacheKey = getCacheKey(packageFile, flags);
            final File cacheFile = new File(mCacheDir, cacheKey);

@@ -1179,6 +1180,9 @@ public class PackageParser {
                Slog.w(TAG, "Error writing cache entry.", ioe);
                cacheFile.delete();
            }
        } catch (Throwable e) {
            Slog.w(TAG, "Error saving package cache.", e);
        }
    }

    /**