The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | // |
| 18 | // Asset management class. AssetManager objects are thread-safe. |
| 19 | // |
| 20 | #ifndef __LIBS_ASSETMANAGER_H |
| 21 | #define __LIBS_ASSETMANAGER_H |
| 22 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 23 | #include <androidfw/Asset.h> |
| 24 | #include <androidfw/AssetDir.h> |
Mathias Agopian | 1f5762e | 2013-05-06 20:20:34 -0700 | [diff] [blame] | 25 | #include <androidfw/ZipFileRO.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 27 | #include <utils/SortedVector.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/String16.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 29 | #include <utils/String8.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include <utils/threads.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 31 | #include <utils/Vector.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
Christopher Tate | 6cce32b | 2010-07-12 18:21:36 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Native-app access is via the opaque typedef struct AAssetManager in the C namespace. |
| 35 | */ |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | struct AAssetManager { }; |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | }; |
| 44 | #endif |
| 45 | |
| 46 | |
| 47 | /* |
| 48 | * Now the proper C++ android-namespace definitions |
| 49 | */ |
| 50 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | namespace android { |
| 52 | |
| 53 | class Asset; // fwd decl for things that include Asset.h first |
| 54 | class ResTable; |
| 55 | struct ResTable_config; |
| 56 | |
| 57 | /* |
| 58 | * Every application that uses assets needs one instance of this. A |
| 59 | * single instance may be shared across multiple threads, and a single |
| 60 | * thread may have more than one instance (the latter is discouraged). |
| 61 | * |
| 62 | * The purpose of the AssetManager is to create Asset objects. To do |
| 63 | * this efficiently it may cache information about the locations of |
| 64 | * files it has seen. This can be controlled with the "cacheMode" |
| 65 | * argument. |
| 66 | * |
| 67 | * The asset hierarchy may be examined like a filesystem, using |
| 68 | * AssetDir objects to peruse a single directory. |
| 69 | */ |
Christopher Tate | 6cce32b | 2010-07-12 18:21:36 -0700 | [diff] [blame] | 70 | class AssetManager : public AAssetManager { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | public: |
Mårten Kongstad | 65a05fd | 2014-01-31 14:01:52 +0100 | [diff] [blame] | 72 | static const char* RESOURCES_FILENAME; |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 73 | static const char* IDMAP_BIN; |
| 74 | static const char* OVERLAY_DIR; |
Jakub Adamek | 1c15c63 | 2016-09-23 09:07:11 +0100 | [diff] [blame^] | 75 | /* |
| 76 | * If OVERLAY_SUBDIR_PROPERTY is set, search for runtime resource overlay |
| 77 | * APKs in OVERLAY_SUBDIR/<value of OVERLAY_SUBDIR_PROPERTY>/ rather than in |
| 78 | * OVERLAY_DIR. |
| 79 | */ |
| 80 | static const char* OVERLAY_SUBDIR; |
| 81 | static const char* OVERLAY_SUBDIR_PROPERTY; |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 82 | static const char* TARGET_PACKAGE_NAME; |
| 83 | static const char* TARGET_APK_PATH; |
| 84 | static const char* IDMAP_DIR; |
| 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | typedef enum CacheMode { |
| 87 | CACHE_UNKNOWN = 0, |
| 88 | CACHE_OFF, // don't try to cache file locations |
| 89 | CACHE_DEFER, // construct cache as pieces are needed |
| 90 | //CACHE_SCAN, // scan full(!) asset hierarchy at init() time |
| 91 | } CacheMode; |
| 92 | |
| 93 | AssetManager(CacheMode cacheMode = CACHE_OFF); |
| 94 | virtual ~AssetManager(void); |
| 95 | |
| 96 | static int32_t getGlobalCount(); |
| 97 | |
| 98 | /* |
| 99 | * Add a new source for assets. This can be called multiple times to |
| 100 | * look in multiple places for assets. It can be either a directory (for |
| 101 | * finding assets as raw files on the disk) or a ZIP file. This newly |
| 102 | * added asset path will be examined first when searching for assets, |
Tao Bai | a6d7e3f | 2015-09-01 18:49:54 -0700 | [diff] [blame] | 103 | * before any that were previously added, the assets are added as shared |
| 104 | * library if appAsLib is true. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | * |
| 106 | * Returns "true" on success, "false" on failure. If 'cookie' is non-NULL, |
| 107 | * then on success, *cookie is set to the value corresponding to the |
| 108 | * newly-added asset source. |
| 109 | */ |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 110 | bool addAssetPath(const String8& path, int32_t* cookie, |
| 111 | bool appAsLib=false, bool isSystemAsset=false); |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 112 | bool addOverlayPath(const String8& path, int32_t* cookie); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 114 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | * Convenience for adding the standard system assets. Uses the |
| 116 | * ANDROID_ROOT environment variable to find them. |
| 117 | */ |
| 118 | bool addDefaultAssets(); |
| 119 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 120 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | * Iterate over the asset paths in this manager. (Previously |
| 122 | * added via addAssetPath() and addDefaultAssets().) On first call, |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 123 | * 'cookie' must be 0, resulting in the first cookie being returned. |
| 124 | * Each next cookie will be returned there-after, until -1 indicating |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | * the end has been reached. |
| 126 | */ |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 127 | int32_t nextAssetPath(const int32_t cookie) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 129 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | * Return an asset path in the manager. 'which' must be between 0 and |
| 131 | * countAssetPaths(). |
| 132 | */ |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 133 | String8 getAssetPath(const int32_t cookie) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Set the current locale and vendor. The locale can change during |
| 137 | * the lifetime of an AssetManager if the user updates the device's |
| 138 | * language setting. The vendor is less likely to change. |
| 139 | * |
| 140 | * Pass in NULL to indicate no preference. |
| 141 | */ |
| 142 | void setLocale(const char* locale); |
| 143 | void setVendor(const char* vendor); |
| 144 | |
| 145 | /* |
| 146 | * Choose screen orientation for resources values returned. |
| 147 | */ |
| 148 | void setConfiguration(const ResTable_config& config, const char* locale = NULL); |
| 149 | |
Dianne Hackborn | 08d5b8f | 2010-08-04 11:12:40 -0700 | [diff] [blame] | 150 | void getConfiguration(ResTable_config* outConfig) const; |
| 151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | typedef Asset::AccessMode AccessMode; // typing shortcut |
| 153 | |
| 154 | /* |
| 155 | * Open an asset. |
| 156 | * |
| 157 | * This will search through locale-specific and vendor-specific |
| 158 | * directories and packages to find the file. |
| 159 | * |
| 160 | * The object returned does not depend on the AssetManager. It should |
| 161 | * be freed by calling Asset::close(). |
| 162 | */ |
| 163 | Asset* open(const char* fileName, AccessMode mode); |
| 164 | |
| 165 | /* |
| 166 | * Open a non-asset file as an asset. |
| 167 | * |
| 168 | * This is for opening files that are included in an asset package |
| 169 | * but aren't assets. These sit outside the usual "locale/vendor" |
| 170 | * path hierarchy, and will not be seen by "AssetDir" or included |
| 171 | * in our filename cache. |
| 172 | */ |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 173 | Asset* openNonAsset(const char* fileName, AccessMode mode, int32_t* outCookie = NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * Explicit non-asset file. The file explicitly named by the cookie (the |
| 177 | * resource set to look in) and fileName will be opened and returned. |
| 178 | */ |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 179 | Asset* openNonAsset(const int32_t cookie, const char* fileName, AccessMode mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * Open a directory within the asset hierarchy. |
| 183 | * |
| 184 | * The contents of the directory are an amalgam of vendor-specific, |
| 185 | * locale-specific, and generic assets stored loosely or in asset |
| 186 | * packages. Depending on the cache setting and previous accesses, |
| 187 | * this call may incur significant disk overhead. |
| 188 | * |
| 189 | * To open the top-level directory, pass in "". |
| 190 | */ |
| 191 | AssetDir* openDir(const char* dirName); |
| 192 | |
| 193 | /* |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 194 | * Open a directory within a particular path of the asset manager. |
| 195 | * |
| 196 | * The contents of the directory are an amalgam of vendor-specific, |
| 197 | * locale-specific, and generic assets stored loosely or in asset |
| 198 | * packages. Depending on the cache setting and previous accesses, |
| 199 | * this call may incur significant disk overhead. |
| 200 | * |
| 201 | * To open the top-level directory, pass in "". |
| 202 | */ |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 203 | AssetDir* openNonAssetDir(const int32_t cookie, const char* dirName); |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | * Get the type of a file in the asset hierarchy. They will either |
| 207 | * be "regular" or "directory". [Currently only works for "regular".] |
| 208 | * |
| 209 | * Can also be used as a quick test for existence of a file. |
| 210 | */ |
| 211 | FileType getFileType(const char* fileName); |
| 212 | |
| 213 | /* |
| 214 | * Return the complete resource table to find things in the package. |
| 215 | */ |
| 216 | const ResTable& getResources(bool required = true) const; |
| 217 | |
| 218 | /* |
| 219 | * Discard cached filename information. This only needs to be called |
| 220 | * if somebody has updated the set of "loose" files, and we want to |
| 221 | * discard our cached notion of what's where. |
| 222 | */ |
| 223 | void purge(void) { purgeFileNameCacheLocked(); } |
| 224 | |
| 225 | /* |
| 226 | * Return true if the files this AssetManager references are all |
| 227 | * up-to-date (have not been changed since it was created). If false |
| 228 | * is returned, you will need to create a new AssetManager to get |
| 229 | * the current data. |
| 230 | */ |
| 231 | bool isUpToDate(); |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | /** |
| 234 | * Get the known locales for this asset manager object. |
| 235 | */ |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 236 | void getLocales(Vector<String8>* locales, bool includeSystemLocales=true) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | |
Mårten Kongstad | 65a05fd | 2014-01-31 14:01:52 +0100 | [diff] [blame] | 238 | /** |
| 239 | * Generate idmap data to translate resources IDs between a package and a |
| 240 | * corresponding overlay package. |
| 241 | */ |
| 242 | bool createIdmap(const char* targetApkPath, const char* overlayApkPath, |
Dianne Hackborn | d9e385b | 2014-02-11 13:56:21 -0800 | [diff] [blame] | 243 | uint32_t targetCrc, uint32_t overlayCrc, uint32_t** outData, size_t* outSize); |
Mårten Kongstad | 65a05fd | 2014-01-31 14:01:52 +0100 | [diff] [blame] | 244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | private: |
| 246 | struct asset_path |
| 247 | { |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 248 | asset_path() : path(""), type(kFileTypeRegular), idmap(""), |
| 249 | isSystemOverlay(false), isSystemAsset(false) {} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | String8 path; |
| 251 | FileType type; |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 252 | String8 idmap; |
Mårten Kongstad | cb7b63d | 2014-11-07 10:57:15 +0100 | [diff] [blame] | 253 | bool isSystemOverlay; |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 254 | bool isSystemAsset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | Asset* openInPathLocked(const char* fileName, AccessMode mode, |
| 258 | const asset_path& path); |
| 259 | Asset* openNonAssetInPathLocked(const char* fileName, AccessMode mode, |
| 260 | const asset_path& path); |
| 261 | Asset* openInLocaleVendorLocked(const char* fileName, AccessMode mode, |
| 262 | const asset_path& path, const char* locale, const char* vendor); |
| 263 | String8 createPathNameLocked(const asset_path& path, const char* locale, |
| 264 | const char* vendor); |
| 265 | String8 createPathNameLocked(const asset_path& path, const char* rootDir); |
| 266 | String8 createZipSourceNameLocked(const String8& zipFileName, |
| 267 | const String8& dirName, const String8& fileName); |
| 268 | |
| 269 | ZipFileRO* getZipFileLocked(const asset_path& path); |
| 270 | Asset* openAssetFromFileLocked(const String8& fileName, AccessMode mode); |
| 271 | Asset* openAssetFromZipLocked(const ZipFileRO* pZipFile, |
| 272 | const ZipEntryRO entry, AccessMode mode, const String8& entryName); |
| 273 | |
| 274 | bool scanAndMergeDirLocked(SortedVector<AssetDir::FileInfo>* pMergedInfo, |
| 275 | const asset_path& path, const char* rootDir, const char* dirName); |
| 276 | SortedVector<AssetDir::FileInfo>* scanDirLocked(const String8& path); |
| 277 | bool scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMergedInfo, |
| 278 | const asset_path& path, const char* rootDir, const char* dirName); |
| 279 | void mergeInfoLocked(SortedVector<AssetDir::FileInfo>* pMergedInfo, |
| 280 | const SortedVector<AssetDir::FileInfo>* pContents); |
| 281 | |
| 282 | void loadFileNameCacheLocked(void); |
| 283 | void fncScanLocked(SortedVector<AssetDir::FileInfo>* pMergedInfo, |
| 284 | const char* dirName); |
| 285 | bool fncScanAndMergeDirLocked( |
| 286 | SortedVector<AssetDir::FileInfo>* pMergedInfo, |
| 287 | const asset_path& path, const char* locale, const char* vendor, |
| 288 | const char* dirName); |
| 289 | void purgeFileNameCacheLocked(void); |
| 290 | |
| 291 | const ResTable* getResTable(bool required = true) const; |
| 292 | void setLocaleLocked(const char* locale); |
| 293 | void updateResourceParamsLocked() const; |
Tao Bai | a6d7e3f | 2015-09-01 18:49:54 -0700 | [diff] [blame] | 294 | bool appendPathToResTable(const asset_path& ap, bool appAsLib=false) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 296 | Asset* openIdmapLocked(const struct asset_path& ap) const; |
| 297 | |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 298 | void addSystemOverlays(const char* pathOverlaysList, const String8& targetPackagePath, |
| 299 | ResTable* sharedRes, size_t offset) const; |
Mårten Kongstad | 57f4b77 | 2011-03-17 14:13:41 +0100 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | class SharedZip : public RefBase { |
| 302 | public: |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 303 | static sp<SharedZip> get(const String8& path, bool createIfNotPresent = true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
| 305 | ZipFileRO* getZip(); |
| 306 | |
| 307 | Asset* getResourceTableAsset(); |
| 308 | Asset* setResourceTableAsset(Asset* asset); |
| 309 | |
Dianne Hackborn | 78c4051 | 2009-07-06 11:07:40 -0700 | [diff] [blame] | 310 | ResTable* getResourceTable(); |
| 311 | ResTable* setResourceTable(ResTable* res); |
| 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | bool isUpToDate(); |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 314 | |
| 315 | void addOverlay(const asset_path& ap); |
| 316 | bool getOverlay(size_t idx, asset_path* out) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | |
| 318 | protected: |
| 319 | ~SharedZip(); |
| 320 | |
| 321 | private: |
| 322 | SharedZip(const String8& path, time_t modWhen); |
| 323 | SharedZip(); // <-- not implemented |
| 324 | |
| 325 | String8 mPath; |
| 326 | ZipFileRO* mZipFile; |
| 327 | time_t mModWhen; |
| 328 | |
| 329 | Asset* mResourceTableAsset; |
Dianne Hackborn | 78c4051 | 2009-07-06 11:07:40 -0700 | [diff] [blame] | 330 | ResTable* mResourceTable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 332 | Vector<asset_path> mOverlays; |
| 333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | static Mutex gLock; |
| 335 | static DefaultKeyedVector<String8, wp<SharedZip> > gOpen; |
| 336 | }; |
| 337 | |
| 338 | /* |
| 339 | * Manage a set of Zip files. For each file we need a pointer to the |
| 340 | * ZipFile and a time_t with the file's modification date. |
| 341 | * |
| 342 | * We currently only have two zip files (current app, "common" app). |
| 343 | * (This was originally written for 8, based on app/locale/vendor.) |
| 344 | */ |
| 345 | class ZipSet { |
| 346 | public: |
| 347 | ZipSet(void); |
| 348 | ~ZipSet(void); |
| 349 | |
| 350 | /* |
| 351 | * Return a ZipFileRO structure for a ZipFileRO with the specified |
| 352 | * parameters. |
| 353 | */ |
| 354 | ZipFileRO* getZip(const String8& path); |
| 355 | |
Dianne Hackborn | 78c4051 | 2009-07-06 11:07:40 -0700 | [diff] [blame] | 356 | Asset* getZipResourceTableAsset(const String8& path); |
| 357 | Asset* setZipResourceTableAsset(const String8& path, Asset* asset); |
| 358 | |
| 359 | ResTable* getZipResourceTable(const String8& path); |
| 360 | ResTable* setZipResourceTable(const String8& path, ResTable* res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | |
| 362 | // generate path, e.g. "common/en-US-noogle.zip" |
| 363 | static String8 getPathName(const char* path); |
| 364 | |
| 365 | bool isUpToDate(); |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 366 | |
| 367 | void addOverlay(const String8& path, const asset_path& overlay); |
| 368 | bool getOverlay(const String8& path, size_t idx, asset_path* out) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | |
| 370 | private: |
| 371 | void closeZip(int idx); |
| 372 | |
| 373 | int getIndex(const String8& zip) const; |
| 374 | mutable Vector<String8> mZipPath; |
| 375 | mutable Vector<sp<SharedZip> > mZipFile; |
| 376 | }; |
| 377 | |
| 378 | // Protect all internal state. |
| 379 | mutable Mutex mLock; |
| 380 | |
| 381 | ZipSet mZipSet; |
| 382 | |
| 383 | Vector<asset_path> mAssetPaths; |
| 384 | char* mLocale; |
| 385 | char* mVendor; |
| 386 | |
| 387 | mutable ResTable* mResources; |
| 388 | ResTable_config* mConfig; |
| 389 | |
| 390 | /* |
| 391 | * Cached data for "loose" files. This lets us avoid poking at the |
| 392 | * filesystem when searching for loose assets. Each entry is the |
| 393 | * "extended partial" path, e.g. "default/default/foo/bar.txt". The |
| 394 | * full set of files is present, including ".EXCLUDE" entries. |
| 395 | * |
| 396 | * We do not cache directory names. We don't retain the ".gz", |
| 397 | * because to our clients "foo" and "foo.gz" both look like "foo". |
| 398 | */ |
| 399 | CacheMode mCacheMode; // is the cache enabled? |
| 400 | bool mCacheValid; // clear when locale or vendor changes |
| 401 | SortedVector<AssetDir::FileInfo> mCache; |
| 402 | }; |
| 403 | |
| 404 | }; // namespace android |
| 405 | |
| 406 | #endif // __LIBS_ASSETMANAGER_H |