42 lines
1.3 KiB
Diff
42 lines
1.3 KiB
Diff
diff --git a/extendedcommands.c b/extendedcommands.c
|
|
index 1ce3bf1..2562e6c 100644
|
|
--- a/extendedcommands.c
|
|
+++ b/extendedcommands.c
|
|
@@ -1110,21 +1110,25 @@ int volume_main(int argc, char **argv) {
|
|
}
|
|
|
|
void handle_chargemode() {
|
|
+ // old code to read /proc/cmdline was broken because file size is always 0 so file_data was always empty string
|
|
const char* filename = "/proc/cmdline";
|
|
- struct stat file_info;
|
|
- if (0 != stat(filename, &file_info))
|
|
- return;
|
|
-
|
|
- int file_len = file_info.st_size;
|
|
- char* file_data = (char*)malloc(file_len + 1);
|
|
FILE *file = fopen(filename, "rb");
|
|
if (file == NULL)
|
|
return;
|
|
- fread(file_data, file_len, 1, file);
|
|
- // supposedly not necessary, but let's be safe.
|
|
+ char file_data[1024];
|
|
+ int file_len=fread(file_data, 1, 1023, file);
|
|
file_data[file_len] = '\0';
|
|
fclose(file);
|
|
-
|
|
+
|
|
if (strstr(file_data, "androidboot.mode=offmode_charging") != NULL)
|
|
- reboot(RB_POWER_OFF);
|
|
+ {
|
|
+ // let recovery kernel charge the battery, reboot on any key press so Android will start as user would expect
|
|
+ ev_init();
|
|
+ struct input_event ev;
|
|
+ do
|
|
+ {
|
|
+ ev_get(&ev, 0);
|
|
+ } while (ev.type != EV_KEY || ev.code > KEY_MAX);
|
|
+ reboot(RB_AUTOBOOT);
|
|
+ }
|
|
}
|
|
\ No newline at end of file
|