summaryrefslogtreecommitdiffstats
path: root/recovery.cpp
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2011-10-28 19:33:05 +0200
committerDoug Zongker <dougz@android.com>2011-10-31 18:24:09 +0100
commit28ce47cfa6919518a8c298088bf08b03bb374c0f (patch)
tree0c429bcc8f4a1935f3be97d87ebdc2f4434ee887 /recovery.cpp
parentallow recovery packages to wipe cache (diff)
downloadandroid_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar.gz
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar.bz2
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar.lz
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar.xz
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.tar.zst
android_bootable_recovery-28ce47cfa6919518a8c298088bf08b03bb374c0f.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",