blob: f8fbb8a4964fa274a2f470160bfd65b131ce231d [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 Hughes01fcbe12016-05-23 17:43:41 -070019#if defined(AB_OTA_UPDATER)
20
21static 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
31static 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 Hughes4af215b2015-04-10 15:00:34 -070042static const char* MENU_ITEMS[] = {
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070043 "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 Hughesec283402015-04-10 10:01:53 -070049 "Mount /system",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070050 "View recovery logs",
Elliott Hughes498cda62016-04-14 16:49:04 -070051 "Run graphics test",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070052 "Power off",
Elliott Hughes01fcbe12016-05-23 17:43:41 -070053 NULL,
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070054};
55
Elliott Hughes01fcbe12016-05-23 17:43:41 -070056static 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 Hughes4af215b2015-04-10 15:00:34 -070071const char* const* Device::GetMenuItems() {
72 return MENU_ITEMS;
73}
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070074
75Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
Elliott Hughes01fcbe12016-05-23 17:43:41 -070076 return menu_position < 0 ? NO_ACTION : MENU_ACTIONS[menu_position];
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070077}
Elliott Hughes4af215b2015-04-10 15:00:34 -070078
79int 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}