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