From b1bccba13c57eb08858404e92ccd39041110da25 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A5rten=20Kongstad?= Date: Thu, 17 Mar 2011 14:13:41 +0100 Subject: [PATCH] Runtime resource overlay, iteration 1. Runtime resource overlay allows unmodified applications to appear as if they had been compiled with additional resources defined. See libs/utils/README for more information. This commit is the first iteration of runtime resource overlay. It provides the actual overlay modifications and loading of trusted overlay packages (ie residing in /vendor) targeting framework-res.apk. This commit loads exactly one overlay package. The overlay, if present, must target framework-res.apk and be located at /vendor/overlay/framework/framework-res.apk. Change-Id: If26ee7754813004a96c043dba37fbe99fa3919db --- Bundle.h | 4 ++++ Main.cpp | 5 +++++ ResourceTable.cpp | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Bundle.h b/Bundle.h index 15570e4..fa84e93 100644 --- a/Bundle.h +++ b/Bundle.h @@ -40,6 +40,7 @@ public: mWantUTF16(false), mValues(false), mCompressionMethod(0), mOutputAPKFile(NULL), mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), + mIsOverlayPackage(false), mAutoAddOverlay(false), mAssetSourceDir(NULL), mProguardFile(NULL), mAndroidManifestFile(NULL), mPublicOutputFile(NULL), mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), @@ -92,6 +93,8 @@ public: void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; } void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; } + bool getIsOverlayPackage() const { return mIsOverlayPackage; } + void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; } bool getAutoAddOverlay() { return mAutoAddOverlay; } void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; } @@ -219,6 +222,7 @@ private: const char* mOutputAPKFile; const char* mManifestPackageNameOverride; const char* mInstrumentationPackageNameOverride; + bool mIsOverlayPackage; bool mAutoAddOverlay; const char* mAssetSourceDir; const char* mProguardFile; diff --git a/Main.cpp b/Main.cpp index 266a02f..1e63131 100644 --- a/Main.cpp +++ b/Main.cpp @@ -68,6 +68,7 @@ void usage(void) " [-S resource-sources [-S resource-sources ...]] " " [-F apk-file] [-J R-file-dir] \\\n" " [--product product1,product2,...] \\\n" + " [-o] \\\n" " [raw-files-dir [raw-files-dir] ...]\n" "\n" " Package the android resources. It will read assets and resources that are\n" @@ -105,6 +106,7 @@ void usage(void) " -j specify a jar or zip file containing classes to include\n" " -k junk path of file(s) added\n" " -m make package directories under location specified by -J\n" + " -o create overlay package (ie only resources; expects in manifest)\n" #if 0 " -p pseudolocalize the default configuration\n" #endif @@ -275,6 +277,9 @@ int main(int argc, char* const argv[]) case 'm': bundle.setMakePackageDirs(true); break; + case 'o': + bundle.setIsOverlayPackage(true); + break; #if 0 case 'p': bundle.setPseudolocalize(true); diff --git a/ResourceTable.cpp b/ResourceTable.cpp index 818c3c6..6459d0e 100644 --- a/ResourceTable.cpp +++ b/ResourceTable.cpp @@ -3674,7 +3674,9 @@ sp ResourceTable::getPackage(const String16& package) { sp p = mPackages.valueFor(package); if (p == NULL) { - if (mIsAppPackage) { + if (mBundle->getIsOverlayPackage()) { + p = new Package(package, 0x00); + } else if (mIsAppPackage) { if (mHaveAppPackage) { fprintf(stderr, "Adding multiple application package resources; only one is allowed.\n" "Use -x to create extended resources.\n"); -- 2.45.2