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

Commit 45fb6c68 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Handle corrupt packages.xml

If the device hard reboots or is otherwise killed
between write and fsync of packages.xml, it can write all zeros. This is
not a problem in most cases as packages.xml is renamed to
packages-backup.xml before writing begins. In the case (boot after a
failed first boot) that a packages.xml does not exist, we may read that
all 0 packages.xml. In such a case we will encounter IOExceptions and
will not get the opportunity to build the VersionInfos that we require
later during boot.

This change adds a finally block for those exception cases to populate
the VersionInfos to adequately handle subsequent stages of boot.

Fixes: 178518634
Bug: 178518634
Test: manual; adb shell 'stop; rm /data/system/packages.xml; fallocate -l 1K /data/system/packages.xml; start'
Change-Id: I532b2bcd5b739345c8cd2e3f3a3d9a6393f68fba
parent 7c6e169d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -3189,6 +3189,17 @@ public final class Settings implements Watchable, Snappable {
            mReadMessages.append("Error reading: " + e.toString());
            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
            Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
        } finally {
            if (!mVersion.containsKey(StorageManager.UUID_PRIVATE_INTERNAL)) {
                Slog.wtf(PackageManagerService.TAG,
                        "No internal VersionInfo found in settings, using current.");
                findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL).forceCurrent();
            }
            if (!mVersion.containsKey(StorageManager.UUID_PRIMARY_PHYSICAL)) {
                Slog.wtf(PackageManagerService.TAG,
                        "No external VersionInfo found in settings, using current.");
                findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL).forceCurrent();
            }
        }

        // If the build is setup to drop runtime permissions