From 1fe1afe863fde957051774cf2d9936c314d342a2 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 1 May 2018 15:56:05 -0700 Subject: Move menu headers/items to std::vector. Test: mmma -j bootable/recovery Test: Run recovery_unit_test on marlin. Test: Build and boot into recovery image on angler. Check the UI that shows menu ('View recovery log', 'Wipe data', 'Run locale test'). Test: Start recovery with '--prompt_and_wipe_data'. Check the UI. Change-Id: If8a4209e0bb4ca64f719f9f9465d3b3589a69cdc --- device.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'device.cpp') diff --git a/device.cpp b/device.cpp index 3b0942c49..5cf9cc242 100644 --- a/device.cpp +++ b/device.cpp @@ -16,9 +16,13 @@ #include "device.h" +#include +#include + #include "ui.h" -static const char* MENU_ITEMS[] = { +// clang-format off +static constexpr const char* kItems[]{ "Reboot system now", "Reboot to bootloader", "Apply update from ADB", @@ -32,10 +36,11 @@ static const char* MENU_ITEMS[] = { "Run graphics test", "Run locale test", "Power off", - nullptr, }; +// clang-format on -static const Device::BuiltinAction MENU_ACTIONS[] = { +// clang-format off +static constexpr Device::BuiltinAction kMenuActions[] { Device::REBOOT, Device::REBOOT_BOOTLOADER, Device::APPLY_ADB_SIDELOAD, @@ -50,18 +55,20 @@ static const Device::BuiltinAction MENU_ACTIONS[] = { Device::RUN_LOCALE_TEST, Device::SHUTDOWN, }; +// clang-format on + +static_assert(arraysize(kItems) == arraysize(kMenuActions), + "kItems and kMenuActions should have the same length."); -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 const std::vector kMenuItems(kItems, kItems + arraysize(kItems)); -const char* const* Device::GetMenuItems() { - return MENU_ITEMS; +const std::vector& Device::GetMenuItems() { + return kMenuItems; } -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) { + // CHECK_LT(menu_position, ); + return kMenuActions[menu_position]; } int Device::HandleMenuKey(int key, bool visible) { -- cgit v1.2.3