blob: f881daff63f7a7c5381d3e3ee4f1f8dc39cede93 [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[] = {
Tianjie Xu29d55752017-09-20 17:53:46 -070020 "Reboot system now",
21 "Reboot to bootloader",
22 "Apply update from ADB",
23 "Apply update from SD card",
24 "Wipe data/factory reset",
Alex Deymo4344d632016-08-03 21:03:53 -070025#ifndef AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070026 "Wipe cache partition",
Alex Deymo4344d632016-08-03 21:03:53 -070027#endif // !AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070028 "Mount /system",
29 "View recovery logs",
30 "Run graphics test",
31 "Run locale test",
32 "Power off",
33 nullptr,
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070034};
35
Elliott Hughes01fcbe12016-05-23 17:43:41 -070036static const Device::BuiltinAction MENU_ACTIONS[] = {
Tianjie Xu29d55752017-09-20 17:53:46 -070037 Device::REBOOT,
38 Device::REBOOT_BOOTLOADER,
39 Device::APPLY_ADB_SIDELOAD,
40 Device::APPLY_SDCARD,
41 Device::WIPE_DATA,
Alex Deymo4344d632016-08-03 21:03:53 -070042#ifndef AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070043 Device::WIPE_CACHE,
Alex Deymo4344d632016-08-03 21:03:53 -070044#endif // !AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070045 Device::MOUNT_SYSTEM,
46 Device::VIEW_RECOVERY_LOGS,
47 Device::RUN_GRAPHICS_TEST,
48 Device::RUN_LOCALE_TEST,
49 Device::SHUTDOWN,
Elliott Hughes01fcbe12016-05-23 17:43:41 -070050};
51
Alex Deymo4344d632016-08-03 21:03:53 -070052static_assert(sizeof(MENU_ITEMS) / sizeof(MENU_ITEMS[0]) ==
53 sizeof(MENU_ACTIONS) / sizeof(MENU_ACTIONS[0]) + 1,
54 "MENU_ITEMS and MENU_ACTIONS should have the same length, "
55 "except for the extra NULL entry in MENU_ITEMS.");
Elliott Hughes01fcbe12016-05-23 17:43:41 -070056
Elliott Hughes4af215b2015-04-10 15:00:34 -070057const char* const* Device::GetMenuItems() {
58 return MENU_ITEMS;
59}
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070060
61Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
Elliott Hughes01fcbe12016-05-23 17:43:41 -070062 return menu_position < 0 ? NO_ACTION : MENU_ACTIONS[menu_position];
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070063}
Elliott Hughes4af215b2015-04-10 15:00:34 -070064
Tao Baofc5499f2017-02-23 19:06:53 -080065int Device::HandleMenuKey(int key, bool visible) {
Elliott Hughes4af215b2015-04-10 15:00:34 -070066 if (!visible) {
67 return kNoAction;
68 }
69
70 switch (key) {
71 case KEY_DOWN:
72 case KEY_VOLUMEDOWN:
73 return kHighlightDown;
74
75 case KEY_UP:
76 case KEY_VOLUMEUP:
77 return kHighlightUp;
78
79 case KEY_ENTER:
80 case KEY_POWER:
81 return kInvokeItem;
82
83 default:
84 // If you have all of the above buttons, any other buttons
85 // are ignored. Otherwise, any button cycles the highlight.
86 return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
87 }
88}