diff --git a/install/include/install/snapshot_utils.h b/install/include/install/snapshot_utils.h index f4b978d2e..c572e7d30 100644 --- a/install/include/install/snapshot_utils.h +++ b/install/include/install/snapshot_utils.h @@ -18,7 +18,7 @@ #include "recovery_ui/device.h" -bool FinishPendingSnapshotMerges(Device* device); +bool FinishPendingSnapshotMerges(Device* device, bool called_from_wipe); /* * This function tries to create the snapshotted devices in the case a Virtual diff --git a/install/snapshot_utils.cpp b/install/snapshot_utils.cpp index 336e50f89..0f538662c 100644 --- a/install/snapshot_utils.cpp +++ b/install/snapshot_utils.cpp @@ -26,7 +26,7 @@ using android::snapshot::CreateResult; using android::snapshot::SnapshotManager; -bool FinishPendingSnapshotMerges(Device* device) { +bool FinishPendingSnapshotMerges(Device* device, bool called_from_wipe) { if (!android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) { return true; } @@ -38,6 +38,45 @@ bool FinishPendingSnapshotMerges(Device* device) { return false; } + if (!called_from_wipe) { + using namespace android::snapshot; + + double progress; + UpdateState update_state = sm->GetUpdateState(&progress); + + ui->Print("State of pending update: "); + + switch (update_state) { + case UpdateState::None: + ui->Print("Pending update not found\n"); + // HandleImminentDataWipe() is not a no-op even in this case, do not return + break; + case UpdateState::Initiated: + ui->Print("Initiated\n"); + break; + case UpdateState::Unverified: + ui->Print("Unverified\n"); + break; + case UpdateState::Merging: + ui->Print("Merging, progress: %.2ff\n", progress); + break; + case UpdateState::MergeNeedsReboot: + ui->Print("MergeNeedsReboot\n"); + break; + case UpdateState::MergeCompleted: + ui->Print("MergeCompleted\n"); + break; + case UpdateState::MergeFailed: + ui->Print("MergeFailed\n"); + break; + case UpdateState::Cancelled: + ui->Print("Cancelled\n"); + break; + default: + ui->Print("unknown (%i)\n", (int) update_state); + } + } + auto callback = [&]() -> void { double progress; sm->GetUpdateState(&progress); @@ -47,6 +86,9 @@ bool FinishPendingSnapshotMerges(Device* device) { ui->Print("Unable to check merge status and/or complete update merge.\n"); return false; } + if (!called_from_wipe) { + ui->Print("Operation completed successfully\n"); + } return true; } diff --git a/install/wipe_data.cpp b/install/wipe_data.cpp index 024c1e1d5..04b31211e 100644 --- a/install/wipe_data.cpp +++ b/install/wipe_data.cpp @@ -84,7 +84,7 @@ bool WipeData(Device* device) { ui->SetBackground(RecoveryUI::ERASING); ui->SetProgressType(RecoveryUI::INDETERMINATE); - if (!FinishPendingSnapshotMerges(device)) { + if (!FinishPendingSnapshotMerges(device, /* called_from_wipe */ true)) { ui->Print("Unable to check update status or complete merge, cannot wipe partitions.\n"); return false; } diff --git a/recovery.cpp b/recovery.cpp index 12bbb5029..4885f6c08 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -431,6 +431,11 @@ static Device::BuiltinAction PromptAndWait(Device* device, InstallResult status) } break; + case Device::DISCARD_PENDING_UPDATE: { + FinishPendingSnapshotMerges(device, /* called_from_wipe */ false); + break; + } + case Device::WIPE_DATA: save_current_log = true; if (ui->IsTextVisible()) { diff --git a/recovery_ui/device.cpp b/recovery_ui/device.cpp index 312d8d8e9..2f71a8381 100644 --- a/recovery_ui/device.cpp +++ b/recovery_ui/device.cpp @@ -28,6 +28,7 @@ static std::vector> g_menu_actions{ { "Reboot system now", Device::REBOOT }, + { "Discard pending OS update", Device::DISCARD_PENDING_UPDATE }, { "Reboot to bootloader", Device::REBOOT_BOOTLOADER }, { "Enter fastboot", Device::ENTER_FASTBOOT }, { "Apply update from ADB", Device::APPLY_ADB_SIDELOAD }, diff --git a/recovery_ui/include/recovery_ui/device.h b/recovery_ui/include/recovery_ui/device.h index 76166f09d..c137fbe8c 100644 --- a/recovery_ui/include/recovery_ui/device.h +++ b/recovery_ui/include/recovery_ui/device.h @@ -63,6 +63,7 @@ class Device { REBOOT_RESCUE = 19, REBOOT_FROM_FASTBOOT = 20, SHUTDOWN_FROM_FASTBOOT = 21, + DISCARD_PENDING_UPDATE = 100, }; explicit Device(RecoveryUI* ui);