From c915fbfbc76eff4b31fbfa06bf45734fb73c104d Mon Sep 17 00:00:00 2001 From: d34d Date: Mon, 18 Jan 2016 19:52:10 -0800 Subject: 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. Change-Id: Icc794da9af2cd48099d42f9d7fbadaad8612b5db TICKET: CYNGNOS-1645 --- libs/androidfw/ResourceTypes.cpp | 7 +++++++ services/core/java/com/android/server/pm/Installer.java | 4 +++- .../core/java/com/android/server/pm/PackageManagerService.java | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index 818e1c5..5fe0d66 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -5290,6 +5290,13 @@ bool ResTable::stringToValue(Res_value* outValue, String16* outString, identifierForName(name.string(), name.size(), type.string(), type.size(), 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 (enforcePrivate) { if ((specFlags&ResTable_typeSpec::SPEC_PUBLIC) == 0) { diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java index 5f183a2..4be7e25 100644 --- a/services/core/java/com/android/server/pm/Installer.java +++ b/services/core/java/com/android/server/pm/Installer.java @@ -129,7 +129,7 @@ public final class Installer extends SystemService { } 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(); if (TextUtils.isEmpty(commonResourcesPath)) { @@ -149,6 +149,8 @@ public final class Installer extends SystemService { builder.append(pkgId); builder.append(' '); builder.append(minSdkVersion); + builder.append(' '); + builder.append(appResourcesPath); if (!TextUtils.isEmpty(commonResourcesPath)) { builder.append(' '); diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 07a627b..c1fe38e 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -8267,8 +8267,12 @@ public class PackageManagerService extends IPackageManager.Stub { } 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, pkg.applicationInfo.targetSdkVersion, + appPath, hasCommonResources ? ThemeUtils.getTargetCacheDir(COMMON_OVERLAY, pkg) + File.separator + "resources.apk" : "") != 0) { 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, Resources.THEME_ICON_PKG_ID, pkg.applicationInfo.targetSdkVersion, - "") != 0) { + "", "") != 0) { throw new AaptException("Failed to run aapt"); } } -- cgit v1.1