Browse Source

Allow customizing WearRecoveryUI via Makefile variables.

With the following Makefile variables, we can reduce the work of writing
(copy/pasting) device-specific WearRecoveryUI classes.

The list of Makefile variables (the ones useful for Wear devices):
- TARGET_RECOVERY_UI_MARGIN_HEIGHT (default: 0)
- TARGET_RECOVERY_UI_MARGIN_WIDTH (default: 0)
  Specify the margin space that we don't want to display texts. They
  replace the former outer_width and outer_height.

- TARGET_RECOVERY_UI_TOUCH_LOW_THRESHOLD (default: 50)
- TARGET_RECOVERY_UI_TOUCH_HIGH_THRESHOLD (default: 90)
  Specify the sensitivity of recognizing a swipe. Devices give absolute
  positions, so for some devices we need to adjust the thresholds.

- TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE
  Specify the progress bar vertical position, which should be adjusted
  to the actual height of a device. It replaces the former
  progress_bar_y.

- TARGET_RECOVERY_UI_ANIMATION_FPS (default: 30)
  Specify the animation FPS if using device-specific animation images.
  It replaces the former animation_fps.

Devices can specify "TARGET_RECOVERY_UI_LIB := librecovery_ui_wear",
with optionally defined Makefile vars above, in BoardConfig.mk to
customize their WearRecoveryUI.

Also remove the obsolete wear_touch.{cpp,h}, which has been merged into
ui.cpp in commit 5f8dd9951d.

Bug: 64307776
Test: Change the device BoardConfig.mk and test recovery image.
Change-Id: Id0fb2d4e3977ab5ddd31e71f9535470cab70e41b
(cherry picked from commit 0470ceea38)
Tao Bao 4 years ago
parent
commit
016120f395
8 changed files with 64 additions and 253 deletions
  1. 22
    1
      Android.mk
  2. 2
    2
      screen_ui.cpp
  3. 3
    3
      screen_ui.h
  4. 23
    0
      wear_device.cpp
  5. 0
    177
      wear_touch.cpp
  6. 0
    58
      wear_touch.h
  7. 13
    8
      wear_ui.cpp
  8. 1
    4
      wear_ui.h

+ 22
- 1
Android.mk View File

@@ -79,7 +79,6 @@ LOCAL_SRC_FILES := \
79 79
     ui.cpp \
80 80
     vr_ui.cpp \
81 81
     wear_ui.cpp \
82
-    wear_touch.cpp \
83 82
 
84 83
 LOCAL_MODULE := recovery
85 84
 
@@ -120,6 +119,18 @@ else
120 119
 LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=90
121 120
 endif
122 121
 
122
+ifneq ($(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE),)
123
+LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=$(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE)
124
+else
125
+LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=259
126
+endif
127
+
128
+ifneq ($(TARGET_RECOVERY_UI_ANIMATION_FPS),)
129
+LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=$(TARGET_RECOVERY_UI_ANIMATION_FPS)
130
+else
131
+LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=30
132
+endif
133
+
123 134
 ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),)
124 135
 LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET)
125 136
 else
@@ -216,6 +227,16 @@ LOCAL_STATIC_LIBRARIES := \
216 227
 LOCAL_CFLAGS := -Werror
217 228
 include $(BUILD_STATIC_LIBRARY)
218 229
 
230
+# Wear default device
231
+# ===============================
232
+include $(CLEAR_VARS)
233
+LOCAL_SRC_FILES := wear_device.cpp
234
+
235
+# Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk.
236
+LOCAL_MODULE := librecovery_ui_wear
237
+
238
+include $(BUILD_STATIC_LIBRARY)
239
+
219 240
 # vr headset default device
220 241
 # ===============================
221 242
 include $(CLEAR_VARS)

+ 2
- 2
screen_ui.cpp View File

@@ -53,6 +53,7 @@ static double now() {
53 53
 ScreenRecoveryUI::ScreenRecoveryUI()
54 54
     : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH),
55 55
       kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT),
56
+      kAnimationFps(RECOVERY_UI_ANIMATION_FPS),
56 57
       density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
57 58
       currentIcon(NONE),
58 59
       progressBarType(EMPTY),
@@ -77,7 +78,6 @@ ScreenRecoveryUI::ScreenRecoveryUI()
77 78
       loop_frames(0),
