blob: 7611c152610495e91664426299a8284d9914d205 [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
20#include "androidfw/StringPiece.h"
21
22#include "AppInfo.h"
23#include "Diagnostics.h"
24#include "SdkConstants.h"
25#include "filter/ConfigFilter.h"
26#include "split/TableSplitter.h"
27#include "util/Maybe.h"
28#include "xml/XmlDom.h"
29
30namespace aapt {
31
32// Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
33// Returns Nothing and logs a human friendly error message if the string was not legal.
34Maybe<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg, IDiagnostics* diag);
35
36// Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in
37// `out_path` with the path and `out_split` with the set of ConfigDescriptions.
38// Returns false and logs a human friendly error message if the string was not legal.
39bool ParseSplitParameter(const android::StringPiece& arg, IDiagnostics* diag, std::string* out_path,
40 SplitConstraints* out_split);
41
42// Parses a set of config filter strings of the form 'en,fr-rFR' and returns an IConfigFilter.
43// Returns nullptr and logs a human friendly error message if the string was not legal.
44std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
45 IDiagnostics* diag);
46
47// Adjust the SplitConstraints so that their SDK version is stripped if it
48// is less than or equal to the min_sdk. Otherwise the resources that have had
49// their SDK version stripped due to min_sdk won't ever match.
50std::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk(
51 int min_sdk, const std::vector<SplitConstraints>& split_constraints);
52
53// Generates a split AndroidManifest.xml given the split constraints and app info. The resulting
54// XmlResource does not need to be linked via XmlReferenceLinker.
55// This will never fail/return nullptr.
56std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
57 const SplitConstraints& constraints);
58
59// Extracts relevant info from the AndroidManifest.xml.
Adam Lesinski8780eb62017-10-31 17:44:39 -070060Maybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
61 IDiagnostics* diag);
Adam Lesinskid0f492d2017-04-03 18:12:45 -070062
63} // namespace aapt
64
65#endif /* AAPT_SPLIT_UTIL_H */