blob: dcf35467249a16034c8bd7bd25208a19853e5fee [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"
Jeff Sharkey83b559c2017-09-12 16:30:52 -060028#include "Ext4Crypt.h"
29#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>
Paul Crowley3b71fc52017-10-09 10:55:21 -070038#include <ext4_utils/ext4_crypt.h>
Jeff Sharkey11c2d382017-09-11 10:32:01 -060039#include <fs_mgr.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,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700361 const std::vector<std::string>& packageNames) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600362 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700363 CHECK_ARGUMENT_PACKAGE_NAMES(packageNames);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600364 ACQUIRE_LOCK;
365
Sudheer Shankaebaad1c2018-07-31 16:39:59 -0700366 return translate(VolumeManager::Instance()->onUserStarted(userId, packageNames));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600367}
368
369binder::Status VoldNativeService::onUserStopped(int32_t userId) {
370 ENFORCE_UID(AID_SYSTEM);
371 ACQUIRE_LOCK;
372
373 return translate(VolumeManager::Instance()->onUserStopped(userId));
374}
375
Sudheer Shankad484aa92018-07-31 10:07:34 -0700376binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700377 const std::vector<int32_t>& appIds) {
Sudheer Shankad484aa92018-07-31 10:07:34 -0700378 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700379 CHECK_ARGUMENT_PACKAGE_NAMES(packageNames);
Sudheer Shankad484aa92018-07-31 10:07:34 -0700380 ACQUIRE_LOCK;
381
382 return translate(VolumeManager::Instance()->addAppIds(packageNames, appIds));
383}
384
Sudheer Shankad484aa92018-07-31 10:07:34 -0700385binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700386 const std::vector<std::string>& sandboxIds) {
Sudheer Shankad484aa92018-07-31 10:07:34 -0700387 ENFORCE_UID(AID_SYSTEM);
Sudheer Shankacc0df592018-08-02 10:21:42 -0700388 CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds);
Sudheer Shankad484aa92018-07-31 10:07:34 -0700389 ACQUIRE_LOCK;
390
391 return translate(VolumeManager::Instance()->addSandboxIds(appIds, sandboxIds));
392}
393
Jeff Sharkey401b2602017-12-14 22:15:20 -0700394binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
395 ENFORCE_UID(AID_SYSTEM);
396 ACQUIRE_LOCK;
397
398 return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
399}
400
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600401binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700402 int32_t ratio) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600403 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600404 CHECK_ARGUMENT_ID(diskId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600405 ACQUIRE_LOCK;
406
407 auto disk = VolumeManager::Instance()->findDisk(diskId);
408 if (disk == nullptr) {
409 return error("Failed to find disk " + diskId);
410 }
411 switch (partitionType) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700412 case PARTITION_TYPE_PUBLIC:
413 return translate(disk->partitionPublic());
414 case PARTITION_TYPE_PRIVATE:
415 return translate(disk->partitionPrivate());
416 case PARTITION_TYPE_MIXED:
417 return translate(disk->partitionMixed(ratio));
418 default:
419 return error("Unknown type " + std::to_string(partitionType));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600420 }
421}
422
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600423binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700424 const std::string& fsUuid) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600425 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600426 CHECK_ARGUMENT_HEX(partGuid);
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600427 CHECK_ARGUMENT_HEX(fsUuid);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600428 ACQUIRE_LOCK;
429
Jeff Sharkey3ce18252017-10-24 11:08:45 -0600430 return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600431}
432
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600433binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700434 int32_t mountUserId) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600435 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600436 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600437 ACQUIRE_LOCK;
438
439 auto vol = VolumeManager::Instance()->findVolume(volId);
440 if (vol == nullptr) {
441 return error("Failed to find volume " + volId);
442 }
443
444 vol->setMountFlags(mountFlags);
445 vol->setMountUserId(mountUserId);
446
447 int res = vol->mount();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600448 if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600449 VolumeManager::Instance()->setPrimary(vol);
450 }
451 return translate(res);
452}
453
454binder::Status VoldNativeService::unmount(const std::string& volId) {
455 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600456 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600457 ACQUIRE_LOCK;
458
459 auto vol = VolumeManager::Instance()->findVolume(volId);
460 if (vol == nullptr) {
461 return error("Failed to find volume " + volId);
462 }
463 return translate(vol->unmount());
464}
465
466binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
467 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600468 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600469 ACQUIRE_LOCK;
470
471 auto vol = VolumeManager::Instance()->findVolume(volId);
472 if (vol == nullptr) {
473 return error("Failed to find volume " + volId);
474 }
475 return translate(vol->format(fsType));
476}
477
Jeff Sharkey2048a282017-06-15 09:59:43 -0600478static binder::Status pathForVolId(const std::string& volId, std::string* path) {
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600479 if (volId == "private" || volId == "null") {
Jeff Sharkey2048a282017-06-15 09:59:43 -0600480 *path = "/data";
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600481 } else {
482 auto vol = VolumeManager::Instance()->findVolume(volId);
483 if (vol == nullptr) {
484 return error("Failed to find volume " + volId);
485 }
486 if (vol->getType() != VolumeBase::Type::kPrivate) {
487 return error("Volume " + volId + " not private");
488 }
489 if (vol->getState() != VolumeBase::State::kMounted) {
490 return error("Volume " + volId + " not mounted");
491 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600492 *path = vol->getPath();
493 if (path->empty()) {
494 return error("Volume " + volId + " missing path");
495 }
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600496 }
Jeff Sharkey2048a282017-06-15 09:59:43 -0600497 return ok();
498}
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600499
Jeff Sharkey2048a282017-06-15 09:59:43 -0600500binder::Status VoldNativeService::benchmark(
501 const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
502 ENFORCE_UID(AID_SYSTEM);
503 CHECK_ARGUMENT_ID(volId);
504 ACQUIRE_LOCK;
505
506 std::string path;
507 auto status = pathForVolId(volId, &path);
508 if (!status.isOk()) return status;
Jeff Sharkey52f7a912017-09-15 12:57:44 -0600509
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700510 std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600511 return ok();
512}
513
Jeff Sharkey2048a282017-06-15 09:59:43 -0600514binder::Status VoldNativeService::checkEncryption(const std::string& volId) {
515 ENFORCE_UID(AID_SYSTEM);
516 CHECK_ARGUMENT_ID(volId);
517 ACQUIRE_LOCK;
518
519 std::string path;
520 auto status = pathForVolId(volId, &path);
521 if (!status.isOk()) return status;
522 return translate(android::vold::CheckEncryption(path));
523}
524
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700525binder::Status VoldNativeService::moveStorage(
526 const std::string& fromVolId, const std::string& toVolId,
527 const android::sp<android::os::IVoldTaskListener>& listener) {
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600528 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600529 CHECK_ARGUMENT_ID(fromVolId);
530 CHECK_ARGUMENT_ID(toVolId);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600531 ACQUIRE_LOCK;
532
533 auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
534 auto toVol = VolumeManager::Instance()->findVolume(toVolId);
535 if (fromVol == nullptr) {
536 return error("Failed to find volume " + fromVolId);
537 } else if (toVol == nullptr) {
538 return error("Failed to find volume " + toVolId);
539 }
Jeff Sharkey01a0e7f2017-10-17 16:06:32 -0600540
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700541 std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600542 return ok();
543}
544
545binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
546 ENFORCE_UID(AID_SYSTEM);
547 ACQUIRE_LOCK;
548
549 std::string tmp;
550 switch (remountMode) {
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700551 case REMOUNT_MODE_NONE:
552 tmp = "none";
553 break;
554 case REMOUNT_MODE_DEFAULT:
555 tmp = "default";
556 break;
557 case REMOUNT_MODE_READ:
558 tmp = "read";
559 break;
560 case REMOUNT_MODE_WRITE:
561 tmp = "write";
562 break;
563 default:
564 return error("Unknown mode " + std::to_string(remountMode));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600565 }
566 return translate(VolumeManager::Instance()->remountUid(uid, tmp));
567}
568
569binder::Status VoldNativeService::mkdirs(const std::string& path) {
570 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600571 CHECK_ARGUMENT_PATH(path);
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600572 ACQUIRE_LOCK;
573
Jeff Sharkey3472e522017-10-06 18:02:53 -0600574 return translate(VolumeManager::Instance()->mkdirs(path));
Jeff Sharkey9462bdd2017-09-07 15:27:28 -0600575}
576
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600577binder::Status VoldNativeService::createObb(const std::string& sourcePath,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700578 const std::string& sourceKey, int32_t ownerGid,
579 std::string* _aidl_return) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600580 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600581 CHECK_ARGUMENT_PATH(sourcePath);
582 CHECK_ARGUMENT_HEX(sourceKey);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600583 ACQUIRE_LOCK;
584
585 return translate(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700586 VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600587}
588
589binder::Status VoldNativeService::destroyObb(const std::string& volId) {
590 ENFORCE_UID(AID_SYSTEM);
Jeff Sharkeyec4fda22017-09-12 13:19:24 -0600591 CHECK_ARGUMENT_ID(volId);
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600592 ACQUIRE_LOCK;
593
594 return translate(VolumeManager::Instance()->destroyObb(volId));
595}
596
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700597binder::Status VoldNativeService::fstrim(
598 int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600599 ENFORCE_UID(AID_SYSTEM);
600 ACQUIRE_LOCK;
601
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700602 std::thread([=]() { android::vold::Trim(listener); }).detach();
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600603 return ok();
604}
605
Jin Qiana370c142017-10-17 15:41:45 -0700606binder::Status VoldNativeService::runIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700607 const android::sp<android::os::IVoldTaskListener>& listener) {
Jin Qiana370c142017-10-17 15:41:45 -0700608 ENFORCE_UID(AID_SYSTEM);
609 ACQUIRE_LOCK;
610
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700611 std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700612 return ok();
613}
614
615binder::Status VoldNativeService::abortIdleMaint(
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700616 const android::sp<android::os::IVoldTaskListener>& listener) {
Jin Qiana370c142017-10-17 15:41:45 -0700617 ENFORCE_UID(AID_SYSTEM);
618 ACQUIRE_LOCK;
619
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700620 std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
Jin Qiana370c142017-10-17 15:41:45 -0700621 return ok();
622}
623
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600624binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700625 android::base::unique_fd* _aidl_return) {
Jeff Sharkey11c2d382017-09-11 10:32:01 -0600626 ENFORCE_UID(AID_SYSTEM);
627 ACQUIRE_LOCK;
628
629 return translate(VolumeManager::Instance()->mountAppFuse(uid, pid, mountId, _aidl_return));
630}
631
632binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId) {
633 ENFORCE_UID(AID_SYSTEM);
634 ACQUIRE_LOCK;
635
636 return translate(VolumeManager::Instance()->unmountAppFuse(uid, pid, mountId));
637}
638
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600639binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
640 ENFORCE_UID(AID_SYSTEM);
641 ACQUIRE_CRYPT_LOCK;
642
643 return translate(cryptfs_check_passwd(password.c_str()));
644}
645
646binder::Status VoldNativeService::fdeRestart() {
647 ENFORCE_UID(AID_SYSTEM);
648 ACQUIRE_CRYPT_LOCK;
649
650 // Spawn as thread so init can issue commands back to vold without
651 // causing deadlock, usually as a result of prep_data_fs.
652 std::thread(&cryptfs_restart).detach();
653 return ok();
654}
655
656binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
657 ENFORCE_UID(AID_SYSTEM);
658 ACQUIRE_CRYPT_LOCK;
659
660 *_aidl_return = cryptfs_crypto_complete();
661 return ok();
662}
663
664static int fdeEnableInternal(int32_t passwordType, const std::string& password,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700665 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600666 bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
667
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600668 for (int tries = 0; tries < 2; ++tries) {
669 int rc;
670 if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800671 rc = cryptfs_enable_default(noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600672 } else {
Paul Lawrence7ee87cf2017-12-22 10:12:06 -0800673 rc = cryptfs_enable(passwordType, password.c_str(), noUi);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600674 }
675
676 if (rc == 0) {
677 return 0;
678 } else if (tries == 0) {
Jeff Sharkey3472e522017-10-06 18:02:53 -0600679 KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600680 }
681 }
682
683 return -1;
684}
685
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700686binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
687 int32_t encryptionFlags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600688 ENFORCE_UID(AID_SYSTEM);
689 ACQUIRE_CRYPT_LOCK;
690
Paul Crowley0fd26262018-01-30 09:48:19 -0800691 LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")";
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600692 if (e4crypt_is_native()) {
Paul Crowley0fd26262018-01-30 09:48:19 -0800693 LOG(ERROR) << "e4crypt_is_native, fdeEnable invalid";
694 return error("e4crypt_is_native, fdeEnable invalid");
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600695 }
Paul Crowley0fd26262018-01-30 09:48:19 -0800696 LOG(DEBUG) << "!e4crypt_is_native, spawning fdeEnableInternal";
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600697
698 // Spawn as thread so init can issue commands back to vold without
699 // causing deadlock, usually as a result of prep_data_fs.
700 std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach();
701 return ok();
702}
703
704binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700705 const std::string& password) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600706 ENFORCE_UID(AID_SYSTEM);
707 ACQUIRE_CRYPT_LOCK;
708
709 return translate(cryptfs_changepw(passwordType, password.c_str()));
710}
711
712binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
713 ENFORCE_UID(AID_SYSTEM);
714 ACQUIRE_CRYPT_LOCK;
715
716 return translate(cryptfs_verify_passwd(password.c_str()));
717}
718
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700719binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600720 ENFORCE_UID(AID_SYSTEM);
721 ACQUIRE_CRYPT_LOCK;
722
723 char buf[PROPERTY_VALUE_MAX];
724 if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) {
725 return error(StringPrintf("Failed to read field %s", key.c_str()));
726 } else {
727 *_aidl_return = buf;
728 return ok();
729 }
730}
731
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700732binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600733 ENFORCE_UID(AID_SYSTEM);
734 ACQUIRE_CRYPT_LOCK;
735
736 return translate(cryptfs_setfield(key.c_str(), value.c_str()));
737}
738
739binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
740 ENFORCE_UID(AID_SYSTEM);
741 ACQUIRE_CRYPT_LOCK;
742
743 *_aidl_return = cryptfs_get_password_type();
744 return ok();
745}
746
747binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
748 ENFORCE_UID(AID_SYSTEM);
749 ACQUIRE_CRYPT_LOCK;
750
751 const char* res = cryptfs_get_password();
752 if (res != nullptr) {
753 *_aidl_return = res;
754 }
755 return ok();
756}
757
758binder::Status VoldNativeService::fdeClearPassword() {
759 ENFORCE_UID(AID_SYSTEM);
760 ACQUIRE_CRYPT_LOCK;
761
762 cryptfs_clear_password();
763 return ok();
764}
765
766binder::Status VoldNativeService::fbeEnable() {
767 ENFORCE_UID(AID_SYSTEM);
768 ACQUIRE_CRYPT_LOCK;
769
770 return translateBool(e4crypt_initialize_global_de());
771}
772
773binder::Status VoldNativeService::mountDefaultEncrypted() {
774 ENFORCE_UID(AID_SYSTEM);
775 ACQUIRE_CRYPT_LOCK;
776
Paul Crowley0fd26262018-01-30 09:48:19 -0800777 if (!e4crypt_is_native()) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600778 // Spawn as thread so init can issue commands back to vold without
779 // causing deadlock, usually as a result of prep_data_fs.
780 std::thread(&cryptfs_mount_default_encrypted).detach();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600781 }
Paul Crowley0fd26262018-01-30 09:48:19 -0800782 return ok();
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600783}
784
785binder::Status VoldNativeService::initUser0() {
786 ENFORCE_UID(AID_SYSTEM);
787 ACQUIRE_CRYPT_LOCK;
788
789 return translateBool(e4crypt_init_user0());
790}
791
792binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
793 ENFORCE_UID(AID_SYSTEM);
794 ACQUIRE_CRYPT_LOCK;
795
796 *_aidl_return = cryptfs_isConvertibleToFBE() != 0;
797 return ok();
798}
799
Paul Crowley0fd26262018-01-30 09:48:19 -0800800binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) {
801 ENFORCE_UID(AID_SYSTEM);
802 ACQUIRE_LOCK;
803
804 return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, false));
805}
806
807binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) {
808 ENFORCE_UID(AID_SYSTEM);
809 ACQUIRE_LOCK;
810
811 return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true));
812}
813
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700814binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600815 ENFORCE_UID(AID_SYSTEM);
816 ACQUIRE_CRYPT_LOCK;
817
818 return translateBool(e4crypt_vold_create_user_key(userId, userSerial, ephemeral));
819}
820
821binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
822 ENFORCE_UID(AID_SYSTEM);
823 ACQUIRE_CRYPT_LOCK;
824
825 return translateBool(e4crypt_destroy_user_key(userId));
826}
827
828binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700829 const std::string& token,
830 const std::string& secret) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600831 ENFORCE_UID(AID_SYSTEM);
832 ACQUIRE_CRYPT_LOCK;
833
Paul Crowley3b71fc52017-10-09 10:55:21 -0700834 return translateBool(e4crypt_add_user_key_auth(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600835}
836
837binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
838 ENFORCE_UID(AID_SYSTEM);
839 ACQUIRE_CRYPT_LOCK;
840
841 return translateBool(e4crypt_fixate_newest_user_key_auth(userId));
842}
843
844binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700845 const std::string& token,
846 const std::string& secret) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600847 ENFORCE_UID(AID_SYSTEM);
848 ACQUIRE_CRYPT_LOCK;
849
Paul Crowley3b71fc52017-10-09 10:55:21 -0700850 return translateBool(e4crypt_unlock_user_key(userId, userSerial, token, secret));
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600851}
852
853binder::Status VoldNativeService::lockUserKey(int32_t userId) {
854 ENFORCE_UID(AID_SYSTEM);
855 ACQUIRE_CRYPT_LOCK;
856
857 return translateBool(e4crypt_lock_user_key(userId));
858}
859
860binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700861 int32_t userId, int32_t userSerial,
862 int32_t flags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600863 ENFORCE_UID(AID_SYSTEM);
Paul Crowley3b71fc52017-10-09 10:55:21 -0700864 std::string empty_string = "";
865 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700866 CHECK_ARGUMENT_HEX(uuid_);
867
868 ACQUIRE_CRYPT_LOCK;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600869 return translateBool(e4crypt_prepare_user_storage(uuid_, userId, userSerial, flags));
870}
871
872binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700873 int32_t userId, int32_t flags) {
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600874 ENFORCE_UID(AID_SYSTEM);
Paul Crowley3b71fc52017-10-09 10:55:21 -0700875 std::string empty_string = "";
876 auto uuid_ = uuid ? *uuid : empty_string;
Paul Crowley06f762d2017-10-16 10:59:51 -0700877 CHECK_ARGUMENT_HEX(uuid_);
878
879 ACQUIRE_CRYPT_LOCK;
Jeff Sharkey83b559c2017-09-12 16:30:52 -0600880 return translateBool(e4crypt_destroy_user_storage(uuid_, userId, flags));
881}
882
Sudheer Shankac7562092018-08-24 10:20:56 -0700883binder::Status VoldNativeService::mountExternalStorageForApp(const std::string& packageName,
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700884 int32_t appId,
885 const std::string& sandboxId,
886 int32_t userId) {
Sudheer Shankac7562092018-08-24 10:20:56 -0700887 ENFORCE_UID(AID_SYSTEM);
888 CHECK_ARGUMENT_PACKAGE_NAME(packageName);
889 CHECK_ARGUMENT_SANDBOX_ID(sandboxId);
890 ACQUIRE_LOCK;
891
Paul Crowleyedf7a4e2018-09-18 15:14:18 -0700892 return translate(VolumeManager::Instance()->mountExternalStorageForApp(packageName, appId,
893 sandboxId, userId));
Sudheer Shankac7562092018-08-24 10:20:56 -0700894}
895
Daniel Rosenberg4f684712018-08-28 01:58:49 -0700896binder::Status VoldNativeService::startCheckpoint(int32_t retry, bool* _aidl_return) {
897 ENFORCE_UID(AID_SYSTEM);
898 ACQUIRE_LOCK;
899
900 *_aidl_return = cp_startCheckpoint(retry);
901 return ok();
902}
903
904binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
905 ENFORCE_UID(AID_SYSTEM);
906 ACQUIRE_LOCK;
907
908 *_aidl_return = cp_needsCheckpoint();
909 return ok();
910}
911
912binder::Status VoldNativeService::commitChanges(bool* _aidl_return) {
913 ENFORCE_UID(AID_SYSTEM);
914 ACQUIRE_LOCK;
915
916 *_aidl_return = cp_commitChanges();
917 return ok();
918}
919
920binder::Status VoldNativeService::prepareDriveForCheckpoint(const std::string& mountPoint,
921 bool* _aidl_return) {
922 ENFORCE_UID(AID_SYSTEM);
923 CHECK_ARGUMENT_PATH(mountPoint);
924 ACQUIRE_LOCK;
925
926 *_aidl_return = cp_prepareDriveForCheckpoint(mountPoint);
927 return ok();
928}
929
930binder::Status VoldNativeService::markBootAttempt(bool* _aidl_return) {
931 ENFORCE_UID(AID_SYSTEM);
932 ACQUIRE_LOCK;
933
934 *_aidl_return = cp_markBootAttempt();
935 return ok();
936}
937
938binder::Status VoldNativeService::abortChanges() {
939 ENFORCE_UID(AID_SYSTEM);
940 ACQUIRE_LOCK;
941
942 cp_abortChanges();
943 return ok();
944}
945
Jeff Sharkey068c6be2017-09-06 13:47:40 -0600946} // namespace vold
947} // namespace android