aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker2011-10-31 11:34:15 -0500
committerDoug Zongker2011-10-31 17:51:07 -0500
commitdaefc1d442fb421606680feb9aeb59c133f4c427 (patch)
tree71b64ebdd66540aca7a523c73a47626ca519d039 /default_device.cpp
parentb88aea8a89f9d3344022cdfe895397baac6c05e7 (diff)
downloadplatform-bootable-recovery-daefc1d442fb421606680feb9aeb59c133f4c427.tar.gz
platform-bootable-recovery-daefc1d442fb421606680feb9aeb59c133f4c427.tar.xz
platform-bootable-recovery-daefc1d442fb421606680feb9aeb59c133f4c427.zip
C++ class for device-specific code
Replace the device-specific functions with a class. Move some of the key handling (for log visibility toggling and rebooting) into the UI class. Fix up the key handling so there is less crosstalk between the immediate keys and the queued keys (an increasing annoyance on button-limited devices). Change-Id: I698f6fd21c67a1e55429312a0484b6c393cad46f
Diffstat (limited to 'default_device.cpp')
-rw-r--r--default_device.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/default_device.cpp b/default_device.cpp
new file mode 100644
index 00000000..265ed071
--- /dev/null
+++ b/default_device.cpp
@@ -0,0 +1,92 @@
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
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}