1*33f37583SAndroid Build Coastguard Worker /* 2*33f37583SAndroid Build Coastguard Worker * Copyright (C) 2018 The Android Open Source Project 3*33f37583SAndroid Build Coastguard Worker * 4*33f37583SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*33f37583SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*33f37583SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*33f37583SAndroid Build Coastguard Worker * 8*33f37583SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*33f37583SAndroid Build Coastguard Worker * 10*33f37583SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*33f37583SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*33f37583SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*33f37583SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*33f37583SAndroid Build Coastguard Worker * limitations under the License. 15*33f37583SAndroid Build Coastguard Worker */ 16*33f37583SAndroid Build Coastguard Worker 17*33f37583SAndroid Build Coastguard Worker #include "apexd_checkpoint_vold.h" 18*33f37583SAndroid Build Coastguard Worker 19*33f37583SAndroid Build Coastguard Worker #include <android-base/logging.h> 20*33f37583SAndroid Build Coastguard Worker #include <android/os/IVold.h> 21*33f37583SAndroid Build Coastguard Worker #include <binder/IServiceManager.h> 22*33f37583SAndroid Build Coastguard Worker 23*33f37583SAndroid Build Coastguard Worker using android::sp; 24*33f37583SAndroid Build Coastguard Worker using android::base::Error; 25*33f37583SAndroid Build Coastguard Worker using android::base::Result; 26*33f37583SAndroid Build Coastguard Worker using android::os::IVold; 27*33f37583SAndroid Build Coastguard Worker 28*33f37583SAndroid Build Coastguard Worker namespace android { 29*33f37583SAndroid Build Coastguard Worker namespace apex { 30*33f37583SAndroid Build Coastguard Worker Create()31*33f37583SAndroid Build Coastguard WorkerResult<VoldCheckpointInterface> VoldCheckpointInterface::Create() { 32*33f37583SAndroid Build Coastguard Worker auto vold_service = 33*33f37583SAndroid Build Coastguard Worker defaultServiceManager()->getService(android::String16("vold")); 34*33f37583SAndroid Build Coastguard Worker if (vold_service != nullptr) { 35*33f37583SAndroid Build Coastguard Worker return VoldCheckpointInterface( 36*33f37583SAndroid Build Coastguard Worker android::interface_cast<android::os::IVold>(vold_service)); 37*33f37583SAndroid Build Coastguard Worker } 38*33f37583SAndroid Build Coastguard Worker return Errorf("Failed to retrieve vold service."); 39*33f37583SAndroid Build Coastguard Worker } 40*33f37583SAndroid Build Coastguard Worker VoldCheckpointInterface(sp<IVold> && vold_service)41*33f37583SAndroid Build Coastguard WorkerVoldCheckpointInterface::VoldCheckpointInterface(sp<IVold>&& vold_service) { 42*33f37583SAndroid Build Coastguard Worker vold_service_ = vold_service; 43*33f37583SAndroid Build Coastguard Worker supports_fs_checkpoints_ = false; 44*33f37583SAndroid Build Coastguard Worker android::binder::Status status = 45*33f37583SAndroid Build Coastguard Worker vold_service_->supportsCheckpoint(&supports_fs_checkpoints_); 46*33f37583SAndroid Build Coastguard Worker if (!status.isOk()) { 47*33f37583SAndroid Build Coastguard Worker LOG(ERROR) << "Failed to check if filesystem checkpoints are supported: " 48*33f37583SAndroid Build Coastguard Worker << status.toString8().c_str(); 49*33f37583SAndroid Build Coastguard Worker } 50*33f37583SAndroid Build Coastguard Worker } 51*33f37583SAndroid Build Coastguard Worker VoldCheckpointInterface(VoldCheckpointInterface && other)52*33f37583SAndroid Build Coastguard WorkerVoldCheckpointInterface::VoldCheckpointInterface( 53*33f37583SAndroid Build Coastguard Worker VoldCheckpointInterface&& other) noexcept { 54*33f37583SAndroid Build Coastguard Worker vold_service_ = std::move(other.vold_service_); 55*33f37583SAndroid Build Coastguard Worker supports_fs_checkpoints_ = other.supports_fs_checkpoints_; 56*33f37583SAndroid Build Coastguard Worker } 57*33f37583SAndroid Build Coastguard Worker ~VoldCheckpointInterface()58*33f37583SAndroid Build Coastguard WorkerVoldCheckpointInterface::~VoldCheckpointInterface() { 59*33f37583SAndroid Build Coastguard Worker // Just here to be able to forward-declare IVold. 60*33f37583SAndroid Build Coastguard Worker } 61*33f37583SAndroid Build Coastguard Worker SupportsFsCheckpoints()62*33f37583SAndroid Build Coastguard WorkerResult<bool> VoldCheckpointInterface::SupportsFsCheckpoints() { 63*33f37583SAndroid Build Coastguard Worker return supports_fs_checkpoints_; 64*33f37583SAndroid Build Coastguard Worker } 65*33f37583SAndroid Build Coastguard Worker NeedsCheckpoint()66*33f37583SAndroid Build Coastguard WorkerResult<bool> VoldCheckpointInterface::NeedsCheckpoint() { 67*33f37583SAndroid Build Coastguard Worker if (supports_fs_checkpoints_) { 68*33f37583SAndroid Build Coastguard Worker bool needs_checkpoint = false; 69*33f37583SAndroid Build Coastguard Worker android::binder::Status status = 70*33f37583SAndroid Build Coastguard Worker vold_service_->needsCheckpoint(&needs_checkpoint); 71*33f37583SAndroid Build Coastguard Worker if (!status.isOk()) { 72*33f37583SAndroid Build Coastguard Worker return Error() << status.toString8().c_str(); 73*33f37583SAndroid Build Coastguard Worker } 74*33f37583SAndroid Build Coastguard Worker return needs_checkpoint; 75*33f37583SAndroid Build Coastguard Worker } 76*33f37583SAndroid Build Coastguard Worker return false; 77*33f37583SAndroid Build Coastguard Worker } 78*33f37583SAndroid Build Coastguard Worker NeedsRollback()79*33f37583SAndroid Build Coastguard WorkerResult<bool> VoldCheckpointInterface::NeedsRollback() { 80*33f37583SAndroid Build Coastguard Worker if (supports_fs_checkpoints_) { 81*33f37583SAndroid Build Coastguard Worker bool needs_rollback = false; 82*33f37583SAndroid Build Coastguard Worker android::binder::Status status = 83*33f37583SAndroid Build Coastguard Worker vold_service_->needsRollback(&needs_rollback); 84*33f37583SAndroid Build Coastguard Worker if (!status.isOk()) { 85*33f37583SAndroid Build Coastguard Worker return Error() << status.toString8().c_str(); 86*33f37583SAndroid Build Coastguard Worker } 87*33f37583SAndroid Build Coastguard Worker return needs_rollback; 88*33f37583SAndroid Build Coastguard Worker } 89*33f37583SAndroid Build Coastguard Worker return false; 90*33f37583SAndroid Build Coastguard Worker } 91*33f37583SAndroid Build Coastguard Worker AbortChanges(const std::string & msg,bool retry)92*33f37583SAndroid Build Coastguard WorkerResult<void> VoldCheckpointInterface::AbortChanges(const std::string& msg, 93*33f37583SAndroid Build Coastguard Worker bool retry) { 94*33f37583SAndroid Build Coastguard Worker vold_service_->abortChanges(msg, retry); 95*33f37583SAndroid Build Coastguard Worker return {}; 96*33f37583SAndroid Build Coastguard Worker } 97*33f37583SAndroid Build Coastguard Worker 98*33f37583SAndroid Build Coastguard Worker } // namespace apex 99*33f37583SAndroid Build Coastguard Worker } // namespace android 100