blob: 97ec2fb416b31b823a930f17b49be95ab9ef80be [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
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070038 // 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)
57 virtual int HandleMenuKey(int key, int visible) = 0;
58
Doug Zongker93950222014-07-08 14:10:23 -070059 enum BuiltinAction { NO_ACTION, REBOOT, APPLY_EXT,
60 APPLY_CACHE, // APPLY_CACHE is deprecated; has no effect
Doug Zongker8d9d3d52014-04-01 13:20:23 -070061 APPLY_ADB_SIDELOAD, WIPE_DATA, WIPE_CACHE,
Nick Kralevicha9ad0322014-10-22 18:38:48 -070062 REBOOT_BOOTLOADER, SHUTDOWN, READ_RECOVERY_LASTLOG };
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070063
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070064 // Return the headers (an array of strings, one per line,
65 // NULL-terminated) for the main menu. Typically these tell users
66 // what to push to move the selection and invoke the selected
67 // item.
68 virtual const char* const* GetMenuHeaders();
69
70 // Return the list of menu items (an array of strings,
71 // NULL-terminated). The menu_position passed to InvokeMenuItem
72 // will correspond to the indexes into this array.
73 virtual const char* const* GetMenuItems();
74
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070075 // Perform a recovery action selected from the menu.
76 // 'menu_position' will be the item number of the selected menu
77 // item, or a non-negative number returned from
78 // device_handle_key(). The menu will be hidden when this is
79 // called; implementations can call ui_print() to print
80 // information to the screen. If the menu position is one of the
81 // builtin actions, you can just return the corresponding enum
82 // value. If it is an action specific to your device, you
83 // actually perform it here and return NO_ACTION.
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070084 virtual BuiltinAction InvokeMenuItem(int menu_position);
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070085
86 static const int kNoAction = -1;
87 static const int kHighlightUp = -2;
88 static const int kHighlightDown = -3;
89 static const int kInvokeItem = -4;
90
91 // Called when we do a wipe data/factory reset operation (either via a
92 // reboot from the main system with the --wipe_data flag, or when the
93 // user boots into recovery manually and selects the option from the
94 // menu.) Can perform whatever device-specific wiping actions are
95 // needed. Return 0 on success. The userdata and cache partitions
96 // are erased AFTER this returns (whether it returns success or not).
97 virtual int WipeData() { return 0; }
98
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070099 private:
100 RecoveryUI* ui_;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -0700101};
102
103// The device-specific library must define this function (or the
104// default one will be used, if there is no device-specific library).
105// It returns the Device object that recovery should use.
106Device* make_device();
107
108#endif // _DEVICE_H