1 /* 2 * Copyright (C) 2011 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 <string.h> 18 #include <linux/input.h> 19 #include <cutils/properties.h> 20 21 #include "common.h" 22 #include "device.h" 23 #include "screen_ui.h" 24 25 extern "C" { 26 int bp_master_clear(void); 27 } 28 29 const char* HEADERS[] = { "Use volume keys to highlight; power button to select.", 30 "", 31 NULL }; 32 33 const char* ITEMS[] = { "reboot system now", 34 "apply update from ADB", 35 "apply update from USB drive", 36 "wipe data/factory reset", 37 "wipe cache partition", 38 NULL }; 39 40 // On stingray, the power key shows up as KEY_END. 41 42 class StingrayUI : public ScreenRecoveryUI { 43 public: 44 StingrayUI() : 45 consecutive_power_keys(0) { 46 } 47 48 virtual KeyAction CheckKey(int key) { 49 if (IsKeyPressed(KEY_END) && key == KEY_VOLUMEUP) { 50 return TOGGLE; 51 } 52 if (key == KEY_POWER) { 53 ++consecutive_power_keys; 54 if (consecutive_power_keys >= 7) { 55 return REBOOT; 56 } 57 } else { 58 consecutive_power_keys = 0; 59 } 60 return ENQUEUE; 61 } 62 63 private: 64 int consecutive_power_keys; 65 }; 66 67 class StingrayDevice : public Device { 68 public: 69 StingrayDevice() : 70 ui(new StingrayUI) { 71 } 72 73 RecoveryUI* GetUI() { return ui; } 74 75 int HandleMenuKey(int key_code, int visible) { 76 if (visible) { 77 switch (key_code) { 78 case KEY_DOWN: 79 case KEY_VOLUMEDOWN: 80 return kHighlightDown; 81 82 case KEY_UP: 83 case KEY_VOLUMEUP: 84 return kHighlightUp; 85 86 case KEY_END: 87 return kInvokeItem; 88 } 89 } 90 91 return kNoAction; 92 } 93 94 BuiltinAction InvokeMenuItem(int menu_position) { 95 switch (menu_position) { 96 case 0: return REBOOT; 97 case 1: return APPLY_ADB_SIDELOAD; 98 case 2: return APPLY_EXT; 99 case 3: return WIPE_DATA; 100 case 4: return WIPE_CACHE; 101 default: return NO_ACTION; 102 } 103 } 104 105 const char* const* GetMenuHeaders() { return HEADERS; } 106 const char* const* GetMenuItems() { return ITEMS; } 107 108 int WipeData() { 109 if (device_has_bp()) { 110 ui->Print("Performing BP clear...\n"); 111 if (bp_master_clear() == 0) { 112 ui->Print("BP clear complete successfully.\n"); 113 } else { 114 ui->Print("BP clear failed.\n"); 115 } 116 } 117 return 0; 118 } 119 120 private: 121 RecoveryUI* ui; 122 123 bool device_has_bp(void) { 124 char value[PROPERTY_VALUE_MAX]; 125 126 property_get("ro.carrier", value, ""); 127 if (strcmp("wifi-only", value) == 0) 128 return false; 129 else 130 return true; 131 } 132 }; 133 134 Device* make_device() { 135 return new StingrayDevice; 136 } 137