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

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

Merge "SnaspshotManager uses SnapshotMergeStats" am: beb3125d

Change-Id: I1ac79aea1c1067ab0b13bc4c7095cdc9f58b4adb
parents 2ef5b50b beb3125d
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -179,7 +179,7 @@ class SnapshotManager final {
    //   - Unverified if called on the source slot
    //   - Unverified if called on the source slot
    //   - MergeCompleted if merge is completed
    //   - MergeCompleted if merge is completed
    //   - other states indicating an error has occurred
    //   - 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
    // 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.
    // merge. If the merge has not been initiated (but should be), wait.
+15 −1
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@
#include "device_info.h"
#include "device_info.h"
#include "partition_cow_creator.h"
#include "partition_cow_creator.h"
#include "snapshot_metadata_updater.h"
#include "snapshot_metadata_updater.h"
#include "snapshot_stats.h"
#include "utility.h"
#include "utility.h"


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


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


    SnapshotMergeStats merge_stats(*this);

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


    LOG(INFO) << "Waiting for any previous merge request to complete. "
    LOG(INFO) << "Waiting for any previous merge request to complete. "
              << "This can take up to several minutes.";
              << "This can take up to several minutes.";
    merge_stats.Resume();
    auto state = ProcessUpdateState(callback);
    auto state = ProcessUpdateState(callback);
    merge_stats.set_state(state);
    if (state == UpdateState::None) {
    if (state == UpdateState::None) {
        LOG(INFO) << "Can't find any snapshot to merge.";
        LOG(INFO) << "Can't find any snapshot to merge.";
        return state;
        return state;
@@ -2419,6 +2424,11 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
            LOG(INFO) << "Cannot merge until device reboots.";
            LOG(INFO) << "Cannot merge until device reboots.";
            return state;
            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()) {
        if (!InitiateMerge()) {
            LOG(ERROR) << "Failed to initiate merge.";
            LOG(ERROR) << "Failed to initiate merge.";
            return state;
            return state;
@@ -2427,9 +2437,13 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
        LOG(INFO) << "Waiting for merge to complete. This can take up to several minutes.";
        LOG(INFO) << "Waiting for merge to complete. This can take up to several minutes.";
        last_progress = 0;
        last_progress = 0;
        state = ProcessUpdateState(callback);
        state = ProcessUpdateState(callback);
        merge_stats.set_state(state);
    }
    }


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