blob: ed601f6c6d55fc1bde0febbdddde002f12776df2 [file] [log] [blame]
Doug Zongkerdaefc1d2011-10-31 09:34:15 -07001/*
2 * Copyright (C) 2009 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#include <linux/input.h>
18
19#include "common.h"
20#include "device.h"
21#include "screen_ui.h"
22
Elliott Hughesc51ac892015-03-20 18:22:15 -070023static const char* HEADERS[] = {
24 "Volume up/down to move highlight.",
25 "Power button to select.",
26 "",
27 NULL
28};
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070029
Elliott Hughesc51ac892015-03-20 18:22:15 -070030static const char* ITEMS[] = {
31 "Reboot system now",
32 "Reboot to bootloader",
33 "Apply update from ADB",
34 "Apply update from SD card",
35 "Wipe data/factory reset",
36 "Wipe cache partition",
37 "View recovery logs",
38 "Power off",
39 NULL
40};
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070041
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070042class DefaultDevice : public Device {
43 public:
44 DefaultDevice() :
Doug Zongker02abde52014-04-01 09:45:24 -070045 ui(new ScreenRecoveryUI) {
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070046 }
47
48 RecoveryUI* GetUI() { return ui; }
49
50 int HandleMenuKey(int key, int visible) {
51 if (visible) {
52 switch (key) {
53 case KEY_DOWN:
54 case KEY_VOLUMEDOWN:
55 return kHighlightDown;
56
57 case KEY_UP:
58 case KEY_VOLUMEUP:
59 return kHighlightUp;
60
61 case KEY_ENTER:
Doug Zongker02abde52014-04-01 09:45:24 -070062 case KEY_POWER:
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070063 return kInvokeItem;
64 }
65 }
66
67 return kNoAction;
68 }
69
70 BuiltinAction InvokeMenuItem(int menu_position) {
71 switch (menu_position) {
72 case 0: return REBOOT;
Elliott Hughesc51ac892015-03-20 18:22:15 -070073 case 1: return REBOOT_BOOTLOADER;
74 case 2: return APPLY_ADB_SIDELOAD;
75 case 3: return APPLY_EXT;
76 case 4: return WIPE_DATA;
77 case 5: return WIPE_CACHE;
Nick Kralevicha9ad0322014-10-22 18:38:48 -070078 case 6: return READ_RECOVERY_LASTLOG;
Elliott Hughesc51ac892015-03-20 18:22:15 -070079 case 7: return SHUTDOWN;
Doug Zongkerdaefc1d2011-10-31 09:34:15 -070080 default: return NO_ACTION;
81 }
82 }
83
84 const char* const* GetMenuHeaders() { return HEADERS; }
85 const char* const* GetMenuItems() { return ITEMS; }
86
87 private:
88 RecoveryUI* ui;
89};
90
91Device* make_device() {
92 return new DefaultDevice();
93}