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

Commit 9d474093 authored by Andrzej Ressel's avatar Andrzej Ressel Committed by Clark Scheff
Browse files

Compile app theme in background

When a lot of themes are installed app installation takes a lot
of time blocking UI. In some cases phone gets rebooted because
of that (Watchdog kills PackageManager for blocking UI for too long).

This commit changes that - only current app theme is compiled on UI
thread, rest is compiled in background (like during theme installation).

Change-Id: Ied2ded26172b1b140e538b3906b25db808e05828
parent 5716ba3d
Loading
Loading
Loading
Loading
+43 −13
Original line number Diff line number Diff line
@@ -1491,6 +1491,17 @@ public class PackageManagerService extends IPackageManager.Stub {
                            // if this was a theme, send it off to the theme service for processing
                            if(res.pkg.mIsThemeApk || res.pkg.mIsLegacyIconPackApk) {
                                processThemeResourcesInThemeService(res.pkg.packageName);
                            } else if (mOverlays.containsKey(res.pkg.packageName)) {
                                // if this was an app and is themed send themes that theme it
                                // for processing
                                ArrayMap<String, PackageParser.Package> themes =
                                        mOverlays.get(res.pkg.packageName);
                                for (PackageParser.Package themePkg : themes.values()) {
                                    processThemeResourcesInThemeService(themePkg.packageName);
                                }
                            }
                            if (res.removedInfo.args != null) {
                                // Remove the replaced package's older resources safely now
@@ -7809,13 +7820,31 @@ public class PackageManagerService extends IPackageManager.Stub {
            // 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
            // During app installation we only compile applied theme here (rest will be compiled
            // in background)
            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 (!isBootScan || (mBootThemeConfig != null &&
                            (themePkg.packageName.equals(mBootThemeConfig.getOverlayPkgName()) ||
                        if (themePkg.packageName.equals(config.getOverlayPkgName()) ||
                            themePkg.packageName.equals(
                                    mBootThemeConfig.getOverlayPkgNameForApp(pkg.packageName))))) {
                                     config.getOverlayPkgNameForApp(pkg.packageName))) {
                            try {
                                compileResourcesAndIdmapIfNeeded(pkg, themePkg);
                            } catch (Exception e) {
@@ -7829,6 +7858,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                        }
                    }
                }
            }
            // If this is a theme we should re-compile common resources if they exist so
            // remove this package from mAvailableCommonResources.