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

Commit 0e609429 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Automerger Merge Worker
Browse files

Merge "libsnapshot: Check if OTA update in progress during reboot" into main...

Merge "libsnapshot: Check if OTA update in progress during reboot" into main am: 41305c38 am: a9e02133

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2829570



Change-Id: Id2a3df38ac8e39d3dca25a97d279921d2b625ca3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 7e52cf3f a9e02133
Loading
Loading
Loading
Loading
+19 −21
Original line number Diff line number Diff line
@@ -4339,32 +4339,30 @@ std::string SnapshotManager::ReadSourceBuildFingerprint() {
}

bool SnapshotManager::IsUserspaceSnapshotUpdateInProgress() {
    auto slot = GetCurrentSlot();
    if (slot == Slot::Target) {
        // Merge in-progress
        if (IsSnapuserdRequired()) {
            return true;
        }
    }

    // Let's check more deeper to see if snapshots are mounted
    auto lock = LockExclusive();
    if (!lock) {
    // We cannot grab /metadata/ota lock here as this
    // is in reboot path. See b/308900853
    //
    // Check if any of the partitions are mounted
    // off dm-user block device. If so, then we are certain
    // that OTA update in progress.
    auto current_suffix = device_->GetSlotSuffix();
    auto& dm = DeviceMapper::Instance();
    auto dm_block_devices = dm.FindDmPartitions();
    if (dm_block_devices.empty()) {
        LOG(ERROR) << "No dm-enabled block device is found.";
        return false;
    }

    std::vector<std::string> snapshots;
    if (!ListSnapshots(lock.get(), &snapshots)) {
    for (auto& partition : dm_block_devices) {
        std::string partition_name = partition.first + current_suffix;
        DeviceMapper::TargetInfo snap_target;
        if (!GetSingleTarget(partition_name, TableQuery::Status, &snap_target)) {
            return false;
        }

    for (const auto& snapshot : snapshots) {
        // Active snapshot and daemon is alive
        if (IsSnapshotDevice(snapshot) && EnsureSnapuserdConnected(2s)) {
        auto type = DeviceMapper::GetTargetType(snap_target.spec);
        if (type == "user") {
            return true;
        }
    }

    return false;
}