1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <libsnapshot/snapshot_stub.h>
16 
17 #include <android-base/logging.h>
18 
19 #include <libsnapshot/snapshot_stats.h>
20 
21 using android::fs_mgr::CreateLogicalPartitionParams;
22 using chromeos_update_engine::DeltaArchiveManifest;
23 using chromeos_update_engine::FileDescriptor;
24 
25 namespace android::snapshot {
26 
New()27 std::unique_ptr<ISnapshotManager> SnapshotManagerStub::New() {
28     return std::make_unique<SnapshotManagerStub>();
29 }
30 
BeginUpdate()31 bool SnapshotManagerStub::BeginUpdate() {
32     LOG(ERROR) << __FUNCTION__ << " should never be called.";
33     return false;
34 }
35 
CancelUpdate()36 bool SnapshotManagerStub::CancelUpdate() {
37     LOG(ERROR) << __FUNCTION__ << " should never be called.";
38     return false;
39 }
40 
FinishedSnapshotWrites(bool)41 bool SnapshotManagerStub::FinishedSnapshotWrites(bool) {
42     LOG(ERROR) << __FUNCTION__ << " should never be called.";
43     return false;
44 }
45 
InitiateMerge()46 bool SnapshotManagerStub::InitiateMerge() {
47     LOG(ERROR) << __FUNCTION__ << " should never be called.";
48     return false;
49 }
50 
ProcessUpdateState(const std::function<bool ()> &,const std::function<bool ()> &)51 UpdateState SnapshotManagerStub::ProcessUpdateState(const std::function<bool()>&,
52                                                     const std::function<bool()>&) {
53     LOG(ERROR) << __FUNCTION__ << " should never be called.";
54     return UpdateState::None;
55 }
56 
GetUpdateState(double *)57 UpdateState SnapshotManagerStub::GetUpdateState(double*) {
58     LOG(ERROR) << __FUNCTION__ << " should never be called.";
59     return UpdateState::None;
60 }
61 
CreateUpdateSnapshots(const DeltaArchiveManifest &)62 Return SnapshotManagerStub::CreateUpdateSnapshots(const DeltaArchiveManifest&) {
63     LOG(ERROR) << __FUNCTION__ << " should never be called.";
64     return Return::Error();
65 }
66 
MapUpdateSnapshot(const CreateLogicalPartitionParams &,std::string *)67 bool SnapshotManagerStub::MapUpdateSnapshot(const CreateLogicalPartitionParams&, std::string*) {
68     LOG(ERROR) << __FUNCTION__ << " should never be called.";
69     return false;
70 }
71 
UnmapUpdateSnapshot(const std::string &)72 bool SnapshotManagerStub::UnmapUpdateSnapshot(const std::string&) {
73     LOG(ERROR) << __FUNCTION__ << " should never be called.";
74     return false;
75 }
76 
NeedSnapshotsInFirstStageMount()77 bool SnapshotManagerStub::NeedSnapshotsInFirstStageMount() {
78     LOG(ERROR) << __FUNCTION__ << " should never be called.";
79     return false;
80 }
81 
CreateLogicalAndSnapshotPartitions(const std::string &,const std::chrono::milliseconds &)82 bool SnapshotManagerStub::CreateLogicalAndSnapshotPartitions(const std::string&,
83                                                              const std::chrono::milliseconds&) {
84     LOG(ERROR) << __FUNCTION__ << " should never be called.";
85     return false;
86 }
87 
HandleImminentDataWipe(const std::function<void ()> &)88 bool SnapshotManagerStub::HandleImminentDataWipe(const std::function<void()>&) {
89     LOG(ERROR) << __FUNCTION__ << " should never be called.";
90     return false;
91 }
92 
FinishMergeInRecovery()93 bool SnapshotManagerStub::FinishMergeInRecovery() {
94     LOG(ERROR) << __FUNCTION__ << " should never be called.";
95     return false;
96 }
97 
RecoveryCreateSnapshotDevices()98 CreateResult SnapshotManagerStub::RecoveryCreateSnapshotDevices() {
99     LOG(ERROR) << __FUNCTION__ << " should never be called.";
100     return CreateResult::ERROR;
101 }
102 
RecoveryCreateSnapshotDevices(const std::unique_ptr<AutoDevice> &)103 CreateResult SnapshotManagerStub::RecoveryCreateSnapshotDevices(
104         const std::unique_ptr<AutoDevice>&) {
105     LOG(ERROR) << __FUNCTION__ << " should never be called.";
106     return CreateResult::ERROR;
107 }
108 
Dump(std::ostream &)109 bool SnapshotManagerStub::Dump(std::ostream&) {
110     LOG(ERROR) << __FUNCTION__ << " should never be called.";
111     return false;
112 }
113 
EnsureMetadataMounted()114 std::unique_ptr<AutoDevice> SnapshotManagerStub::EnsureMetadataMounted() {
115     LOG(ERROR) << __FUNCTION__ << " should never be called.";
116     return nullptr;
117 }
118 
UpdateUsesCompression()119 bool SnapshotManagerStub::UpdateUsesCompression() {
120     LOG(ERROR) << __FUNCTION__ << " should never be called.";
121     return false;
122 }
123 
124 class SnapshotMergeStatsStub : public ISnapshotMergeStats {
Start()125     bool Start() override { return false; }
set_state(android::snapshot::UpdateState,bool)126     void set_state(android::snapshot::UpdateState, bool) override {}
set_cow_file_size(uint64_t)127     void set_cow_file_size(uint64_t) override {}
cow_file_size()128     uint64_t cow_file_size() override { return 0; }
Finish()129     std::unique_ptr<Result> Finish() override { return nullptr; }
set_total_cow_size_bytes(uint64_t)130     void set_total_cow_size_bytes(uint64_t) override {}
set_estimated_cow_size_bytes(uint64_t)131     void set_estimated_cow_size_bytes(uint64_t) override {}
total_cow_size_bytes()132     uint64_t total_cow_size_bytes() override { return 0; }
estimated_cow_size_bytes()133     uint64_t estimated_cow_size_bytes() override { return 0; }
set_boot_complete_time_ms(uint32_t)134     void set_boot_complete_time_ms(uint32_t) override {}
boot_complete_time_ms()135     uint32_t boot_complete_time_ms() override { return 0; }
set_boot_complete_to_merge_start_time_ms(uint32_t)136     void set_boot_complete_to_merge_start_time_ms(uint32_t) override {}
boot_complete_to_merge_start_time_ms()137     uint32_t boot_complete_to_merge_start_time_ms() override { return 0; }
set_merge_failure_code(MergeFailureCode)138     void set_merge_failure_code(MergeFailureCode) override {}
merge_failure_code()139     MergeFailureCode merge_failure_code() override { return MergeFailureCode::Ok; }
set_source_build_fingerprint(const std::string &)140     void set_source_build_fingerprint(const std::string&) override {}
source_build_fingerprint()141     std::string source_build_fingerprint() override { return {}; }
WriteState()142     bool WriteState() override { return false; }
143 };
144 
GetSnapshotMergeStatsInstance()145 ISnapshotMergeStats* SnapshotManagerStub::GetSnapshotMergeStatsInstance() {
146     static SnapshotMergeStatsStub snapshot_merge_stats;
147     LOG(ERROR) << __FUNCTION__ << " should never be called.";
148     return &snapshot_merge_stats;
149 }
150 
OpenSnapshotWriter(const CreateLogicalPartitionParams &,const std::optional<std::string> &)151 std::unique_ptr<ISnapshotWriter> SnapshotManagerStub::OpenSnapshotWriter(
152         const CreateLogicalPartitionParams&, const std::optional<std::string>&) {
153     LOG(ERROR) << __FUNCTION__ << " should never be called.";
154     return nullptr;
155 }
156 
MapAllSnapshots(const std::chrono::milliseconds &)157 bool SnapshotManagerStub::MapAllSnapshots(const std::chrono::milliseconds&) {
158     LOG(ERROR) << __FUNCTION__ << " should never be called.";
159     return false;
160 }
161 
UnmapAllSnapshots()162 bool SnapshotManagerStub::UnmapAllSnapshots() {
163     LOG(ERROR) << __FUNCTION__ << " should never be called.";
164     return false;
165 }
166 
UpdateCowStats(ISnapshotMergeStats *)167 void SnapshotManagerStub::UpdateCowStats(ISnapshotMergeStats*) {
168     LOG(ERROR) << __FUNCTION__ << " should never be called.";
169 }
170 
ReadMergeFailureCode()171 auto SnapshotManagerStub::ReadMergeFailureCode() -> MergeFailureCode {
172     LOG(ERROR) << __FUNCTION__ << " should never be called.";
173     return MergeFailureCode::Ok;
174 }
175 
ReadSourceBuildFingerprint()176 std::string SnapshotManagerStub::ReadSourceBuildFingerprint() {
177     LOG(ERROR) << __FUNCTION__ << " should never be called.";
178     return {};
179 }
180 
181 }  // namespace android::snapshot
182