blob: 0da167303ccd8b8ad9d6052c9ce5dd8adee7f328 [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"
Alex Buynytskyy96e350b2020-04-02 20:03:47 -070020#include "IncrementalServiceValidation.h"
Songchun Fan3c82a302019-11-29 14:23:45 -080021
22#include <android-base/file.h>
23#include <android-base/logging.h>
24#include <android-base/properties.h>
25#include <android-base/stringprintf.h>
26#include <android-base/strings.h>
27#include <android/content/pm/IDataLoaderStatusListener.h>
28#include <android/os/IVold.h>
29#include <androidfw/ZipFileRO.h>
30#include <androidfw/ZipUtils.h>
31#include <binder/BinderService.h>
Jooyung Han66c567a2020-03-07 21:47:09 +090032#include <binder/Nullable.h>
Songchun Fan3c82a302019-11-29 14:23:45 -080033#include <binder/ParcelFileDescriptor.h>
34#include <binder/Status.h>
35#include <sys/stat.h>
36#include <uuid/uuid.h>
37#include <zlib.h>
38
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -070039#include <charconv>
Alex Buynytskyy18b07a42020-02-03 20:06:00 -080040#include <ctime>
Songchun Fan1124fd32020-02-10 12:49:41 -080041#include <filesystem>
Songchun Fan3c82a302019-11-29 14:23:45 -080042#include <iterator>
43#include <span>
44#include <stack>
45#include <thread>
46#include <type_traits>
47
48#include "Metadata.pb.h"
49
50using namespace std::literals;
51using namespace android::content::pm;
Songchun Fan1124fd32020-02-10 12:49:41 -080052namespace fs = std::filesystem;
Songchun Fan3c82a302019-11-29 14:23:45 -080053
Alex Buynytskyy96e350b2020-04-02 20:03:47 -070054constexpr const char* kDataUsageStats = "android.permission.LOADER_USAGE_STATS";
55constexpr const char* kOpUsage = "android:get_usage_stats";
56
Songchun Fan3c82a302019-11-29 14:23:45 -080057namespace android::incremental {
58
59namespace {
60
61using IncrementalFileSystemControlParcel =
62 ::android::os::incremental::IncrementalFileSystemControlParcel;
63
64struct Constants {
65 static constexpr auto backing = "backing_store"sv;
66 static constexpr auto mount = "mount"sv;
Songchun Fan1124fd32020-02-10 12:49:41 -080067 static constexpr auto mountKeyPrefix = "MT_"sv;
Songchun Fan3c82a302019-11-29 14:23:45 -080068 static constexpr auto storagePrefix = "st"sv;
69 static constexpr auto mountpointMdPrefix = ".mountpoint."sv;
70 static constexpr auto infoMdName = ".info"sv;
Songchun Fan0f8b6fe2020-02-05 17:41:25 -080071 static constexpr auto libDir = "lib"sv;
72 static constexpr auto libSuffix = ".so"sv;
73 static constexpr auto blockSize = 4096;
Songchun Fan3c82a302019-11-29 14:23:45 -080074};
75
76static const Constants& constants() {
77 static Constants c;
78 return c;
79}
80
81template <base::LogSeverity level = base::ERROR>
82bool mkdirOrLog(std::string_view name, int mode = 0770, bool allowExisting = true) {
83 auto cstr = path::c_str(name);
84 if (::mkdir(cstr, mode)) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080085 if (!allowExisting || errno != EEXIST) {
Songchun Fan3c82a302019-11-29 14:23:45 -080086 PLOG(level) << "Can't create directory '" << name << '\'';
87 return false;
88 }
89 struct stat st;
90 if (::stat(cstr, &st) || !S_ISDIR(st.st_mode)) {
91 PLOG(level) << "Path exists but is not a directory: '" << name << '\'';
92 return false;
93 }
94 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080095 if (::chmod(cstr, mode)) {
96 PLOG(level) << "Changing permission failed for '" << name << '\'';
97 return false;
98 }
99
Songchun Fan3c82a302019-11-29 14:23:45 -0800100 return true;
101}
102
103static std::string toMountKey(std::string_view path) {
104 if (path.empty()) {
105 return "@none";
106 }
107 if (path == "/"sv) {
108 return "@root";
109 }
110 if (path::isAbsolute(path)) {
111 path.remove_prefix(1);
112 }
113 std::string res(path);
114 std::replace(res.begin(), res.end(), '/', '_');
115 std::replace(res.begin(), res.end(), '@', '_');
Songchun Fan1124fd32020-02-10 12:49:41 -0800116 return std::string(constants().mountKeyPrefix) + res;
Songchun Fan3c82a302019-11-29 14:23:45 -0800117}
118
119static std::pair<std::string, std::string> makeMountDir(std::string_view incrementalDir,
120 std::string_view path) {
121 auto mountKey = toMountKey(path);
122 const auto prefixSize = mountKey.size();
123 for (int counter = 0; counter < 1000;
124 mountKey.resize(prefixSize), base::StringAppendF(&mountKey, "%d", counter++)) {
125 auto mountRoot = path::join(incrementalDir, mountKey);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800126 if (mkdirOrLog(mountRoot, 0777, false)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800127 return {mountKey, mountRoot};
128 }
129 }
130 return {};
131}
132
133template <class ProtoMessage, class Control>
134static ProtoMessage parseFromIncfs(const IncFsWrapper* incfs, Control&& control,
135 std::string_view path) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800136 auto md = incfs->getMetadata(control, path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800137 ProtoMessage message;
138 return message.ParseFromArray(md.data(), md.size()) ? message : ProtoMessage{};
139}
140
141static bool isValidMountTarget(std::string_view path) {
142 return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true);
143}
144
145std::string makeBindMdName() {
146 static constexpr auto uuidStringSize = 36;
147
148 uuid_t guid;
149 uuid_generate(guid);
150
151 std::string name;
152 const auto prefixSize = constants().mountpointMdPrefix.size();
153 name.reserve(prefixSize + uuidStringSize);
154
155 name = constants().mountpointMdPrefix;
156 name.resize(prefixSize + uuidStringSize);
157 uuid_unparse(guid, name.data() + prefixSize);
158
159 return name;
160}
161} // namespace
162
163IncrementalService::IncFsMount::~IncFsMount() {
Songchun Fan68645c42020-02-27 15:57:35 -0800164 incrementalService.mDataLoaderManager->destroyDataLoader(mountId);
Songchun Fan3c82a302019-11-29 14:23:45 -0800165 LOG(INFO) << "Unmounting and cleaning up mount " << mountId << " with root '" << root << '\'';
166 for (auto&& [target, _] : bindPoints) {
167 LOG(INFO) << "\tbind: " << target;
168 incrementalService.mVold->unmountIncFs(target);
169 }
170 LOG(INFO) << "\troot: " << root;
171 incrementalService.mVold->unmountIncFs(path::join(root, constants().mount));
172 cleanupFilesystem(root);
173}
174
175auto IncrementalService::IncFsMount::makeStorage(StorageId id) -> StorageMap::iterator {
Songchun Fan3c82a302019-11-29 14:23:45 -0800176 std::string name;
177 for (int no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), i = 0;
178 i < 1024 && no >= 0; no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), ++i) {
179 name.clear();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800180 base::StringAppendF(&name, "%.*s_%d_%d", int(constants().storagePrefix.size()),
181 constants().storagePrefix.data(), id, no);
182 auto fullName = path::join(root, constants().mount, name);
Songchun Fan96100932020-02-03 19:20:58 -0800183 if (auto err = incrementalService.mIncFs->makeDir(control, fullName, 0755); !err) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800184 std::lock_guard l(lock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800185 return storages.insert_or_assign(id, Storage{std::move(fullName)}).first;
186 } else if (err != EEXIST) {
187 LOG(ERROR) << __func__ << "(): failed to create dir |" << fullName << "| " << err;
188 break;
Songchun Fan3c82a302019-11-29 14:23:45 -0800189 }
190 }
191 nextStorageDirNo = 0;
192 return storages.end();
193}
194
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800195static std::unique_ptr<DIR, decltype(&::closedir)> openDir(const char* path) {
196 return {::opendir(path), ::closedir};
197}
198
199static int rmDirContent(const char* path) {
200 auto dir = openDir(path);
201 if (!dir) {
202 return -EINVAL;
203 }
204 while (auto entry = ::readdir(dir.get())) {
205 if (entry->d_name == "."sv || entry->d_name == ".."sv) {
206 continue;
207 }
208 auto fullPath = android::base::StringPrintf("%s/%s", path, entry->d_name);
209 if (entry->d_type == DT_DIR) {
210 if (const auto err = rmDirContent(fullPath.c_str()); err != 0) {
211 PLOG(WARNING) << "Failed to delete " << fullPath << " content";
212 return err;
213 }
214 if (const auto err = ::rmdir(fullPath.c_str()); err != 0) {
215 PLOG(WARNING) << "Failed to rmdir " << fullPath;
216 return err;
217 }
218 } else {
219 if (const auto err = ::unlink(fullPath.c_str()); err != 0) {
220 PLOG(WARNING) << "Failed to delete " << fullPath;
221 return err;
222 }
223 }
224 }
225 return 0;
226}
227
Songchun Fan3c82a302019-11-29 14:23:45 -0800228void IncrementalService::IncFsMount::cleanupFilesystem(std::string_view root) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800229 rmDirContent(path::join(root, constants().backing).c_str());
Songchun Fan3c82a302019-11-29 14:23:45 -0800230 ::rmdir(path::join(root, constants().backing).c_str());
231 ::rmdir(path::join(root, constants().mount).c_str());
232 ::rmdir(path::c_str(root));
233}
234
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800235IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir)
Songchun Fan3c82a302019-11-29 14:23:45 -0800236 : mVold(sm.getVoldService()),
Songchun Fan68645c42020-02-27 15:57:35 -0800237 mDataLoaderManager(sm.getDataLoaderManager()),
Songchun Fan3c82a302019-11-29 14:23:45 -0800238 mIncFs(sm.getIncFs()),
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700239 mAppOpsManager(sm.getAppOpsManager()),
Songchun Fan3c82a302019-11-29 14:23:45 -0800240 mIncrementalDir(rootDir) {
241 if (!mVold) {
242 LOG(FATAL) << "Vold service is unavailable";
243 }
Songchun Fan68645c42020-02-27 15:57:35 -0800244 if (!mDataLoaderManager) {
245 LOG(FATAL) << "DataLoaderManagerService is unavailable";
Songchun Fan3c82a302019-11-29 14:23:45 -0800246 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700247 if (!mAppOpsManager) {
248 LOG(FATAL) << "AppOpsManager is unavailable";
249 }
Songchun Fan1124fd32020-02-10 12:49:41 -0800250 mountExistingImages();
Songchun Fan3c82a302019-11-29 14:23:45 -0800251}
252
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800253FileId IncrementalService::idFromMetadata(std::span<const uint8_t> metadata) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800254 return IncFs_FileIdFromMetadata({(const char*)metadata.data(), metadata.size()});
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800255}
256
Songchun Fan3c82a302019-11-29 14:23:45 -0800257IncrementalService::~IncrementalService() = default;
258
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800259inline const char* toString(TimePoint t) {
260 using SystemClock = std::chrono::system_clock;
Songchun Fan0f8b6fe2020-02-05 17:41:25 -0800261 time_t time = SystemClock::to_time_t(
262 SystemClock::now() +
263 std::chrono::duration_cast<SystemClock::duration>(t - Clock::now()));
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800264 return std::ctime(&time);
265}
266
267inline const char* toString(IncrementalService::BindKind kind) {
268 switch (kind) {
Songchun Fan0f8b6fe2020-02-05 17:41:25 -0800269 case IncrementalService::BindKind::Temporary:
270 return "Temporary";
271 case IncrementalService::BindKind::Permanent:
272 return "Permanent";
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800273 }
274}
275
276void IncrementalService::onDump(int fd) {
277 dprintf(fd, "Incremental is %s\n", incfs::enabled() ? "ENABLED" : "DISABLED");
278 dprintf(fd, "Incremental dir: %s\n", mIncrementalDir.c_str());
279
280 std::unique_lock l(mLock);
281
282 dprintf(fd, "Mounts (%d):\n", int(mMounts.size()));
283 for (auto&& [id, ifs] : mMounts) {
284 const IncFsMount& mnt = *ifs.get();
285 dprintf(fd, "\t[%d]:\n", id);
286 dprintf(fd, "\t\tmountId: %d\n", mnt.mountId);
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -0700287 dprintf(fd, "\t\troot: %s\n", mnt.root.c_str());
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800288 dprintf(fd, "\t\tnextStorageDirNo: %d\n", mnt.nextStorageDirNo.load());
289 dprintf(fd, "\t\tdataLoaderStatus: %d\n", mnt.dataLoaderStatus.load());
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700290 {
291 const auto& params = mnt.dataLoaderParams;
292 dprintf(fd, "\t\tdataLoaderParams:\n");
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800293 dprintf(fd, "\t\t\ttype: %s\n", toString(params.type).c_str());
294 dprintf(fd, "\t\t\tpackageName: %s\n", params.packageName.c_str());
295 dprintf(fd, "\t\t\tclassName: %s\n", params.className.c_str());
296 dprintf(fd, "\t\t\targuments: %s\n", params.arguments.c_str());
Alex Buynytskyy18b07a42020-02-03 20:06:00 -0800297 }
298 dprintf(fd, "\t\tstorages (%d):\n", int(mnt.storages.size()));
299 for (auto&& [storageId, storage] : mnt.storages) {
300 dprintf(fd, "\t\t\t[%d] -> [%s]\n", storageId, storage.name.c_str());
301 }
302
303 dprintf(fd, "\t\tbindPoints (%d):\n", int(mnt.bindPoints.size()));
304 for (auto&& [target, bind] : mnt.bindPoints) {
305 dprintf(fd, "\t\t\t[%s]->[%d]:\n", target.c_str(), bind.storage);
306 dprintf(fd, "\t\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str());
307 dprintf(fd, "\t\t\t\tsourceDir: %s\n", bind.sourceDir.c_str());
308 dprintf(fd, "\t\t\t\tkind: %s\n", toString(bind.kind));
309 }
310 }
311
312 dprintf(fd, "Sorted binds (%d):\n", int(mBindsByPath.size()));
313 for (auto&& [target, mountPairIt] : mBindsByPath) {
314 const auto& bind = mountPairIt->second;
315 dprintf(fd, "\t\t[%s]->[%d]:\n", target.c_str(), bind.storage);
316 dprintf(fd, "\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str());
317 dprintf(fd, "\t\t\tsourceDir: %s\n", bind.sourceDir.c_str());
318 dprintf(fd, "\t\t\tkind: %s\n", toString(bind.kind));
319 }
320}
321
Songchun Fan3c82a302019-11-29 14:23:45 -0800322std::optional<std::future<void>> IncrementalService::onSystemReady() {
323 std::promise<void> threadFinished;
324 if (mSystemReady.exchange(true)) {
325 return {};
326 }
327
328 std::vector<IfsMountPtr> mounts;
329 {
330 std::lock_guard l(mLock);
331 mounts.reserve(mMounts.size());
332 for (auto&& [id, ifs] : mMounts) {
333 if (ifs->mountId == id) {
334 mounts.push_back(ifs);
335 }
336 }
337 }
338
339 std::thread([this, mounts = std::move(mounts)]() {
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700340 /* TODO(b/151241369): restore data loaders on reboot.
Songchun Fan3c82a302019-11-29 14:23:45 -0800341 for (auto&& ifs : mounts) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800342 if (prepareDataLoader(*ifs)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800343 LOG(INFO) << "Successfully started data loader for mount " << ifs->mountId;
344 } else {
Songchun Fan1124fd32020-02-10 12:49:41 -0800345 // TODO(b/133435829): handle data loader start failures
Songchun Fan3c82a302019-11-29 14:23:45 -0800346 LOG(WARNING) << "Failed to start data loader for mount " << ifs->mountId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800347 }
348 }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700349 */
Songchun Fan3c82a302019-11-29 14:23:45 -0800350 mPrepareDataLoaders.set_value_at_thread_exit();
351 }).detach();
352 return mPrepareDataLoaders.get_future();
353}
354
355auto IncrementalService::getStorageSlotLocked() -> MountMap::iterator {
356 for (;;) {
357 if (mNextId == kMaxStorageId) {
358 mNextId = 0;
359 }
360 auto id = ++mNextId;
361 auto [it, inserted] = mMounts.try_emplace(id, nullptr);
362 if (inserted) {
363 return it;
364 }
365 }
366}
367
Songchun Fan1124fd32020-02-10 12:49:41 -0800368StorageId IncrementalService::createStorage(
369 std::string_view mountPoint, DataLoaderParamsParcel&& dataLoaderParams,
370 const DataLoaderStatusListener& dataLoaderStatusListener, CreateOptions options) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800371 LOG(INFO) << "createStorage: " << mountPoint << " | " << int(options);
372 if (!path::isAbsolute(mountPoint)) {
373 LOG(ERROR) << "path is not absolute: " << mountPoint;
374 return kInvalidStorageId;
375 }
376
377 auto mountNorm = path::normalize(mountPoint);
378 {
379 const auto id = findStorageId(mountNorm);
380 if (id != kInvalidStorageId) {
381 if (options & CreateOptions::OpenExisting) {
382 LOG(INFO) << "Opened existing storage " << id;
383 return id;
384 }
385 LOG(ERROR) << "Directory " << mountPoint << " is already mounted at storage " << id;
386 return kInvalidStorageId;
387 }
388 }
389
390 if (!(options & CreateOptions::CreateNew)) {
391 LOG(ERROR) << "not requirested create new storage, and it doesn't exist: " << mountPoint;
392 return kInvalidStorageId;
393 }
394
395 if (!path::isEmptyDir(mountNorm)) {
396 LOG(ERROR) << "Mounting over existing non-empty directory is not supported: " << mountNorm;
397 return kInvalidStorageId;
398 }
399 auto [mountKey, mountRoot] = makeMountDir(mIncrementalDir, mountNorm);
400 if (mountRoot.empty()) {
401 LOG(ERROR) << "Bad mount point";
402 return kInvalidStorageId;
403 }
404 // Make sure the code removes all crap it may create while still failing.
405 auto firstCleanup = [](const std::string* ptr) { IncFsMount::cleanupFilesystem(*ptr); };
406 auto firstCleanupOnFailure =
407 std::unique_ptr<std::string, decltype(firstCleanup)>(&mountRoot, firstCleanup);
408
409 auto mountTarget = path::join(mountRoot, constants().mount);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800410 const auto backing = path::join(mountRoot, constants().backing);
411 if (!mkdirOrLog(backing, 0777) || !mkdirOrLog(mountTarget)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800412 return kInvalidStorageId;
413 }
414
Songchun Fan3c82a302019-11-29 14:23:45 -0800415 IncFsMount::Control control;
416 {
417 std::lock_guard l(mMountOperationLock);
418 IncrementalFileSystemControlParcel controlParcel;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800419
420 if (auto err = rmDirContent(backing.c_str())) {
421 LOG(ERROR) << "Coudn't clean the backing directory " << backing << ": " << err;
422 return kInvalidStorageId;
423 }
424 if (!mkdirOrLog(path::join(backing, ".index"), 0777)) {
425 return kInvalidStorageId;
426 }
427 auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel);
Songchun Fan3c82a302019-11-29 14:23:45 -0800428 if (!status.isOk()) {
429 LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
430 return kInvalidStorageId;
431 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800432 if (controlParcel.cmd.get() < 0 || controlParcel.pendingReads.get() < 0 ||
433 controlParcel.log.get() < 0) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800434 LOG(ERROR) << "Vold::mountIncFs() returned invalid control parcel.";
435 return kInvalidStorageId;
436 }
Songchun Fan20d6ef22020-03-03 09:47:15 -0800437 int cmd = controlParcel.cmd.release().release();
438 int pendingReads = controlParcel.pendingReads.release().release();
439 int logs = controlParcel.log.release().release();
440 control = mIncFs->createControl(cmd, pendingReads, logs);
Songchun Fan3c82a302019-11-29 14:23:45 -0800441 }
442
443 std::unique_lock l(mLock);
444 const auto mountIt = getStorageSlotLocked();
445 const auto mountId = mountIt->first;
446 l.unlock();
447
448 auto ifs =
449 std::make_shared<IncFsMount>(std::move(mountRoot), mountId, std::move(control), *this);
450 // Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need
451 // is the removal of the |ifs|.
452 firstCleanupOnFailure.release();
453
454 auto secondCleanup = [this, &l](auto itPtr) {
455 if (!l.owns_lock()) {
456 l.lock();
457 }
458 mMounts.erase(*itPtr);
459 };
460 auto secondCleanupOnFailure =
461 std::unique_ptr<decltype(mountIt), decltype(secondCleanup)>(&mountIt, secondCleanup);
462
463 const auto storageIt = ifs->makeStorage(ifs->mountId);
464 if (storageIt == ifs->storages.end()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800465 LOG(ERROR) << "Can't create a default storage directory";
Songchun Fan3c82a302019-11-29 14:23:45 -0800466 return kInvalidStorageId;
467 }
468
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700469 ifs->dataLoaderParams = std::move(dataLoaderParams);
470
Songchun Fan3c82a302019-11-29 14:23:45 -0800471 {
472 metadata::Mount m;
473 m.mutable_storage()->set_id(ifs->mountId);
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700474 m.mutable_loader()->set_type((int)ifs->dataLoaderParams.type);
475 m.mutable_loader()->set_package_name(ifs->dataLoaderParams.packageName);
476 m.mutable_loader()->set_class_name(ifs->dataLoaderParams.className);
477 m.mutable_loader()->set_arguments(ifs->dataLoaderParams.arguments);
Songchun Fan3c82a302019-11-29 14:23:45 -0800478 const auto metadata = m.SerializeAsString();
479 m.mutable_loader()->release_arguments();
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -0800480 m.mutable_loader()->release_class_name();
Songchun Fan3c82a302019-11-29 14:23:45 -0800481 m.mutable_loader()->release_package_name();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800482 if (auto err =
483 mIncFs->makeFile(ifs->control,
484 path::join(ifs->root, constants().mount,
485 constants().infoMdName),
486 0777, idFromMetadata(metadata),
487 {.metadata = {metadata.data(), (IncFsSize)metadata.size()}})) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800488 LOG(ERROR) << "Saving mount metadata failed: " << -err;
489 return kInvalidStorageId;
490 }
491 }
492
493 const auto bk =
494 (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800495 if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name,
496 std::string(storageIt->second.name), std::move(mountNorm), bk, l);
Songchun Fan3c82a302019-11-29 14:23:45 -0800497 err < 0) {
498 LOG(ERROR) << "adding bind mount failed: " << -err;
499 return kInvalidStorageId;
500 }
501
502 // Done here as well, all data structures are in good state.
503 secondCleanupOnFailure.release();
504
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700505 if (!prepareDataLoader(*ifs, &dataLoaderStatusListener)) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800506 LOG(ERROR) << "prepareDataLoader() failed";
507 deleteStorageLocked(*ifs, std::move(l));
508 return kInvalidStorageId;
509 }
510
511 mountIt->second = std::move(ifs);
512 l.unlock();
513 LOG(INFO) << "created storage " << mountId;
514 return mountId;
515}
516
517StorageId IncrementalService::createLinkedStorage(std::string_view mountPoint,
518 StorageId linkedStorage,
519 IncrementalService::CreateOptions options) {
520 if (!isValidMountTarget(mountPoint)) {
521 LOG(ERROR) << "Mount point is invalid or missing";
522 return kInvalidStorageId;
523 }
524
525 std::unique_lock l(mLock);
526 const auto& ifs = getIfsLocked(linkedStorage);
527 if (!ifs) {
528 LOG(ERROR) << "Ifs unavailable";
529 return kInvalidStorageId;
530 }
531
532 const auto mountIt = getStorageSlotLocked();
533 const auto storageId = mountIt->first;
534 const auto storageIt = ifs->makeStorage(storageId);
535 if (storageIt == ifs->storages.end()) {
536 LOG(ERROR) << "Can't create a new storage";
537 mMounts.erase(mountIt);
538 return kInvalidStorageId;
539 }
540
541 l.unlock();
542
543 const auto bk =
544 (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800545 if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name,
546 std::string(storageIt->second.name), path::normalize(mountPoint),
547 bk, l);
Songchun Fan3c82a302019-11-29 14:23:45 -0800548 err < 0) {
549 LOG(ERROR) << "bindMount failed with error: " << err;
550 return kInvalidStorageId;
551 }
552
553 mountIt->second = ifs;
554 return storageId;
555}
556
557IncrementalService::BindPathMap::const_iterator IncrementalService::findStorageLocked(
558 std::string_view path) const {
559 auto bindPointIt = mBindsByPath.upper_bound(path);
560 if (bindPointIt == mBindsByPath.begin()) {
561 return mBindsByPath.end();
562 }
563 --bindPointIt;
564 if (!path::startsWith(path, bindPointIt->first)) {
565 return mBindsByPath.end();
566 }
567 return bindPointIt;
568}
569
570StorageId IncrementalService::findStorageId(std::string_view path) const {
571 std::lock_guard l(mLock);
572 auto it = findStorageLocked(path);
573 if (it == mBindsByPath.end()) {
574 return kInvalidStorageId;
575 }
576 return it->second->second.storage;
577}
578
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700579int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLogs) {
580 const auto ifs = getIfs(storageId);
581 if (!ifs) {
582 return -EINVAL;
583 }
584
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700585 ifs->dataLoaderFilesystemParams.readLogsEnabled = enableReadLogs;
586 if (enableReadLogs) {
587 // We never unregister the callbacks, but given a restricted number of data loaders and even fewer asking for read log access, should be ok.
588 registerAppOpsCallback(ifs->dataLoaderParams.packageName);
589 }
590
591 return applyStorageParams(*ifs);
592}
593
594int IncrementalService::applyStorageParams(IncFsMount& ifs) {
595 const bool enableReadLogs = ifs.dataLoaderFilesystemParams.readLogsEnabled;
596 if (enableReadLogs) {
597 if (auto status = CheckPermissionForDataDelivery(kDataUsageStats, kOpUsage);
598 !status.isOk()) {
599 LOG(ERROR) << "CheckPermissionForDataDelivery failed: " << status.toString8();
600 return fromBinderStatus(status);
601 }
602 }
603
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700604 using unique_fd = ::android::base::unique_fd;
605 ::android::os::incremental::IncrementalFileSystemControlParcel control;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700606 control.cmd.reset(unique_fd(dup(ifs.control.cmd())));
607 control.pendingReads.reset(unique_fd(dup(ifs.control.pendingReads())));
608 auto logsFd = ifs.control.logs();
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700609 if (logsFd >= 0) {
610 control.log.reset(unique_fd(dup(logsFd)));
611 }
612
613 std::lock_guard l(mMountOperationLock);
614 const auto status = mVold->setIncFsMountOptions(control, enableReadLogs);
615 if (!status.isOk()) {
616 LOG(ERROR) << "Calling Vold::setIncFsMountOptions() failed: " << status.toString8();
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700617 return fromBinderStatus(status);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700618 }
619
620 return 0;
621}
622
Songchun Fan3c82a302019-11-29 14:23:45 -0800623void IncrementalService::deleteStorage(StorageId storageId) {
624 const auto ifs = getIfs(storageId);
625 if (!ifs) {
626 return;
627 }
628 deleteStorage(*ifs);
629}
630
631void IncrementalService::deleteStorage(IncrementalService::IncFsMount& ifs) {
632 std::unique_lock l(ifs.lock);
633 deleteStorageLocked(ifs, std::move(l));
634}
635
636void IncrementalService::deleteStorageLocked(IncrementalService::IncFsMount& ifs,
637 std::unique_lock<std::mutex>&& ifsLock) {
638 const auto storages = std::move(ifs.storages);
639 // Don't move the bind points out: Ifs's dtor will use them to unmount everything.
640 const auto bindPoints = ifs.bindPoints;
641 ifsLock.unlock();
642
643 std::lock_guard l(mLock);
644 for (auto&& [id, _] : storages) {
645 if (id != ifs.mountId) {
646 mMounts.erase(id);
647 }
648 }
649 for (auto&& [path, _] : bindPoints) {
650 mBindsByPath.erase(path);
651 }
652 mMounts.erase(ifs.mountId);
653}
654
655StorageId IncrementalService::openStorage(std::string_view pathInMount) {
656 if (!path::isAbsolute(pathInMount)) {
657 return kInvalidStorageId;
658 }
659
660 return findStorageId(path::normalize(pathInMount));
661}
662
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800663FileId IncrementalService::nodeFor(StorageId storage, std::string_view subpath) const {
Songchun Fan3c82a302019-11-29 14:23:45 -0800664 const auto ifs = getIfs(storage);
665 if (!ifs) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800666 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800667 }
668 std::unique_lock l(ifs->lock);
669 auto storageIt = ifs->storages.find(storage);
670 if (storageIt == ifs->storages.end()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800671 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800672 }
673 if (subpath.empty() || subpath == "."sv) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800674 return kIncFsInvalidFileId;
Songchun Fan3c82a302019-11-29 14:23:45 -0800675 }
676 auto path = path::join(ifs->root, constants().mount, storageIt->second.name, subpath);
677 l.unlock();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800678 return mIncFs->getFileId(ifs->control, path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800679}
680
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800681std::pair<FileId, std::string_view> IncrementalService::parentAndNameFor(
Songchun Fan3c82a302019-11-29 14:23:45 -0800682 StorageId storage, std::string_view subpath) const {
683 auto name = path::basename(subpath);
684 if (name.empty()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800685 return {kIncFsInvalidFileId, {}};
Songchun Fan3c82a302019-11-29 14:23:45 -0800686 }
687 auto dir = path::dirname(subpath);
688 if (dir.empty() || dir == "/"sv) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800689 return {kIncFsInvalidFileId, {}};
Songchun Fan3c82a302019-11-29 14:23:45 -0800690 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800691 auto id = nodeFor(storage, dir);
692 return {id, name};
Songchun Fan3c82a302019-11-29 14:23:45 -0800693}
694
695IncrementalService::IfsMountPtr IncrementalService::getIfs(StorageId storage) const {
696 std::lock_guard l(mLock);
697 return getIfsLocked(storage);
698}
699
700const IncrementalService::IfsMountPtr& IncrementalService::getIfsLocked(StorageId storage) const {
701 auto it = mMounts.find(storage);
702 if (it == mMounts.end()) {
703 static const IfsMountPtr kEmpty = {};
704 return kEmpty;
705 }
706 return it->second;
707}
708
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800709int IncrementalService::bind(StorageId storage, std::string_view source, std::string_view target,
710 BindKind kind) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800711 if (!isValidMountTarget(target)) {
712 return -EINVAL;
713 }
714
715 const auto ifs = getIfs(storage);
716 if (!ifs) {
717 return -EINVAL;
718 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800719
Songchun Fan3c82a302019-11-29 14:23:45 -0800720 std::unique_lock l(ifs->lock);
721 const auto storageInfo = ifs->storages.find(storage);
722 if (storageInfo == ifs->storages.end()) {
723 return -EINVAL;
724 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800725 std::string normSource = normalizePathToStorage(ifs, storage, source);
Songchun Fan3c82a302019-11-29 14:23:45 -0800726 l.unlock();
727 std::unique_lock l2(mLock, std::defer_lock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800728 return addBindMount(*ifs, storage, storageInfo->second.name, std::move(normSource),
729 path::normalize(target), kind, l2);
Songchun Fan3c82a302019-11-29 14:23:45 -0800730}
731
732int IncrementalService::unbind(StorageId storage, std::string_view target) {
733 if (!path::isAbsolute(target)) {
734 return -EINVAL;
735 }
736
737 LOG(INFO) << "Removing bind point " << target;
738
739 // Here we should only look up by the exact target, not by a subdirectory of any existing mount,
740 // otherwise there's a chance to unmount something completely unrelated
741 const auto norm = path::normalize(target);
742 std::unique_lock l(mLock);
743 const auto storageIt = mBindsByPath.find(norm);
744 if (storageIt == mBindsByPath.end() || storageIt->second->second.storage != storage) {
745 return -EINVAL;
746 }
747 const auto bindIt = storageIt->second;
748 const auto storageId = bindIt->second.storage;
749 const auto ifs = getIfsLocked(storageId);
750 if (!ifs) {
751 LOG(ERROR) << "Internal error: storageId " << storageId << " for bound path " << target
752 << " is missing";
753 return -EFAULT;
754 }
755 mBindsByPath.erase(storageIt);
756 l.unlock();
757
758 mVold->unmountIncFs(bindIt->first);
759 std::unique_lock l2(ifs->lock);
760 if (ifs->bindPoints.size() <= 1) {
761 ifs->bindPoints.clear();
762 deleteStorageLocked(*ifs, std::move(l2));
763 } else {
764 const std::string savedFile = std::move(bindIt->second.savedFilename);
765 ifs->bindPoints.erase(bindIt);
766 l2.unlock();
767 if (!savedFile.empty()) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800768 mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, savedFile));
Songchun Fan3c82a302019-11-29 14:23:45 -0800769 }
770 }
771 return 0;
772}
773
Songchun Fan103ba1d2020-02-03 17:32:32 -0800774std::string IncrementalService::normalizePathToStorage(const IncrementalService::IfsMountPtr ifs,
775 StorageId storage, std::string_view path) {
776 const auto storageInfo = ifs->storages.find(storage);
777 if (storageInfo == ifs->storages.end()) {
778 return {};
779 }
780 std::string normPath;
781 if (path::isAbsolute(path)) {
782 normPath = path::normalize(path);
783 } else {
784 normPath = path::normalize(path::join(storageInfo->second.name, path));
785 }
786 if (!path::startsWith(normPath, storageInfo->second.name)) {
787 return {};
788 }
789 return normPath;
790}
791
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800792int IncrementalService::makeFile(StorageId storage, std::string_view path, int mode, FileId id,
793 incfs::NewFileParams params) {
794 if (auto ifs = getIfs(storage)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800795 std::string normPath = normalizePathToStorage(ifs, storage, path);
796 if (normPath.empty()) {
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700797 LOG(ERROR) << "Internal error: storageId " << storage << " failed to normalize: " << path;
Songchun Fan54c6aed2020-01-31 16:52:41 -0800798 return -EINVAL;
799 }
800 auto err = mIncFs->makeFile(ifs->control, normPath, mode, id, params);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800801 if (err) {
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700802 LOG(ERROR) << "Internal error: storageId " << storage << " failed to makeFile: " << err;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800803 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800804 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800805 std::vector<uint8_t> metadataBytes;
806 if (params.metadata.data && params.metadata.size > 0) {
807 metadataBytes.assign(params.metadata.data, params.metadata.data + params.metadata.size);
Songchun Fan3c82a302019-11-29 14:23:45 -0800808 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800809 return 0;
Songchun Fan3c82a302019-11-29 14:23:45 -0800810 }
811 return -EINVAL;
812}
813
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800814int IncrementalService::makeDir(StorageId storageId, std::string_view path, int mode) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800815 if (auto ifs = getIfs(storageId)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800816 std::string normPath = normalizePathToStorage(ifs, storageId, path);
817 if (normPath.empty()) {
818 return -EINVAL;
819 }
820 return mIncFs->makeDir(ifs->control, normPath, mode);
Songchun Fan3c82a302019-11-29 14:23:45 -0800821 }
822 return -EINVAL;
823}
824
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800825int IncrementalService::makeDirs(StorageId storageId, std::string_view path, int mode) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800826 const auto ifs = getIfs(storageId);
827 if (!ifs) {
828 return -EINVAL;
829 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800830 std::string normPath = normalizePathToStorage(ifs, storageId, path);
831 if (normPath.empty()) {
832 return -EINVAL;
833 }
834 auto err = mIncFs->makeDir(ifs->control, normPath, mode);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800835 if (err == -EEXIST) {
836 return 0;
837 } else if (err != -ENOENT) {
838 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800839 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800840 if (auto err = makeDirs(storageId, path::dirname(normPath), mode)) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800841 return err;
Songchun Fan3c82a302019-11-29 14:23:45 -0800842 }
Songchun Fan103ba1d2020-02-03 17:32:32 -0800843 return mIncFs->makeDir(ifs->control, normPath, mode);
Songchun Fan3c82a302019-11-29 14:23:45 -0800844}
845
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800846int IncrementalService::link(StorageId sourceStorageId, std::string_view oldPath,
847 StorageId destStorageId, std::string_view newPath) {
848 if (auto ifsSrc = getIfs(sourceStorageId), ifsDest = getIfs(destStorageId);
849 ifsSrc && ifsSrc == ifsDest) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800850 std::string normOldPath = normalizePathToStorage(ifsSrc, sourceStorageId, oldPath);
851 std::string normNewPath = normalizePathToStorage(ifsDest, destStorageId, newPath);
852 if (normOldPath.empty() || normNewPath.empty()) {
853 return -EINVAL;
854 }
855 return mIncFs->link(ifsSrc->control, normOldPath, normNewPath);
Songchun Fan3c82a302019-11-29 14:23:45 -0800856 }
857 return -EINVAL;
858}
859
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800860int IncrementalService::unlink(StorageId storage, std::string_view path) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800861 if (auto ifs = getIfs(storage)) {
Songchun Fan103ba1d2020-02-03 17:32:32 -0800862 std::string normOldPath = normalizePathToStorage(ifs, storage, path);
863 return mIncFs->unlink(ifs->control, normOldPath);
Songchun Fan3c82a302019-11-29 14:23:45 -0800864 }
865 return -EINVAL;
866}
867
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800868int IncrementalService::addBindMount(IncFsMount& ifs, StorageId storage,
869 std::string_view storageRoot, std::string&& source,
Songchun Fan3c82a302019-11-29 14:23:45 -0800870 std::string&& target, BindKind kind,
871 std::unique_lock<std::mutex>& mainLock) {
872 if (!isValidMountTarget(target)) {
873 return -EINVAL;
874 }
875
876 std::string mdFileName;
877 if (kind != BindKind::Temporary) {
878 metadata::BindPoint bp;
879 bp.set_storage_id(storage);
880 bp.set_allocated_dest_path(&target);
Songchun Fan1124fd32020-02-10 12:49:41 -0800881 bp.set_allocated_source_subdir(&source);
Songchun Fan3c82a302019-11-29 14:23:45 -0800882 const auto metadata = bp.SerializeAsString();
Songchun Fan3c82a302019-11-29 14:23:45 -0800883 bp.release_dest_path();
Songchun Fan1124fd32020-02-10 12:49:41 -0800884 bp.release_source_subdir();
Songchun Fan3c82a302019-11-29 14:23:45 -0800885 mdFileName = makeBindMdName();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800886 auto node =
887 mIncFs->makeFile(ifs.control, path::join(ifs.root, constants().mount, mdFileName),
888 0444, idFromMetadata(metadata),
889 {.metadata = {metadata.data(), (IncFsSize)metadata.size()}});
890 if (node) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800891 return int(node);
892 }
893 }
894
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800895 return addBindMountWithMd(ifs, storage, std::move(mdFileName), std::move(source),
Songchun Fan3c82a302019-11-29 14:23:45 -0800896 std::move(target), kind, mainLock);
897}
898
899int IncrementalService::addBindMountWithMd(IncrementalService::IncFsMount& ifs, StorageId storage,
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800900 std::string&& metadataName, std::string&& source,
Songchun Fan3c82a302019-11-29 14:23:45 -0800901 std::string&& target, BindKind kind,
902 std::unique_lock<std::mutex>& mainLock) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800903 {
Songchun Fan3c82a302019-11-29 14:23:45 -0800904 std::lock_guard l(mMountOperationLock);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800905 const auto status = mVold->bindMount(source, target);
Songchun Fan3c82a302019-11-29 14:23:45 -0800906 if (!status.isOk()) {
907 LOG(ERROR) << "Calling Vold::bindMount() failed: " << status.toString8();
908 return status.exceptionCode() == binder::Status::EX_SERVICE_SPECIFIC
909 ? status.serviceSpecificErrorCode() > 0 ? -status.serviceSpecificErrorCode()
910 : status.serviceSpecificErrorCode() == 0
911 ? -EFAULT
912 : status.serviceSpecificErrorCode()
913 : -EIO;
914 }
915 }
916
917 if (!mainLock.owns_lock()) {
918 mainLock.lock();
919 }
920 std::lock_guard l(ifs.lock);
921 const auto [it, _] =
922 ifs.bindPoints.insert_or_assign(target,
923 IncFsMount::Bind{storage, std::move(metadataName),
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800924 std::move(source), kind});
Songchun Fan3c82a302019-11-29 14:23:45 -0800925 mBindsByPath[std::move(target)] = it;
926 return 0;
927}
928
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800929RawMetadata IncrementalService::getMetadata(StorageId storage, FileId node) const {
Songchun Fan3c82a302019-11-29 14:23:45 -0800930 const auto ifs = getIfs(storage);
931 if (!ifs) {
932 return {};
933 }
934 return mIncFs->getMetadata(ifs->control, node);
935}
936
937std::vector<std::string> IncrementalService::listFiles(StorageId storage) const {
938 const auto ifs = getIfs(storage);
939 if (!ifs) {
940 return {};
941 }
942
943 std::unique_lock l(ifs->lock);
944 auto subdirIt = ifs->storages.find(storage);
945 if (subdirIt == ifs->storages.end()) {
946 return {};
947 }
948 auto dir = path::join(ifs->root, constants().mount, subdirIt->second.name);
949 l.unlock();
950
951 const auto prefixSize = dir.size() + 1;
952 std::vector<std::string> todoDirs{std::move(dir)};
953 std::vector<std::string> result;
954 do {
955 auto currDir = std::move(todoDirs.back());
956 todoDirs.pop_back();
957
958 auto d =
959 std::unique_ptr<DIR, decltype(&::closedir)>(::opendir(currDir.c_str()), ::closedir);
960 while (auto e = ::readdir(d.get())) {
961 if (e->d_type == DT_REG) {
962 result.emplace_back(
963 path::join(std::string_view(currDir).substr(prefixSize), e->d_name));
964 continue;
965 }
966 if (e->d_type == DT_DIR) {
967 if (e->d_name == "."sv || e->d_name == ".."sv) {
968 continue;
969 }
970 todoDirs.emplace_back(path::join(currDir, e->d_name));
971 continue;
972 }
973 }
974 } while (!todoDirs.empty());
975 return result;
976}
977
978bool IncrementalService::startLoading(StorageId storage) const {
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700979 {
980 std::unique_lock l(mLock);
981 const auto& ifs = getIfsLocked(storage);
982 if (!ifs) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800983 return false;
984 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700985 if (ifs->dataLoaderStatus != IDataLoaderStatusListener::DATA_LOADER_CREATED) {
986 ifs->dataLoaderStartRequested = true;
987 return true;
988 }
Songchun Fan3c82a302019-11-29 14:23:45 -0800989 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700990 return startDataLoader(storage);
991}
992
993bool IncrementalService::startDataLoader(MountId mountId) const {
Songchun Fan68645c42020-02-27 15:57:35 -0800994 sp<IDataLoader> dataloader;
Alex Buynytskyybf1c0632020-03-10 15:49:29 -0700995 auto status = mDataLoaderManager->getDataLoader(mountId, &dataloader);
Songchun Fan3c82a302019-11-29 14:23:45 -0800996 if (!status.isOk()) {
997 return false;
998 }
Songchun Fan68645c42020-02-27 15:57:35 -0800999 if (!dataloader) {
1000 return false;
1001 }
Alex Buynytskyyb6e02f72020-03-17 18:12:23 -07001002 status = dataloader->start(mountId);
Songchun Fan68645c42020-02-27 15:57:35 -08001003 if (!status.isOk()) {
1004 return false;
1005 }
1006 return true;
Songchun Fan3c82a302019-11-29 14:23:45 -08001007}
1008
1009void IncrementalService::mountExistingImages() {
Songchun Fan1124fd32020-02-10 12:49:41 -08001010 for (const auto& entry : fs::directory_iterator(mIncrementalDir)) {
1011 const auto path = entry.path().u8string();
1012 const auto name = entry.path().filename().u8string();
1013 if (!base::StartsWith(name, constants().mountKeyPrefix)) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001014 continue;
1015 }
Songchun Fan1124fd32020-02-10 12:49:41 -08001016 const auto root = path::join(mIncrementalDir, name);
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001017 if (!mountExistingImage(root)) {
Songchun Fan1124fd32020-02-10 12:49:41 -08001018 IncFsMount::cleanupFilesystem(path);
Songchun Fan3c82a302019-11-29 14:23:45 -08001019 }
1020 }
1021}
1022
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001023bool IncrementalService::mountExistingImage(std::string_view root) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001024 auto mountTarget = path::join(root, constants().mount);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001025 const auto backing = path::join(root, constants().backing);
Songchun Fan3c82a302019-11-29 14:23:45 -08001026
Songchun Fan3c82a302019-11-29 14:23:45 -08001027 IncrementalFileSystemControlParcel controlParcel;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001028 auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel);
Songchun Fan3c82a302019-11-29 14:23:45 -08001029 if (!status.isOk()) {
1030 LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8();
1031 return false;
1032 }
Songchun Fan20d6ef22020-03-03 09:47:15 -08001033
1034 int cmd = controlParcel.cmd.release().release();
1035 int pendingReads = controlParcel.pendingReads.release().release();
1036 int logs = controlParcel.log.release().release();
1037 IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs);
Songchun Fan3c82a302019-11-29 14:23:45 -08001038
1039 auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this);
1040
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001041 auto mount = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control,
1042 path::join(mountTarget, constants().infoMdName));
1043 if (!mount.has_loader() || !mount.has_storage()) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001044 LOG(ERROR) << "Bad mount metadata in mount at " << root;
1045 return false;
1046 }
1047
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001048 ifs->mountId = mount.storage().id();
Songchun Fan3c82a302019-11-29 14:23:45 -08001049 mNextId = std::max(mNextId, ifs->mountId + 1);
1050
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001051 // DataLoader params
1052 {
1053 auto& dlp = ifs->dataLoaderParams;
1054 const auto& loader = mount.loader();
1055 dlp.type = (android::content::pm::DataLoaderType)loader.type();
1056 dlp.packageName = loader.package_name();
1057 dlp.className = loader.class_name();
1058 dlp.arguments = loader.arguments();
1059 }
1060
Songchun Fan3c82a302019-11-29 14:23:45 -08001061 std::vector<std::pair<std::string, metadata::BindPoint>> bindPoints;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001062 auto d = openDir(path::c_str(mountTarget));
Songchun Fan3c82a302019-11-29 14:23:45 -08001063 while (auto e = ::readdir(d.get())) {
1064 if (e->d_type == DT_REG) {
1065 auto name = std::string_view(e->d_name);
1066 if (name.starts_with(constants().mountpointMdPrefix)) {
1067 bindPoints.emplace_back(name,
1068 parseFromIncfs<metadata::BindPoint>(mIncFs.get(),
1069 ifs->control,
1070 path::join(mountTarget,
1071 name)));
1072 if (bindPoints.back().second.dest_path().empty() ||
1073 bindPoints.back().second.source_subdir().empty()) {
1074 bindPoints.pop_back();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001075 mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, name));
Songchun Fan3c82a302019-11-29 14:23:45 -08001076 }
1077 }
1078 } else if (e->d_type == DT_DIR) {
1079 if (e->d_name == "."sv || e->d_name == ".."sv) {
1080 continue;
1081 }
1082 auto name = std::string_view(e->d_name);
1083 if (name.starts_with(constants().storagePrefix)) {
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001084 int storageId;
1085 const auto res = std::from_chars(name.data() + constants().storagePrefix.size() + 1,
1086 name.data() + name.size(), storageId);
1087 if (res.ec != std::errc{} || *res.ptr != '_') {
1088 LOG(WARNING) << "Ignoring storage with invalid name '" << name << "' for mount "
1089 << root;
1090 continue;
1091 }
1092 auto [_, inserted] = mMounts.try_emplace(storageId, ifs);
Songchun Fan3c82a302019-11-29 14:23:45 -08001093 if (!inserted) {
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001094 LOG(WARNING) << "Ignoring storage with duplicate id " << storageId
Songchun Fan3c82a302019-11-29 14:23:45 -08001095 << " for mount " << root;
1096 continue;
1097 }
Yurii Zubrytskyi107ae352020-04-03 13:12:51 -07001098 ifs->storages.insert_or_assign(storageId,
1099 IncFsMount::Storage{
1100 path::join(root, constants().mount, name)});
1101 mNextId = std::max(mNextId, storageId + 1);
Songchun Fan3c82a302019-11-29 14:23:45 -08001102 }
1103 }
1104 }
1105
1106 if (ifs->storages.empty()) {
1107 LOG(WARNING) << "No valid storages in mount " << root;
1108 return false;
1109 }
1110
1111 int bindCount = 0;
1112 for (auto&& bp : bindPoints) {
1113 std::unique_lock l(mLock, std::defer_lock);
1114 bindCount += !addBindMountWithMd(*ifs, bp.second.storage_id(), std::move(bp.first),
1115 std::move(*bp.second.mutable_source_subdir()),
1116 std::move(*bp.second.mutable_dest_path()),
1117 BindKind::Permanent, l);
1118 }
1119
1120 if (bindCount == 0) {
1121 LOG(WARNING) << "No valid bind points for mount " << root;
1122 deleteStorage(*ifs);
1123 return false;
1124 }
1125
Songchun Fan3c82a302019-11-29 14:23:45 -08001126 mMounts[ifs->mountId] = std::move(ifs);
1127 return true;
1128}
1129
1130bool IncrementalService::prepareDataLoader(IncrementalService::IncFsMount& ifs,
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001131 const DataLoaderStatusListener* externalListener) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001132 if (!mSystemReady.load(std::memory_order_relaxed)) {
1133 std::unique_lock l(ifs.lock);
Songchun Fan3c82a302019-11-29 14:23:45 -08001134 return true; // eventually...
1135 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001136
1137 std::unique_lock l(ifs.lock);
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001138 if (ifs.dataLoaderStatus != -1) {
Songchun Fan3c82a302019-11-29 14:23:45 -08001139 LOG(INFO) << "Skipped data loader preparation because it already exists";
1140 return true;
1141 }
1142
Songchun Fan3c82a302019-11-29 14:23:45 -08001143 FileSystemControlParcel fsControlParcel;
Jooyung Han66c567a2020-03-07 21:47:09 +09001144 fsControlParcel.incremental = aidl::make_nullable<IncrementalFileSystemControlParcel>();
Songchun Fan20d6ef22020-03-03 09:47:15 -08001145 fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd())));
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -08001146 fsControlParcel.incremental->pendingReads.reset(
Songchun Fan20d6ef22020-03-03 09:47:15 -08001147 base::unique_fd(::dup(ifs.control.pendingReads())));
1148 fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs())));
Songchun Fan1124fd32020-02-10 12:49:41 -08001149 sp<IncrementalDataLoaderListener> listener =
Songchun Fan306b7df2020-03-17 12:37:07 -07001150 new IncrementalDataLoaderListener(*this,
1151 externalListener ? *externalListener
1152 : DataLoaderStatusListener());
Songchun Fan3c82a302019-11-29 14:23:45 -08001153 bool created = false;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001154 auto status = mDataLoaderManager->initializeDataLoader(ifs.mountId, ifs.dataLoaderParams, fsControlParcel, listener, &created);
Songchun Fan3c82a302019-11-29 14:23:45 -08001155 if (!status.isOk() || !created) {
1156 LOG(ERROR) << "Failed to create a data loader for mount " << ifs.mountId;
1157 return false;
1158 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001159 return true;
1160}
1161
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001162// Extract lib filse from zip, create new files in incfs and write data to them
1163bool IncrementalService::configureNativeBinaries(StorageId storage, std::string_view apkFullPath,
1164 std::string_view libDirRelativePath,
1165 std::string_view abi) {
1166 const auto ifs = getIfs(storage);
1167 // First prepare target directories if they don't exist yet
1168 if (auto res = makeDirs(storage, libDirRelativePath, 0755)) {
1169 LOG(ERROR) << "Failed to prepare target lib directory " << libDirRelativePath
1170 << " errno: " << res;
1171 return false;
1172 }
1173
1174 std::unique_ptr<ZipFileRO> zipFile(ZipFileRO::open(apkFullPath.data()));
1175 if (!zipFile) {
1176 LOG(ERROR) << "Failed to open zip file at " << apkFullPath;
1177 return false;
1178 }
1179 void* cookie = nullptr;
1180 const auto libFilePrefix = path::join(constants().libDir, abi);
1181 if (!zipFile.get()->startIteration(&cookie, libFilePrefix.c_str() /* prefix */,
1182 constants().libSuffix.data() /* suffix */)) {
1183 LOG(ERROR) << "Failed to start zip iteration for " << apkFullPath;
1184 return false;
1185 }
1186 ZipEntryRO entry = nullptr;
1187 bool success = true;
1188 while ((entry = zipFile.get()->nextEntry(cookie)) != nullptr) {
1189 char fileName[PATH_MAX];
1190 if (zipFile.get()->getEntryFileName(entry, fileName, sizeof(fileName))) {
1191 continue;
1192 }
1193 const auto libName = path::basename(fileName);
1194 const auto targetLibPath = path::join(libDirRelativePath, libName);
1195 const auto targetLibPathAbsolute = normalizePathToStorage(ifs, storage, targetLibPath);
1196 // If the extract file already exists, skip
1197 struct stat st;
1198 if (stat(targetLibPathAbsolute.c_str(), &st) == 0) {
1199 LOG(INFO) << "Native lib file already exists: " << targetLibPath
1200 << "; skipping extraction";
1201 continue;
1202 }
1203
1204 uint32_t uncompressedLen;
1205 if (!zipFile.get()->getEntryInfo(entry, nullptr, &uncompressedLen, nullptr, nullptr,
1206 nullptr, nullptr)) {
1207 LOG(ERROR) << "Failed to read native lib entry: " << fileName;
1208 success = false;
1209 break;
1210 }
1211
1212 // Create new lib file without signature info
George Burgess IVdd5275d2020-02-10 11:18:07 -08001213 incfs::NewFileParams libFileParams{};
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001214 libFileParams.size = uncompressedLen;
Alex Buynytskyyf5e605a2020-03-13 13:31:12 -07001215 libFileParams.signature = {};
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001216 // Metadata of the new lib file is its relative path
1217 IncFsSpan libFileMetadata;
1218 libFileMetadata.data = targetLibPath.c_str();
1219 libFileMetadata.size = targetLibPath.size();
1220 libFileParams.metadata = libFileMetadata;
1221 incfs::FileId libFileId = idFromMetadata(targetLibPath);
1222 if (auto res = makeFile(storage, targetLibPath, 0777, libFileId, libFileParams)) {
1223 LOG(ERROR) << "Failed to make file for: " << targetLibPath << " errno: " << res;
1224 success = false;
1225 // If one lib file fails to be created, abort others as well
1226 break;
1227 }
Songchun Fanafaf6e92020-03-18 14:12:20 -07001228 // If it is a zero-byte file, skip data writing
1229 if (uncompressedLen == 0) {
1230 continue;
1231 }
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001232
1233 // Write extracted data to new file
1234 std::vector<uint8_t> libData(uncompressedLen);
1235 if (!zipFile.get()->uncompressEntry(entry, &libData[0], uncompressedLen)) {
1236 LOG(ERROR) << "Failed to extract native lib zip entry: " << fileName;
1237 success = false;
1238 break;
1239 }
Yurii Zubrytskyie82cdd72020-04-01 12:19:26 -07001240 const auto writeFd = mIncFs->openForSpecialOps(ifs->control, libFileId);
1241 if (!writeFd.ok()) {
Songchun Fan0f8b6fe2020-02-05 17:41:25 -08001242 LOG(ERROR) << "Failed to open write fd for: " << targetLibPath << " errno: " << writeFd;
1243 success = false;
1244 break;
1245 }
1246 const int numBlocks = uncompressedLen / constants().blockSize + 1;
1247 std::vector<IncFsDataBlock> instructions;
1248 auto remainingData = std::span(libData);
1249 for (int i = 0; i < numBlocks - 1; i++) {
1250 auto inst = IncFsDataBlock{
1251 .fileFd = writeFd,
1252 .pageIndex = static_cast<IncFsBlockIndex>(i),
1253 .compression = INCFS_COMPRESSION_KIND_NONE,
1254 .kind = INCFS_BLOCK_KIND_DATA,
1255 .dataSize = static_cast<uint16_t>(constants().blockSize),
1256 .data = reinterpret_cast<const char*>(remainingData.data()),
1257 };
1258 instructions.push_back(inst);
1259 remainingData = remainingData.subspan(constants().blockSize);
1260 }
1261 // Last block
1262 auto inst = IncFsDataBlock{
1263 .fileFd = writeFd,
1264 .pageIndex = static_cast<IncFsBlockIndex>(numBlocks - 1),
1265 .compression = INCFS_COMPRESSION_KIND_NONE,
1266 .kind = INCFS_BLOCK_KIND_DATA,
1267 .dataSize = static_cast<uint16_t>(remainingData.size()),
1268 .data = reinterpret_cast<const char*>(remainingData.data()),
1269 };
1270 instructions.push_back(inst);
1271 size_t res = mIncFs->writeBlocks(instructions);
1272 if (res != instructions.size()) {
1273 LOG(ERROR) << "Failed to write data into: " << targetLibPath;
1274 success = false;
1275 }
1276 instructions.clear();
1277 }
1278 zipFile.get()->endIteration(cookie);
1279 return success;
1280}
1281
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001282void IncrementalService::registerAppOpsCallback(const std::string& packageName) {
1283 if (packageName.empty()) {
1284 return;
1285 }
1286
1287 {
1288 std::unique_lock lock{mCallbacksLock};
1289 if (!mCallbackRegistered.insert(packageName).second) {
1290 return;
1291 }
1292 }
1293
1294 /* TODO(b/152633648): restore callback after it's not crashing Binder anymore.
1295 sp<AppOpsListener> listener = new AppOpsListener(*this, packageName);
1296 mAppOpsManager->startWatchingMode(AppOpsManager::OP_GET_USAGE_STATS, String16(packageName.c_str()), listener);
1297 */
1298}
1299
1300void IncrementalService::onAppOppChanged(const std::string& packageName) {
1301 std::vector<IfsMountPtr> affected;
1302 {
1303 std::lock_guard l(mLock);
1304 affected.reserve(mMounts.size());
1305 for (auto&& [id, ifs] : mMounts) {
1306 if (ifs->dataLoaderFilesystemParams.readLogsEnabled && ifs->dataLoaderParams.packageName == packageName) {
1307 affected.push_back(ifs);
1308 }
1309 }
1310 }
1311 /* TODO(b/152633648): restore callback after it's not crashing Kernel anymore.
1312 for (auto&& ifs : affected) {
1313 applyStorageParams(*ifs);
1314 }
1315 */
1316}
1317
Songchun Fan3c82a302019-11-29 14:23:45 -08001318binder::Status IncrementalService::IncrementalDataLoaderListener::onStatusChanged(MountId mountId,
1319 int newStatus) {
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001320 if (externalListener) {
1321 // Give an external listener a chance to act before we destroy something.
1322 externalListener->onStatusChanged(mountId, newStatus);
1323 }
1324
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001325 bool startRequested = false;
1326 {
1327 std::unique_lock l(incrementalService.mLock);
1328 const auto& ifs = incrementalService.getIfsLocked(mountId);
1329 if (!ifs) {
Songchun Fan306b7df2020-03-17 12:37:07 -07001330 LOG(WARNING) << "Received data loader status " << int(newStatus)
1331 << " for unknown mount " << mountId;
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001332 return binder::Status::ok();
1333 }
1334 ifs->dataLoaderStatus = newStatus;
1335
1336 if (newStatus == IDataLoaderStatusListener::DATA_LOADER_DESTROYED) {
1337 ifs->dataLoaderStatus = IDataLoaderStatusListener::DATA_LOADER_STOPPED;
1338 incrementalService.deleteStorageLocked(*ifs, std::move(l));
1339 return binder::Status::ok();
1340 }
1341
1342 startRequested = ifs->dataLoaderStartRequested;
Songchun Fan3c82a302019-11-29 14:23:45 -08001343 }
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001344
Songchun Fan3c82a302019-11-29 14:23:45 -08001345 switch (newStatus) {
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001346 case IDataLoaderStatusListener::DATA_LOADER_CREATED: {
Alex Buynytskyybf1c0632020-03-10 15:49:29 -07001347 if (startRequested) {
1348 incrementalService.startDataLoader(mountId);
1349 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001350 break;
1351 }
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001352 case IDataLoaderStatusListener::DATA_LOADER_DESTROYED: {
Songchun Fan3c82a302019-11-29 14:23:45 -08001353 break;
1354 }
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -08001355 case IDataLoaderStatusListener::DATA_LOADER_STARTED: {
Songchun Fan3c82a302019-11-29 14:23:45 -08001356 break;
1357 }
1358 case IDataLoaderStatusListener::DATA_LOADER_STOPPED: {
1359 break;
1360 }
Alex Buynytskyy04f73912020-02-10 08:34:18 -08001361 case IDataLoaderStatusListener::DATA_LOADER_IMAGE_READY: {
1362 break;
1363 }
1364 case IDataLoaderStatusListener::DATA_LOADER_IMAGE_NOT_READY: {
1365 break;
1366 }
Alex Buynytskyy2cf1d182020-03-17 09:33:45 -07001367 case IDataLoaderStatusListener::DATA_LOADER_UNRECOVERABLE: {
1368 // Nothing for now. Rely on externalListener to handle this.
1369 break;
1370 }
Songchun Fan3c82a302019-11-29 14:23:45 -08001371 default: {
1372 LOG(WARNING) << "Unknown data loader status: " << newStatus
1373 << " for mount: " << mountId;
1374 break;
1375 }
1376 }
1377
1378 return binder::Status::ok();
1379}
1380
Alex Buynytskyy96e350b2020-04-02 20:03:47 -07001381void IncrementalService::AppOpsListener::opChanged(int32_t op, const String16&) {
1382 incrementalService.onAppOppChanged(packageName);
1383}
1384
Songchun Fan3c82a302019-11-29 14:23:45 -08001385} // namespace android::incremental