summaryrefslogtreecommitdiff
path: root/tools/aapt2/cmd/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/cmd/Util.cpp')
-rw-r--r--tools/aapt2/cmd/Util.cpp52
1 files changed, 47 insertions, 5 deletions
diff --git a/tools/aapt2/cmd/Util.cpp b/tools/aapt2/cmd/Util.cpp
index 25010c52235c..792120e449ae 100644
--- a/tools/aapt2/cmd/Util.cpp
+++ b/tools/aapt2/cmd/Util.cpp
@@ -31,6 +31,7 @@
using ::android::ConfigDescription;
using ::android::LocaleValue;
using ::android::StringPiece;
+using ::android::base::StringPrintf;
namespace aapt {
@@ -74,6 +75,7 @@ bool ParseSplitParameter(const StringPiece& arg, IDiagnostics* diag, std::string
}
*out_path = parts[0];
+ out_split->name = parts[1];
for (const StringPiece& config_str : util::Tokenize(parts[1], ',')) {
ConfigDescription config;
if (!ConfigDescription::Parse(config_str, &config)) {
@@ -120,12 +122,15 @@ std::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk(
for (const SplitConstraints& constraints : split_constraints) {
SplitConstraints constraint;
for (const ConfigDescription& config : constraints.configs) {
- if (config.sdkVersion <= min_sdk) {
- constraint.configs.insert(config.CopyWithoutSdkVersion());
- } else {
- constraint.configs.insert(config);
+ const ConfigDescription &configToInsert = (config.sdkVersion <= min_sdk)
+ ? config.CopyWithoutSdkVersion()
+ : config;
+ // only add the config if it actually selects something
+ if (configToInsert != ConfigDescription::DefaultConfig()) {
+ constraint.configs.insert(configToInsert);
}
}
+ constraint.name = constraints.name;
adjusted_constraints.push_back(std::move(constraint));
}
return adjusted_constraints;
@@ -147,7 +152,7 @@ static xml::NamespaceDecl CreateAndroidNamespaceDecl() {
//
// See frameworks/base/core/java/android/content/pm/PackageParser.java which
// checks this at runtime.
-static std::string MakePackageSafeName(const std::string &name) {
+std::string MakePackageSafeName(const std::string &name) {
std::string result(name);
bool first = true;
for (char &c : result) {
@@ -170,6 +175,7 @@ static std::string MakePackageSafeName(const std::string &name) {
std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
const SplitConstraints& constraints) {
const ResourceId kVersionCode(0x0101021b);
+ const ResourceId kVersionCodeMajor(0x01010576);
const ResourceId kRevisionCode(0x010104d5);
const ResourceId kHasCode(0x0101000c);
@@ -186,6 +192,14 @@ std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_DEC, version_code)});
}
+ if (app_info.version_code_major) {
+ const uint32_t version_code_major = app_info.version_code_major.value();
+ manifest_el->attributes.push_back(xml::Attribute{
+ xml::kSchemaAndroid, "versionCodeMajor", std::to_string(version_code_major),
+ CreateAttributeWithId(kVersionCodeMajor),
+ util::make_unique<BinaryPrimitive>(android::Res_value::TYPE_INT_DEC, version_code_major)});
+ }
+
if (app_info.revision_code) {
const uint32_t revision_code = app_info.revision_code.value();
manifest_el->attributes.push_back(xml::Attribute{
@@ -357,6 +371,17 @@ Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
app_info.version_code = maybe_code.value();
}
+ if (const xml::Attribute* version_code_major_attr =
+ manifest_el->FindAttribute(xml::kSchemaAndroid, "versionCodeMajor")) {
+ Maybe<uint32_t> maybe_code = ExtractCompiledInt(*version_code_major_attr, &error_msg);
+ if (!maybe_code) {
+ diag->Error(DiagMessage(xml_res.file.source.WithLine(manifest_el->line_number))
+ << "invalid android:versionCodeMajor: " << error_msg);
+ return {};
+ }
+ app_info.version_code_major = maybe_code.value();
+ }
+
if (const xml::Attribute* revision_code_attr =
manifest_el->FindAttribute(xml::kSchemaAndroid, "revisionCode")) {
Maybe<uint32_t> maybe_code = ExtractCompiledInt(*revision_code_attr, &error_msg);
@@ -393,4 +418,21 @@ Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
return app_info;
}
+void SetLongVersionCode(xml::Element* manifest, uint64_t version) {
+ // Write the low bits of the version code to android:versionCode
+ auto version_code = manifest->FindOrCreateAttribute(xml::kSchemaAndroid, "versionCode");
+ version_code->value = StringPrintf("0x%08x", (uint32_t) (version & 0xffffffff));
+ version_code->compiled_value = ResourceUtils::TryParseInt(version_code->value);
+
+ auto version_high = (uint32_t) (version >> 32);
+ if (version_high != 0) {
+ // Write the high bits of the version code to android:versionCodeMajor
+ auto version_major = manifest->FindOrCreateAttribute(xml::kSchemaAndroid, "versionCodeMajor");
+ version_major->value = StringPrintf("0x%08x", version_high);
+ version_major->compiled_value = ResourceUtils::TryParseInt(version_major->value);
+ } else {
+ manifest->RemoveAttribute(xml::kSchemaAndroid, "versionCodeMajor");
+ }
+}
+
} // namespace aapt