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

Commit ae2558d9 authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: RemoveUpdateState on rollback.

If rollback is detected in ProcessUpdateState, call
RemoveUpdateState and return UpdateState::Cancelled. Now that
update_engine is reponsible for initiating the merge, it can react to
this state and clean up markers appropriately.

Test: libsnapshot_test
Test: apply OTA, manually rollback (by setting the active slot), then
  inspect /metadata/ota as well as /data/misc/update_engine/prefs.

Bug: 147696014

Change-Id: Ibfee11fb50e4f4fb7c6cf02b4921b35e77b8f5a5
Merged-In: Ibfee11fb50e4f4fb7c6cf02b4921b35e77b8f5a5
parent 1d32aa1a
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());