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