• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
22 #include "ResourceTable.h"
23 #include "filter/Filter.h"
24 #include "flatten/Archive.h"
25 #include "flatten/TableFlattener.h"
26 #include "io/ZipArchive.h"
27 #include "unflatten/BinaryResourceParser.h"
28 
29 namespace aapt {
30 
31 /** Info about an APK loaded in memory. */
32 class LoadedApk {
33  public:
LoadedApk(const Source & source,std::unique_ptr<io::IFileCollection> apk,std::unique_ptr<ResourceTable> table)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 
GetFileCollection()40   io::IFileCollection* GetFileCollection() { return apk_.get(); }
41 
GetResourceTable()42   ResourceTable* GetResourceTable() { return table_.get(); }
43 
GetSource()44   const Source& GetSource() { return source_; }
45 
46   /**
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    */
50   bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options,
51                       IArchiveWriter* writer);
52 
53   /**
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    */
58   bool WriteToArchive(IAaptContext* context, const TableFlattenerOptions& options,
59                       FilterChain* filters, IArchiveWriter* writer);
60 
61   static std::unique_ptr<LoadedApk> LoadApkFromPath(IAaptContext* context,
62                                                     const android::StringPiece& path);
63 
64  private:
65   Source source_;
66   std::unique_ptr<io::IFileCollection> apk_;
67   std::unique_ptr<ResourceTable> table_;
68 
69   DISALLOW_COPY_AND_ASSIGN(LoadedApk);
70 };
71 
72 }  // namespace aapt
73 
74 #endif /* AAPT_LOADEDAPK_H */
75