summaryrefslogtreecommitdiffstats
path: root/device.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--device.cpp84
1 files changed, 46 insertions, 38 deletions
diff --git a/device.cpp b/device.cpp
index f881daff6..eec1932c2 100644
--- a/device.cpp
+++ b/device.cpp
@@ -16,50 +16,58 @@
#include "device.h"
-static const char* MENU_ITEMS[] = {
- "Reboot system now",
- "Reboot to bootloader",
- "Apply update from ADB",
- "Apply update from SD card",
- "Wipe data/factory reset",
-#ifndef AB_OTA_UPDATER
- "Wipe cache partition",
-#endif // !AB_OTA_UPDATER
- "Mount /system",
- "View recovery logs",
- "Run graphics test",
- "Run locale test",
- "Power off",
- nullptr,
-};
+#include <algorithm>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <android-base/logging.h>
+
+#include "ui.h"
-static const Device::BuiltinAction MENU_ACTIONS[] = {
- Device::REBOOT,
- Device::REBOOT_BOOTLOADER,
- Device::APPLY_ADB_SIDELOAD,
- Device::APPLY_SDCARD,
- Device::WIPE_DATA,
-#ifndef AB_OTA_UPDATER
- Device::WIPE_CACHE,
-#endif // !AB_OTA_UPDATER
- Device::MOUNT_SYSTEM,
- Device::VIEW_RECOVERY_LOGS,
- Device::RUN_GRAPHICS_TEST,
- Device::RUN_LOCALE_TEST,
- Device::SHUTDOWN,
+static std::vector<std::pair<std::string, Device::BuiltinAction>> g_menu_actions{
+ { "Reboot system now", Device::REBOOT },
+ { "Reboot to bootloader", Device::REBOOT_BOOTLOADER },
+ { "Enter fastboot", Device::ENTER_FASTBOOT },
+ { "Apply update from ADB", Device::APPLY_ADB_SIDELOAD },
+ { "Apply update from SD card", Device::APPLY_SDCARD },
+ { "Wipe data/factory reset", Device::WIPE_DATA },
+ { "Wipe cache partition", Device::WIPE_CACHE },
+ { "Mount /system", Device::MOUNT_SYSTEM },
+ { "View recovery logs", Device::VIEW_RECOVERY_LOGS },
+ { "Run graphics test", Device::RUN_GRAPHICS_TEST },
+ { "Run locale test", Device::RUN_LOCALE_TEST },
+ { "Power off", Device::SHUTDOWN },
};
-static_assert(sizeof(MENU_ITEMS) / sizeof(MENU_ITEMS[0]) ==
- sizeof(MENU_ACTIONS) / sizeof(MENU_ACTIONS[0]) + 1,
- "MENU_ITEMS and MENU_ACTIONS should have the same length, "
- "except for the extra NULL entry in MENU_ITEMS.");
+static std::vector<std::string> g_menu_items;
+
+static void PopulateMenuItems() {
+ g_menu_items.clear();
+ std::transform(g_menu_actions.cbegin(), g_menu_actions.cend(), std::back_inserter(g_menu_items),
+ [](const auto& entry) { return entry.first; });
+}
+
+Device::Device(RecoveryUI* ui) : ui_(ui) {
+ PopulateMenuItems();
+}
+
+void Device::RemoveMenuItemForAction(Device::BuiltinAction action) {
+ g_menu_actions.erase(
+ std::remove_if(g_menu_actions.begin(), g_menu_actions.end(),
+ [action](const auto& entry) { return entry.second == action; }));
+ CHECK(!g_menu_actions.empty());
+
+ // Re-populate the menu items.
+ PopulateMenuItems();
+}
-const char* const* Device::GetMenuItems() {
- return MENU_ITEMS;
+const std::vector<std::string>& Device::GetMenuItems() {
+ return g_menu_items;
}
-Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
- return menu_position < 0 ? NO_ACTION : MENU_ACTIONS[menu_position];
+Device::BuiltinAction Device::InvokeMenuItem(size_t menu_position) {
+ return g_menu_actions[menu_position].second;
}
int Device::HandleMenuKey(int key, bool visible) {