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