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

Commit 43ae37ba authored by Alessio Balsini's avatar Alessio Balsini
Browse files

Merge "SnaspshotManager uses SnapshotMergeStats" am: beb3125d am: c16d61d6 am: 80ce91a5

Change-Id: I1eab478e557cf675ed700b7041d4faa052288106
parents fa9e5f16 80ce91a5
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;
}