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