Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 19 | #include "common.h" |
| 20 | #include "device.h" |
| 21 | #include "screen_ui.h" |
| 22 | |
| 23 | static const char* HEADERS[] = { "Volume up/down to move highlight;", |
| 24 | "enter button to select.", |
| 25 | "", |
| 26 | NULL }; |
| 27 | |
| 28 | static const char* ITEMS[] = {"reboot system now", |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 29 | "apply update from ADB", |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 30 | "wipe data/factory reset", |
| 31 | "wipe cache partition", |
Doug Zongker | 8d9d3d5 | 2014-04-01 13:20:23 -0700 | [diff] [blame] | 32 | "reboot to bootloader", |
| 33 | "power down", |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 34 | NULL }; |
| 35 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 36 | class DefaultDevice : public Device { |
| 37 | public: |
| 38 | DefaultDevice() : |
Doug Zongker | 02abde5 | 2014-04-01 09:45:24 -0700 | [diff] [blame] | 39 | ui(new ScreenRecoveryUI) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | RecoveryUI* GetUI() { return ui; } |
| 43 | |
| 44 | int HandleMenuKey(int key, int visible) { |
| 45 | if (visible) { |
| 46 | switch (key) { |
| 47 | case KEY_DOWN: |
| 48 | case KEY_VOLUMEDOWN: |
| 49 | return kHighlightDown; |
| 50 | |
| 51 | case KEY_UP: |
| 52 | case KEY_VOLUMEUP: |
| 53 | return kHighlightUp; |
| 54 | |
| 55 | case KEY_ENTER: |
Doug Zongker | 02abde5 | 2014-04-01 09:45:24 -0700 | [diff] [blame] | 56 | case KEY_POWER: |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 57 | return kInvokeItem; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return kNoAction; |
| 62 | } |
| 63 | |
| 64 | BuiltinAction InvokeMenuItem(int menu_position) { |
| 65 | switch (menu_position) { |
| 66 | case 0: return REBOOT; |
Doug Zongker | 9270a20 | 2012-01-09 15:16:13 -0800 | [diff] [blame] | 67 | case 1: return APPLY_ADB_SIDELOAD; |
| 68 | case 2: return WIPE_DATA; |
| 69 | case 3: return WIPE_CACHE; |
Doug Zongker | 8d9d3d5 | 2014-04-01 13:20:23 -0700 | [diff] [blame] | 70 | case 4: return REBOOT_BOOTLOADER; |
| 71 | case 5: return SHUTDOWN; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 72 | default: return NO_ACTION; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | const char* const* GetMenuHeaders() { return HEADERS; } |
| 77 | const char* const* GetMenuItems() { return ITEMS; } |
| 78 | |
| 79 | private: |
| 80 | RecoveryUI* ui; |
| 81 | }; |
| 82 | |
| 83 | Device* make_device() { |
| 84 | return new DefaultDevice(); |
| 85 | } |