aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-08-22 12:44:16 -0500
committerGerrit Code Review2017-08-22 12:44:16 -0500
commit89ad02206a993f063f2a32782427812ba87f6cb8 (patch)
tree366f8fbdf3193a2635844b1f49d275afc22f89d6
parentb127fddf090aa6c3177d39fdbb4d0e421302c2db (diff)
parenteea3af3f911d36ac1a82a9fb95d24912cc07e3b1 (diff)
downloadplatform-bootable-recovery-89ad02206a993f063f2a32782427812ba87f6cb8.tar.gz
platform-bootable-recovery-89ad02206a993f063f2a32782427812ba87f6cb8.tar.xz
platform-bootable-recovery-89ad02206a993f063f2a32782427812ba87f6cb8.zip
Merge changes I5d7a6baa,Id0fb2d4e
* changes: wear_ui: Expose menu_unusable_rows via Makefile var. Allow customizing WearRecoveryUI via Makefile variables.
-rw-r--r--Android.mk29
-rw-r--r--screen_ui.cpp4
-rw-r--r--screen_ui.h6
-rw-r--r--wear_device.cpp23
-rw-r--r--wear_touch.cpp177
-rw-r--r--wear_touch.h58
-rw-r--r--wear_ui.cpp24
-rw-r--r--wear_ui.h7
8 files changed, 73 insertions, 255 deletions
diff --git a/Android.mk b/Android.mk
index 967b9dfb..776e6ea1 100644
--- a/Android.mk
+++ b/Android.mk
@@ -79,7 +79,6 @@ LOCAL_SRC_FILES := \
79 ui.cpp \ 79 ui.cpp \
80 vr_ui.cpp \ 80 vr_ui.cpp \
81 wear_ui.cpp \ 81 wear_ui.cpp \
82 wear_touch.cpp \
83 82
84LOCAL_MODULE := recovery 83LOCAL_MODULE := recovery
85 84
@@ -120,6 +119,24 @@ else
120LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=90 119LOCAL_CFLAGS += -DRECOVERY_UI_TOUCH_HIGH_THRESHOLD=90
121endif 120endif
122 121
122ifneq ($(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE),)
123LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=$(TARGET_RECOVERY_UI_PROGRESS_BAR_BASELINE)
124else
125LOCAL_CFLAGS += -DRECOVERY_UI_PROGRESS_BAR_BASELINE=259
126endif
127
128ifneq ($(TARGET_RECOVERY_UI_ANIMATION_FPS),)
129LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=$(TARGET_RECOVERY_UI_ANIMATION_FPS)
130else
131LOCAL_CFLAGS += -DRECOVERY_UI_ANIMATION_FPS=30
132endif
133
134ifneq ($(TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS),)
135LOCAL_CFLAGS += -DRECOVERY_UI_MENU_UNUSABLE_ROWS=$(TARGET_RECOVERY_UI_MENU_UNUSABLE_ROWS)
136else
137LOCAL_CFLAGS += -DRECOVERY_UI_MENU_UNUSABLE_ROWS=9
138endif
139
123ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),) 140ifneq ($(TARGET_RECOVERY_UI_VR_STEREO_OFFSET),)
124LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET) 141LOCAL_CFLAGS += -DRECOVERY_UI_VR_STEREO_OFFSET=$(TARGET_RECOVERY_UI_VR_STEREO_OFFSET)
125else 142else
@@ -216,6 +233,16 @@ LOCAL_STATIC_LIBRARIES := \
216LOCAL_CFLAGS := -Werror 233LOCAL_CFLAGS := -Werror
217include $(BUILD_STATIC_LIBRARY) 234include $(BUILD_STATIC_LIBRARY)
218 235
236# Wear default device
237# ===============================
238include $(CLEAR_VARS)
239LOCAL_SRC_FILES := wear_device.cpp
240
241# Should match TARGET_RECOVERY_UI_LIB in BoardConfig.mk.
242LOCAL_MODULE := librecovery_ui_wear
243
244include $(BUILD_STATIC_LIBRARY)
245
219# vr headset default device 246# vr headset default device
220# =============================== 247# ===============================
221include $(CLEAR_VARS) 248include $(CLEAR_VARS)
diff --git a/screen_ui.cpp b/screen_ui.cpp
index a0255019..5c93b667 100644
--- a/screen_ui.cpp
+++ b/screen_ui.cpp
@@ -53,6 +53,7 @@ static double now() {
53ScreenRecoveryUI::ScreenRecoveryUI() 53ScreenRecoveryUI::ScreenRecoveryUI()
54 : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH), 54 : kMarginWidth(RECOVERY_UI_MARGIN_WIDTH),
55 kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT), 55 kMarginHeight(RECOVERY_UI_MARGIN_HEIGHT),
56 kAnimationFps(RECOVERY_UI_ANIMATION_FPS),
56 density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f), 57 density_(static_cast<float>(android::base::GetIntProperty("ro.sf.lcd_density", 160)) / 160.f),
57 currentIcon(NONE), 58 currentIcon(NONE),
58 progressBarType(EMPTY), 59 progressBarType(EMPTY),
@@ -77,7 +78,6 @@ ScreenRecoveryUI::ScreenRecoveryUI()
77 loop_frames(0), 78 loop_frames(0),
78 current_frame(0), 79 current_frame(0),
79 intro_done(false), 80 intro_done(false),
80 animation_fps(30), // TODO: there's currently no way to infer this.
81 stage(-1), 81 stage(-1),
82 max_stage(-1), 82 max_stage(-1),
83 updateMutex(PTHREAD_MUTEX_INITIALIZER) {} 83 updateMutex(PTHREAD_MUTEX_INITIALIZER) {}
@@ -404,7 +404,7 @@ void* ScreenRecoveryUI::ProgressThreadStartRoutine(void* data) {
404} 404}
405 405
406void ScreenRecoveryUI::ProgressThreadLoop() { 406void ScreenRecoveryUI::ProgressThreadLoop() {
407 double interval = 1.0 / animation_fps; 407 double interval = 1.0 / kAnimationFps;
408 while (true) { 408 while (true) {
409 double start = now(); 409 double start = now();
410 pthread_mutex_lock(&updateMutex); 410 pthread_mutex_lock(&updateMutex);
diff --git a/screen_ui.h b/screen_ui.h
index df7cc25b..62dda755 100644
--- a/screen_ui.h
+++ b/screen_ui.h
@@ -84,6 +84,9 @@ class ScreenRecoveryUI : public RecoveryUI {
84 const int kMarginWidth; 84 const int kMarginWidth;
85 const int kMarginHeight; 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 // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi. 90 // The scale factor from dp to pixels. 1.0 for mdpi, 4.0 for xxxhdpi.
88 const float density_; 91 const float density_;
89 92
@@ -141,9 +144,6 @@ class ScreenRecoveryUI : public RecoveryUI {
141 size_t current_frame; 144 size_t current_frame;
142 bool intro_done; 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 int stage, max_stage; 147 int stage, max_stage;
148 148
149 int char_width_; 149 int char_width_;
diff --git a/wear_device.cpp b/wear_device.cpp
new file mode 100644
index 00000000..3268130b
--- /dev/null
+++ b/wear_device.cpp
@@ -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
20Device* make_device() {
21 return new Device(new WearRecoveryUI);
22}
23
diff --git a/wear_touch.cpp b/wear_touch.cpp
deleted file mode 100644
index e2ab44d2..00000000
--- a/wear_touch.cpp
+++ /dev/null
@@ -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
32WearSwipeDetector::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
41WearSwipeDetector::~WearSwipeDetector() {
42}
43
44void 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
60void 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
105void 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
120void* 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
127int 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
155int 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
diff --git a/wear_touch.h b/wear_touch.h
deleted file mode 100644
index 9a1d3150..00000000
--- a/wear_touch.h
+++ /dev/null
@@ -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
22class WearSwipeDetector {
23
24public:
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
31private:
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
diff --git a/wear_ui.cpp b/wear_ui.cpp
index 18c30d34..169ef20e 100644
--- a/wear_ui.cpp
+++ b/wear_ui.cpp
@@ -51,10 +51,16 @@ static double now() {
51} 51}
52 52
53WearRecoveryUI::WearRecoveryUI() 53WearRecoveryUI::WearRecoveryUI()
54 : progress_bar_y(259), outer_height(0), outer_width(0), menu_unusable_rows(0) { 54 : kProgressBarBaseline(RECOVERY_UI_PROGRESS_BAR_BASELINE),
55 kMenuUnusableRows(RECOVERY_UI_MENU_UNUSABLE_ROWS) {
56 // TODO: kMenuUnusableRows should be computed based on the lines in draw_screen_locked().
57
58 // TODO: The following three variables are likely not needed. The first two are detected
59 // automatically in ScreenRecoveryUI::LoadAnimation(), based on the actual files seen on device.
55 intro_frames = 22; 60 intro_frames = 22;
56 loop_frames = 60; 61 loop_frames = 60;
57 animation_fps = 30; 62
63 touch_screen_allowed_ = true;
58 64
59 for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL; 65 for (size_t i = 0; i < 5; i++) backgroundIcon[i] = NULL;
60 66
@@ -62,7 +68,7 @@ WearRecoveryUI::WearRecoveryUI()
62} 68}
63 69
64int WearRecoveryUI::GetProgressBaseline() const { 70int WearRecoveryUI::GetProgressBaseline() const {
65 return progress_bar_y; 71 return kProgressBarBaseline;
66} 72}
67 73
68// Draw background frame on the screen. Does not flip pages. 74// Draw background frame on the screen. Does not flip pages.
@@ -113,8 +119,8 @@ void WearRecoveryUI::draw_screen_locked() {
113 SetColor(TEXT_FILL); 119 SetColor(TEXT_FILL);
114 gr_fill(0, 0, gr_fb_width(), gr_fb_height()); 120 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
115 121
116 int y = outer_height; 122 int y = kMarginHeight;
117 int x = outer_width; 123 int x = kMarginWidth;
118 if (show_menu) { 124 if (show_menu) {
119 std::string recovery_fingerprint = 125 std::string recovery_fingerprint =
120 android::base::GetProperty("ro.bootimage.build.fingerprint", ""); 126 android::base::GetProperty("ro.bootimage.build.fingerprint", "");
@@ -170,7 +176,7 @@ void WearRecoveryUI::draw_screen_locked() {
170 int ty; 176 int ty;
171 int row = (text_top_ + text_rows_ - 1) % text_rows_; 177 int row = (text_top_ + text_rows_ - 1) % text_rows_;
172 size_t count = 0; 178 size_t count = 0;
173 for (int ty = gr_fb_height() - char_height_ - outer_height; ty > y + 2 && count < text_rows_; 179 for (int ty = gr_fb_height() - char_height_ - kMarginHeight; ty > y + 2 && count < text_rows_;
174 ty -= char_height_, ++count) { 180 ty -= char_height_, ++count) {
175 gr_text(gr_sys_font(), x + 4, ty, text_[row], 0); 181 gr_text(gr_sys_font(), x + 4, ty, text_[row], 0);
176 --row; 182 --row;
@@ -190,12 +196,12 @@ bool WearRecoveryUI::InitTextParams() {
190 return false; 196 return false;
191 } 197 }
192 198
193 text_cols_ = (gr_fb_width() - (outer_width * 2)) / char_width_; 199 text_cols_ = (gr_fb_width() - (kMarginWidth * 2)) / char_width_;
194 200
195 if (text_rows_ > kMaxRows) text_rows_ = kMaxRows; 201 if (text_rows_ > kMaxRows) text_rows_ = kMaxRows;
196 if (text_cols_ > kMaxCols) text_cols_ = kMaxCols; 202 if (text_cols_ > kMaxCols) text_cols_ = kMaxCols;
197 203
198 visible_text_rows = (gr_fb_height() - (outer_height * 2)) / char_height_; 204 visible_text_rows = (gr_fb_height() - (kMarginHeight * 2)) / char_height_;
199 return true; 205 return true;
200} 206}
201 207
@@ -263,7 +269,7 @@ void WearRecoveryUI::StartMenu(const char* const* headers, const char* const* it
263 show_menu = true; 269 show_menu = true;
264 menu_sel = initial_selection; 270 menu_sel = initial_selection;
265 menu_start = 0; 271 menu_start = 0;
266 menu_end = visible_text_rows - 1 - menu_unusable_rows; 272 menu_end = visible_text_rows - 1 - kMenuUnusableRows;
267 if (menu_items <= menu_end) menu_end = menu_items; 273 if (menu_items <= menu_end) menu_end = menu_items;
268 update_screen_locked(); 274 update_screen_locked();
269 } 275 }
diff --git a/wear_ui.h b/wear_ui.h
index a814118c..3bd90b69 100644
--- a/wear_ui.h
+++ b/wear_ui.h
@@ -42,14 +42,11 @@ class WearRecoveryUI : public ScreenRecoveryUI {
42 42
43 protected: 43 protected:
44 // progress bar vertical position, it's centered horizontally 44 // progress bar vertical position, it's centered horizontally
45 int progress_bar_y; 45 const int kProgressBarBaseline;
46
47 // outer of window
48 int outer_height, outer_width;
49 46
50 // Unusable rows when displaying the recovery menu, including the lines for headers (Android 47 // Unusable rows when displaying the recovery menu, including the lines for headers (Android
51 // Recovery, build id and etc) and the bottom lines that may otherwise go out of the screen. 48 // Recovery, build id and etc) and the bottom lines that may otherwise go out of the screen.
52 int menu_unusable_rows; 49 const int kMenuUnusableRows;
53 50
54 int GetProgressBaseline() const override; 51 int GetProgressBaseline() const override;
55 52