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

Commit 00007ba7 authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

ThemeEngine : Use manifest.mf for hash calculation

Using just AndroidManifest xml is not sufficient since
the apk could have different resources yet same manifest.

issue-id: CYNGNOS-916

Change-Id: I5ffa95733110b1c37b5f07ef29b457bb68b50cb2
(cherry picked from commit a22cfa76)
parent efb8efe8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1124,6 +1124,7 @@ public class PackageParser {
     */
    public void collectManifestDigest(Package pkg) throws PackageParserException {
        pkg.manifestDigest = null;
        pkg.manifestHashCode = 0;

        // TODO: extend to gather digest for split APKs
        try {
@@ -1132,7 +1133,7 @@ public class PackageParser {
                final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
                if (je != null) {
                    pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
                    pkg.manifestHashCode = ThemeUtils.getPackageHashCode(pkg);
                    pkg.manifestHashCode = ThemeUtils.getPackageHashCode(pkg, jarFile);
                }
            } finally {
                jarFile.close();
+19 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import java.io.OutputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.jar.StrictJarFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -120,6 +121,7 @@ public class ThemeUtils {
    private static final String SETTINGS_DB =
            "/data/data/com.android.providers.settings/databases/settings.db";
    private static final String SETTINGS_SECURE_TABLE = "secure";
    private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";

    /**
     * IDMAP hash version code used to alter the resulting hash and force recreating
@@ -771,8 +773,24 @@ public class ThemeUtils {
     * @param pkg
     * @return
     */
    public static int getPackageHashCode(PackageParser.Package pkg) {
    public static int getPackageHashCode(PackageParser.Package pkg, StrictJarFile jarFile) {
        int hash = pkg.manifestDigest != null ? pkg.manifestDigest.hashCode() : 0;
        final ZipEntry je = jarFile.findEntry(MANIFEST_NAME);
        if (je != null) {
            try {
                try {
                    ManifestDigest digest = ManifestDigest.fromInputStream(
                        jarFile.getInputStream(je));
                    if (digest != null) {
                        hash += digest.hashCode();
                    }
                } finally {
                    jarFile.close();
                }
            } catch (IOException | RuntimeException e) {
                // Failed to generate digest from manifest.mf
            }
        }
        hash = 31 * hash + IDMAP_HASH_VERSION;
        return hash;
    }