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