Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 1 | /* |
| 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 Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 19 | #include <android-base/logging.h> |
| 20 | #include <android-base/macros.h> |
| 21 | |
Tao Bao | c16fd8a | 2018-04-30 17:12:03 -0700 | [diff] [blame] | 22 | #include "ui.h" |
| 23 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 24 | // clang-format off |
| 25 | static constexpr const char* kItems[]{ |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 26 | "Reboot system now", |
| 27 | "Reboot to bootloader", |
| 28 | "Apply update from ADB", |
| 29 | "Apply update from SD card", |
| 30 | "Wipe data/factory reset", |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 31 | #ifndef AB_OTA_UPDATER |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 32 | "Wipe cache partition", |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 33 | #endif // !AB_OTA_UPDATER |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 34 | "Mount /system", |
| 35 | "View recovery logs", |
| 36 | "Run graphics test", |
| 37 | "Run locale test", |
| 38 | "Power off", |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 39 | }; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 40 | // clang-format on |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 41 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 42 | // clang-format off |
| 43 | static constexpr Device::BuiltinAction kMenuActions[] { |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 44 | Device::REBOOT, |
| 45 | Device::REBOOT_BOOTLOADER, |
| 46 | Device::APPLY_ADB_SIDELOAD, |
| 47 | Device::APPLY_SDCARD, |
| 48 | Device::WIPE_DATA, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 49 | #ifndef AB_OTA_UPDATER |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 50 | Device::WIPE_CACHE, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 51 | #endif // !AB_OTA_UPDATER |
Tianjie Xu | 29d5575 | 2017-09-20 17:53:46 -0700 | [diff] [blame] | 52 | Device::MOUNT_SYSTEM, |
| 53 | Device::VIEW_RECOVERY_LOGS, |
| 54 | Device::RUN_GRAPHICS_TEST, |
| 55 | Device::RUN_LOCALE_TEST, |
| 56 | Device::SHUTDOWN, |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 57 | }; |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 58 | // clang-format on |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 59 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 60 | static_assert(arraysize(kItems) == arraysize(kMenuActions), |
| 61 | "kItems and kMenuActions should have the same length."); |
Elliott Hughes | 01fcbe1 | 2016-05-23 17:43:41 -0700 | [diff] [blame] | 62 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 63 | static const std::vector<std::string> kMenuItems(kItems, kItems + arraysize(kItems)); |
| 64 | |
| 65 | const std::vector<std::string>& Device::GetMenuItems() { |
| 66 | return kMenuItems; |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 67 | } |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 68 | |
Tao Bao | 1fe1afe | 2018-05-01 15:56:05 -0700 | [diff] [blame] | 69 | Device::BuiltinAction Device::InvokeMenuItem(size_t menu_position) { |
| 70 | // CHECK_LT(menu_position, ); |
| 71 | return kMenuActions[menu_position]; |
Elliott Hughes | 9e7ae8a | 2015-04-09 13:40:31 -0700 | [diff] [blame] | 72 | } |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 73 | |
Tao Bao | fc5499f | 2017-02-23 19:06:53 -0800 | [diff] [blame] | 74 | int Device::HandleMenuKey(int key, bool visible) { |
Elliott Hughes | 4af215b | 2015-04-10 15:00:34 -0700 | [diff] [blame] | 75 | 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 | } |