78 79
       current_frame(0),
79 80
       intro_done(false),
80
-      animation_fps(30),  // TODO: there's currently no way to infer this.
81 81
       stage(-1),
82 82
       max_stage(-1),
83 83
       updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
@@ -375,7 +375,7 @@ void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
375 375
 }
376 376
 
377 377
 void ScreenRecoveryUI::ProgressThreadLoop() {
378
-  double interval = 1.0 / animation_fps;
378
+  double interval = 1.0 / kAnimationFps;
379 379
   while (true) {
380 380
     double start = now();
381 381
     pthread_mutex_lock(&updateMutex);

+ 3
- 3
screen_ui.h View File

@@ -84,6 +84,9 @@ class ScreenRecoveryUI : public RecoveryUI {
84 84
   const int kMarginWidth;
85 85
   const int kMarginHeight;
86 86
 
87
+  // Number of frames per sec (default: 30) for both parts of the animation.
88
+  const int kAnimationFps;
89
+
87 90
   // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
88 91
   const float density_;
89 92
 
@@ -141,9 +144,6 @@ class ScreenRecoveryUI : public RecoveryUI {
141 144
   size_t current_frame;
142 145
   bool intro_done;
143 146
 
144
-  // Number of frames per sec (default: 30) for both parts of the animation.
145
-  int animation_fps;
146
-
147 147
   int stage, max_stage;
148 148
 
149 149
   int char_width_;

+ 23
- 0
wear_device.cpp View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * Copyright (C) 2017 The Android Open Source Project
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ *      http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+#include "device.h"
18
+#include "wear_ui.h"
19
+
20
+Device* make_device() {
21
+  return new Device(new WearRecoveryUI);
22
+}
23
+

+ 0
- 177
wear_touch.cpp View File

@@ -1,177 +0,0 @@
1
-/*
2
- * Copyright (C) 2016 The Android Open Source Project
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- *      http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
-#include <dirent.h>
18
-#include <fcntl.h>
19
-#include <stdio.h>
20
-#include <stdlib.h>
21
-#include <unistd.h>
22
-#include <errno.h>
23
-#include <string.h>
24
-
25
-#include <android-base/logging.h>
26
-#include <linux/input.h>
27
-
28
-#include "wear_touch.h"
29
-
30
-#define DEVICE_PATH "/dev/input"
31
-
32
-WearSwipeDetector::WearSwipeDetector(int low, int high, OnSwipeCallback callback, void* cookie):
33
-    mLowThreshold(low),
34
-    mHighThreshold(high),
35
-    mCallback(callback),
36
-    mCookie(cookie),
37
-    mCurrentSlot(-1) {
38
-    pthread_create(&mThread, NULL, touch_thread, this);
39
-}
40
-
41
-WearSwipeDetector::~WearSwipeDetector() {
42
-}
43
-
44
-void WearSwipeDetector::detect(int dx, int dy) {
45
-    enum SwipeDirection direction;
46
-
47
-    if (abs(dy) < mLowThreshold && abs(dx) > mHighThreshold) {
48
-        direction = dx < 0 ? LEFT : RIGHT;
49
-    } else if (abs(dx) < mLowThreshold && abs(dy) > mHighThreshold) {
50
-        direction = dy < 0 ? UP : DOWN;
51
-    } else {
52
-        LOG(DEBUG) << "Ignore " << dx << " " << dy;
53
-        return;
54
-    }
55
-
56
-    LOG(DEBUG) << "Swipe direction=" << direction;
57
-    mCallback(mCookie, direction);
58
-}
59
-
60
-void WearSwipeDetector::process(struct input_event *event) {
61
-    if (mCurrentSlot < 0) {
62
-        mCallback(mCookie, UP);
63
-        mCurrentSlot = 0;
64
-    }
65
-
66
-    if (event->type == EV_ABS) {
67
-        if (event->code == ABS_MT_SLOT)
68
-            mCurrentSlot = event->value;
69
-
70
-        // Ignore other fingers
71
-        if (mCurrentSlot > 0) {
72
-            return;
73
-        }
74
-
75
-        switch (event->code) {
76
-        case ABS_MT_POSITION_X:
77
-            mX = event->value;
78
-            mFingerDown = true;
79
-            break;
80
-
81
-        case ABS_MT_POSITION_Y:
82
-            mY = event->value;
83
-            mFingerDown = true;
84
-            break;
85
-
86
-        case ABS_MT_TRACKING_ID:
87
-            if (event->value < 0)
88
-                mFingerDown = false;
89
-            break;
90
-        }
91
-    } else if (event->type == EV_SYN) {
92
-        if (event->code == SYN_REPORT) {
93
-            if (mFingerDown && !mSwiping) {
94
-                mStartX = mX;
95
-                mStartY = mY;
96
-                mSwiping = true;
97
-            } else if (!mFingerDown && mSwiping) {
98
-                mSwiping = false;
99
-                detect(mX - mStartX, mY - mStartY);
100
-            }
101
-        }
102
-    }
103
-}
104
-
105
-void WearSwipeDetector::run() {
106
-    int fd = findDevice(DEVICE_PATH);
107
-    if (fd < 0) {
108
-        LOG(ERROR) << "no input devices found";
109
-        return;
110
-    }
111
-
112
-    struct input_event event;
113
-    while (read(fd, &event, sizeof(event)) == sizeof(event)) {
114
-        process(&event);
115
-    }
116
-
117
-    close(fd);
118
-}
119
-
120
-void* WearSwipeDetector::touch_thread(void* cookie) {
121
-    (static_cast<WearSwipeDetector*>(cookie))->run();
122
-    return NULL;
123
-}
124
-
125
-#define test_bit(bit, array)    ((array)[(bit)/8] & (1<<((bit)%8)))
126
-
127
-int WearSwipeDetector::openDevice(const char *device) {
128
-    int fd = open(device, O_RDONLY);
129
-    if (fd < 0) {
130
-        PLOG(ERROR) << "could not open " << device;
131
-        return false;
132
-    }
133
-
134
-    char name[80];
135
-    name[sizeof(name) - 1] = '\0';
136
-    if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
137
-        PLOG(ERROR) << "could not get device name for " << device;
138
-        name[0] = '\0';
139
-    }
140
-
141
-    uint8_t bits[512];
142
-    memset(bits, 0, sizeof(bits));
143
-    int ret = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(bits)), bits);
144
-    if (ret > 0) {
145
-        if (test_bit(ABS_MT_POSITION_X, bits) && test_bit(ABS_MT_POSITION_Y, bits)) {
146
-            LOG(DEBUG) << "Found " << device << " " << name;
147
-            return fd;
148
-        }
149
-    }
150
-
151
-    close(fd);
152
-    return -1;
153
-}
154
-
155
-int WearSwipeDetector::findDevice(const char* path) {
156
-    DIR* dir = opendir(path);
157
-    if (dir == NULL) {
158
-        PLOG(ERROR) << "Could not open directory " << path;
159
-        return false;
160
-    }
161
-
162
-    struct dirent* entry;
163
-    int ret = -1;
164
-    while (ret < 0 && (entry = readdir(dir)) != NULL) {
165
-        if (entry->d_name[0] == '.') continue;
166
-
167
-        char device[PATH_MAX];
168
-        device[PATH_MAX-1] = '\0';
169
-        snprintf(device, PATH_MAX-1, "%s/%s", path, entry->d_name);
170
-
171
-        ret = openDevice(device);
172
-    }
173
-
174
-    closedir(dir);
175
-    return ret;
176
-}
177
-

+ 0
- 58
wear_touch.h View File

@@ -1,58 +0,0 @@
1
-/*
2
- * Copyright (C) 2016 The Android Open Source Project
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- *      http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
-#ifndef __WEAR_TOUCH_H
18
-#define __WEAR_TOUCH_H
19
-
20
-#include <pthread.h>
21
-
22
-class WearSwipeDetector {
23
-
24
-public:
25
-    enum SwipeDirection { UP, DOWN, RIGHT, LEFT };
26
-    typedef void (*OnSwipeCallback)(void* cookie, enum SwipeDirection direction);
27
-
28
-    WearSwipeDetector(int low, int high, OnSwipeCallback cb, void* cookie);
29
-    ~WearSwipeDetector();
30
-
31
-private:
32
-    void run();
33
-    void process(struct input_event *event);
34
-    void detect(int dx, int dy);
35
-
36
-    pthread_t mThread;
37
-    static void* touch_thread(void* cookie);
38
-
39
-    int findDevice(const char* path);
40
-    int openDevice(const char* device);
41
-
42
-    int mLowThreshold;
43
-    int mHighThreshold;
44
-
45
-    OnSwipeCallback mCallback;
46
-    void *mCookie;
47
-
48
-    int mX;
49
-    int mY;
50
-    int mStartX;
51
-    int mStartY;
52
-
53
-    int mCurrentSlot;
54
-    bool mFingerDown;
55
-    bool mSwiping;
56
-};
57
-
58
-#endif // __WEAR_TOUCH_H

+ 13
- 8
wear_ui.cpp View File

@@ -51,10 +51,15 @@ static double now() {
51 51
 }
52 52
 
53 53
 WearRecoveryUI::WearRecoveryUI()
54
-    : progress_bar_y(259), outer_height(0), outer_width(0), menu_unusable_rows(0) {
54
+    : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE), menu_unusable_rows(9) {
55
+  // TODO: menu_unusable_rows should be computed based on the lines in draw_screen_locked().
56
+
57
+  // TODO: The following three variables are likely not needed. The first two are detected
58
+  // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device.
55 59
   intro_frames = 22;
56 60
   loop_frames = 60;
57
-  animation_fps = 30;
61
+
62
+  touch_screen_allowed_ = true;
58 63
 
59 64
   for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL;
60 65
 
@@ -62,7 +67,7 @@ WearRecoveryUI::WearRecoveryUI()
62 67
 }
63 68
 
64 69
 int WearRecoveryUI::GetProgressBaseline() const {
65
-  return progress_bar_y;
70
+  return kProgressBarBaseline;
66 71
 }
67 72
 
68 73
 // Draw background frame on the screen.  Does not flip pages.
@@ -113,8 +118,8 @@ void WearRecoveryUI::draw_screen_locked() {
113 118
     SetColor(TEXT_FILL);
114 119
     gr_fill(0, 0, gr_fb_width(), gr_fb_height());
115 120
 
116
-    int y = outer_height;
117
-    int x = outer_width;
121
+    int y = kMarginHeight;
122
+    int x = kMarginWidth;
118 123
     if (show_menu) {
119 124
       std::string recovery_fingerprint =
120 125
           android::base::GetProperty("ro.bootimage.build.fingerprint", "");
@@ -170,7 +175,7 @@ void WearRecoveryUI::draw_screen_locked() {
170 175
     int ty;
171 176
     int row = (text_top_ + text_rows_ - 1) % text_rows_;
172 177
     size_t count = 0;
173
-    for (int ty = gr_fb_height() - char_height_ - outer_height; ty > y + 2 && count < text_rows_;
178
+    for (int ty = gr_fb_height() - char_height_ - kMarginHeight; ty > y + 2 && count < text_rows_;
174 179
          ty -= char_height_, ++count) {
175 180
       gr_text(gr_sys_font(), x + 4, ty, text_[row], 0);
176 181
       --row;
@@ -190,12 +195,12 @@ bool WearRecoveryUI::InitTextParams() {
190 195
     return false;
191 196
   }
192 197
 
193
-  text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_;
198
+  text_cols_ = (gr_fb_width() - (kMarginWidth * 2)) / char_width_;
194 199
 
195 200
   if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
196 201
   if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
197 202
 
198
-  visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_;
203
+  visible_text_rows = (gr_fb_height() - (kMarginHeight * 2)) / char_height_;
199 204
   return true;
200 205
 }
201 206
 

+ 1
- 4
wear_ui.h View File

@@ -42,10 +42,7 @@ class WearRecoveryUI : public ScreenRecoveryUI {
42 42
 
43 43
  protected:
44 44
   // progress bar vertical position, it's centered horizontally
45
-  int progress_bar_y;
46
-
47
-  // outer of window
48
-  int outer_height, outer_width;
45
+  const int kProgressBarBaseline;
49 46
 
50 47
   // Unusable rows when displaying the recovery menu, including the lines for headers (Android
51 48
   // Recovery, build id and etc) and the bottom lines that may otherwise go out of the screen.