Merge "Factor out the "yes/no" menu and use it for "Wipe cache" too."
This commit is contained in:
+34
-59
@@ -502,8 +502,7 @@ erase_volume(const char *volume) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char**
|
static const char** prepend_title(const char* const* headers) {
|
||||||
prepend_title(const char* const* headers) {
|
|
||||||
// count the number of lines in our title, plus the
|
// count the number of lines in our title, plus the
|
||||||
// caller-provided headers.
|
// caller-provided headers.
|
||||||
int count = 3; // our title has 3 lines
|
int count = 3; // our title has 3 lines
|
||||||
@@ -578,24 +577,15 @@ static int compare_string(const void* a, const void* b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a malloc'd path, or NULL.
|
// Returns a malloc'd path, or NULL.
|
||||||
static char*
|
static char* browse_directory(const char* path, Device* device) {
|
||||||
browse_directory(const char* path, Device* device) {
|
|
||||||
ensure_path_mounted(path);
|
ensure_path_mounted(path);
|
||||||
|
|
||||||
const char* MENU_HEADERS[] = { "Choose a package to install:",
|
DIR* d = opendir(path);
|
||||||
path,
|
|
||||||
"",
|
|
||||||
NULL };
|
|
||||||
DIR* d;
|
|
||||||
struct dirent* de;
|
|
||||||
d = opendir(path);
|
|
||||||
if (d == NULL) {
|
if (d == NULL) {
|
||||||
LOGE("error opening %s: %s\n", path, strerror(errno));
|
LOGE("error opening %s: %s\n", path, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char** headers = prepend_title(MENU_HEADERS);
|
|
||||||
|
|
||||||
int d_size = 0;
|
int d_size = 0;
|
||||||
int d_alloc = 10;
|
int d_alloc = 10;
|
||||||
char** dirs = (char**)malloc(d_alloc * sizeof(char*));
|
char** dirs = (char**)malloc(d_alloc * sizeof(char*));
|
||||||
@@ -604,6 +594,7 @@ browse_directory(const char* path, Device* device) {
|
|||||||
char** zips = (char**)malloc(z_alloc * sizeof(char*));
|
char** zips = (char**)malloc(z_alloc * sizeof(char*));
|
||||||
zips[0] = strdup("../");
|
zips[0] = strdup("../");
|
||||||
|
|
||||||
|
struct dirent* de;
|
||||||
while ((de = readdir(d)) != NULL) {
|
while ((de = readdir(d)) != NULL) {
|
||||||
int name_len = strlen(de->d_name);
|
int name_len = strlen(de->d_name);
|
||||||
|
|
||||||
@@ -647,6 +638,8 @@ browse_directory(const char* path, Device* device) {
|
|||||||
z_size += d_size;
|
z_size += d_size;
|
||||||
zips[z_size] = NULL;
|
zips[z_size] = NULL;
|
||||||
|
|
||||||
|
const char* headers[] = { "Choose a package to install:", path, "", NULL };
|
||||||
|
|
||||||
char* result;
|
char* result;
|
||||||
int chosen_item = 0;
|
int chosen_item = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -677,44 +670,23 @@ browse_directory(const char* path, Device* device) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (int i = 0; i < z_size; ++i) free(zips[i]);
|
||||||
for (i = 0; i < z_size; ++i) free(zips[i]);
|
|
||||||
free(zips);
|
free(zips);
|
||||||
free(headers);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool yes_no(Device* device, const char* question1, const char* question2) {
|
||||||
wipe_data(int confirm, Device* device) {
|
const char* headers[] = { question1, question2, "", NULL };
|
||||||
if (confirm) {
|
const char* items[] = { " No", " Yes", NULL };
|
||||||
static const char** title_headers = NULL;
|
|
||||||
|
|
||||||
if (title_headers == NULL) {
|
int chosen_item = get_menu_selection(headers, items, 1, 0, device);
|
||||||
const char* headers[] = { "Confirm wipe of all user data?",
|
return (chosen_item == 1);
|
||||||
" THIS CAN NOT BE UNDONE.",
|
}
|
||||||
"",
|
|
||||||
NULL };
|
|
||||||
title_headers = prepend_title((const char**)headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* items[] = { " No",
|
static void wipe_data(int confirm, Device* device) {
|
||||||
" No",
|
if (confirm && !yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!")) {
|
||||||
" No",
|
return;
|
||||||
" 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, device);
|
|
||||||
if (chosen_item != 7) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->Print("\n-- Wiping data...\n");
|
ui->Print("\n-- Wiping data...\n");
|
||||||
@@ -725,6 +697,16 @@ wipe_data(int confirm, Device* device) {
|
|||||||
ui->Print("Data wipe complete.\n");
|
ui->Print("Data wipe complete.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wipe_cache(bool should_confirm, Device* device) {
|
||||||
|
if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->Print("\n-- Wiping cache...\n");
|
||||||
|
erase_volume("/cache");
|
||||||
|
ui->Print("Cache wipe complete.\n");
|
||||||
|
}
|
||||||
|
|
||||||
static void file_to_ui(const char* fn) {
|
static void file_to_ui(const char* fn) {
|
||||||
FILE *fp = fopen_path(fn, "re");
|
FILE *fp = fopen_path(fn, "re");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
@@ -782,9 +764,6 @@ static void choose_recovery_file(Device* device) {
|
|||||||
unsigned int n;
|
unsigned int n;
|
||||||
static const char** title_headers = NULL;
|
static const char** title_headers = NULL;
|
||||||
char *filename;
|
char *filename;
|
||||||
const char* headers[] = { "Select file to view",
|
|
||||||
"",
|
|
||||||
NULL };
|
|
||||||
// "Go back" + LAST_KMSG_FILE + KEEP_LOG_COUNT + terminating NULL entry
|
// "Go back" + LAST_KMSG_FILE + KEEP_LOG_COUNT + terminating NULL entry
|
||||||
char* entries[KEEP_LOG_COUNT + 3];
|
char* entries[KEEP_LOG_COUNT + 3];
|
||||||
memset(entries, 0, sizeof(entries));
|
memset(entries, 0, sizeof(entries));
|
||||||
@@ -812,10 +791,10 @@ static void choose_recovery_file(Device* device) {
|
|||||||
entries[n++] = filename;
|
entries[n++] = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
title_headers = prepend_title((const char**)headers);
|
const char* headers[] = { "Select file to view", "", NULL };
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int chosen_item = get_menu_selection(title_headers, entries, 1, 0, device);
|
int chosen_item = get_menu_selection(headers, entries, 1, 0, device);
|
||||||
if (chosen_item == 0) break;
|
if (chosen_item == 0) break;
|
||||||
file_to_ui(entries[chosen_item]);
|
file_to_ui(entries[chosen_item]);
|
||||||
}
|
}
|
||||||
@@ -878,7 +857,7 @@ prompt_and_wait(Device* device, int status) {
|
|||||||
// statement below.
|
// statement below.
|
||||||
Device::BuiltinAction chosen_action = device->InvokeMenuItem(chosen_item);
|
Device::BuiltinAction chosen_action = device->InvokeMenuItem(chosen_item);
|
||||||
|
|
||||||
bool wipe_cache = false;
|
bool should_wipe_cache = false;
|
||||||
switch (chosen_action) {
|
switch (chosen_action) {
|
||||||
case Device::NO_ACTION:
|
case Device::NO_ACTION:
|
||||||
break;
|
break;
|
||||||
@@ -894,9 +873,7 @@ prompt_and_wait(Device* device, int status) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Device::WIPE_CACHE:
|
case Device::WIPE_CACHE:
|
||||||
ui->Print("\n-- Wiping cache...\n");
|
wipe_cache(ui->IsTextVisible(), device);
|
||||||
erase_volume("/cache");
|
|
||||||
ui->Print("Cache wipe complete.\n");
|
|
||||||
if (!ui->IsTextVisible()) return Device::NO_ACTION;
|
if (!ui->IsTextVisible()) return Device::NO_ACTION;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -905,15 +882,13 @@ prompt_and_wait(Device* device, int status) {
|
|||||||
{
|
{
|
||||||
bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
|
bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
|
||||||
if (adb) {
|
if (adb) {
|
||||||
status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE);
|
status = apply_from_adb(ui, &should_wipe_cache, TEMPORARY_INSTALL_FILE);
|
||||||
} else {
|
} else {
|
||||||
status = apply_from_sdcard(device, &wipe_cache);
|
status = apply_from_sdcard(device, &should_wipe_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == INSTALL_SUCCESS && wipe_cache) {
|
if (status == INSTALL_SUCCESS && should_wipe_cache) {
|
||||||
ui->Print("\n-- Wiping cache (at package request)...\n");
|
wipe_cache(false, device);
|
||||||
bool okay = erase_volume("/cache");
|
|
||||||
ui->Print("Cache wipe %s.\n", okay ? "succeeded" : "failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user