1d0f492db038c6210c1138865d816bfb134376538Adam Lesinski/*
2d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * Copyright (C) 2017 The Android Open Source Project
3d0f492db038c6210c1138865d816bfb134376538Adam Lesinski *
4d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License");
5d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * you may not use this file except in compliance with the License.
6d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * You may obtain a copy of the License at
7d0f492db038c6210c1138865d816bfb134376538Adam Lesinski *
8d0f492db038c6210c1138865d816bfb134376538Adam Lesinski *      http://www.apache.org/licenses/LICENSE-2.0
9d0f492db038c6210c1138865d816bfb134376538Adam Lesinski *
10d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * Unless required by applicable law or agreed to in writing, software
11d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS,
12d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * See the License for the specific language governing permissions and
14d0f492db038c6210c1138865d816bfb134376538Adam Lesinski * limitations under the License.
15d0f492db038c6210c1138865d816bfb134376538Adam Lesinski */
16d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
17d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#ifndef AAPT_SPLIT_UTIL_H
18d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#define AAPT_SPLIT_UTIL_H
19d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
20d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "androidfw/StringPiece.h"
21d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
22d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "AppInfo.h"
23d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "Diagnostics.h"
24d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "SdkConstants.h"
25d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "filter/ConfigFilter.h"
26d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "split/TableSplitter.h"
27d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "util/Maybe.h"
28d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#include "xml/XmlDom.h"
29d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
30d0f492db038c6210c1138865d816bfb134376538Adam Lesinskinamespace aapt {
31d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
32d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Parses a configuration density (ex. hdpi, xxhdpi, 234dpi, anydpi, etc).
33d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Returns Nothing and logs a human friendly error message if the string was not legal.
34d0f492db038c6210c1138865d816bfb134376538Adam LesinskiMaybe<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg, IDiagnostics* diag);
35d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
36d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in
37d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// `out_path` with the path and `out_split` with the set of ConfigDescriptions.
38d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Returns false and logs a human friendly error message if the string was not legal.
39d0f492db038c6210c1138865d816bfb134376538Adam Lesinskibool ParseSplitParameter(const android::StringPiece& arg, IDiagnostics* diag, std::string* out_path,
40d0f492db038c6210c1138865d816bfb134376538Adam Lesinski                         SplitConstraints* out_split);
41d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
42d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Parses a set of config filter strings of the form 'en,fr-rFR' and returns an IConfigFilter.
43d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Returns nullptr and logs a human friendly error message if the string was not legal.
44d0f492db038c6210c1138865d816bfb134376538Adam Lesinskistd::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args,
45d0f492db038c6210c1138865d816bfb134376538Adam Lesinski                                                           IDiagnostics* diag);
46d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
47d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Adjust the SplitConstraints so that their SDK version is stripped if it
48d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// is less than or equal to the min_sdk. Otherwise the resources that have had
49d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// their SDK version stripped due to min_sdk won't ever match.
50d0f492db038c6210c1138865d816bfb134376538Adam Lesinskistd::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk(
51d0f492db038c6210c1138865d816bfb134376538Adam Lesinski    int min_sdk, const std::vector<SplitConstraints>& split_constraints);
52d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
53d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Generates a split AndroidManifest.xml given the split constraints and app info. The resulting
54d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// XmlResource does not need to be linked via XmlReferenceLinker.
55d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// This will never fail/return nullptr.
56d0f492db038c6210c1138865d816bfb134376538Adam Lesinskistd::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info,
57d0f492db038c6210c1138865d816bfb134376538Adam Lesinski                                                        const SplitConstraints& constraints);
58d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
59d0f492db038c6210c1138865d816bfb134376538Adam Lesinski// Extracts relevant info from the AndroidManifest.xml.
608780eb6e4918ae24fb1ae74d631042c32e41dc3dAdam LesinskiMaybe<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res,
618780eb6e4918ae24fb1ae74d631042c32e41dc3dAdam Lesinski                                                IDiagnostics* diag);
62d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
63d0f492db038c6210c1138865d816bfb134376538Adam Lesinski}  // namespace aapt
64d0f492db038c6210c1138865d816bfb134376538Adam Lesinski
65d0f492db038c6210c1138865d816bfb134376538Adam Lesinski#endif /* AAPT_SPLIT_UTIL_H */
66