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

Commit c915fbfb authored by d34d's avatar d34d Committed by Gerrit Code Review
Browse files

Themes: Reference app resource when compiling theme [2/2]

This allows us to pass in the path to the target apk as an additional
included resource apk, allowing theme designers to reference styles
and attributes from the original package without needing to duplicate
them.  Duplicating attributes never worked quite well, and causes
all sorts of issues, including crashing apps.

Instead of a theme declaring attributes, that are app specific, it
can simply reference the originals.  This way things like colors that
are style specific get included correctly.

Here's an example of stat_sys_wifi_signal_4_fully.xml using this feature.
By using ?com.android.systemui:attr/ we are able to reference attributes
defined in SystemUI directly in our themed resource.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="17.25dp"
    android:height="18dp"
    android:viewportWidth="46.0"
    android:viewportHeight="48.0">

    <path
        android:fillColor="?com.android.systemui:attr/backgroundColor"
        android:pathData="M20.4,18.0"/>
    <path
        android:fillColor="?com.android.systemui:attr/fillColor"
        android:pathData="M42.0,32.0l0.0,-4.0L26.0,18.0L26.0,7.0c0.0,-1.7 -1.3,-3.0 -3.0,
        -3.0c-1.7,0.0 -3.0,1.3 -3.0,3.0l0.0,11.0L4.0,28.0l0.0,4.0l16.0,-5.0l0.0,11.0l-4.0,
        3.0l0.0,3.0l7.0,-2.0l7.0,2.0l0.0,-3.0l-4.0,-3.0L26.0,27.0L42.0,32.0z"/>
</vector>

Change-Id: Icc794da9af2cd48099d42f9d7fbadaad8612b5db
TICKET: CYNGNOS-1645
parent 9e2a8303
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -5290,6 +5290,13 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString,
            identifierForName(name.string(), name.size(),
            identifierForName(name.string(), name.size(),
                              type.string(), type.size(),
                              type.string(), type.size(),
                              package.string(), package.size(), &specFlags);
                              package.string(), package.size(), &specFlags);
// HACK
// This allows themes to reference attributes that are app specific and
// normally private.  Only applies to aapt running on device not host
// build systems.
#ifdef HAVE_ANDROID_OS
        enforcePrivate = false;
#endif
        if (rid != 0) {
        if (rid != 0) {
            if (enforcePrivate) {
            if (enforcePrivate) {
                if ((specFlags&ResTable_typeSpec::SPEC_PUBLIC) == 0) {
                if ((specFlags&ResTable_typeSpec::SPEC_PUBLIC) == 0) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ public final class Installer extends SystemService {
    }
    }


    public int aapt(String themeApkPath, String internalPath, String resTablePath, int uid,
    public int aapt(String themeApkPath, String internalPath, String resTablePath, int uid,
                    int pkgId, int minSdkVersion, String commonResourcesPath) {
            int pkgId, int minSdkVersion, String appResourcesPath, String commonResourcesPath) {


        StringBuilder builder = new StringBuilder();
        StringBuilder builder = new StringBuilder();
        if (TextUtils.isEmpty(commonResourcesPath)) {
        if (TextUtils.isEmpty(commonResourcesPath)) {
@@ -149,6 +149,8 @@ public final class Installer extends SystemService {
        builder.append(pkgId);
        builder.append(pkgId);
        builder.append(' ');
        builder.append(' ');
        builder.append(minSdkVersion);
        builder.append(minSdkVersion);
        builder.append(' ');
        builder.append(appResourcesPath);


        if (!TextUtils.isEmpty(commonResourcesPath)) {
        if (!TextUtils.isEmpty(commonResourcesPath)) {
            builder.append(' ');
            builder.append(' ');
+5 −1
Original line number Original line Diff line number Diff line
@@ -8267,8 +8267,12 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
        boolean hasCommonResources = (hasCommonResources(pkg) && !COMMON_OVERLAY.equals(target));
        boolean hasCommonResources = (hasCommonResources(pkg) && !COMMON_OVERLAY.equals(target));
        PackageParser.Package targetPkg = mPackages.get(target);
        String appPath = targetPkg != null ? targetPkg.baseCodePath : "";
        if (mInstaller.aapt(pkg.baseCodePath, internalPath, resPath, sharedGid, pkgId,
        if (mInstaller.aapt(pkg.baseCodePath, internalPath, resPath, sharedGid, pkgId,
                pkg.applicationInfo.targetSdkVersion,
                pkg.applicationInfo.targetSdkVersion,
                appPath,
                hasCommonResources ? ThemeUtils.getTargetCacheDir(COMMON_OVERLAY, pkg)
                hasCommonResources ? ThemeUtils.getTargetCacheDir(COMMON_OVERLAY, pkg)
                        + File.separator + "resources.apk" : "") != 0) {
                        + File.separator + "resources.apk" : "") != 0) {
            throw new AaptException("Failed to run aapt");
            throw new AaptException("Failed to run aapt");
@@ -8282,7 +8286,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        if (mInstaller.aapt(pkg.baseCodePath, APK_PATH_TO_ICONS, resPath, sharedGid,
        if (mInstaller.aapt(pkg.baseCodePath, APK_PATH_TO_ICONS, resPath, sharedGid,
                Resources.THEME_ICON_PKG_ID,
                Resources.THEME_ICON_PKG_ID,
                pkg.applicationInfo.targetSdkVersion,
                pkg.applicationInfo.targetSdkVersion,
                "") != 0) {
                "", "") != 0) {
            throw new AaptException("Failed to run aapt");
            throw new AaptException("Failed to run aapt");
        }
        }
    }
    }