1 /* 2 * Copyright 2012 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 "wipe data/factory reset", 34 "wipe cache partition", 35 NULL }; 36 37 class DebUI : public ScreenRecoveryUI 38 { 39 public: 40 DebUI() : 41 consecutive_power_keys(0) { 42 } 43 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 DebDevice : public Device 64 { 65 public: 66 DebDevice() : 67 ui(new DebUI) { 68 } 69 70 RecoveryUI* GetUI() { return ui; } 71 72 int HandleMenuKey(int key_code, int visible) { 73 if (visible) { 74 switch (key_code) { 75 case KEY_DOWN: 76 case KEY_VOLUMEDOWN: 77 return kHighlightDown; 78 79 case KEY_UP: 80 case KEY_VOLUMEUP: 81 return kHighlightUp; 82 83 case KEY_POWER: 84 return kInvokeItem; 85 } 86 } 87 88 return kNoAction; 89 } 90 91 BuiltinAction InvokeMenuItem(int menu_position) { 92 switch (menu_position) { 93 case 0: return REBOOT; 94 case 1: return APPLY_ADB_SIDELOAD; 95 case 2: return WIPE_DATA; 96 case 3: return WIPE_CACHE; 97 default: return NO_ACTION; 98 } 99 } 100 101 const char* const* GetMenuHeaders() { return HEADERS; } 102 const char* const* GetMenuItems() { return ITEMS; } 103 104 private: 105 RecoveryUI* ui; 106 }; 107 108 Device* make_device() { 109 return new DebDevice; 110 } 111