blob: dacd0c2130a90fa5f3e873a89bf6189a9eb94a6b [file] [log] [blame]
Pierre Lecesneff759e62017-02-01 00:29:25 +00001/*
2 * Copyright (C) 2016 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_LOADEDAPK_H
18#define AAPT_LOADEDAPK_H
19
20#include "androidfw/StringPiece.h"
21
Pierre Lecesneff759e62017-02-01 00:29:25 +000022#include "ResourceTable.h"
Shane Farmer57669432017-06-19 12:52:04 -070023#include "filter/Filter.h"
Pierre Lecesne2599aa42017-02-01 22:47:03 +000024#include "flatten/Archive.h"
Adam Lesinskid48944a2017-02-21 14:22:30 -080025#include "flatten/TableFlattener.h"
Pierre Lecesne2599aa42017-02-01 22:47:03 +000026#include "io/ZipArchive.h"
Pierre Lecesneff759e62017-02-01 00:29:25 +000027#include "unflatten/BinaryResourceParser.h"
28
Pierre Lecesneff759e62017-02-01 00:29:25 +000029namespace aapt {
30
31/** Info about an APK loaded in memory. */
32class LoadedApk {
33 public:
34 LoadedApk(
35 const Source& source,
36 std::unique_ptr<io::IFileCollection> apk,
37 std::unique_ptr<ResourceTable> table)
38 : source_(source), apk_(std::move(apk)), table_(std::move(table)) {}
39
40 io::IFileCollection* GetFileCollection() { return apk_.get(); }
41
42 ResourceTable* GetResourceTable() { return table_.get(); }
43
44 const Source& GetSource() { return source_; }
45
Pierre Lecesne2599aa42017-02-01 22:47:03 +000046 /**
47 * Writes the APK on disk at the given path, while also removing the resource
48 * files that are not referenced in the resource table.
49 */
Shane Farmer0a5b2012017-06-22 12:24:12 -070050 virtual bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options,
51 IArchiveWriter* writer);
Pierre Lecesne2599aa42017-02-01 22:47:03 +000052
Shane Farmer57669432017-06-19 12:52:04 -070053 /**
54 * Writes the APK on disk at the given path, while also removing the resource
55 * files that are not referenced in the resource table. The provided filter
56 * chain is applied to each entry in the APK file.
57 */
Shane Farmer0a5b2012017-06-22 12:24:12 -070058 virtual bool WriteToArchive(IAaptContext* context, ResourceTable* split_table,
59 const TableFlattenerOptions& options, FilterChain* filters,
60 IArchiveWriter* writer);
Shane Farmer57669432017-06-19 12:52:04 -070061
Pierre Lecesne2599aa42017-02-01 22:47:03 +000062 static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context,
63 const android::StringPiece& path);
Pierre Lecesneff759e62017-02-01 00:29:25 +000064
65 private:
66 Source source_;
67 std::unique_ptr<io::IFileCollection> apk_;
68 std::unique_ptr<ResourceTable> table_;
69
70 DISALLOW_COPY_AND_ASSIGN(LoadedApk);
71};
72
73} // namespace aapt
74
75#endif /* AAPT_LOADEDAPK_H */