diff --git a/Android.mk b/Android.mk index 3dac199..1dc34a5 100644 --- a/Android.mk +++ b/Android.mk @@ -66,7 +66,7 @@ LOCAL_C_INCLUDES += system/extras/ext4_utils include $(BUILD_EXECUTABLE) -RECOVERY_LINKS := edify busybox flash_image dump_image mkyaffs2image unyaffs erase_image nandroid reboot +RECOVERY_LINKS := edify busybox flash_image dump_image mkyaffs2image unyaffs erase_image nandroid reboot volume # nc is provided by external/netcat RECOVERY_SYMLINKS := $(addprefix $(TARGET_RECOVERY_ROOT_OUT)/sbin/,$(RECOVERY_LINKS)) diff --git a/extendedcommands.c b/extendedcommands.c index 6b26d27..36e696a 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -1099,4 +1099,29 @@ int is_path_mounted(const char* path) { int has_datadata() { Volume *vol = volume_for_path("/datadata"); return vol != NULL; -} \ No newline at end of file +} + +int volume_main(int argc, char **argv) { + load_volume_table(); + return 0; +} + +void handle_chargemode() { + 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. + file_data[file_len] = '\0'; + fclose(file); + + if (strstr(file_data, "androidboot.mode=offmode_charging") != NULL) + reboot(RB_POWER_OFF); + } \ No newline at end of file diff --git a/recovery.c b/recovery.c index 4fa4587..bb4c1be 100644 --- a/recovery.c +++ b/recovery.c @@ -766,6 +766,8 @@ main(int argc, char **argv) { { if (strstr(argv[0], "flash_image") != NULL) return flash_image_main(argc, argv); + if (strstr(argv[0], "volume") != NULL) + return volume_main(argc, argv); if (strstr(argv[0], "edify") != NULL) return edify_main(argc, argv); if (strstr(argv[0], "dump_image") != NULL) @@ -784,6 +786,7 @@ main(int argc, char **argv) { return setprop_main(argc, argv); return busybox_driver(argc, argv); } + handle_chargemode(); __system("/sbin/postrecoveryboot.sh"); int is_user_initiated_recovery = 0;