Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 780ea239 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Simplify wipe handling in recovery." into main

parents 5b7dfb0d c85af559
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -104,6 +104,24 @@ bool DeviceInfo::IsFirstStageInit() const {
    return first_stage_init_;
}

bool DeviceInfo::SetActiveBootSlot([[maybe_unused]] unsigned int slot) {
#ifdef LIBSNAPSHOT_USE_HAL
    if (!EnsureBootHal()) {
        return false;
    }

    CommandResult result = boot_control_->SetActiveBootSlot(slot);
    if (!result.success) {
        LOG(ERROR) << "Error setting slot " << slot << " active: " << result.errMsg;
        return false;
    }
    return true;
#else
    LOG(ERROR) << "HAL support not enabled.";
    return false;
#endif
}

bool DeviceInfo::SetSlotAsUnbootable([[maybe_unused]] unsigned int slot) {
#ifdef LIBSNAPSHOT_USE_HAL
    if (!EnsureBootHal()) {
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class DeviceInfo final : public SnapshotManager::IDeviceInfo {
    std::string GetSuperDevice(uint32_t slot) const override;
    bool IsOverlayfsSetup() const override;
    bool SetBootControlMergeStatus(MergeStatus status) override;
    bool SetActiveBootSlot(unsigned int slot) override;
    bool SetSlotAsUnbootable(unsigned int slot) override;
    bool IsRecovery() const override;
    std::unique_ptr<IImageManager> OpenImageManager() const override;
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class MockDeviceInfo : public SnapshotManager::IDeviceInfo {
    MOCK_METHOD(const android::fs_mgr::IPartitionOpener&, GetPartitionOpener, (), (const));
    MOCK_METHOD(bool, IsOverlayfsSetup, (), (const, override));
    MOCK_METHOD(bool, SetBootControlMergeStatus, (MergeStatus status), (override));
    MOCK_METHOD(bool, SetActiveBootSlot, (unsigned int slot), (override));
    MOCK_METHOD(bool, SetSlotAsUnbootable, (unsigned int slot), (override));
    MOCK_METHOD(bool, IsRecovery, (), (const, override));
    MOCK_METHOD(bool, IsFirstStageInit, (), (const, override));
+5 −6
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ class ISnapshotManager {
        virtual const android::fs_mgr::IPartitionOpener& GetPartitionOpener() const = 0;
        virtual bool IsOverlayfsSetup() const = 0;
        virtual bool SetBootControlMergeStatus(MergeStatus status) = 0;
        virtual bool SetActiveBootSlot(unsigned int slot) = 0;
        virtual bool SetSlotAsUnbootable(unsigned int slot) = 0;
        virtual bool IsRecovery() const = 0;
        virtual bool IsTestDevice() const { return false; }
@@ -675,6 +676,8 @@ class SnapshotManager final : public ISnapshotManager {
    std::string GetBootSnapshotsWithoutSlotSwitchPath();
    std::string GetSnapuserdFromSystemPath();

    bool HasForwardMergeIndicator();

    const LpMetadata* ReadOldPartitionMetadata(LockedFile* lock);

    bool MapAllPartitions(LockedFile* lock, const std::string& super_device, uint32_t slot,
@@ -785,11 +788,8 @@ class SnapshotManager final : public ISnapshotManager {
    bool UpdateForwardMergeIndicator(bool wipe);

    // Helper for HandleImminentDataWipe.
    // Call ProcessUpdateState and handle states with special rules before data wipe. Specifically,
    // if |allow_forward_merge| and allow-forward-merge indicator exists, initiate merge if
    // necessary.
    UpdateState ProcessUpdateStateOnDataWipe(bool allow_forward_merge,
                                             const std::function<bool()>& callback);
    // Call ProcessUpdateState and handle states with special rules before data wipe.
    UpdateState ProcessUpdateStateOnDataWipe(const std::function<bool()>& callback);

    // Return device string of a mapped image, or if it is not available, the mapped image path.
    bool GetMappedImageDeviceStringOrPath(const std::string& device_name,
@@ -848,7 +848,6 @@ class SnapshotManager final : public ISnapshotManager {
    std::string metadata_dir_;
    std::unique_ptr<IImageManager> images_;
    bool use_first_stage_snapuserd_ = false;
    bool in_factory_data_reset_ = false;
    std::function<bool(const std::string&)> uevent_regen_callback_;
    std::unique_ptr<SnapuserdClient> snapuserd_client_;
    std::unique_ptr<LpMetadata> old_partition_metadata_;
+1 −0
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo {
    }
    bool IsOverlayfsSetup() const override { return false; }
    bool IsRecovery() const override { return recovery_; }
    bool SetActiveBootSlot([[maybe_unused]] unsigned int slot) override { return true; }
    bool SetSlotAsUnbootable(unsigned int slot) override {
        unbootable_slots_.insert(slot);
        return true;
Loading