+
+ // 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, String16("name"));
+
+ 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, String16("name"));
+ } else if (tag == "activity-alias") {
+ fullyQualifyClassName(origPackage, child, String16("name"));
+ fullyQualifyClassName(origPackage, child, String16("targetActivity"));
+ }
+ }
+ }
+ }
+
+ // Deal with manifest package name overrides
+ const char* instrumentationPackageNameOverride = bundle->getInstrumentationPackageNameOverride();
+ if (instrumentationPackageNameOverride != NULL) {
+ // Fix up instrumentation targets.
+ Vector<sp<XMLNode> >& children = const_cast<Vector<sp<XMLNode> >&>(root->getChildren());
+ for (size_t i = 0; i < children.size(); i++) {
+ sp<XMLNode> child = children.editItemAt(i);
+ String8 tag(child->getElementName());
+ if (tag == "instrumentation") {
+ XMLNode::attribute_entry* attr = child->editAttribute(
+ String16("http://schemas.android.com/apk/res/android"), String16("targetPackage"));
+ if (attr != NULL) {
+ attr->string.setTo(String16(instrumentationPackageNameOverride));
+ }
+ }
+ }
+ }