diff options
author | Doug Zongker <dougz@android.com> | 2011-10-28 19:33:05 +0200 |
---|---|---|
committer | Doug Zongker <dougz@android.com> | 2011-10-28 19:33:05 +0200 |
commit | 10e418d3c89ec404fbf959c1ef77a720a42a66ed (patch) | |
tree | 0c429bcc8f4a1935f3be97d87ebdc2f4434ee887 /recovery.cpp | |
parent | allow recovery packages to wipe cache (diff) | |
download | android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar.gz android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar.bz2 android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar.lz android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar.xz android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.tar.zst android_bootable_recovery-10e418d3c89ec404fbf959c1ef77a720a42a66ed.zip |
Diffstat (limited to '')
-rw-r--r-- | recovery.cpp (renamed from recovery.c) | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/recovery.c b/recovery.cpp index 06d649809..7c1d7fb0f 100644 --- a/recovery.c +++ b/recovery.cpp @@ -38,6 +38,7 @@ #include "minzip/DirUtil.h" #include "roots.h" #include "recovery_ui.h" +#include "ui.h" static const struct option OPTIONS[] = { { "send_intent", required_argument, NULL, 's' }, @@ -349,7 +350,7 @@ copy_sideloaded_package(const char* original_path) { strcpy(copy_path, SIDELOAD_TEMP_DIR); strcat(copy_path, "/package.zip"); - char* buffer = malloc(BUFSIZ); + char* buffer = (char*)malloc(BUFSIZ); if (buffer == NULL) { LOGE("Failed to allocate buffer\n"); return NULL; @@ -396,22 +397,22 @@ copy_sideloaded_package(const char* original_path) { return strdup(copy_path); } -static char** +static const char** prepend_title(const char** headers) { - char* title[] = { "Android system recovery <" - EXPAND(RECOVERY_API_VERSION) "e>", - "", - NULL }; + const char* title[] = { "Android system recovery <" + EXPAND(RECOVERY_API_VERSION) "e>", + "", + NULL }; // count the number of lines in our title, plus the // caller-provided headers. int count = 0; - char** p; + const char** p; for (p = title; *p; ++p, ++count); for (p = headers; *p; ++p, ++count); - char** new_headers = malloc((count+1) * sizeof(char*)); - char** h = new_headers; + const char** new_headers = (const char**)malloc((count+1) * sizeof(char*)); + const char** h = new_headers; for (p = title; *p; ++p, ++h) *h = *p; for (p = headers; *p; ++p, ++h) *h = *p; *h = NULL; @@ -420,8 +421,8 @@ prepend_title(const char** headers) { } static int -get_menu_selection(char** headers, char** items, int menu_only, - int initial_selection) { +get_menu_selection(const char* const * headers, const char* const * items, + int menu_only, int initial_selection) { // throw away keys pressed previously, so user doesn't // accidentally trigger menu items. ui_clear_key_queue(); @@ -495,14 +496,14 @@ update_directory(const char* path, const char* unmount_when_done, return 0; } - char** headers = prepend_title(MENU_HEADERS); + const char** headers = prepend_title(MENU_HEADERS); int d_size = 0; int d_alloc = 10; - char** dirs = malloc(d_alloc * sizeof(char*)); + char** dirs = (char**)malloc(d_alloc * sizeof(char*)); int z_size = 1; int z_alloc = 10; - char** zips = malloc(z_alloc * sizeof(char*)); + char** zips = (char**)malloc(z_alloc * sizeof(char*)); zips[0] = strdup("../"); while ((de = readdir(d)) != NULL) { @@ -516,9 +517,9 @@ update_directory(const char* path, const char* unmount_when_done, if (d_size >= d_alloc) { d_alloc *= 2; - dirs = realloc(dirs, d_alloc * sizeof(char*)); + dirs = (char**)realloc(dirs, d_alloc * sizeof(char*)); } - dirs[d_size] = malloc(name_len + 2); + dirs[d_size] = (char*)malloc(name_len + 2); strcpy(dirs[d_size], de->d_name); dirs[d_size][name_len] = '/'; dirs[d_size][name_len+1] = '\0'; @@ -528,7 +529,7 @@ update_directory(const char* path, const char* unmount_when_done, strncasecmp(de->d_name + (name_len-4), ".zip", 4) == 0) { if (z_size >= z_alloc) { z_alloc *= 2; - zips = realloc(zips, z_alloc * sizeof(char*)); + zips = (char**)realloc(zips, z_alloc * sizeof(char*)); } zips[z_size++] = strdup(de->d_name); } @@ -541,7 +542,7 @@ update_directory(const char* path, const char* unmount_when_done, // append dirs to the zips list if (d_size + z_size + 1 > z_alloc) { z_alloc = d_size + z_size + 1; - zips = realloc(zips, z_alloc * sizeof(char*)); + zips = (char**)realloc(zips, z_alloc * sizeof(char*)); } memcpy(zips + z_size, dirs, d_size * sizeof(char*)); free(dirs); @@ -606,28 +607,28 @@ update_directory(const char* path, const char* unmount_when_done, static void wipe_data(int confirm) { if (confirm) { - static char** title_headers = NULL; + static const char** title_headers = NULL; if (title_headers == NULL) { - char* headers[] = { "Confirm wipe of all user data?", - " THIS CAN NOT BE UNDONE.", - "", - NULL }; + const char* headers[] = { "Confirm wipe of all user data?", + " THIS CAN NOT BE UNDONE.", + "", + NULL }; title_headers = prepend_title((const char**)headers); } - char* items[] = { " No", - " No", - " No", - " No", - " No", - " No", - " No", - " Yes -- delete all user data", // [7] - " No", - " No", - " No", - NULL }; + const char* items[] = { " No", + " No", + " No", + " No", + " No", + " No", + " No", + " Yes -- delete all user data", // [7] + " No", + " No", + " No", + NULL }; int chosen_item = get_menu_selection(title_headers, items, 1, 0); if (chosen_item != 7) { @@ -644,7 +645,7 @@ wipe_data(int confirm) { static void prompt_and_wait() { - char** headers = prepend_title((const char**)MENU_HEADERS); + const char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); @@ -777,7 +778,7 @@ main(int argc, char **argv) { // "/cache/foo". if (strncmp(update_package, "CACHE:", 6) == 0) { int len = strlen(update_package) + 10; - char* modified_path = malloc(len); + char* modified_path = (char*)malloc(len); strlcpy(modified_path, "/cache/", len); strlcat(modified_path, update_package+6, len); printf("(replacing path \"%s\" with \"%s\")\n", |