blob: dedb610e1caa99743321b9b7169014bddce14833 [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>
23
Shane Farmer0a5b2012017-06-22 12:24:12 -070024#include "Diagnostics.h"
25#include "LoadedApk.h"
26#include "configuration/ConfigurationParser.h"
27
28namespace aapt {
29
Shane Farmerefe45392017-08-21 14:39:28 -070030struct MultiApkGeneratorOptions {
31 std::string out_dir;
32 configuration::PostProcessingConfiguration config;
33 TableFlattenerOptions table_flattener_options;
Shane Farmer666de342017-11-29 16:07:51 -080034 std::unordered_set<std::string> kept_artifacts;
Shane Farmerefe45392017-08-21 14:39:28 -070035};
36
Shane Farmer0a5b2012017-06-22 12:24:12 -070037/**
38 * Generates a set of APKs that are a subset of the original base APKs. Each of the new APKs contain
39 * only the resources and assets for an artifact in the configuration file.
40 */
41class MultiApkGenerator {
42 public:
43 MultiApkGenerator(LoadedApk* apk, IAaptContext* context);
44
45 /**
46 * Writes a set of APKs to the provided output directory. Each APK is a subset fo the base APK and
47 * represents an artifact in the post processing configuration.
48 */
Shane Farmerefe45392017-08-21 14:39:28 -070049 bool FromBaseApk(const MultiApkGeneratorOptions& options);
50
51 protected:
52 virtual std::unique_ptr<ResourceTable> FilterTable(
53 const configuration::Artifact& artifact,
54 const configuration::PostProcessingConfiguration& config, const ResourceTable& old_table,
Shane Farmer20ac0342017-11-29 16:55:05 -080055 IAaptContext* context, FilterChain* chain);
Shane Farmer0a5b2012017-06-22 12:24:12 -070056
57 private:
58 IDiagnostics* GetDiagnostics() {
59 return context_->GetDiagnostics();
60 }
61
Shane Farmer810fd182017-09-21 14:37:44 -070062 bool UpdateManifest(const configuration::Artifact& artifact,
63 const configuration::PostProcessingConfiguration& config,
64 std::unique_ptr<xml::XmlResource>* updated_manifest, IDiagnostics* diag);
65
Shane Farmer0a5b2012017-06-22 12:24:12 -070066 LoadedApk* apk_;
67 IAaptContext* context_;
68};
69
70} // namespace aapt
71
72#endif // AAPT2_APKSPLITTER_H