blob: 2465b077897e9d1051157634a5614cf91215bf36 [file] [log] [blame]
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -07001/*
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 Hughes4af215b2015-04-10 15:00:34 -070019static const char* MENU_ITEMS[] = {
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070020 "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 Hughesec283402015-04-10 10:01:53 -070026 "Mount /system",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070027 "View recovery logs",
Elliott Hughes498cda62016-04-14 16:49:04 -070028 "Run graphics test",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070029 "Power off",
30 NULL
31};
32
Elliott Hughes4af215b2015-04-10 15:00:34 -070033const char* const* Device::GetMenuItems() {
34 return MENU_ITEMS;
35}
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070036
37Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
38 switch (menu_position) {
39 case 0: return REBOOT;
40 case 1: return REBOOT_BOOTLOADER;
41 case 2: return APPLY_ADB_SIDELOAD;
Elliott Hughesec283402015-04-10 10:01:53 -070042 case 3: return APPLY_SDCARD;
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070043 case 4: return WIPE_DATA;
44 case 5: return WIPE_CACHE;
Elliott Hughesec283402015-04-10 10:01:53 -070045 case 6: return MOUNT_SYSTEM;
46 case 7: return VIEW_RECOVERY_LOGS;
Elliott Hughes498cda62016-04-14 16:49:04 -070047 case 8: return RUN_GRAPHICS_TEST;
48 case 9: return SHUTDOWN;
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070049 default: return NO_ACTION;
50 }
51}
Elliott Hughes4af215b2015-04-10 15:00:34 -070052
53int Device::HandleMenuKey(int key, int visible) {
54 if (!visible) {
55 return kNoAction;
56 }
57
58 switch (key) {
59 case KEY_DOWN:
60 case KEY_VOLUMEDOWN:
61 return kHighlightDown;
62
63 case KEY_UP:
64 case KEY_VOLUMEUP:
65 return kHighlightUp;
66
67 case KEY_ENTER:
68 case KEY_POWER:
69 return kInvokeItem;
70
71 default:
72 // If you have all of the above buttons, any other buttons
73 // are ignored. Otherwise, any button cycles the highlight.
74 return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
75 }
76}