blob: 024fc3465602b29ed1c36f65eacd94f059241e4b [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* REGULAR_HEADERS[] = {
20 "Volume up/down move highlight.",
21 "Power button activates.",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070022 "",
23 NULL
24};
25
Elliott Hughes4af215b2015-04-10 15:00:34 -070026static const char* LONG_PRESS_HEADERS[] = {
27 "Any button cycles highlight.",
28 "Long-press activates.",
29 "",
30 NULL
31};
32
33static const char* MENU_ITEMS[] = {
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070034 "Reboot system now",
35 "Reboot to bootloader",
36 "Apply update from ADB",
37 "Apply update from SD card",
38 "Wipe data/factory reset",
39 "Wipe cache partition",
Elliott Hughesec283402015-04-10 10:01:53 -070040 "Mount /system",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070041 "View recovery logs",
42 "Power off",
43 NULL
44};
45
Elliott Hughes4af215b2015-04-10 15:00:34 -070046const char* const* Device::GetMenuHeaders() {
47 return ui_->HasThreeButtons() ? REGULAR_HEADERS : LONG_PRESS_HEADERS;
48}
49
50const char* const* Device::GetMenuItems() {
51 return MENU_ITEMS;
52}
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070053
54Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
55 switch (menu_position) {
56 case 0: return REBOOT;
57 case 1: return REBOOT_BOOTLOADER;
58 case 2: return APPLY_ADB_SIDELOAD;
Elliott Hughesec283402015-04-10 10:01:53 -070059 case 3: return APPLY_SDCARD;
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070060 case 4: return WIPE_DATA;
61 case 5: return WIPE_CACHE;
Elliott Hughesec283402015-04-10 10:01:53 -070062 case 6: return MOUNT_SYSTEM;
63 case 7: return VIEW_RECOVERY_LOGS;
64 case 8: return SHUTDOWN;
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070065 default: return NO_ACTION;
66 }
67}
Elliott Hughes4af215b2015-04-10 15:00:34 -070068
69int Device::HandleMenuKey(int key, int visible) {
70 if (!visible) {
71 return kNoAction;
72 }
73
74 switch (key) {
75 case KEY_DOWN:
76 case KEY_VOLUMEDOWN:
77 return kHighlightDown;
78
79 case KEY_UP:
80 case KEY_VOLUMEUP:
81 return kHighlightUp;
82
83 case KEY_ENTER:
84 case KEY_POWER:
85 return kInvokeItem;
86
87 default:
88 // If you have all of the above buttons, any other buttons
89 // are ignored. Otherwise, any button cycles the highlight.
90 return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
91 }
92}