Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1 | /* |
| 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 Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER |
| 18 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 19 | #include "VoldNativeService.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 20 | #include "Benchmark.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 21 | #include "CheckEncryption.h" |
| 22 | #include "IdleMaint.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 23 | #include "MoveStorage.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 24 | #include "Process.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 25 | #include "VolumeManager.h" |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 26 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 27 | #include "Checkpoint.h" |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 28 | #include "FsCrypt.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 29 | #include "MetadataCrypt.h" |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 30 | #include "cryptfs.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 31 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 32 | #include <fstream> |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 33 | #include <thread> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 34 | |
| 35 | #include <android-base/logging.h> |
| 36 | #include <android-base/stringprintf.h> |
| 37 | #include <android-base/strings.h> |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 38 | #include <fs_mgr.h> |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 39 | #include <fscrypt/fscrypt.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 40 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 41 | #include <utils/Trace.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 42 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 43 | using android::base::StringPrintf; |
| 44 | using std::endl; |
| 45 | |
| 46 | namespace android { |
| 47 | namespace vold { |
| 48 | |
| 49 | namespace { |
| 50 | |
| 51 | constexpr const char* kDump = "android.permission.DUMP"; |
| 52 | |
| 53 | static binder::Status ok() { |
| 54 | return binder::Status::ok(); |
| 55 | } |
| 56 | |
| 57 | static binder::Status exception(uint32_t code, const std::string& msg) { |
| 58 | return binder::Status::fromExceptionCode(code, String8(msg.c_str())); |
| 59 | } |
| 60 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 61 | static binder::Status error(const std::string& msg) { |
| 62 | PLOG(ERROR) << msg; |
| 63 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 64 | } |
| 65 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 66 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 67 | if (status == 0) { |
| 68 | return binder::Status::ok(); |
| 69 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 70 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 74 | static 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 Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 82 | binder::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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 87 | reinterpret_cast<int32_t*>(&uid))) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 88 | return ok(); |
| 89 | } else { |
| 90 | return exception(binder::Status::EX_SECURITY, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 91 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 95 | binder::Status checkUidOrRoot(uid_t expectedUid) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 101 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 105 | binder::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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 112 | StringPrintf("ID %s is malformed", id.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | return ok(); |
| 116 | } |
| 117 | |
| 118 | binder::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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 124 | StringPrintf("Path %s is relative", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 125 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 126 | if ((path + '/').find("/../") != std::string::npos) { |
| 127 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 128 | StringPrintf("Path %s is shady", path.c_str())); |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 129 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 130 | for (const char& c : path) { |
| 131 | if (c == '\0' || c == '\n') { |
| 132 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 133 | StringPrintf("Path %s is malformed", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | return ok(); |
| 137 | } |
| 138 | |
| 139 | binder::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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 144 | StringPrintf("Hex %s is malformed", hex.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | return ok(); |
| 148 | } |
| 149 | |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 150 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 151 | { \ |
| 152 | binder::Status status = checkUidOrRoot(AID_SYSTEM); \ |
| 153 | if (!status.isOk()) { \ |
| 154 | return status; \ |
| 155 | } \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 156 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 157 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 158 | #define CHECK_ARGUMENT_ID(id) \ |
| 159 | { \ |
| 160 | binder::Status status = checkArgumentId((id)); \ |
| 161 | if (!status.isOk()) { \ |
| 162 | return status; \ |
| 163 | } \ |
| 164 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 165 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 166 | #define CHECK_ARGUMENT_PATH(path) \ |
| 167 | { \ |
| 168 | binder::Status status = checkArgumentPath((path)); \ |
| 169 | if (!status.isOk()) { \ |
| 170 | return status; \ |
| 171 | } \ |
| 172 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 173 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 174 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 175 | { \ |
| 176 | binder::Status status = checkArgumentHex((hex)); \ |
| 177 | if (!status.isOk()) { \ |
| 178 | return status; \ |
| 179 | } \ |
| 180 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 181 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 182 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 183 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 184 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 185 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 186 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 187 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 188 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 189 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 190 | } // namespace |
| 191 | |
| 192 | status_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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 204 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 205 | 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 Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 212 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 213 | out << "vold is happy!" << endl; |
| 214 | out.flush(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 215 | return NO_ERROR; |
| 216 | } |
| 217 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 218 | binder::Status VoldNativeService::setListener( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 219 | const android::sp<android::os::IVoldListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 220 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 221 | ACQUIRE_LOCK; |
| 222 | |
| 223 | VolumeManager::Instance()->setListener(listener); |
| 224 | return ok(); |
| 225 | } |
| 226 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 227 | binder::Status VoldNativeService::monitor() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 228 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 229 | |
| 230 | // Simply acquire/release each lock for watchdog |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 231 | { ACQUIRE_LOCK; } |
| 232 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 233 | |
| 234 | return ok(); |
| 235 | } |
| 236 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 237 | binder::Status VoldNativeService::reset() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 238 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 239 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 240 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 241 | return translate(VolumeManager::Instance()->reset()); |
| 242 | } |
| 243 | |
| 244 | binder::Status VoldNativeService::shutdown() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 245 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 246 | ACQUIRE_LOCK; |
| 247 | |
| 248 | return translate(VolumeManager::Instance()->shutdown()); |
| 249 | } |
| 250 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 251 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 252 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 253 | ACQUIRE_LOCK; |
| 254 | |
| 255 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 256 | } |
| 257 | |
| 258 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 259 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 260 | ACQUIRE_LOCK; |
| 261 | |
| 262 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 263 | } |
| 264 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 265 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 266 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 267 | ACQUIRE_LOCK; |
| 268 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 269 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 273 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 274 | ACQUIRE_LOCK; |
| 275 | |
| 276 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 277 | } |
| 278 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 279 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 280 | const std::vector<int32_t>& appIds) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 281 | return ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 284 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 285 | const std::vector<std::string>& sandboxIds) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 286 | return ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 289 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 290 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 291 | ACQUIRE_LOCK; |
| 292 | |
| 293 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 294 | } |
| 295 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 296 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 297 | int32_t ratio) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 298 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 299 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 300 | 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 Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 307 | 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 Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 318 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 319 | const std::string& fsUuid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 320 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 321 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 322 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 323 | ACQUIRE_LOCK; |
| 324 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 325 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 326 | } |
| 327 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 328 | binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags, |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 329 | int32_t mountUserId, |
| 330 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 331 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 332 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 333 | ACQUIRE_LOCK; |
| 334 | |
| 335 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 336 | if (vol == nullptr) { |
| 337 | return error("Failed to find volume " + volId); |
| 338 | } |
| 339 | |
| 340 | vol->setMountFlags(mountFlags); |
| 341 | vol->setMountUserId(mountUserId); |
| 342 | |
| 343 | int res = vol->mount(); |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 344 | if (res != OK) { |
| 345 | return translate(res); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 346 | } |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 347 | |
Nandana Dutt | a914cc7 | 2019-08-29 15:22:42 +0100 | [diff] [blame] | 348 | _aidl_return->reset(dup(vol->getFuseFd().get())); |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 349 | if (_aidl_return->get() == -1) { |
| 350 | // Let's not return invalid fd since binder will not allow null fds. Instead give it a |
| 351 | // default value. |
| 352 | _aidl_return->reset(open("/dev/null", O_RDONLY | O_CLOEXEC)); |
| 353 | } |
| 354 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 355 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
| 356 | res = VolumeManager::Instance()->setPrimary(vol); |
| 357 | if (res != OK) { |
| 358 | return translate(res); |
| 359 | } |
| 360 | } |
| 361 | return translate(OK); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 365 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 366 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 367 | ACQUIRE_LOCK; |
| 368 | |
| 369 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 370 | if (vol == nullptr) { |
| 371 | return error("Failed to find volume " + volId); |
| 372 | } |
| 373 | return translate(vol->unmount()); |
| 374 | } |
| 375 | |
| 376 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 377 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 378 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 379 | ACQUIRE_LOCK; |
| 380 | |
| 381 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 382 | if (vol == nullptr) { |
| 383 | return error("Failed to find volume " + volId); |
| 384 | } |
| 385 | return translate(vol->format(fsType)); |
| 386 | } |
| 387 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 388 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 389 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 390 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 391 | } else { |
| 392 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 393 | if (vol == nullptr) { |
| 394 | return error("Failed to find volume " + volId); |
| 395 | } |
| 396 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 397 | return error("Volume " + volId + " not private"); |
| 398 | } |
| 399 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 400 | return error("Volume " + volId + " not mounted"); |
| 401 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 402 | *path = vol->getPath(); |
| 403 | if (path->empty()) { |
| 404 | return error("Volume " + volId + " missing path"); |
| 405 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 406 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 407 | return ok(); |
| 408 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 409 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 410 | binder::Status VoldNativeService::benchmark( |
| 411 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 412 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 413 | CHECK_ARGUMENT_ID(volId); |
| 414 | ACQUIRE_LOCK; |
| 415 | |
| 416 | std::string path; |
| 417 | auto status = pathForVolId(volId, &path); |
| 418 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 419 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 420 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 421 | return ok(); |
| 422 | } |
| 423 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 424 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 425 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 426 | CHECK_ARGUMENT_ID(volId); |
| 427 | ACQUIRE_LOCK; |
| 428 | |
| 429 | std::string path; |
| 430 | auto status = pathForVolId(volId, &path); |
| 431 | if (!status.isOk()) return status; |
| 432 | return translate(android::vold::CheckEncryption(path)); |
| 433 | } |
| 434 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 435 | binder::Status VoldNativeService::moveStorage( |
| 436 | const std::string& fromVolId, const std::string& toVolId, |
| 437 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 438 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 439 | CHECK_ARGUMENT_ID(fromVolId); |
| 440 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 441 | ACQUIRE_LOCK; |
| 442 | |
| 443 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 444 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 445 | if (fromVol == nullptr) { |
| 446 | return error("Failed to find volume " + fromVolId); |
| 447 | } else if (toVol == nullptr) { |
| 448 | return error("Failed to find volume " + toVolId); |
| 449 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 450 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 451 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 452 | return ok(); |
| 453 | } |
| 454 | |
| 455 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 456 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 457 | ACQUIRE_LOCK; |
| 458 | |
Sudheer Shanka | 817b911 | 2018-12-13 17:40:28 -0800 | [diff] [blame] | 459 | return translate(VolumeManager::Instance()->remountUid(uid, remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | binder::Status VoldNativeService::mkdirs(const std::string& path) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 463 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 464 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 465 | ACQUIRE_LOCK; |
| 466 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 467 | return translate(VolumeManager::Instance()->mkdirs(path)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 468 | } |
| 469 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 470 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 471 | const std::string& sourceKey, int32_t ownerGid, |
| 472 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 473 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 474 | CHECK_ARGUMENT_PATH(sourcePath); |
| 475 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 476 | ACQUIRE_LOCK; |
| 477 | |
| 478 | return translate( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 479 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 483 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 484 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 485 | ACQUIRE_LOCK; |
| 486 | |
| 487 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 488 | } |
| 489 | |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 490 | binder::Status VoldNativeService::createStubVolume( |
| 491 | const std::string& sourcePath, const std::string& mountPath, const std::string& fsType, |
| 492 | const std::string& fsUuid, const std::string& fsLabel, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 493 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 494 | CHECK_ARGUMENT_PATH(sourcePath); |
| 495 | CHECK_ARGUMENT_PATH(mountPath); |
| 496 | CHECK_ARGUMENT_HEX(fsUuid); |
| 497 | // Label limitation seems to be different between fs (including allowed characters), so checking |
| 498 | // is quite meaningless. |
| 499 | ACQUIRE_LOCK; |
| 500 | |
| 501 | return translate(VolumeManager::Instance()->createStubVolume(sourcePath, mountPath, fsType, |
| 502 | fsUuid, fsLabel, _aidl_return)); |
| 503 | } |
| 504 | |
| 505 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 506 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 507 | CHECK_ARGUMENT_ID(volId); |
| 508 | ACQUIRE_LOCK; |
| 509 | |
| 510 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 511 | } |
| 512 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 513 | binder::Status VoldNativeService::fstrim( |
| 514 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 515 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 516 | ACQUIRE_LOCK; |
| 517 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 518 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 519 | return ok(); |
| 520 | } |
| 521 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 522 | binder::Status VoldNativeService::runIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 523 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 524 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 525 | ACQUIRE_LOCK; |
| 526 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 527 | std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 528 | return ok(); |
| 529 | } |
| 530 | |
| 531 | binder::Status VoldNativeService::abortIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 532 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 533 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 534 | ACQUIRE_LOCK; |
| 535 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 536 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 537 | return ok(); |
| 538 | } |
| 539 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 540 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 541 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 542 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 543 | ACQUIRE_LOCK; |
| 544 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 545 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 548 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 549 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 550 | ACQUIRE_LOCK; |
| 551 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 552 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 553 | } |
| 554 | |
| 555 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 556 | int32_t flags, |
| 557 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 558 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 559 | ACQUIRE_LOCK; |
| 560 | |
| 561 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 562 | if (fd == -1) { |
| 563 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 564 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 565 | " flags: " + std::to_string(flags)); |
| 566 | } |
| 567 | |
| 568 | *_aidl_return = android::base::unique_fd(fd); |
| 569 | return ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 570 | } |
| 571 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 572 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 573 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 574 | ACQUIRE_CRYPT_LOCK; |
| 575 | |
| 576 | return translate(cryptfs_check_passwd(password.c_str())); |
| 577 | } |
| 578 | |
| 579 | binder::Status VoldNativeService::fdeRestart() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 580 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 581 | ACQUIRE_CRYPT_LOCK; |
| 582 | |
| 583 | // Spawn as thread so init can issue commands back to vold without |
| 584 | // causing deadlock, usually as a result of prep_data_fs. |
| 585 | std::thread(&cryptfs_restart).detach(); |
| 586 | return ok(); |
| 587 | } |
| 588 | |
| 589 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 590 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 591 | ACQUIRE_CRYPT_LOCK; |
| 592 | |
| 593 | *_aidl_return = cryptfs_crypto_complete(); |
| 594 | return ok(); |
| 595 | } |
| 596 | |
| 597 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 598 | int32_t encryptionFlags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 599 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 600 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 601 | for (int tries = 0; tries < 2; ++tries) { |
| 602 | int rc; |
| 603 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 604 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 605 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 606 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | if (rc == 0) { |
| 610 | return 0; |
| 611 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 612 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | return -1; |
| 617 | } |
| 618 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 619 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 620 | int32_t encryptionFlags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 621 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 622 | ACQUIRE_CRYPT_LOCK; |
| 623 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 624 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 625 | if (fscrypt_is_native()) { |
| 626 | LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid"; |
| 627 | return error("fscrypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 628 | } |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 629 | LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 630 | |
| 631 | // Spawn as thread so init can issue commands back to vold without |
| 632 | // causing deadlock, usually as a result of prep_data_fs. |
| 633 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
| 634 | return ok(); |
| 635 | } |
| 636 | |
| 637 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 638 | const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 639 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 640 | ACQUIRE_CRYPT_LOCK; |
| 641 | |
| 642 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 643 | } |
| 644 | |
| 645 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 646 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 647 | ACQUIRE_CRYPT_LOCK; |
| 648 | |
| 649 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 650 | } |
| 651 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 652 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 653 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 654 | ACQUIRE_CRYPT_LOCK; |
| 655 | |
| 656 | char buf[PROPERTY_VALUE_MAX]; |
| 657 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 658 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 659 | } else { |
| 660 | *_aidl_return = buf; |
| 661 | return ok(); |
| 662 | } |
| 663 | } |
| 664 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 665 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 666 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 667 | ACQUIRE_CRYPT_LOCK; |
| 668 | |
| 669 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 670 | } |
| 671 | |
| 672 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 673 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 674 | ACQUIRE_CRYPT_LOCK; |
| 675 | |
| 676 | *_aidl_return = cryptfs_get_password_type(); |
| 677 | return ok(); |
| 678 | } |
| 679 | |
| 680 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 681 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 682 | ACQUIRE_CRYPT_LOCK; |
| 683 | |
| 684 | const char* res = cryptfs_get_password(); |
| 685 | if (res != nullptr) { |
| 686 | *_aidl_return = res; |
| 687 | } |
| 688 | return ok(); |
| 689 | } |
| 690 | |
| 691 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 692 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 693 | ACQUIRE_CRYPT_LOCK; |
| 694 | |
| 695 | cryptfs_clear_password(); |
| 696 | return ok(); |
| 697 | } |
| 698 | |
| 699 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 700 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 701 | ACQUIRE_CRYPT_LOCK; |
| 702 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 703 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 707 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 708 | ACQUIRE_CRYPT_LOCK; |
| 709 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 710 | if (!fscrypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 711 | // Spawn as thread so init can issue commands back to vold without |
| 712 | // causing deadlock, usually as a result of prep_data_fs. |
| 713 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 714 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 715 | return ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | binder::Status VoldNativeService::initUser0() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 719 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 720 | ACQUIRE_CRYPT_LOCK; |
| 721 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 722 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 726 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 727 | ACQUIRE_CRYPT_LOCK; |
| 728 | |
| 729 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
| 730 | return ok(); |
| 731 | } |
| 732 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 733 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 734 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 735 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 736 | ACQUIRE_LOCK; |
| 737 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 738 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 741 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
| 742 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 743 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 744 | ACQUIRE_LOCK; |
| 745 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 746 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 749 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 750 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 751 | ACQUIRE_CRYPT_LOCK; |
| 752 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 753 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 757 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 758 | ACQUIRE_CRYPT_LOCK; |
| 759 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 760 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 764 | const std::string& token, |
| 765 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 766 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 767 | ACQUIRE_CRYPT_LOCK; |
| 768 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 769 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 773 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 774 | ACQUIRE_CRYPT_LOCK; |
| 775 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 776 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 780 | const std::string& token, |
| 781 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 782 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 783 | ACQUIRE_CRYPT_LOCK; |
| 784 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 785 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 789 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 790 | ACQUIRE_CRYPT_LOCK; |
| 791 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 792 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 796 | int32_t userId, int32_t userSerial, |
| 797 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 798 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 799 | std::string empty_string = ""; |
| 800 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 801 | CHECK_ARGUMENT_HEX(uuid_); |
| 802 | |
| 803 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 804 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 808 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 809 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 810 | std::string empty_string = ""; |
| 811 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 812 | CHECK_ARGUMENT_HEX(uuid_); |
| 813 | |
| 814 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 815 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 816 | } |
| 817 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 818 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 819 | int32_t appId, const std::string& sandboxId, |
| 820 | int32_t userId) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 821 | return ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 825 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 826 | int32_t userId) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 827 | return ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 830 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 831 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 832 | ACQUIRE_LOCK; |
| 833 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 834 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 837 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 838 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 839 | ACQUIRE_LOCK; |
| 840 | |
| 841 | *_aidl_return = cp_needsRollback(); |
| 842 | return ok(); |
| 843 | } |
| 844 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 845 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 846 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 847 | ACQUIRE_LOCK; |
| 848 | |
| 849 | *_aidl_return = cp_needsCheckpoint(); |
| 850 | return ok(); |
| 851 | } |
| 852 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 853 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 854 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 855 | ACQUIRE_LOCK; |
| 856 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 857 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 860 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 861 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 862 | ACQUIRE_LOCK; |
| 863 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 864 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 867 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 868 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 869 | CHECK_ARGUMENT_PATH(mountPoint); |
| 870 | ACQUIRE_LOCK; |
| 871 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 872 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 875 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 876 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 877 | CHECK_ARGUMENT_PATH(mountPoint); |
| 878 | ACQUIRE_LOCK; |
| 879 | |
| 880 | return cp_restoreCheckpoint(mountPoint, count); |
| 881 | } |
| 882 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 883 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 884 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 885 | ACQUIRE_LOCK; |
| 886 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 887 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 890 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 891 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 892 | ACQUIRE_LOCK; |
| 893 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 894 | cp_abortChanges(message, retry); |
| 895 | return ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 898 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 899 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 900 | ACQUIRE_LOCK; |
| 901 | |
| 902 | return cp_supportsCheckpoint(*_aidl_return); |
| 903 | } |
| 904 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 905 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 906 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 907 | ACQUIRE_LOCK; |
| 908 | |
| 909 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 910 | } |
| 911 | |
| 912 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 913 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 914 | ACQUIRE_LOCK; |
| 915 | |
| 916 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 917 | } |
| 918 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 919 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame^] | 920 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 921 | ACQUIRE_LOCK; |
| 922 | |
| 923 | cp_resetCheckpoint(); |
| 924 | return ok(); |
| 925 | } |
| 926 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 927 | } // namespace vold |
| 928 | } // namespace android |