Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Orlowska | 0faba5f | 2018-06-01 12:06:31 +0100 | [diff] [blame] | 20 | #include <regex> |
| 21 | |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 22 | #include "AppInfo.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 23 | #include "SdkConstants.h" |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 24 | #include "androidfw/IDiagnostics.h" |
| 25 | #include "androidfw/StringPiece.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 26 | #include "filter/ConfigFilter.h" |
| 27 | #include "split/TableSplitter.h" |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 28 | #include "xml/XmlDom.h" |
| 29 | |
| 30 | namespace 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. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 34 | std::optional<uint16_t> ParseTargetDensityParameter(const android::StringPiece& arg, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 35 | android::IDiagnostics* diag); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 36 | |
| 37 | // Parses a string of the form 'path/to/output.apk:<config>[,<config>...]' and fills in |
| 38 | // `out_path` with the path and `out_split` with the set of ConfigDescriptions. |
| 39 | // Returns false and logs a human friendly error message if the string was not legal. |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 40 | bool ParseSplitParameter(const android::StringPiece& arg, android::IDiagnostics* diag, |
| 41 | std::string* out_path, SplitConstraints* out_split); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 42 | |
| 43 | // Parses a set of config filter strings of the form 'en,fr-rFR' and returns an IConfigFilter. |
| 44 | // Returns nullptr and logs a human friendly error message if the string was not legal. |
| 45 | std::unique_ptr<IConfigFilter> ParseConfigFilterParameters(const std::vector<std::string>& args, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 46 | android::IDiagnostics* diag); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 47 | |
| 48 | // Adjust the SplitConstraints so that their SDK version is stripped if it |
| 49 | // is less than or equal to the min_sdk. Otherwise the resources that have had |
| 50 | // their SDK version stripped due to min_sdk won't ever match. |
| 51 | std::vector<SplitConstraints> AdjustSplitConstraintsForMinSdk( |
| 52 | int min_sdk, const std::vector<SplitConstraints>& split_constraints); |
| 53 | |
| 54 | // Generates a split AndroidManifest.xml given the split constraints and app info. The resulting |
| 55 | // XmlResource does not need to be linked via XmlReferenceLinker. |
| 56 | // This will never fail/return nullptr. |
| 57 | std::unique_ptr<xml::XmlResource> GenerateSplitManifest(const AppInfo& app_info, |
| 58 | const SplitConstraints& constraints); |
| 59 | |
| 60 | // Extracts relevant info from the AndroidManifest.xml. |
Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 61 | std::optional<AppInfo> ExtractAppInfoFromBinaryManifest(const xml::XmlResource& xml_res, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 62 | android::IDiagnostics* diag); |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 63 | |
Izabela Orlowska | 1056019 | 2018-04-13 11:56:35 +0100 | [diff] [blame] | 64 | // Returns a copy of 'name' which conforms to the regex '[a-zA-Z]+[a-zA-Z0-9_]*' by |
| 65 | // replacing nonconforming characters with underscores. |
| 66 | // |
| 67 | // See frameworks/base/core/java/android/content/pm/PackageParser.java which |
| 68 | // checks this at runtime. |
| 69 | std::string MakePackageSafeName(const std::string &name); |
| 70 | |
Ryan Mitchell | 5fa2bb1 | 2018-07-12 11:24:51 -0700 | [diff] [blame] | 71 | // Sets the versionCode and versionCodeMajor attributes to the version code. Attempts to encode the |
| 72 | // version code using the versionCode attribute only, and encodes using both versionCode and |
| 73 | // versionCodeMajor if the version code requires more than 32 bits. |
| 74 | void SetLongVersionCode(xml::Element* manifest, uint64_t version_code); |
| 75 | |
Izabela Orlowska | 0faba5f | 2018-06-01 12:06:31 +0100 | [diff] [blame] | 76 | // Returns a case insensitive regular expression based on the input. |
| 77 | std::regex GetRegularExpression(const std::string &input); |
| 78 | |
Adam Lesinski | d0f492d | 2017-04-03 18:12:45 -0700 | [diff] [blame] | 79 | } // namespace aapt |
| 80 | |
| 81 | #endif /* AAPT_SPLIT_UTIL_H */ |