1 /*
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
23 static const char* HEADERS[] = { "Volume up/down to move highlight;",
24 "enter button to select.",
25 "",
26 NULL };
27
28 static const char* ITEMS[] = {"reboot system now",
29 "apply update from ADB",
30 "wipe data/factory reset",
31 "wipe cache partition",
32 NULL };
33
34 class DefaultUI : public ScreenRecoveryUI {
35 public:
CheckKey(int key)36 virtual KeyAction CheckKey(int key) {
37 if (key == KEY_HOME) {
38 return TOGGLE;
39 }
40 return ENQUEUE;
41 }
42 };
43
44 class DefaultDevice : public Device {
45 public:
DefaultDevice()46 DefaultDevice() :
47 ui(new DefaultUI) {
48 }
49
GetUI()50 RecoveryUI* GetUI() { return ui; }
51
HandleMenuKey(int key,int visible)52 int HandleMenuKey(int key, int visible) {
53 if (visible) {
54 switch (key) {
55 case KEY_DOWN:
56 case KEY_VOLUMEDOWN:
57 return kHighlightDown;
58
59 case KEY_UP:
60 case KEY_VOLUMEUP:
61 return kHighlightUp;
62
63 case KEY_ENTER:
64 return kInvokeItem;
65 }
66 }
67
68 return kNoAction;
69 }
70
InvokeMenuItem(int menu_position)71 BuiltinAction InvokeMenuItem(int menu_position) {
72 switch (menu_position) {
73 case 0: return REBOOT;
74 case 1: return APPLY_ADB_SIDELOAD;
75 case 2: return WIPE_DATA;
76 case 3: return WIPE_CACHE;
77 default: return NO_ACTION;
78 }
79 }
80
GetMenuHeaders()81 const char* const* GetMenuHeaders() { return HEADERS; }
GetMenuItems()82 const char* const* GetMenuItems() { return ITEMS; }
83
84 private:
85 RecoveryUI* ui;
86 };
87
make_device()88 Device* make_device() {
89 return new DefaultDevice();
90 }
91