blob: f8878d13ae35bdb02ad58bdb4cffb3841a04ae17 [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"
Pierre Lecesne2599aa42017-02-01 22:47:03 +000023#include "flatten/Archive.h"
24#include "io/ZipArchive.h"
Pierre Lecesneff759e62017-02-01 00:29:25 +000025#include "unflatten/BinaryResourceParser.h"
26
Pierre Lecesneff759e62017-02-01 00:29:25 +000027namespace aapt {
28
29/** Info about an APK loaded in memory. */
30class LoadedApk {
31 public:
32 LoadedApk(
33 const Source& source,
34 std::unique_ptr<io::IFileCollection> apk,
35 std::unique_ptr<ResourceTable> table)
36 : source_(source), apk_(std::move(apk)), table_(std::move(table)) {}
37
38 io::IFileCollection* GetFileCollection() { return apk_.get(); }
39
40 ResourceTable* GetResourceTable() { return table_.get(); }
41
42 const Source& GetSource() { return source_; }
43
Pierre Lecesne2599aa42017-02-01 22:47:03 +000044 /**
45 * Writes the APK on disk at the given path, while also removing the resource
46 * files that are not referenced in the resource table.
47 */
48 bool WriteToArchive(IAaptContext* context, IArchiveWriter* writer);
49
50 static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context,
51 const android::StringPiece& path);
Pierre Lecesneff759e62017-02-01 00:29:25 +000052
53 private:
54 Source source_;
55 std::unique_ptr<io::IFileCollection> apk_;
56 std::unique_ptr<ResourceTable> table_;
57
58 DISALLOW_COPY_AND_ASSIGN(LoadedApk);
59};
60
61} // namespace aapt
62
63#endif /* AAPT_LOADEDAPK_H */