• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 #include <sys/stat.h>
19 #include <errno.h>
20 #include <string.h>
21 
22 #include "common.h"
23 #include "device.h"
24 #include "screen_ui.h"
25 
26 const char* HEADERS[] = { "Volume up/down to move highlight;",
27                           "power button to select.",
28                           "",
29                           NULL };
30 
31 const char* ITEMS[] = { "reboot system now",
32                         "apply update from ADB",
33                         "apply update from /sdcard",
34                         "wipe data/factory reset",
35                         "wipe cache partition",
36                         NULL };
37 
38 class CrespoUI : public ScreenRecoveryUI {
39   public:
CrespoUI()40     CrespoUI() :
41         consecutive_power_keys(0) {
42     }
43 
CheckKey(int key)44     virtual KeyAction CheckKey(int key) {
45         if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) {
46             return TOGGLE;
47         }
48         if (key == KEY_POWER) {
49             ++consecutive_power_keys;
50             if (consecutive_power_keys >= 7) {
51                 return REBOOT;
52             }
53         } else {
54             consecutive_power_keys = 0;
55         }
56         return ENQUEUE;
57     }
58 
59   private:
60     int consecutive_power_keys;
61 };
62 
63 class CrespoDevice : public Device {
64   public:
CrespoDevice()65     CrespoDevice() :
66         ui(new CrespoUI) {
67     }
68 
GetUI()69     RecoveryUI* GetUI() { return ui; }
70 
HandleMenuKey(int key_code,int visible)71     int HandleMenuKey(int key_code, int visible) {
72         if (visible) {
73             switch (key_code) {
74               case KEY_DOWN:
75               case KEY_VOLUMEDOWN:
76                 return kHighlightDown;
77 
78               case KEY_UP:
79               case KEY_VOLUMEUP:
80                 return kHighlightUp;
81 
82               case KEY_POWER:
83                 return kInvokeItem;
84             }
85         }
86 
87         return kNoAction;
88     }
89 
InvokeMenuItem(int menu_position)90     BuiltinAction InvokeMenuItem(int menu_position) {
91         switch (menu_position) {
92           case 0: return REBOOT;
93           case 1: return APPLY_ADB_SIDELOAD;
94           case 2: return APPLY_EXT;
95           case 3: return WIPE_DATA;
96           case 4: return WIPE_CACHE;
97           default: return NO_ACTION;
98         }
99     }
100 
GetMenuHeaders()101     const char* const* GetMenuHeaders() { return HEADERS; }
GetMenuItems()102     const char* const* GetMenuItems() { return ITEMS; }
103 
104   private:
105     RecoveryUI* ui;
106 };
107 
make_device()108 Device* make_device() {
109     return new CrespoDevice;
110 }
111