The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef RECOVERY_COMMON_H |
| 18 | #define RECOVERY_COMMON_H |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | |
| 22 | // Initialize the graphics system. |
| 23 | void ui_init(); |
| 24 | |
| 25 | // Use KEY_* codes from <linux/input.h> or KEY_DREAM_* from "minui/minui.h". |
| 26 | int ui_wait_key(); // waits for a key/button press, returns the code |
| 27 | int ui_key_pressed(int key); // returns >0 if the code is currently pressed |
| 28 | int ui_text_visible(); // returns >0 if text log is currently visible |
Doug Zongker | 5cae445 | 2011-01-25 13:15:30 -0800 | [diff] [blame] | 29 | int ui_text_ever_visible(); // returns >0 if text log was ever visible |
Doug Zongker | 4bc9806 | 2010-09-03 11:00:13 -0700 | [diff] [blame] | 30 | void ui_show_text(int visible); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 31 | void ui_clear_key_queue(); |
| 32 | |
| 33 | // Write a message to the on-screen log shown with Alt-L (also to stderr). |
| 34 | // The screen is small, and users may need to report these messages to support, |
| 35 | // so keep the output short and not too cryptic. |
Nick Kralevich | 21b97ed | 2010-06-24 16:11:17 -0700 | [diff] [blame] | 36 | void ui_print(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
Tanguy Pruvot | 67d358c | 2011-06-10 20:26:44 +0200 | [diff] [blame] | 37 | void ui_printlogtail(int nb_lines); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 38 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 39 | void ui_reset_text_col(); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 40 | void ui_set_show_text(int value); |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 42 | // Display some header text followed by a menu of items, which appears |
| 43 | // at the top of the screen (in place of any scrolling ui_print() |
| 44 | // output, if necessary). |
Koushik Dutta | df1e406 | 2010-12-18 17:42:31 -0800 | [diff] [blame] | 45 | int ui_start_menu(char** headers, char** items, int initial_selection); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 46 | // Set the menu highlight to the given index, and return it (capped to |
| 47 | // the range [0..numitems). |
| 48 | int ui_menu_select(int sel); |
| 49 | // End menu mode, resetting the text overlay so that ui_print() |
| 50 | // statements will be displayed. |
| 51 | void ui_end_menu(); |
| 52 | |
Koushik Dutta | 4ca9b4c | 2010-07-14 18:37:33 -0700 | [diff] [blame] | 53 | int ui_get_showing_back_button(); |
| 54 | void ui_set_showing_back_button(int showBackButton); |
| 55 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 56 | // Set the icon (normally the only thing visible besides the progress bar). |
| 57 | enum { |
| 58 | BACKGROUND_ICON_NONE, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 59 | BACKGROUND_ICON_INSTALLING, |
| 60 | BACKGROUND_ICON_ERROR, |
Koushik Dutta | 5d80817 | 2010-12-18 22:29:27 -0800 | [diff] [blame] | 61 | BACKGROUND_ICON_CLOCKWORK, |
Koushik Dutta | 107629b | 2010-06-30 23:17:53 -0700 | [diff] [blame] | 62 | BACKGROUND_ICON_FIRMWARE_INSTALLING, |
| 63 | BACKGROUND_ICON_FIRMWARE_ERROR, |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 64 | NUM_BACKGROUND_ICONS |
| 65 | }; |
| 66 | void ui_set_background(int icon); |
| 67 | |
Koushik Dutta | 107629b | 2010-06-30 23:17:53 -0700 | [diff] [blame] | 68 | // Get a malloc'd copy of the screen image showing (only) the specified icon. |
| 69 | // Also returns the width, height, and bits per pixel of the returned image. |
| 70 | // TODO: Use some sort of "struct Bitmap" here instead of all these variables? |
| 71 | char *ui_copy_image(int icon, int *width, int *height, int *bpp); |
| 72 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 73 | // Show a progress bar and define the scope of the next operation: |
| 74 | // portion - fraction of the progress bar the next operation will use |
| 75 | // seconds - expected time interval (progress bar moves at this minimum rate) |
| 76 | void ui_show_progress(float portion, int seconds); |
| 77 | void ui_set_progress(float fraction); // 0.0 - 1.0 within the defined scope |
| 78 | |
| 79 | // Default allocation of progress bar segments to operations |
| 80 | static const int VERIFICATION_PROGRESS_TIME = 60; |
Doug Zongker | fd8fb0c | 2009-09-20 14:10:27 -0700 | [diff] [blame] | 81 | static const float VERIFICATION_PROGRESS_FRACTION = 0.25; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 82 | static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; |
| 83 | static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; |
| 84 | |
| 85 | // Show a rotating "barberpole" for ongoing operations. Updates automatically. |
| 86 | void ui_show_indeterminate_progress(); |
| 87 | |
| 88 | // Hide and reset the progress bar. |
| 89 | void ui_reset_progress(); |
| 90 | |
| 91 | #define LOGE(...) ui_print("E:" __VA_ARGS__) |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 92 | #define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__) |
| 93 | #define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 94 | |
| 95 | #if 0 |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 96 | #define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__) |
| 97 | #define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 98 | #else |
| 99 | #define LOGV(...) do {} while (0) |
| 100 | #define LOGD(...) do {} while (0) |
| 101 | #endif |
| 102 | |
Doug Zongker | fb2e3af | 2009-06-17 17:29:40 -0700 | [diff] [blame] | 103 | #define STRINGIFY(x) #x |
| 104 | #define EXPAND(x) STRINGIFY(x) |
| 105 | |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 106 | typedef struct { |
| 107 | const char* mount_point; // eg. "/cache". must live in the root directory. |
| 108 | |
| 109 | const char* fs_type; // "yaffs2" or "ext4" or "vfat" |
| 110 | |
| 111 | const char* device; // MTD partition name if fs_type == "yaffs" |
| 112 | // block device if fs_type == "ext4" or "vfat" |
| 113 | |
| 114 | const char* device2; // alternative device to try if fs_type |
| 115 | // == "ext4" or "vfat" and mounting |
| 116 | // 'device' fails |
Doug Zongker | 2810ced | 2011-02-17 15:55:21 -0800 | [diff] [blame] | 117 | |
| 118 | long long length; // (ext4 partition only) when |
| 119 | // formatting, size to use for the |
| 120 | // partition. 0 or negative number |
| 121 | // means to format all but the last |
| 122 | // (that much). |
Koushik Dutta | 0df56f4 | 2011-11-16 16:00:35 -0800 | [diff] [blame] | 123 | |
Koushik Dutta | 64d79c6 | 2011-02-09 06:12:44 -0800 | [diff] [blame] | 124 | const char* fs_type2; |
Koushik Dutta | e8bc2c8 | 2011-02-27 14:00:19 -0800 | [diff] [blame] | 125 | |
| 126 | const char* fs_options; |
| 127 | |
| 128 | const char* fs_options2; |
Doug Zongker | d4208f9 | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 129 | } Volume; |
| 130 | |
Doug Zongker | 6809c51 | 2011-03-01 14:04:34 -0800 | [diff] [blame] | 131 | typedef struct { |
| 132 | // number of frames in indeterminate progress bar animation |
| 133 | int indeterminate_frames; |
| 134 | |
| 135 | // number of frames per second to try to maintain when animating |
| 136 | int update_fps; |
| 137 | |
| 138 | // number of frames in installing animation. may be zero for a |
| 139 | // static installation icon. |
| 140 | int installing_frames; |
| 141 | |
| 142 | // the install icon is animated by drawing images containing the |
| 143 | // changing part over the base icon. These specify the |
| 144 | // coordinates of the upper-left corner. |
| 145 | int install_overlay_offset_x; |
| 146 | int install_overlay_offset_y; |
| 147 | |
| 148 | } UIParameters; |
| 149 | |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 150 | // fopen a file, mounting volumes and making parent dirs as necessary. |
| 151 | FILE* fopen_path(const char *path, const char *mode); |
| 152 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 153 | #endif // RECOVERY_COMMON_H |