summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Zongker <dougz@android.com>2011-03-08 21:25:05 +0100
committerDoug Zongker <dougz@android.com>2011-03-08 21:25:05 +0100
commit4cc533dd1c946664df1cd7386f60d37fd16c2668 (patch)
tree6e57875846903714d31b6511f30e7bce77d0d896
parentam 68189f29: allow paletted RGB images in recovery (diff)
downloadandroid_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar.gz
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar.bz2
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar.lz
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar.xz
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.tar.zst
android_bootable_recovery-4cc533dd1c946664df1cd7386f60d37fd16c2668.zip
Diffstat (limited to '')
-rw-r--r--ui.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/ui.c b/ui.c
index 5a2a83715..179eb2ae6 100644
--- a/ui.c
+++ b/ui.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <errno.h>
+#include <fcntl.h>
#include <linux/input.h>
#include <pthread.h>
#include <stdarg.h>
@@ -21,10 +23,11 @@
#include <stdlib.h>
#include <string.h>
#include <sys/reboot.h>
+#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <time.h>
#include <unistd.h>
-#include <errno.h>
#include "common.h"
#include "minui/minui.h"
@@ -587,22 +590,44 @@ void ui_show_text(int visible)
pthread_mutex_unlock(&gUpdateMutex);
}
+// Return true if USB is connected.
+static int usb_connected() {
+ int fd = open("/sys/class/switch/usb_connected/state", O_RDONLY);
+ if (fd < 0) {
+ printf("failed to open /sys/class/switch/usb_connected/state: %s\n",
+ strerror(errno));
+ return 0;
+ }
+
+ char buf;
+ int connected = (read(fd, &buf, 1) == 1) && (buf == '1');
+ if (close(fd) < 0) {
+ printf("failed to close /sys/class/switch/usb_connected/state: %s\n",
+ strerror(errno));
+ }
+ return connected;
+}
+
int ui_wait_key()
{
pthread_mutex_lock(&key_queue_mutex);
- struct timeval now;
- struct timespec timeout;
- gettimeofday(&now, NULL);
- timeout.tv_sec = now.tv_sec;
- timeout.tv_nsec = now.tv_usec * 1000;
- timeout.tv_sec += UI_WAIT_KEY_TIMEOUT_SEC;
-
- int rc = 0;
- while (key_queue_len == 0 && rc != ETIMEDOUT) {
- rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex,
- &timeout);
- }
+ // Time out after UI_WAIT_KEY_TIMEOUT_SEC, unless a USB cable is
+ // plugged in.
+ do {
+ struct timeval now;
+ struct timespec timeout;
+ gettimeofday(&now, NULL);
+ timeout.tv_sec = now.tv_sec;
+ timeout.tv_nsec = now.tv_usec * 1000;
+ timeout.tv_sec += UI_WAIT_KEY_TIMEOUT_SEC;
+
+ int rc = 0;
+ while (key_queue_len == 0 && rc != ETIMEDOUT) {
+ rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex,
+ &timeout);
+ }
+ } while (usb_connected() && key_queue_len == 0);
int key = -1;
if (key_queue_len > 0) {