From 9e7ae8a62652258f3ecbf147b578b73286f6d4d8 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 9 Apr 2015 13:40:31 -0700 Subject: Move default implementations into Device. The current abstract class was a nice idea but has led to a lot of copy & paste in practice. Right now, no one we know of has any extra menu items, so let's make the default menu available to everyone. (If we assume that someone somewhere really does need custom device-specific menu options, a better API would let them add to our menu rather than replacing it.) Change-Id: I59f6a92f3ecd830c2ce78ce9da19eaaf472c5dfa --- default_device.cpp | 90 ++++++++++++++---------------------------------------- 1 file changed, 23 insertions(+), 67 deletions(-) (limited to 'default_device.cpp') diff --git a/default_device.cpp b/default_device.cpp index ed601f6..d7dd452 100644 --- a/default_device.cpp +++ b/default_device.cpp @@ -14,80 +14,36 @@ * limitations under the License. */ -#include - -#include "common.h" #include "device.h" #include "screen_ui.h" -static const char* HEADERS[] = { - "Volume up/down to move highlight.", - "Power button to select.", - "", - NULL -}; - -static const char* ITEMS[] = { - "Reboot system now", - "Reboot to bootloader", - "Apply update from ADB", - "Apply update from SD card", - "Wipe data/factory reset", - "Wipe cache partition", - "View recovery logs", - "Power off", - NULL -}; - class DefaultDevice : public Device { - public: - DefaultDevice() : - ui(new ScreenRecoveryUI) { - } - - RecoveryUI* GetUI() { return ui; } - - int HandleMenuKey(int key, int visible) { - if (visible) { - switch (key) { - case KEY_DOWN: - case KEY_VOLUMEDOWN: - return kHighlightDown; - - case KEY_UP: - case KEY_VOLUMEUP: - return kHighlightUp; - - case KEY_ENTER: - case KEY_POWER: - return kInvokeItem; - } - } - - return kNoAction; + public: + DefaultDevice() : Device(new ScreenRecoveryUI) { + } + + // TODO: make this handle more cases, and move the default implementation into Device too. + int HandleMenuKey(int key, int visible) { + if (visible) { + switch (key) { + case KEY_DOWN: + case KEY_VOLUMEDOWN: + return kHighlightDown; + + case KEY_UP: + case KEY_VOLUMEUP: + return kHighlightUp; + + case KEY_ENTER: + case KEY_POWER: + return kInvokeItem; + } } - BuiltinAction InvokeMenuItem(int menu_position) { - switch (menu_position) { - case 0: return REBOOT; - case 1: return REBOOT_BOOTLOADER; - case 2: return APPLY_ADB_SIDELOAD; - case 3: return APPLY_EXT; - case 4: return WIPE_DATA; - case 5: return WIPE_CACHE; - case 6: return READ_RECOVERY_LASTLOG; - case 7: return SHUTDOWN; - default: return NO_ACTION; - } - } - - const char* const* GetMenuHeaders() { return HEADERS; } - const char* const* GetMenuItems() { return ITEMS; } - - private: - RecoveryUI* ui; + return kNoAction; + } }; Device* make_device() { - return new DefaultDevice(); + return new DefaultDevice; } -- cgit v1.1