blob: cd6bfedb8a9e0ddeef37cf066a38bb94ca1f9f00 [file] [log] [blame]
Songchun Fan3c82a302019-11-29 14:23:45 -08001/*
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 Zubrytskyi629051fd2020-04-17 23:13:47 -070019#include <android/content/pm/BnDataLoaderStatusListener.h>
Songchun Fan3c82a302019-11-29 14:23:45 -080020#include <android/content/pm/DataLoaderParamsParcel.h>
Alex Buynytskyycca2c112020-05-05 12:48:41 -070021#include <android/content/pm/FileSystemControlParcel.h>
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -070022#include <android/content/pm/IDataLoaderStatusListener.h>
23#include <android/os/incremental/BnIncrementalServiceConnector.h>
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -070024#include <android/os/incremental/BnStorageHealthListener.h>
25#include <android/os/incremental/StorageHealthCheckParams.h>
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -070026#include <binder/IAppOpsCallback.h>
Songchun Fan3c82a302019-11-29 14:23:45 -080027#include <utils/String16.h>
28#include <utils/StrongPointer.h>
Yurii Zubrytskyida208012020-04-07 15:35:21 -070029#include <ziparchive/zip_archive.h>
Songchun Fan3c82a302019-11-29 14:23:45 -080030
31#include <atomic>
32#include <chrono>
Yurii Zubrytskyida208012020-04-07 15:35:21 -070033#include <condition_variable>
34#include <functional>
Songchun Fan3c82a302019-11-29 14:23:45 -080035#include <limits>
36#include <map>
37#include <mutex>
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -070038#include <set>
Songchun Fan9b753082020-02-26 13:08:06 -080039#include <span>
Songchun Fan3c82a302019-11-29 14:23:45 -080040#include <string>
41#include <string_view>
Yurii Zubrytskyida208012020-04-07 15:35:21 -070042#include <thread>
Songchun Fan3c82a302019-11-29 14:23:45 -080043#include <unordered_map>
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -070044#include <unordered_set>
Songchun Fan3c82a302019-11-29 14:23:45 -080045#include <utility>
46#include <vector>
47
48#include "ServiceWrappers.h"
Songchun Fan3c82a302019-11-29 14:23:45 -080049#include "incfs.h"
50#include "path.h"
51
Songchun Fan3c82a302019-11-29 14:23:45 -080052namespace android::incremental {
53
54using MountId = int;
55using StorageId = int;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080056using FileId = incfs::FileId;
Songchun Fan3c82a302019-11-29 14:23:45 -080057using BlockIndex = incfs::BlockIndex;
58using RawMetadata = incfs::RawMetadata;
Songchun Fan3c82a302019-11-29 14:23:45 -080059using Seconds = std::chrono::seconds;
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -070060using BootClockTsUs = uint64_t;
Songchun Fan3c82a302019-11-29 14:23:45 -080061
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -070062using IDataLoaderStatusListener = ::android::content::pm::IDataLoaderStatusListener;
63using DataLoaderStatusListener = ::android::sp<IDataLoaderStatusListener>;
Alex Buynytskyy04f73912020-02-10 08:34:18 -080064
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -070065using StorageHealthCheckParams = ::android::os::incremental::StorageHealthCheckParams;
66using IStorageHealthListener = ::android::os::incremental::IStorageHealthListener;
67using StorageHealthListener = ::android::sp<IStorageHealthListener>;
68
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080069class IncrementalService final {
Songchun Fan3c82a302019-11-29 14:23:45 -080070public:
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080071 explicit IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir);
Songchun Fan3c82a302019-11-29 14:23:45 -080072
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
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -070081 static constexpr BootClockTsUs kMaxBootClockTsUs = std::numeric_limits<BootClockTsUs>::max();
82
Songchun Fan3c82a302019-11-29 14:23:45 -080083 enum CreateOptions {
84 TemporaryBind = 1,
85 PermanentBind = 2,
86 CreateNew = 4,
87 OpenExisting = 8,
88
89 Default = TemporaryBind | CreateNew
90 };
91
92 enum class BindKind {
93 Temporary = 0,
94 Permanent = 1,
95 };
96
Alex Buynytskyy3697d9e2020-06-06 20:15:58 -070097 enum StorageFlags {
98 ReadLogsEnabled = 1,
99 };
100
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800101 static FileId idFromMetadata(std::span<const uint8_t> metadata);
102 static inline FileId idFromMetadata(std::span<const char> metadata) {
103 return idFromMetadata({(const uint8_t*)metadata.data(), metadata.size()});
104 }
105
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800106 void onDump(int fd);
107
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700108 void onSystemReady();
Songchun Fan3c82a302019-11-29 14:23:45 -0800109
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700110 StorageId createStorage(std::string_view mountPoint,
111 content::pm::DataLoaderParamsParcel&& dataLoaderParams,
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -0700112 CreateOptions options, const DataLoaderStatusListener& statusListener,
113 StorageHealthCheckParams&& healthCheckParams,
114 const StorageHealthListener& healthListener);
Songchun Fan3c82a302019-11-29 14:23:45 -0800115 StorageId createLinkedStorage(std::string_view mountPoint, StorageId linkedStorage,
116 CreateOptions options = CreateOptions::Default);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800117 StorageId openStorage(std::string_view path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800118
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800119 int bind(StorageId storage, std::string_view source, std::string_view target, BindKind kind);
Songchun Fan3c82a302019-11-29 14:23:45 -0800120 int unbind(StorageId storage, std::string_view target);
121 void deleteStorage(StorageId storage);
122
Alex Buynytskyy3697d9e2020-06-06 20:15:58 -0700123 void disableReadLogs(StorageId storage);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700124 int setStorageParams(StorageId storage, bool enableReadLogs);
125
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800126 int makeFile(StorageId storage, std::string_view path, int mode, FileId id,
127 incfs::NewFileParams params);
Songchun Fan96100932020-02-03 19:20:58 -0800128 int makeDir(StorageId storage, std::string_view path, int mode = 0755);
129 int makeDirs(StorageId storage, std::string_view path, int mode = 0755);
Songchun Fan3c82a302019-11-29 14:23:45 -0800130
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800131 int link(StorageId sourceStorageId, std::string_view oldPath, StorageId destStorageId,
132 std::string_view newPath);
133 int unlink(StorageId storage, std::string_view path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800134
Songchun Fan374f7652020-08-20 08:40:29 -0700135 float getLoadingProgress(StorageId storage) const;
Songchun Fan3c82a302019-11-29 14:23:45 -0800136
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700137 RawMetadata getMetadata(StorageId storage, std::string_view path) const;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800138 RawMetadata getMetadata(StorageId storage, FileId node) const;
Songchun Fan3c82a302019-11-29 14:23:45 -0800139
Songchun Fan3c82a302019-11-29 14:23:45 -0800140 bool startLoading(StorageId storage) const;
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700141
Songchun Fan0f8b6fe2020-02-05 17:41:25 -0800142 bool configureNativeBinaries(StorageId storage, std::string_view apkFullPath,
Songchun Fan14f6c3c2020-05-21 18:19:07 -0700143 std::string_view libDirRelativePath, std::string_view abi,
144 bool extractNativeLibs);
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700145 bool waitForNativeBinariesExtraction(StorageId storage);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700146
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700147 class AppOpsListener : public android::BnAppOpsCallback {
148 public:
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700149 AppOpsListener(IncrementalService& incrementalService, std::string packageName)
150 : incrementalService(incrementalService), packageName(std::move(packageName)) {}
Alex Buynytskyyf4156792020-04-07 14:26:55 -0700151 void opChanged(int32_t op, const String16& packageName) final;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700152
153 private:
154 IncrementalService& incrementalService;
155 const std::string packageName;
156 };
157
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700158 class IncrementalServiceConnector : public os::incremental::BnIncrementalServiceConnector {
Alex Buynytskyyf4156792020-04-07 14:26:55 -0700159 public:
160 IncrementalServiceConnector(IncrementalService& incrementalService, int32_t storage)
Alex Buynytskyy5f9e3a02020-04-07 21:13:41 -0700161 : incrementalService(incrementalService), storage(storage) {}
Alex Buynytskyyf4156792020-04-07 14:26:55 -0700162 binder::Status setStorageParams(bool enableReadLogs, int32_t* _aidl_return) final;
163
164 private:
165 IncrementalService& incrementalService;
Alex Buynytskyy5f9e3a02020-04-07 21:13:41 -0700166 int32_t const storage;
Alex Buynytskyyf4156792020-04-07 14:26:55 -0700167 };
168
Songchun Fan3c82a302019-11-29 14:23:45 -0800169private:
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700170 struct IncFsMount;
171
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700172 class DataLoaderStub : public content::pm::BnDataLoaderStatusListener {
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700173 public:
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700174 DataLoaderStub(IncrementalService& service, MountId id,
175 content::pm::DataLoaderParamsParcel&& params,
176 content::pm::FileSystemControlParcel&& control,
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -0700177 const DataLoaderStatusListener* statusListener,
178 StorageHealthCheckParams&& healthCheckParams,
179 const StorageHealthListener* healthListener, std::string&& healthPath);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700180 ~DataLoaderStub();
Alex Buynytskyy9a545792020-04-17 15:34:47 -0700181 // Cleans up the internal state and invalidates DataLoaderStub. Any subsequent calls will
182 // result in an error.
183 void cleanupResources();
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700184
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700185 bool requestCreate();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700186 bool requestStart();
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700187 bool requestDestroy();
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700188
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700189 void onDump(int fd);
190
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700191 MountId id() const { return mId.load(std::memory_order_relaxed); }
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700192 const content::pm::DataLoaderParamsParcel& params() const { return mParams; }
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700193
194 private:
195 binder::Status onStatusChanged(MountId mount, int newStatus) final;
196
Alex Buynytskyy0bdbccf2020-04-23 20:36:42 -0700197 sp<content::pm::IDataLoader> getDataLoader();
Alex Buynytskyy9a545792020-04-17 15:34:47 -0700198
Alex Buynytskyyea1390f2020-04-22 16:08:50 -0700199 bool bind();
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700200 bool create();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700201 bool start();
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700202 bool destroy();
203
204 bool setTargetStatus(int status);
Alex Buynytskyy7e0a1a82020-04-27 17:06:10 -0700205 void setTargetStatusLocked(int status);
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700206
207 bool fsmStep();
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700208 bool fsmStep(int currentStatus, int targetStatus);
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700209
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700210 void onHealthStatus(StorageHealthListener healthListener, int healthStatus);
211 void updateHealthStatus(bool baseline = false);
212
213 bool isValid() const { return id() != kInvalidStorageId; }
214
215 bool isHealthParamsValid() const;
216
217 const incfs::UniqueControl& initializeHealthControl();
218 void resetHealthControl();
219
220 BootClockTsUs getOldestPendingReadTs();
221
222 void registerForPendingReads();
223 void unregisterFromPendingReads();
Alex Buynytskyyd0855a32020-05-07 18:40:51 -0700224
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700225 IncrementalService& mService;
Alex Buynytskyyb0ea4482020-05-04 18:39:58 -0700226
227 std::mutex mMutex;
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700228 std::atomic<MountId> mId = kInvalidStorageId;
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700229 content::pm::DataLoaderParamsParcel mParams;
230 content::pm::FileSystemControlParcel mControl;
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -0700231 DataLoaderStatusListener mStatusListener;
232 StorageHealthListener mHealthListener;
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700233
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700234 std::condition_variable mStatusCondition;
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700235 int mCurrentStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
236 int mTargetStatus = content::pm::IDataLoaderStatusListener::DATA_LOADER_DESTROYED;
Alex Buynytskyyab65cb12020-04-17 10:01:47 -0700237 TimePoint mTargetStatusTs = {};
Alex Buynytskyycca2c112020-05-05 12:48:41 -0700238
Alex Buynytskyyd0855a32020-05-07 18:40:51 -0700239 std::string mHealthPath;
240 incfs::UniqueControl mHealthControl;
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700241 struct {
242 TimePoint userTs;
243 BootClockTsUs kernelTsUs;
244 } mHealthBase = {TimePoint::max(), kMaxBootClockTsUs};
245 StorageHealthCheckParams mHealthCheckParams;
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700246 };
247 using DataLoaderStubPtr = sp<DataLoaderStub>;
248
Songchun Fan3c82a302019-11-29 14:23:45 -0800249 struct IncFsMount {
250 struct Bind {
251 StorageId storage;
252 std::string savedFilename;
253 std::string sourceDir;
254 BindKind kind;
255 };
256
257 struct Storage {
258 std::string name;
Songchun Fan3c82a302019-11-29 14:23:45 -0800259 };
260
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800261 using Control = incfs::UniqueControl;
Songchun Fan3c82a302019-11-29 14:23:45 -0800262
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700263 using BindMap = std::map<std::string, Bind, path::PathLess>;
Songchun Fan3c82a302019-11-29 14:23:45 -0800264 using StorageMap = std::unordered_map<StorageId, Storage>;
265
266 mutable std::mutex lock;
267 const std::string root;
268 Control control;
269 /*const*/ MountId mountId;
Alex Buynytskyy3697d9e2020-06-06 20:15:58 -0700270 int32_t flags = StorageFlags::ReadLogsEnabled;
Songchun Fan3c82a302019-11-29 14:23:45 -0800271 StorageMap storages;
272 BindMap bindPoints;
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700273 DataLoaderStubPtr dataLoaderStub;
Songchun Fan3c82a302019-11-29 14:23:45 -0800274 std::atomic<int> nextStorageDirNo{0};
Songchun Fan3c82a302019-11-29 14:23:45 -0800275 const IncrementalService& incrementalService;
276
277 IncFsMount(std::string root, MountId mountId, Control control,
278 const IncrementalService& incrementalService)
279 : root(std::move(root)),
280 control(std::move(control)),
281 mountId(mountId),
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700282 incrementalService(incrementalService) {}
Songchun Fan3c82a302019-11-29 14:23:45 -0800283 IncFsMount(IncFsMount&&) = delete;
284 IncFsMount& operator=(IncFsMount&&) = delete;
285 ~IncFsMount();
286
287 StorageMap::iterator makeStorage(StorageId id);
288
Alex Buynytskyy3697d9e2020-06-06 20:15:58 -0700289 void disableReadLogs() { flags &= ~StorageFlags::ReadLogsEnabled; }
290 int32_t readLogsEnabled() const { return (flags & StorageFlags::ReadLogsEnabled); }
291
Songchun Fan3c82a302019-11-29 14:23:45 -0800292 static void cleanupFilesystem(std::string_view root);
293 };
294
295 using IfsMountPtr = std::shared_ptr<IncFsMount>;
296 using MountMap = std::unordered_map<MountId, IfsMountPtr>;
297 using BindPathMap = std::map<std::string, IncFsMount::BindMap::iterator, path::PathLess>;
298
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700299 static bool perfLoggingEnabled();
300
301 std::unordered_set<std::string_view> adoptMountedInstances();
302 void mountExistingImages(const std::unordered_set<std::string_view>& mountedRootNames);
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -0700303 bool mountExistingImage(std::string_view root);
Songchun Fan3c82a302019-11-29 14:23:45 -0800304
305 IfsMountPtr getIfs(StorageId storage) const;
306 const IfsMountPtr& getIfsLocked(StorageId storage) const;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800307 int addBindMount(IncFsMount& ifs, StorageId storage, std::string_view storageRoot,
308 std::string&& source, std::string&& target, BindKind kind,
309 std::unique_lock<std::mutex>& mainLock);
Songchun Fan3c82a302019-11-29 14:23:45 -0800310
311 int addBindMountWithMd(IncFsMount& ifs, StorageId storage, std::string&& metadataName,
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800312 std::string&& source, std::string&& target, BindKind kind,
Songchun Fan3c82a302019-11-29 14:23:45 -0800313 std::unique_lock<std::mutex>& mainLock);
314
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700315 void addBindMountRecordLocked(IncFsMount& ifs, StorageId storage, std::string&& metadataName,
316 std::string&& source, std::string&& target, BindKind kind);
317
318 DataLoaderStubPtr prepareDataLoader(IncFsMount& ifs,
319 content::pm::DataLoaderParamsParcel&& params,
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -0700320 const DataLoaderStatusListener* statusListener = nullptr,
321 StorageHealthCheckParams&& healthCheckParams = {},
322 const StorageHealthListener* healthListener = nullptr);
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700323 void prepareDataLoaderLocked(IncFsMount& ifs, content::pm::DataLoaderParamsParcel&& params,
Alex Buynytskyy8ef61ae2020-05-08 16:18:52 -0700324 const DataLoaderStatusListener* statusListener = nullptr,
325 StorageHealthCheckParams&& healthCheckParams = {},
326 const StorageHealthListener* healthListener = nullptr);
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700327
Songchun Fan3c82a302019-11-29 14:23:45 -0800328 BindPathMap::const_iterator findStorageLocked(std::string_view path) const;
329 StorageId findStorageId(std::string_view path) const;
330
331 void deleteStorage(IncFsMount& ifs);
332 void deleteStorageLocked(IncFsMount& ifs, std::unique_lock<std::mutex>&& ifsLock);
333 MountMap::iterator getStorageSlotLocked();
Yurii Zubrytskyiefebb452020-04-22 13:59:06 -0700334 std::string normalizePathToStorage(const IncFsMount& incfs, StorageId storage,
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700335 std::string_view path) const;
Yurii Zubrytskyiefebb452020-04-22 13:59:06 -0700336 std::string normalizePathToStorageLocked(const IncFsMount& incfs,
337 IncFsMount::StorageMap::const_iterator storageIt,
Yurii Zubrytskyi629051fd2020-04-17 23:13:47 -0700338 std::string_view path) const;
Yurii Zubrytskyiefebb452020-04-22 13:59:06 -0700339 int makeDirs(const IncFsMount& ifs, StorageId storageId, std::string_view path, int mode);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700340 binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700341
Songchun Fan374f7652020-08-20 08:40:29 -0700342 float getLoadingProgressFromPath(const IncFsMount& ifs, std::string_view path) const;
343
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700344 void registerAppOpsCallback(const std::string& packageName);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700345 bool unregisterAppOpsCallback(const std::string& packageName);
346 void onAppOpChanged(const std::string& packageName);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700347
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700348 void runJobProcessing();
349 void extractZipFile(const IfsMountPtr& ifs, ZipArchiveHandle zipFile, ZipEntry& entry,
350 const incfs::FileId& libFileId, std::string_view targetLibPath,
351 Clock::time_point scheduledTs);
352
Alex Buynytskyycca2c112020-05-05 12:48:41 -0700353 void runCmdLooper();
354
Alex Buynytskyy46d3ddb2020-05-29 12:05:05 -0700355 void addTimedJob(MountId id, Milliseconds after, Job what);
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700356 void removeTimedJobs(MountId id);
Alex Buynytskyy4760d8f2020-05-08 16:18:52 -0700357
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700358private:
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700359 const std::unique_ptr<VoldServiceWrapper> mVold;
360 const std::unique_ptr<DataLoaderManagerWrapper> mDataLoaderManager;
361 const std::unique_ptr<IncFsWrapper> mIncFs;
362 const std::unique_ptr<AppOpsManagerWrapper> mAppOpsManager;
363 const std::unique_ptr<JniWrapper> mJni;
Alex Buynytskyycca2c112020-05-05 12:48:41 -0700364 const std::unique_ptr<LooperWrapper> mLooper;
Alex Buynytskyy46d3ddb2020-05-29 12:05:05 -0700365 const std::unique_ptr<TimedQueueWrapper> mTimedQueue;
Songchun Fan374f7652020-08-20 08:40:29 -0700366 const std::unique_ptr<FsWrapper> mFs;
Songchun Fan3c82a302019-11-29 14:23:45 -0800367 const std::string mIncrementalDir;
368
369 mutable std::mutex mLock;
370 mutable std::mutex mMountOperationLock;
371 MountMap mMounts;
372 BindPathMap mBindsByPath;
373
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700374 std::mutex mCallbacksLock;
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700375 std::map<std::string, sp<AppOpsListener>> mCallbackRegistered;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700376
Songchun Fan3c82a302019-11-29 14:23:45 -0800377 std::atomic_bool mSystemReady = false;
378 StorageId mNextId = 0;
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700379
Alex Buynytskyycca2c112020-05-05 12:48:41 -0700380 std::atomic_bool mRunning{true};
381
Yurii Zubrytskyi721ac4d2020-04-13 11:34:32 -0700382 std::unordered_map<MountId, std::vector<Job>> mJobQueue;
383 MountId mPendingJobsMount = kInvalidStorageId;
Yurii Zubrytskyida208012020-04-07 15:35:21 -0700384 std::condition_variable mJobCondition;
385 std::mutex mJobMutex;
386 std::thread mJobProcessor;
Alex Buynytskyycca2c112020-05-05 12:48:41 -0700387
388 std::thread mCmdLooperThread;
Songchun Fan3c82a302019-11-29 14:23:45 -0800389};
390
391} // namespace android::incremental