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", |
| 25 | "Wipe cache partition", |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 26 | "Mount /system", |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 27 | "View recovery logs", |
| 28 | "Power off", |
| 29 | NULL |
| 30 | }; |
| 31 | |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 32 | const char* const* Device::GetMenuItems() { |
| 33 | return MENU_ITEMS; |
| 34 | } |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 35 | |
| 36 | Device::BuiltinAction Device::InvokeMenuItem(int menu_position) { |
| 37 | switch (menu_position) { |
| 38 | case 0: return REBOOT; |
| 39 | case 1: return REBOOT_BOOTLOADER; |
| 40 | case 2: return APPLY_ADB_SIDELOAD; |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 41 | case 3: return APPLY_SDCARD; |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 42 | case 4: return WIPE_DATA; |
| 43 | case 5: return WIPE_CACHE; |
Elliott Hughes | ec28340 | 2015-04-10 10:01:53 -0700 | [diff] [blame] | 44 | case 6: return MOUNT_SYSTEM; |
| 45 | case 7: return VIEW_RECOVERY_LOGS; |
| 46 | case 8: return SHUTDOWN; |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 47 | default: return NO_ACTION; |
| 48 | } |
| 49 | } |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 50 | |
| 51 | int Device::HandleMenuKey(int key, int visible) { |
| 52 | if (!visible) { |
| 53 | return kNoAction; |
| 54 | } |
| 55 | |
| 56 | switch (key) { |
| 57 | case KEY_DOWN: |
| 58 | case KEY_VOLUMEDOWN: |
| 59 | return kHighlightDown; |
| 60 | |
| 61 | case KEY_UP: |
| 62 | case KEY_VOLUMEUP: |
| 63 | return kHighlightUp; |
| 64 | |
| 65 | case KEY_ENTER: |
| 66 | case KEY_POWER: |
| 67 | return kInvokeItem; |
| 68 | |
| 69 | default: |
| 70 | // If you have all of the above buttons, any other buttons |
| 71 | // are ignored. Otherwise, any button cycles the highlight. |
| 72 | return ui_->HasThreeButtons() ? kNoAction : kHighlightDown; |
| 73 | } |
| 74 | } |