blob: 5cf9cc2427da1eb68103546a3b748db1a2000623 [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
Tao Bao1fe1afe2018-05-01 15:56:05 -070019#include <android-base/logging.h>
20#include <android-base/macros.h>
21
Tao Baoc16fd8a2018-04-30 17:12:03 -070022#include "ui.h"
23
Tao Bao1fe1afe2018-05-01 15:56:05 -070024// clang-format off
25static constexpr const char* kItems[]{
Tianjie Xu29d55752017-09-20 17:53:46 -070026 "Reboot system now",
27 "Reboot to bootloader",
28 "Apply update from ADB",
29 "Apply update from SD card",
30 "Wipe data/factory reset",
Alex Deymo4344d632016-08-03 21:03:53 -070031#ifndef AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070032 "Wipe cache partition",
Alex Deymo4344d632016-08-03 21:03:53 -070033#endif // !AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070034 "Mount /system",
35 "View recovery logs",
36 "Run graphics test",
37 "Run locale test",
38 "Power off",
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070039};
Tao Bao1fe1afe2018-05-01 15:56:05 -070040// clang-format on
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070041
Tao Bao1fe1afe2018-05-01 15:56:05 -070042// clang-format off
43static constexpr Device::BuiltinAction kMenuActions[] {
Tianjie Xu29d55752017-09-20 17:53:46 -070044 Device::REBOOT,
45 Device::REBOOT_BOOTLOADER,
46 Device::APPLY_ADB_SIDELOAD,
47 Device::APPLY_SDCARD,
48 Device::WIPE_DATA,
Alex Deymo4344d632016-08-03 21:03:53 -070049#ifndef AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070050 Device::WIPE_CACHE,
Alex Deymo4344d632016-08-03 21:03:53 -070051#endif // !AB_OTA_UPDATER
Tianjie Xu29d55752017-09-20 17:53:46 -070052 Device::MOUNT_SYSTEM,
53 Device::VIEW_RECOVERY_LOGS,
54 Device::RUN_GRAPHICS_TEST,
55 Device::RUN_LOCALE_TEST,
56 Device::SHUTDOWN,
Elliott Hughes01fcbe12016-05-23 17:43:41 -070057};
Tao Bao1fe1afe2018-05-01 15:56:05 -070058// clang-format on
Elliott Hughes01fcbe12016-05-23 17:43:41 -070059
Tao Bao1fe1afe2018-05-01 15:56:05 -070060static_assert(arraysize(kItems) == arraysize(kMenuActions),
61 "kItems and kMenuActions should have the same length.");
Elliott Hughes01fcbe12016-05-23 17:43:41 -070062
Tao Bao1fe1afe2018-05-01 15:56:05 -070063static const std::vector<std::string> kMenuItems(kItems, kItems + arraysize(kItems));
64
65const std::vector<std::string>& Device::GetMenuItems() {
66 return kMenuItems;
Elliott Hughes4af215b2015-04-10 15:00:34 -070067}
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070068
Tao Bao1fe1afe2018-05-01 15:56:05 -070069Device::BuiltinAction Device::InvokeMenuItem(size_t menu_position) {
70 // CHECK_LT(menu_position, );
71 return kMenuActions[menu_position];
Elliott Hughes9e7ae8a2015-04-09 13:40:31 -070072}
Elliott Hughes4af215b2015-04-10 15:00:34 -070073
Tao Baofc5499f2017-02-23 19:06:53 -080074int Device::HandleMenuKey(int key, bool visible) {
Elliott Hughes4af215b2015-04-10 15:00:34 -070075 if (!visible) {
76 return kNoAction;
77 }
78
79 switch (key) {
80 case KEY_DOWN:
81 case KEY_VOLUMEDOWN:
82 return kHighlightDown;
83
84 case KEY_UP:
85 case KEY_VOLUMEUP:
86 return kHighlightUp;
87
88 case KEY_ENTER:
89 case KEY_POWER:
90 return kInvokeItem;
91
92 default:
93 // If you have all of the above buttons, any other buttons
94 // are ignored. Otherwise, any button cycles the highlight.
95 return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
96 }
97}