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

Commit 8fb3ab5f authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

libsnapshot: RemoveUpdateState on rollback. am: ae2558d9

Change-Id: I65ab6e6250e3ed1a56c9bd2901fcd17bd268c839
parents 99edc19a ae2558d9
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -1185,17 +1185,34 @@ bool SnapshotManager::HandleCancelledUpdate(LockedFile* lock,

    // If all snapshots were reflashed, then cancel the entire update.
    if (AreAllSnapshotsCancelled(lock)) {
        LOG(WARNING) << "Detected re-flashing, cancelling unverified update.";
        RemoveAllUpdateState(lock, before_cancel);
        return true;
    }

    // This unverified update might be rolled back, or it might not (b/147347110
    // comment #77). Take no action, as update_engine is responsible for deciding
    // whether to cancel.
    LOG(ERROR) << "Update state is being processed before reboot, taking no action.";
    // If update has been rolled back, then cancel the entire update.
    // Client (update_engine) is responsible for doing additional cleanup work on its own states
    // when ProcessUpdateState() returns UpdateState::Cancelled.
    auto current_slot = GetCurrentSlot();
    if (current_slot != Slot::Source) {
        LOG(INFO) << "Update state is being processed while booting at " << current_slot
                  << " slot, taking no action.";
        return false;
    }

    // current_slot == Source. Attempt to detect rollbacks.
    if (access(GetRollbackIndicatorPath().c_str(), F_OK) != 0) {
        // This unverified update is not attempted. Take no action.
        PLOG(INFO) << "Rollback indicator not detected. "
                   << "Update state is being processed before reboot, taking no action.";
        return false;
    }

    LOG(WARNING) << "Detected rollback, cancelling unverified update.";
    RemoveAllUpdateState(lock, before_cancel);
    return true;
}

std::unique_ptr<LpMetadata> SnapshotManager::ReadCurrentMetadata() {
    const auto& opener = device_->GetPartitionOpener();
    uint32_t slot = SlotNumberForSlotSuffix(device_->GetSlotSuffix());