am f91bd41c: am 1c302caf: (-s ours) am c14a7fbd: (-s ours) Reconcile with jb-mr1-release - do not merge

* commit 'f91bd41c46ec8bd085c361ea0bdf53efe13c87ca':
diff --git a/minui/Android.mk b/minui/Android.mk
index 285ac62..43e0ad3 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -20,4 +20,10 @@
   LOCAL_CFLAGS += -DRECOVERY_BGRA
 endif
 
+ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),)
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT)
+else
+  LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0
+endif
+
 include $(BUILD_STATIC_LIBRARY)
diff --git a/minui/graphics.c b/minui/graphics.c
index 287878e..747b2db 100644
--- a/minui/graphics.c
+++ b/minui/graphics.c
@@ -60,6 +60,9 @@
 static GGLSurface gr_mem_surface;
 static unsigned gr_active_fb = 0;
 static unsigned double_buffering = 0;
+static int overscan_percent = OVERSCAN_PERCENT;
+static int overscan_offset_x = 0;
+static int overscan_offset_y = 0;
 
 static int gr_fb_fd = -1;
 static int gr_vt_fd = -1;
@@ -132,6 +135,9 @@
         return -1;
     }
 
+    overscan_offset_x = vi.xres * overscan_percent / 100;
+    overscan_offset_y = vi.yres * overscan_percent / 100;
+
     fb->version = sizeof(*fb);
     fb->width = vi.xres;
     fb->height = vi.yres;
@@ -224,6 +230,9 @@
     GRFont *font = gr_font;
     unsigned off;
 
+    x += overscan_offset_x;
+    y += overscan_offset_y;
+
     y -= font->ascent;
 
     gl->bindTexture(gl, &font->texture);
@@ -250,6 +259,9 @@
     }
     GGLContext* gl = gr_context;
 
+    x += overscan_offset_x;
+    y += overscan_offset_y;
+
     gl->bindTexture(gl, (GGLSurface*) icon);
     gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
     gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
@@ -263,11 +275,17 @@
     gl->recti(gl, x, y, x+gr_get_width(icon), y+gr_get_height(icon));
 }
 
-void gr_fill(int x, int y, int w, int h)
+void gr_fill(int x1, int y1, int x2, int y2)
 {
+    x1 += overscan_offset_x;
+    y1 += overscan_offset_y;
+
+    x2 += overscan_offset_x;
+    y2 += overscan_offset_y;
+
     GGLContext *gl = gr_context;
     gl->disable(gl, GGL_TEXTURE_2D);
-    gl->recti(gl, x, y, w, h);
+    gl->recti(gl, x1, y1, x2, y2);
 }
 
 void gr_blit(gr_surface source, int sx, int sy, int w, int h, int dx, int dy) {
@@ -276,6 +294,9 @@
     }
     GGLContext *gl = gr_context;
 
+    dx += overscan_offset_x;
+    dy += overscan_offset_y;
+
     gl->bindTexture(gl, (GGLSurface*) source);
     gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
     gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
@@ -385,12 +406,12 @@
 
 int gr_fb_width(void)
 {
-    return gr_framebuffer[0].width;
+    return gr_framebuffer[0].width - 2*overscan_offset_x;
 }
 
 int gr_fb_height(void)
 {
-    return gr_framebuffer[0].height;
+    return gr_framebuffer[0].height - 2*overscan_offset_y;
 }
 
 gr_pixel *gr_fb_data(void)
diff --git a/minui/minui.h b/minui/minui.h
index 767ffcb..bc43bb5 100644
--- a/minui/minui.h
+++ b/minui/minui.h
@@ -36,7 +36,7 @@
 void gr_fb_blank(bool blank);
 
 void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
-void gr_fill(int x, int y, int w, int h);
+void gr_fill(int x1, int y1, int x2, int y2);
 int gr_text(int x, int y, const char *s);
  void gr_texticon(int x, int y, gr_surface icon);
 int gr_measure(const char *s);
