Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
Tom Marshall | 74f4824 | 2017-08-24 13:50:01 +0000 | [diff] [blame] | 3 | * Copyright (C) 2019 The LineageOS Project |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 4 | * |
| 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 | |
| 23 | class Device { |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 24 | public: |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 25 | explicit Device(RecoveryUI* ui); |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 26 | virtual ~Device() {} |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 27 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 28 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 34 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 35 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 38 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 39 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 56 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 57 | enum BuiltinAction { |
| 58 | NO_ACTION = 0, |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 59 | // Main menu |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 60 | REBOOT = 1, |
Tom Marshall | a08c6f1 | 2019-01-04 14:37:31 -0800 | [diff] [blame] | 61 | APPLY_UPDATE = 2, |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 62 | 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, |
jrior001 | 25f976d | 2019-03-24 17:57:07 -0400 | [diff] [blame] | 70 | 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 Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 76 | }; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 77 | |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 78 | 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 Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 92 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 93 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 100 | |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 101 | virtual void GoHome(); |
| 102 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 103 | static const int kNoAction = -1; |
| 104 | static const int kHighlightUp = -2; |
| 105 | static const int kHighlightDown = -3; |
| 106 | static const int kInvokeItem = -4; |
Tom Marshall | 74f4824 | 2017-08-24 13:50:01 +0000 | [diff] [blame] | 107 | static const int kGoBack = -5; |
| 108 | static const int kGoHome = -6; |
Tom Marshall | a08c6f1 | 2019-01-04 14:37:31 -0800 | [diff] [blame] | 109 | static const int kRefresh = -7; |
Alessandro Astone | d6eb74e | 2019-03-28 22:02:02 +0100 | [diff] [blame] | 110 | static const int kScrollUp = -8; |
| 111 | static const int kScrollDown = -9; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 112 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 113 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 121 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 122 | virtual bool PostWipeData() { |
| 123 | return true; |
| 124 | } |
| 125 | |
Tom Marshall | a08c6f1 | 2019-01-04 14:37:31 -0800 | [diff] [blame] | 126 | virtual void handleVolumeChanged() { |
| 127 | ui_->onVolumeChanged(); |
| 128 | } |
| 129 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 130 | private: |
| 131 | RecoveryUI* ui_; |
Tom Marshall | 820517b | 2019-01-14 14:28:55 -0800 | [diff] [blame] | 132 | |
| 133 | bool menu_is_main_; |
| 134 | menu_type_t menu_type_; |
| 135 | MenuItemVector menu_items_; |
| 136 | MenuActionVector menu_actions_; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 139 | // 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 Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 141 | Device* make_device(); |
| 142 | |
| 143 | #endif // _DEVICE_H |