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 | |
| 19 | #include <android-base/strings.h> |
| 20 | #include <android-base/unique_fd.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 21 | #include <android/content/pm/DataLoaderParamsParcel.h> |
| 22 | #include <binder/IServiceManager.h> |
| 23 | #include <utils/String16.h> |
| 24 | #include <utils/StrongPointer.h> |
| 25 | #include <utils/Vector.h> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 26 | #include <ziparchive/zip_archive.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 27 | |
| 28 | #include <atomic> |
| 29 | #include <chrono> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 30 | #include <condition_variable> |
| 31 | #include <functional> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 32 | #include <limits> |
| 33 | #include <map> |
| 34 | #include <mutex> |
Songchun Fan | 9b75308 | 2020-02-26 13:08:06 -0800 | [diff] [blame] | 35 | #include <span> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 36 | #include <string> |
| 37 | #include <string_view> |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 38 | #include <thread> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 39 | #include <unordered_map> |
| 40 | #include <utility> |
| 41 | #include <vector> |
| 42 | |
| 43 | #include "ServiceWrappers.h" |
| 44 | #include "android/content/pm/BnDataLoaderStatusListener.h" |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 45 | #include "android/os/incremental/BnIncrementalServiceConnector.h" |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 46 | #include "incfs.h" |
| 47 | #include "path.h" |
| 48 | |
| 49 | using namespace android::os::incremental; |
| 50 | |
| 51 | namespace android::os { |
| 52 | class IVold; |
| 53 | } |
| 54 | |
| 55 | namespace android::incremental { |
| 56 | |
| 57 | using MountId = int; |
| 58 | using StorageId = int; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 59 | using FileId = incfs::FileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 60 | using BlockIndex = incfs::BlockIndex; |
| 61 | using RawMetadata = incfs::RawMetadata; |
| 62 | using Clock = std::chrono::steady_clock; |
| 63 | using TimePoint = std::chrono::time_point<Clock>; |
| 64 | using Seconds = std::chrono::seconds; |
| 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 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 69 | class IncrementalService final { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 70 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 71 | explicit IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 72 | |
| 73 | #pragma GCC diagnostic push |
| 74 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 75 | ~IncrementalService(); |
| 76 | #pragma GCC diagnostic pop |
| 77 | |
| 78 | static constexpr StorageId kInvalidStorageId = -1; |
| 79 | static constexpr StorageId kMaxStorageId = std::numeric_limits<int>::max(); |
| 80 | |
| 81 | enum CreateOptions { |
| 82 | TemporaryBind = 1, |
| 83 | PermanentBind = 2, |
| 84 | CreateNew = 4, |
| 85 | OpenExisting = 8, |
| 86 | |
| 87 | Default = TemporaryBind | CreateNew |
| 88 | }; |
| 89 | |
| 90 | enum class BindKind { |
| 91 | Temporary = 0, |
| 92 | Permanent = 1, |
| 93 | }; |
| 94 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 95 | static FileId idFromMetadata(std::span<const uint8_t> metadata); |
| 96 | static inline FileId idFromMetadata(std::span<const char> metadata) { |
| 97 | return idFromMetadata({(const uint8_t*)metadata.data(), metadata.size()}); |
| 98 | } |
| 99 | |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 100 | void onDump(int fd); |
| 101 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 102 | void onSystemReady(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 103 | |
Songchun Fan | 9b75308 | 2020-02-26 13:08:06 -0800 | [diff] [blame] | 104 | StorageId createStorage(std::string_view mountPoint, DataLoaderParamsParcel&& dataLoaderParams, |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 105 | const DataLoaderStatusListener& dataLoaderStatusListener, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 106 | CreateOptions options = CreateOptions::Default); |
| 107 | StorageId createLinkedStorage(std::string_view mountPoint, StorageId linkedStorage, |
| 108 | CreateOptions options = CreateOptions::Default); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 109 | StorageId openStorage(std::string_view path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 110 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 111 | FileId nodeFor(StorageId storage, std::string_view path) const; |
| 112 | std::pair<FileId, std::string_view> parentAndNameFor(StorageId storage, |
| 113 | std::string_view path) const; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 114 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 115 | 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] | 116 | int unbind(StorageId storage, std::string_view target); |
| 117 | void deleteStorage(StorageId storage); |
| 118 | |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 119 | int setStorageParams(StorageId storage, bool enableReadLogs); |
| 120 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 121 | int makeFile(StorageId storage, std::string_view path, int mode, FileId id, |
| 122 | incfs::NewFileParams params); |
Songchun Fan | 9610093 | 2020-02-03 19:20:58 -0800 | [diff] [blame] | 123 | int makeDir(StorageId storage, std::string_view path, int mode = 0755); |
| 124 | int makeDirs(StorageId storage, std::string_view path, int mode = 0755); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 125 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 126 | int link(StorageId sourceStorageId, std::string_view oldPath, StorageId destStorageId, |
| 127 | std::string_view newPath); |
| 128 | int unlink(StorageId storage, std::string_view path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 129 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 130 | bool isRangeLoaded(StorageId storage, FileId file, std::pair<BlockIndex, BlockIndex> range) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 131 | return false; |
| 132 | } |
| 133 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 134 | RawMetadata getMetadata(StorageId storage, FileId node) const; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 135 | |
| 136 | std::vector<std::string> listFiles(StorageId storage) const; |
| 137 | bool startLoading(StorageId storage) const; |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 138 | |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 139 | bool configureNativeBinaries(StorageId storage, std::string_view apkFullPath, |
| 140 | std::string_view libDirRelativePath, std::string_view abi); |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 141 | bool waitForNativeBinariesExtraction(StorageId storage); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 142 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 143 | class AppOpsListener : public android::BnAppOpsCallback { |
| 144 | public: |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 145 | AppOpsListener(IncrementalService& incrementalService, std::string packageName) |
| 146 | : incrementalService(incrementalService), packageName(std::move(packageName)) {} |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 147 | void opChanged(int32_t op, const String16& packageName) final; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 148 | |
| 149 | private: |
| 150 | IncrementalService& incrementalService; |
| 151 | const std::string packageName; |
| 152 | }; |
| 153 | |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 154 | class IncrementalServiceConnector : public BnIncrementalServiceConnector { |
| 155 | public: |
| 156 | IncrementalServiceConnector(IncrementalService& incrementalService, int32_t storage) |
Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 157 | : incrementalService(incrementalService), storage(storage) {} |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 158 | binder::Status setStorageParams(bool enableReadLogs, int32_t* _aidl_return) final; |
| 159 | |
| 160 | private: |
| 161 | IncrementalService& incrementalService; |
Alex Buynytskyy | 5f9e3a0 | 2020-04-07 21:13:41 -0700 | [diff] [blame] | 162 | int32_t const storage; |
Alex Buynytskyy | f415679 | 2020-04-07 14:26:55 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 165 | private: |
Yurii Zubrytskyi | 3787c9f | 2020-04-06 23:10:28 -0700 | [diff] [blame] | 166 | static const bool sEnablePerfLogging; |
| 167 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 168 | struct IncFsMount; |
| 169 | |
| 170 | class DataLoaderStub : public android::content::pm::BnDataLoaderStatusListener { |
| 171 | public: |
| 172 | DataLoaderStub(IncrementalService& service, MountId id, DataLoaderParamsParcel&& params, |
| 173 | FileSystemControlParcel&& control, |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 174 | const DataLoaderStatusListener* externalListener); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 175 | ~DataLoaderStub(); |
Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 176 | // Cleans up the internal state and invalidates DataLoaderStub. Any subsequent calls will |
| 177 | // result in an error. |
| 178 | void cleanupResources(); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 179 | |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 180 | bool requestCreate(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 181 | bool requestStart(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 182 | bool requestDestroy(); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 183 | |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 184 | void onDump(int fd); |
| 185 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 186 | MountId id() const { return mId; } |
| 187 | const DataLoaderParamsParcel& params() const { return mParams; } |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 188 | |
| 189 | private: |
| 190 | binder::Status onStatusChanged(MountId mount, int newStatus) final; |
| 191 | |
Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 192 | bool isValid() const { return mId != kInvalidStorageId; } |
| 193 | |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 194 | bool create(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 195 | bool start(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 196 | bool destroy(); |
| 197 | |
| 198 | bool setTargetStatus(int status); |
| 199 | bool waitForStatus(int status, Clock::duration duration); |
| 200 | |
| 201 | bool fsmStep(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 202 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 203 | IncrementalService& mService; |
Alex Buynytskyy | 9a54579a | 2020-04-17 15:34:47 -0700 | [diff] [blame] | 204 | MountId mId = kInvalidStorageId; |
| 205 | DataLoaderParamsParcel mParams; |
| 206 | FileSystemControlParcel mControl; |
| 207 | DataLoaderStatusListener mListener; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 208 | |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 209 | std::mutex mStatusMutex; |
| 210 | std::condition_variable mStatusCondition; |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 211 | int mCurrentStatus = IDataLoaderStatusListener::DATA_LOADER_DESTROYED; |
| 212 | int mTargetStatus = IDataLoaderStatusListener::DATA_LOADER_DESTROYED; |
| 213 | TimePoint mTargetStatusTs = {}; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 214 | }; |
| 215 | using DataLoaderStubPtr = sp<DataLoaderStub>; |
| 216 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 217 | struct IncFsMount { |
| 218 | struct Bind { |
| 219 | StorageId storage; |
| 220 | std::string savedFilename; |
| 221 | std::string sourceDir; |
| 222 | BindKind kind; |
| 223 | }; |
| 224 | |
| 225 | struct Storage { |
| 226 | std::string name; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 227 | }; |
| 228 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 229 | using Control = incfs::UniqueControl; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 230 | |
| 231 | using BindMap = std::map<std::string, Bind>; |
| 232 | using StorageMap = std::unordered_map<StorageId, Storage>; |
| 233 | |
| 234 | mutable std::mutex lock; |
| 235 | const std::string root; |
| 236 | Control control; |
| 237 | /*const*/ MountId mountId; |
| 238 | StorageMap storages; |
| 239 | BindMap bindPoints; |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 240 | DataLoaderStubPtr dataLoaderStub; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 241 | std::atomic<int> nextStorageDirNo{0}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 242 | const IncrementalService& incrementalService; |
| 243 | |
| 244 | IncFsMount(std::string root, MountId mountId, Control control, |
| 245 | const IncrementalService& incrementalService) |
| 246 | : root(std::move(root)), |
| 247 | control(std::move(control)), |
| 248 | mountId(mountId), |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 249 | incrementalService(incrementalService) {} |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 250 | IncFsMount(IncFsMount&&) = delete; |
| 251 | IncFsMount& operator=(IncFsMount&&) = delete; |
| 252 | ~IncFsMount(); |
| 253 | |
| 254 | StorageMap::iterator makeStorage(StorageId id); |
| 255 | |
| 256 | static void cleanupFilesystem(std::string_view root); |
| 257 | }; |
| 258 | |
| 259 | using IfsMountPtr = std::shared_ptr<IncFsMount>; |
| 260 | using MountMap = std::unordered_map<MountId, IfsMountPtr>; |
| 261 | using BindPathMap = std::map<std::string, IncFsMount::BindMap::iterator, path::PathLess>; |
| 262 | |
| 263 | void mountExistingImages(); |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 264 | bool mountExistingImage(std::string_view root); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 265 | |
| 266 | IfsMountPtr getIfs(StorageId storage) const; |
| 267 | const IfsMountPtr& getIfsLocked(StorageId storage) const; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 268 | int addBindMount(IncFsMount& ifs, StorageId storage, std::string_view storageRoot, |
| 269 | std::string&& source, std::string&& target, BindKind kind, |
| 270 | std::unique_lock<std::mutex>& mainLock); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 271 | |
| 272 | int addBindMountWithMd(IncFsMount& ifs, StorageId storage, std::string&& metadataName, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 273 | std::string&& source, std::string&& target, BindKind kind, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 274 | std::unique_lock<std::mutex>& mainLock); |
| 275 | |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 276 | DataLoaderStubPtr prepareDataLoader(IncFsMount& ifs, DataLoaderParamsParcel&& params, |
| 277 | const DataLoaderStatusListener* externalListener = nullptr); |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 278 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 279 | BindPathMap::const_iterator findStorageLocked(std::string_view path) const; |
| 280 | StorageId findStorageId(std::string_view path) const; |
| 281 | |
| 282 | void deleteStorage(IncFsMount& ifs); |
| 283 | void deleteStorageLocked(IncFsMount& ifs, std::unique_lock<std::mutex>&& ifsLock); |
| 284 | MountMap::iterator getStorageSlotLocked(); |
Yurii Zubrytskyi | 3787c9f | 2020-04-06 23:10:28 -0700 | [diff] [blame] | 285 | std::string normalizePathToStorage(const IfsMountPtr& incfs, StorageId storage, |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 286 | std::string_view path); |
Yurii Zubrytskyi | 3787c9f | 2020-04-06 23:10:28 -0700 | [diff] [blame] | 287 | std::string normalizePathToStorageLocked(IncFsMount::StorageMap::iterator storageIt, |
| 288 | std::string_view path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 289 | |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 290 | binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 291 | |
| 292 | void registerAppOpsCallback(const std::string& packageName); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 293 | bool unregisterAppOpsCallback(const std::string& packageName); |
| 294 | void onAppOpChanged(const std::string& packageName); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 295 | |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 296 | void runJobProcessing(); |
| 297 | void extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle zipFile, ZipEntry& entry, |
| 298 | const incfs::FileId& libFileId, std::string_view targetLibPath, |
| 299 | Clock::time_point scheduledTs); |
| 300 | |
| 301 | private: |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 302 | const std::unique_ptr<VoldServiceWrapper> mVold; |
| 303 | const std::unique_ptr<DataLoaderManagerWrapper> mDataLoaderManager; |
| 304 | const std::unique_ptr<IncFsWrapper> mIncFs; |
| 305 | const std::unique_ptr<AppOpsManagerWrapper> mAppOpsManager; |
| 306 | const std::unique_ptr<JniWrapper> mJni; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 307 | const std::string mIncrementalDir; |
| 308 | |
| 309 | mutable std::mutex mLock; |
| 310 | mutable std::mutex mMountOperationLock; |
| 311 | MountMap mMounts; |
| 312 | BindPathMap mBindsByPath; |
| 313 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 314 | std::mutex mCallbacksLock; |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 315 | std::map<std::string, sp<AppOpsListener>> mCallbackRegistered; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 316 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 317 | std::atomic_bool mSystemReady = false; |
| 318 | StorageId mNextId = 0; |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 319 | |
| 320 | using Job = std::function<void()>; |
Yurii Zubrytskyi | 721ac4d | 2020-04-13 11:34:32 -0700 | [diff] [blame] | 321 | std::unordered_map<MountId, std::vector<Job>> mJobQueue; |
| 322 | MountId mPendingJobsMount = kInvalidStorageId; |
Yurii Zubrytskyi | da20801 | 2020-04-07 15:35:21 -0700 | [diff] [blame] | 323 | std::condition_variable mJobCondition; |
| 324 | std::mutex mJobMutex; |
| 325 | std::thread mJobProcessor; |
| 326 | bool mRunning = true; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | } // namespace android::incremental |