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 <linux/input.h> 18 #include <sys/stat.h> 19 #include <errno.h> 20 #include <string.h> 21 22 #include "recovery_ui.h" 23 #include "common.h" 24 25 char* MENU_HEADERS[] = { "Volume up/down to move highlight;", 26 "power button to select.", 27 "", 28 NULL }; 29 30 char* MENU_ITEMS[] = { "reboot system now", 31 "apply update from /cache", 32 "wipe data/factory reset", 33 "wipe cache partition", 34 NULL }; 35 36 void device_ui_init(UIParameters* ui_parameters) { 37 } 38 39 int device_recovery_start() { 40 // recovery can get started before the kernel has created the EMMC 41 // devices, which will make the wipe_data operation fail (trying 42 // to open a device that doesn't exist). Hold up the start of 43 // recovery for up to 5 seconds waiting for the userdata partition 44 // block device to exist. 45 46 const char* fn = "/dev/block/platform/omap/omap_hsmmc.0/by-name/userdata"; 47 48 int tries = 0; 49 int ret; 50 struct stat buf; 51 do { 52 ++tries; 53 ret = stat(fn, &buf); 54 if (ret) { 55 printf("try %d: %s\n", tries, strerror(errno)); 56 sleep(1); 57 } 58 } while (ret && tries < 5); 59 if (!ret) { 60 printf("stat() of %s succeeded on try %d\n", fn, tries); 61 } else { 62 printf("failed to stat %s\n", fn); 63 } 64 65 // We let recovery attempt to carry on even if the stat never 66 // succeeded. 67 68 return 0; 69 } 70 71 int device_toggle_display(volatile char* key_pressed, int key_code) { 72 // hold power and press volume-up 73 return key_pressed[KEY_POWER] && key_code == KEY_VOLUMEUP; 74 } 75 76 int device_reboot_now(volatile char* key_pressed, int key_code) { 77 // Reboot if the power key is pressed five times in a row, with 78 // no other keys in between. 79 static int presses = 0; 80 if (key_code == KEY_POWER) { // power button 81 ++presses; 82 return presses == 5; 83 } else { 84 presses = 0; 85 return 0; 86 } 87 } 88 89 int device_handle_key(int key_code, int visible) { 90 if (visible) { 91 switch (key_code) { 92 case KEY_DOWN: 93 case KEY_VOLUMEDOWN: 94 return HIGHLIGHT_DOWN; 95 96 case KEY_UP: 97 case KEY_VOLUMEUP: 98 return HIGHLIGHT_UP; 99 100 case KEY_ENTER: 101 case KEY_POWER: // crespo power 102 return SELECT_ITEM; 103 } 104 } 105 106 return NO_ACTION; 107 } 108 109 int device_perform_action(int which) { 110 return which == 1 ? ITEM_APPLY_CACHE : which; 111 } 112 113 int device_wipe_data() { 114 return 0; 115 } 116