Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #pragma once |
| 18 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 19 | #include <android/content/pm/BnDataLoaderStatusListener.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 20 | #include <android/content/pm/DataLoaderParamsParcel.h> |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 21 | #include <android/content/pm/FileSystemControlParcel.h> |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 22 | #include <android/content/pm/IDataLoaderStatusListener.h> |
Songchun Fan | 1b76ccf | 2021-02-24 22:25:59 +0000 | [diff] [blame] | 23 | #include <android/os/incremental/BnIncrementalService.h> |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 24 | #include <android/os/incremental/BnIncrementalServiceConnector.h> |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 25 | #include <android/os/incremental/BnStorageHealthListener.h> |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 26 | #include <android/os/incremental/BnStorageLoadingProgressListener.h> |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 27 | #include <android/os/incremental/PerUidReadTimeouts.h> |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 28 | #include <android/os/incremental/StorageHealthCheckParams.h> |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 29 | #include <binder/IAppOpsCallback.h> |
Songchun Fan | 1b76ccf | 2021-02-24 22:25:59 +0000 | [diff] [blame] | 30 | #include <binder/PersistableBundle.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 31 | #include <utils/String16.h> |
| 32 | #include <utils/StrongPointer.h> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 33 | #include <ziparchive/zip_archive.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 34 | |
| 35 | #include <atomic> |
| 36 | #include <chrono> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 37 | #include <condition_variable> |
| 38 | #include <functional> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 39 | #include <limits> |
| 40 | #include <map> |
| 41 | #include <mutex> |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 42 | #include <set> |
Songchun Fan | 9b75308 | 2020-02-26 13:08:06 -0800 | [diff] [blame] | 43 | #include <span> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 44 | #include <string> |
| 45 | #include <string_view> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 46 | #include <thread> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 47 | #include <unordered_map> |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 48 | #include <unordered_set> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 49 | #include <utility> |
| 50 | #include <vector> |
| 51 | |
| 52 | #include "ServiceWrappers.h" |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 53 | #include "incfs.h" |
| 54 | #include "path.h" |
| 55 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 56 | namespace android::incremental { |
| 57 | |
| 58 | using MountId = int; |
| 59 | using StorageId = int; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 60 | using FileId = incfs::FileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 61 | using BlockIndex = incfs::BlockIndex; |
| 62 | using RawMetadata = incfs::RawMetadata; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 63 | using Seconds = std::chrono::seconds; |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 64 | using BootClockTsUs = uint64_t; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 65 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 66 | using IDataLoaderStatusListener = ::android::content::pm::IDataLoaderStatusListener; |
| 67 | using DataLoaderStatusListener = ::android::sp<IDataLoaderStatusListener>; |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 68 | |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 69 | using StorageHealthCheckParams = ::android::os::incremental::StorageHealthCheckParams; |
| 70 | using IStorageHealthListener = ::android::os::incremental::IStorageHealthListener; |
| 71 | using StorageHealthListener = ::android::sp<IStorageHealthListener>; |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 72 | using IStorageLoadingProgressListener = ::android::os::incremental::IStorageLoadingProgressListener; |
| 73 | using StorageLoadingProgressListener = ::android::sp<IStorageLoadingProgressListener>; |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 74 | |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 75 | using PerUidReadTimeouts = ::android::os::incremental::PerUidReadTimeouts; |
| 76 | |
Alex Buynytskyy | cb163f9 | 2021-03-18 21:21:27 -0700 | [diff] [blame] | 77 | struct IfsState { |
| 78 | // If mount is fully loaded. |
| 79 | bool fullyLoaded = false; |
| 80 | // If read logs are enabled on this mount. Populated only if fullyLoaded == true. |
| 81 | bool readLogsEnabled = false; |
| 82 | // If there was an error fetching any of the above. |
| 83 | bool error = false; |
| 84 | }; |
| 85 | // Returns true if wants to be called again. |
| 86 | using IfsStateCallback = std::function<bool(StorageId, IfsState)>; |
| 87 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 88 | class IncrementalService final { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 89 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 90 | explicit IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 91 | |
| 92 | #pragma GCC diagnostic push |
| 93 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 94 | ~IncrementalService(); |
| 95 | #pragma GCC diagnostic pop |
| 96 | |
| 97 | static constexpr StorageId kInvalidStorageId = -1; |
Yurii Zubrytskyi | 9acc9ac | 2021-03-24 00:48:24 -0700 | [diff] [blame] | 98 | static constexpr StorageId kMaxStorageId = std::numeric_limits<int>::max() - 1; |
| 99 | static constexpr StorageId kAllStoragesId = kMaxStorageId + 1; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 100 | |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 101 | static constexpr BootClockTsUs kMaxBootClockTsUs = std::numeric_limits<BootClockTsUs>::max(); |
| 102 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 103 | enum CreateOptions { |
| 104 | TemporaryBind = 1, |
| 105 | PermanentBind = 2, |
| 106 | CreateNew = 4, |
| 107 | OpenExisting = 8, |
| 108 | |
| 109 | Default = TemporaryBind | CreateNew |
| 110 | }; |
| 111 | |
| 112 | enum class BindKind { |
| 113 | Temporary = 0, |
| 114 | Permanent = 1, |
| 115 | }; |
| 116 | |
Alex Buynytskyy | 3697d9e | 2020-06-06 20:15:58 -0700 | [diff] [blame] | 117 | enum StorageFlags { |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 118 | ReadLogsAllowed = 1 << 0, |
| 119 | ReadLogsEnabled = 1 << 1, |
Alex Buynytskyy | 50d83ff | 2021-03-23 22:37:02 -0700 | [diff] [blame] | 120 | ReadLogsRequested = 1 << 2, |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 121 | |
| 122 | ReadTimeoutsEnabled = 1 << 3, |
| 123 | ReadTimeoutsRequested = 1 << 4, |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct LoadingProgress { |
| 127 | ssize_t filledBlocks; |
| 128 | ssize_t totalBlocks; |
| 129 | |
| 130 | bool isError() const { return totalBlocks < 0; } |
| 131 | bool started() const { return totalBlocks > 0; } |
| 132 | bool fullyLoaded() const { return !isError() && (totalBlocks == filledBlocks); } |
| 133 | |
Alex Buynytskyy | 07694ed | 2021-01-27 06:58:55 -0800 | [diff] [blame] | 134 | int blocksRemainingOrError() const { |
| 135 | return totalBlocks <= 0 ? totalBlocks : totalBlocks - filledBlocks; |
| 136 | } |
| 137 | |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 138 | float getProgress() const { |
| 139 | return totalBlocks < 0 |
| 140 | ? totalBlocks |
| 141 | : totalBlocks > 0 ? double(filledBlocks) / double(totalBlocks) : 1.f; |
| 142 | } |
Alex Buynytskyy | 3697d9e | 2020-06-06 20:15:58 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 145 | static FileId idFromMetadata(std::span<const uint8_t> metadata); |
| 146 | static inline FileId idFromMetadata(std::span<const char> metadata) { |
| 147 | return idFromMetadata({(const uint8_t*)metadata.data(), metadata.size()}); |
| 148 | } |
| 149 | |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 150 | void onDump(int fd); |
| 151 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 152 | void onSystemReady(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 153 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 154 | StorageId createStorage(std::string_view mountPoint, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 155 | content::pm::DataLoaderParamsParcel dataLoaderParams, |
Alex Buynytskyy | 07694ed | 2021-01-27 06:58:55 -0800 | [diff] [blame] | 156 | CreateOptions options); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 157 | StorageId createLinkedStorage(std::string_view mountPoint, StorageId linkedStorage, |
| 158 | CreateOptions options = CreateOptions::Default); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 159 | StorageId openStorage(std::string_view path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 160 | |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 161 | bool startLoading(StorageId storage, content::pm::DataLoaderParamsParcel dataLoaderParams, |
| 162 | DataLoaderStatusListener statusListener, |
| 163 | const StorageHealthCheckParams& healthCheckParams, |
| 164 | StorageHealthListener healthListener, |
| 165 | std::vector<PerUidReadTimeouts> perUidReadTimeouts); |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 166 | void onInstallationComplete(StorageId storage); |
Alex Buynytskyy | 07694ed | 2021-01-27 06:58:55 -0800 | [diff] [blame] | 167 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 168 | int bind(StorageId storage, std::string_view source, std::string_view target, BindKind kind); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 169 | int unbind(StorageId storage, std::string_view target); |
| 170 | void deleteStorage(StorageId storage); |
| 171 | |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 172 | void disallowReadLogs(StorageId storage); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 173 | int setStorageParams(StorageId storage, bool enableReadLogs); |
| 174 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 175 | int makeFile(StorageId storage, std::string_view path, int mode, FileId id, |
Alex Buynytskyy | b39d13e | 2020-09-12 16:12:36 -0700 | [diff] [blame] | 176 | incfs::NewFileParams params, std::span<const uint8_t> data); |
Songchun Fan | 9610093 | 2020-02-03 19:20:58 -0800 | [diff] [blame] | 177 | int makeDir(StorageId storage, std::string_view path, int mode = 0755); |
| 178 | int makeDirs(StorageId storage, std::string_view path, int mode = 0755); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 179 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 180 | int link(StorageId sourceStorageId, std::string_view oldPath, StorageId destStorageId, |
| 181 | std::string_view newPath); |
| 182 | int unlink(StorageId storage, std::string_view path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 183 | |
Yurii Zubrytskyi | 256a1a4 | 2021-03-18 14:21:54 -0700 | [diff] [blame] | 184 | incfs::LoadingState isFileFullyLoaded(StorageId storage, std::string_view filePath) const; |
| 185 | incfs::LoadingState isMountFullyLoaded(StorageId storage) const; |
Alex Buynytskyy | 07694ed | 2021-01-27 06:58:55 -0800 | [diff] [blame] | 186 | |
Yurii Zubrytskyi | 883a27a | 2021-03-18 19:30:56 -0700 | [diff] [blame] | 187 | LoadingProgress getLoadingProgress(StorageId storage) const; |
Alex Buynytskyy | 07694ed | 2021-01-27 06:58:55 -0800 | [diff] [blame] | 188 | |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 189 | bool registerLoadingProgressListener(StorageId storage, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 190 | StorageLoadingProgressListener progressListener); |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 191 | bool unregisterLoadingProgressListener(StorageId storage); |
Songchun Fan | 5ada150 | 2021-04-14 19:04:11 +0000 | [diff] [blame] | 192 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 193 | RawMetadata getMetadata(StorageId storage, std::string_view path) const; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 194 | RawMetadata getMetadata(StorageId storage, FileId node) const; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 195 | |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 196 | bool configureNativeBinaries(StorageId storage, std::string_view apkFullPath, |
Songchun Fan | 14f6c3c | 2020-05-21 18:19:07 -0700 | [diff] [blame] | 197 | std::string_view libDirRelativePath, std::string_view abi, |
| 198 | bool extractNativeLibs); |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 199 | bool waitForNativeBinariesExtraction(StorageId storage); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 200 | |
Songchun Fan | 1b76ccf | 2021-02-24 22:25:59 +0000 | [diff] [blame] | 201 | void getMetrics(int32_t storageId, android::os::PersistableBundle* _aidl_return); |
| 202 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 203 | class AppOpsListener : public android::BnAppOpsCallback { |
| 204 | public: |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 205 | AppOpsListener(IncrementalService& incrementalService, std::string packageName) |
| 206 | : incrementalService(incrementalService), packageName(std::move(packageName)) {} |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 207 | void opChanged(int32_t op, const String16& packageName) final; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 208 | |
| 209 | private: |
| 210 | IncrementalService& incrementalService; |
| 211 | const std::string packageName; |
| 212 | }; |
| 213 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 214 | class IncrementalServiceConnector : public os::incremental::BnIncrementalServiceConnector { |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 215 | public: |
| 216 | IncrementalServiceConnector(IncrementalService& incrementalService, int32_t storage) |
Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 217 | : incrementalService(incrementalService), storage(storage) {} |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 218 | binder::Status setStorageParams(bool enableReadLogs, int32_t* _aidl_return) final; |
| 219 | |
| 220 | private: |
| 221 | IncrementalService& incrementalService; |
Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 222 | int32_t const storage; |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 225 | private: |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 226 | struct IncFsMount; |
| 227 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 228 | class DataLoaderStub : public content::pm::BnDataLoaderStatusListener { |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 229 | public: |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 230 | DataLoaderStub(IncrementalService& service, MountId id, |
| 231 | content::pm::DataLoaderParamsParcel&& params, |
| 232 | content::pm::FileSystemControlParcel&& control, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 233 | DataLoaderStatusListener&& statusListener, |
| 234 | const StorageHealthCheckParams& healthCheckParams, |
| 235 | StorageHealthListener&& healthListener, std::string&& healthPath); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 236 | ~DataLoaderStub(); |
Alex Buynytskyy | 9a54579 | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 237 | // Cleans up the internal state and invalidates DataLoaderStub. Any subsequent calls will |
| 238 | // result in an error. |
| 239 | void cleanupResources(); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 240 | |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 241 | bool requestCreate(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 242 | bool requestStart(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 243 | bool requestDestroy(); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 244 | |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 245 | void onDump(int fd); |
| 246 | |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 247 | MountId id() const { return mId.load(std::memory_order_relaxed); } |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 248 | const content::pm::DataLoaderParamsParcel& params() const { return mParams; } |
Alex Buynytskyy | d7aa346 | 2021-03-14 22:20:20 -0700 | [diff] [blame] | 249 | bool isSystemDataLoader() const; |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 250 | void setHealthListener(const StorageHealthCheckParams& healthCheckParams, |
| 251 | StorageHealthListener&& healthListener); |
Songchun Fan | 9471be5 | 2021-04-21 17:49:27 -0700 | [diff] [blame] | 252 | void getMetrics(android::os::PersistableBundle* _aidl_return); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 253 | |
| 254 | private: |
| 255 | binder::Status onStatusChanged(MountId mount, int newStatus) final; |
| 256 | |
Alex Buynytskyy | 060c9d6 | 2021-02-18 20:55:17 -0800 | [diff] [blame] | 257 | void setCurrentStatus(int newStatus); |
Alex Buynytskyy | 4bafd4d | 2021-06-08 16:35:39 -0700 | [diff] [blame] | 258 | void compareAndSetCurrentStatus(int expectedStatus, int newStatus); |
Alex Buynytskyy | 060c9d6 | 2021-02-18 20:55:17 -0800 | [diff] [blame] | 259 | |
Alex Buynytskyy | 0bdbccf | 2020-04-23 20:36:42 -0700 | [diff] [blame] | 260 | sp<content::pm::IDataLoader> getDataLoader(); |
Alex Buynytskyy | 9a54579 | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 261 | |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 262 | bool bind(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 263 | bool create(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 264 | bool start(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 265 | bool destroy(); |
| 266 | |
| 267 | bool setTargetStatus(int status); |
Alex Buynytskyy | 7e0a1a8 | 2020-04-27 17:06:10 -0700 | [diff] [blame] | 268 | void setTargetStatusLocked(int status); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 269 | |
| 270 | bool fsmStep(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 271 | |
Yurii Zubrytskyi | 883a27a | 2021-03-18 19:30:56 -0700 | [diff] [blame] | 272 | void onHealthStatus(const StorageHealthListener& healthListener, int healthStatus); |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 273 | void updateHealthStatus(bool baseline = false); |
| 274 | |
| 275 | bool isValid() const { return id() != kInvalidStorageId; } |
| 276 | |
| 277 | bool isHealthParamsValid() const; |
| 278 | |
| 279 | const incfs::UniqueControl& initializeHealthControl(); |
| 280 | void resetHealthControl(); |
| 281 | |
| 282 | BootClockTsUs getOldestPendingReadTs(); |
Songchun Fan | 1b76ccf | 2021-02-24 22:25:59 +0000 | [diff] [blame] | 283 | BootClockTsUs getOldestTsFromLastPendingReads(); |
| 284 | Milliseconds elapsedMsSinceKernelTs(TimePoint now, BootClockTsUs kernelTsUs); |
Songchun Fan | 9471be5 | 2021-04-21 17:49:27 -0700 | [diff] [blame] | 285 | long elapsedMsSinceOldestPendingRead(); |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 286 | |
Alex Buynytskyy | 7e06d71 | 2021-03-09 19:24:23 -0800 | [diff] [blame] | 287 | // If the stub has to bind to the DL. |
| 288 | // Returns {} if bind operation is already in progress. |
| 289 | // Or bind delay in ms. |
| 290 | std::optional<Milliseconds> needToBind(); |
Alex Buynytskyy | b19ee3e | 2021-02-06 20:31:43 -0800 | [diff] [blame] | 291 | |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 292 | void registerForPendingReads(); |
| 293 | void unregisterFromPendingReads(); |
Alex Buynytskyy | d0855a3 | 2020-05-07 18:40:51 -0700 | [diff] [blame] | 294 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 295 | IncrementalService& mService; |
Alex Buynytskyy | b0ea448 | 2020-05-04 18:39:58 -0700 | [diff] [blame] | 296 | |
| 297 | std::mutex mMutex; |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 298 | std::atomic<MountId> mId = kInvalidStorageId; |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 299 | content::pm::DataLoaderParamsParcel mParams; |
| 300 | content::pm::FileSystemControlParcel mControl; |
Alex Buynytskyy | 8ef61ae | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 301 | DataLoaderStatusListener mStatusListener; |
| 302 | StorageHealthListener mHealthListener; |
Songchun Fan | 9471be5 | 2021-04-21 17:49:27 -0700 | [diff] [blame] | 303 | std::atomic<int> mHealthStatus = IStorageHealthListener::HEALTH_STATUS_OK; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 304 | |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 305 | std::condition_variable mStatusCondition; |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 306 | int mCurrentStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED; |
Alex Buynytskyy | 7e06d71 | 2021-03-09 19:24:23 -0800 | [diff] [blame] | 307 | TimePoint mCurrentStatusTs = {}; |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 308 | int mTargetStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED; |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 309 | TimePoint mTargetStatusTs = {}; |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 310 | |
Alex Buynytskyy | b19ee3e | 2021-02-06 20:31:43 -0800 | [diff] [blame] | 311 | TimePoint mPreviousBindTs = {}; |
| 312 | Milliseconds mPreviousBindDelay = {}; |
| 313 | |
Alex Buynytskyy | d0855a3 | 2020-05-07 18:40:51 -0700 | [diff] [blame] | 314 | std::string mHealthPath; |
| 315 | incfs::UniqueControl mHealthControl; |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 316 | struct { |
| 317 | TimePoint userTs; |
| 318 | BootClockTsUs kernelTsUs; |
| 319 | } mHealthBase = {TimePoint::max(), kMaxBootClockTsUs}; |
| 320 | StorageHealthCheckParams mHealthCheckParams; |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 321 | std::vector<incfs::ReadInfoWithUid> mLastPendingReads; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 322 | }; |
| 323 | using DataLoaderStubPtr = sp<DataLoaderStub>; |
| 324 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 325 | struct IncFsMount { |
| 326 | struct Bind { |
| 327 | StorageId storage; |
| 328 | std::string savedFilename; |
| 329 | std::string sourceDir; |
| 330 | BindKind kind; |
| 331 | }; |
| 332 | |
| 333 | struct Storage { |
| 334 | std::string name; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 335 | }; |
| 336 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 337 | using Control = incfs::UniqueControl; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 338 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 339 | using BindMap = std::map<std::string, Bind, path::PathLess>; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 340 | using StorageMap = std::unordered_map<StorageId, Storage>; |
| 341 | |
| 342 | mutable std::mutex lock; |
| 343 | const std::string root; |
Alex Buynytskyy | e76e1ef | 2021-05-07 14:50:02 -0700 | [diff] [blame] | 344 | const std::string metricsKey; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 345 | Control control; |
| 346 | /*const*/ MountId mountId; |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 347 | int32_t flags = StorageFlags::ReadLogsAllowed; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 348 | StorageMap storages; |
| 349 | BindMap bindPoints; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 350 | DataLoaderStubPtr dataLoaderStub; |
Alex Buynytskyy | d7aa346 | 2021-03-14 22:20:20 -0700 | [diff] [blame] | 351 | TimePoint startLoadingTs = {}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 352 | std::atomic<int> nextStorageDirNo{0}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 353 | const IncrementalService& incrementalService; |
| 354 | |
Alex Buynytskyy | e76e1ef | 2021-05-07 14:50:02 -0700 | [diff] [blame] | 355 | IncFsMount(std::string root, std::string metricsKey, MountId mountId, Control control, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 356 | const IncrementalService& incrementalService) |
| 357 | : root(std::move(root)), |
Alex Buynytskyy | e76e1ef | 2021-05-07 14:50:02 -0700 | [diff] [blame] | 358 | metricsKey(std::move(metricsKey)), |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 359 | control(std::move(control)), |
| 360 | mountId(mountId), |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 361 | incrementalService(incrementalService) {} |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 362 | IncFsMount(IncFsMount&&) = delete; |
| 363 | IncFsMount& operator=(IncFsMount&&) = delete; |
| 364 | ~IncFsMount(); |
| 365 | |
| 366 | StorageMap::iterator makeStorage(StorageId id); |
| 367 | |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 368 | void disallowReadLogs() { flags &= ~StorageFlags::ReadLogsAllowed; } |
| 369 | int32_t readLogsAllowed() const { return (flags & StorageFlags::ReadLogsAllowed); } |
| 370 | |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 371 | void setReadLogsEnabled(bool value) { |
| 372 | return setFlag(StorageFlags::ReadLogsEnabled, value); |
| 373 | } |
Alex Buynytskyy | 3697d9e | 2020-06-06 20:15:58 -0700 | [diff] [blame] | 374 | int32_t readLogsEnabled() const { return (flags & StorageFlags::ReadLogsEnabled); } |
| 375 | |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 376 | void setReadLogsRequested(bool value) { |
| 377 | return setFlag(StorageFlags::ReadLogsRequested, value); |
| 378 | } |
Alex Buynytskyy | 50d83ff | 2021-03-23 22:37:02 -0700 | [diff] [blame] | 379 | int32_t readLogsRequested() const { return (flags & StorageFlags::ReadLogsRequested); } |
| 380 | |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 381 | void setReadTimeoutsEnabled(bool value) { |
| 382 | return setFlag(StorageFlags::ReadTimeoutsEnabled, value); |
| 383 | } |
| 384 | int32_t readTimeoutsEnabled() const { return (flags & StorageFlags::ReadTimeoutsEnabled); } |
| 385 | |
| 386 | void setReadTimeoutsRequested(bool value) { |
| 387 | return setFlag(StorageFlags::ReadTimeoutsRequested, value); |
| 388 | } |
| 389 | int32_t readTimeoutsRequested() const { |
| 390 | return (flags & StorageFlags::ReadTimeoutsRequested); |
| 391 | } |
| 392 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 393 | static void cleanupFilesystem(std::string_view root); |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 394 | |
| 395 | private: |
| 396 | void setFlag(StorageFlags flag, bool value); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | using IfsMountPtr = std::shared_ptr<IncFsMount>; |
| 400 | using MountMap = std::unordered_map<MountId, IfsMountPtr>; |
| 401 | using BindPathMap = std::map<std::string, IncFsMount::BindMap::iterator, path::PathLess>; |
| 402 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 403 | static bool perfLoggingEnabled(); |
| 404 | |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 405 | void setUidReadTimeouts(StorageId storage, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 406 | std::vector<PerUidReadTimeouts>&& perUidReadTimeouts); |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 407 | void clearUidReadTimeouts(StorageId storage); |
Alex Buynytskyy | cb163f9 | 2021-03-18 21:21:27 -0700 | [diff] [blame] | 408 | bool checkUidReadTimeouts(StorageId storage, IfsState state, Clock::time_point timeLimit); |
Alex Buynytskyy | aa8e95e | 2020-12-14 21:50:04 -0800 | [diff] [blame] | 409 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 410 | std::unordered_set<std::string_view> adoptMountedInstances(); |
| 411 | void mountExistingImages(const std::unordered_set<std::string_view>& mountedRootNames); |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 412 | bool mountExistingImage(std::string_view root); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 413 | |
| 414 | IfsMountPtr getIfs(StorageId storage) const; |
| 415 | const IfsMountPtr& getIfsLocked(StorageId storage) const; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 416 | int addBindMount(IncFsMount& ifs, StorageId storage, std::string_view storageRoot, |
| 417 | std::string&& source, std::string&& target, BindKind kind, |
| 418 | std::unique_lock<std::mutex>& mainLock); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 419 | |
| 420 | int addBindMountWithMd(IncFsMount& ifs, StorageId storage, std::string&& metadataName, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 421 | std::string&& source, std::string&& target, BindKind kind, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 422 | std::unique_lock<std::mutex>& mainLock); |
| 423 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 424 | void addBindMountRecordLocked(IncFsMount& ifs, StorageId storage, std::string&& metadataName, |
| 425 | std::string&& source, std::string&& target, BindKind kind); |
| 426 | |
Alex Buynytskyy | b19ee3e | 2021-02-06 20:31:43 -0800 | [diff] [blame] | 427 | bool needStartDataLoaderLocked(IncFsMount& ifs); |
| 428 | |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 429 | void prepareDataLoaderLocked(IncFsMount& ifs, content::pm::DataLoaderParamsParcel&& params, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 430 | DataLoaderStatusListener&& statusListener = {}, |
| 431 | const StorageHealthCheckParams& healthCheckParams = {}, |
| 432 | StorageHealthListener&& healthListener = {}); |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 433 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 434 | BindPathMap::const_iterator findStorageLocked(std::string_view path) const; |
| 435 | StorageId findStorageId(std::string_view path) const; |
| 436 | |
| 437 | void deleteStorage(IncFsMount& ifs); |
| 438 | void deleteStorageLocked(IncFsMount& ifs, std::unique_lock<std::mutex>&& ifsLock); |
| 439 | MountMap::iterator getStorageSlotLocked(); |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 440 | std::string normalizePathToStorage(const IncFsMount& incfs, StorageId storage, |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 441 | std::string_view path) const; |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 442 | std::string normalizePathToStorageLocked(const IncFsMount& incfs, |
| 443 | IncFsMount::StorageMap::const_iterator storageIt, |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 444 | std::string_view path) const; |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 445 | int makeDirs(const IncFsMount& ifs, StorageId storageId, std::string_view path, int mode); |
Alex Buynytskyy | d7aa346 | 2021-03-14 22:20:20 -0700 | [diff] [blame] | 446 | |
Alex Buynytskyy | cb163f9 | 2021-03-18 21:21:27 -0700 | [diff] [blame] | 447 | int disableReadLogsLocked(IncFsMount& ifs); |
Alex Buynytskyy | c144cc4 | 2021-03-31 22:19:42 -0700 | [diff] [blame] | 448 | int applyStorageParamsLocked(IncFsMount& ifs); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 449 | |
Yurii Zubrytskyi | 883a27a | 2021-03-18 19:30:56 -0700 | [diff] [blame] | 450 | LoadingProgress getLoadingProgressFromPath(const IncFsMount& ifs, std::string_view path) const; |
Songchun Fan | 374f765 | 2020-08-20 08:40:29 -0700 | [diff] [blame] | 451 | |
Alex Buynytskyy | b39d13e | 2020-09-12 16:12:36 -0700 | [diff] [blame] | 452 | int setFileContent(const IfsMountPtr& ifs, const incfs::FileId& fileId, |
| 453 | std::string_view debugFilePath, std::span<const uint8_t> data) const; |
| 454 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 455 | void registerAppOpsCallback(const std::string& packageName); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 456 | bool unregisterAppOpsCallback(const std::string& packageName); |
| 457 | void onAppOpChanged(const std::string& packageName); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 458 | |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 459 | void runJobProcessing(); |
| 460 | void extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle zipFile, ZipEntry& entry, |
Alex Buynytskyy | b39d13e | 2020-09-12 16:12:36 -0700 | [diff] [blame] | 461 | const incfs::FileId& libFileId, std::string_view debugLibPath, |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 462 | Clock::time_point scheduledTs); |
| 463 | |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 464 | void runCmdLooper(); |
| 465 | |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 466 | bool addTimedJob(TimedQueueWrapper& timedQueue, MountId id, Milliseconds after, Job what); |
| 467 | bool removeTimedJobs(TimedQueueWrapper& timedQueue, MountId id); |
Alex Buynytskyy | cb163f9 | 2021-03-18 21:21:27 -0700 | [diff] [blame] | 468 | |
| 469 | void addIfsStateCallback(StorageId storageId, IfsStateCallback callback); |
| 470 | void removeIfsStateCallbacks(StorageId storageId); |
| 471 | void processIfsStateCallbacks(); |
| 472 | void processIfsStateCallbacks(StorageId storageId, std::vector<IfsStateCallback>& callbacks); |
| 473 | |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 474 | bool updateLoadingProgress(int32_t storageId, |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 475 | StorageLoadingProgressListener&& progressListener); |
Alex Buynytskyy | 4760d8f | 2020-05-08 16:18:52 -0700 | [diff] [blame] | 476 | |
Yurii Zubrytskyi | 4cd2492 | 2021-03-24 00:46:29 -0700 | [diff] [blame] | 477 | void trimReservedSpaceV1(const IncFsMount& ifs); |
Songchun Fan | 0dc7772 | 2021-05-03 17:13:52 -0700 | [diff] [blame] | 478 | int64_t elapsedUsSinceMonoTs(uint64_t monoTsUs); |
Yurii Zubrytskyi | 4cd2492 | 2021-03-24 00:46:29 -0700 | [diff] [blame] | 479 | |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 480 | private: |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 481 | const std::unique_ptr<VoldServiceWrapper> mVold; |
| 482 | const std::unique_ptr<DataLoaderManagerWrapper> mDataLoaderManager; |
| 483 | const std::unique_ptr<IncFsWrapper> mIncFs; |
| 484 | const std::unique_ptr<AppOpsManagerWrapper> mAppOpsManager; |
| 485 | const std::unique_ptr<JniWrapper> mJni; |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 486 | const std::unique_ptr<LooperWrapper> mLooper; |
Alex Buynytskyy | 46d3ddb | 2020-05-29 12:05:05 -0700 | [diff] [blame] | 487 | const std::unique_ptr<TimedQueueWrapper> mTimedQueue; |
Songchun Fan | a709859 | 2020-09-03 11:45:53 -0700 | [diff] [blame] | 488 | const std::unique_ptr<TimedQueueWrapper> mProgressUpdateJobQueue; |
Songchun Fan | 374f765 | 2020-08-20 08:40:29 -0700 | [diff] [blame] | 489 | const std::unique_ptr<FsWrapper> mFs; |
Alex Buynytskyy | 7e06d71 | 2021-03-09 19:24:23 -0800 | [diff] [blame] | 490 | const std::unique_ptr<ClockWrapper> mClock; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 491 | const std::string mIncrementalDir; |
| 492 | |
| 493 | mutable std::mutex mLock; |
| 494 | mutable std::mutex mMountOperationLock; |
| 495 | MountMap mMounts; |
| 496 | BindPathMap mBindsByPath; |
| 497 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 498 | std::mutex mCallbacksLock; |
Yurii Zubrytskyi | f4769e2 | 2021-03-18 20:37:45 -0700 | [diff] [blame] | 499 | std::unordered_map<std::string, sp<AppOpsListener>> mCallbackRegistered; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 500 | |
Yurii Zubrytskyi | 9acc9ac | 2021-03-24 00:48:24 -0700 | [diff] [blame] | 501 | using IfsStateCallbacks = std::map<StorageId, std::vector<IfsStateCallback>>; |
Alex Buynytskyy | cb163f9 | 2021-03-18 21:21:27 -0700 | [diff] [blame] | 502 | std::mutex mIfsStateCallbacksLock; |
| 503 | IfsStateCallbacks mIfsStateCallbacks; |
| 504 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 505 | std::atomic_bool mSystemReady = false; |
| 506 | StorageId mNextId = 0; |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 507 | |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 508 | std::atomic_bool mRunning{true}; |
| 509 | |
Yurii Zubrytskyi | 721ac4d | 2020-04-13 11:34:32 -0700 | [diff] [blame] | 510 | std::unordered_map<MountId, std::vector<Job>> mJobQueue; |
| 511 | MountId mPendingJobsMount = kInvalidStorageId; |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 512 | std::condition_variable mJobCondition; |
| 513 | std::mutex mJobMutex; |
| 514 | std::thread mJobProcessor; |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 515 | |
| 516 | std::thread mCmdLooperThread; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | } // namespace android::incremental |