| 197 | } |
| 198 | |
| 199 | bool AssetManager::addAssetPath(const String8& path, void** cookie) |
| 200 | { |
| 201 | AutoMutex _l(mLock); |
| 202 | |
| 203 | asset_path ap; |
| 204 | |
| 205 | String8 realPath(path); |
| 206 | if (kAppZipName) { |
| 207 | realPath.appendPath(kAppZipName); |
| 208 | } |
| 209 | ap.type = ::getFileType(realPath.string()); |
| 210 | if (ap.type == kFileTypeRegular) { |
| 211 | ap.path = realPath; |
| 212 | } else { |
| 213 | ap.path = path; |
| 214 | ap.type = ::getFileType(path.string()); |
| 215 | if (ap.type != kFileTypeDirectory && ap.type != kFileTypeRegular) { |
| 216 | ALOGW("Asset path %s is neither a directory nor file (type=%d).", |
| 217 | path.string(), (int)ap.type); |
| 218 | return false; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // Skip if we have it already. |
| 223 | for (size_t i=0; i<mAssetPaths.size(); i++) { |
| 224 | if (mAssetPaths[i].path == ap.path) { |
| 225 | if (cookie) { |
| 226 | *cookie = (void*)(i+1); |
| 227 | } |
| 228 | return true; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | ALOGV("In %p Asset %s path: %s", this, |
| 233 | ap.type == kFileTypeDirectory ? "dir" : "zip", ap.path.string()); |
| 234 | |
| 235 | mAssetPaths.add(ap); |
| 236 | |
| 237 | // new paths are always added at the end |
| 238 | if (cookie) { |
| 239 | *cookie = (void*)mAssetPaths.size(); |
| 240 | } |
| 241 | |
| 242 | #ifdef HAVE_ANDROID_OS |
| 243 | // Load overlays, if any |
| 244 | asset_path oap; |
| 245 | for (size_t idx = 0; mZipSet.getOverlay(ap.path, idx, &oap); idx++) { |
| 246 | mAssetPaths.add(oap); |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | return true; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | /* |
no test coverage detected