Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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_DEVICE_H |
| 18 | #define _RECOVERY_DEVICE_H |
| 19 | |
| 20 | #include "ui.h" |
| 21 | |
| 22 | class Device { |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 23 | public: |
| 24 | explicit Device(RecoveryUI* ui) : ui_(ui) {} |
| 25 | virtual ~Device() {} |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 26 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 27 | // Called to obtain the UI object that should be used to display the recovery user interface for |
| 28 | // this device. You should not have called Init() on the UI object already, the caller will do |
| 29 | // that after this method returns. |
| 30 | virtual RecoveryUI* GetUI() { |
| 31 | return ui_; |
| 32 | } |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 33 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 34 | // Called when recovery starts up (after the UI has been obtained and initialized and after the |
| 35 | // arguments have been parsed, but before anything else). |
| 36 | virtual void StartRecovery() {}; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 37 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 38 | // Called from the main thread when recovery is at the main menu and waiting for input, and a key |
| 39 | // is pressed. (Note that "at" the main menu does not necessarily mean the menu is visible; |
| 40 | // recovery will be at the main menu with it invisible after an unsuccessful operation [ie OTA |
| 41 | // package failure], or if recovery is started with no command.) |
| 42 | // |
| 43 | // 'key' is the code of the key just pressed. (You can call IsKeyPressed() on the RecoveryUI |
| 44 | // object you returned from GetUI if you want to find out if other keys are held down.) |
| 45 | // |
| 46 | // 'visible' is true if the menu is visible. |
| 47 | // |
| 48 | // Returns one of the defined constants below in order to: |
| 49 | // |
| 50 | // - move the menu highlight (kHighlight{Up,Down}) |
| 51 | // - invoke the highlighted item (kInvokeItem) |
| 52 | // - do nothing (kNoAction) |
| 53 | // - invoke a specific action (a menu position: any non-negative number) |
| 54 | virtual int HandleMenuKey(int key, bool visible); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 55 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 56 | enum BuiltinAction { |
| 57 | NO_ACTION = 0, |
| 58 | REBOOT = 1, |
| 59 | APPLY_SDCARD = 2, |
| 60 | // APPLY_CACHE was 3. |
| 61 | APPLY_ADB_SIDELOAD = 4, |
| 62 | WIPE_DATA = 5, |
| 63 | WIPE_CACHE = 6, |
| 64 | REBOOT_BOOTLOADER = 7, |
| 65 | SHUTDOWN = 8, |
| 66 | VIEW_RECOVERY_LOGS = 9, |
| 67 | MOUNT_SYSTEM = 10, |
| 68 | RUN_GRAPHICS_TEST = 11, |
| 69 | }; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 70 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 71 | // Return the list of menu items (an array of strings, NULL-terminated). The menu_position passed |
| 72 | // to InvokeMenuItem will correspond to the indexes into this array. |
| 73 | virtual const char* const* GetMenuItems(); |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 74 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 75 | // Perform a recovery action selected from the menu. 'menu_position' will be the item number of |
| 76 | // the selected menu item, or a non-negative number returned from HandleMenuKey(). The menu will |
| 77 | // be hidden when this is called; implementations can call ui_print() to print information to the |
| 78 | // screen. If the menu position is one of the builtin actions, you can just return the |
| 79 | // corresponding enum value. If it is an action specific to your device, you actually perform it |
| 80 | // here and return NO_ACTION. |
| 81 | virtual BuiltinAction InvokeMenuItem(int menu_position); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 82 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 83 | static const int kNoAction = -1; |
| 84 | static const int kHighlightUp = -2; |
| 85 | static const int kHighlightDown = -3; |
| 86 | static const int kInvokeItem = -4; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 87 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 88 | // Called before and after we do a wipe data/factory reset operation, either via a reboot from the |
| 89 | // main system with the --wipe_data flag, or when the user boots into recovery image manually and |
| 90 | // selects the option from the menu, to perform whatever device-specific wiping actions as needed. |
| 91 | // Returns true on success; returning false from PreWipeData will prevent the regular wipe, and |
| 92 | // returning false from PostWipeData will cause the wipe to be considered a failure. |
| 93 | virtual bool PreWipeData() { |
| 94 | return true; |
| 95 | } |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 96 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 97 | virtual bool PostWipeData() { |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | RecoveryUI* ui_; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 105 | // The device-specific library must define this function (or the default one will be used, if there |
| 106 | // 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] | 107 | Device* make_device(); |
| 108 | |
| 109 | #endif // _DEVICE_H |