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

Commit adfa9fdd authored by Alessio Balsini's avatar Alessio Balsini
Browse files

SnaspshotManager uses SnapshotMergeStats



The SnapshotMergeStats class is issued by SnapshotManager to track the
merge duration and possible reboots during the merge process.

Bug: 138817833
Test: m
Change-Id: I04e53bb8f6aa9e740c0dcc77c3a9566383954fba
Signed-off-by: default avatarAlessio Balsini <balsini@google.com>
parent cd3915d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ class SnapshotManager final {
    //   - Unverified if called on the source slot
    //   - MergeCompleted if merge is completed
    //   - other states indicating an error has occurred
    UpdateState InitiateMergeAndWait();
    UpdateState InitiateMergeAndWait(SnapshotMergeReport* report = nullptr);

    // Wait for the merge if rebooted into the new slot. Does NOT initiate a
    // merge. If the merge has not been initiated (but should be), wait.
+15 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include "device_info.h"
#include "partition_cow_creator.h"
#include "snapshot_metadata_updater.h"
#include "snapshot_stats.h"
#include "utility.h"

namespace android {
@@ -2387,7 +2388,7 @@ std::unique_ptr<AutoDevice> SnapshotManager::EnsureMetadataMounted() {
    return AutoUnmountDevice::New(device_->GetMetadataDir());
}

UpdateState SnapshotManager::InitiateMergeAndWait() {
UpdateState SnapshotManager::InitiateMergeAndWait(SnapshotMergeReport* stats_report) {
    {
        auto lock = LockExclusive();
        // Sync update state from file with bootloader.
@@ -2397,6 +2398,8 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
        }
    }

    SnapshotMergeStats merge_stats(*this);

    unsigned int last_progress = 0;
    auto callback = [&]() -> void {
        double progress;
@@ -2409,7 +2412,9 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {

    LOG(INFO) << "Waiting for any previous merge request to complete. "
              << "This can take up to several minutes.";
    merge_stats.Resume();
    auto state = ProcessUpdateState(callback);
    merge_stats.set_state(state);
    if (state == UpdateState::None) {
        LOG(INFO) << "Can't find any snapshot to merge.";
        return state;
@@ -2419,6 +2424,11 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
            LOG(INFO) << "Cannot merge until device reboots.";
            return state;
        }

        // This is the first snapshot merge that is requested after OTA. We can
        // initialize the merge duration statistics.
        merge_stats.Start();

        if (!InitiateMerge()) {
            LOG(ERROR) << "Failed to initiate merge.";
            return state;
@@ -2427,9 +2437,13 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
        LOG(INFO) << "Waiting for merge to complete. This can take up to several minutes.";
        last_progress = 0;
        state = ProcessUpdateState(callback);
        merge_stats.set_state(state);
    }

    LOG(INFO) << "Merge finished with state \"" << state << "\".";
    if (stats_report) {
        *stats_report = merge_stats.GetReport();
    }
    return state;
}