Use libsnapshot stub classes
... to avoid crashes in update_engine. The stub classes
does nothing but return a failure for all function
calls, and act as if Virtual A/B is not enabled.
Fixes: 148956645
Test: update_engine_unittests
Change-Id: I48206958aba8d9a71cc7cf49f6b9d5d4f1c8735d
diff --git a/cleanup_previous_update_action.cc b/cleanup_previous_update_action.cc
index 26cc6be..6490ca8 100644
--- a/cleanup_previous_update_action.cc
+++ b/cleanup_previous_update_action.cc
@@ -30,7 +30,7 @@
#include "update_engine/common/utils.h"
#include "update_engine/payload_consumer/delta_performer.h"
-using android::snapshot::SnapshotManager;
+using android::snapshot::ISnapshotManager;
using android::snapshot::SnapshotMergeStats;
using android::snapshot::UpdateState;
using brillo::MessageLoop;
@@ -55,7 +55,7 @@
CleanupPreviousUpdateAction::CleanupPreviousUpdateAction(
PrefsInterface* prefs,
BootControlInterface* boot_control,
- android::snapshot::SnapshotManager* snapshot,
+ android::snapshot::ISnapshotManager* snapshot,
CleanupPreviousUpdateActionDelegateInterface* delegate)
: prefs_(prefs),
boot_control_(boot_control),
@@ -64,7 +64,7 @@
running_(false),
cancel_failed_(false),
last_percentage_(0),
- merge_stats_(SnapshotMergeStats::GetInstance(*snapshot)) {}
+ merge_stats_(nullptr) {}
void CleanupPreviousUpdateAction::PerformAction() {
ResumeAction();
@@ -110,8 +110,10 @@
processor_->ActionComplete(this, ErrorCode::kSuccess);
return;
}
- // SnapshotManager is only available on VAB devices.
- CHECK(snapshot_);
+ // SnapshotManager must be available on VAB devices.
+ CHECK(snapshot_ != nullptr);
+ merge_stats_ = snapshot_->GetSnapshotMergeStatsInstance();
+ CHECK(merge_stats_ != nullptr);
WaitBootCompletedOrSchedule();
}
diff --git a/cleanup_previous_update_action.h b/cleanup_previous_update_action.h
index 91e08b0..6f6ce07 100644
--- a/cleanup_previous_update_action.h
+++ b/cleanup_previous_update_action.h
@@ -49,7 +49,7 @@
CleanupPreviousUpdateAction(
PrefsInterface* prefs,
BootControlInterface* boot_control,
- android::snapshot::SnapshotManager* snapshot,
+ android::snapshot::ISnapshotManager* snapshot,
CleanupPreviousUpdateActionDelegateInterface* delegate);
void PerformAction() override;
@@ -67,13 +67,13 @@
private:
PrefsInterface* prefs_;
BootControlInterface* boot_control_;
- android::snapshot::SnapshotManager* snapshot_;
+ android::snapshot::ISnapshotManager* snapshot_;
CleanupPreviousUpdateActionDelegateInterface* delegate_;
std::unique_ptr<android::snapshot::AutoDevice> metadata_device_;
bool running_{false};
bool cancel_failed_{false};
unsigned int last_percentage_{0};
- android::snapshot::SnapshotMergeStats* merge_stats_;
+ android::snapshot::ISnapshotMergeStats* merge_stats_;
void StartActionInternal();
void ScheduleWaitBootCompleted();
diff --git a/dynamic_partition_control_android.cc b/dynamic_partition_control_android.cc
index a310f20..bf31244 100644
--- a/dynamic_partition_control_android.cc
+++ b/dynamic_partition_control_android.cc
@@ -35,6 +35,7 @@
#include <libavb/libavb.h>
#include <libdm/dm.h>
#include <libsnapshot/snapshot.h>
+#include <libsnapshot/snapshot_stub.h>
#include "update_engine/cleanup_previous_update_action.h"
#include "update_engine/common/boot_control_interface.h"
@@ -58,6 +59,7 @@
using android::snapshot::OptimizeSourceCopyOperation;
using android::snapshot::Return;
using android::snapshot::SnapshotManager;
+using android::snapshot::SnapshotManagerStub;
using android::snapshot::UpdateState;
namespace chromeos_update_engine {
@@ -108,8 +110,10 @@
virtual_ab_(GetFeatureFlag(kVirtualAbEnabled, kVirtualAbRetrofit)) {
if (GetVirtualAbFeatureFlag().IsEnabled()) {
snapshot_ = SnapshotManager::New();
- CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager.";
+ } else {
+ snapshot_ = SnapshotManagerStub::New();
}
+ CHECK(snapshot_ != nullptr) << "Cannot initialize SnapshotManager.";
}
FeatureFlag DynamicPartitionControlAndroid::GetDynamicPartitionsFeatureFlag() {
diff --git a/dynamic_partition_control_android.h b/dynamic_partition_control_android.h
index 8ad7593..4918ea6 100644
--- a/dynamic_partition_control_android.h
+++ b/dynamic_partition_control_android.h
@@ -258,7 +258,7 @@
std::set<std::string> mapped_devices_;
const FeatureFlag dynamic_partitions_;
const FeatureFlag virtual_ab_;
- std::unique_ptr<android::snapshot::SnapshotManager> snapshot_;
+ std::unique_ptr<android::snapshot::ISnapshotManager> snapshot_;
std::unique_ptr<android::snapshot::AutoDevice> metadata_device_;
bool target_supports_snapshot_ = false;
// Whether the target partitions should be loaded as dynamic partitions. Set