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 20 #include <memory> 21 #include <string> 22 #include <unordered_set> 23 #include <vector> 24 25 #include "androidfw/ConfigDescription.h" 26 27 #include "Diagnostics.h" 28 #include "LoadedApk.h" 29 #include "configuration/ConfigurationParser.h" 30 31 namespace aapt { 32 33 struct MultiApkGeneratorOptions { 34 std::string out_dir; 35 std::vector<configuration::OutputArtifact> apk_artifacts; 36 TableFlattenerOptions table_flattener_options; 37 std::unordered_set<std::string> kept_artifacts; 38 }; 39 40 /** 41 * Generates a set of APKs that are a subset of the original base APKs. Each of the new APKs contain 42 * only the resources and assets for an artifact in the configuration file. 43 */ 44 class MultiApkGenerator { 45 public: 46 MultiApkGenerator(LoadedApk* apk, IAaptContext* context); 47 48 /** 49 * Writes a set of APKs to the provided output directory. Each APK is a subset fo the base APK and 50 * represents an artifact in the post processing configuration. 51 */ 52 bool FromBaseApk(const MultiApkGeneratorOptions& options); 53 54 protected: 55 virtual std::unique_ptr<ResourceTable> FilterTable(IAaptContext* context, 56 const configuration::OutputArtifact& artifact, 57 const ResourceTable& old_table, 58 FilterChain* chain); 59 60 private: GetDiagnostics()61 IDiagnostics* GetDiagnostics() { 62 return context_->GetDiagnostics(); 63 } 64 65 bool UpdateManifest(const configuration::OutputArtifact& artifact, 66 std::unique_ptr<xml::XmlResource>* updated_manifest, IDiagnostics* diag); 67 68 /** 69 * Adds the <screen> elements to the parent node for the provided density configuration. 70 */ 71 void AddScreens(const android::ConfigDescription& config, xml::Element* parent); 72 73 LoadedApk* apk_; 74 IAaptContext* context_; 75 }; 76 77 } // namespace aapt 78 79 #endif // AAPT2_APKSPLITTER_H 80