Weston Carvalho | 6ab2065 | 2024-12-03 15:21:45 -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 | |
| 17 | #include "VendorVoldNativeService.h" |
| 18 | |
| 19 | #include <mutex> |
| 20 | |
| 21 | #include <android-base/logging.h> |
| 22 | #include <binder/IServiceManager.h> |
| 23 | #include <private/android_filesystem_config.h> |
| 24 | #include <utils/Trace.h> |
| 25 | |
| 26 | #include "Checkpoint.h" |
| 27 | #include "VoldNativeServiceValidation.h" |
| 28 | #include "VolumeManager.h" |
| 29 | |
| 30 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 31 | { \ |
| 32 | binder::Status status = CheckUidOrRoot(AID_SYSTEM); \ |
| 33 | if (!status.isOk()) { \ |
| 34 | return status; \ |
| 35 | } \ |
| 36 | } |
| 37 | |
| 38 | #define ACQUIRE_LOCK \ |
| 39 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 40 | ATRACE_CALL(); |
| 41 | |
| 42 | namespace android::vold { |
| 43 | |
| 44 | status_t VendorVoldNativeService::try_start() { |
| 45 | auto service_name = String16("android.system.vold.IVold/default"); |
| 46 | if (!defaultServiceManager()->isDeclared(service_name)) { |
| 47 | LOG(DEBUG) << "Service for VendorVoldNativeService (" << service_name << ") not declared."; |
| 48 | return OK; |
| 49 | } |
| 50 | return defaultServiceManager()->addService(std::move(service_name), |
| 51 | new VendorVoldNativeService()); |
| 52 | } |
| 53 | |
| 54 | binder::Status VendorVoldNativeService::registerCheckpointListener( |
| 55 | const sp<android::system::vold::IVoldCheckpointListener>& listener, |
| 56 | android::system::vold::CheckpointingState* _aidl_return) { |
| 57 | ENFORCE_SYSTEM_OR_ROOT; |
| 58 | ACQUIRE_LOCK; |
| 59 | |
| 60 | bool possible_checkpointing = cp_registerCheckpointListener(listener); |
| 61 | *_aidl_return = possible_checkpointing |
| 62 | ? android::system::vold::CheckpointingState::POSSIBLE_CHECKPOINTING |
| 63 | : android::system::vold::CheckpointingState::CHECKPOINTING_COMPLETE; |
| 64 | return binder::Status::ok(); |
| 65 | } |
| 66 | |
| 67 | } // namespace android::vold |