diff options
author | Alan Viverette <alanv@google.com> | 2017-11-09 15:41:44 -0500 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-12-04 17:37:28 -0800 |
commit | 11be9317efffafcac52cd2dc5cce1d951c966dd1 (patch) | |
tree | dda14779d25fc5e71e760c29b3c9dd3723c4143a | |
parent | c6284379a5dde6bc5927409eff292db2f0add578 (diff) |
AAPT v1 embed compile SDK version and codename into app
Also adds support for dumping compile SDK attributes.
Bug: 63388434
Fixes: 68854953
Test: manual, compiled & dumped ApiDemos APK
Change-Id: I2eef812bd957950cdef5f1257b73b57044a1e731
-rw-r--r-- | tools/aapt/Bundle.h | 7 | ||||
-rw-r--r-- | tools/aapt/Command.cpp | 34 | ||||
-rw-r--r-- | tools/aapt/Resource.cpp | 38 |
3 files changed, 74 insertions, 5 deletions
diff --git a/tools/aapt/Bundle.h b/tools/aapt/Bundle.h index a93ee2e2b71d..deb9cc083eb0 100644 --- a/tools/aapt/Bundle.h +++ b/tools/aapt/Bundle.h @@ -68,6 +68,7 @@ public: mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL), mBuildSharedLibrary(false), mBuildAppAsSharedLibrary(false), + mCompileSdkVersion(0), mArgc(0), mArgv(NULL) {} ~Bundle(void) {} @@ -123,6 +124,10 @@ public: void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; } bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; } void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; } + const android::String8& getCompileSdkVersionCodename() { return mCompileSdkVersionCodename; } + void setCompileSdkVersionCodename(const android::String8& codename) { mCompileSdkVersionCodename = codename; } + int getCompileSdkVersion() { return mCompileSdkVersion; } + void setCompileSdkVersion(int version) { mCompileSdkVersion = version; } const android::String8& getPlatformBuildVersionCode() { return mPlatformVersionCode; } void setPlatformBuildVersionCode(const android::String8& code) { mPlatformVersionCode = code; } const android::String8& getPlatformBuildVersionName() { return mPlatformVersionName; } @@ -344,6 +349,8 @@ private: const char* mSingleCrunchOutputFile; bool mBuildSharedLibrary; bool mBuildAppAsSharedLibrary; + int mCompileSdkVersion; + android::String8 mCompileSdkVersionCodename; android::String8 mPlatformVersionCode; android::String8 mPlatformVersionName; android::String8 mPrivateSymbolsPackage; diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index cb87737c6868..05375b0cb871 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -293,6 +293,8 @@ enum { ISGAME_ATTR = 0x10103f4, REQUIRED_FEATURE_ATTR = 0x1010557, REQUIRED_NOT_FEATURE_ATTR = 0x1010558, + COMPILE_SDK_VERSION_ATTR = 0x01010572, // NOT FINALIZED + COMPILE_SDK_VERSION_CODENAME_ATTR = 0x01010573, // NOT FINALIZED }; String8 getComponentName(String8 &pkgName, String8 &componentName) { @@ -1247,9 +1249,37 @@ int doDump(Bundle* bundle) splitName.string()).string()); } - String8 platformVersionName = AaptXml::getAttribute(tree, NULL, + String8 platformBuildVersionName = AaptXml::getAttribute(tree, NULL, "platformBuildVersionName"); - printf(" platformBuildVersionName='%s'", platformVersionName.string()); + if (platformBuildVersionName != "") { + printf(" platformBuildVersionName='%s'", platformBuildVersionName.string()); + } + + String8 platformBuildVersionCode = AaptXml::getAttribute(tree, NULL, + "platformBuildVersionCode"); + if (platformBuildVersionCode != "") { + printf(" platformBuildVersionCode='%s'", platformBuildVersionCode.string()); + } + + int32_t compileSdkVersion = AaptXml::getIntegerAttribute(tree, + COMPILE_SDK_VERSION_ATTR, &error); + if (error != "") { + SourcePos(manifestFile, tree.getLineNumber()).error( + "ERROR getting 'android:compileSdkVersion' attribute: %s", + error.string()); + goto bail; + } + if (compileSdkVersion > 0) { + printf(" compileSdkVersion='%d'", compileSdkVersion); + } + + String8 compileSdkVersionCodename = AaptXml::getResolvedAttribute(res, tree, + COMPILE_SDK_VERSION_CODENAME_ATTR, &error); + if (compileSdkVersionCodename != "") { + printf(" compileSdkVersionCodename='%s'", ResTable::normalizeForOutput( + compileSdkVersionCodename.string()).string()); + } + printf("\n"); int32_t installLocation = AaptXml::getResolvedIntegerAttribute(res, tree, diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index bd2b2a36788f..ab6dced5b67d 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -918,6 +918,22 @@ status_t massageManifest(Bundle* bundle, ResourceTable* table, sp<XMLNode> root) } } + + if (bundle->getCompileSdkVersion() != 0) { + if (!addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "compileSdkVersion", + String8::format("%d", bundle->getCompileSdkVersion()), + errorOnFailedInsert, true)) { + return UNKNOWN_ERROR; + } + } + + if (bundle->getCompileSdkVersionCodename() != "") { + if (!addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "compileSdkVersionCodename", + bundle->getCompileSdkVersionCodename(), errorOnFailedInsert, true)) { + return UNKNOWN_ERROR; + } + } + if (bundle->getPlatformBuildVersionCode() != "") { if (!addTagAttribute(root, "", "platformBuildVersionCode", bundle->getPlatformBuildVersionCode(), errorOnFailedInsert, true)) { @@ -1052,7 +1068,12 @@ enum { VERSION_NAME_ATTR = 0x0101021c, }; -static ssize_t extractPlatformBuildVersion(ResXMLTree& tree, Bundle* bundle) { +static ssize_t extractPlatformBuildVersion(const ResTable& table, ResXMLTree& tree, Bundle* bundle) { + // First check if we should be recording the compileSdkVersion* attributes. + static const String16 compileSdkVersionName("android:attr/compileSdkVersion"); + const bool useCompileSdkVersion = table.identifierForName(compileSdkVersionName.string(), + compileSdkVersionName.size()) != 0u; + size_t len; ResXMLTree::event_code_t code; while ((code = tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) { @@ -1082,6 +1103,10 @@ static ssize_t extractPlatformBuildVersion(ResXMLTree& tree, Bundle* bundle) { bundle->setPlatformBuildVersionCode(String8::format("%d", versionCode)); } + if (useCompileSdkVersion && versionCode >= 0 && bundle->getCompileSdkVersion() == 0) { + bundle->setCompileSdkVersion(versionCode); + } + String8 versionName = AaptXml::getAttribute(tree, VERSION_NAME_ATTR, &error); if (error != "") { fprintf(stderr, "ERROR: failed to get platform version name\n"); @@ -1091,6 +1116,11 @@ static ssize_t extractPlatformBuildVersion(ResXMLTree& tree, Bundle* bundle) { if (versionName != "" && bundle->getPlatformBuildVersionName() == "") { bundle->setPlatformBuildVersionName(versionName); } + + if (useCompileSdkVersion && versionName != "" + && bundle->getCompileSdkVersionCodename() == "") { + bundle->setCompileSdkVersionCodename(versionName); + } return NO_ERROR; } @@ -1121,7 +1151,7 @@ static ssize_t extractPlatformBuildVersion(AssetManager& assets, Bundle* bundle) fprintf(stderr, "ERROR: Platform AndroidManifest.xml is corrupt\n"); result = UNKNOWN_ERROR; } else { - result = extractPlatformBuildVersion(tree, bundle); + result = extractPlatformBuildVersion(assets.getResources(true), tree, bundle); } } @@ -1707,7 +1737,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets, sp<ApkBuil // extract them from the platform APK. if (packageType != ResourceTable::System && (bundle->getPlatformBuildVersionCode() == "" || - bundle->getPlatformBuildVersionName() == "")) { + bundle->getPlatformBuildVersionName() == "" || + bundle->getCompileSdkVersion() == 0 || + bundle->getCompileSdkVersionCodename() == "")) { err = extractPlatformBuildVersion(assets->getAssetManager(), bundle); if (err != NO_ERROR) { return UNKNOWN_ERROR; |