blob: ea1f5c03ab6cea9ff482c40c13c9d35322929c6c [file] [log] [blame]
Doug Zongker211aebc2011-10-28 15:13:10 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
Tom Marshall820517b2019-01-14 14:28:55 -08003 * Copyright (C) 2019 The LineageOS Project
Doug Zongker211aebc2011-10-28 15:13:10 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef RECOVERY_SCREEN_UI_H
19#define RECOVERY_SCREEN_UI_H
20
21#include <pthread.h>
Elliott Hughes95fc63e2015-04-10 19:12:01 -070022#include <stdio.h>
Doug Zongker211aebc2011-10-28 15:13:10 -070023
Tao Bao736d59c2017-01-03 10:15:33 -080024#include <string>
Tao Baoe15d7a52017-09-07 13:38:51 -070025#include <vector>
Tao Bao736d59c2017-01-03 10:15:33 -080026
Doug Zongker211aebc2011-10-28 15:13:10 -070027#include "ui.h"
Tao Bao0ecbd762017-01-16 21:16:58 -080028
Tom Marshall820517b2019-01-14 14:28:55 -080029#define MAX_MENU_ITEMS 32
30
Tao Bao0ecbd762017-01-16 21:16:58 -080031// From minui/minui.h.
32struct GRSurface;
Doug Zongker211aebc2011-10-28 15:13:10 -070033
Tom Marshall820517b2019-01-14 14:28:55 -080034class ScreenMenuItem {
35 public:
36 ScreenMenuItem() : icon_(nullptr), icon_sel_(nullptr) {}
37 explicit ScreenMenuItem(const MenuItem& mi)
38 : text_(mi.text()),
39 icon_name_(mi.icon_name()),
40 icon_(nullptr),
41 icon_name_sel_(mi.icon_name_sel()),
42 icon_sel_(nullptr) {}
43 ~ScreenMenuItem();
44
45 const std::string& text() const {
46 return text_;
47 }
48 GRSurface* icon();
49 GRSurface* icon_sel();
50
51 private:
52 std::string text_;
53 std::string icon_name_;
54 GRSurface* icon_;
55 std::string icon_name_sel_;
56 GRSurface* icon_sel_;
57};
58typedef std::vector<ScreenMenuItem> ScreenMenuItemVector;
59
Doug Zongker211aebc2011-10-28 15:13:10 -070060// Implementation of RecoveryUI appropriate for devices with a screen
61// (shows an icon + a progress bar, text logging, menu, etc.)
62class ScreenRecoveryUI : public RecoveryUI {
Tao Bao5d2e3bd2017-06-23 22:23:50 -070063 public:
Tao Bao75779652017-09-10 11:28:32 -070064 enum UIElement {
Tom Marshall820517b2019-01-14 14:28:55 -080065 STATUSBAR,
Tao Bao75779652017-09-10 11:28:32 -070066 HEADER,
67 MENU,
68 MENU_SEL_BG,
69 MENU_SEL_BG_ACTIVE,
70 MENU_SEL_FG,
71 LOG,
72 TEXT_FILL,
73 INFO
74 };
75
Tao Bao5d2e3bd2017-06-23 22:23:50 -070076 ScreenRecoveryUI();
Doug Zongker211aebc2011-10-28 15:13:10 -070077
Tao Bao5d2e3bd2017-06-23 22:23:50 -070078 bool Init(const std::string& locale) override;
Tom Marshallcfcafa12017-09-08 19:48:46 +000079 void Stop() override;
Doug Zongker211aebc2011-10-28 15:13:10 -070080
Tao Bao5d2e3bd2017-06-23 22:23:50 -070081 // overall recovery state ("background image")
Tao Bao99b2d772017-06-23 22:47:03 -070082 void SetBackground(Icon icon) override;
83 void SetSystemUpdateText(bool security_update) override;
Doug Zongker211aebc2011-10-28 15:13:10 -070084
Tao Bao5d2e3bd2017-06-23 22:23:50 -070085 // progress indicator
86 void SetProgressType(ProgressType type) override;
87 void ShowProgress(float portion, float seconds) override;
88 void SetProgress(float fraction) override;
Doug Zongker211aebc2011-10-28 15:13:10 -070089
Tao Bao5d2e3bd2017-06-23 22:23:50 -070090 void SetStage(int current, int max) override;
Doug Zongkerc87bab12013-11-25 13:53:25 -080091
Tao Bao5d2e3bd2017-06-23 22:23:50 -070092 // text log
93 void ShowText(bool visible) override;
94 bool IsTextVisible() override;
95 bool WasTextEverVisible() override;
Alessandro Astone20c8d412019-04-01 11:11:33 +020096 void UpdateScreenOnPrint(bool update) override {
97 update_screen_on_print = update;
98 }
Doug Zongker211aebc2011-10-28 15:13:10 -070099
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700100 // printing messages
Tao Bao99b2d772017-06-23 22:47:03 -0700101 void Print(const char* fmt, ...) override __printflike(2, 3);
102 void PrintOnScreenOnly(const char* fmt, ...) override __printflike(2, 3);
Tom Marshall820517b2019-01-14 14:28:55 -0800103 int ShowFile(const char* filename) override;
Doug Zongker211aebc2011-10-28 15:13:10 -0700104
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700105 // menu display
Tom Marshall820517b2019-01-14 14:28:55 -0800106 void StartMenu(bool is_main, menu_type_t type, const char* const* headers,
107 const MenuItemVector& items, int initial_selection) override;
Tao Bao99b2d772017-06-23 22:47:03 -0700108 int SelectMenu(int sel) override;
Tom Marshall820517b2019-01-14 14:28:55 -0800109 int SelectMenu(const Point& point) override;
Alessandro Astoned6eb74e2019-03-28 22:02:02 +0100110 int ScrollMenu(int updown) override;
Tao Bao99b2d772017-06-23 22:47:03 -0700111 void EndMenu() override;
Doug Zongker211aebc2011-10-28 15:13:10 -0700112
Tom Marshall820517b2019-01-14 14:28:55 -0800113 bool MenuShowing() const {
114 return show_menu;
115 }
116 bool MenuScrollable() const {
117 return (menu_type_ == MT_LIST);
118 }
119 int MenuItemStart() const {
120 return menu_start_y_;
121 }
122 int MenuItemHeight() const {
123 return (3 * menu_char_height_);
124 }
125
Tao Bao99b2d772017-06-23 22:47:03 -0700126 void KeyLongPress(int) override;
Elliott Hughes642aaa72015-04-10 12:47:46 -0700127
Tom Marshallf780f1c2018-03-01 23:51:51 +0100128 void Redraw() override;
Doug Zongkerc0441d12013-07-31 11:28:24 -0700129
Tao Bao99b2d772017-06-23 22:47:03 -0700130 void SetColor(UIElement e) const;
Doug Zongkerc0441d12013-07-31 11:28:24 -0700131
Tianjie Xu29d55752017-09-20 17:53:46 -0700132 // Check the background text image. Use volume up/down button to cycle through the locales
133 // embedded in the png file, and power button to go back to recovery main menu.
134 void CheckBackgroundTextImages(const std::string& saved_locale);
135
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700136 protected:
137 // The margin that we don't want to use for showing texts (e.g. round screen, or screen with
138 // rounded corners).
139 const int kMarginWidth;
140 const int kMarginHeight;
Tao Bao4521b702017-06-20 18:11:21 -0700141
Tao Bao0470cee2017-08-02 17:11:04 -0700142 // Number of frames per sec (default: 30) for both parts of the animation.
143 const int kAnimationFps;
144
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700145 // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
Tao Bao75779652017-09-10 11:28:32 -0700146 const float kDensity;
147
148 virtual bool InitTextParams();
149
150 virtual void draw_background_locked();
Tom Marshallf780f1c2018-03-01 23:51:51 +0100151 virtual void draw_foreground_locked(int& y);
Tom Marshall820517b2019-01-14 14:28:55 -0800152 virtual void draw_statusbar_locked();
153 virtual void draw_header_locked(int& y);
154 virtual void draw_text_menu_locked(int& y);
155 virtual void draw_grid_menu_locked(int& y);
Tao Bao75779652017-09-10 11:28:32 -0700156 virtual void draw_screen_locked();
157 virtual void update_screen_locked();
158 virtual void update_progress_locked();
159
160 GRSurface* GetCurrentFrame() const;
161 GRSurface* GetCurrentText() const;
162
163 static void* ProgressThreadStartRoutine(void* data);
164 void ProgressThreadLoop();
165
Tom Marshall820517b2019-01-14 14:28:55 -0800166 virtual int ShowFile(FILE*);
Tao Bao75779652017-09-10 11:28:32 -0700167 virtual void PrintV(const char*, bool, va_list);
Alessandro Astone20c8d412019-04-01 11:11:33 +0200168 void NewLine();
Tao Bao75779652017-09-10 11:28:32 -0700169 void PutChar(char);
170 void ClearText();
171
172 void LoadAnimation();
173 void LoadBitmap(const char* filename, GRSurface** surface);
Tom Marshall820517b2019-01-14 14:28:55 -0800174 void FreeBitmap(GRSurface* surface);
Tao Bao75779652017-09-10 11:28:32 -0700175 void LoadLocalizedBitmap(const char* filename, GRSurface** surface);
176
177 int PixelsFromDp(int dp) const;
178 virtual int GetAnimationBaseline() const;
179 virtual int GetProgressBaseline() const;
180 virtual int GetTextBaseline() const;
181
Luke Song92eda4d2017-09-19 10:51:35 -0700182 // Returns pixel width of draw buffer.
183 virtual int ScreenWidth() const;
184 // Returns pixel height of draw buffer.
185 virtual int ScreenHeight() const;
186
Tao Bao75779652017-09-10 11:28:32 -0700187 // Draws a highlight bar at (x, y) - (x + width, y + height).
188 virtual void DrawHighlightBar(int x, int y, int width, int height) const;
189 // Draws a horizontal rule at Y. Returns the offset it should be moving along Y-axis.
190 virtual int DrawHorizontalRule(int y) const;
191 // Draws a line of text. Returns the offset it should be moving along Y-axis.
192 virtual int DrawTextLine(int x, int y, const char* line, bool bold) const;
Luke Song92eda4d2017-09-19 10:51:35 -0700193 // Draws surface portion (sx, sy, w, h) at screen location (dx, dy).
194 virtual void DrawSurface(GRSurface* surface, int sx, int sy, int w, int h, int dx, int dy) const;
195 // Draws rectangle at (x, y) - (x + w, y + h).
196 virtual void DrawFill(int x, int y, int w, int h) const;
197 // Draws given surface (surface->pixel_bytes = 1) as text at (x, y).
198 virtual void DrawTextIcon(int x, int y, GRSurface* surface) const;
Tao Bao75779652017-09-10 11:28:32 -0700199 // Draws multiple text lines. Returns the offset it should be moving along Y-axis.
200 int DrawTextLines(int x, int y, const char* const* lines) const;
201 // Similar to DrawTextLines() to draw multiple text lines, but additionally wraps long lines.
202 // Returns the offset it should be moving along Y-axis.
203 int DrawWrappedTextLines(int x, int y, const char* const* lines) const;
Tao Bao171b4c42017-06-19 23:10:44 -0700204
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700205 Icon currentIcon;
Doug Zongker211aebc2011-10-28 15:13:10 -0700206
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700207 // The layout to use.
208 int layout_;
Elliott Hughesfaf36e02016-04-20 17:22:16 -0700209
Tom Marshall820517b2019-01-14 14:28:55 -0800210 GRSurface* logo_image;
211 GRSurface* ic_back;
212 GRSurface* ic_back_sel;
213
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700214 GRSurface* error_icon;
Elliott Hughes498cda62016-04-14 16:49:04 -0700215
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700216 GRSurface* erasing_text;
217 GRSurface* error_text;
218 GRSurface* installing_text;
219 GRSurface* no_command_text;
Elliott Hughes498cda62016-04-14 16:49:04 -0700220
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700221 GRSurface** introFrames;
222 GRSurface** loopFrames;
Elliott Hughes498cda62016-04-14 16:49:04 -0700223
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700224 GRSurface* progressBarEmpty;
225 GRSurface* progressBarFill;
226 GRSurface* stageMarkerEmpty;
227 GRSurface* stageMarkerFill;
Doug Zongker211aebc2011-10-28 15:13:10 -0700228
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700229 ProgressType progressBarType;
Doug Zongker211aebc2011-10-28 15:13:10 -0700230
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700231 float progressScopeStart, progressScopeSize, progress;
232 double progressScopeTime, progressScopeDuration;
Doug Zongker211aebc2011-10-28 15:13:10 -0700233
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700234 // true when both graphics pages are the same (except for the progress bar).
235 bool pagesIdentical;
Doug Zongker211aebc2011-10-28 15:13:10 -0700236
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700237 size_t text_cols_, text_rows_;
Elliott Hughesc0491632015-05-06 12:40:05 -0700238
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700239 // Log text overlay, displayed when a magic key is pressed.
240 char** text_;
Tao Baocb5524c2017-09-08 21:25:32 -0700241 size_t text_col_, text_row_;
Elliott Hughesc0491632015-05-06 12:40:05 -0700242
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700243 bool show_text;
244 bool show_text_ever; // has show_text ever been true?
Alessandro Astone20c8d412019-04-01 11:11:33 +0200245 bool previous_row_ended;
246 bool update_screen_on_print;
Doug Zongker211aebc2011-10-28 15:13:10 -0700247
Tao Baoe15d7a52017-09-07 13:38:51 -0700248 std::vector<std::string> menu_;
Tom Marshall820517b2019-01-14 14:28:55 -0800249 bool menu_is_main_;
250 menu_type_t menu_type_;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700251 const char* const* menu_headers_;
Tom Marshall820517b2019-01-14 14:28:55 -0800252 ScreenMenuItemVector menu_items_;
253 int menu_start_y_;
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700254 bool show_menu;
Tom Marshall820517b2019-01-14 14:28:55 -0800255 int menu_show_start;
256 int menu_show_count;
257 int menu_sel;
Doug Zongker211aebc2011-10-28 15:13:10 -0700258
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700259 // An alternate text screen, swapped with 'text_' when we're viewing a log file.
260 char** file_viewer_text_;
Elliott Hughesc0491632015-05-06 12:40:05 -0700261
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700262 pthread_t progress_thread_;
Doug Zongker32a0a472011-11-01 11:00:20 -0700263
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700264 // Number of intro frames and loop frames in the animation.
265 size_t intro_frames;
266 size_t loop_frames;
Damien Bargiacchi5e7cfb92016-08-24 18:28:43 -0700267
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700268 size_t current_frame;
269 bool intro_done;
Elliott Hughes498cda62016-04-14 16:49:04 -0700270
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700271 int stage, max_stage;
Doug Zongkerc87bab12013-11-25 13:53:25 -0800272
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700273 int char_width_;
274 int char_height_;
Tao Bao171b4c42017-06-19 23:10:44 -0700275
Tom Marshall820517b2019-01-14 14:28:55 -0800276 int menu_char_width_;
277 int menu_char_height_;
278
Tao Baoefb49ad2017-01-31 23:03:10 -0800279 // The locale that's used to show the rendered texts.
280 std::string locale_;
281 bool rtl_locale_;
282
Tao Bao5d2e3bd2017-06-23 22:23:50 -0700283 pthread_mutex_t updateMutex;
Tao Baoefb49ad2017-01-31 23:03:10 -0800284
285 private:
CEnnis910ccad612013-05-02 13:29:53 -0400286 bool rainbow;
287 int wrap_count;
288
Tao Baoefb49ad2017-01-31 23:03:10 -0800289 void SetLocale(const std::string&);
Tianjie Xu29d55752017-09-20 17:53:46 -0700290
291 // Display the background texts for "erasing", "error", "no_command" and "installing" for the
292 // selected locale.
293 void SelectAndShowBackgroundText(const std::vector<std::string>& locales_entries, size_t sel);
CEnnis910ccad612013-05-02 13:29:53 -0400294
295 void OMGRainbows();
Doug Zongker211aebc2011-10-28 15:13:10 -0700296};
297
298#endif // RECOVERY_UI_H