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: Device(RecoveryUI * ui)24 explicit Device(RecoveryUI* ui) : ui_(ui) {} ~Device()25 virtual ~Device() {} 26 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. GetUI()30 virtual RecoveryUI* GetUI() { 31 return ui_; 32 } 33 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). StartRecovery()36 virtual void StartRecovery() {}; 37 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); 55 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 }; 70 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(); 74 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); 82 83 static const int kNoAction = -1; 84 static const int kHighlightUp = -2; 85 static const int kHighlightDown = -3; 86 static const int kInvokeItem = -4; 87 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. PreWipeData()93 virtual bool PreWipeData() { 94 return true; 95 } 96 PostWipeData()97 virtual bool PostWipeData() { 98 return true; 99 } 100 101 private: 102 RecoveryUI* ui_; 103 }; 104 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. 107 Device* make_device(); 108 109 #endif // _DEVICE_H 110