blob: 74745b36c37c5cd325a81ce403a5310353114be2 [file] [log] [blame]
Doug Zongkerdaefc1d2011-10-31 09:34:15 -07001/*
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
22class Device {
Tao Baofc5499f2017-02-23 19:06:53 -080023 public:
24 explicit Device(RecoveryUI* ui) : ui_(ui) {}
25 virtual ~Device() {}
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070026
Tao Baofc5499f2017-02-23 19:06:53 -080027 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070033
Tao Baofc5499f2017-02-23 19:06:53 -080034 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070037
Tao Baofc5499f2017-02-23 19:06:53 -080038 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070055
Tao Baofc5499f2017-02-23 19:06:53 -080056 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,
Tianjie Xu29d55752017-09-20 17:53:46 -070069 RUN_LOCALE_TEST = 12,
Tao Baofc5499f2017-02-23 19:06:53 -080070 };
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070071
Tao Baofc5499f2017-02-23 19:06:53 -080072 // Return the list of menu items (an array of strings, NULL-terminated). The menu_position passed
73 // to InvokeMenuItem will correspond to the indexes into this array.
74 virtual const char* const* GetMenuItems();
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070075
Tao Baofc5499f2017-02-23 19:06:53 -080076 // Perform a recovery action selected from the menu. 'menu_position' will be the item number of
77 // the selected menu item, or a non-negative number returned from HandleMenuKey(). The menu will
78 // be hidden when this is called; implementations can call ui_print() to print information to the
79 // screen. If the menu position is one of the builtin actions, you can just return the
80 // corresponding enum value. If it is an action specific to your device, you actually perform it
81 // here and return NO_ACTION.
82 virtual BuiltinAction InvokeMenuItem(int menu_position);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070083
Tao Baofc5499f2017-02-23 19:06:53 -080084 static const int kNoAction = -1;
85 static const int kHighlightUp = -2;
86 static const int kHighlightDown = -3;
87 static const int kInvokeItem = -4;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070088
Tao Baofc5499f2017-02-23 19:06:53 -080089 // Called before and after we do a wipe data/factory reset operation, either via a reboot from the
90 // main system with the --wipe_data flag, or when the user boots into recovery image manually and
91 // selects the option from the menu, to perform whatever device-specific wiping actions as needed.
92 // Returns true on success; returning false from PreWipeData will prevent the regular wipe, and
93 // returning false from PostWipeData will cause the wipe to be considered a failure.
94 virtual bool PreWipeData() {
95 return true;
96 }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070097
Tao Baofc5499f2017-02-23 19:06:53 -080098 virtual bool PostWipeData() {
99 return true;
100 }
101
102 private:
103 RecoveryUI* ui_;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700104};
105
Tao Baofc5499f2017-02-23 19:06:53 -0800106// The device-specific library must define this function (or the default one will be used, if there
107// is no device-specific library). It returns the Device object that recovery should use.
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700108Device* make_device();
109
110#endif // _DEVICE_H