aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-02-23 21:06:53 -0600
committerTao Bao2017-03-07 17:35:12 -0600
commitfc5499f22bd9b30affca08e584411012f71b6e9c (patch)
tree80131d47bb390fe5d54587e7e2257ada9725d6e8 /recovery.cpp
parentb7f56f9b914c9c1fa9065e9ddfc72f2c930123e1 (diff)
downloadplatform-bootable-recovery-fc5499f22bd9b30affca08e584411012f71b6e9c.tar.gz
platform-bootable-recovery-fc5499f22bd9b30affca08e584411012f71b6e9c.tar.xz
platform-bootable-recovery-fc5499f22bd9b30affca08e584411012f71b6e9c.zip
recovery: Move a few int to bool.
Most of the changes are trivial. Also update a dead reference to device_handle_key() in device.h comment, and add some comments to get_menu_selection() function. Test: `mmma bootable/recovery` Change-Id: I59ef9213ec88ab35c0e7b8a7813ccf9c56dbd5c5
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp135
1 files changed, 68 insertions, 67 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 618a2e8c..b5cd3484 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -607,54 +607,55 @@ static bool erase_volume(const char* volume) {
607 return (result == 0); 607 return (result == 0);
608} 608}
609 609
610static int 610// Display a menu with the specified 'headers' and 'items'. Device specific HandleMenuKey() may
611get_menu_selection(const char* const * headers, const char* const * items, 611// return a positive number beyond the given range. Caller sets 'menu_only' to true to ensure only
612 int menu_only, int initial_selection, Device* device) { 612// a menu item gets selected. 'initial_selection' controls the initial cursor location.
613 // throw away keys pressed previously, so user doesn't 613static int get_menu_selection(const char* const* headers, const char* const* items, bool menu_only,
614 // accidentally trigger menu items. 614 int initial_selection, Device* device) {
615 ui->FlushKeys(); 615 // Throw away keys pressed previously, so user doesn't accidentally trigger menu items.
616 616 ui->FlushKeys();
617 ui->StartMenu(headers, items, initial_selection); 617
618 int selected = initial_selection; 618 ui->StartMenu(headers, items, initial_selection);
619 int chosen_item = -1; 619 int selected = initial_selection;
620 620 int chosen_item = -1;
621 while (chosen_item < 0) { 621
622 int key = ui->WaitKey(); 622 while (chosen_item < 0) {
623 int visible = ui->IsTextVisible(); 623 int key = ui->WaitKey();
624 624
625 if (key == -1) { // ui_wait_key() timed out 625 if (key == -1) { // ui_wait_key() timed out
626 if (ui->WasTextEverVisible()) { 626 if (ui->WasTextEverVisible()) {
627 continue; 627 continue;
628 } else { 628 } else {
629 LOG(INFO) << "timed out waiting for key input; rebooting."; 629 LOG(INFO) << "timed out waiting for key input; rebooting.";
630 ui->EndMenu(); 630 ui->EndMenu();
631 return 0; // XXX fixme 631 return 0; // XXX fixme
632 } 632 }
633 } 633 }
634 634
635 int action = device->HandleMenuKey(key, visible); 635 bool visible = ui->IsTextVisible();
636 636 int action = device->HandleMenuKey(key, visible);
637 if (action < 0) { 637
638 switch (action) { 638 if (action < 0) {
639 case Device::kHighlightUp: 639 switch (action) {
640 selected = ui->SelectMenu(--selected); 640 case Device::kHighlightUp:
641 break; 641 selected = ui->SelectMenu(--selected);
642 case Device::kHighlightDown: 642 break;
643 selected = ui->SelectMenu(++selected); 643 case Device::kHighlightDown:
644 break; 644 selected = ui->SelectMenu(++selected);
645 case Device::kInvokeItem: 645 break;
646 chosen_item = selected; 646 case Device::kInvokeItem:
647 break; 647 chosen_item = selected;
648 case Device::kNoAction: 648 break;
649 break; 649 case Device::kNoAction:
650 } 650 break;
651 } else if (!menu_only) { 651 }
652 chosen_item = action; 652 } else if (!menu_only) {
653 } 653 chosen_item = action;
654 } 654 }
655 }
655 656
656 ui->EndMenu(); 657 ui->EndMenu();
657 return chosen_item; 658 return chosen_item;
658} 659}
659 660
660// Returns the selected filename, or an empty string. 661// Returns the selected filename, or an empty string.
@@ -699,7 +700,7 @@ static std::string browse_directory(const std::string& path, Device* device) {
699 700
700 int chosen_item = 0; 701 int chosen_item = 0;
701 while (true) { 702 while (true) {
702 chosen_item = get_menu_selection(headers, entries, 1, chosen_item, device); 703 chosen_item = get_menu_selection(headers, entries, true, chosen_item, device);
703 704
704 const std::string& item = zips[chosen_item]; 705 const std::string& item = zips[chosen_item];
705 if (chosen_item == 0) { 706 if (chosen_item == 0) {
@@ -726,7 +727,7 @@ static bool yes_no(Device* device, const char* question1, const char* question2)
726 const char* headers[] = { question1, question2, NULL }; 727 const char* headers[] = { question1, question2, NULL };
727 const char* items[] = { " No", " Yes", NULL }; 728 const char* items[] = { " No", " Yes", NULL };
728 729
729 int chosen_item = get_menu_selection(headers, items, 1, 0, device); 730 int chosen_item = get_menu_selection(headers, items, true, 0, device);
730 return (chosen_item == 1); 731 return (chosen_item == 1);
731} 732}
732 733
@@ -749,25 +750,25 @@ static bool wipe_data(Device* device) {
749} 750}
750 751
751static bool prompt_and_wipe_data(Device* device) { 752static bool prompt_and_wipe_data(Device* device) {
752 const char* const headers[] = { 753 const char* const headers[] = {
753 "Boot halted, user data is corrupt", 754 "Boot halted, user data is corrupt",
754 "Wipe all user data to recover", 755 "Wipe all user data to recover",
755 NULL 756 NULL
756 }; 757 };
757 const char* const items[] = { 758 const char* const items[] = {
758 "Retry boot", 759 "Retry boot",
759 "Wipe user data", 760 "Wipe user data",
760 NULL 761 NULL
761 }; 762 };
762 for (;;) { 763 for (;;) {
763 int chosen_item = get_menu_selection(headers, items, 1, 0, device); 764 int chosen_item = get_menu_selection(headers, items, true, 0, device);
764 if (chosen_item != 1) { 765 if (chosen_item != 1) {
765 return true; // Just reboot, no wipe; not a failure, user asked for it 766 return true; // Just reboot, no wipe; not a failure, user asked for it
766 } 767 }
767 if (ask_to_wipe_data(device)) { 768 if (ask_to_wipe_data(device)) {
768 return wipe_data(device); 769 return wipe_data(device);
769 }
770 } 770 }
771 }
771} 772}
772 773
773// Return true on success. 774// Return true on success.
@@ -961,7 +962,7 @@ static void choose_recovery_file(Device* device) {
961 962
962 int chosen_item = 0; 963 int chosen_item = 0;
963 while (true) { 964 while (true) {
964 chosen_item = get_menu_selection(headers, menu_entries.data(), 1, chosen_item, device); 965 chosen_item = get_menu_selection(headers, menu_entries.data(), true, chosen_item, device);
965 if (entries[chosen_item] == "Back") break; 966 if (entries[chosen_item] == "Back") break;
966 967
967 ui->ShowFile(entries[chosen_item].c_str()); 968 ui->ShowFile(entries[chosen_item].c_str());
@@ -1110,7 +1111,7 @@ prompt_and_wait(Device* device, int status) {
1110 } 1111 }
1111 ui->SetProgressType(RecoveryUI::EMPTY); 1112 ui->SetProgressType(RecoveryUI::EMPTY);
1112 1113
1113 int chosen_item = get_menu_selection(nullptr, device->GetMenuItems(), 0, 0, device); 1114 int chosen_item = get_menu_selection(nullptr, device->GetMenuItems(), false, 0, device);
1114 1115
1115 // device-specific code may take some action here. It may 1116 // device-specific code may take some action here. It may
1116 // return one of the core actions handled in the switch 1117 // return one of the core actions handled in the switch