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

Commit 87e7e16c authored by Andy Mast's avatar Andy Mast
Browse files

Themes: Avoid compiling icon packs every boot

Change-Id: I51c7effdd4592a302f457822a05cbebee6cde06b
parent 5bfbc4bb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public class ThemeUtils {
    public static final String IDMAP_SUFFIX = "@idmap";
    public static final String COMMON_RES_SUFFIX = ".common";
    public static final String COMMON_RES_TARGET = "common";
    public static final String ICON_HASH_FILENAME = "hash";

    // path to external theme resources, i.e. bootanimation.zip
    public static final String SYSTEM_THEME_PATH = "/data/system/theme";
@@ -149,6 +150,10 @@ public class ThemeUtils {
      return IDMAP_PREFIX + pkgName;
    }

    public static String getIconHashFile(String pkgName) {
        return getIconPackDir(pkgName) + File.separator  +  ICON_HASH_FILENAME;
    }

    public static String getIconPackApkPath(String pkgName) {
        return getIconPackDir(pkgName) + "/resources.apk";
    }
+36 −1
Original line number Diff line number Diff line
@@ -142,6 +142,8 @@ import android.view.WindowManager;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
@@ -151,6 +153,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -5409,7 +5412,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            //Icon Packs need aapt too
            //TODO: No need to run aapt on icons for every startup...
            if (pkg.hasIconPack) {
            if (isIconCompileNeeded(pkg)) {
                try {
                    ThemeUtils.createCacheDirIfNotExists();
                    ThemeUtils.createIconDirIfNotExists(pkg.packageName);
@@ -5425,6 +5428,29 @@ public class PackageManagerService extends IPackageManager.Stub {
        return pkg;
    }
    private boolean isIconCompileNeeded(Package pkg) {
        if (!pkg.hasIconPack) return false;
        // Read in the stored hash value and compare to the pkgs computed hash value
        FileInputStream in = null;
        DataInputStream dataInput = null;
        try {
            String hashFile = ThemeUtils.getIconHashFile(pkg.packageName);
            in = new FileInputStream(hashFile);
            dataInput = new DataInputStream(in);
            int storedHashCode = dataInput.readInt();
            int actualHashCode = getPackageHashCode(pkg);
            return storedHashCode != actualHashCode;
        } catch(IOException e) {
            Log.e(TAG, "Could not read hash for " + pkg + "not compiling icon pack", e);
        } finally {
            IoUtils.closeQuietly(in);
            IoUtils.closeQuietly(dataInput);
        }
        return true;
    }
    private void compileResourcesAndIdmapIfNeeded(PackageParser.Package targetPkg,
                                               PackageParser.Package themePkg)
            throws IdmapException, AaptException, IOException, Exception
@@ -5490,10 +5516,19 @@ public class PackageManagerService extends IPackageManager.Stub {
    private void compileIconPack(Package pkg) throws Exception {
        if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Compile resource table for " + pkg.packageName);
        OutputStream out = null;
        DataOutputStream dataOut = null;
        try {
            createTempManifest(pkg.packageName);
            int code = getPackageHashCode(pkg);
            String hashFile = ThemeUtils.getIconHashFile(pkg.packageName);
            out = new FileOutputStream(hashFile);
            dataOut = new DataOutputStream(out);
            dataOut.writeInt(code);
            compileIconsWithAapt(pkg);
        } finally {
            IoUtils.closeQuietly(out);
            IoUtils.closeQuietly(dataOut);
            cleanupTempManifest();
        }
    }