blob: c8588791662a387fef16c7bae4cc4eff2e44f8f2 [file] [log] [blame]
Shane Farmer0a5b2012017-06-22 12:24:12 -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 AAPT2_APKSPLITTER_H
18#define AAPT2_APKSPLITTER_H
19
Shane Farmer666de342017-11-29 16:07:51 -080020#include <memory>
21#include <string>
22#include <unordered_set>
Shane Farmercb6c3f92017-11-27 13:19:36 -080023#include <vector>
Shane Farmer666de342017-11-29 16:07:51 -080024
Shane Farmer0a5b2012017-06-22 12:24:12 -070025#include "Diagnostics.h"
26#include "LoadedApk.h"
27#include "configuration/ConfigurationParser.h"
28
29namespace aapt {
30
Shane Farmerefe45392017-08-21 14:39:28 -070031struct MultiApkGeneratorOptions {
32 std::string out_dir;
Shane Farmercb6c3f92017-11-27 13:19:36 -080033 std::vector<configuration::OutputArtifact> apk_artifacts;
Shane Farmerefe45392017-08-21 14:39:28 -070034 TableFlattenerOptions table_flattener_options;
Shane Farmer666de342017-11-29 16:07:51 -080035 std::unordered_set<std::string> kept_artifacts;
Shane Farmerefe45392017-08-21 14:39:28 -070036};
37
Shane Farmer0a5b2012017-06-22 12:24:12 -070038/**
39 * Generates a set of APKs that are a subset of the original base APKs. Each of the new APKs contain
40 * only the resources and assets for an artifact in the configuration file.
41 */
42class MultiApkGenerator {
43 public:
44 MultiApkGenerator(LoadedApk* apk, IAaptContext* context);
45
46 /**
47 * Writes a set of APKs to the provided output directory. Each APK is a subset fo the base APK and
48 * represents an artifact in the post processing configuration.
49 */
Shane Farmerefe45392017-08-21 14:39:28 -070050 bool FromBaseApk(const MultiApkGeneratorOptions& options);
51
52 protected:
Shane Farmercb6c3f92017-11-27 13:19:36 -080053 virtual std::unique_ptr<ResourceTable> FilterTable(IAaptContext* context,
54 const configuration::OutputArtifact& artifact,
55 const ResourceTable& old_table,
56 FilterChain* chain);
Shane Farmer0a5b2012017-06-22 12:24:12 -070057
58 private:
59 IDiagnostics* GetDiagnostics() {
60 return context_->GetDiagnostics();
61 }
62
Shane Farmercb6c3f92017-11-27 13:19:36 -080063 bool UpdateManifest(const configuration::OutputArtifact& artifact,
Shane Farmer810fd182017-09-21 14:37:44 -070064 std::unique_ptr<xml::XmlResource>* updated_manifest, IDiagnostics* diag);
65
Shane Farmerd05b9132018-02-14 15:40:35 -080066 /**
67 * Adds the <screen> elements to the parent node for the provided density configuration.
68 */
69 void AddScreens(const ConfigDescription& config, xml::Element* parent);
70
Shane Farmer0a5b2012017-06-22 12:24:12 -070071 LoadedApk* apk_;
72 IAaptContext* context_;
73};
74
75} // namespace aapt
76
77#endif // AAPT2_APKSPLITTER_H