Merge "recovery: Configure device menu based on runtime info."
This commit is contained in:
@@ -185,10 +185,6 @@ LOCAL_STATIC_LIBRARIES := \
|
|||||||
|
|
||||||
LOCAL_HAL_STATIC_LIBRARIES := libhealthd
|
LOCAL_HAL_STATIC_LIBRARIES := libhealthd
|
||||||
|
|
||||||
ifeq ($(AB_OTA_UPDATER),true)
|
|
||||||
LOCAL_CFLAGS += -DAB_OTA_UPDATER=1
|
|
||||||
endif
|
|
||||||
|
|
||||||
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
|
LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin
|
||||||
|
|
||||||
ifeq ($(BOARD_CACHEIMAGE_PARTITION_SIZE),)
|
ifeq ($(BOARD_CACHEIMAGE_PARTITION_SIZE),)
|
||||||
|
|||||||
78
device.cpp
78
device.cpp
@@ -16,59 +16,57 @@
|
|||||||
|
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/macros.h>
|
|
||||||
|
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
// clang-format off
|
static std::vector<std::pair<std::string, Device::BuiltinAction>> g_menu_actions{
|
||||||
static constexpr const char* kItems[]{
|
{ "Reboot system now", Device::REBOOT },
|
||||||
"Reboot system now",
|
{ "Reboot to bootloader", Device::REBOOT_BOOTLOADER },
|
||||||
"Reboot to bootloader",
|
{ "Apply update from ADB", Device::APPLY_ADB_SIDELOAD },
|
||||||
"Apply update from ADB",
|
{ "Apply update from SD card", Device::APPLY_SDCARD },
|
||||||
"Apply update from SD card",
|
{ "Wipe data/factory reset", Device::WIPE_DATA },
|
||||||
"Wipe data/factory reset",
|
{ "Wipe cache partition", Device::WIPE_CACHE },
|
||||||
#ifndef AB_OTA_UPDATER
|
{ "Mount /system", Device::MOUNT_SYSTEM },
|
||||||
"Wipe cache partition",
|
{ "View recovery logs", Device::VIEW_RECOVERY_LOGS },
|
||||||
#endif // !AB_OTA_UPDATER
|
{ "Run graphics test", Device::RUN_GRAPHICS_TEST },
|
||||||
"Mount /system",
|
{ "Run locale test", Device::RUN_LOCALE_TEST },
|
||||||
"View recovery logs",
|
{ "Power off", Device::SHUTDOWN },
|
||||||
"Run graphics test",
|
|
||||||
"Run locale test",
|
|
||||||
"Power off",
|
|
||||||
};
|
};
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
// clang-format off
|
static std::vector<std::string> g_menu_items;
|
||||||
static constexpr Device::BuiltinAction kMenuActions[] {
|
|
||||||
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,
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
static_assert(arraysize(kItems) == arraysize(kMenuActions),
|
static void PopulateMenuItems() {
|
||||||
"kItems and kMenuActions should have the same length.");
|
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; });
|
||||||
|
}
|
||||||
|
|
||||||
static const std::vector<std::string> kMenuItems(kItems, kItems + arraysize(kItems));
|
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 std::vector<std::string>& Device::GetMenuItems() {
|
const std::vector<std::string>& Device::GetMenuItems() {
|
||||||
return kMenuItems;
|
return g_menu_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::BuiltinAction Device::InvokeMenuItem(size_t menu_position) {
|
Device::BuiltinAction Device::InvokeMenuItem(size_t menu_position) {
|
||||||
// CHECK_LT(menu_position, );
|
return g_menu_actions[menu_position].second;
|
||||||
return kMenuActions[menu_position];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::HandleMenuKey(int key, bool visible) {
|
int Device::HandleMenuKey(int key, bool visible) {
|
||||||
|
|||||||
6
device.h
6
device.h
@@ -49,7 +49,7 @@ class Device {
|
|||||||
RUN_LOCALE_TEST = 12,
|
RUN_LOCALE_TEST = 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Device(RecoveryUI* ui) : ui_(ui) {}
|
explicit Device(RecoveryUI* ui);
|
||||||
virtual ~Device() {}
|
virtual ~Device() {}
|
||||||
|
|
||||||
// Returns a raw pointer to the RecoveryUI object.
|
// Returns a raw pointer to the RecoveryUI object.
|
||||||
@@ -96,6 +96,10 @@ class Device {
|
|||||||
// here and return NO_ACTION.
|
// here and return NO_ACTION.
|
||||||
virtual BuiltinAction InvokeMenuItem(size_t menu_position);
|
virtual BuiltinAction InvokeMenuItem(size_t menu_position);
|
||||||
|
|
||||||
|
// Removes the menu item for the given action. This allows tailoring the menu based on the
|
||||||
|
// runtime info, such as the availability of /cache or /sdcard.
|
||||||
|
virtual void RemoveMenuItemForAction(Device::BuiltinAction action);
|
||||||
|
|
||||||
// Called before and after we do a wipe data/factory reset operation, either via a reboot from the
|
// Called before and after we do a wipe data/factory reset operation, either via a reboot from the
|
||||||
// main system with the --wipe_data flag, or when the user boots into recovery image manually and
|
// main system with the --wipe_data flag, or when the user boots into recovery image manually and
|
||||||
// selects the option from the menu, to perform whatever device-specific wiping actions as needed.
|
// selects the option from the menu, to perform whatever device-specific wiping actions as needed.
|
||||||
|
|||||||
@@ -1182,6 +1182,10 @@ int start_recovery(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
ui = device->GetUI();
|
ui = device->GetUI();
|
||||||
|
|
||||||
|
if (!has_cache) {
|
||||||
|
device->RemoveMenuItemForAction(Device::WIPE_CACHE);
|
||||||
|
}
|
||||||
|
|
||||||
// Set background string to "installing security update" for security update,
|
// Set background string to "installing security update" for security update,
|
||||||
// otherwise set it to "installing system update".
|
// otherwise set it to "installing system update".
|
||||||
ui->SetSystemUpdateText(security_update);
|
ui->SetSystemUpdateText(security_update);
|
||||||
|
|||||||
Reference in New Issue
Block a user