Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "device.h" |
| 18 | |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 19 | static const char* MENU_ITEMS[] = { |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 20 | "Reboot system now", |
| 21 | "Reboot to bootloader", |
| 22 | "Apply update from ADB", |
| 23 | "Apply update from SD card", |
| 24 | "Wipe data/factory reset", |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 25 | #ifndef AB_OTA_UPDATER |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 26 | "Wipe cache partition", |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 27 | #endif // !AB_OTA_UPDATER |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 28 | "Mount /system", |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 29 | "View recovery logs", |
Elliott Hughes | 498cda6 | 2016-04-14 16:49:04 -0700 | [diff] [blame] | 30 | "Run graphics test", |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 31 | "Power off", |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 32 | NULL, |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 35 | static const Device::BuiltinAction MENU_ACTIONS[] = { |
| 36 | Device::REBOOT, |
| 37 | Device::REBOOT_BOOTLOADER, |
| 38 | Device::APPLY_ADB_SIDELOAD, |
| 39 | Device::APPLY_SDCARD, |
| 40 | Device::WIPE_DATA, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 41 | #ifndef AB_OTA_UPDATER |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 42 | Device::WIPE_CACHE, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 43 | #endif // !AB_OTA_UPDATER |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 44 | Device::MOUNT_SYSTEM, |
| 45 | Device::VIEW_RECOVERY_LOGS, |
| 46 | Device::RUN_GRAPHICS_TEST, |
| 47 | Device::SHUTDOWN, |
| 48 | }; |
| 49 | |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 50 | static_assert(sizeof(MENU_ITEMS) / sizeof(MENU_ITEMS[0]) == |
| 51 | sizeof(MENU_ACTIONS) / sizeof(MENU_ACTIONS[0]) + 1, |
| 52 | "MENU_ITEMS and MENU_ACTIONS should have the same length, " |
| 53 | "except for the extra NULL entry in MENU_ITEMS."); |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 54 | |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 55 | const char* const* Device::GetMenuItems() { |
| 56 | return MENU_ITEMS; |
| 57 | } |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 58 | |
| 59 | Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 60 | return menu_position < 0 ? NO_ACTION : MENU_ACTIONS[menu_position]; |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 61 | } |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 62 | |
| 63 | int Device::HandleMenuKey(int key, int visible) { |
| 64 | if (!visible) { |
| 65 | return kNoAction; |
| 66 | } |
| 67 | |
| 68 | switch (key) { |
| 69 | case KEY_DOWN: |
| 70 | case KEY_VOLUMEDOWN: |
| 71 | return kHighlightDown; |
| 72 | |
| 73 | case KEY_UP: |
| 74 | case KEY_VOLUMEUP: |
| 75 | return kHighlightUp; |
| 76 | |
| 77 | case KEY_ENTER: |
| 78 | case KEY_POWER: |
| 79 | return kInvokeItem; |
| 80 | |
| 81 | default: |
| 82 | // If you have all of the above buttons, any other buttons |
| 83 | // are ignored. Otherwise, any button cycles the highlight. |
| 84 | return ui_->HasThreeButtons() ? kNoAction : kHighlightDown; |
| 85 | } |
| 86 | } |