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 | |
Elliott Hughes | c51ac89 | 2015-03-20 18:22:15 -0700 | [diff] [blame] | 23 | static const char* HEADERS[] = { |
| 24 | "Volume up/down to move highlight.", |
| 25 | "Power button to select.", |
| 26 | "", |
| 27 | NULL |
| 28 | }; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 29 | |
Elliott Hughes | c51ac89 | 2015-03-20 18:22:15 -0700 | [diff] [blame] | 30 | static const char* ITEMS[] = { |
| 31 | "Reboot system now", |
| 32 | "Reboot to bootloader", |
| 33 | "Apply update from ADB", |
| 34 | "Apply update from SD card", |
| 35 | "Wipe data/factory reset", |
| 36 | "Wipe cache partition", |
| 37 | "View recovery logs", |
| 38 | "Power off", |
| 39 | NULL |
| 40 | }; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 41 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 42 | class DefaultDevice : public Device { |
| 43 | public: |
| 44 | DefaultDevice() : |
Doug Zongker | 02abde5 | 2014-04-01 09:45:24 -0700 | [diff] [blame] | 45 | ui(new ScreenRecoveryUI) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | RecoveryUI* GetUI() { return ui; } |
| 49 | |
| 50 | int HandleMenuKey(int key, int visible) { |
| 51 | if (visible) { |
| 52 | switch (key) { |
| 53 | case KEY_DOWN: |
| 54 | case KEY_VOLUMEDOWN: |
| 55 | return kHighlightDown; |
| 56 | |
| 57 | case KEY_UP: |
| 58 | case KEY_VOLUMEUP: |
| 59 | return kHighlightUp; |
| 60 | |
| 61 | case KEY_ENTER: |
Doug Zongker | 02abde5 | 2014-04-01 09:45:24 -0700 | [diff] [blame] | 62 | case KEY_POWER: |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 63 | return kInvokeItem; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return kNoAction; |
| 68 | } |
| 69 | |
| 70 | BuiltinAction InvokeMenuItem(int menu_position) { |
| 71 | switch (menu_position) { |
| 72 | case 0: return REBOOT; |
Elliott Hughes | c51ac89 | 2015-03-20 18:22:15 -0700 | [diff] [blame] | 73 | case 1: return REBOOT_BOOTLOADER; |
| 74 | case 2: return APPLY_ADB_SIDELOAD; |
| 75 | case 3: return APPLY_EXT; |
| 76 | case 4: return WIPE_DATA; |
| 77 | case 5: return WIPE_CACHE; |
Nick Kralevich | a9ad032 | 2014-10-22 18:38:48 -0700 | [diff] [blame] | 78 | case 6: return READ_RECOVERY_LASTLOG; |
Elliott Hughes | c51ac89 | 2015-03-20 18:22:15 -0700 | [diff] [blame] | 79 | case 7: return SHUTDOWN; |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 80 | default: return NO_ACTION; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | const char* const* GetMenuHeaders() { return HEADERS; } |
| 85 | const char* const* GetMenuItems() { return ITEMS; } |
| 86 | |
| 87 | private: |
| 88 | RecoveryUI* ui; |
| 89 | }; |
| 90 | |
| 91 | Device* make_device() { |
| 92 | return new DefaultDevice(); |
| 93 | } |