Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -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 AAPT2_APKSPLITTER_H |
| 18 | #define AAPT2_APKSPLITTER_H |
| 19 | |
Shane Farmer | 666de34 | 2017-11-29 16:07:51 -0800 | [diff] [blame] | 20 | #include <memory> |
| 21 | #include <string> |
| 22 | #include <unordered_set> |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 23 | #include <vector> |
Shane Farmer | 666de34 | 2017-11-29 16:07:51 -0800 | [diff] [blame] | 24 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 25 | #include "LoadedApk.h" |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 26 | #include "androidfw/ConfigDescription.h" |
| 27 | #include "androidfw/IDiagnostics.h" |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 28 | #include "configuration/ConfigurationParser.h" |
| 29 | |
| 30 | namespace aapt { |
| 31 | |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 32 | struct MultiApkGeneratorOptions { |
| 33 | std::string out_dir; |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 34 | std::vector<configuration::OutputArtifact> apk_artifacts; |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 35 | TableFlattenerOptions table_flattener_options; |
Shane Farmer | 666de34 | 2017-11-29 16:07:51 -0800 | [diff] [blame] | 36 | std::unordered_set<std::string> kept_artifacts; |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 39 | /** |
| 40 | * Generates a set of APKs that are a subset of the original base APKs. Each of the new APKs contain |
| 41 | * only the resources and assets for an artifact in the configuration file. |
| 42 | */ |
| 43 | class MultiApkGenerator { |
| 44 | public: |
| 45 | MultiApkGenerator(LoadedApk* apk, IAaptContext* context); |
| 46 | |
| 47 | /** |
| 48 | * Writes a set of APKs to the provided output directory. Each APK is a subset fo the base APK and |
| 49 | * represents an artifact in the post processing configuration. |
| 50 | */ |
Shane Farmer | efe4539 | 2017-08-21 14:39:28 -0700 | [diff] [blame] | 51 | bool FromBaseApk(const MultiApkGeneratorOptions& options); |
| 52 | |
| 53 | protected: |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 54 | virtual std::unique_ptr<ResourceTable> FilterTable(IAaptContext* context, |
| 55 | const configuration::OutputArtifact& artifact, |
| 56 | const ResourceTable& old_table, |
| 57 | FilterChain* chain); |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 58 | |
| 59 | private: |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 60 | android::IDiagnostics* GetDiagnostics() { |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 61 | return context_->GetDiagnostics(); |
| 62 | } |
| 63 | |
Shane Farmer | cb6c3f9 | 2017-11-27 13:19:36 -0800 | [diff] [blame] | 64 | bool UpdateManifest(const configuration::OutputArtifact& artifact, |
Jeremy Meyer | 56f36e8 | 2022-05-20 20:35:42 +0000 | [diff] [blame^] | 65 | std::unique_ptr<xml::XmlResource>* updated_manifest, |
| 66 | android::IDiagnostics* diag); |
Shane Farmer | 810fd18 | 2017-09-21 14:37:44 -0700 | [diff] [blame] | 67 | |
Shane Farmer | d05b913 | 2018-02-14 15:40:35 -0800 | [diff] [blame] | 68 | /** |
| 69 | * Adds the <screen> elements to the parent node for the provided density configuration. |
| 70 | */ |
MÃ¥rten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 71 | void AddScreens(const android::ConfigDescription& config, xml::Element* parent); |
Shane Farmer | d05b913 | 2018-02-14 15:40:35 -0800 | [diff] [blame] | 72 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 73 | LoadedApk* apk_; |
| 74 | IAaptContext* context_; |
| 75 | }; |
| 76 | |
| 77 | } // namespace aapt |
| 78 | |
| 79 | #endif // AAPT2_APKSPLITTER_H |