blob: 59eb8161a868bfef7c3f9282dbf6445a00f5abfa [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"
Adam Lesinskid48944a2017-02-21 14:22:30 -080024#include "flatten/TableFlattener.h"
Pierre Lecesne2599aa42017-02-01 22:47:03 +000025#include "io/ZipArchive.h"
Pierre Lecesneff759e62017-02-01 00:29:25 +000026#include "unflatten/BinaryResourceParser.h"
27
Pierre Lecesneff759e62017-02-01 00:29:25 +000028namespace aapt {
29
30/** Info about an APK loaded in memory. */
31class LoadedApk {
32 public:
33 LoadedApk(
34 const Source& source,
35 std::unique_ptr<io::IFileCollection> apk,
36 std::unique_ptr<ResourceTable> table)
37 : source_(source), apk_(std::move(apk)), table_(std::move(table)) {}
38
39 io::IFileCollection* GetFileCollection() { return apk_.get(); }
40
41 ResourceTable* GetResourceTable() { return table_.get(); }
42
43 const Source& GetSource() { return source_; }
44
Pierre Lecesne2599aa42017-02-01 22:47:03 +000045 /**
46 * Writes the APK on disk at the given path, while also removing the resource
47 * files that are not referenced in the resource table.
48 */
Adam Lesinskid48944a2017-02-21 14:22:30 -080049 bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options,
50 IArchiveWriter* writer);
Pierre Lecesne2599aa42017-02-01 22:47:03 +000051
52 static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context,
53 const android::StringPiece& path);
Pierre Lecesneff759e62017-02-01 00:29:25 +000054
55 private:
56 Source source_;
57 std::unique_ptr<io::IFileCollection> apk_;
58 std::unique_ptr<ResourceTable> table_;
59
60 DISALLOW_COPY_AND_ASSIGN(LoadedApk);
61};
62
63} // namespace aapt
64
65#endif /* AAPT_LOADEDAPK_H */