ApkAssets.h revision 7ad1110ecd6a840fcd2895c62668828a1ca029c6
17ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski/* 27ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * Copyright (C) 2016 The Android Open Source Project 37ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * 47ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 57ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * you may not use this file except in compliance with the License. 67ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * You may obtain a copy of the License at 77ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * 87ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 97ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * 107ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * Unless required by applicable law or agreed to in writing, software 117ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 127ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * See the License for the specific language governing permissions and 147ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski * limitations under the License. 157ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski */ 167ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 177ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#ifndef APKASSETS_H_ 187ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#define APKASSETS_H_ 197ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 207ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include <memory> 217ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include <string> 227ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 237ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "android-base/macros.h" 247ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "ziparchive/zip_archive.h" 257ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 267ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "androidfw/Asset.h" 277ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#include "androidfw/LoadedArsc.h" 287ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 297ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinskinamespace android { 307ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 317ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski// Holds an APK. 327ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinskiclass ApkAssets { 337ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski public: 347ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski static std::unique_ptr<ApkAssets> Load(const std::string& path); 357ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 367ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Asset> Open(const std::string& path, 377ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski Asset::AccessMode mode = Asset::AccessMode::ACCESS_RANDOM) const; 387ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 397ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski inline const std::string& GetPath() const { return path_; } 407ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 417ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski inline const LoadedArsc* GetLoadedArsc() const { return loaded_arsc_.get(); } 427ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 437ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski private: 447ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski DISALLOW_COPY_AND_ASSIGN(ApkAssets); 457ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 467ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ApkAssets() = default; 477ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 487ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski struct ZipArchivePtrCloser { 497ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski void operator()(::ZipArchiveHandle handle) { ::CloseArchive(handle); } 507ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski }; 517ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 527ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski using ZipArchivePtr = 537ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<typename std::remove_pointer<::ZipArchiveHandle>::type, ZipArchivePtrCloser>; 547ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski ZipArchivePtr zip_handle_; 557ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::string path_; 567ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<Asset> resources_asset_; 577ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski std::unique_ptr<LoadedArsc> loaded_arsc_; 587ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski}; 597ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 607ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski} // namespace android 617ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski 627ad1110ecd6a840fcd2895c62668828a1ca029c6Adam Lesinski#endif /* APKASSETS_H_ */ 63