blob: d6ce529fb56f3f9bb3456ebd2785af605c82a682 [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#define LOG_TAG "IncrementalService"
18
19#include "IncrementalService.h"
20
21#include <android-base/file.h>
22#include <android-base/logging.h>
23#include <android-base/properties.h>
24#include <android-base/stringprintf.h>
25#include <android-base/strings.h>
26#include <android/content/pm/IDataLoaderStatusListener.h>
27#include <android/os/IVold.h>
28#include <androidfw/ZipFileRO.h>
29#include <androidfw/ZipUtils.h>
30#include <binder/BinderService.h>
Jooyung Han66c567a2020-03-07 21:47:09 +090031#include <binder/Nullable.h>
Songchun Fan3c82a302019-11-29 14:23:45 -080032#include <binder/ParcelFileDescriptor.h>
33#include <binder/Status.h>
34#include <sys/stat.h>
35#include <uuid/uuid.h>
36#include <zlib.h>
37
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -070038#include <charconv>
Alex Buynytskyy18b07a42020-02-03 20:06:00 -080039#include <ctime>
Songchun Fan1124fd32020-02-10 12:49:41 -080040#include <filesystem>
Songchun Fan3c82a302019-11-29 14:23:45 -080041#include <iterator>
42#include <span>
43#include <stack>
44#include <thread>
45#include <type_traits>
46
47#include "Metadata.pb.h"
48
49using namespace std::literals;
50using namespace android::content::pm;
Songchun Fan1124fd32020-02-10 12:49:41 -080051namespace fs = std::filesystem;
Songchun Fan3c82a302019-11-29 14:23:45 -080052
Alex Buynytskyy96e350b2020-04-02 20:03:47 -070053constexpr const char* kDataUsageStats = "android.permission.LOADER_USAGE_STATS";
54constexpr const char* kOpUsage = "android:get_usage_stats";
55
Songchun Fan3c82a302019-11-29 14:23:45 -080056namespace android::incremental {
57
58namespace {
59
60using IncrementalFileSystemControlParcel =
61 ::android::os::incremental::IncrementalFileSystemControlParcel;
62
63struct Constants {
64 static constexpr auto backing = "backing_store"sv;
65 static constexpr auto mount = "mount"sv;
Songchun Fan1124fd32020-02-10 12:49:41 -080066 static constexpr auto mountKeyPrefix = "MT_"sv;
Songchun Fan3c82a302019-11-29 14:23:45 -080067 static constexpr auto storagePrefix = "st"sv;
68 static constexpr auto mountpointMdPrefix = ".mountpoint."sv;
69 static constexpr auto infoMdName = ".info"sv;
Songchun Fan0f8b6fe2020-02-05 17:41:25 -080070 static constexpr auto libDir = "lib"sv;
71 static constexpr auto libSuffix = ".so"sv;
72 static constexpr auto blockSize = 4096;
Songchun Fan3c82a302019-11-29 14:23:45 -080073};
74
75static const Constants& constants() {
76 static Constants c;
77 return c;
78}
79
80template <base::LogSeverity level = base::ERROR>
81bool mkdirOrLog(std::string_view name, int mode = 0770, bool allowExisting = true) {
82 auto cstr = path::c_str(name);
83 if (::mkdir(cstr, mode)) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080084 if (!allowExisting || errno != EEXIST) {
Songchun Fan3c82a302019-11-29 14:23:45 -080085 PLOG(level) << "Can't create directory '" << name << '\'';
86 return false;
87 }
88 struct stat st;
89 if (::stat(cstr, &st) || !S_ISDIR(st.st_mode)) {
90 PLOG(level) << "Path exists but is not a directory: '" << name << '\'';
91 return false;
92 }
93 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080094 if (::chmod(cstr, mode)) {
95 PLOG(level) << "Changing permission failed for '" << name << '\'';
96 return false;
97 }
98
Songchun Fan3c82a302019-11-29 14:23:45 -080099 return true;
100}
101
102static std::string toMountKey(std::string_view path) {
103 if (path.empty()) {
104 return "@none";
105 }
106 if (path == "/"sv) {
107 return "@root";
108 }
109 if (path::isAbsolute(path)) {
110 path.remove_prefix(1);
111 }
112 std::string res(path);
113 std::replace(res.begin(), res.end(), '/', '_');
114 std::replace(res.begin(), res.end(), '@', '_');
Songchun Fan1124fd32020-02-10 12:49:41 -0800115 return std::string(constants().mountKeyPrefix) + res;
Songchun Fan3c82a302019-11-29 14:23:45 -0800116}
117
118static std::pair<std::string, std::string> makeMountDir(std::string_view incrementalDir,
119 std::string_view path) {
120 auto mountKey = toMountKey(path);
121 const auto prefixSize = mountKey.size();
122 for (int counter = 0; counter < 1000;
123 mountKey.resize(prefixSize), base::StringAppendF(&mountKey, "%d", counter++)) {
124 auto mountRoot = path::join(incrementalDir, mountKey);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800125 if (mkdirOrLog(mountRoot, 0777, false)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800126 return {mountKey, mountRoot};
127 }
128 }
129 return {};
130}
131
132template <class ProtoMessage, class Control>
133static ProtoMessage parseFromIncfs(const IncFsWrapper* incfs, Control&& control,
134 std::string_view path) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800135 auto md = incfs->getMetadata(control, path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800136 ProtoMessage message;
137 return message.ParseFromArray(md.data(), md.size()) ? message : ProtoMessage{};
138}
139
140static bool isValidMountTarget(std::string_view path) {
141 return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true);
142}
143
144std::string makeBindMdName() {
145 static constexpr auto uuidStringSize = 36;
146
147 uuid_t guid;
148 uuid_generate(guid);
149
150 std::string name;
151 const auto prefixSize = constants().mountpointMdPrefix.size();
152 name.reserve(prefixSize + uuidStringSize);
153
154 name = constants().mountpointMdPrefix;
155 name.resize(prefixSize + uuidStringSize);
156 uuid_unparse(guid, name.data() + prefixSize);
157
158 return name;
159}
160} // namespace
161
162IncrementalService::IncFsMount::~IncFsMount() {
Songchun Fan68645c42020-02-27 15:57:35 -0800163 incrementalService.mDataLoaderManager->destroyDataLoader(mountId);
Songchun Fan3c82a302019-11-29 14:23:45 -0800164 LOG(INFO) << "Unmounting and cleaning up mount " << mountId << " with root '" << root << '\'';
165 for (auto&& [target, _] : bindPoints) {
166 LOG(INFO) << "\tbind: " << target;
167 incrementalService.mVold->unmountIncFs(target);
168 }
169 LOG(INFO) << "\troot: " << root;
170 incrementalService.mVold->unmountIncFs(path::join(root, constants().mount));
171 cleanupFilesystem(root);
172}
173
174auto IncrementalService::IncFsMount::makeStorage(StorageId id) -> StorageMap::iterator {
Songchun Fan3c82a302019-11-29 14:23:45 -0800175 std::string name;
176 for (int no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), i = 0;
177 i < 1024 && no >= 0; no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), ++i) {
178 name.clear();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800179 base::StringAppendF(&name, "%.*s_%d_%d", int(constants().storagePrefix.size()),
180 constants().storagePrefix.data(), id, no);
181 auto fullName = path::join(root, constants().mount, name);
Songchun Fan96100932020-02-03 19:20:58 -0800182 if (auto err = incrementalService.mIncFs->makeDir(control, fullName, 0755); !err) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800183 std::lock_guard l(lock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800184 return storages.insert_or_assign(id, Storage{std::move(fullName)}).first;
185 } else if (err != EEXIST) {
186 LOG(ERROR) << __func__ << "(): failed to create dir |" << fullName << "| " << err;
187 break;
Songchun Fan3c82a302019-11-29 14:23:45 -0800188 }
189 }
190 nextStorageDirNo = 0;
191 return storages.end();
192}
193
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800194static std::unique_ptr<DIR, decltype(&::closedir)> openDir(const char* path) {
195 return {::opendir(path), ::closedir};
196}
197
198static int rmDirContent(const char* path) {
199 auto dir = openDir(path);
200 if (!dir) {
201 return -EINVAL;
202 }
203 while (auto entry = ::readdir(dir.get())) {
204 if (entry->d_name == "."sv || entry->d_name == ".."sv) {
205 continue;
206 }
207 auto fullPath = android::base::StringPrintf("%s/%s", path, entry->d_name);
208 if (entry->d_type == DT_DIR) {
209 if (const auto err = rmDirContent(fullPath.c_str()); err != 0) {
210 PLOG(WARNING) << "Failed to delete " << fullPath << " content";
211 return err;
212 }
213 if (const auto err = ::rmdir(fullPath.c_str()); err != 0) {
214 PLOG(WARNING) << "Failed to rmdir " << fullPath;
215 return err;
216 }
217 } else {
218 if (const auto err = ::unlink(fullPath.c_str()); err != 0) {
219 PLOG(WARNING) << "Failed to delete " << fullPath;
220 return err;
221 }
222 }
223 }
224 return 0;
225}
226
Songchun Fan3c82a302019-11-29 14:23:45 -0800227void IncrementalService::IncFsMount::cleanupFilesystem(std::string_view root) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800228 rmDirContent(path::join(root, constants().backing).c_str());
Songchun Fan3c82a302019-11-29 14:23:45 -0800229 ::rmdir(path::join(root, constants().backing).c_str());
230 ::rmdir(path::join(root, constants().mount).c_str());
231 ::rmdir(path::c_str(root));
232}
233
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800234IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir)
Songchun Fan3c82a302019-11-29 14:23:45 -0800235 : mVold(sm.getVoldService()),
Songchun Fan68645c42020-02-27 15:57:35 -0800236 mDataLoaderManager(sm.getDataLoaderManager()),
Songchun Fan3c82a302019-11-29 14:23:45 -0800237 mIncFs(sm.getIncFs()),
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700238 mAppOpsManager(sm.getAppOpsManager()),
Songchun Fan3c82a302019-11-29 14:23:45 -0800239 mIncrementalDir(rootDir) {
240 if (!mVold) {
241 LOG(FATAL) << "Vold service is unavailable";
242 }
Songchun Fan68645c42020-02-27 15:57:35 -0800243 if (!mDataLoaderManager) {
244 LOG(FATAL) << "DataLoaderManagerService is unavailable";
Songchun Fan3c82a302019-11-29 14:23:45 -0800245 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700246 if (!mAppOpsManager) {
247 LOG(FATAL) << "AppOpsManager is unavailable";
248 }
Songchun Fan1124fd32020-02-10 12:49:41 -0800249 mountExistingImages();
Songchun Fan3c82a302019-11-29 14:23:45 -0800250}
251
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800252FileId IncrementalService::idFromMetadata(std::span<const uint8_t> metadata) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800253 return IncFs_FileIdFromMetadata({(const char*)metadata.data(), metadata.size()});
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800254}
255
Songchun Fan3c82a302019-11-29 14:23:45 -0800256IncrementalService::~IncrementalService() = default;
257
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800258inline const char* toString(TimePoint t) {
259 using SystemClock = std::chrono::system_clock;
Songchun Fan0f8b6fe2020-02-05 17:41:25 -0800260 time_t time = SystemClock::to_time_t(
261 SystemClock::now() +
262 std::chrono::duration_cast<SystemClock::duration>(t - Clock::now()));
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800263 return std::ctime(&time);
264}
265
266inline const char* toString(IncrementalService::BindKind kind) {
267 switch (kind) {
Songchun Fan0f8b6fe2020-02-05 17:41:25 -0800268 case IncrementalService::BindKind::Temporary:
269 return "Temporary";
270 case IncrementalService::BindKind::Permanent:
271 return "Permanent";
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800272 }
273}
274
275void IncrementalService::onDump(int fd) {
276 dprintf(fd, "Incremental is %s\n", incfs::enabled() ? "ENABLED" : "DISABLED");
277 dprintf(fd, "Incremental dir: %s\n", mIncrementalDir.c_str());
278
279 std::unique_lock l(mLock);
280
281 dprintf(fd, "Mounts (%d):\n", int(mMounts.size()));
282 for (auto&& [id, ifs] : mMounts) {
283 const IncFsMount& mnt = *ifs.get();
284 dprintf(fd, "\t[%d]:\n", id);
285 dprintf(fd, "\t\tmountId: %d\n", mnt.mountId);
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -0700286 dprintf(fd, "\t\troot: %s\n", mnt.root.c_str());
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800287 dprintf(fd, "\t\tnextStorageDirNo: %d\n", mnt.nextStorageDirNo.load());
288 dprintf(fd, "\t\tdataLoaderStatus: %d\n", mnt.dataLoaderStatus.load());
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700289 {
290 const auto& params = mnt.dataLoaderParams;
291 dprintf(fd, "\t\tdataLoaderParams:\n");
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800292 dprintf(fd, "\t\t\ttype: %s\n", toString(params.type).c_str());
293 dprintf(fd, "\t\t\tpackageName: %s\n", params.packageName.c_str());
294 dprintf(fd, "\t\t\tclassName: %s\n", params.className.c_str());
295 dprintf(fd, "\t\t\targuments: %s\n", params.arguments.c_str());
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800296 }
297 dprintf(fd, "\t\tstorages (%d):\n", int(mnt.storages.size()));
298 for (auto&& [storageId, storage] : mnt.storages) {
299 dprintf(fd, "\t\t\t[%d] -> [%s]\n", storageId, storage.name.c_str());
300 }
301
302 dprintf(fd, "\t\tbindPoints (%d):\n", int(mnt.bindPoints.size()));
303 for (auto&& [target, bind] : mnt.bindPoints) {
304 dprintf(fd, "\t\t\t[%s]->[%d]:\n", target.c_str(), bind.storage);
305 dprintf(fd, "\t\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str());
306 dprintf(fd, "\t\t\t\tsourceDir: %s\n", bind.sourceDir.c_str());
307 dprintf(fd, "\t\t\t\tkind: %s\n", toString(bind.kind));
308 }
309 }
310
311 dprintf(fd, "Sorted binds (%d):\n", int(mBindsByPath.size()));
312 for (auto&& [target, mountPairIt] : mBindsByPath) {
313 const auto& bind = mountPairIt->second;
314 dprintf(fd, "\t\t[%s]->[%d]:\n", target.c_str(), bind.storage);
315 dprintf(fd, "\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str());
316 dprintf(fd, "\t\t\tsourceDir: %s\n", bind.sourceDir.c_str());
317 dprintf(fd, "\t\t\tkind: %s\n", toString(bind.kind));
318 }
319}
320
Songchun Fan3c82a302019-11-29 14:23:45 -0800321std::optional<std::future<void>> IncrementalService::onSystemReady() {
322 std::promise<void> threadFinished;
323 if (mSystemReady.exchange(true)) {
324 return {};
325 }
326
327 std::vector<IfsMountPtr> mounts;
328 {
329 std::lock_guard l(mLock);
330 mounts.reserve(mMounts.size());
331 for (auto&& [id, ifs] : mMounts) {
332 if (ifs->mountId == id) {
333 mounts.push_back(ifs);
334 }
335 }
336 }
337
338 std::thread([this, mounts = std::move(mounts)]() {
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700339 /* TODO(b/151241369): restore data loaders on reboot.
Songchun Fan3c82a302019-11-29 14:23:45 -0800340 for (auto&& ifs : mounts) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800341 if (prepareDataLoader(*ifs)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800342 LOG(INFO) << "Successfully started data loader for mount " << ifs->mountId;
343 } else {
Songchun Fan1124fd32020-02-10 12:49:41 -0800344 // TODO(b/133435829): handle data loader start failures
Songchun Fan3c82a302019-11-29 14:23:45 -0800345 LOG(WARNING) << "Failed to start data loader for mount " << ifs->mountId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800346 }
347 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700348 */
Songchun Fan3c82a302019-11-29 14:23:45 -0800349 mPrepareDataLoaders.set_value_at_thread_exit();
350 }).detach();
351 return mPrepareDataLoaders.get_future();
352}
353
354auto IncrementalService::getStorageSlotLocked() -> MountMap::iterator {
355 for (;;) {
356 if (mNextId == kMaxStorageId) {
357 mNextId = 0;
358 }
359 auto id = ++mNextId;
360 auto [it, inserted] = mMounts.try_emplace(id, nullptr);
361 if (inserted) {
362 return it;
363 }
364 }
365}
366
Songchun Fan1124fd32020-02-10 12:49:41 -0800367StorageId IncrementalService::createStorage(
368 std::string_view mountPoint, DataLoaderParamsParcel&& dataLoaderParams,
369 const DataLoaderStatusListener& dataLoaderStatusListener, CreateOptions options) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800370 LOG(INFO) << "createStorage: " << mountPoint << " | " << int(options);
371 if (!path::isAbsolute(mountPoint)) {
372 LOG(ERROR) << "path is not absolute: " << mountPoint;
373 return kInvalidStorageId;
374 }
375
376 auto mountNorm = path::normalize(mountPoint);
377 {
378 const auto id = findStorageId(mountNorm);
379 if (id != kInvalidStorageId) {
380 if (options & CreateOptions::OpenExisting) {
381 LOG(INFO) << "Opened existing storage " << id;
382 return id;
383 }
384 LOG(ERROR) << "Directory " << mountPoint << " is already mounted at storage " << id;
385 return kInvalidStorageId;
386 }
387 }
388
389 if (!(options & CreateOptions::CreateNew)) {
390 LOG(ERROR) << "not requirested create new storage, and it doesn't exist: " << mountPoint;
391 return kInvalidStorageId;
392 }
393
394 if (!path::isEmptyDir(mountNorm)) {
395 LOG(ERROR) << "Mounting over existing non-empty directory is not supported: " << mountNorm;
396 return kInvalidStorageId;
397 }
398 auto [mountKey, mountRoot] = makeMountDir(mIncrementalDir, mountNorm);
399 if (mountRoot.empty()) {
400 LOG(ERROR) << "Bad mount point";
401 return kInvalidStorageId;
402 }
403 // Make sure the code removes all crap it may create while still failing.
404 auto firstCleanup = [](const std::string* ptr) { IncFsMount::cleanupFilesystem(*ptr); };
405 auto firstCleanupOnFailure =
406 std::unique_ptr<std::string, decltype(firstCleanup)>(&mountRoot, firstCleanup);
407
408 auto mountTarget = path::join(mountRoot, constants().mount);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800409 const auto backing = path::join(mountRoot, constants().backing);
410 if (!mkdirOrLog(backing, 0777) || !mkdirOrLog(mountTarget)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800411 return kInvalidStorageId;
412 }
413
Songchun Fan3c82a302019-11-29 14:23:45 -0800414 IncFsMount::Control control;
415 {
416 std::lock_guard l(mMountOperationLock);
417 IncrementalFileSystemControlParcel controlParcel;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800418
419 if (auto err = rmDirContent(backing.c_str())) {
420 LOG(ERROR) << "Coudn't clean the backing directory " << backing << ": " << err;
421 return kInvalidStorageId;
422 }
423 if (!mkdirOrLog(path::join(backing, ".index"), 0777)) {
424 return kInvalidStorageId;
425 }
426 auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel);
Songchun Fan3c82a302019-11-29 14:23:45 -0800427 if (!status.isOk()) {
428 LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
429 return kInvalidStorageId;
430 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800431 if (controlParcel.cmd.get() < 0 || controlParcel.pendingReads.get() < 0 ||
432 controlParcel.log.get() < 0) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800433 LOG(ERROR) << "Vold::mountIncFs() returned invalid control parcel.";
434 return kInvalidStorageId;
435 }
Songchun Fan20d6ef22020-03-03 09:47:15 -0800436 int cmd = controlParcel.cmd.release().release();
437 int pendingReads = controlParcel.pendingReads.release().release();
438 int logs = controlParcel.log.release().release();
439 control = mIncFs->createControl(cmd, pendingReads, logs);
Songchun Fan3c82a302019-11-29 14:23:45 -0800440 }
441
442 std::unique_lock l(mLock);
443 const auto mountIt = getStorageSlotLocked();
444 const auto mountId = mountIt->first;
445 l.unlock();
446
447 auto ifs =
448 std::make_shared<IncFsMount>(std::move(mountRoot), mountId, std::move(control), *this);
449 // Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need
450 // is the removal of the |ifs|.
451 firstCleanupOnFailure.release();
452
453 auto secondCleanup = [this, &l](auto itPtr) {
454 if (!l.owns_lock()) {
455 l.lock();
456 }
457 mMounts.erase(*itPtr);
458 };
459 auto secondCleanupOnFailure =
460 std::unique_ptr<decltype(mountIt), decltype(secondCleanup)>(&mountIt, secondCleanup);
461
462 const auto storageIt = ifs->makeStorage(ifs->mountId);
463 if (storageIt == ifs->storages.end()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800464 LOG(ERROR) << "Can't create a default storage directory";
Songchun Fan3c82a302019-11-29 14:23:45 -0800465 return kInvalidStorageId;
466 }
467
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700468 ifs->dataLoaderParams = std::move(dataLoaderParams);
469
Songchun Fan3c82a302019-11-29 14:23:45 -0800470 {
471 metadata::Mount m;
472 m.mutable_storage()->set_id(ifs->mountId);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700473 m.mutable_loader()->set_type((int)ifs->dataLoaderParams.type);
474 m.mutable_loader()->set_package_name(ifs->dataLoaderParams.packageName);
475 m.mutable_loader()->set_class_name(ifs->dataLoaderParams.className);
476 m.mutable_loader()->set_arguments(ifs->dataLoaderParams.arguments);
Songchun Fan3c82a302019-11-29 14:23:45 -0800477 const auto metadata = m.SerializeAsString();
478 m.mutable_loader()->release_arguments();
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -0800479 m.mutable_loader()->release_class_name();
Songchun Fan3c82a302019-11-29 14:23:45 -0800480 m.mutable_loader()->release_package_name();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800481 if (auto err =
482 mIncFs->makeFile(ifs->control,
483 path::join(ifs->root, constants().mount,
484 constants().infoMdName),
485 0777, idFromMetadata(metadata),
486 {.metadata = {metadata.data(), (IncFsSize)metadata.size()}})) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800487 LOG(ERROR) << "Saving mount metadata failed: " << -err;
488 return kInvalidStorageId;
489 }
490 }
491
492 const auto bk =
493 (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800494 if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name,
495 std::string(storageIt->second.name), std::move(mountNorm), bk, l);
Songchun Fan3c82a302019-11-29 14:23:45 -0800496 err < 0) {
497 LOG(ERROR) << "adding bind mount failed: " << -err;
498 return kInvalidStorageId;
499 }
500
501 // Done here as well, all data structures are in good state.
502 secondCleanupOnFailure.release();
503
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700504 if (!prepareDataLoader(*ifs, &dataLoaderStatusListener)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800505 LOG(ERROR) << "prepareDataLoader() failed";
506 deleteStorageLocked(*ifs, std::move(l));
507 return kInvalidStorageId;
508 }
509
510 mountIt->second = std::move(ifs);
511 l.unlock();
512 LOG(INFO) << "created storage " << mountId;
513 return mountId;
514}
515
516StorageId IncrementalService::createLinkedStorage(std::string_view mountPoint,
517 StorageId linkedStorage,
518 IncrementalService::CreateOptions options) {
519 if (!isValidMountTarget(mountPoint)) {
520 LOG(ERROR) << "Mount point is invalid or missing";
521 return kInvalidStorageId;
522 }
523
524 std::unique_lock l(mLock);
525 const auto& ifs = getIfsLocked(linkedStorage);
526 if (!ifs) {
527 LOG(ERROR) << "Ifs unavailable";
528 return kInvalidStorageId;
529 }
530
531 const auto mountIt = getStorageSlotLocked();
532 const auto storageId = mountIt->first;
533 const auto storageIt = ifs->makeStorage(storageId);
534 if (storageIt == ifs->storages.end()) {
535 LOG(ERROR) << "Can't create a new storage";
536 mMounts.erase(mountIt);
537 return kInvalidStorageId;
538 }
539
540 l.unlock();
541
542 const auto bk =
543 (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800544 if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name,
545 std::string(storageIt->second.name), path::normalize(mountPoint),
546 bk, l);
Songchun Fan3c82a302019-11-29 14:23:45 -0800547 err < 0) {
548 LOG(ERROR) << "bindMount failed with error: " << err;
549 return kInvalidStorageId;
550 }
551
552 mountIt->second = ifs;
553 return storageId;
554}
555
556IncrementalService::BindPathMap::const_iterator IncrementalService::findStorageLocked(
557 std::string_view path) const {
558 auto bindPointIt = mBindsByPath.upper_bound(path);
559 if (bindPointIt == mBindsByPath.begin()) {
560 return mBindsByPath.end();
561 }
562 --bindPointIt;
563 if (!path::startsWith(path, bindPointIt->first)) {
564 return mBindsByPath.end();
565 }
566 return bindPointIt;
567}
568
569StorageId IncrementalService::findStorageId(std::string_view path) const {
570 std::lock_guard l(mLock);
571 auto it = findStorageLocked(path);
572 if (it == mBindsByPath.end()) {
573 return kInvalidStorageId;
574 }
575 return it->second->second.storage;
576}
577
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700578int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLogs) {
579 const auto ifs = getIfs(storageId);
580 if (!ifs) {
581 return -EINVAL;
582 }
583
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700584 if (enableReadLogs) {
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700585 if (auto status =
586 mAppOpsManager->checkPermission(kDataUsageStats, kOpUsage,
587 ifs->dataLoaderParams.packageName.c_str());
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700588 !status.isOk()) {
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700589 LOG(ERROR) << "checkPermission failed: " << status.toString8();
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700590 return fromBinderStatus(status);
591 }
592 }
593
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700594 if (auto status = applyStorageParams(*ifs, enableReadLogs); !status.isOk()) {
595 LOG(ERROR) << "applyStorageParams failed: " << status.toString8();
596 return fromBinderStatus(status);
597 }
598
599 if (enableReadLogs) {
600 registerAppOpsCallback(ifs->dataLoaderParams.packageName);
601 }
602
603 return 0;
604}
605
606binder::Status IncrementalService::applyStorageParams(IncFsMount& ifs, bool enableReadLogs) {
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700607 using unique_fd = ::android::base::unique_fd;
608 ::android::os::incremental::IncrementalFileSystemControlParcel control;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700609 control.cmd.reset(unique_fd(dup(ifs.control.cmd())));
610 control.pendingReads.reset(unique_fd(dup(ifs.control.pendingReads())));
611 auto logsFd = ifs.control.logs();
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700612 if (logsFd >= 0) {
613 control.log.reset(unique_fd(dup(logsFd)));
614 }
615
616 std::lock_guard l(mMountOperationLock);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700617 return mVold->setIncFsMountOptions(control, enableReadLogs);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700618}
619
Songchun Fan3c82a302019-11-29 14:23:45 -0800620void IncrementalService::deleteStorage(StorageId storageId) {
621 const auto ifs = getIfs(storageId);
622 if (!ifs) {
623 return;
624 }
625 deleteStorage(*ifs);
626}
627
628void IncrementalService::deleteStorage(IncrementalService::IncFsMount& ifs) {
629 std::unique_lock l(ifs.lock);
630 deleteStorageLocked(ifs, std::move(l));
631}
632
633void IncrementalService::deleteStorageLocked(IncrementalService::IncFsMount& ifs,
634 std::unique_lock<std::mutex>&& ifsLock) {
635 const auto storages = std::move(ifs.storages);
636 // Don't move the bind points out: Ifs's dtor will use them to unmount everything.
637 const auto bindPoints = ifs.bindPoints;
638 ifsLock.unlock();
639
640 std::lock_guard l(mLock);
641 for (auto&& [id, _] : storages) {
642 if (id != ifs.mountId) {
643 mMounts.erase(id);
644 }
645 }
646 for (auto&& [path, _] : bindPoints) {
647 mBindsByPath.erase(path);
648 }
649 mMounts.erase(ifs.mountId);
650}
651
652StorageId IncrementalService::openStorage(std::string_view pathInMount) {
653 if (!path::isAbsolute(pathInMount)) {
654 return kInvalidStorageId;
655 }
656
657 return findStorageId(path::normalize(pathInMount));
658}
659
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800660FileId IncrementalService::nodeFor(StorageId storage, std::string_view subpath) const {
Songchun Fan3c82a302019-11-29 14:23:45 -0800661 const auto ifs = getIfs(storage);
662 if (!ifs) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800663 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800664 }
665 std::unique_lock l(ifs->lock);
666 auto storageIt = ifs->storages.find(storage);
667 if (storageIt == ifs->storages.end()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800668 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800669 }
670 if (subpath.empty() || subpath == "."sv) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800671 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800672 }
673 auto path = path::join(ifs->root, constants().mount, storageIt->second.name, subpath);
674 l.unlock();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800675 return mIncFs->getFileId(ifs->control, path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800676}
677
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800678std::pair<FileId, std::string_view> IncrementalService::parentAndNameFor(
Songchun Fan3c82a302019-11-29 14:23:45 -0800679 StorageId storage, std::string_view subpath) const {
680 auto name = path::basename(subpath);
681 if (name.empty()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800682 return {kIncFsInvalidFileId, {}};
Songchun Fan3c82a302019-11-29 14:23:45 -0800683 }
684 auto dir = path::dirname(subpath);
685 if (dir.empty() || dir == "/"sv) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800686 return {kIncFsInvalidFileId, {}};
Songchun Fan3c82a302019-11-29 14:23:45 -0800687 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800688 auto id = nodeFor(storage, dir);
689 return {id, name};
Songchun Fan3c82a302019-11-29 14:23:45 -0800690}
691
692IncrementalService::IfsMountPtr IncrementalService::getIfs(StorageId storage) const {
693 std::lock_guard l(mLock);
694 return getIfsLocked(storage);
695}
696
697const IncrementalService::IfsMountPtr& IncrementalService::getIfsLocked(StorageId storage) const {
698 auto it = mMounts.find(storage);
699 if (it == mMounts.end()) {
700 static const IfsMountPtr kEmpty = {};
701 return kEmpty;
702 }
703 return it->second;
704}
705
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800706int IncrementalService::bind(StorageId storage, std::string_view source, std::string_view target,
707 BindKind kind) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800708 if (!isValidMountTarget(target)) {
709 return -EINVAL;
710 }
711
712 const auto ifs = getIfs(storage);
713 if (!ifs) {
714 return -EINVAL;
715 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800716
Songchun Fan3c82a302019-11-29 14:23:45 -0800717 std::unique_lock l(ifs->lock);
718 const auto storageInfo = ifs->storages.find(storage);
719 if (storageInfo == ifs->storages.end()) {
720 return -EINVAL;
721 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800722 std::string normSource = normalizePathToStorage(ifs, storage, source);
Songchun Fan3c82a302019-11-29 14:23:45 -0800723 l.unlock();
724 std::unique_lock l2(mLock, std::defer_lock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800725 return addBindMount(*ifs, storage, storageInfo->second.name, std::move(normSource),
726 path::normalize(target), kind, l2);
Songchun Fan3c82a302019-11-29 14:23:45 -0800727}
728
729int IncrementalService::unbind(StorageId storage, std::string_view target) {
730 if (!path::isAbsolute(target)) {
731 return -EINVAL;
732 }
733
734 LOG(INFO) << "Removing bind point " << target;
735
736 // Here we should only look up by the exact target, not by a subdirectory of any existing mount,
737 // otherwise there's a chance to unmount something completely unrelated
738 const auto norm = path::normalize(target);
739 std::unique_lock l(mLock);
740 const auto storageIt = mBindsByPath.find(norm);
741 if (storageIt == mBindsByPath.end() || storageIt->second->second.storage != storage) {
742 return -EINVAL;
743 }
744 const auto bindIt = storageIt->second;
745 const auto storageId = bindIt->second.storage;
746 const auto ifs = getIfsLocked(storageId);
747 if (!ifs) {
748 LOG(ERROR) << "Internal error: storageId " << storageId << " for bound path " << target
749 << " is missing";
750 return -EFAULT;
751 }
752 mBindsByPath.erase(storageIt);
753 l.unlock();
754
755 mVold->unmountIncFs(bindIt->first);
756 std::unique_lock l2(ifs->lock);
757 if (ifs->bindPoints.size() <= 1) {
758 ifs->bindPoints.clear();
759 deleteStorageLocked(*ifs, std::move(l2));
760 } else {
761 const std::string savedFile = std::move(bindIt->second.savedFilename);
762 ifs->bindPoints.erase(bindIt);
763 l2.unlock();
764 if (!savedFile.empty()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800765 mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, savedFile));
Songchun Fan3c82a302019-11-29 14:23:45 -0800766 }
767 }
768 return 0;
769}
770
Songchun Fan103ba1d2020-02-03 17:32:32 -0800771std::string IncrementalService::normalizePathToStorage(const IncrementalService::IfsMountPtr ifs,
772 StorageId storage, std::string_view path) {
773 const auto storageInfo = ifs->storages.find(storage);
774 if (storageInfo == ifs->storages.end()) {
775 return {};
776 }
777 std::string normPath;
778 if (path::isAbsolute(path)) {
779 normPath = path::normalize(path);
780 } else {
781 normPath = path::normalize(path::join(storageInfo->second.name, path));
782 }
783 if (!path::startsWith(normPath, storageInfo->second.name)) {
784 return {};
785 }
786 return normPath;
787}
788
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800789int IncrementalService::makeFile(StorageId storage, std::string_view path, int mode, FileId id,
790 incfs::NewFileParams params) {
791 if (auto ifs = getIfs(storage)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800792 std::string normPath = normalizePathToStorage(ifs, storage, path);
793 if (normPath.empty()) {
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700794 LOG(ERROR) << "Internal error: storageId " << storage << " failed to normalize: " << path;
Songchun Fan54c6aed2020-01-31 16:52:41 -0800795 return -EINVAL;
796 }
797 auto err = mIncFs->makeFile(ifs->control, normPath, mode, id, params);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800798 if (err) {
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700799 LOG(ERROR) << "Internal error: storageId " << storage << " failed to makeFile: " << err;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800800 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800801 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800802 std::vector<uint8_t> metadataBytes;
803 if (params.metadata.data && params.metadata.size > 0) {
804 metadataBytes.assign(params.metadata.data, params.metadata.data + params.metadata.size);
Songchun Fan3c82a302019-11-29 14:23:45 -0800805 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800806 return 0;
Songchun Fan3c82a302019-11-29 14:23:45 -0800807 }
808 return -EINVAL;
809}
810
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800811int IncrementalService::makeDir(StorageId storageId, std::string_view path, int mode) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800812 if (auto ifs = getIfs(storageId)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800813 std::string normPath = normalizePathToStorage(ifs, storageId, path);
814 if (normPath.empty()) {
815 return -EINVAL;
816 }
817 return mIncFs->makeDir(ifs->control, normPath, mode);
Songchun Fan3c82a302019-11-29 14:23:45 -0800818 }
819 return -EINVAL;
820}
821
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800822int IncrementalService::makeDirs(StorageId storageId, std::string_view path, int mode) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800823 const auto ifs = getIfs(storageId);
824 if (!ifs) {
825 return -EINVAL;
826 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800827 std::string normPath = normalizePathToStorage(ifs, storageId, path);
828 if (normPath.empty()) {
829 return -EINVAL;
830 }
831 auto err = mIncFs->makeDir(ifs->control, normPath, mode);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800832 if (err == -EEXIST) {
833 return 0;
834 } else if (err != -ENOENT) {
835 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800836 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800837 if (auto err = makeDirs(storageId, path::dirname(normPath), mode)) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800838 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800839 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800840 return mIncFs->makeDir(ifs->control, normPath, mode);
Songchun Fan3c82a302019-11-29 14:23:45 -0800841}
842
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800843int IncrementalService::link(StorageId sourceStorageId, std::string_view oldPath,
844 StorageId destStorageId, std::string_view newPath) {
845 if (auto ifsSrc = getIfs(sourceStorageId), ifsDest = getIfs(destStorageId);
846 ifsSrc && ifsSrc == ifsDest) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800847 std::string normOldPath = normalizePathToStorage(ifsSrc, sourceStorageId, oldPath);
848 std::string normNewPath = normalizePathToStorage(ifsDest, destStorageId, newPath);
849 if (normOldPath.empty() || normNewPath.empty()) {
850 return -EINVAL;
851 }
852 return mIncFs->link(ifsSrc->control, normOldPath, normNewPath);
Songchun Fan3c82a302019-11-29 14:23:45 -0800853 }
854 return -EINVAL;
855}
856
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800857int IncrementalService::unlink(StorageId storage, std::string_view path) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800858 if (auto ifs = getIfs(storage)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800859 std::string normOldPath = normalizePathToStorage(ifs, storage, path);
860 return mIncFs->unlink(ifs->control, normOldPath);
Songchun Fan3c82a302019-11-29 14:23:45 -0800861 }
862 return -EINVAL;
863}
864
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800865int IncrementalService::addBindMount(IncFsMount& ifs, StorageId storage,
866 std::string_view storageRoot, std::string&& source,
Songchun Fan3c82a302019-11-29 14:23:45 -0800867 std::string&& target, BindKind kind,
868 std::unique_lock<std::mutex>& mainLock) {
869 if (!isValidMountTarget(target)) {
870 return -EINVAL;
871 }
872
873 std::string mdFileName;
874 if (kind != BindKind::Temporary) {
875 metadata::BindPoint bp;
876 bp.set_storage_id(storage);
877 bp.set_allocated_dest_path(&target);
Songchun Fan1124fd32020-02-10 12:49:41 -0800878 bp.set_allocated_source_subdir(&source);
Songchun Fan3c82a302019-11-29 14:23:45 -0800879 const auto metadata = bp.SerializeAsString();
Songchun Fan3c82a302019-11-29 14:23:45 -0800880 bp.release_dest_path();
Songchun Fan1124fd32020-02-10 12:49:41 -0800881 bp.release_source_subdir();
Songchun Fan3c82a302019-11-29 14:23:45 -0800882 mdFileName = makeBindMdName();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800883 auto node =
884 mIncFs->makeFile(ifs.control, path::join(ifs.root, constants().mount, mdFileName),
885 0444, idFromMetadata(metadata),
886 {.metadata = {metadata.data(), (IncFsSize)metadata.size()}});
887 if (node) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800888 return int(node);
889 }
890 }
891
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800892 return addBindMountWithMd(ifs, storage, std::move(mdFileName), std::move(source),
Songchun Fan3c82a302019-11-29 14:23:45 -0800893 std::move(target), kind, mainLock);
894}
895
896int IncrementalService::addBindMountWithMd(IncrementalService::IncFsMount& ifs, StorageId storage,
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800897 std::string&& metadataName, std::string&& source,
Songchun Fan3c82a302019-11-29 14:23:45 -0800898 std::string&& target, BindKind kind,
899 std::unique_lock<std::mutex>& mainLock) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800900 {
Songchun Fan3c82a302019-11-29 14:23:45 -0800901 std::lock_guard l(mMountOperationLock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800902 const auto status = mVold->bindMount(source, target);
Songchun Fan3c82a302019-11-29 14:23:45 -0800903 if (!status.isOk()) {
904 LOG(ERROR) << "Calling Vold::bindMount() failed: " << status.toString8();
905 return status.exceptionCode() == binder::Status::EX_SERVICE_SPECIFIC
906 ? status.serviceSpecificErrorCode() > 0 ? -status.serviceSpecificErrorCode()
907 : status.serviceSpecificErrorCode() == 0
908 ? -EFAULT
909 : status.serviceSpecificErrorCode()
910 : -EIO;
911 }
912 }
913
914 if (!mainLock.owns_lock()) {
915 mainLock.lock();
916 }
917 std::lock_guard l(ifs.lock);
918 const auto [it, _] =
919 ifs.bindPoints.insert_or_assign(target,
920 IncFsMount::Bind{storage, std::move(metadataName),
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800921 std::move(source), kind});
Songchun Fan3c82a302019-11-29 14:23:45 -0800922 mBindsByPath[std::move(target)] = it;
923 return 0;
924}
925
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800926RawMetadata IncrementalService::getMetadata(StorageId storage, FileId node) const {
Songchun Fan3c82a302019-11-29 14:23:45 -0800927 const auto ifs = getIfs(storage);
928 if (!ifs) {
929 return {};
930 }
931 return mIncFs->getMetadata(ifs->control, node);
932}
933
934std::vector<std::string> IncrementalService::listFiles(StorageId storage) const {
935 const auto ifs = getIfs(storage);
936 if (!ifs) {
937 return {};
938 }
939
940 std::unique_lock l(ifs->lock);
941 auto subdirIt = ifs->storages.find(storage);
942 if (subdirIt == ifs->storages.end()) {
943 return {};
944 }
945 auto dir = path::join(ifs->root, constants().mount, subdirIt->second.name);
946 l.unlock();
947
948 const auto prefixSize = dir.size() + 1;
949 std::vector<std::string> todoDirs{std::move(dir)};
950 std::vector<std::string> result;
951 do {
952 auto currDir = std::move(todoDirs.back());
953 todoDirs.pop_back();
954
955 auto d =
956 std::unique_ptr<DIR, decltype(&::closedir)>(::opendir(currDir.c_str()), ::closedir);
957 while (auto e = ::readdir(d.get())) {
958 if (e->d_type == DT_REG) {
959 result.emplace_back(
960 path::join(std::string_view(currDir).substr(prefixSize), e->d_name));
961 continue;
962 }
963 if (e->d_type == DT_DIR) {
964 if (e->d_name == "."sv || e->d_name == ".."sv) {
965 continue;
966 }
967 todoDirs.emplace_back(path::join(currDir, e->d_name));
968 continue;
969 }
970 }
971 } while (!todoDirs.empty());
972 return result;
973}
974
975bool IncrementalService::startLoading(StorageId storage) const {
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700976 {
977 std::unique_lock l(mLock);
978 const auto& ifs = getIfsLocked(storage);
979 if (!ifs) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800980 return false;
981 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700982 if (ifs->dataLoaderStatus != IDataLoaderStatusListener::DATA_LOADER_CREATED) {
983 ifs->dataLoaderStartRequested = true;
984 return true;
985 }
Songchun Fan3c82a302019-11-29 14:23:45 -0800986 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700987 return startDataLoader(storage);
988}
989
990bool IncrementalService::startDataLoader(MountId mountId) const {
Songchun Fan68645c42020-02-27 15:57:35 -0800991 sp<IDataLoader> dataloader;
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700992 auto status = mDataLoaderManager->getDataLoader(mountId, &dataloader);
Songchun Fan3c82a302019-11-29 14:23:45 -0800993 if (!status.isOk()) {
994 return false;
995 }
Songchun Fan68645c42020-02-27 15:57:35 -0800996 if (!dataloader) {
997 return false;
998 }
Alex Buynytskyyb6e02f72020-03-17 18:12:23 -0700999 status = dataloader->start(mountId);
Songchun Fan68645c42020-02-27 15:57:35 -08001000 if (!status.isOk()) {
1001 return false;
1002 }
1003 return true;
Songchun Fan3c82a302019-11-29 14:23:45 -08001004}
1005
1006void IncrementalService::mountExistingImages() {
Songchun Fan1124fd32020-02-10 12:49:41 -08001007 for (const auto& entry : fs::directory_iterator(mIncrementalDir)) {
1008 const auto path = entry.path().u8string();
1009 const auto name = entry.path().filename().u8string();
1010 if (!base::StartsWith(name, constants().mountKeyPrefix)) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001011 continue;
1012 }
Songchun Fan1124fd32020-02-10 12:49:41 -08001013 const auto root = path::join(mIncrementalDir, name);
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001014 if (!mountExistingImage(root)) {
Songchun Fan1124fd32020-02-10 12:49:41 -08001015 IncFsMount::cleanupFilesystem(path);
Songchun Fan3c82a302019-11-29 14:23:45 -08001016 }
1017 }
1018}
1019
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001020bool IncrementalService::mountExistingImage(std::string_view root) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001021 auto mountTarget = path::join(root, constants().mount);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001022 const auto backing = path::join(root, constants().backing);
Songchun Fan3c82a302019-11-29 14:23:45 -08001023
Songchun Fan3c82a302019-11-29 14:23:45 -08001024 IncrementalFileSystemControlParcel controlParcel;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001025 auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel);
Songchun Fan3c82a302019-11-29 14:23:45 -08001026 if (!status.isOk()) {
1027 LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
1028 return false;
1029 }
Songchun Fan20d6ef22020-03-03 09:47:15 -08001030
1031 int cmd = controlParcel.cmd.release().release();
1032 int pendingReads = controlParcel.pendingReads.release().release();
1033 int logs = controlParcel.log.release().release();
1034 IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs);
Songchun Fan3c82a302019-11-29 14:23:45 -08001035
1036 auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this);
1037
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001038 auto mount = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control,
1039 path::join(mountTarget, constants().infoMdName));
1040 if (!mount.has_loader() || !mount.has_storage()) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001041 LOG(ERROR) << "Bad mount metadata in mount at " << root;
1042 return false;
1043 }
1044
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001045 ifs->mountId = mount.storage().id();
Songchun Fan3c82a302019-11-29 14:23:45 -08001046 mNextId = std::max(mNextId, ifs->mountId + 1);
1047
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001048 // DataLoader params
1049 {
1050 auto& dlp = ifs->dataLoaderParams;
1051 const auto& loader = mount.loader();
1052 dlp.type = (android::content::pm::DataLoaderType)loader.type();
1053 dlp.packageName = loader.package_name();
1054 dlp.className = loader.class_name();
1055 dlp.arguments = loader.arguments();
1056 }
1057
Songchun Fan3c82a302019-11-29 14:23:45 -08001058 std::vector<std::pair<std::string, metadata::BindPoint>> bindPoints;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001059 auto d = openDir(path::c_str(mountTarget));
Songchun Fan3c82a302019-11-29 14:23:45 -08001060 while (auto e = ::readdir(d.get())) {
1061 if (e->d_type == DT_REG) {
1062 auto name = std::string_view(e->d_name);
1063 if (name.starts_with(constants().mountpointMdPrefix)) {
1064 bindPoints.emplace_back(name,
1065 parseFromIncfs<metadata::BindPoint>(mIncFs.get(),
1066 ifs->control,
1067 path::join(mountTarget,
1068 name)));
1069 if (bindPoints.back().second.dest_path().empty() ||
1070 bindPoints.back().second.source_subdir().empty()) {
1071 bindPoints.pop_back();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001072 mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, name));
Songchun Fan3c82a302019-11-29 14:23:45 -08001073 }
1074 }
1075 } else if (e->d_type == DT_DIR) {
1076 if (e->d_name == "."sv || e->d_name == ".."sv) {
1077 continue;
1078 }
1079 auto name = std::string_view(e->d_name);
1080 if (name.starts_with(constants().storagePrefix)) {
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001081 int storageId;
1082 const auto res = std::from_chars(name.data() + constants().storagePrefix.size() + 1,
1083 name.data() + name.size(), storageId);
1084 if (res.ec != std::errc{} || *res.ptr != '_') {
1085 LOG(WARNING) << "Ignoring storage with invalid name '" << name << "' for mount "
1086 << root;
1087 continue;
1088 }
1089 auto [_, inserted] = mMounts.try_emplace(storageId, ifs);
Songchun Fan3c82a302019-11-29 14:23:45 -08001090 if (!inserted) {
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001091 LOG(WARNING) << "Ignoring storage with duplicate id " << storageId
Songchun Fan3c82a302019-11-29 14:23:45 -08001092 << " for mount " << root;
1093 continue;
1094 }
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001095 ifs->storages.insert_or_assign(storageId,
1096 IncFsMount::Storage{
1097 path::join(root, constants().mount, name)});
1098 mNextId = std::max(mNextId, storageId + 1);
Songchun Fan3c82a302019-11-29 14:23:45 -08001099 }
1100 }
1101 }
1102
1103 if (ifs->storages.empty()) {
1104 LOG(WARNING) << "No valid storages in mount " << root;
1105 return false;
1106 }
1107
1108 int bindCount = 0;
1109 for (auto&& bp : bindPoints) {
1110 std::unique_lock l(mLock, std::defer_lock);
1111 bindCount += !addBindMountWithMd(*ifs, bp.second.storage_id(), std::move(bp.first),
1112 std::move(*bp.second.mutable_source_subdir()),
1113 std::move(*bp.second.mutable_dest_path()),
1114 BindKind::Permanent, l);
1115 }
1116
1117 if (bindCount == 0) {
1118 LOG(WARNING) << "No valid bind points for mount " << root;
1119 deleteStorage(*ifs);
1120 return false;
1121 }
1122
Songchun Fan3c82a302019-11-29 14:23:45 -08001123 mMounts[ifs->mountId] = std::move(ifs);
1124 return true;
1125}
1126
1127bool IncrementalService::prepareDataLoader(IncrementalService::IncFsMount& ifs,
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001128 const DataLoaderStatusListener* externalListener) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001129 if (!mSystemReady.load(std::memory_order_relaxed)) {
1130 std::unique_lock l(ifs.lock);
Songchun Fan3c82a302019-11-29 14:23:45 -08001131 return true; // eventually...
1132 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001133
1134 std::unique_lock l(ifs.lock);
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001135 if (ifs.dataLoaderStatus != -1) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001136 LOG(INFO) << "Skipped data loader preparation because it already exists";
1137 return true;
1138 }
1139
Songchun Fan3c82a302019-11-29 14:23:45 -08001140 FileSystemControlParcel fsControlParcel;
Jooyung Han66c567a2020-03-07 21:47:09 +09001141 fsControlParcel.incremental = aidl::make_nullable<IncrementalFileSystemControlParcel>();
Songchun Fan20d6ef22020-03-03 09:47:15 -08001142 fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd())));
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001143 fsControlParcel.incremental->pendingReads.reset(
Songchun Fan20d6ef22020-03-03 09:47:15 -08001144 base::unique_fd(::dup(ifs.control.pendingReads())));
1145 fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs())));
Alex Buynytskyyf4156792020-04-07 14:26:55 -07001146 fsControlParcel.service = new IncrementalServiceConnector(*this, ifs.mountId);
Songchun Fan1124fd32020-02-10 12:49:41 -08001147 sp<IncrementalDataLoaderListener> listener =
Songchun Fan306b7df2020-03-17 12:37:07 -07001148 new IncrementalDataLoaderListener(*this,
1149 externalListener ? *externalListener
1150 : DataLoaderStatusListener());
Songchun Fan3c82a302019-11-29 14:23:45 -08001151 bool created = false;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001152 auto status = mDataLoaderManager->initializeDataLoader(ifs.mountId, ifs.dataLoaderParams, fsControlParcel, listener, &created);
Songchun Fan3c82a302019-11-29 14:23:45 -08001153 if (!status.isOk() || !created) {
1154 LOG(ERROR) << "Failed to create a data loader for mount " << ifs.mountId;
1155 return false;
1156 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001157 return true;
1158}
1159
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001160// Extract lib filse from zip, create new files in incfs and write data to them
1161bool IncrementalService::configureNativeBinaries(StorageId storage, std::string_view apkFullPath,
1162 std::string_view libDirRelativePath,
1163 std::string_view abi) {
1164 const auto ifs = getIfs(storage);
1165 // First prepare target directories if they don't exist yet
1166 if (auto res = makeDirs(storage, libDirRelativePath, 0755)) {
1167 LOG(ERROR) << "Failed to prepare target lib directory " << libDirRelativePath
1168 << " errno: " << res;
1169 return false;
1170 }
1171
1172 std::unique_ptr<ZipFileRO> zipFile(ZipFileRO::open(apkFullPath.data()));
1173 if (!zipFile) {
1174 LOG(ERROR) << "Failed to open zip file at " << apkFullPath;
1175 return false;
1176 }
1177 void* cookie = nullptr;
1178 const auto libFilePrefix = path::join(constants().libDir, abi);
1179 if (!zipFile.get()->startIteration(&cookie, libFilePrefix.c_str() /* prefix */,
1180 constants().libSuffix.data() /* suffix */)) {
1181 LOG(ERROR) << "Failed to start zip iteration for " << apkFullPath;
1182 return false;
1183 }
1184 ZipEntryRO entry = nullptr;
1185 bool success = true;
1186 while ((entry = zipFile.get()->nextEntry(cookie)) != nullptr) {
1187 char fileName[PATH_MAX];
1188 if (zipFile.get()->getEntryFileName(entry, fileName, sizeof(fileName))) {
1189 continue;
1190 }
1191 const auto libName = path::basename(fileName);
1192 const auto targetLibPath = path::join(libDirRelativePath, libName);
1193 const auto targetLibPathAbsolute = normalizePathToStorage(ifs, storage, targetLibPath);
1194 // If the extract file already exists, skip
1195 struct stat st;
1196 if (stat(targetLibPathAbsolute.c_str(), &st) == 0) {
1197 LOG(INFO) << "Native lib file already exists: " << targetLibPath
1198 << "; skipping extraction";
1199 continue;
1200 }
1201
1202 uint32_t uncompressedLen;
1203 if (!zipFile.get()->getEntryInfo(entry, nullptr, &uncompressedLen, nullptr, nullptr,
1204 nullptr, nullptr)) {
1205 LOG(ERROR) << "Failed to read native lib entry: " << fileName;
1206 success = false;
1207 break;
1208 }
1209
1210 // Create new lib file without signature info
George Burgess IVdd5275d2020-02-10 11:18:07 -08001211 incfs::NewFileParams libFileParams{};
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001212 libFileParams.size = uncompressedLen;
Alex Buynytskyyf5e605a2020-03-13 13:31:12 -07001213 libFileParams.signature = {};
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001214 // Metadata of the new lib file is its relative path
1215 IncFsSpan libFileMetadata;
1216 libFileMetadata.data = targetLibPath.c_str();
1217 libFileMetadata.size = targetLibPath.size();
1218 libFileParams.metadata = libFileMetadata;
1219 incfs::FileId libFileId = idFromMetadata(targetLibPath);
1220 if (auto res = makeFile(storage, targetLibPath, 0777, libFileId, libFileParams)) {
1221 LOG(ERROR) << "Failed to make file for: " << targetLibPath << " errno: " << res;
1222 success = false;
1223 // If one lib file fails to be created, abort others as well
1224 break;
1225 }
Songchun Fanafaf6e92020-03-18 14:12:20 -07001226 // If it is a zero-byte file, skip data writing
1227 if (uncompressedLen == 0) {
1228 continue;
1229 }
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001230
1231 // Write extracted data to new file
1232 std::vector<uint8_t> libData(uncompressedLen);
1233 if (!zipFile.get()->uncompressEntry(entry, &libData[0], uncompressedLen)) {
1234 LOG(ERROR) << "Failed to extract native lib zip entry: " << fileName;
1235 success = false;
1236 break;
1237 }
Yurii Zubrytskyie82cdd72020-04-01 12:19:26 -07001238 const auto writeFd = mIncFs->openForSpecialOps(ifs->control, libFileId);
1239 if (!writeFd.ok()) {
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001240 LOG(ERROR) << "Failed to open write fd for: " << targetLibPath << " errno: " << writeFd;
1241 success = false;
1242 break;
1243 }
1244 const int numBlocks = uncompressedLen / constants().blockSize + 1;
1245 std::vector<IncFsDataBlock> instructions;
1246 auto remainingData = std::span(libData);
1247 for (int i = 0; i < numBlocks - 1; i++) {
1248 auto inst = IncFsDataBlock{
1249 .fileFd = writeFd,
1250 .pageIndex = static_cast<IncFsBlockIndex>(i),
1251 .compression = INCFS_COMPRESSION_KIND_NONE,
1252 .kind = INCFS_BLOCK_KIND_DATA,
1253 .dataSize = static_cast<uint16_t>(constants().blockSize),
1254 .data = reinterpret_cast<const char*>(remainingData.data()),
1255 };
1256 instructions.push_back(inst);
1257 remainingData = remainingData.subspan(constants().blockSize);
1258 }
1259 // Last block
1260 auto inst = IncFsDataBlock{
1261 .fileFd = writeFd,
1262 .pageIndex = static_cast<IncFsBlockIndex>(numBlocks - 1),
1263 .compression = INCFS_COMPRESSION_KIND_NONE,
1264 .kind = INCFS_BLOCK_KIND_DATA,
1265 .dataSize = static_cast<uint16_t>(remainingData.size()),
1266 .data = reinterpret_cast<const char*>(remainingData.data()),
1267 };
1268 instructions.push_back(inst);
1269 size_t res = mIncFs->writeBlocks(instructions);
1270 if (res != instructions.size()) {
1271 LOG(ERROR) << "Failed to write data into: " << targetLibPath;
1272 success = false;
1273 }
1274 instructions.clear();
1275 }
1276 zipFile.get()->endIteration(cookie);
1277 return success;
1278}
1279
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001280void IncrementalService::registerAppOpsCallback(const std::string& packageName) {
Alex Buynytskyy1d892162020-04-03 23:00:19 -07001281 sp<IAppOpsCallback> listener;
1282 {
1283 std::unique_lock lock{mCallbacksLock};
1284 auto& cb = mCallbackRegistered[packageName];
1285 if (cb) {
1286 return;
1287 }
1288 cb = new AppOpsListener(*this, packageName);
1289 listener = cb;
1290 }
1291
1292 mAppOpsManager->startWatchingMode(AppOpsManager::OP_GET_USAGE_STATS, String16(packageName.c_str()), listener);
1293}
1294
1295bool IncrementalService::unregisterAppOpsCallback(const std::string& packageName) {
1296 sp<IAppOpsCallback> listener;
1297 {
1298 std::unique_lock lock{mCallbacksLock};
1299 auto found = mCallbackRegistered.find(packageName);
1300 if (found == mCallbackRegistered.end()) {
1301 return false;
1302 }
1303 listener = found->second;
1304 mCallbackRegistered.erase(found);
1305 }
1306
1307 mAppOpsManager->stopWatchingMode(listener);
1308 return true;
1309}
1310
1311void IncrementalService::onAppOpChanged(const std::string& packageName) {
1312 if (!unregisterAppOpsCallback(packageName)) {
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001313 return;
1314 }
1315
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001316 std::vector<IfsMountPtr> affected;
1317 {
1318 std::lock_guard l(mLock);
1319 affected.reserve(mMounts.size());
1320 for (auto&& [id, ifs] : mMounts) {
Alex Buynytskyy1d892162020-04-03 23:00:19 -07001321 if (ifs->mountId == id && ifs->dataLoaderParams.packageName == packageName) {
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001322 affected.push_back(ifs);
1323 }
1324 }
1325 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001326 for (auto&& ifs : affected) {
Alex Buynytskyy1d892162020-04-03 23:00:19 -07001327 applyStorageParams(*ifs, false);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001328 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001329}
1330
Songchun Fan3c82a302019-11-29 14:23:45 -08001331binder::Status IncrementalService::IncrementalDataLoaderListener::onStatusChanged(MountId mountId,
1332 int newStatus) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001333 if (externalListener) {
1334 // Give an external listener a chance to act before we destroy something.
1335 externalListener->onStatusChanged(mountId, newStatus);
1336 }
1337
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001338 bool startRequested = false;
1339 {
1340 std::unique_lock l(incrementalService.mLock);
1341 const auto& ifs = incrementalService.getIfsLocked(mountId);
1342 if (!ifs) {
Songchun Fan306b7df2020-03-17 12:37:07 -07001343 LOG(WARNING) << "Received data loader status " << int(newStatus)
1344 << " for unknown mount " << mountId;
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001345 return binder::Status::ok();
1346 }
1347 ifs->dataLoaderStatus = newStatus;
1348
1349 if (newStatus == IDataLoaderStatusListener::DATA_LOADER_DESTROYED) {
1350 ifs->dataLoaderStatus = IDataLoaderStatusListener::DATA_LOADER_STOPPED;
1351 incrementalService.deleteStorageLocked(*ifs, std::move(l));
1352 return binder::Status::ok();
1353 }
1354
1355 startRequested = ifs->dataLoaderStartRequested;
Songchun Fan3c82a302019-11-29 14:23:45 -08001356 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001357
Songchun Fan3c82a302019-11-29 14:23:45 -08001358 switch (newStatus) {
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001359 case IDataLoaderStatusListener::DATA_LOADER_CREATED: {
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001360 if (startRequested) {
1361 incrementalService.startDataLoader(mountId);
1362 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001363 break;
1364 }
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001365 case IDataLoaderStatusListener::DATA_LOADER_DESTROYED: {
Songchun Fan3c82a302019-11-29 14:23:45 -08001366 break;
1367 }
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001368 case IDataLoaderStatusListener::DATA_LOADER_STARTED: {
Songchun Fan3c82a302019-11-29 14:23:45 -08001369 break;
1370 }
1371 case IDataLoaderStatusListener::DATA_LOADER_STOPPED: {
1372 break;
1373 }
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001374 case IDataLoaderStatusListener::DATA_LOADER_IMAGE_READY: {
1375 break;
1376 }
1377 case IDataLoaderStatusListener::DATA_LOADER_IMAGE_NOT_READY: {
1378 break;
1379 }
Alex Buynytskyy2cf1d182020-03-17 09:33:45 -07001380 case IDataLoaderStatusListener::DATA_LOADER_UNRECOVERABLE: {
1381 // Nothing for now. Rely on externalListener to handle this.
1382 break;
1383 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001384 default: {
1385 LOG(WARNING) << "Unknown data loader status: " << newStatus
1386 << " for mount: " << mountId;
1387 break;
1388 }
1389 }
1390
1391 return binder::Status::ok();
1392}
1393
Alex Buynytskyy1d892162020-04-03 23:00:19 -07001394void IncrementalService::AppOpsListener::opChanged(int32_t, const String16&) {
1395 incrementalService.onAppOpChanged(packageName);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001396}
1397
Alex Buynytskyyf4156792020-04-07 14:26:55 -07001398binder::Status IncrementalService::IncrementalServiceConnector::setStorageParams(
1399 bool enableReadLogs, int32_t* _aidl_return) {
1400 *_aidl_return = incrementalService.setStorageParams(storage, enableReadLogs);
1401 return binder::Status::ok();
1402}
1403
Songchun Fan3c82a302019-11-29 14:23:45 -08001404} // namespace android::incremental