diff options
author | Jeff Hamilton <jham@android.com> | 2010-01-06 15:46:38 -0600 |
---|---|---|
committer | Jeff Hamilton <jham@android.com> | 2010-02-01 18:47:01 -0600 |
commit | 2fee0ed6eb99b211efa06f095a41268a2021214a (patch) | |
tree | bc7ce3df25a1d7ec1f61fb85ef56899dab5eb66b /tools | |
parent | 7188f946521d64ea21121939d2a4c279f33fe910 (diff) | |
download | frameworks_base-2fee0ed6eb99b211efa06f095a41268a2021214a.zip frameworks_base-2fee0ed6eb99b211efa06f095a41268a2021214a.tar.gz frameworks_base-2fee0ed6eb99b211efa06f095a41268a2021214a.tar.bz2 |
Add the --rename-manifest-package option to aapt.
It allows you to force override the manifest
package listed in the AndroidManifest.xml when
creating an APK file.
Change-Id: I7eac7943c4e56610b65728ae54773a273634fd9d
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt/Bundle.h | 5 | ||||
-rw-r--r-- | tools/aapt/Main.cpp | 9 | ||||
-rw-r--r-- | tools/aapt/Resource.cpp | 68 | ||||
-rw-r--r-- | tools/aapt/StringPool.cpp | 2 | ||||
-rw-r--r-- | tools/aapt/XMLNode.cpp | 13 | ||||
-rw-r--r-- | tools/aapt/XMLNode.h | 2 |
6 files changed, 91 insertions, 8 deletions
diff --git a/tools/aapt/Bundle.h b/tools/aapt/Bundle.h index c53f7f1..cbb5203 100644 --- a/tools/aapt/Bundle.h +++ b/tools/aapt/Bundle.h @@ -38,7 +38,7 @@ public: mUpdate(false), mExtending(false), mRequireLocalization(false), mPseudolocalize(false), mUTF8(false), mEncodingSpecified(false), mValues(false), - mCompressionMethod(0), mOutputAPKFile(NULL), + mCompressionMethod(0), mOutputAPKFile(NULL), mManifestPackageNameOverride(NULL), mAssetSourceDir(NULL), mProguardFile(NULL), mAndroidManifestFile(NULL), mPublicOutputFile(NULL), mRClassDir(NULL), mResourceIntermediatesDir(NULL), @@ -88,6 +88,8 @@ public: void setJunkPath(bool val) { mJunkPath = val; } const char* getOutputAPKFile() const { return mOutputAPKFile; } void setOutputAPKFile(const char* val) { mOutputAPKFile = val; } + const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; } + void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; } /* * Input options. @@ -178,6 +180,7 @@ private: int mCompressionMethod; bool mJunkPath; const char* mOutputAPKFile; + const char* mManifestPackageNameOverride; const char* mAssetSourceDir; const char* mProguardFile; const char* mAndroidManifestFile; diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp index 1e6b52e..6675ac2 100644 --- a/tools/aapt/Main.cpp +++ b/tools/aapt/Main.cpp @@ -436,6 +436,15 @@ int main(int argc, char* const argv[]) } else if (strcmp(cp, "-utf16") == 0) { bundle.setEncodingSpecified(true); bundle.setUTF8(false); + } else if (strcmp(cp, "-rename-manifest-package") == 0) { + argc--; + argv++; + if (!argc) { + fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n"); + wantUsage = true; + goto bail; + } + bundle.setManifestPackageNameOverride(argv[0]); } else { fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp); wantUsage = true; diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index d53c472..0d2ea60 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -489,11 +489,11 @@ static bool applyFileOverlay(Bundle *bundle, DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> > baseFiles = baseGroup->getFiles(); for (size_t i=0; i < baseFiles.size(); i++) { - printf("baseFile %d has flavor %s\n", i, + printf("baseFile %ld has flavor %s\n", i, baseFiles.keyAt(i).toString().string()); } for (size_t i=0; i < overlayFiles.size(); i++) { - printf("overlayFile %d has flavor %s\n", i, + printf("overlayFile %ld has flavor %s\n", i, overlayFiles.keyAt(i).toString().string()); } } @@ -507,7 +507,7 @@ static bool applyFileOverlay(Bundle *bundle, keyAt(overlayGroupIndex)); if(baseFileIndex < UNKNOWN_ERROR) { if (bundle->getVerbose()) { - printf("found a match (%d) for overlay file %s, for flavor %s\n", + printf("found a match (%ld) for overlay file %s, for flavor %s\n", baseFileIndex, overlayGroup->getLeaf().string(), overlayFiles.keyAt(overlayGroupIndex).toString().string()); @@ -562,6 +562,33 @@ void addTagAttribute(const sp<XMLNode>& node, const char* ns8, node->addAttribute(ns, attr, String16(value)); } +static void fullyQualifyClassName(String8& package, sp<XMLNode> node) { + XMLNode::attribute_entry* attr = node->editAttribute( + String16("http://schemas.android.com/apk/res/android"), String16("name")); + if (attr != NULL) { + String8 name(attr->string); + + // asdf --> package.asdf + // .asdf .a.b --> package.asdf package.a.b + // asdf.adsf --> asdf.asdf + String8 className; + const char* p = name.string(); + const char* q = strchr(p, '.'); + if (p == q) { + className += package; + className += name; + } else if (q == NULL) { + className += package; + className += "."; + className += name; + } else { + className += name; + } + NOISY(printf("Qualifying class '%s' to '%s'", name.string(), className.string())); + attr->string.setTo(String16(className)); + } +} + status_t massageManifest(Bundle* bundle, sp<XMLNode> root) { root = root->searchElement(String16(), String16("manifest")); @@ -591,7 +618,36 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root) addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "maxSdkVersion", bundle->getMaxSdkVersion()); } - + + // Deal with manifest package name overrides + const char* manifestPackageNameOverride = bundle->getManifestPackageNameOverride(); + if (manifestPackageNameOverride != NULL) { + // Update the actual package name + XMLNode::attribute_entry* attr = root->editAttribute(String16(), String16("package")); + if (attr == NULL) { + fprintf(stderr, "package name is required with --rename-manifest-package.\n"); + return UNKNOWN_ERROR; + } + String8 origPackage(attr->string); + attr->string.setTo(String16(manifestPackageNameOverride)); + NOISY(printf("Overriding package '%s' to be '%s'\n", origPackage.string(), manifestPackageNameOverride)); + + // Make class names fully qualified + sp<XMLNode> application = root->getChildElement(String16(), String16("application")); + if (application != NULL) { + fullyQualifyClassName(origPackage, application); + + Vector<sp<XMLNode> >& children = const_cast<Vector<sp<XMLNode> >&>(application->getChildren()); + for (size_t i = 0; i < children.size(); i++) { + sp<XMLNode> child = children.editItemAt(i); + String8 tag(child->getElementName()); + if (tag == "activity" || tag == "service" || tag == "receiver" || tag == "provider") { + fullyQualifyClassName(origPackage, child); + } + } + } + } + return NO_ERROR; } @@ -1173,14 +1229,14 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets) table.writePublicDefinitions(String16(assets->getPackage()), fp); fclose(fp); } - +#if 0 NOISY( ResTable rt; rt.add(resFile->getData(), resFile->getSize(), NULL); printf("Generated resources:\n"); rt.print(); ) - +#endif // These resources are now considered to be a part of the included // resources, for others to reference. err = assets->addIncludedResources(resFile); diff --git a/tools/aapt/StringPool.cpp b/tools/aapt/StringPool.cpp index ec58591..51afc0a 100644 --- a/tools/aapt/StringPool.cpp +++ b/tools/aapt/StringPool.cpp @@ -25,7 +25,7 @@ void printStringPool(const ResStringPool* pool) const size_t NS = pool->size(); for (size_t s=0; s<NS; s++) { size_t len; - printf("String #%d: %s\n", s, + printf("String #%ld: %s\n", s, String8(pool->stringAt(s, &len)).string()); } } diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index 036dde4..4c59288 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -555,6 +555,19 @@ const XMLNode::attribute_entry* XMLNode::getAttribute(const String16& ns, return NULL; } +XMLNode::attribute_entry* XMLNode::editAttribute(const String16& ns, + const String16& name) +{ + for (size_t i=0; i<mAttributes.size(); i++) { + attribute_entry * ae = &mAttributes.editItemAt(i); + if (ae->ns == ns && ae->name == name) { + return ae; + } + } + + return NULL; +} + const String16& XMLNode::getCData() const { return mChars; diff --git a/tools/aapt/XMLNode.h b/tools/aapt/XMLNode.h index dc92fa7..e9a263b 100644 --- a/tools/aapt/XMLNode.h +++ b/tools/aapt/XMLNode.h @@ -95,6 +95,8 @@ public: const attribute_entry* getAttribute(const String16& ns, const String16& name) const; + attribute_entry* editAttribute(const String16& ns, const String16& name); + const String16& getCData() const; const String16& getComment() const; |