recovery: Add ability to interrupt UI
Normally calling a UI method will block indefinitely until the UI is actually used. This creates a method to interrupt the UI, causing waitKey to return -2. This in turn, will cause ShowMenu to return -2. This allows switching between recovery and fastbootd via usb commands. Test: adb shell /data/nativetest64/recovery_unit_test/recovery_unit_test Bug: 78793464 Change-Id: I4c6c9aa18d79070877841a5c9818acf723fa6096
This commit is contained in:
committed by
Hridya Valsaraju
parent
6f1f2c811a
commit
b76af93ab5
+11
-2
@@ -417,6 +417,7 @@ void ScreenRecoveryUI::CheckBackgroundTextImages() {
|
||||
FlushKeys();
|
||||
while (true) {
|
||||
int key = WaitKey();
|
||||
if (key == static_cast<int>(KeyError::INTERRUPTED)) break;
|
||||
if (key == KEY_POWER || key == KEY_ENTER) {
|
||||
break;
|
||||
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
||||
@@ -925,6 +926,7 @@ void ScreenRecoveryUI::ShowFile(FILE* fp) {
|
||||
while (show_prompt) {
|
||||
show_prompt = false;
|
||||
int key = WaitKey();
|
||||
if (key == static_cast<int>(KeyError::INTERRUPTED)) return;
|
||||
if (key == KEY_POWER || key == KEY_ENTER) {
|
||||
return;
|
||||
} else if (key == KEY_UP || key == KEY_VOLUMEUP) {
|
||||
@@ -1017,19 +1019,26 @@ size_t ScreenRecoveryUI::ShowMenu(const std::vector<std::string>& headers,
|
||||
// Throw away keys pressed previously, so user doesn't accidentally trigger menu items.
|
||||
FlushKeys();
|
||||
|
||||
// If there is a key interrupt in progress, return KeyError::INTERRUPTED without starting the
|
||||
// menu.
|
||||
if (IsKeyInterrupted()) return static_cast<size_t>(KeyError::INTERRUPTED);
|
||||
|
||||
StartMenu(headers, items, initial_selection);
|
||||
|
||||
int selected = initial_selection;
|
||||
int chosen_item = -1;
|
||||
while (chosen_item < 0) {
|
||||
int key = WaitKey();
|
||||
if (key == -1) { // WaitKey() timed out.
|
||||
if (key == static_cast<int>(KeyError::INTERRUPTED)) { // WaitKey() was interrupted.
|
||||
return static_cast<size_t>(KeyError::INTERRUPTED);
|
||||
}
|
||||
if (key == static_cast<int>(KeyError::TIMED_OUT)) { // WaitKey() timed out.
|
||||
if (WasTextEverVisible()) {
|
||||
continue;
|
||||
} else {
|
||||
LOG(INFO) << "Timed out waiting for key input; rebooting.";
|
||||
EndMenu();
|
||||
return static_cast<size_t>(-1);
|
||||
return static_cast<size_t>(KeyError::TIMED_OUT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user