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 
UpdateUsesUserSnapshots()124 bool SnapshotManagerStub::UpdateUsesUserSnapshots() {
125     LOG(ERROR) << __FUNCTION__ << " should never be called.";
126     return false;
127 }
128 
129 class SnapshotMergeStatsStub : public ISnapshotMergeStats {
Start()130     bool Start() override { return false; }
set_state(android::snapshot::UpdateState)131     void set_state(android::snapshot::UpdateState) override {}
cow_file_size()132     uint64_t cow_file_size() override { return 0; }
Finish()133     std::unique_ptr<Result> Finish() override { return nullptr; }
total_cow_size_bytes()134     uint64_t total_cow_size_bytes() override { return 0; }
estimated_cow_size_bytes()135     uint64_t estimated_cow_size_bytes() override { return 0; }
set_boot_complete_time_ms(uint32_t)136     void set_boot_complete_time_ms(uint32_t) override {}
boot_complete_time_ms()137     uint32_t boot_complete_time_ms() override { return 0; }
set_boot_complete_to_merge_start_time_ms(uint32_t)138     void set_boot_complete_to_merge_start_time_ms(uint32_t) override {}
boot_complete_to_merge_start_time_ms()139     uint32_t boot_complete_to_merge_start_time_ms() override { return 0; }
set_merge_failure_code(MergeFailureCode)140     void set_merge_failure_code(MergeFailureCode) override {}
merge_failure_code()141     MergeFailureCode merge_failure_code() override { return MergeFailureCode::Ok; }
set_source_build_fingerprint(const std::string &)142     void set_source_build_fingerprint(const std::string&) override {}
source_build_fingerprint()143     std::string source_build_fingerprint() override { return {}; }
WriteState()144     bool WriteState() override { return false; }
report()145     SnapshotMergeReport* report() override { return &report_; }
146 
147   private:
148     SnapshotMergeReport report_;
149 };
150 
GetSnapshotMergeStatsInstance()151 ISnapshotMergeStats* SnapshotManagerStub::GetSnapshotMergeStatsInstance() {
152     static SnapshotMergeStatsStub snapshot_merge_stats;
153     LOG(ERROR) << __FUNCTION__ << " should never be called.";
154     return &snapshot_merge_stats;
155 }
156 
OpenSnapshotWriter(const CreateLogicalPartitionParams &,std::optional<uint64_t>)157 std::unique_ptr<ICowWriter> SnapshotManagerStub::OpenSnapshotWriter(
158         const CreateLogicalPartitionParams&, std::optional<uint64_t>) {
159     LOG(ERROR) << __FUNCTION__ << " should never be called.";
160     return nullptr;
161 }
162 
MapAllSnapshots(const std::chrono::milliseconds &)163 bool SnapshotManagerStub::MapAllSnapshots(const std::chrono::milliseconds&) {
164     LOG(ERROR) << __FUNCTION__ << " should never be called.";
165     return false;
166 }
167 
UnmapAllSnapshots()168 bool SnapshotManagerStub::UnmapAllSnapshots() {
169     LOG(ERROR) << __FUNCTION__ << " should never be called.";
170     return false;
171 }
172 
UpdateCowStats(ISnapshotMergeStats *)173 void SnapshotManagerStub::UpdateCowStats(ISnapshotMergeStats*) {
174     LOG(ERROR) << __FUNCTION__ << " should never be called.";
175 }
176 
ReadMergeFailureCode()177 auto SnapshotManagerStub::ReadMergeFailureCode() -> MergeFailureCode {
178     LOG(ERROR) << __FUNCTION__ << " should never be called.";
179     return MergeFailureCode::Ok;
180 }
181 
ReadSourceBuildFingerprint()182 std::string SnapshotManagerStub::ReadSourceBuildFingerprint() {
183     LOG(ERROR) << __FUNCTION__ << " should never be called.";
184     return {};
185 }
186 
SetMergeStatsFeatures(ISnapshotMergeStats *)187 void SnapshotManagerStub::SetMergeStatsFeatures(ISnapshotMergeStats*) {
188     LOG(ERROR) << __FUNCTION__ << " should never be called.";
189 }
190 
191 }  // namespace android::snapshot
192