blob: 2696e300537119816dfc936d3ad2c8a5dd22eeec [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
95binder::Status checkUid(uid_t expectedUid) {
96 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
Sudheer Shankacc0df592018-08-02 10:21:42 -0700150binder::Status checkArgumentPackageName(const std::string& packageName) {
151 // This logic is borrowed from PackageParser.java
152 bool hasSep = false;
153 bool front = true;
154
155 for (size_t i = 0; i < packageName.length(); ++i) {
156 char c = packageName[i];
157 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
158 front = false;
159 continue;
160 }
161 if (!front) {
162 if ((c >= '0' && c <= '9') || c == '_') {
163 continue;
164 }
165 }
166 if (c == '.') {
167 hasSep = true;
168 front = true;
169 continue;
170 }
171 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700172 StringPrintf("Bad package character %c in %s", c, packageName.c_str()));
Sudheer Shankacc0df592018-08-02 10:21:42 -0700173 }
174
175 if (front) {
176 return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700177 StringPrintf("Missing separator in %s", packageName.c_str()));
Sudheer Shankacc0df592018-08-02 10:21:42 -0700178 }
179
180 return ok();
181}
182
183binder::Status checkArgumentPackageNames(const std::vector<std::string>& packageNames) {
184 for (size_t i = 0; i < packageNames.size(); ++i) {
185 binder::Status status = checkArgumentPackageName(packageNames[i]);
186 if (!status.isOk()) {
187 return status;
188 }
189 }
190 return ok();
191}
192
193binder::Status checkArgumentSandboxId(const std::string& sandboxId) {
194 // sandboxId will be in either the format shared:<shared-user-id> or <package-name>
195 // and <shared-user-id> name has same requirements as <package-name>.
196 std::size_t nameStartIndex = 0;
Greg Kaisere3f59322018-08-06 06:16:29 -0700197 if (android::base::StartsWith(sandboxId, "shared:")) {
198 nameStartIndex = 7; // len("shared:")
Sudheer Shankacc0df592018-08-02 10:21:42 -0700199 }
200 return checkArgumentPackageName(sandboxId.substr(nameStartIndex));
201}
202
203binder::Status checkArgumentSandboxIds(const std::vector<std::string>& sandboxIds) {
204 for (size_t i = 0; i < sandboxIds.size(); ++i) {
205 binder::Status status = checkArgumentSandboxId(sandboxIds[i]);
206 if (!status.isOk()) {
207 return status;
208 }
209 }
210 return ok();
211}
212
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700213#define ENFORCE_UID(uid) \
214 { \
215 binder::Status status = checkUid((uid)); \
216 if (!status.isOk()) { \
217 return status; \
218 } \
219 }
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600220
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700221#define CHECK_ARGUMENT_ID(id) \
222 { \
223 binder::Status status = checkArgumentId((id)); \
224 if (!status.isOk()) { \
225 return status; \
226 } \
227 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600228
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700229#define CHECK_ARGUMENT_PATH(path) \
230 { \
231 binder::Status status = checkArgumentPath((path)); \
232 if (!status.isOk()) { \
233 return status; \
234 } \
235 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600236
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700237#define CHECK_ARGUMENT_HEX(hex) \
238 { \
239 binder::Status status = checkArgumentHex((hex)); \
240 if (!status.isOk()) { \
241 return status; \
242 } \
243 }
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600244
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700245#define CHECK_ARGUMENT_PACKAGE_NAMES(packageNames) \
246 { \
247 binder::Status status = checkArgumentPackageNames((packageNames)); \
248 if (!status.isOk()) { \
249 return status; \
250 } \
251 }
Sudheer Shankacc0df592018-08-02 10:21:42 -0700252
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700253#define CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds) \
254 { \
255 binder::Status status = checkArgumentSandboxIds((sandboxIds)); \
256 if (!status.isOk()) { \
257 return status; \
258 } \
259 }
Sudheer Shankacc0df592018-08-02 10:21:42 -0700260
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700261#define CHECK_ARGUMENT_PACKAGE_NAME(packageName) \
262 { \
263 binder::Status status = checkArgumentPackageName((packageName)); \
264 if (!status.isOk()) { \
265 return status; \
266 } \
267 }
Sudheer Shankac7562092018-08-24 10:20:56 -0700268
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700269#define CHECK_ARGUMENT_SANDBOX_ID(sandboxId) \
270 { \
271 binder::Status status = checkArgumentSandboxId((sandboxId)); \
272 if (!status.isOk()) { \
273 return status; \
274 } \
275 }
Sudheer Shankac7562092018-08-24 10:20:56 -0700276
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700277#define ACQUIRE_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600278 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
279 ATRACE_CALL();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600280
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700281#define ACQUIRE_CRYPT_LOCK \
Jeff Sharkey67b8c492017-09-21 17:08:43 -0600282 std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
283 ATRACE_CALL();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600284
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600285} // namespace
286
287status_t VoldNativeService::start() {
288 IPCThreadState::self()->disableBackgroundScheduling(true);
289 status_t ret = BinderService<VoldNativeService>::publish();
290 if (ret != android::OK) {
291 return ret;
292 }
293 sp<ProcessState> ps(ProcessState::self());
294 ps->startThreadPool();
295 ps->giveThreadPoolName();
296 return android::OK;
297}
298
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700299status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600300 auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd));
301 const binder::Status dump_permission = checkPermission(kDump);
302 if (!dump_permission.isOk()) {
303 out << dump_permission.toString8() << endl;
304 return PERMISSION_DENIED;
305 }
306
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600307 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600308 out << "vold is happy!" << endl;
309 out.flush();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600310 return NO_ERROR;
311}
312
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600313binder::Status VoldNativeService::setListener(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700314 const android::sp<android::os::IVoldListener>& listener) {
Jeff Sharkey814e9d32017-09-13 11:49:44 -0600315 ENFORCE_UID(AID_SYSTEM);
316 ACQUIRE_LOCK;
317
318 VolumeManager::Instance()->setListener(listener);
319 return ok();
320}
321
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600322binder::Status VoldNativeService::monitor() {
323 ENFORCE_UID(AID_SYSTEM);
324
325 // Simply acquire/release each lock for watchdog
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700326 { ACQUIRE_LOCK; }
327 { ACQUIRE_CRYPT_LOCK; }
Jeff Sharkeycbe69fc2017-09-15 16:50:28 -0600328
329 return ok();
330}
331
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600332binder::Status VoldNativeService::reset() {
333 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600334 ACQUIRE_LOCK;
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600335
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600336 return translate(VolumeManager::Instance()->reset());
337}
338
339binder::Status VoldNativeService::shutdown() {
340 ENFORCE_UID(AID_SYSTEM);
341 ACQUIRE_LOCK;
342
343 return translate(VolumeManager::Instance()->shutdown());
344}
345
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600346binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) {
347 ENFORCE_UID(AID_SYSTEM);
348 ACQUIRE_LOCK;
349
350 return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial));
351}
352
353binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
354 ENFORCE_UID(AID_SYSTEM);
355 ACQUIRE_LOCK;
356
357 return translate(VolumeManager::Instance()->onUserRemoved(userId));
358}
359
Sudheer Shankaebaad1c2018-07-31 16:39:59 -0700360binder::Status VoldNativeService::onUserStarted(int32_t userId,
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700361 const std::vector<std::string>& packageNames,
362 const std::vector<int>& appIds,
363 const std::vector<std::string>& sandboxIds) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600364 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700365 CHECK_ARGUMENT_PACKAGE_NAMES(packageNames);
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700366 CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600367 ACQUIRE_LOCK;
368
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700369 return translate(
370 VolumeManager::Instance()->onUserStarted(userId, packageNames, appIds, sandboxIds));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600371}
372
373binder::Status VoldNativeService::onUserStopped(int32_t userId) {
374 ENFORCE_UID(AID_SYSTEM);
375 ACQUIRE_LOCK;
376
377 return translate(VolumeManager::Instance()->onUserStopped(userId));
378}
379
Sudheer Shankad484aa92018-07-31 10:07:34 -0700380binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700381 const std::vector<int32_t>& appIds) {
Sudheer Shankad484aa92018-07-31 10:07:34 -0700382 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700383 CHECK_ARGUMENT_PACKAGE_NAMES(packageNames);
Sudheer Shankad484aa92018-07-31 10:07:34 -0700384 ACQUIRE_LOCK;
385
386 return translate(VolumeManager::Instance()->addAppIds(packageNames, appIds));
387}
388
Sudheer Shankad484aa92018-07-31 10:07:34 -0700389binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700390 const std::vector<std::string>& sandboxIds) {
Sudheer Shankad484aa92018-07-31 10:07:34 -0700391 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700392 CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds);
Sudheer Shankad484aa92018-07-31 10:07:34 -0700393 ACQUIRE_LOCK;
394
395 return translate(VolumeManager::Instance()->addSandboxIds(appIds, sandboxIds));
396}
397
Jeff Sharkey401b2602017-12-14 22:15:20 -0700398binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
399 ENFORCE_UID(AID_SYSTEM);
400 ACQUIRE_LOCK;
401
402 return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
403}
404
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600405binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700406 int32_t ratio) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600407 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600408 CHECK_ARGUMENT_ID(diskId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600409 ACQUIRE_LOCK;
410
411 auto disk = VolumeManager::Instance()->findDisk(diskId);
412 if (disk == nullptr) {
413 return error("Failed to find disk " + diskId);
414 }
415 switch (partitionType) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700416 case PARTITION_TYPE_PUBLIC:
417 return translate(disk->partitionPublic());
418 case PARTITION_TYPE_PRIVATE:
419 return translate(disk->partitionPrivate());
420 case PARTITION_TYPE_MIXED:
421 return translate(disk->partitionMixed(ratio));
422 default:
423 return error("Unknown type " + std::to_string(partitionType));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600424 }
425}
426
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600427binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700428 const std::string& fsUuid) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600429 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600430 CHECK_ARGUMENT_HEX(partGuid);
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600431 CHECK_ARGUMENT_HEX(fsUuid);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600432 ACQUIRE_LOCK;
433
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600434 return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600435}
436
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600437binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700438 int32_t mountUserId) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600439 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600440 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600441 ACQUIRE_LOCK;
442
443 auto vol = VolumeManager::Instance()->findVolume(volId);
444 if (vol == nullptr) {
445 return error("Failed to find volume " + volId);
446 }
447
448 vol->setMountFlags(mountFlags);
449 vol->setMountUserId(mountUserId);
450
451 int res = vol->mount();
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700452 if (res != OK) {
453 return translate(res);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600454 }
Sudheer Shanka40ab6742018-09-18 13:07:45 -0700455 if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) {
456 res = VolumeManager::Instance()->setPrimary(vol);
457 if (res != OK) {
458 return translate(res);
459 }
460 }
461 return translate(OK);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600462}
463
464binder::Status VoldNativeService::unmount(const std::string& volId) {
465 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600466 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600467 ACQUIRE_LOCK;
468
469 auto vol = VolumeManager::Instance()->findVolume(volId);
470 if (vol == nullptr) {
471 return error("Failed to find volume " + volId);
472 }
473 return translate(vol->unmount());
474}
475
476binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
477 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600478 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600479 ACQUIRE_LOCK;
480
481 auto vol = VolumeManager::Instance()->findVolume(volId);
482 if (vol == nullptr) {
483 return error("Failed to find volume " + volId);
484 }
485 return translate(vol->format(fsType));
486}
487
Jeff Sharkey2048a282017-06-15 09:59:43 -0600488static binder::Status pathForVolId(const std::string& volId, std::string* path) {
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600489 if (volId == "private" || volId == "null") {
Jeff Sharkey2048a282017-06-15 09:59:43 -0600490 *path = "/data";
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600491 } else {
492 auto vol = VolumeManager::Instance()->findVolume(volId);
493 if (vol == nullptr) {
494 return error("Failed to find volume " + volId);
495 }
496 if (vol->getType() != VolumeBase::Type::kPrivate) {
497 return error("Volume " + volId + " not private");
498 }
499 if (vol->getState() != VolumeBase::State::kMounted) {
500 return error("Volume " + volId + " not mounted");
501 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600502 *path = vol->getPath();
503 if (path->empty()) {
504 return error("Volume " + volId + " missing path");
505 }
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600506 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600507 return ok();
508}
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600509
Jeff Sharkey2048a282017-06-15 09:59:43 -0600510binder::Status VoldNativeService::benchmark(
511 const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
512 ENFORCE_UID(AID_SYSTEM);
513 CHECK_ARGUMENT_ID(volId);
514 ACQUIRE_LOCK;
515
516 std::string path;
517 auto status = pathForVolId(volId, &path);
518 if (!status.isOk()) return status;
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600519
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700520 std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600521 return ok();
522}
523
Jeff Sharkey2048a282017-06-15 09:59:43 -0600524binder::Status VoldNativeService::checkEncryption(const std::string& volId) {
525 ENFORCE_UID(AID_SYSTEM);
526 CHECK_ARGUMENT_ID(volId);
527 ACQUIRE_LOCK;
528
529 std::string path;
530 auto status = pathForVolId(volId, &path);
531 if (!status.isOk()) return status;
532 return translate(android::vold::CheckEncryption(path));
533}
534
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700535binder::Status VoldNativeService::moveStorage(
536 const std::string& fromVolId, const std::string& toVolId,
537 const android::sp<android::os::IVoldTaskListener>& listener) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600538 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600539 CHECK_ARGUMENT_ID(fromVolId);
540 CHECK_ARGUMENT_ID(toVolId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600541 ACQUIRE_LOCK;
542
543 auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
544 auto toVol = VolumeManager::Instance()->findVolume(toVolId);
545 if (fromVol == nullptr) {
546 return error("Failed to find volume " + fromVolId);
547 } else if (toVol == nullptr) {
548 return error("Failed to find volume " + toVolId);
549 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600550
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700551 std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600552 return ok();
553}
554
555binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
556 ENFORCE_UID(AID_SYSTEM);
557 ACQUIRE_LOCK;
558
559 std::string tmp;
560 switch (remountMode) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700561 case REMOUNT_MODE_NONE:
562 tmp = "none";
563 break;
564 case REMOUNT_MODE_DEFAULT:
565 tmp = "default";
566 break;
567 case REMOUNT_MODE_READ:
568 tmp = "read";
569 break;
570 case REMOUNT_MODE_WRITE:
571 tmp = "write";
572 break;
573 default:
574 return error("Unknown mode " + std::to_string(remountMode));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600575 }
576 return translate(VolumeManager::Instance()->remountUid(uid, tmp));
577}
578
579binder::Status VoldNativeService::mkdirs(const std::string& path) {
580 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600581 CHECK_ARGUMENT_PATH(path);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600582 ACQUIRE_LOCK;
583
Jeff Sharkey3472e522017-10-06 18:02:53 -0600584 return translate(VolumeManager::Instance()->mkdirs(path));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600585}
586
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600587binder::Status VoldNativeService::createObb(const std::string& sourcePath,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700588 const std::string& sourceKey, int32_t ownerGid,
589 std::string* _aidl_return) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600590 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600591 CHECK_ARGUMENT_PATH(sourcePath);
592 CHECK_ARGUMENT_HEX(sourceKey);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600593 ACQUIRE_LOCK;
594
595 return translate(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700596 VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600597}
598
599binder::Status VoldNativeService::destroyObb(const std::string& volId) {
600 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600601 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600602 ACQUIRE_LOCK;
603
604 return translate(VolumeManager::Instance()->destroyObb(volId));
605}
606
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700607binder::Status VoldNativeService::fstrim(
608 int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600609 ENFORCE_UID(AID_SYSTEM);
610 ACQUIRE_LOCK;
611
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700612 std::thread([=]() { android::vold::Trim(listener); }).detach();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600613 return ok();
614}
615
Jin Qiana370c142017-10-17 15:41:45 -0700616binder::Status VoldNativeService::runIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700617 const android::sp<android::os::IVoldTaskListener>& listener) {
Jin Qiana370c142017-10-17 15:41:45 -0700618 ENFORCE_UID(AID_SYSTEM);
619 ACQUIRE_LOCK;
620
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700621 std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700622 return ok();
623}
624
625binder::Status VoldNativeService::abortIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700626 const android::sp<android::os::IVoldTaskListener>& listener) {
Jin Qiana370c142017-10-17 15:41:45 -0700627 ENFORCE_UID(AID_SYSTEM);
628 ACQUIRE_LOCK;
629
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700630 std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700631 return ok();
632}
633
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600634binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700635 android::base::unique_fd* _aidl_return) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600636 ENFORCE_UID(AID_SYSTEM);
637 ACQUIRE_LOCK;
638
639 return translate(VolumeManager::Instance()->mountAppFuse(uid, pid, mountId, _aidl_return));
640}
641
642binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId) {
643 ENFORCE_UID(AID_SYSTEM);
644 ACQUIRE_LOCK;
645
646 return translate(VolumeManager::Instance()->unmountAppFuse(uid, pid, mountId));
647}
648
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600649binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
650 ENFORCE_UID(AID_SYSTEM);
651 ACQUIRE_CRYPT_LOCK;
652
653 return translate(cryptfs_check_passwd(password.c_str()));
654}
655
656binder::Status VoldNativeService::fdeRestart() {
657 ENFORCE_UID(AID_SYSTEM);
658 ACQUIRE_CRYPT_LOCK;
659
660 // Spawn as thread so init can issue commands back to vold without
661 // causing deadlock, usually as a result of prep_data_fs.
662 std::thread(&cryptfs_restart).detach();
663 return ok();
664}
665
666binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
667 ENFORCE_UID(AID_SYSTEM);
668 ACQUIRE_CRYPT_LOCK;
669
670 *_aidl_return = cryptfs_crypto_complete();
671 return ok();
672}
673
674static int fdeEnableInternal(int32_t passwordType, const std::string& password,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700675 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600676 bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
677
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600678 for (int tries = 0; tries < 2; ++tries) {
679 int rc;
680 if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800681 rc = cryptfs_enable_default(noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600682 } else {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800683 rc = cryptfs_enable(passwordType, password.c_str(), noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600684 }
685
686 if (rc == 0) {
687 return 0;
688 } else if (tries == 0) {
Jeff Sharkey3472e522017-10-06 18:02:53 -0600689 KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600690 }
691 }
692
693 return -1;
694}
695
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700696binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
697 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600698 ENFORCE_UID(AID_SYSTEM);
699 ACQUIRE_CRYPT_LOCK;
700
Paul Crowley0fd26262018-01-30 09:48:19 -0800701 LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")";
Eric Biggersa701c452018-10-23 13:06:55 -0700702 if (fscrypt_is_native()) {
703 LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid";
704 return error("fscrypt_is_native, fdeEnable invalid");
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600705 }
Eric Biggersa701c452018-10-23 13:06:55 -0700706 LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal";
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600707
708 // Spawn as thread so init can issue commands back to vold without
709 // causing deadlock, usually as a result of prep_data_fs.
710 std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach();
711 return ok();
712}
713
714binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700715 const std::string& password) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600716 ENFORCE_UID(AID_SYSTEM);
717 ACQUIRE_CRYPT_LOCK;
718
719 return translate(cryptfs_changepw(passwordType, password.c_str()));
720}
721
722binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
723 ENFORCE_UID(AID_SYSTEM);
724 ACQUIRE_CRYPT_LOCK;
725
726 return translate(cryptfs_verify_passwd(password.c_str()));
727}
728
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700729binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600730 ENFORCE_UID(AID_SYSTEM);
731 ACQUIRE_CRYPT_LOCK;
732
733 char buf[PROPERTY_VALUE_MAX];
734 if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) {
735 return error(StringPrintf("Failed to read field %s", key.c_str()));
736 } else {
737 *_aidl_return = buf;
738 return ok();
739 }
740}
741
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700742binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600743 ENFORCE_UID(AID_SYSTEM);
744 ACQUIRE_CRYPT_LOCK;
745
746 return translate(cryptfs_setfield(key.c_str(), value.c_str()));
747}
748
749binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
750 ENFORCE_UID(AID_SYSTEM);
751 ACQUIRE_CRYPT_LOCK;
752
753 *_aidl_return = cryptfs_get_password_type();
754 return ok();
755}
756
757binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
758 ENFORCE_UID(AID_SYSTEM);
759 ACQUIRE_CRYPT_LOCK;
760
761 const char* res = cryptfs_get_password();
762 if (res != nullptr) {
763 *_aidl_return = res;
764 }
765 return ok();
766}
767
768binder::Status VoldNativeService::fdeClearPassword() {
769 ENFORCE_UID(AID_SYSTEM);
770 ACQUIRE_CRYPT_LOCK;
771
772 cryptfs_clear_password();
773 return ok();
774}
775
776binder::Status VoldNativeService::fbeEnable() {
777 ENFORCE_UID(AID_SYSTEM);
778 ACQUIRE_CRYPT_LOCK;
779
Eric Biggersa701c452018-10-23 13:06:55 -0700780 return translateBool(fscrypt_initialize_global_de());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600781}
782
783binder::Status VoldNativeService::mountDefaultEncrypted() {
784 ENFORCE_UID(AID_SYSTEM);
785 ACQUIRE_CRYPT_LOCK;
786
Eric Biggersa701c452018-10-23 13:06:55 -0700787 if (!fscrypt_is_native()) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600788 // Spawn as thread so init can issue commands back to vold without
789 // causing deadlock, usually as a result of prep_data_fs.
790 std::thread(&cryptfs_mount_default_encrypted).detach();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600791 }
Paul Crowley0fd26262018-01-30 09:48:19 -0800792 return ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600793}
794
795binder::Status VoldNativeService::initUser0() {
796 ENFORCE_UID(AID_SYSTEM);
797 ACQUIRE_CRYPT_LOCK;
798
Eric Biggersa701c452018-10-23 13:06:55 -0700799 return translateBool(fscrypt_init_user0());
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600800}
801
802binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
803 ENFORCE_UID(AID_SYSTEM);
804 ACQUIRE_CRYPT_LOCK;
805
806 *_aidl_return = cryptfs_isConvertibleToFBE() != 0;
807 return ok();
808}
809
Paul Crowley0fd26262018-01-30 09:48:19 -0800810binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) {
811 ENFORCE_UID(AID_SYSTEM);
812 ACQUIRE_LOCK;
813
Eric Biggersa701c452018-10-23 13:06:55 -0700814 return translateBool(fscrypt_mount_metadata_encrypted(mountPoint, false));
Paul Crowley0fd26262018-01-30 09:48:19 -0800815}
816
817binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) {
818 ENFORCE_UID(AID_SYSTEM);
819 ACQUIRE_LOCK;
820
Eric Biggersa701c452018-10-23 13:06:55 -0700821 return translateBool(fscrypt_mount_metadata_encrypted(mountPoint, true));
Paul Crowley0fd26262018-01-30 09:48:19 -0800822}
823
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700824binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600825 ENFORCE_UID(AID_SYSTEM);
826 ACQUIRE_CRYPT_LOCK;
827
Eric Biggersa701c452018-10-23 13:06:55 -0700828 return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600829}
830
831binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
832 ENFORCE_UID(AID_SYSTEM);
833 ACQUIRE_CRYPT_LOCK;
834
Eric Biggersa701c452018-10-23 13:06:55 -0700835 return translateBool(fscrypt_destroy_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600836}
837
838binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700839 const std::string& token,
840 const std::string& secret) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600841 ENFORCE_UID(AID_SYSTEM);
842 ACQUIRE_CRYPT_LOCK;
843
Eric Biggersa701c452018-10-23 13:06:55 -0700844 return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600845}
846
847binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
848 ENFORCE_UID(AID_SYSTEM);
849 ACQUIRE_CRYPT_LOCK;
850
Eric Biggersa701c452018-10-23 13:06:55 -0700851 return translateBool(fscrypt_fixate_newest_user_key_auth(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600852}
853
854binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700855 const std::string& token,
856 const std::string& secret) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600857 ENFORCE_UID(AID_SYSTEM);
858 ACQUIRE_CRYPT_LOCK;
859
Eric Biggersa701c452018-10-23 13:06:55 -0700860 return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600861}
862
863binder::Status VoldNativeService::lockUserKey(int32_t userId) {
864 ENFORCE_UID(AID_SYSTEM);
865 ACQUIRE_CRYPT_LOCK;
866
Eric Biggersa701c452018-10-23 13:06:55 -0700867 return translateBool(fscrypt_lock_user_key(userId));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600868}
869
870binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700871 int32_t userId, int32_t userSerial,
872 int32_t flags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600873 ENFORCE_UID(AID_SYSTEM);
Paul Crowley3b71fc52017-10-09 10:55:21 -0700874 std::string empty_string = "";
875 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700876 CHECK_ARGUMENT_HEX(uuid_);
877
878 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700879 return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600880}
881
882binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700883 int32_t userId, int32_t flags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600884 ENFORCE_UID(AID_SYSTEM);
Paul Crowley3b71fc52017-10-09 10:55:21 -0700885 std::string empty_string = "";
886 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700887 CHECK_ARGUMENT_HEX(uuid_);
888
889 ACQUIRE_CRYPT_LOCK;
Eric Biggersa701c452018-10-23 13:06:55 -0700890 return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600891}
892
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700893binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
894 int32_t appId, const std::string& sandboxId,
895 int32_t userId) {
Sudheer Shankac7562092018-08-24 10:20:56 -0700896 ENFORCE_UID(AID_SYSTEM);
897 CHECK_ARGUMENT_PACKAGE_NAME(packageName);
898 CHECK_ARGUMENT_SANDBOX_ID(sandboxId);
899 ACQUIRE_LOCK;
900
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700901 return translate(
902 VolumeManager::Instance()->prepareSandboxForApp(packageName, appId, sandboxId, userId));
903}
904
905binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700906 const std::string& sandboxId,
Sudheer Shankafa6a1742018-10-04 16:26:22 -0700907 int32_t userId) {
908 ENFORCE_UID(AID_SYSTEM);
909 CHECK_ARGUMENT_PACKAGE_NAME(packageName);
910 CHECK_ARGUMENT_SANDBOX_ID(sandboxId);
911 ACQUIRE_LOCK;
912
913 return translate(
Sudheer Shanka69bc40f2018-10-25 11:06:55 -0700914 VolumeManager::Instance()->destroySandboxForApp(packageName, sandboxId, userId));
Sudheer Shankac7562092018-08-24 10:20:56 -0700915}
916
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700917binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700918 ENFORCE_UID(AID_SYSTEM);
919 ACQUIRE_LOCK;
920
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700921 return cp_startCheckpoint(retry);
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700922}
923
Daniel Rosenbergd3992492018-10-02 17:40:44 -0700924binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
925 ENFORCE_UID(AID_SYSTEM);
926 ACQUIRE_LOCK;
927
928 *_aidl_return = cp_needsRollback();
929 return ok();
930}
931
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700932binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
933 ENFORCE_UID(AID_SYSTEM);
934 ACQUIRE_LOCK;
935
936 *_aidl_return = cp_needsCheckpoint();
937 return ok();
938}
939
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700940binder::Status VoldNativeService::commitChanges() {
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700941 ENFORCE_UID(AID_SYSTEM);
942 ACQUIRE_LOCK;
943
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700944 return cp_commitChanges();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700945}
946
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700947binder::Status VoldNativeService::prepareCheckpoint() {
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700948 ENFORCE_UID(AID_SYSTEM);
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700949 ACQUIRE_LOCK;
950
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700951 return cp_prepareCheckpoint();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700952}
953
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700954binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700955 ENFORCE_UID(AID_SYSTEM);
956 CHECK_ARGUMENT_PATH(mountPoint);
957 ACQUIRE_LOCK;
958
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700959 return cp_restoreCheckpoint(mountPoint);
Paul Lawrence1abb2fe2018-09-21 10:49:57 -0700960}
961
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700962binder::Status VoldNativeService::markBootAttempt() {
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700963 ENFORCE_UID(AID_SYSTEM);
964 ACQUIRE_LOCK;
965
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700966 return cp_markBootAttempt();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700967}
968
969binder::Status VoldNativeService::abortChanges() {
970 ENFORCE_UID(AID_SYSTEM);
971 ACQUIRE_LOCK;
972
Daniel Rosenberge334aab2018-10-10 18:52:04 -0700973 return cp_abortChanges();
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700974}
975
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600976} // namespace vold
977} // namespace android