blob: 542b891c5c23fee94611f5d102ed270ef7488b04 [file] [log] [blame]
Doug Zongkerdaefc1d2011-10-31 09:34:15 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
Tom Marshall74f48242017-08-24 13:50:01 +00003 * Copyright (C) 2019 The LineageOS Project
Doug Zongkerdaefc1d2011-10-31 09:34:15 -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_DEVICE_H
19#define _RECOVERY_DEVICE_H
20
21#include "ui.h"
22
23class Device {
Tao Baofc5499f2017-02-23 19:06:53 -080024 public:
Tom Marshall820517b2019-01-14 14:28:55 -080025 explicit Device(RecoveryUI* ui);
Tao Baofc5499f2017-02-23 19:06:53 -080026 virtual ~Device() {}
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070027
Tao Baofc5499f2017-02-23 19:06:53 -080028 // Called to obtain the UI object that should be used to display the recovery user interface for
29 // this device. You should not have called Init() on the UI object already, the caller will do
30 // that after this method returns.
31 virtual RecoveryUI* GetUI() {
32 return ui_;
33 }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070034
Tao Baofc5499f2017-02-23 19:06:53 -080035 // Called when recovery starts up (after the UI has been obtained and initialized and after the
36 // arguments have been parsed, but before anything else).
37 virtual void StartRecovery() {};
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070038
Tao Baofc5499f2017-02-23 19:06:53 -080039 // Called from the main thread when recovery is at the main menu and waiting for input, and a key
40 // is pressed. (Note that "at" the main menu does not necessarily mean the menu is visible;
41 // recovery will be at the main menu with it invisible after an unsuccessful operation [ie OTA
42 // package failure], or if recovery is started with no command.)
43 //
44 // 'key' is the code of the key just pressed. (You can call IsKeyPressed() on the RecoveryUI
45 // object you returned from GetUI if you want to find out if other keys are held down.)
46 //
47 // 'visible' is true if the menu is visible.
48 //
49 // Returns one of the defined constants below in order to:
50 //
51 // - move the menu highlight (kHighlight{Up,Down})
52 // - invoke the highlighted item (kInvokeItem)
53 // - do nothing (kNoAction)
54 // - invoke a specific action (a menu position: any non-negative number)
55 virtual int HandleMenuKey(int key, bool visible);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070056
Tao Baofc5499f2017-02-23 19:06:53 -080057 enum BuiltinAction {
58 NO_ACTION = 0,
Tom Marshall820517b2019-01-14 14:28:55 -080059 // Main menu
Tao Baofc5499f2017-02-23 19:06:53 -080060 REBOOT = 1,
Tom Marshalla08c6f12019-01-04 14:37:31 -080061 APPLY_UPDATE = 2,
Tom Marshall820517b2019-01-14 14:28:55 -080062 WIPE_MENU = 3,
63 ADVANCED_MENU = 4,
64 // Wipe menu
65 WIPE_DATA = 10,
66 WIPE_CACHE = 11,
67 WIPE_SYSTEM = 12,
68 // Advanced menu
69 REBOOT_BOOTLOADER = 20,
jrior00125f976d2019-03-24 17:57:07 -040070 REBOOT_RECOVERY = 21,
71 MOUNT_SYSTEM = 22,
72 VIEW_RECOVERY_LOGS = 23,
73 RUN_GRAPHICS_TEST = 24,
74 RUN_LOCALE_TEST = 25,
75 SHUTDOWN = 26,
Tao Baofc5499f2017-02-23 19:06:53 -080076 };
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070077
Tom Marshall820517b2019-01-14 14:28:55 -080078 typedef std::vector<MenuItem> MenuItemVector;
79 typedef std::vector<BuiltinAction> MenuActionVector;
80
81 // Return the menu properties. The menu_position passed to InvokeMenuItem
82 // will correspond to the indexes in the associated vectors.
83 virtual bool IsMainMenu() const {
84 return menu_is_main_;
85 }
86 virtual menu_type_t GetMenuType() const {
87 return menu_type_;
88 }
89 virtual const MenuItemVector& GetMenuItems() const {
90 return menu_items_;
91 }
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070092
Tao Baofc5499f2017-02-23 19:06:53 -080093 // Perform a recovery action selected from the menu. 'menu_position' will be the item number of
94 // the selected menu item, or a non-negative number returned from HandleMenuKey(). The menu will
95 // be hidden when this is called; implementations can call ui_print() to print information to the
96 // screen. If the menu position is one of the builtin actions, you can just return the
97 // corresponding enum value. If it is an action specific to your device, you actually perform it
98 // here and return NO_ACTION.
99 virtual BuiltinAction InvokeMenuItem(int menu_position);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700100
Tom Marshall820517b2019-01-14 14:28:55 -0800101 virtual void GoHome();
102
Tao Baofc5499f2017-02-23 19:06:53 -0800103 static const int kNoAction = -1;
104 static const int kHighlightUp = -2;
105 static const int kHighlightDown = -3;
106 static const int kInvokeItem = -4;
Tom Marshall74f48242017-08-24 13:50:01 +0000107 static const int kGoBack = -5;
108 static const int kGoHome = -6;
Tom Marshalla08c6f12019-01-04 14:37:31 -0800109 static const int kRefresh = -7;
Alessandro Astoned6eb74e2019-03-28 22:02:02 +0100110 static const int kScrollUp = -8;
111 static const int kScrollDown = -9;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700112
Tao Baofc5499f2017-02-23 19:06:53 -0800113 // Called before and after we do a wipe data/factory reset operation, either via a reboot from the
114 // main system with the --wipe_data flag, or when the user boots into recovery image manually and
115 // selects the option from the menu, to perform whatever device-specific wiping actions as needed.
116 // Returns true on success; returning false from PreWipeData will prevent the regular wipe, and
117 // returning false from PostWipeData will cause the wipe to be considered a failure.
118 virtual bool PreWipeData() {
119 return true;
120 }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700121
Tao Baofc5499f2017-02-23 19:06:53 -0800122 virtual bool PostWipeData() {
123 return true;
124 }
125
Tom Marshalla08c6f12019-01-04 14:37:31 -0800126 virtual void handleVolumeChanged() {
127 ui_->onVolumeChanged();
128 }
129
Tao Baofc5499f2017-02-23 19:06:53 -0800130 private:
131 RecoveryUI* ui_;
Tom Marshall820517b2019-01-14 14:28:55 -0800132
133 bool menu_is_main_;
134 menu_type_t menu_type_;
135 MenuItemVector menu_items_;
136 MenuActionVector menu_actions_;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700137};
138
Tao Baofc5499f2017-02-23 19:06:53 -0800139// The device-specific library must define this function (or the default one will be used, if there
140// is no device-specific library). It returns the Device object that recovery should use.
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700141Device* make_device();
142
143#endif // _DEVICE_H