Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 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 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 17 | #include "androidfw/ApkAssets.h" |
| 18 | |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 19 | #include <algorithm> |
| 20 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 21 | #include "android-base/errors.h" |
| 22 | #include "android-base/file.h" |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 23 | #include "android-base/logging.h" |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 24 | #include "android-base/unique_fd.h" |
| 25 | #include "android-base/utf8.h" |
| 26 | #include "utils/Compat.h" |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 27 | #include "utils/FileMap.h" |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 28 | #include "ziparchive/zip_archive.h" |
| 29 | |
| 30 | #include "androidfw/Asset.h" |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 31 | #include "androidfw/Idmap.h" |
Winson | b0085ce | 2019-02-19 12:48:22 -0800 | [diff] [blame] | 32 | #include "androidfw/misc.h" |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 33 | #include "androidfw/ResourceTypes.h" |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 34 | #include "androidfw/Util.h" |
| 35 | |
| 36 | namespace android { |
| 37 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 38 | using base::SystemErrorCodeToString; |
| 39 | using base::unique_fd; |
| 40 | |
| 41 | static const std::string kResourcesArsc("resources.arsc"); |
| 42 | |
Winson | b0085ce | 2019-02-19 12:48:22 -0800 | [diff] [blame] | 43 | ApkAssets::ApkAssets(ZipArchiveHandle unmanaged_handle, |
| 44 | const std::string& path, |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 45 | time_t last_mod_time, |
| 46 | bool for_loader) |
| 47 | : zip_handle_(unmanaged_handle, ::CloseArchive), path_(path), last_mod_time_(last_mod_time), |
| 48 | for_loader(for_loader) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 49 | } |
Adam Lesinski | 03ebac8 | 2017-09-25 13:10:14 -0700 | [diff] [blame] | 50 | |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 51 | std::unique_ptr<const ApkAssets> ApkAssets::Load(const std::string& path, bool system, |
| 52 | bool for_loader) { |
| 53 | return LoadImpl({} /*fd*/, path, nullptr, nullptr, system, false /*load_as_shared_library*/, |
| 54 | for_loader); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 55 | } |
| 56 | |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 57 | std::unique_ptr<const ApkAssets> ApkAssets::LoadAsSharedLibrary(const std::string& path, |
| 58 | bool system) { |
Adam Lesinski | 441500b | 2017-11-13 17:52:25 -0800 | [diff] [blame] | 59 | return LoadImpl({} /*fd*/, path, nullptr, nullptr, system, true /*load_as_shared_library*/); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 60 | } |
| 61 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 62 | std::unique_ptr<const ApkAssets> ApkAssets::LoadOverlay(const std::string& idmap_path, |
| 63 | bool system) { |
| 64 | std::unique_ptr<Asset> idmap_asset = CreateAssetFromFile(idmap_path); |
| 65 | if (idmap_asset == nullptr) { |
| 66 | return {}; |
| 67 | } |
| 68 | |
| 69 | const StringPiece idmap_data( |
| 70 | reinterpret_cast<const char*>(idmap_asset->getBuffer(true /*wordAligned*/)), |
| 71 | static_cast<size_t>(idmap_asset->getLength())); |
| 72 | std::unique_ptr<const LoadedIdmap> loaded_idmap = LoadedIdmap::Load(idmap_data); |
| 73 | if (loaded_idmap == nullptr) { |
| 74 | LOG(ERROR) << "failed to load IDMAP " << idmap_path; |
| 75 | return {}; |
| 76 | } |
Adam Lesinski | 441500b | 2017-11-13 17:52:25 -0800 | [diff] [blame] | 77 | return LoadImpl({} /*fd*/, loaded_idmap->OverlayApkPath(), std::move(idmap_asset), |
| 78 | std::move(loaded_idmap), system, false /*load_as_shared_library*/); |
| 79 | } |
| 80 | |
| 81 | std::unique_ptr<const ApkAssets> ApkAssets::LoadFromFd(unique_fd fd, |
| 82 | const std::string& friendly_name, |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 83 | bool system, bool force_shared_lib, |
| 84 | bool for_loader) { |
Adam Lesinski | 441500b | 2017-11-13 17:52:25 -0800 | [diff] [blame] | 85 | return LoadImpl(std::move(fd), friendly_name, nullptr /*idmap_asset*/, nullptr /*loaded_idmap*/, |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 86 | system, force_shared_lib, for_loader); |
| 87 | } |
| 88 | |
| 89 | std::unique_ptr<const ApkAssets> ApkAssets::LoadArsc(const std::string& path, |
| 90 | bool for_loader) { |
| 91 | return LoadArscImpl({} /*fd*/, path, for_loader); |
| 92 | } |
| 93 | |
| 94 | std::unique_ptr<const ApkAssets> ApkAssets::LoadArsc(unique_fd fd, |
| 95 | const std::string& friendly_name, |
| 96 | bool for_loader) { |
| 97 | return LoadArscImpl(std::move(fd), friendly_name, for_loader); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | std::unique_ptr<Asset> ApkAssets::CreateAssetFromFile(const std::string& path) { |
| 101 | unique_fd fd(base::utf8::open(path.c_str(), O_RDONLY | O_BINARY | O_CLOEXEC)); |
| 102 | if (fd == -1) { |
| 103 | LOG(ERROR) << "Failed to open file '" << path << "': " << SystemErrorCodeToString(errno); |
| 104 | return {}; |
| 105 | } |
| 106 | |
| 107 | const off64_t file_len = lseek64(fd, 0, SEEK_END); |
| 108 | if (file_len < 0) { |
| 109 | LOG(ERROR) << "Failed to get size of file '" << path << "': " << SystemErrorCodeToString(errno); |
| 110 | return {}; |
| 111 | } |
| 112 | |
| 113 | std::unique_ptr<FileMap> file_map = util::make_unique<FileMap>(); |
| 114 | if (!file_map->create(path.c_str(), fd, 0, static_cast<size_t>(file_len), true /*readOnly*/)) { |
| 115 | LOG(ERROR) << "Failed to mmap file '" << path << "': " << SystemErrorCodeToString(errno); |
| 116 | return {}; |
| 117 | } |
| 118 | return Asset::createFromUncompressedMap(std::move(file_map), Asset::AccessMode::ACCESS_RANDOM); |
| 119 | } |
| 120 | |
| 121 | std::unique_ptr<const ApkAssets> ApkAssets::LoadImpl( |
Adam Lesinski | 441500b | 2017-11-13 17:52:25 -0800 | [diff] [blame] | 122 | unique_fd fd, const std::string& path, std::unique_ptr<Asset> idmap_asset, |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 123 | std::unique_ptr<const LoadedIdmap> loaded_idmap, bool system, bool load_as_shared_library, |
| 124 | bool for_loader) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 125 | ::ZipArchiveHandle unmanaged_handle; |
Adam Lesinski | 441500b | 2017-11-13 17:52:25 -0800 | [diff] [blame] | 126 | int32_t result; |
| 127 | if (fd >= 0) { |
| 128 | result = |
| 129 | ::OpenArchiveFd(fd.release(), path.c_str(), &unmanaged_handle, true /*assume_ownership*/); |
| 130 | } else { |
| 131 | result = ::OpenArchive(path.c_str(), &unmanaged_handle); |
| 132 | } |
| 133 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 134 | if (result != 0) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 135 | LOG(ERROR) << "Failed to open APK '" << path << "' " << ::ErrorCodeString(result); |
Songchun Fan | 898b316 | 2019-07-08 09:00:34 -0700 | [diff] [blame] | 136 | ::CloseArchive(unmanaged_handle); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 137 | return {}; |
| 138 | } |
| 139 | |
Winson | b0085ce | 2019-02-19 12:48:22 -0800 | [diff] [blame] | 140 | time_t last_mod_time = getFileModDate(path.c_str()); |
| 141 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 142 | // Wrap the handle in a unique_ptr so it gets automatically closed. |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 143 | std::unique_ptr<ApkAssets> |
| 144 | loaded_apk(new ApkAssets(unmanaged_handle, path, last_mod_time, for_loader)); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 145 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 146 | // Find the resource table. |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 147 | ::ZipEntry entry; |
Elliott Hughes | b97e737 | 2019-05-03 22:42:31 -0700 | [diff] [blame] | 148 | result = ::FindEntry(loaded_apk->zip_handle_.get(), kResourcesArsc, &entry); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 149 | if (result != 0) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 150 | // There is no resources.arsc, so create an empty LoadedArsc and return. |
| 151 | loaded_apk->loaded_arsc_ = LoadedArsc::CreateEmpty(); |
| 152 | return std::move(loaded_apk); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | if (entry.method == kCompressDeflated) { |
Ryan Mitchell | 31b1105 | 2019-06-13 13:47:26 -0700 | [diff] [blame] | 156 | ANDROID_LOG(WARNING) << kResourcesArsc << " in APK '" << path << "' is compressed."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 159 | // Open the resource table via mmap unless it is compressed. This logic is taken care of by Open. |
| 160 | loaded_apk->resources_asset_ = loaded_apk->Open(kResourcesArsc, Asset::AccessMode::ACCESS_BUFFER); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 161 | if (loaded_apk->resources_asset_ == nullptr) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 162 | LOG(ERROR) << "Failed to open '" << kResourcesArsc << "' in APK '" << path << "'."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 163 | return {}; |
| 164 | } |
| 165 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 166 | // Must retain ownership of the IDMAP Asset so that all pointers to its mmapped data remain valid. |
| 167 | loaded_apk->idmap_asset_ = std::move(idmap_asset); |
| 168 | |
| 169 | const StringPiece data( |
| 170 | reinterpret_cast<const char*>(loaded_apk->resources_asset_->getBuffer(true /*wordAligned*/)), |
| 171 | loaded_apk->resources_asset_->getLength()); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 172 | loaded_apk->loaded_arsc_ = |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 173 | LoadedArsc::Load(data, loaded_idmap.get(), system, load_as_shared_library, for_loader); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 174 | if (loaded_apk->loaded_arsc_ == nullptr) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 175 | LOG(ERROR) << "Failed to load '" << kResourcesArsc << "' in APK '" << path << "'."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 176 | return {}; |
| 177 | } |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 178 | |
| 179 | // Need to force a move for mingw32. |
| 180 | return std::move(loaded_apk); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 183 | std::unique_ptr<const ApkAssets> ApkAssets::LoadArscImpl(unique_fd fd, |
| 184 | const std::string& path, |
| 185 | bool for_loader) { |
| 186 | std::unique_ptr<Asset> resources_asset; |
| 187 | |
| 188 | if (fd >= 0) { |
| 189 | resources_asset = std::unique_ptr<Asset>(Asset::createFromFd(fd.release(), nullptr, |
| 190 | Asset::AccessMode::ACCESS_BUFFER)); |
| 191 | } else { |
| 192 | resources_asset = CreateAssetFromFile(path); |
| 193 | } |
| 194 | |
| 195 | if (resources_asset == nullptr) { |
| 196 | LOG(ERROR) << "Failed to open ARSC '" << path; |
| 197 | return {}; |
| 198 | } |
| 199 | |
| 200 | time_t last_mod_time = getFileModDate(path.c_str()); |
| 201 | |
| 202 | std::unique_ptr<ApkAssets> loaded_apk(new ApkAssets(nullptr, path, last_mod_time, for_loader)); |
| 203 | loaded_apk->resources_asset_ = std::move(resources_asset); |
| 204 | |
| 205 | const StringPiece data( |
| 206 | reinterpret_cast<const char*>(loaded_apk->resources_asset_->getBuffer(true /*wordAligned*/)), |
| 207 | loaded_apk->resources_asset_->getLength()); |
| 208 | loaded_apk->loaded_arsc_ = LoadedArsc::Load(data, nullptr, false, false, for_loader); |
| 209 | if (loaded_apk->loaded_arsc_ == nullptr) { |
| 210 | LOG(ERROR) << "Failed to load '" << kResourcesArsc << path; |
| 211 | return {}; |
| 212 | } |
| 213 | |
| 214 | // Need to force a move for mingw32. |
| 215 | return std::move(loaded_apk); |
| 216 | } |
| 217 | |
| 218 | std::unique_ptr<const ApkAssets> ApkAssets::LoadEmpty(bool for_loader) { |
| 219 | std::unique_ptr<ApkAssets> loaded_apk(new ApkAssets(nullptr, "", -1, for_loader)); |
| 220 | loaded_apk->loaded_arsc_ = LoadedArsc::CreateEmpty(); |
| 221 | // Need to force a move for mingw32. |
| 222 | return std::move(loaded_apk); |
| 223 | } |
| 224 | |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 225 | std::unique_ptr<Asset> ApkAssets::Open(const std::string& path, Asset::AccessMode mode) const { |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 226 | // If this is a resource loader from an .arsc, there will be no zip handle |
| 227 | if (zip_handle_ == nullptr) { |
| 228 | return {}; |
| 229 | } |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 230 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 231 | ::ZipEntry entry; |
Elliott Hughes | b97e737 | 2019-05-03 22:42:31 -0700 | [diff] [blame] | 232 | int32_t result = ::FindEntry(zip_handle_.get(), path, &entry); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 233 | if (result != 0) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 234 | return {}; |
| 235 | } |
| 236 | |
| 237 | if (entry.method == kCompressDeflated) { |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 238 | std::unique_ptr<FileMap> map = util::make_unique<FileMap>(); |
| 239 | if (!map->create(path_.c_str(), ::GetFileDescriptor(zip_handle_.get()), entry.offset, |
| 240 | entry.compressed_length, true /*readOnly*/)) { |
| 241 | LOG(ERROR) << "Failed to mmap file '" << path << "' in APK '" << path_ << "'"; |
| 242 | return {}; |
| 243 | } |
| 244 | |
| 245 | std::unique_ptr<Asset> asset = |
| 246 | Asset::createFromCompressedMap(std::move(map), entry.uncompressed_length, mode); |
| 247 | if (asset == nullptr) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 248 | LOG(ERROR) << "Failed to decompress '" << path << "'."; |
| 249 | return {}; |
| 250 | } |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 251 | return asset; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 252 | } else { |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 253 | std::unique_ptr<FileMap> map = util::make_unique<FileMap>(); |
| 254 | if (!map->create(path_.c_str(), ::GetFileDescriptor(zip_handle_.get()), entry.offset, |
| 255 | entry.uncompressed_length, true /*readOnly*/)) { |
| 256 | LOG(ERROR) << "Failed to mmap file '" << path << "' in APK '" << path_ << "'"; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 257 | return {}; |
| 258 | } |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 259 | |
| 260 | std::unique_ptr<Asset> asset = Asset::createFromUncompressedMap(std::move(map), mode); |
| 261 | if (asset == nullptr) { |
| 262 | LOG(ERROR) << "Failed to mmap file '" << path << "' in APK '" << path_ << "'"; |
| 263 | return {}; |
| 264 | } |
| 265 | return asset; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 266 | } |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | bool ApkAssets::ForEachFile(const std::string& root_path, |
| 270 | const std::function<void(const StringPiece&, FileType)>& f) const { |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 271 | // If this is a resource loader from an .arsc, there will be no zip handle |
| 272 | if (zip_handle_ == nullptr) { |
| 273 | return false; |
| 274 | } |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 275 | |
| 276 | std::string root_path_full = root_path; |
| 277 | if (root_path_full.back() != '/') { |
| 278 | root_path_full += '/'; |
| 279 | } |
| 280 | |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 281 | void* cookie; |
Elliott Hughes | 7a6cc0c | 2019-05-08 12:12:39 -0700 | [diff] [blame] | 282 | if (::StartIteration(zip_handle_.get(), &cookie, root_path_full, "") != 0) { |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 283 | return false; |
| 284 | } |
| 285 | |
Elliott Hughes | 78de4f9 | 2019-06-14 15:28:38 -0700 | [diff] [blame] | 286 | std::string name; |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 287 | ::ZipEntry entry; |
| 288 | |
| 289 | // We need to hold back directories because many paths will contain them and we want to only |
| 290 | // surface one. |
| 291 | std::set<std::string> dirs; |
| 292 | |
| 293 | int32_t result; |
| 294 | while ((result = ::Next(cookie, &entry, &name)) == 0) { |
Elliott Hughes | 78de4f9 | 2019-06-14 15:28:38 -0700 | [diff] [blame] | 295 | StringPiece full_file_path(name); |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 296 | StringPiece leaf_file_path = full_file_path.substr(root_path_full.size()); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 297 | |
| 298 | if (!leaf_file_path.empty()) { |
| 299 | auto iter = std::find(leaf_file_path.begin(), leaf_file_path.end(), '/'); |
| 300 | if (iter != leaf_file_path.end()) { |
| 301 | std::string dir = |
| 302 | leaf_file_path.substr(0, std::distance(leaf_file_path.begin(), iter)).to_string(); |
| 303 | dirs.insert(std::move(dir)); |
| 304 | } else { |
| 305 | f(leaf_file_path, kFileTypeRegular); |
| 306 | } |
Adam Lesinski | d1ecd7a | 2017-01-23 12:58:11 -0800 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | ::EndIteration(cookie); |
| 310 | |
| 311 | // Now present the unique directories. |
| 312 | for (const std::string& dir : dirs) { |
| 313 | f(dir, kFileTypeDirectory); |
| 314 | } |
| 315 | |
| 316 | // -1 is end of iteration, anything else is an error. |
| 317 | return result == -1; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Winson | b0085ce | 2019-02-19 12:48:22 -0800 | [diff] [blame] | 320 | bool ApkAssets::IsUpToDate() const { |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame^] | 321 | // Loaders are invalidated by the app, not the system, so assume up to date |
| 322 | if (for_loader) { |
| 323 | return true; |
| 324 | } |
| 325 | |
Winson | b0085ce | 2019-02-19 12:48:22 -0800 | [diff] [blame] | 326 | return last_mod_time_ == getFileModDate(path_.c_str()); |
| 327 | } |
| 328 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 329 | } // namespace android |