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