Home | History | Annotate | Download | only in recovery
      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 "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 USB drive",
     34                         "wipe data/factory reset",
     35                         "wipe cache partition",
     36                         NULL };
     37 
     38 class TunaUI : public ScreenRecoveryUI {
     39   public:
     40     TunaUI() :
     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 
     64 class TunaDevice : public Device {
     65   public:
     66     TunaDevice() :
     67         ui(new TunaUI) {
     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 APPLY_EXT;
     96           case 3: return WIPE_DATA;
     97           case 4: return WIPE_CACHE;
     98           default: return NO_ACTION;
     99         }
    100     }
    101 
    102     const char* const* GetMenuHeaders() { return HEADERS; }
    103     const char* const* GetMenuItems() { return ITEMS; }
    104 
    105   private:
    106     RecoveryUI* ui;
    107 };
    108 
    109 Device* make_device() {
    110     return new TunaDevice;
    111 }
    112