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

Commit df41276b authored by Steve Kondik's avatar Steve Kondik Committed by d34d
Browse files

pm: Fix lock insanity with ActivityManager

 * It's possible that ActivityManager may be trying to stop a package
   while the PackageManager is trying to perform a scan during
   an upgrade. When AM tries to perform the stop, it will attempt
   to look up the package user, which will try to take the PM lock.
   This is fine, but while we're holding the lock in PM during
   the package upgrade we're attempting to call back into AM to
   get the current theme, which tries to take the AM lock. This
   results in the entire system locking up until watchdog kills
   off system server.
 * Instead of looking up the current theme while holding the lock
   in PM, look it up before locking the whole place down.

Change-Id: If322a7f214218740d73043ff65860ccadd92f01d
parent fc8a6d86
Loading
Loading
Loading
Loading
+19 −16
Original line number Diff line number Diff line
@@ -7481,6 +7481,25 @@ public class PackageManagerService extends IPackageManager.Stub {
        KeySetManagerService ksms = mSettings.mKeySetManagerService;
        ksms.assertScannedPackageValid(pkg);
        // Get the current theme config. We do this outside the lock
        // since ActivityManager might be waiting on us already
        // and a deadlock would result.
        final boolean isBootScan = (scanFlags & SCAN_BOOTING) != 0;
        ThemeConfig config = mBootThemeConfig;
        if (!isBootScan) {
            final IActivityManager am = ActivityManagerNative.getDefault();
            try {
                if (am != null) {
                    config = am.getConfiguration().themeConfig;
                } else {
                    Log.w(TAG, "ActivityManager getDefault() " +
                            "returned null, cannot compile app's theme");
                }
            } catch(RemoteException e) {
                Log.w(TAG, "Failed to get the theme config from ActivityManager");
            }
        }
        // writer
        synchronized (mPackages) {
            // We don't expect installation to fail beyond this point
@@ -7828,7 +7847,6 @@ public class PackageManagerService extends IPackageManager.Stub {
            pkgSetting.setTimeStamp(scanFileTime);
            final boolean isBootScan = (scanFlags & SCAN_BOOTING) != 0;
            // Generate resources & idmaps if pkg is NOT a theme
            // We must compile resources here because during the initial boot process we may get
            // here before a default theme has had a chance to compile its resources
@@ -7837,21 +7855,6 @@ public class PackageManagerService extends IPackageManager.Stub {
            if (pkg.mOverlayTargets.isEmpty() && mOverlays.containsKey(pkg.packageName)) {
                ArrayMap<String, PackageParser.Package> themes = mOverlays.get(pkg.packageName);
                final IActivityManager am = ActivityManagerNative.getDefault();
                ThemeConfig themeConfig = null;
                try {
                    if (am != null) {
                        themeConfig = am.getConfiguration().themeConfig;
                    } else {
                        Log.e(TAG, "ActivityManager getDefault() " +
                                "returned null, cannot compile app's theme");
                    }
                } catch(RemoteException e) {
                    Log.e(TAG, "Failed to get the theme config ", e);
                }
                ThemeConfig config = isBootScan ? mBootThemeConfig : themeConfig;
                if (config != null) {
                    for(PackageParser.Package themePkg : themes.values()) {
                        if (themePkg.packageName.equals(config.getOverlayPkgName()) ||