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

Commit ce85d7f4 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android Git Automerger
Browse files

am b03b9759: am 4c880877: Merge "Recover from missing upgrade to system package." into lmp-dev

* commit 'b03b9759':
  Recover from missing upgrade to system package.
parents aa4b0d82 b03b9759
Loading
Loading
Loading
Loading
+64 −1
Original line number Original line Diff line number Diff line
@@ -176,11 +176,13 @@ import android.view.Display;
import java.io.BufferedInputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
@@ -1554,6 +1556,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            // Prune any system packages that no longer exist.
            // Prune any system packages that no longer exist.
            final List<String> possiblyDeletedUpdatedSystemApps = new ArrayList<String>();
            final List<String> possiblyDeletedUpdatedSystemApps = new ArrayList<String>();
            final ArrayMap<String, File> expectingBetter = new ArrayMap<>();
            if (!mOnlyCore) {
            if (!mOnlyCore) {
                Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator();
                Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator();
                while (psit.hasNext()) {
                while (psit.hasNext()) {
@@ -1586,6 +1589,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                                    + ", versionCode=" + ps.versionCode + "; scanned versionCode="
                                    + ", versionCode=" + ps.versionCode + "; scanned versionCode="
                                    + scannedPkg.mVersionCode);
                                    + scannedPkg.mVersionCode);
                            removePackageLI(ps, true);
                            removePackageLI(ps, true);
                            expectingBetter.put(ps.name, ps.codePath);
                        }
                        }
                        continue;
                        continue;
@@ -1653,6 +1657,49 @@ public class PackageManagerService extends IPackageManager.Stub {
                    }
                    }
                    logCriticalInfo(Log.WARN, msg);
                    logCriticalInfo(Log.WARN, msg);
                }
                }
                /**
                 * Make sure all system apps that we expected to appear on
                 * the userdata partition actually showed up. If they never
                 * appeared, crawl back and revive the system version.
                 */
                for (int i = 0; i < expectingBetter.size(); i++) {
                    final String packageName = expectingBetter.keyAt(i);
                    if (!mPackages.containsKey(packageName)) {
                        final File scanFile = expectingBetter.valueAt(i);
                        logCriticalInfo(Log.WARN, "Expected better " + packageName
                                + " but never showed up; reverting to system");
                        final int reparseFlags;
                        if (FileUtils.contains(privilegedAppDir, scanFile)) {
                            reparseFlags = PackageParser.PARSE_IS_SYSTEM
                                    | PackageParser.PARSE_IS_SYSTEM_DIR
                                    | PackageParser.PARSE_IS_PRIVILEGED;
                        } else if (FileUtils.contains(systemAppDir, scanFile)) {
                            reparseFlags = PackageParser.PARSE_IS_SYSTEM
                                    | PackageParser.PARSE_IS_SYSTEM_DIR;
                        } else if (FileUtils.contains(vendorAppDir, scanFile)) {
                            reparseFlags = PackageParser.PARSE_IS_SYSTEM
                                    | PackageParser.PARSE_IS_SYSTEM_DIR;
                        } else if (FileUtils.contains(oemAppDir, scanFile)) {
                            reparseFlags = PackageParser.PARSE_IS_SYSTEM
                                    | PackageParser.PARSE_IS_SYSTEM_DIR;
                        } else {
                            Slog.e(TAG, "Ignoring unexpected fallback path " + scanFile);
                            continue;
                        }
                        mSettings.enableSystemPackageLPw(packageName);
                        try {
                            scanPackageLI(scanFile, reparseFlags, scanFlags, 0, null);
                        } catch (PackageManagerException e) {
                            Slog.e(TAG, "Failed to parse original system package: "
                                    + e.getMessage());
                        }
                    }
                }
            }
            }
            // Now that we know all of the shared libraries, update all clients to have
            // Now that we know all of the shared libraries, update all clients to have
@@ -12163,6 +12210,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                break;
                break;
            }
            }
            opti++;
            opti++;
            if ("-a".equals(opt)) {
            if ("-a".equals(opt)) {
                // Right now we only know how to print all.
                // Right now we only know how to print all.
            } else if ("-h".equals(opt)) {
            } else if ("-h".equals(opt)) {
@@ -12509,6 +12557,21 @@ public class PackageManagerService extends IPackageManager.Stub {
                    }
                    }
                }
                }
            }
            }
            if (checkin && dumpState.isDumping(DumpState.DUMP_MESSAGES)) {
                BufferedReader in = null;
                String line = null;
                try {
                    in = new BufferedReader(new FileReader(getSettingsProblemFile()));
                    while ((line = in.readLine()) != null) {
                        pw.print("msg,");
                        pw.println(line);
                    }
                } catch (IOException ignored) {
                } finally {
                    IoUtils.closeQuietly(in);
                }
            }
        }
        }
    }
    }