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                                "reboot to bootloader",
33                                "power down",
34                                "view recovery logs",
35                                NULL };
36 
37 class DefaultDevice : public Device {
38   public:
DefaultDevice()39     DefaultDevice() :
40         ui(new ScreenRecoveryUI) {
41     }
42 
GetUI()43     RecoveryUI* GetUI() { return ui; }
44 
HandleMenuKey(int key,int visible)45     int HandleMenuKey(int key, int visible) {
46         if (visible) {
47             switch (key) {
48               case KEY_DOWN:
49               case KEY_VOLUMEDOWN:
50                 return kHighlightDown;
51 
52               case KEY_UP:
53               case KEY_VOLUMEUP:
54                 return kHighlightUp;
55 
56               case KEY_ENTER:
57               case KEY_POWER:
58                 return kInvokeItem;
59             }
60         }
61 
62         return kNoAction;
63     }
64 
InvokeMenuItem(int menu_position)65     BuiltinAction InvokeMenuItem(int menu_position) {
66         switch (menu_position) {
67           case 0: return REBOOT;
68           case 1: return APPLY_ADB_SIDELOAD;
69           case 2: return WIPE_DATA;
70           case 3: return WIPE_CACHE;
71           case 4: return REBOOT_BOOTLOADER;
72           case 5: return SHUTDOWN;
73           case 6: return READ_RECOVERY_LASTLOG;
74           default: return NO_ACTION;
75         }
76     }
77 
GetMenuHeaders()78     const char* const* GetMenuHeaders() { return HEADERS; }
GetMenuItems()79     const char* const* GetMenuItems() { return ITEMS; }
80 
81   private:
82     RecoveryUI* ui;
83 };
84 
make_device()85 Device* make_device() {
86     return new DefaultDevice();
87 }
88