1 /* 2 * Copyright (C) 2018 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 #define LOG_TAG "apexd" 18 19 #include "apexd_checkpoint_vold.h" 20 21 #include <android-base/logging.h> 22 #include <android/os/IVold.h> 23 #include <binder/IServiceManager.h> 24 25 using android::sp; 26 using android::os::IVold; 27 28 namespace android { 29 namespace apex { 30 Create()31StatusOr<VoldCheckpointInterface> VoldCheckpointInterface::Create() { 32 auto voldService = 33 defaultServiceManager()->getService(android::String16("vold")); 34 if (voldService != nullptr) { 35 return StatusOr<VoldCheckpointInterface>(VoldCheckpointInterface( 36 android::interface_cast<android::os::IVold>(voldService))); 37 } 38 return StatusOr<VoldCheckpointInterface>::Fail( 39 "Failed to retrieve vold service."); 40 } 41 VoldCheckpointInterface(sp<IVold> && vold_service)42VoldCheckpointInterface::VoldCheckpointInterface(sp<IVold>&& vold_service) { 43 vold_service_ = vold_service; 44 supports_fs_checkpoints_ = false; 45 android::binder::Status status = 46 vold_service_->supportsCheckpoint(&supports_fs_checkpoints_); 47 if (!status.isOk()) { 48 LOG(ERROR) << "Failed to check if filesystem checkpoints are supported: " 49 << status.toString8().c_str(); 50 } 51 } 52 VoldCheckpointInterface(VoldCheckpointInterface && other)53VoldCheckpointInterface::VoldCheckpointInterface( 54 VoldCheckpointInterface&& other) noexcept { 55 vold_service_ = std::move(other.vold_service_); 56 supports_fs_checkpoints_ = other.supports_fs_checkpoints_; 57 } 58 ~VoldCheckpointInterface()59VoldCheckpointInterface::~VoldCheckpointInterface() { 60 // Just here to be able to forward-declare IVold. 61 } 62 SupportsFsCheckpoints()63StatusOr<bool> VoldCheckpointInterface::SupportsFsCheckpoints() { 64 return StatusOr<bool>(supports_fs_checkpoints_); 65 } 66 NeedsCheckpoint()67StatusOr<bool> VoldCheckpointInterface::NeedsCheckpoint() { 68 if (supports_fs_checkpoints_) { 69 bool needs_checkpoint = false; 70 android::binder::Status status = 71 vold_service_->needsCheckpoint(&needs_checkpoint); 72 if (!status.isOk()) { 73 return StatusOr<bool>::Fail(status.toString8().c_str()); 74 } 75 return StatusOr<bool>(needs_checkpoint); 76 } 77 return StatusOr<bool>(false); 78 } 79 NeedsRollback()80StatusOr<bool> VoldCheckpointInterface::NeedsRollback() { 81 if (supports_fs_checkpoints_) { 82 bool needs_rollback = false; 83 android::binder::Status status = 84 vold_service_->needsRollback(&needs_rollback); 85 if (!status.isOk()) { 86 return StatusOr<bool>::Fail(status.toString8().c_str()); 87 } 88 return StatusOr<bool>(needs_rollback); 89 } 90 return StatusOr<bool>(false); 91 } 92 StartCheckpoint(int32_t numRetries)93Status VoldCheckpointInterface::StartCheckpoint(int32_t numRetries) { 94 if (supports_fs_checkpoints_) { 95 android::binder::Status status = vold_service_->startCheckpoint(numRetries); 96 if (!status.isOk()) { 97 return Status::Fail(status.toString8().c_str()); 98 } 99 return Status::Success(); 100 } 101 return Status::Fail("Device does not support filesystem checkpointing"); 102 } 103 AbortChanges(const std::string & msg,bool retry)104Status VoldCheckpointInterface::AbortChanges(const std::string& msg, 105 bool retry) { 106 vold_service_->abortChanges(msg, retry); 107 return Status::Success(); 108 } 109 110 } // namespace apex 111 } // namespace android 112