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