aboutsummaryrefslogtreecommitdiffstats
path: root/install.cpp
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2011-10-28 15:13:10 -0700
committerDoug Zongker <dougz@android.com>2011-10-28 15:13:10 -0700
commit7440630caa77869e7d264dfb9da47db2182524a2 (patch)
tree395aa8bc2d1d0412a52d42a3bb2d75a54f96685c /install.cpp
parent10e418d3c89ec404fbf959c1ef77a720a42a66ed (diff)
downloadbootable_recovery-7440630caa77869e7d264dfb9da47db2182524a2.zip
bootable_recovery-7440630caa77869e7d264dfb9da47db2182524a2.tar.gz
bootable_recovery-7440630caa77869e7d264dfb9da47db2182524a2.tar.bz2
refactor ui functions into a class
Move all the functions in ui.c to be members of a ScreenRecoveryUI class, which is a subclass of an abstract RecoveryUI class. Recovery then creates a global singleton instance of this class and then invoke the methods to drive the UI. We use this to allow substitution of a different RecoveryUI implementation for devices with radically different form factors (eg, that don't have a screen). Change-Id: I7fd8b2949d0db5a3f47c52978bca183966c86f33
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/install.cpp b/install.cpp
index 482e0d7..0783433 100644
--- a/install.cpp
+++ b/install.cpp
@@ -34,9 +34,17 @@
#include "verifier.h"
#include "ui.h"
+extern RecoveryUI* ui;
+
#define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary"
#define PUBLIC_KEYS_FILE "/res/keys"
+// Default allocation of progress bar segments to operations
+static const int VERIFICATION_PROGRESS_TIME = 60;
+static const float VERIFICATION_PROGRESS_FRACTION = 0.25;
+static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4;
+static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1;
+
// If the package contains an update binary, extract it and run it.
static int
try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) {
@@ -134,18 +142,17 @@ try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) {
float fraction = strtof(fraction_s, NULL);
int seconds = strtol(seconds_s, NULL, 10);
- ui_show_progress(fraction * (1-VERIFICATION_PROGRESS_FRACTION),
- seconds);
+ ui->ShowProgress(fraction * (1-VERIFICATION_PROGRESS_FRACTION), seconds);
} else if (strcmp(command, "set_progress") == 0) {
char* fraction_s = strtok(NULL, " \n");
float fraction = strtof(fraction_s, NULL);
- ui_set_progress(fraction);
+ ui->SetProgress(fraction);
} else if (strcmp(command, "ui_print") == 0) {
char* str = strtok(NULL, "\n");
if (str) {
- ui_print("%s", str);
+ ui->Print("%s", str);
} else {
- ui_print("\n");
+ ui->Print("\n");
}
} else if (strcmp(command, "wipe_cache") == 0) {
*wipe_cache = 1;
@@ -244,9 +251,9 @@ exit:
static int
really_install_package(const char *path, int* wipe_cache)
{
- ui_set_background(BACKGROUND_ICON_INSTALLING);
- ui_print("Finding update package...\n");
- ui_show_indeterminate_progress();
+ ui->SetBackground(RecoveryUI::INSTALLING);
+ ui->Print("Finding update package...\n");
+ ui->SetProgressType(RecoveryUI::INDETERMINATE);
LOGI("Update location: %s\n", path);
if (ensure_path_mounted(path) != 0) {
@@ -254,7 +261,7 @@ really_install_package(const char *path, int* wipe_cache)
return INSTALL_CORRUPT;
}
- ui_print("Opening update package...\n");
+ ui->Print("Opening update package...\n");
int numKeys;
RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
@@ -265,10 +272,9 @@ really_install_package(const char *path, int* wipe_cache)
LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);
// Give verification half the progress bar...
- ui_print("Verifying update package...\n");
- ui_show_progress(
- VERIFICATION_PROGRESS_FRACTION,
- VERIFICATION_PROGRESS_TIME);
+ ui->Print("Verifying update package...\n");
+ ui->SetProgressType(RecoveryUI::DETERMINATE);
+ ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME);
int err;
err = verify_file(path, loadedKeys, numKeys);
@@ -290,7 +296,7 @@ really_install_package(const char *path, int* wipe_cache)
/* Verify and install the contents of the package.
*/
- ui_print("Installing update...\n");
+ ui->Print("Installing update...\n");
return try_update_binary(path, &zip, wipe_cache);
}