diff options
author | Doug Zongker | 2011-10-28 17:13:10 -0500 |
---|---|---|
committer | Doug Zongker | 2011-10-28 17:13:10 -0500 |
commit | 7440630caa77869e7d264dfb9da47db2182524a2 (patch) | |
tree | 395aa8bc2d1d0412a52d42a3bb2d75a54f96685c /install.cpp | |
parent | 10e418d3c89ec404fbf959c1ef77a720a42a66ed (diff) | |
download | platform-bootable-recovery-7440630caa77869e7d264dfb9da47db2182524a2.tar.gz platform-bootable-recovery-7440630caa77869e7d264dfb9da47db2182524a2.tar.xz platform-bootable-recovery-7440630caa77869e7d264dfb9da47db2182524a2.zip |
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.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/install.cpp b/install.cpp index 482e0d75..07834333 100644 --- a/install.cpp +++ b/install.cpp | |||
@@ -34,9 +34,17 @@ | |||
34 | #include "verifier.h" | 34 | #include "verifier.h" |
35 | #include "ui.h" | 35 | #include "ui.h" |
36 | 36 | ||
37 | extern RecoveryUI* ui; | ||
38 | |||
37 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" | 39 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" |
38 | #define PUBLIC_KEYS_FILE "/res/keys" | 40 | #define PUBLIC_KEYS_FILE "/res/keys" |
39 | 41 | ||
42 | // Default allocation of progress bar segments to operations | ||
43 | static const int VERIFICATION_PROGRESS_TIME = 60; | ||
44 | static const float VERIFICATION_PROGRESS_FRACTION = 0.25; | ||
45 | static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; | ||
46 | static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; | ||
47 | |||
40 | // If the package contains an update binary, extract it and run it. | 48 | // If the package contains an update binary, extract it and run it. |
41 | static int | 49 | static int |
42 | try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) { | 50 | 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) { | |||
134 | float fraction = strtof(fraction_s, NULL); | 142 | float fraction = strtof(fraction_s, NULL); |
135 | int seconds = strtol(seconds_s, NULL, 10); | 143 | int seconds = strtol(seconds_s, NULL, 10); |
136 | 144 | ||
137 | ui_show_progress(fraction * (1-VERIFICATION_PROGRESS_FRACTION), | 145 | ui->ShowProgress(fraction * (1-VERIFICATION_PROGRESS_FRACTION), seconds); |
138 | seconds); | ||
139 | } else if (strcmp(command, "set_progress") == 0) { | 146 | } else if (strcmp(command, "set_progress") == 0) { |
140 | char* fraction_s = strtok(NULL, " \n"); | 147 | char* fraction_s = strtok(NULL, " \n"); |
141 | float fraction = strtof(fraction_s, NULL); | 148 | float fraction = strtof(fraction_s, NULL); |
142 | ui_set_progress(fraction); | 149 | ui->SetProgress(fraction); |
143 | } else if (strcmp(command, "ui_print") == 0) { | 150 | } else if (strcmp(command, "ui_print") == 0) { |
144 | char* str = strtok(NULL, "\n"); | 151 | char* str = strtok(NULL, "\n"); |
145 | if (str) { | 152 | if (str) { |
146 | ui_print("%s", str); | 153 | ui->Print("%s", str); |
147 | } else { | 154 | } else { |
148 | ui_print("\n"); | 155 | ui->Print("\n"); |
149 | } | 156 | } |
150 | } else if (strcmp(command, "wipe_cache") == 0) { | 157 | } else if (strcmp(command, "wipe_cache") == 0) { |
151 | *wipe_cache = 1; | 158 | *wipe_cache = 1; |
@@ -244,9 +251,9 @@ exit: | |||
244 | static int | 251 | static int |
245 | really_install_package(const char *path, int* wipe_cache) | 252 | really_install_package(const char *path, int* wipe_cache) |
246 | { | 253 | { |
247 | ui_set_background(BACKGROUND_ICON_INSTALLING); | 254 | ui->SetBackground(RecoveryUI::INSTALLING); |
248 | ui_print("Finding update package...\n"); | 255 | ui->Print("Finding update package...\n"); |
249 | ui_show_indeterminate_progress(); | 256 | ui->SetProgressType(RecoveryUI::INDETERMINATE); |
250 | LOGI("Update location: %s\n", path); | 257 | LOGI("Update location: %s\n", path); |
251 | 258 | ||
252 | if (ensure_path_mounted(path) != 0) { | 259 | if (ensure_path_mounted(path) != 0) { |
@@ -254,7 +261,7 @@ really_install_package(const char *path, int* wipe_cache) | |||
254 | return INSTALL_CORRUPT; | 261 | return INSTALL_CORRUPT; |
255 | } | 262 | } |
256 | 263 | ||
257 | ui_print("Opening update package...\n"); | 264 | ui->Print("Opening update package...\n"); |
258 | 265 | ||
259 | int numKeys; | 266 | int numKeys; |
260 | RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); | 267 | RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); |
@@ -265,10 +272,9 @@ really_install_package(const char *path, int* wipe_cache) | |||
265 | LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); | 272 | LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); |
266 | 273 | ||
267 | // Give verification half the progress bar... | 274 | // Give verification half the progress bar... |
268 | ui_print("Verifying update package...\n"); | 275 | ui->Print("Verifying update package...\n"); |
269 | ui_show_progress( | 276 | ui->SetProgressType(RecoveryUI::DETERMINATE); |
270 | VERIFICATION_PROGRESS_FRACTION, | 277 | ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); |
271 | VERIFICATION_PROGRESS_TIME); | ||
272 | 278 | ||
273 | int err; | 279 | int err; |
274 | err = verify_file(path, loadedKeys, numKeys); | 280 | err = verify_file(path, loadedKeys, numKeys); |
@@ -290,7 +296,7 @@ really_install_package(const char *path, int* wipe_cache) | |||
290 | 296 | ||
291 | /* Verify and install the contents of the package. | 297 | /* Verify and install the contents of the package. |
292 | */ | 298 | */ |
293 | ui_print("Installing update...\n"); | 299 | ui->Print("Installing update...\n"); |
294 | return try_update_binary(path, &zip, wipe_cache); | 300 | return try_update_binary(path, &zip, wipe_cache); |
295 | } | 301 | } |
296 | 302 | ||