aboutsummaryrefslogtreecommitdiffstats
path: root/default_device.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-09 13:40:31 -0700
committerElliott Hughes <enh@google.com>2015-04-09 13:40:31 -0700
commit9e7ae8a62652258f3ecbf147b578b73286f6d4d8 (patch)
treef614a82b9b246e72327fe00ca1ecf8d616d94a0e /default_device.cpp
parent52222a58417e7e6349e91e19e4f5e293a3a971c5 (diff)
downloadbootable_recovery-9e7ae8a62652258f3ecbf147b578b73286f6d4d8.zip
bootable_recovery-9e7ae8a62652258f3ecbf147b578b73286f6d4d8.tar.gz
bootable_recovery-9e7ae8a62652258f3ecbf147b578b73286f6d4d8.tar.bz2
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
Diffstat (limited to 'default_device.cpp')
-rw-r--r--default_device.cpp90
1 files changed, 23 insertions, 67 deletions
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 <linux/input.h>
-
-#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;
}