blob: a24540066e8db792275e8888f0876f600259e20f [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 {
23 public:
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070024 Device(RecoveryUI* ui) : ui_(ui) { }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070025 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 Hughes9e7ae8a2015-04-09 13:40:31 -070031 virtual RecoveryUI* GetUI() { return ui_; }
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070032
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
38 // enum KeyAction { NONE, TOGGLE, REBOOT };
39
40 // // Called in the input thread when a new key (key_code) is
41 // // pressed. *key_pressed is an array of KEY_MAX+1 bytes
42 // // indicating which other keys are already pressed. Return a
43 // // KeyAction to indicate action should be taken immediately.
44 // // These actions happen when recovery is not waiting for input
45 // // (eg, in the midst of installing a package).
46 // virtual KeyAction CheckImmediateKeyAction(volatile char* key_pressed, int key_code) = 0;
47
48 // Called from the main thread when recovery is at the main menu
49 // and waiting for input, and a key is pressed. (Note that "at"
50 // the main menu does not necessarily mean the menu is visible;
51 // recovery will be at the main menu with it invisible after an
52 // unsuccessful operation [ie OTA package failure], or if recovery
53 // is started with no command.)
54 //
55 // key is the code of the key just pressed. (You can call
56 // IsKeyPressed() on the RecoveryUI object you returned from GetUI
57 // if you want to find out if other keys are held down.)
58 //
59 // visible is true if the menu is visible.
60 //
61 // Return one of the defined constants below in order to:
62 //
63 // - move the menu highlight (kHighlight{Up,Down})
64 // - invoke the highlighted item (kInvokeItem)
65 // - do nothing (kNoAction)
66 // - invoke a specific action (a menu position: any non-negative number)
67 virtual int HandleMenuKey(int key, int visible) = 0;
68
Doug Zongker93950222014-07-08 14:10:23 -070069 enum BuiltinAction { NO_ACTION, REBOOT, APPLY_EXT,
70 APPLY_CACHE, // APPLY_CACHE is deprecated; has no effect
Doug Zongker8d9d3d52014-04-01 13:20:23 -070071 APPLY_ADB_SIDELOAD, WIPE_DATA, WIPE_CACHE,
Nick Kralevicha9ad0322014-10-22 18:38:48 -070072 REBOOT_BOOTLOADER, SHUTDOWN, READ_RECOVERY_LASTLOG };
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070073
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070074 // Return the headers (an array of strings, one per line,
75 // NULL-terminated) for the main menu. Typically these tell users
76 // what to push to move the selection and invoke the selected
77 // item.
78 virtual const char* const* GetMenuHeaders();
79
80 // Return the list of menu items (an array of strings,
81 // NULL-terminated). The menu_position passed to InvokeMenuItem
82 // will correspond to the indexes into this array.
83 virtual const char* const* GetMenuItems();
84
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070085 // Perform a recovery action selected from the menu.
86 // 'menu_position' will be the item number of the selected menu
87 // item, or a non-negative number returned from
88 // device_handle_key(). The menu will be hidden when this is
89 // called; implementations can call ui_print() to print
90 // information to the screen. If the menu position is one of the
91 // builtin actions, you can just return the corresponding enum
92 // value. If it is an action specific to your device, you
93 // actually perform it here and return NO_ACTION.
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070094 virtual BuiltinAction InvokeMenuItem(int menu_position);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070095
96 static const int kNoAction = -1;
97 static const int kHighlightUp = -2;
98 static const int kHighlightDown = -3;
99 static const int kInvokeItem = -4;
100
101 // Called when we do a wipe data/factory reset operation (either via a
102 // reboot from the main system with the --wipe_data flag, or when the
103 // user boots into recovery manually and selects the option from the
104 // menu.) Can perform whatever device-specific wiping actions are
105 // needed. Return 0 on success. The userdata and cache partitions
106 // are erased AFTER this returns (whether it returns success or not).
107 virtual int WipeData() { return 0; }
108
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -0700109 private:
110 RecoveryUI* ui_;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700111};
112
113// The device-specific library must define this function (or the
114// default one will be used, if there is no device-specific library).
115// It returns the Device object that recovery should use.
116Device* make_device();
117
118#endif // _DEVICE_H