diff --git a/ui.cpp b/ui.cpp
index bd0fcae..65f4028 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -45,7 +45,8 @@
 
 RecoveryUI::RecoveryUI() :
     key_queue_len(0),
-    key_last_down(-1) {
+    key_last_down(-1),
+    key_down_time(0) {
     pthread_mutex_init(&key_queue_mutex, NULL);
     pthread_cond_init(&key_queue_cond, NULL);
     self = this;
@@ -109,19 +110,29 @@
 // updown == 1 for key down events; 0 for key up events
 void RecoveryUI::process_key(int key_code, int updown) {
     bool register_key = false;
+    bool long_press = false;
+
+    const long long_threshold = CLOCKS_PER_SEC * 750 / 1000;
 
     pthread_mutex_lock(&key_queue_mutex);
     key_pressed[key_code] = updown;
     if (updown) {
         key_last_down = key_code;
+        key_down_time = clock();
     } else {
-        if (key_last_down == key_code)
+        if (key_last_down == key_code) {
+            long duration = clock() - key_down_time;
+            if (duration > long_threshold) {
+                long_press = true;
+            }
             register_key = true;
+        }
         key_last_down = -1;
     }
     pthread_mutex_unlock(&key_queue_mutex);
 
     if (register_key) {
+        NextCheckKeyIsLong(long_press);
         switch (CheckKey(key_code)) {
           case RecoveryUI::IGNORE:
             break;
@@ -135,18 +146,23 @@
             break;
 
           case RecoveryUI::ENQUEUE:
-            pthread_mutex_lock(&key_queue_mutex);
-            const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
-            if (key_queue_len < queue_max) {
-                key_queue[key_queue_len++] = key_code;
-                pthread_cond_signal(&key_queue_cond);
-            }
-            pthread_mutex_unlock(&key_queue_mutex);
+            EnqueueKey(key_code);
             break;
         }
     }
 }
 
+void RecoveryUI::EnqueueKey(int key_code) {
+    pthread_mutex_lock(&key_queue_mutex);
+    const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
+    if (key_queue_len < queue_max) {
+        key_queue[key_queue_len++] = key_code;
+        pthread_cond_signal(&key_queue_cond);
+    }
+    pthread_mutex_unlock(&key_queue_mutex);
+}
+
+
 // Reads input events, handles special hot keys, and adds to the key queue.
 void* RecoveryUI::input_thread(void *cookie)
 {
@@ -223,3 +239,6 @@
 RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) {
     return RecoveryUI::ENQUEUE;
 }
+
+void RecoveryUI::NextCheckKeyIsLong(bool is_long_press) {
+}
diff --git a/ui.h b/ui.h
index acb5766..aca7b7b 100644
--- a/ui.h
+++ b/ui.h
@@ -19,6 +19,7 @@
 
 #include <linux/input.h>
 #include <pthread.h>
+#include <time.h>
 
 // Abstract class for controlling the user interface during recovery.
 class RecoveryUI {
@@ -79,6 +80,8 @@
     enum KeyAction { ENQUEUE, TOGGLE, REBOOT, IGNORE };
     virtual KeyAction CheckKey(int key);
 
+    virtual void NextCheckKeyIsLong(bool is_long_press);
+
     // --- menu display ---
 
     // Display some header text followed by a menu of items, which appears
@@ -95,6 +98,9 @@
     // statements will be displayed.
     virtual void EndMenu() = 0;
 
+protected:
+    void EnqueueKey(int key_code);
+
 private:
     // Key event input queue
     pthread_mutex_t key_queue_mutex;
@@ -102,6 +108,7 @@
     int key_queue[256], key_queue_len;
     char key_pressed[KEY_MAX + 1];     // under key_queue_mutex
     int key_last_down;                 // under key_queue_mutex
+    clock_t key_down_time;             // under key_queue_mutex
     int rel_sum;
 
     pthread_t input_t;