Browse Source

Auto-detect whether to use the long-press UI.

Change-Id: Ie77a5584e301467c6a5e164d2c62d6f036b2c0c0
Elliott Hughes 6 years ago
parent
commit
4af215b2c3
6 changed files with 56 additions and 41 deletions
  1. 2
    4
      README.md
  2. 1
    28
      default_device.cpp
  3. 43
    7
      device.cpp
  4. 1
    1
      device.h
  5. 5
    1
      ui.cpp
  6. 4
    0
      ui.h

+ 2
- 4
README.md View File

@@ -4,11 +4,9 @@ The Recovery Image
4 4
 Quick turn-around testing
5 5
 -------------------------
6 6
 
7
-    mm -j
8
-    m ramdisk-nodeps
9
-    m recoveryimage-nodeps
10
-    adb reboot bootloader
7
+    mm -j && m ramdisk-nodeps && m recoveryimage-nodeps
11 8
 
12 9
     # To boot into the new recovery image
13 10
     # without flashing the recovery partition:
11
+    adb reboot bootloader
14 12
     fastboot boot $ANDROID_PRODUCT_OUT/recovery.img

+ 1
- 28
default_device.cpp View File

@@ -17,33 +17,6 @@
17 17
 #include "device.h"
18 18
 #include "screen_ui.h"
19 19
 
20
-class DefaultDevice : public Device {
21
- public:
22
-  DefaultDevice() : Device(new ScreenRecoveryUI) {
23
-  }
24
-
25
-  // TODO: make this handle more cases, and move the default implementation into Device too.
26
-  int HandleMenuKey(int key, int visible) {
27
-    if (visible) {
28
-      switch (key) {
29
-        case KEY_DOWN:
30
-        case KEY_VOLUMEDOWN:
31
-          return kHighlightDown;
32
-
33
-        case KEY_UP:
34
-        case KEY_VOLUMEUP:
35
-          return kHighlightUp;
36
-
37
-        case KEY_ENTER:
38
-        case KEY_POWER:
39
-          return kInvokeItem;
40
-      }
41
-    }
42
-
43
-    return kNoAction;
44
-  }
45
-};
46
-
47 20
 Device* make_device() {
48
-  return new DefaultDevice;
21
+  return new Device(new ScreenRecoveryUI);
49 22
 }

+ 43
- 7
device.cpp View File

@@ -16,15 +16,21 @@
16 16
 
17 17
 #include "device.h"
18 18
 
19
-// TODO: this is a lie for, say, fugu.
20
-static const char* HEADERS[] = {
21
-    "Volume up/down to move highlight.",
22
-    "Power button to select.",
19
+static const char* REGULAR_HEADERS[] = {
20
+    "Volume up/down move highlight.",
21
+    "Power button activates.",
23 22
     "",
24 23
     NULL
25 24
 };
26 25
 
27
-static const char* ITEMS[] = {
26
+static const char* LONG_PRESS_HEADERS[] = {
27
+    "Any button cycles highlight.",
28
+    "Long-press activates.",
29
+    "",
30
+    NULL
31
+};
32
+
33
+static const char* MENU_ITEMS[] = {
28 34
     "Reboot system now",
29 35
     "Reboot to bootloader",
30 36
     "Apply update from ADB",
@@ -37,8 +43,13 @@ static const char* ITEMS[] = {
37 43
     NULL
38 44
 };
39 45
 
40
-const char* const* Device::GetMenuHeaders() { return HEADERS; }
41
-const char* const* Device::GetMenuItems() { return ITEMS; }
46
+const char* const* Device::GetMenuHeaders() {
47
+  return ui_->HasThreeButtons() ? REGULAR_HEADERS : LONG_PRESS_HEADERS;
48
+}
49
+
50
+const char* const* Device::GetMenuItems() {
51
+  return MENU_ITEMS;
52
+}
42 53
 
43 54
 Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
44 55
   switch (menu_position) {
@@ -54,3 +65,28 @@ Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
54 65
     default: return NO_ACTION;
55 66
   }
56 67
 }
68
+
69
+int Device::HandleMenuKey(int key, int visible) {
70
+  if (!visible) {
71
+    return kNoAction;
72
+  }
73
+
74
+  switch (key) {
75
+    case KEY_DOWN:
76
+    case KEY_VOLUMEDOWN:
77
+      return kHighlightDown;
78
+
79
+    case KEY_UP:
80
+    case KEY_VOLUMEUP:
81
+      return kHighlightUp;
82
+
83
+    case KEY_ENTER:
84
+    case KEY_POWER:
85
+      return kInvokeItem;
86
+
87
+    default:
88
+      // If you have all of the above buttons, any other buttons
89
+      // are ignored. Otherwise, any button cycles the highlight.
90
+      return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
91
+  }
92
+}

+ 1
- 1
device.h View File

@@ -54,7 +54,7 @@ class Device {
54 54
     //   - invoke the highlighted item (kInvokeItem)
55 55
     //   - do nothing (kNoAction)
56 56
     //   - invoke a specific action (a menu position: any non-negative number)
57
-    virtual int HandleMenuKey(int key, int visible) = 0;
57
+    virtual int HandleMenuKey(int key, int visible);
58 58
 
59 59
     enum BuiltinAction {
60 60
         NO_ACTION = 0,

+ 5
- 1
ui.cpp View File

@@ -278,6 +278,10 @@ bool RecoveryUI::IsLongPress() {
278 278
     return result;
279 279
 }
280 280
 
281
+bool RecoveryUI::HasThreeButtons() {
282
+    return has_power_key && has_up_key && has_down_key;
283
+}
284
+
281 285
 void RecoveryUI::FlushKeys() {
282 286
     pthread_mutex_lock(&key_queue_mutex);
283 287
     key_queue_len = 0;
@@ -290,7 +294,7 @@ RecoveryUI::KeyAction RecoveryUI::CheckKey(int key, bool is_long_press) {
290 294
     pthread_mutex_unlock(&key_queue_mutex);
291 295
 
292 296
     // If we have power and volume up keys, that chord is the signal to toggle the text display.
293
-    if (has_power_key && has_up_key) {
297
+    if (HasThreeButtons()) {
294 298
         if (key == KEY_VOLUMEUP && IsKeyPressed(KEY_POWER)) {
295 299
             return TOGGLE;
296 300
         }

+ 4
- 0
ui.h View File

@@ -75,6 +75,10 @@ class RecoveryUI {
75 75
     virtual bool IsKeyPressed(int key);
76 76
     virtual bool IsLongPress();
77 77
 
78
+    // Returns true if you have the volume up/down and power trio typical
79
+    // of phones and tablets, false otherwise.
80
+    virtual bool HasThreeButtons();
81
+
78 82
     // Erase any queued-up keys.
79 83
     virtual void FlushKeys();
80 84