Skip to content

Commit f59b994

Browse files
committed
Add basic navigation controls to log viewer.
Bug: 18642766 Change-Id: I95a6c8edf83513d421a041e79c15111b5c991dde Signed-off-by: Patrick Tjin <[email protected]>
1 parent cd055ee commit f59b994

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

recovery.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static const char *LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
8282

8383
#define KEEP_LOG_COUNT 10
8484

85+
// Number of lines per page when displaying a file on screen
86+
#define LINES_PER_PAGE 30
87+
8588
RecoveryUI* ui = NULL;
8689
char* locale = NULL;
8790
char recovery_version[PROPERTY_VALUE_MAX+1];
@@ -725,15 +728,46 @@ static void file_to_ui(const char* fn) {
725728
}
726729
char line[1024];
727730
int ct = 0;
731+
int key = 0;
728732
redirect_stdio("/dev/null");
729733
while(fgets(line, sizeof(line), fp) != NULL) {
730734
ui->Print("%s", line);
731735
ct++;
732-
if (ct % 30 == 0) {
736+
if (ct % LINES_PER_PAGE == 0) {
733737
// give the user time to glance at the entries
734-
ui->WaitKey();
738+
key = ui->WaitKey();
739+
740+
if (key == KEY_POWER) {
741+
break;
742+
}
743+
744+
if (key == KEY_VOLUMEUP) {
745+
// Go back by seeking to the beginning and dumping ct - n
746+
// lines. It's ugly, but this way we don't need to store
747+
// the previous offsets. The files we're dumping here aren't
748+
// expected to be very large.
749+
int i;
750+
751+
ct -= 2 * LINES_PER_PAGE;
752+
if (ct < 0) {
753+
ct = 0;
754+
}
755+
fseek(fp, 0, SEEK_SET);
756+
for (i = 0; i < ct; i++) {
757+
fgets(line, sizeof(line), fp);
758+
}
759+
ui->Print("^^^^^^^^^^\n");
760+
}
735761
}
736762
}
763+
764+
// If the user didn't abort, then give the user time to glance at
765+
// the end of the log, sorry, no rewind here
766+
if (key != KEY_POWER) {
767+
ui->Print("\n--END-- (press any key)\n");
768+
ui->WaitKey();
769+
}
770+
737771
redirect_stdio(TEMPORARY_LOG_FILE);
738772
fclose(fp);
739773
}

0 commit comments

Comments
 (0)