blob: f17f59f80206486d494fc97afd1dd92a6adfbd61 [file] [log] [blame]
Jeff Sharkey068c6be2017-09-06 13:47:40 -06001/*
2 * Copyright (C) 2017 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
Jeff Sharkey67b8c492017-09-21 17:08:43 -060017#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
18
Jeff Sharkey068c6be2017-09-06 13:47:40 -060019#include "VoldNativeService.h"
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -060020#include "Benchmark.h"
Jeff Sharkey2048a282017-06-15 09:59:43 -060021#include "CheckEncryption.h"
22#include "IdleMaint.h"
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -060023#include "MoveStorage.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060024#include "Process.h"
Jeff Sharkey2048a282017-06-15 09:59:43 -060025#include "VolumeManager.h"
Jeff Sharkey068c6be2017-09-06 13:47:40 -060026
Daniel Rosenberg4f684712018-08-28 01:58:49 -070027#include "Checkpoint.h"
Eric Biggersa701c452018-10-23 13:06:55 -070028#include "FsCrypt.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060029#include "MetadataCrypt.h"
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070030#include "cryptfs.h"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060031
Jeff Sharkey068c6be2017-09-06 13:47:40 -060032#include <fstream>
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -060033#include <thread>
Jeff Sharkey068c6be2017-09-06 13:47:40 -060034
35#include <android-base/logging.h>
36#include <android-base/stringprintf.h>
37#include <android-base/strings.h>
Jeff Sharkey11c2d382017-09-11 10:32:01 -060038#include <fs_mgr.h>
Eric Biggersa701c452018-10-23 13:06:55 -070039#include <fscrypt/fscrypt.h>
Jeff Sharkey068c6be2017-09-06 13:47:40 -060040#include <private/android_filesystem_config.h>
Jeff Sharkey67b8c492017-09-21 17:08:43 -060041#include <utils/Trace.h>
Jeff Sharkey068c6be2017-09-06 13:47:40 -060042
Jeff Sharkey068c6be2017-09-06 13:47:40 -060043using android::base::StringPrintf;
44using std::endl;
45
46namespace android {
47namespace vold {
48
49namespace {
50
51constexpr const char* kDump = "android.permission.DUMP";
52
53static binder::Status ok() {
54 return binder::Status::ok();
55}
56
57static binder::Status exception(uint32_t code, const std::string& msg) {
58 return binder::Status::fromExceptionCode(code, String8(msg.c_str()));
59}
60
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060061static binder::Status error(const std::string& msg) {
62 PLOG(ERROR) << msg;
63 return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
64}
65
Jeff Sharkey83b559c2017-09-12 16:30:52 -060066static binder::Status translate(int status) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060067 if (status == 0) {
68 return binder::Status::ok();
69 } else {
Jeff Sharkey11c2d382017-09-11 10:32:01 -060070 return binder::Status::fromServiceSpecificError(status);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -060071 }
72}
73
Jeff Sharkey83b559c2017-09-12 16:30:52 -060074static binder::Status translateBool(bool status) {
75 if (status) {
76 return binder::Status::ok();
77 } else {
78 return binder::Status::fromServiceSpecificError(status);
79 }
80}
81
Jeff Sharkey068c6be2017-09-06 13:47:40 -060082binder::Status checkPermission(const char* permission) {
83 pid_t pid;
84 uid_t uid;
85
86 if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070087 reinterpret_cast<int32_t*>(&uid))) {
Jeff Sharkey068c6be2017-09-06 13:47:40 -060088 return ok();
89 } else {
90 return exception(binder::Status::EX_SECURITY,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -070091 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission));
Jeff Sharkey068c6be2017-09-06 13:47:40 -060092 }
93}
94
Nikita Ioffee1fd4892019-10-23 17:19:13 +010095binder::Status checkUidOrRoot(uid_t expectedUid) {
Jeff Sharkey068c6be2017-09-06 13:47:40 -060096 uid_t uid = IPCThreadState::self()->getCallingUid();
97 if (uid == expectedUid || uid == AID_ROOT) {
98 return ok();
99 } else {
100 return exception(binder::Status::EX_SECURITY,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700101 StringPrintf("UID %d is not expected UID %d", uid, expectedUid));
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600102 }
103}
104
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600105binder::Status checkArgumentId(const std::string& id) {
106 if (id.empty()) {
107 return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing ID");
108 }
109 for (const char& c : id) {
110 if (!std::isalnum(c) && c != ':' && c != ',') {
111 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700112 StringPrintf("ID %s is malformed", id.c_str()));
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600113 }
114 }
115 return ok();
116}
117
118binder::Status checkArgumentPath(const std::string& path) {
119 if (path.empty()) {
120 return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing path");
121 }
122 if (path[0] != '/') {
123 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700124 StringPrintf("Path %s is relative", path.c_str()));
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600125 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600126 if ((path + '/').find("/../") != std::string::npos) {
127 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700128 StringPrintf("Path %s is shady", path.c_str()));
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600129 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600130 for (const char& c : path) {
131 if (c == '\0' || c == '\n') {
132 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700133 StringPrintf("Path %s is malformed", path.c_str()));
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600134 }
135 }
136 return ok();
137}
138
139binder::Status checkArgumentHex(const std::string& hex) {
140 // Empty hex strings are allowed
141 for (const char& c : hex) {
142 if (!std::isxdigit(c) && c != ':' && c != '-') {
143 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700144 StringPrintf("Hex %s is malformed", hex.c_str()));
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600145 }
146 }
147 return ok();
148}
149
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100150#define ENFORCE_SYSTEM_OR_ROOT \
151 { \
152 binder::Status status = checkUidOrRoot(AID_SYSTEM); \
153 if (!status.isOk()) { \
154 return status; \
155 } \
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700156 }
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600157
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700158#define CHECK_ARGUMENT_ID(id) \
159 { \
160 binder::Status status = checkArgumentId((id)); \
161 if (!status.isOk()) { \
162 return status; \
163 } \
164 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600165
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700166#define CHECK_ARGUMENT_PATH(path) \
167 { \
168 binder::Status status = checkArgumentPath((path)); \
169 if (!status.isOk()) { \
170 return status; \
171 } \
172 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600173
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700174#define CHECK_ARGUMENT_HEX(hex) \
175 { \
176 binder::Status status = checkArgumentHex((hex)); \
177 if (!status.isOk()) { \
178 return status; \
179 } \
180 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600181
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700182#define ACQUIRE_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600183 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
184 ATRACE_CALL();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600185
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700186#define ACQUIRE_CRYPT_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600187 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
188 ATRACE_CALL();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600189
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600190} // namespace
191
192status_t VoldNativeService::start() {
193 IPCThreadState::self()->disableBackgroundScheduling(true);
194 status_t ret = BinderService<VoldNativeService>::publish();
195 if (ret != android::OK) {
196 return ret;
197 }
198 sp<ProcessState> ps(ProcessState::self());
199 ps->startThreadPool();
200 ps->giveThreadPoolName();
201 return android::OK;
202}
203
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700204status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600205 auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd));
206 const binder::Status dump_permission = checkPermission(kDump);
207 if (!dump_permission.isOk()) {
208 out << dump_permission.toString8() << endl;
209 return PERMISSION_DENIED;
210 }
211
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600212 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600213 out << "vold is happy!" << endl;
214 out.flush();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600215 return NO_ERROR;
216}
217
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600218binder::Status VoldNativeService::setListener(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700219 const android::sp<android::os::IVoldListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100220 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600221 ACQUIRE_LOCK;
222
223 VolumeManager::Instance()->setListener(listener);
224 return ok();
225}
226
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600227binder::Status VoldNativeService::monitor() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100228 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600229
230 // Simply acquire/release each lock for watchdog
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700231 { ACQUIRE_LOCK; }
232 { ACQUIRE_CRYPT_LOCK; }
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600233
234 return ok();
235}
236
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600237binder::Status VoldNativeService::reset() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100238 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600239 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600240
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600241 return translate(VolumeManager::Instance()->reset());
242}
243
244binder::Status VoldNativeService::shutdown() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100245 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600246 ACQUIRE_LOCK;
247
248 return translate(VolumeManager::Instance()->shutdown());
249}
250
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600251binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100252 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600253 ACQUIRE_LOCK;
254
255 return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial));
256}
257
258binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100259 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600260 ACQUIRE_LOCK;
261
262 return translate(VolumeManager::Instance()->onUserRemoved(userId));
263}
264
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700265binder::Status VoldNativeService::onUserStarted(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100266 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600267 ACQUIRE_LOCK;
268
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700269 return translate(VolumeManager::Instance()->onUserStarted(userId));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600270}
271
272binder::Status VoldNativeService::onUserStopped(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100273 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600274 ACQUIRE_LOCK;
275
276 return translate(VolumeManager::Instance()->onUserStopped(userId));
277}
278
Sudheer Shankad484aa92018-07-31 10:07:34 -0700279binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700280 const std::vector<int32_t>& appIds) {
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700281 return ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700282}
283
Sudheer Shankad484aa92018-07-31 10:07:34 -0700284binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700285 const std::vector<std::string>& sandboxIds) {
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700286 return ok();
Sudheer Shankad484aa92018-07-31 10:07:34 -0700287}
288
Jeff Sharkey401b2602017-12-14 22:15:20 -0700289binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100290 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey401b2602017-12-14 22:15:20 -0700291 ACQUIRE_LOCK;
292
293 return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
294}
295
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600296binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700297 int32_t ratio) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100298 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600299 CHECK_ARGUMENT_ID(diskId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600300 ACQUIRE_LOCK;
301
302 auto disk = VolumeManager::Instance()->findDisk(diskId);
303 if (disk == nullptr) {
304 return error("Failed to find disk " + diskId);
305 }
306 switch (partitionType) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700307 case PARTITION_TYPE_PUBLIC:
308 return translate(disk->partitionPublic());
309 case PARTITION_TYPE_PRIVATE:
310 return translate(disk->partitionPrivate());
311 case PARTITION_TYPE_MIXED:
312 return translate(disk->partitionMixed(ratio));
313 default:
314 return error("Unknown type " + std::to_string(partitionType));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600315 }
316}
317
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600318binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700319 const std::string& fsUuid) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100320 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600321 CHECK_ARGUMENT_HEX(partGuid);
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600322 CHECK_ARGUMENT_HEX(fsUuid);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600323 ACQUIRE_LOCK;
324
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600325 return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600326}
327
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600328binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700329 int32_t mountUserId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100330 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600331 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600332 ACQUIRE_LOCK;
333
334 auto vol = VolumeManager::Instance()->findVolume(volId);
335 if (vol == nullptr) {
336 return error("Failed to find volume " + volId);
337 }
338
339 vol->setMountFlags(mountFlags);
340 vol->setMountUserId(mountUserId);
341
342 int res = vol->mount();
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700343 if (res != OK) {
344 return translate(res);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600345 }
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700346 if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) {
347 res = VolumeManager::Instance()->setPrimary(vol);
348 if (res != OK) {
349 return translate(res);
350 }
351 }
352 return translate(OK);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600353}
354
355binder::Status VoldNativeService::unmount(const std::string& volId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100356 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600357 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600358 ACQUIRE_LOCK;
359
360 auto vol = VolumeManager::Instance()->findVolume(volId);
361 if (vol == nullptr) {
362 return error("Failed to find volume " + volId);
363 }
364 return translate(vol->unmount());
365}
366
367binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100368 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600369 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600370 ACQUIRE_LOCK;
371
372 auto vol = VolumeManager::Instance()->findVolume(volId);
373 if (vol == nullptr) {
374 return error("Failed to find volume " + volId);
375 }
376 return translate(vol->format(fsType));
377}
378
Jeff Sharkey2048a282017-06-15 09:59:43 -0600379static binder::Status pathForVolId(const std::string& volId, std::string* path) {
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600380 if (volId == "private" || volId == "null") {
Jeff Sharkey2048a282017-06-15 09:59:43 -0600381 *path = "/data";
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600382 } else {
383 auto vol = VolumeManager::Instance()->findVolume(volId);
384 if (vol == nullptr) {
385 return error("Failed to find volume " + volId);
386 }
387 if (vol->getType() != VolumeBase::Type::kPrivate) {
388 return error("Volume " + volId + " not private");
389 }
390 if (vol->getState() != VolumeBase::State::kMounted) {
391 return error("Volume " + volId + " not mounted");
392 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600393 *path = vol->getPath();
394 if (path->empty()) {
395 return error("Volume " + volId + " missing path");
396 }
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600397 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600398 return ok();
399}
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600400
Jeff Sharkey2048a282017-06-15 09:59:43 -0600401binder::Status VoldNativeService::benchmark(
402 const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100403 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey2048a282017-06-15 09:59:43 -0600404 CHECK_ARGUMENT_ID(volId);
405 ACQUIRE_LOCK;
406
407 std::string path;
408 auto status = pathForVolId(volId, &path);
409 if (!status.isOk()) return status;
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600410
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700411 std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600412 return ok();
413}
414
Jeff Sharkey2048a282017-06-15 09:59:43 -0600415binder::Status VoldNativeService::checkEncryption(const std::string& volId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100416 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey2048a282017-06-15 09:59:43 -0600417 CHECK_ARGUMENT_ID(volId);
418 ACQUIRE_LOCK;
419
420 std::string path;
421 auto status = pathForVolId(volId, &path);
422 if (!status.isOk()) return status;
423 return translate(android::vold::CheckEncryption(path));
424}
425
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700426binder::Status VoldNativeService::moveStorage(
427 const std::string& fromVolId, const std::string& toVolId,
428 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100429 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600430 CHECK_ARGUMENT_ID(fromVolId);
431 CHECK_ARGUMENT_ID(toVolId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600432 ACQUIRE_LOCK;
433
434 auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
435 auto toVol = VolumeManager::Instance()->findVolume(toVolId);
436 if (fromVol == nullptr) {
437 return error("Failed to find volume " + fromVolId);
438 } else if (toVol == nullptr) {
439 return error("Failed to find volume " + toVolId);
440 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600441
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700442 std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600443 return ok();
444}
445
446binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100447 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600448 ACQUIRE_LOCK;
449
Sudheer Shanka817b9112018-12-13 17:40:28 -0800450 return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600451}
452
453binder::Status VoldNativeService::mkdirs(const std::string& path) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100454 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600455 CHECK_ARGUMENT_PATH(path);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600456 ACQUIRE_LOCK;
457
Jeff Sharkey3472e522017-10-06 18:02:53 -0600458 return translate(VolumeManager::Instance()->mkdirs(path));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600459}
460
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600461binder::Status VoldNativeService::createObb(const std::string& sourcePath,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700462 const std::string& sourceKey, int32_t ownerGid,
463 std::string* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100464 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600465 CHECK_ARGUMENT_PATH(sourcePath);
466 CHECK_ARGUMENT_HEX(sourceKey);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600467 ACQUIRE_LOCK;
468
469 return translate(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700470 VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600471}
472
473binder::Status VoldNativeService::destroyObb(const std::string& volId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100474 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600475 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600476 ACQUIRE_LOCK;
477
478 return translate(VolumeManager::Instance()->destroyObb(volId));
479}
480
Risan8c9f3322018-10-29 08:52:56 +0900481binder::Status VoldNativeService::createStubVolume(
482 const std::string& sourcePath, const std::string& mountPath, const std::string& fsType,
483 const std::string& fsUuid, const std::string& fsLabel, std::string* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100484 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900485 CHECK_ARGUMENT_PATH(sourcePath);
486 CHECK_ARGUMENT_PATH(mountPath);
487 CHECK_ARGUMENT_HEX(fsUuid);
488 // Label limitation seems to be different between fs (including allowed characters), so checking
489 // is quite meaningless.
490 ACQUIRE_LOCK;
491
492 return translate(VolumeManager::Instance()->createStubVolume(sourcePath, mountPath, fsType,
493 fsUuid, fsLabel, _aidl_return));
494}
495
496binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100497 ENFORCE_SYSTEM_OR_ROOT;
Risan8c9f3322018-10-29 08:52:56 +0900498 CHECK_ARGUMENT_ID(volId);
499 ACQUIRE_LOCK;
500
501 return translate(VolumeManager::Instance()->destroyStubVolume(volId));
502}
503
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700504binder::Status VoldNativeService::fstrim(
505 int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100506 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600507 ACQUIRE_LOCK;
508
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700509 std::thread([=]() { android::vold::Trim(listener); }).detach();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600510 return ok();
511}
512
Jin Qiana370c142017-10-17 15:41:45 -0700513binder::Status VoldNativeService::runIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700514 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100515 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700516 ACQUIRE_LOCK;
517
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700518 std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700519 return ok();
520}
521
522binder::Status VoldNativeService::abortIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700523 const android::sp<android::os::IVoldTaskListener>& listener) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100524 ENFORCE_SYSTEM_OR_ROOT;
Jin Qiana370c142017-10-17 15:41:45 -0700525 ACQUIRE_LOCK;
526
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700527 std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700528 return ok();
529}
530
Risan8f6198d2018-10-26 20:56:45 -0600531binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700532 android::base::unique_fd* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100533 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600534 ACQUIRE_LOCK;
535
Risan8f6198d2018-10-26 20:56:45 -0600536 return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600537}
538
Risan8f6198d2018-10-26 20:56:45 -0600539binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100540 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600541 ACQUIRE_LOCK;
542
Risan8f6198d2018-10-26 20:56:45 -0600543 return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
544}
545
546binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
547 int32_t flags,
548 android::base::unique_fd* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100549 ENFORCE_SYSTEM_OR_ROOT;
Risan8f6198d2018-10-26 20:56:45 -0600550 ACQUIRE_LOCK;
551
552 int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
553 if (fd == -1) {
554 return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
555 " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
556 " flags: " + std::to_string(flags));
557 }
558
559 *_aidl_return = android::base::unique_fd(fd);
560 return ok();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600561}
562
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600563binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100564 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600565 ACQUIRE_CRYPT_LOCK;
566
567 return translate(cryptfs_check_passwd(password.c_str()));
568}
569
570binder::Status VoldNativeService::fdeRestart() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100571 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600572 ACQUIRE_CRYPT_LOCK;
573
574 // Spawn as thread so init can issue commands back to vold without
575 // causing deadlock, usually as a result of prep_data_fs.
576 std::thread(&cryptfs_restart).detach();
577 return ok();
578}
579
580binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100581 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600582 ACQUIRE_CRYPT_LOCK;
583
584 *_aidl_return = cryptfs_crypto_complete();
585 return ok();
586}
587
588static int fdeEnableInternal(int32_t passwordType, const std::string& password,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700589 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600590 bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
591
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600592 for (int tries = 0; tries < 2; ++tries) {
593 int rc;
594 if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800595 rc = cryptfs_enable_default(noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600596 } else {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800597 rc = cryptfs_enable(passwordType, password.c_str(), noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600598 }
599
600 if (rc == 0) {
601 return 0;
602 } else if (tries == 0) {
Jeff Sharkey3472e522017-10-06 18:02:53 -0600603 KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600604 }
605 }
606
607 return -1;
608}
609
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700610binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
611 int32_t encryptionFlags) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100612 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600613 ACQUIRE_CRYPT_LOCK;
614
Paul Crowley0fd26262018-01-30 09:48:19 -0800615 LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")";
Eric Biggersa701c452018-10-23 13:06:55 -0700616 if (fscrypt_is_native()) {
617 LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid";
618 return error("fscrypt_is_native, fdeEnable invalid");
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600619 }
Eric Biggersa701c452018-10-23 13:06:55 -0700620 LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal";
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600621
622 // Spawn as thread so init can issue commands back to vold without
623 // causing deadlock, usually as a result of prep_data_fs.
624 std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach();
625 return ok();
626}
627
628binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700629 const std::string& password) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100630 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600631 ACQUIRE_CRYPT_LOCK;
632
633 return translate(cryptfs_changepw(passwordType, password.c_str()));
634}
635
636binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100637 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600638 ACQUIRE_CRYPT_LOCK;
639
640 return translate(cryptfs_verify_passwd(password.c_str()));
641}
642
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700643binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100644 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600645 ACQUIRE_CRYPT_LOCK;
646
647 char buf[PROPERTY_VALUE_MAX];
648 if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) {
649 return error(StringPrintf("Failed to read field %s", key.c_str()));
650 } else {
651 *_aidl_return = buf;
652 return ok();
653 }
654}
655
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700656binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100657 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600658 ACQUIRE_CRYPT_LOCK;
659
660 return translate(cryptfs_setfield(key.c_str(), value.c_str()));
661}
662
663binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100664 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600665 ACQUIRE_CRYPT_LOCK;
666
667 *_aidl_return = cryptfs_get_password_type();
668 return ok();
669}
670
671binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100672 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600673 ACQUIRE_CRYPT_LOCK;
674
675 const char* res = cryptfs_get_password();
676 if (res != nullptr) {
677 *_aidl_return = res;
678 }
679 return ok();
680}
681
682binder::Status VoldNativeService::fdeClearPassword() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100683 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600684 ACQUIRE_CRYPT_LOCK;
685
686 cryptfs_clear_password();
687 return ok();
688}
689
690binder::Status VoldNativeService::fbeEnable() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100691 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600692 ACQUIRE_CRYPT_LOCK;
693
Paul Crowleyc8a3ef32019-09-11 15:00:08 -0700694 return translateBool(fscrypt_initialize_systemwide_keys());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600695}
696
697binder::Status VoldNativeService::mountDefaultEncrypted() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100698 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600699 ACQUIRE_CRYPT_LOCK;
700
Eric Biggersa701c452018-10-23 13:06:55 -0700701 if (!fscrypt_is_native()) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600702 // Spawn as thread so init can issue commands back to vold without
703 // causing deadlock, usually as a result of prep_data_fs.
704 std::thread(&cryptfs_mount_default_encrypted).detach();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600705 }
Paul Crowley0fd26262018-01-30 09:48:19 -0800706 return ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600707}
708
709binder::Status VoldNativeService::initUser0() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100710 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600711 ACQUIRE_CRYPT_LOCK;
712
Eric Biggersa701c452018-10-23 13:06:55 -0700713 return translateBool(fscrypt_init_user0());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600714}
715
716binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100717 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600718 ACQUIRE_CRYPT_LOCK;
719
720 *_aidl_return = cryptfs_isConvertibleToFBE() != 0;
721 return ok();
722}
723
Paul Lawrence236e5e82019-06-25 14:44:33 -0700724binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
725 const std::string& mountPoint) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100726 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800727 ACQUIRE_LOCK;
728
Paul Lawrence236e5e82019-06-25 14:44:33 -0700729 return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false));
Paul Crowley0fd26262018-01-30 09:48:19 -0800730}
731
Paul Lawrence236e5e82019-06-25 14:44:33 -0700732binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
733 const std::string& mountPoint) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100734 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley0fd26262018-01-30 09:48:19 -0800735 ACQUIRE_LOCK;
736
Paul Lawrence236e5e82019-06-25 14:44:33 -0700737 return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true));
Paul Crowley0fd26262018-01-30 09:48:19 -0800738}
739
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700740binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100741 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600742 ACQUIRE_CRYPT_LOCK;
743
Eric Biggersa701c452018-10-23 13:06:55 -0700744 return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600745}
746
747binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100748 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600749 ACQUIRE_CRYPT_LOCK;
750
Eric Biggersa701c452018-10-23 13:06:55 -0700751 return translateBool(fscrypt_destroy_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600752}
753
754binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700755 const std::string& token,
756 const std::string& secret) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100757 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600758 ACQUIRE_CRYPT_LOCK;
759
Eric Biggersa701c452018-10-23 13:06:55 -0700760 return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600761}
762
763binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100764 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600765 ACQUIRE_CRYPT_LOCK;
766
Eric Biggersa701c452018-10-23 13:06:55 -0700767 return translateBool(fscrypt_fixate_newest_user_key_auth(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600768}
769
770binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700771 const std::string& token,
772 const std::string& secret) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100773 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600774 ACQUIRE_CRYPT_LOCK;
775
Eric Biggersa701c452018-10-23 13:06:55 -0700776 return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600777}
778
779binder::Status VoldNativeService::lockUserKey(int32_t userId) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100780 ENFORCE_SYSTEM_OR_ROOT;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600781 ACQUIRE_CRYPT_LOCK;
782
Eric Biggersa701c452018-10-23 13:06:55 -0700783 return translateBool(fscrypt_lock_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600784}
785
786binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700787 int32_t userId, int32_t userSerial,
788 int32_t flags) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100789 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700790 std::string empty_string = "";
791 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700792 CHECK_ARGUMENT_HEX(uuid_);
793
794 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700795 return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600796}
797
798binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700799 int32_t userId, int32_t flags) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100800 ENFORCE_SYSTEM_OR_ROOT;
Paul Crowley3b71fc52017-10-09 10:55:21 -0700801 std::string empty_string = "";
802 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700803 CHECK_ARGUMENT_HEX(uuid_);
804
805 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700806 return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600807}
808
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700809binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
810 int32_t appId, const std::string& sandboxId,
811 int32_t userId) {
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700812 return ok();
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700813}
814
815binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700816 const std::string& sandboxId,
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700817 int32_t userId) {
Sudheer Shanka5fceb482019-04-29 10:46:35 -0700818 return ok();
Sudheer Shankac7562092018-08-24 10:20:56 -0700819}
820
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700821binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100822 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700823 ACQUIRE_LOCK;
824
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700825 return cp_startCheckpoint(retry);
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700826}
827
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700828binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100829 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700830 ACQUIRE_LOCK;
831
832 *_aidl_return = cp_needsRollback();
833 return ok();
834}
835
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700836binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100837 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700838 ACQUIRE_LOCK;
839
840 *_aidl_return = cp_needsCheckpoint();
841 return ok();
842}
843
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700844binder::Status VoldNativeService::commitChanges() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100845 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700846 ACQUIRE_LOCK;
847
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700848 return cp_commitChanges();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700849}
850
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700851binder::Status VoldNativeService::prepareCheckpoint() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100852 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700853 ACQUIRE_LOCK;
854
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700855 return cp_prepareCheckpoint();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700856}
857
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700858binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100859 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700860 CHECK_ARGUMENT_PATH(mountPoint);
861 ACQUIRE_LOCK;
862
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700863 return cp_restoreCheckpoint(mountPoint);
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700864}
865
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800866binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100867 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenbergdda59812019-03-06 17:45:17 -0800868 CHECK_ARGUMENT_PATH(mountPoint);
869 ACQUIRE_LOCK;
870
871 return cp_restoreCheckpoint(mountPoint, count);
872}
873
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700874binder::Status VoldNativeService::markBootAttempt() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100875 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700876 ACQUIRE_LOCK;
877
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700878 return cp_markBootAttempt();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700879}
880
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700881binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100882 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700883 ACQUIRE_LOCK;
884
Daniel Rosenberga59e4392019-03-20 17:02:47 -0700885 cp_abortChanges(message, retry);
886 return ok();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700887}
888
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800889binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100890 ENFORCE_SYSTEM_OR_ROOT;
Daniel Rosenberg9b667fb2019-01-22 17:27:25 -0800891 ACQUIRE_LOCK;
892
893 return cp_supportsCheckpoint(*_aidl_return);
894}
895
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700896binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100897 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700898 ACQUIRE_LOCK;
899
900 return cp_supportsBlockCheckpoint(*_aidl_return);
901}
902
903binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100904 ENFORCE_SYSTEM_OR_ROOT;
Paul Lawrencec5c79c52019-03-18 13:36:40 -0700905 ACQUIRE_LOCK;
906
907 return cp_supportsFileCheckpoint(*_aidl_return);
908}
909
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100910binder::Status VoldNativeService::resetCheckpoint() {
Nikita Ioffee1fd4892019-10-23 17:19:13 +0100911 ENFORCE_SYSTEM_OR_ROOT;
Nikita Ioffea5798fc2019-10-11 16:38:21 +0100912 ACQUIRE_LOCK;
913
914 cp_resetCheckpoint();
915 return ok();
916}
917
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600918} // namespace vold
919} // namespace android