blob: 4ea3159bd137f5db2df0cd3f9346d541649021a2 [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
Tao Baoc16fd8a2018-04-30 17:12:03 -070020// Forward declaration to avoid including "ui.h".
21class RecoveryUI;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070022
23class Device {
Tao Baofc5499f2017-02-23 19:06:53 -080024 public:
25 explicit Device(RecoveryUI* ui) : ui_(ui) {}
26 virtual ~Device() {}
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070027
Tao Baofc5499f2017-02-23 19:06:53 -080028 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070034
Tao Baofc5499f2017-02-23 19:06:53 -080035 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070038
Tao Baofc5499f2017-02-23 19:06:53 -080039 // 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 Zongkerdaefc1d2011-10-31 09:34:15 -070056
Tao Baofc5499f2017-02-23 19:06:53 -080057 enum BuiltinAction {
58 NO_ACTION = 0,
59 REBOOT = 1,
60 APPLY_SDCARD = 2,
61 // APPLY_CACHE was 3.
62 APPLY_ADB_SIDELOAD = 4,
63 WIPE_DATA = 5,
64 WIPE_CACHE = 6,
65 REBOOT_BOOTLOADER = 7,
66 SHUTDOWN = 8,
67 VIEW_RECOVERY_LOGS = 9,
68 MOUNT_SYSTEM = 10,
69 RUN_GRAPHICS_TEST = 11,
Tianjie Xu29d55752017-09-20 17:53:46 -070070 RUN_LOCALE_TEST = 12,
Tao Baofc5499f2017-02-23 19:06:53 -080071 };
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070072
Tao Baofc5499f2017-02-23 19:06:53 -080073 // Return the list of menu items (an array of strings, NULL-terminated). The menu_position passed
74 // to InvokeMenuItem will correspond to the indexes into this array.
75 virtual const char* const* GetMenuItems();
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070076
Tao Baofc5499f2017-02-23 19:06:53 -080077 // Perform a recovery action selected from the menu. 'menu_position' will be the item number of
78 // the selected menu item, or a non-negative number returned from HandleMenuKey(). The menu will
79 // be hidden when this is called; implementations can call ui_print() to print information to the
80 // screen. If the menu position is one of the builtin actions, you can just return the
81 // corresponding enum value. If it is an action specific to your device, you actually perform it
82 // here and return NO_ACTION.
83 virtual BuiltinAction InvokeMenuItem(int menu_position);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070084
Tao Baofc5499f2017-02-23 19:06:53 -080085 static const int kNoAction = -1;
86 static const int kHighlightUp = -2;
87 static const int kHighlightDown = -3;
88 static const int kInvokeItem = -4;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070089
Tao Baofc5499f2017-02-23 19:06:53 -080090 // Called before and after we do a wipe data/factory reset operation, either via a reboot from the
91 // main system with the --wipe_data flag, or when the user boots into recovery image manually and
92 // selects the option from the menu, to perform whatever device-specific wiping actions as needed.
93 // Returns true on success; returning false from PreWipeData will prevent the regular wipe, and
94 // returning false from PostWipeData will cause the wipe to be considered a failure.
95 virtual bool PreWipeData() {
96 return true;
97 }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070098
Tao Baofc5499f2017-02-23 19:06:53 -080099 virtual bool PostWipeData() {
100 return true;
101 }
102
103 private:
104 RecoveryUI* ui_;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700105};
106
Tao Baofc5499f2017-02-23 19:06:53 -0800107// The device-specific library must define this function (or the default one will be used, if there
108// is no device-specific library). It returns the Device object that recovery should use.
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700109Device* make_device();
110
111#endif // _DEVICE_H