blob: 3d4ca245ee28434e24c7ae7df7d67b5540c0b171 [file] [log] [blame]
Adam Lesinskid0f492d2017-04-03 18:12:45 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAPT_SPLIT_UTIL_H
18#define AAPT_SPLIT_UTIL_H
19
Izabela Orlowska0faba5f2018-06-01 12:06:31 +010020#include <regex>
Iurii Makhno054e4332022-10-12 16:03:03 +000021#include <set>
22#include <unordered_set>
Izabela Orlowska0faba5f2018-06-01 12:06:31 +010023
Adam Lesinskid0f492d2017-04-03 18:12:45 -070024#include "AppInfo.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070025#include "SdkConstants.h"
Jeremy Meyer56f36e82022-05-20 20:35:42 +000026#include "androidfw/IDiagnostics.h"
27#include "androidfw/StringPiece.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070028#include "filter/ConfigFilter.h"
Iurii Makhno054e4332022-10-12 16:03:03 +000029#include "process/IResourceTableConsumer.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070030#include "split/TableSplitter.h"
Adam Lesinskid0f492d2017-04-03 18:12:45 -070031#include "xml/XmlDom.h"
32
33namespace aapt {
34
35// Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
36// Returns Nothing and logs a human friendly error message if the string was not legal.
Ryan Mitchell4382e442021-07-14 12:53:01 -070037std::optional<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg,
Jeremy Meyer56f36e82022-05-20 20:35:42 +000038 android::IDiagnostics* diag);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070039
40// Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in
41// `out_path` with the path and `out_split` with the set of ConfigDescriptions.
42// Returns false and logs a human friendly error message if the string was not legal.
Jeremy Meyer56f36e82022-05-20 20:35:42 +000043bool ParseSplitParameter(const android::StringPiece& arg, android::IDiagnostics* diag,
44 std::string* out_path, SplitConstraints* out_split);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070045
46// Parses a set of config filter strings of the form 'en,fr-rFR' and returns an IConfigFilter.
47// Returns nullptr and logs a human friendly error message if the string was not legal.
48std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
Jeremy Meyer56f36e82022-05-20 20:35:42 +000049 android::IDiagnostics* diag);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070050
51// Adjust the SplitConstraints so that their SDK version is stripped if it
52// is less than or equal to the min_sdk. Otherwise the resources that have had
53// their SDK version stripped due to min_sdk won't ever match.
54std::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk(
55 int min_sdk, const std::vector<SplitConstraints>& split_constraints);
56
57// Generates a split AndroidManifest.xml given the split constraints and app info. The resulting
58// XmlResource does not need to be linked via XmlReferenceLinker.
59// This will never fail/return nullptr.
60std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
61 const SplitConstraints& constraints);
62
63// Extracts relevant info from the AndroidManifest.xml.
Ryan Mitchell4382e442021-07-14 12:53:01 -070064std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
Jeremy Meyer56f36e82022-05-20 20:35:42 +000065 android::IDiagnostics* diag);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070066
Izabela Orlowska10560192018-04-13 11:56:35 +010067// Returns a copy of 'name' which conforms to the regex '[a-zA-Z]+[a-zA-Z0-9_]*' by
68// replacing nonconforming characters with underscores.
69//
70// See frameworks/base/core/java/android/content/pm/PackageParser.java which
71// checks this at runtime.
72std::string MakePackageSafeName(const std::string &name);
73
Ryan Mitchell5fa2bb12018-07-12 11:24:51 -070074// Sets the versionCode and versionCodeMajor attributes to the version code. Attempts to encode the
75// version code using the versionCode attribute only, and encodes using both versionCode and
76// versionCodeMajor if the version code requires more than 32 bits.
77void SetLongVersionCode(xml::Element* manifest, uint64_t version_code);
78
Izabela Orlowska0faba5f2018-06-01 12:06:31 +010079// Returns a case insensitive regular expression based on the input.
80std::regex GetRegularExpression(const std::string &input);
81
Iurii Makhno054e4332022-10-12 16:03:03 +000082bool ParseResourceConfig(const std::string& content, IAaptContext* context,
83 std::unordered_set<ResourceName>& out_resource_exclude_list,
84 std::set<ResourceName>& out_name_collapse_exemptions);
85
Adam Lesinskid0f492d2017-04-03 18:12:45 -070086} // namespace aapt
87
88#endif /* AAPT_SPLIT_UTIL_H */