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