2009-03-04 03:28:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-03-08 20:25:05 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2009-03-04 03:28:42 +00:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-03-08 20:25:05 +00:00
|
|
|
#include <sys/stat.h>
|
2009-03-04 03:28:42 +00:00
|
|
|
#include <sys/time.h>
|
2011-03-08 20:25:05 +00:00
|
|
|
#include <sys/types.h>
|
2009-03-04 03:28:42 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
2011-03-08 07:37:27 +00:00
|
|
|
#include <cutils/android_reboot.h>
|
2012-05-11 07:20:12 +00:00
|
|
|
#include <cutils/properties.h>
|
2009-03-04 03:28:42 +00:00
|
|
|
#include "minui/minui.h"
|
2009-07-23 17:16:07 +00:00
|
|
|
#include "recovery_ui.h"
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-06-10 18:26:44 +00:00
|
|
|
extern int __system(const char *command);
|
|
|
|
|
2012-07-15 22:30:43 +00:00
|
|
|
#if defined(BOARD_HAS_NO_SELECT_BUTTON) || defined(BOARD_TOUCH_RECOVERY)
|
2010-07-15 01:37:33 +00:00
|
|
|
static int gShowBackButton = 1;
|
|
|
|
#else
|
|
|
|
static int gShowBackButton = 0;
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 20:55:25 +00:00
|
|
|
#define MAX_COLS 96
|
2009-03-04 03:28:42 +00:00
|
|
|
#define MAX_ROWS 32
|
|
|
|
|
2012-11-18 19:49:50 +00:00
|
|
|
#define MENU_MAX_COLS 64
|
|
|
|
#define MENU_MAX_ROWS 250
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2012-01-27 06:56:00 +00:00
|
|
|
#define MIN_LOG_ROWS 3
|
|
|
|
|
2012-01-27 00:49:33 +00:00
|
|
|
#define CHAR_WIDTH BOARD_RECOVERY_CHAR_WIDTH
|
|
|
|
#define CHAR_HEIGHT BOARD_RECOVERY_CHAR_HEIGHT
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-11-17 00:47:53 +00:00
|
|
|
#define UI_WAIT_KEY_TIMEOUT_SEC 3600
|
2012-05-11 07:20:12 +00:00
|
|
|
#define UI_KEY_REPEAT_INTERVAL 80
|
|
|
|
#define UI_KEY_WAIT_REPEAT 400
|
2011-01-25 21:15:30 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
UIParameters ui_parameters = {
|
2011-03-02 18:38:02 +00:00
|
|
|
6, // indeterminate progress bar frames
|
|
|
|
20, // fps
|
|
|
|
7, // installation icon frames (0 == static image)
|
2011-09-20 21:16:46 +00:00
|
|
|
13, 190, // installation icon overlay offset
|
2011-03-01 22:04:34 +00:00
|
|
|
};
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
static pthread_mutex_t gUpdateMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static gr_surface gBackgroundIcon[NUM_BACKGROUND_ICONS];
|
2011-03-01 22:04:34 +00:00
|
|
|
static gr_surface *gInstallationOverlay;
|
|
|
|
static gr_surface *gProgressBarIndeterminate;
|
2009-10-08 23:32:58 +00:00
|
|
|
static gr_surface gProgressBarEmpty;
|
|
|
|
static gr_surface gProgressBarFill;
|
2012-07-16 02:41:24 +00:00
|
|
|
static gr_surface gBackground;
|
2010-07-03 20:56:45 +00:00
|
|
|
static int ui_has_initialized = 0;
|
2011-06-10 18:26:44 +00:00
|
|
|
static int ui_log_stdout = 1;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
static int boardEnableKeyRepeat = 0;
|
|
|
|
static int boardRepeatableKeys[64], boardNumRepeatableKeys = 0;
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
static const struct { gr_surface* surface; const char *name; } BITMAPS[] = {
|
|
|
|
{ &gBackgroundIcon[BACKGROUND_ICON_INSTALLING], "icon_installing" },
|
|
|
|
{ &gBackgroundIcon[BACKGROUND_ICON_ERROR], "icon_error" },
|
2010-12-19 06:29:27 +00:00
|
|
|
{ &gBackgroundIcon[BACKGROUND_ICON_CLOCKWORK], "icon_clockwork" },
|
2011-09-08 23:55:35 +00:00
|
|
|
{ &gBackgroundIcon[BACKGROUND_ICON_FIRMWARE_INSTALLING], "icon_firmware_install" },
|
|
|
|
{ &gBackgroundIcon[BACKGROUND_ICON_FIRMWARE_ERROR], "icon_firmware_error" },
|
2009-10-08 23:32:58 +00:00
|
|
|
{ &gProgressBarEmpty, "progress_empty" },
|
|
|
|
{ &gProgressBarFill, "progress_fill" },
|
2012-07-16 02:41:24 +00:00
|
|
|
{ &gBackground, "stitch" },
|
2009-03-04 03:28:42 +00:00
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
static int gCurrentIcon = 0;
|
|
|
|
static int gInstallingFrame = 0;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
static enum ProgressBarType {
|
|
|
|
PROGRESSBAR_TYPE_NONE,
|
|
|
|
PROGRESSBAR_TYPE_INDETERMINATE,
|
|
|
|
PROGRESSBAR_TYPE_NORMAL,
|
|
|
|
} gProgressBarType = PROGRESSBAR_TYPE_NONE;
|
|
|
|
|
|
|
|
// Progress bar scope of current operation
|
|
|
|
static float gProgressScopeStart = 0, gProgressScopeSize = 0, gProgress = 0;
|
2011-03-01 22:04:34 +00:00
|
|
|
static double gProgressScopeTime, gProgressScopeDuration;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
// Set to 1 when both graphics pages are the same (except for the progress bar)
|
|
|
|
static int gPagesIdentical = 0;
|
|
|
|
|
|
|
|
// Log text overlay, displayed when a magic key is pressed
|
|
|
|
static char text[MAX_ROWS][MAX_COLS];
|
|
|
|
static int text_cols = 0, text_rows = 0;
|
|
|
|
static int text_col = 0, text_row = 0, text_top = 0;
|
2010-09-01 21:52:22 +00:00
|
|
|
static int show_text = 0;
|
2011-01-25 21:15:30 +00:00
|
|
|
static int show_text_ever = 0; // has show_text ever been 1?
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2010-03-08 15:09:49 +00:00
|
|
|
static char menu[MENU_MAX_ROWS][MENU_MAX_COLS];
|
2009-03-04 03:28:42 +00:00
|
|
|
static int show_menu = 0;
|
|
|
|
static int menu_top = 0, menu_items = 0, menu_sel = 0;
|
2011-06-10 18:26:44 +00:00
|
|
|
static int menu_show_start = 0; // this is line which menu display is starting at
|
2012-01-27 06:56:00 +00:00
|
|
|
static int max_menu_rows;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
// Key event input queue
|
|
|
|
static pthread_mutex_t key_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static pthread_cond_t key_queue_cond = PTHREAD_COND_INITIALIZER;
|
|
|
|
static int key_queue[256], key_queue_len = 0;
|
2012-05-11 07:20:12 +00:00
|
|
|
static unsigned long key_last_repeat[KEY_MAX + 1], key_press_time[KEY_MAX + 1];
|
2009-03-04 03:28:42 +00:00
|
|
|
static volatile char key_pressed[KEY_MAX + 1];
|
|
|
|
|
2012-07-15 22:30:43 +00:00
|
|
|
static void update_screen_locked(void);
|
|
|
|
|
|
|
|
#ifdef BOARD_TOUCH_RECOVERY
|
|
|
|
#include "../../vendor/koush/recovery/touch.c"
|
|
|
|
#endif
|
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
// Return the current time as a double (including fractions of a second).
|
|
|
|
static double now() {
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the given frame over the installation overlay animation. The
|
|
|
|
// background is not cleared or draw with the base icon first; we
|
|
|
|
// assume that the frame already contains some other frame of the
|
|
|
|
// animation. Does nothing if no overlay animation is defined.
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
|
|
|
static void draw_install_overlay_locked(int frame) {
|
|
|
|
if (gInstallationOverlay == NULL) return;
|
|
|
|
gr_surface surface = gInstallationOverlay[frame];
|
|
|
|
int iconWidth = gr_get_width(surface);
|
|
|
|
int iconHeight = gr_get_height(surface);
|
|
|
|
gr_blit(surface, 0, 0, iconWidth, iconHeight,
|
|
|
|
ui_parameters.install_overlay_offset_x,
|
|
|
|
ui_parameters.install_overlay_offset_y);
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
// Clear the screen and draw the currently selected background icon (if any).
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
2011-03-01 22:04:34 +00:00
|
|
|
static void draw_background_locked(int icon)
|
2009-03-04 03:28:42 +00:00
|
|
|
{
|
|
|
|
gPagesIdentical = 0;
|
2012-07-16 02:41:24 +00:00
|
|
|
// gr_color(0, 0, 0, 255);
|
|
|
|
// gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
|
|
|
|
|
|
|
{
|
|
|
|
int bw = gr_get_width(gBackground);
|
|
|
|
int bh = gr_get_height(gBackground);
|
|
|
|
int bx = 0;
|
|
|
|
int by = 0;
|
|
|
|
for (by = 0; by < gr_fb_height(); by += bh) {
|
|
|
|
for (bx = 0; bx < gr_fb_width(); bx += bw) {
|
|
|
|
gr_blit(gBackground, 0, 0, bw, bh, bx, by);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
if (icon) {
|
2011-03-01 22:04:34 +00:00
|
|
|
gr_surface surface = gBackgroundIcon[icon];
|
|
|
|
int iconWidth = gr_get_width(surface);
|
|
|
|
int iconHeight = gr_get_height(surface);
|
2009-03-04 03:28:42 +00:00
|
|
|
int iconX = (gr_fb_width() - iconWidth) / 2;
|
|
|
|
int iconY = (gr_fb_height() - iconHeight) / 2;
|
2011-03-01 22:04:34 +00:00
|
|
|
gr_blit(surface, 0, 0, iconWidth, iconHeight, iconX, iconY);
|
|
|
|
if (icon == BACKGROUND_ICON_INSTALLING) {
|
|
|
|
draw_install_overlay_locked(gInstallingFrame);
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the progress bar (if any) on the screen. Does not flip pages.
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
|
|
|
static void draw_progress_locked()
|
|
|
|
{
|
2011-03-01 22:04:34 +00:00
|
|
|
if (gCurrentIcon == BACKGROUND_ICON_INSTALLING) {
|
|
|
|
draw_install_overlay_locked(gInstallingFrame);
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
if (gProgressBarType != PROGRESSBAR_TYPE_NONE) {
|
|
|
|
int iconHeight = gr_get_height(gBackgroundIcon[BACKGROUND_ICON_INSTALLING]);
|
|
|
|
int width = gr_get_width(gProgressBarEmpty);
|
|
|
|
int height = gr_get_height(gProgressBarEmpty);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
int dx = (gr_fb_width() - width)/2;
|
|
|
|
int dy = (3*gr_fb_height() + iconHeight - 2*height)/4;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
// Erase behind the progress bar (in case this was a progress-only update)
|
|
|
|
gr_color(0, 0, 0, 255);
|
|
|
|
gr_fill(dx, dy, width, height);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL) {
|
|
|
|
float progress = gProgressScopeStart + gProgress * gProgressScopeSize;
|
|
|
|
int pos = (int) (progress * width);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
if (pos > 0) {
|
|
|
|
gr_blit(gProgressBarFill, 0, 0, pos, height, dx, dy);
|
|
|
|
}
|
|
|
|
if (pos < width-1) {
|
|
|
|
gr_blit(gProgressBarEmpty, pos, 0, width-pos, height, dx+pos, dy);
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
if (gProgressBarType == PROGRESSBAR_TYPE_INDETERMINATE) {
|
|
|
|
static int frame = 0;
|
|
|
|
gr_blit(gProgressBarIndeterminate[frame], 0, 0, width, height, dx, dy);
|
|
|
|
frame = (frame + 1) % ui_parameters.indeterminate_frames;
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_text_line(int row, const char* t) {
|
|
|
|
if (t[0] != '\0') {
|
|
|
|
gr_text(0, (row+1)*CHAR_HEIGHT-1, t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 04:14:06 +00:00
|
|
|
//#define MENU_TEXT_COLOR 255, 160, 49, 255
|
|
|
|
#define MENU_TEXT_COLOR 0, 191, 255, 255
|
2010-02-26 00:51:45 +00:00
|
|
|
#define NORMAL_TEXT_COLOR 200, 200, 200, 255
|
|
|
|
#define HEADER_TEXT_COLOR NORMAL_TEXT_COLOR
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
// Redraw everything on the screen. Does not flip pages.
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
|
|
|
static void draw_screen_locked(void)
|
|
|
|
{
|
2010-07-03 20:56:45 +00:00
|
|
|
if (!ui_has_initialized) return;
|
2009-03-04 03:28:42 +00:00
|
|
|
draw_background_locked(gCurrentIcon);
|
|
|
|
draw_progress_locked();
|
|
|
|
|
|
|
|
if (show_text) {
|
2012-07-17 02:45:07 +00:00
|
|
|
// don't "disable" the background anymore with this...
|
|
|
|
// gr_color(0, 0, 0, 160);
|
|
|
|
// gr_fill(0, 0, gr_fb_width(), gr_fb_height());
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2012-01-27 06:56:00 +00:00
|
|
|
int total_rows = gr_fb_height() / CHAR_HEIGHT;
|
2009-03-04 03:28:42 +00:00
|
|
|
int i = 0;
|
2010-03-08 15:09:49 +00:00
|
|
|
int j = 0;
|
|
|
|
int row = 0; // current row that we are drawing on
|
2009-03-04 03:28:42 +00:00
|
|
|
if (show_menu) {
|
2012-07-15 22:30:43 +00:00
|
|
|
#ifndef BOARD_TOUCH_RECOVERY
|
2010-02-26 00:51:45 +00:00
|
|
|
gr_color(MENU_TEXT_COLOR);
|
2010-03-08 15:09:49 +00:00
|
|
|
gr_fill(0, (menu_top + menu_sel - menu_show_start) * CHAR_HEIGHT,
|
|
|
|
gr_fb_width(), (menu_top + menu_sel - menu_show_start + 1)*CHAR_HEIGHT+1);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2010-02-26 00:51:45 +00:00
|
|
|
gr_color(HEADER_TEXT_COLOR);
|
2010-03-08 15:09:49 +00:00
|
|
|
for (i = 0; i < menu_top; ++i) {
|
|
|
|
draw_text_line(i, menu[i]);
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
|
2012-02-01 04:02:38 +00:00
|
|
|
if (menu_items - menu_show_start + menu_top >= max_menu_rows)
|
|
|
|
j = max_menu_rows - menu_top;
|
2010-03-08 15:09:49 +00:00
|
|
|
else
|
|
|
|
j = menu_items - menu_show_start;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2010-03-08 15:09:49 +00:00
|
|
|
gr_color(MENU_TEXT_COLOR);
|
|
|
|
for (i = menu_show_start + menu_top; i < (menu_show_start + menu_top + j); ++i) {
|
2009-03-04 03:28:42 +00:00
|
|
|
if (i == menu_top + menu_sel) {
|
|
|
|
gr_color(255, 255, 255, 255);
|
2010-03-08 15:09:49 +00:00
|
|
|
draw_text_line(i - menu_show_start , menu[i]);
|
2010-02-26 00:51:45 +00:00
|
|
|
gr_color(MENU_TEXT_COLOR);
|
2009-03-04 03:28:42 +00:00
|
|
|
} else {
|
2010-03-08 15:09:49 +00:00
|
|
|
gr_color(MENU_TEXT_COLOR);
|
|
|
|
draw_text_line(i - menu_show_start, menu[i]);
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2010-03-08 15:09:49 +00:00
|
|
|
row++;
|
2012-02-01 04:02:38 +00:00
|
|
|
if (row >= max_menu_rows)
|
2012-01-27 06:56:00 +00:00
|
|
|
break;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2012-01-15 04:51:58 +00:00
|
|
|
|
2012-07-18 04:49:23 +00:00
|
|
|
gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
|
|
|
|
gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
|
2012-07-15 22:30:43 +00:00
|
|
|
#else
|
|
|
|
row = draw_touch_menu(menu, menu_items, menu_top, menu_sel, menu_show_start);
|
|
|
|
#endif
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 00:51:45 +00:00
|
|
|
gr_color(NORMAL_TEXT_COLOR);
|
2012-01-27 06:56:00 +00:00
|
|
|
int cur_row = text_row;
|
|
|
|
int available_rows = total_rows - row - 1;
|
|
|
|
int start_row = row + 1;
|
|
|
|
if (available_rows < MAX_ROWS)
|
|
|
|
cur_row = (cur_row + (MAX_ROWS - available_rows)) % MAX_ROWS;
|
|
|
|
else
|
|
|
|
start_row = total_rows - MAX_ROWS;
|
|
|
|
|
|
|
|
int r;
|
|
|
|
for (r = 0; r < (available_rows < MAX_ROWS ? available_rows : MAX_ROWS); r++) {
|
|
|
|
draw_text_line(start_row + r, text[(cur_row + r) % MAX_ROWS]);
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redraw everything on the screen and flip the screen (make it visible).
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
|
|
|
static void update_screen_locked(void)
|
|
|
|
{
|
2010-07-03 20:56:45 +00:00
|
|
|
if (!ui_has_initialized) return;
|
2009-03-04 03:28:42 +00:00
|
|
|
draw_screen_locked();
|
|
|
|
gr_flip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates only the progress bar, if possible, otherwise redraws the screen.
|
|
|
|
// Should only be called with gUpdateMutex locked.
|
|
|
|
static void update_progress_locked(void)
|
|
|
|
{
|
2010-07-03 20:56:45 +00:00
|
|
|
if (!ui_has_initialized) return;
|
2009-03-04 03:28:42 +00:00
|
|
|
if (show_text || !gPagesIdentical) {
|
|
|
|
draw_screen_locked(); // Must redraw the whole screen
|
|
|
|
gPagesIdentical = 1;
|
|
|
|
} else {
|
2011-03-01 22:04:34 +00:00
|
|
|
draw_progress_locked(); // Draw only the progress bar and overlays
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
gr_flip();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keeps the progress bar updated, even when the process is otherwise busy.
|
|
|
|
static void *progress_thread(void *cookie)
|
|
|
|
{
|
2011-03-01 22:04:34 +00:00
|
|
|
double interval = 1.0 / ui_parameters.update_fps;
|
2009-03-04 03:28:42 +00:00
|
|
|
for (;;) {
|
2011-03-01 22:04:34 +00:00
|
|
|
double start = now();
|
2009-03-04 03:28:42 +00:00
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
int redraw = 0;
|
|
|
|
|
|
|
|
// update the installation animation, if active
|
|
|
|
// skip this if we have a text overlay (too expensive to update)
|
|
|
|
if (gCurrentIcon == BACKGROUND_ICON_INSTALLING &&
|
|
|
|
ui_parameters.installing_frames > 0 &&
|
|
|
|
!show_text) {
|
|
|
|
gInstallingFrame =
|
|
|
|
(gInstallingFrame + 1) % ui_parameters.installing_frames;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
// update the progress bar animation, if active
|
|
|
|
// skip this if we have a text overlay (too expensive to update)
|
|
|
|
if (gProgressBarType == PROGRESSBAR_TYPE_INDETERMINATE && !show_text) {
|
2011-03-01 22:04:34 +00:00
|
|
|
redraw = 1;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move the progress bar forward on timed intervals, if configured
|
|
|
|
int duration = gProgressScopeDuration;
|
|
|
|
if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL && duration > 0) {
|
2011-03-01 22:04:34 +00:00
|
|
|
double elapsed = now() - gProgressScopeTime;
|
2009-03-04 03:28:42 +00:00
|
|
|
float progress = 1.0 * elapsed / duration;
|
|
|
|
if (progress > 1.0) progress = 1.0;
|
|
|
|
if (progress > gProgress) {
|
|
|
|
gProgress = progress;
|
2011-03-01 22:04:34 +00:00
|
|
|
redraw = 1;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-01 22:04:34 +00:00
|
|
|
if (redraw) update_progress_locked();
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
2011-03-01 22:04:34 +00:00
|
|
|
double end = now();
|
|
|
|
// minimum of 20ms delay between frames
|
|
|
|
double delay = interval - (end-start);
|
|
|
|
if (delay < 0.02) delay = 0.02;
|
|
|
|
usleep((long)(delay * 1000000));
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-30 18:59:45 +00:00
|
|
|
static int rel_sum = 0;
|
|
|
|
|
|
|
|
static int input_callback(int fd, short revents, void *data)
|
2009-03-04 03:28:42 +00:00
|
|
|
{
|
2011-08-30 18:59:45 +00:00
|
|
|
struct input_event ev;
|
|
|
|
int ret;
|
2009-03-04 03:28:42 +00:00
|
|
|
int fake_key = 0;
|
2011-08-30 18:59:45 +00:00
|
|
|
|
|
|
|
ret = ev_get_input(fd, revents, &ev);
|
|
|
|
if (ret)
|
|
|
|
return -1;
|
|
|
|
|
2012-07-15 22:30:43 +00:00
|
|
|
#ifdef BOARD_TOUCH_RECOVERY
|
|
|
|
if (touch_handle_input(fd, ev))
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2011-08-30 18:59:45 +00:00
|
|
|
if (ev.type == EV_SYN) {
|
|
|
|
return 0;
|
|
|
|
} else if (ev.type == EV_REL) {
|
|
|
|
if (ev.code == REL_Y) {
|
|
|
|
// accumulate the up or down motion reported by
|
|
|
|
// the trackball. When it exceeds a threshold
|
|
|
|
// (positive or negative), fake an up/down
|
|
|
|
// key event.
|
|
|
|
rel_sum += ev.value;
|
|
|
|
if (rel_sum > 3) {
|
|
|
|
fake_key = 1;
|
|
|
|
ev.type = EV_KEY;
|
|
|
|
ev.code = KEY_DOWN;
|
|
|
|
ev.value = 1;
|
|
|
|
rel_sum = 0;
|
|
|
|
} else if (rel_sum < -3) {
|
|
|
|
fake_key = 1;
|
|
|
|
ev.type = EV_KEY;
|
|
|
|
ev.code = KEY_UP;
|
|
|
|
ev.value = 1;
|
2009-03-04 03:28:42 +00:00
|
|
|
rel_sum = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 18:59:45 +00:00
|
|
|
} else {
|
|
|
|
rel_sum = 0;
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-08-30 18:59:45 +00:00
|
|
|
if (ev.type != EV_KEY || ev.code > KEY_MAX)
|
|
|
|
return 0;
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
if (ev.value == 2) {
|
|
|
|
boardEnableKeyRepeat = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 18:59:45 +00:00
|
|
|
pthread_mutex_lock(&key_queue_mutex);
|
|
|
|
if (!fake_key) {
|
|
|
|
// our "fake" keys only report a key-down event (no
|
|
|
|
// key-up), so don't record them in the key_pressed
|
|
|
|
// table.
|
|
|
|
key_pressed[ev.code] = ev.value;
|
|
|
|
}
|
|
|
|
const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
|
|
|
|
if (ev.value > 0 && key_queue_len < queue_max) {
|
|
|
|
key_queue[key_queue_len++] = ev.code;
|
2012-05-11 07:20:12 +00:00
|
|
|
|
|
|
|
if (boardEnableKeyRepeat) {
|
|
|
|
struct timeval now;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
|
|
|
|
key_press_time[ev.code] = (now.tv_sec * 1000) + (now.tv_usec / 1000);
|
|
|
|
key_last_repeat[ev.code] = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 18:59:45 +00:00
|
|
|
pthread_cond_signal(&key_queue_cond);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
|
|
|
|
if (ev.value > 0 && device_toggle_display(key_pressed, ev.code)) {
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
show_text = !show_text;
|
|
|
|
if (show_text) show_text_ever = 1;
|
|
|
|
update_screen_locked();
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.value > 0 && device_reboot_now(key_pressed, ev.code)) {
|
|
|
|
android_reboot(ANDROID_RB_RESTART, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads input events, handles special hot keys, and adds to the key queue.
|
|
|
|
static void *input_thread(void *cookie)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
if (!ev_wait(-1))
|
|
|
|
ev_dispatch();
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_init(void)
|
|
|
|
{
|
2010-07-03 20:56:45 +00:00
|
|
|
ui_has_initialized = 1;
|
2009-03-04 03:28:42 +00:00
|
|
|
gr_init();
|
2011-08-30 18:59:45 +00:00
|
|
|
ev_init(input_callback, NULL);
|
2012-07-15 22:30:43 +00:00
|
|
|
#ifdef BOARD_TOUCH_RECOVERY
|
|
|
|
touch_init();
|
|
|
|
#endif
|
2009-03-04 03:28:42 +00:00
|
|
|
|
|
|
|
text_col = text_row = 0;
|
|
|
|
text_rows = gr_fb_height() / CHAR_HEIGHT;
|
2012-01-27 06:56:00 +00:00
|
|
|
max_menu_rows = text_rows - MIN_LOG_ROWS;
|
2012-07-15 22:30:43 +00:00
|
|
|
#ifdef BOARD_TOUCH_RECOVERY
|
|
|
|
max_menu_rows = get_max_menu_rows(max_menu_rows);
|
|
|
|
#endif
|
2012-02-01 04:02:38 +00:00
|
|
|
if (max_menu_rows > MENU_MAX_ROWS)
|
|
|
|
max_menu_rows = MENU_MAX_ROWS;
|
2009-03-04 03:28:42 +00:00
|
|
|
if (text_rows > MAX_ROWS) text_rows = MAX_ROWS;
|
|
|
|
text_top = 1;
|
|
|
|
|
|
|
|
text_cols = gr_fb_width() / CHAR_WIDTH;
|
|
|
|
if (text_cols > MAX_COLS - 1) text_cols = MAX_COLS - 1;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; BITMAPS[i].name != NULL; ++i) {
|
|
|
|
int result = res_create_surface(BITMAPS[i].name, BITMAPS[i].surface);
|
|
|
|
if (result < 0) {
|
2011-03-01 22:04:34 +00:00
|
|
|
LOGE("Missing bitmap %s\n(Code %d)\n", BITMAPS[i].name, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gProgressBarIndeterminate = malloc(ui_parameters.indeterminate_frames *
|
|
|
|
sizeof(gr_surface));
|
|
|
|
for (i = 0; i < ui_parameters.indeterminate_frames; ++i) {
|
|
|
|
char filename[40];
|
2011-03-02 18:38:02 +00:00
|
|
|
// "indeterminate01.png", "indeterminate02.png", ...
|
|
|
|
sprintf(filename, "indeterminate%02d", i+1);
|
2011-03-01 22:04:34 +00:00
|
|
|
int result = res_create_surface(filename, gProgressBarIndeterminate+i);
|
|
|
|
if (result < 0) {
|
|
|
|
LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui_parameters.installing_frames > 0) {
|
|
|
|
gInstallationOverlay = malloc(ui_parameters.installing_frames *
|
|
|
|
sizeof(gr_surface));
|
|
|
|
for (i = 0; i < ui_parameters.installing_frames; ++i) {
|
|
|
|
char filename[40];
|
2011-03-02 18:38:02 +00:00
|
|
|
// "icon_installing_overlay01.png",
|
|
|
|
// "icon_installing_overlay02.png", ...
|
|
|
|
sprintf(filename, "icon_installing_overlay%02d", i+1);
|
2011-03-01 22:04:34 +00:00
|
|
|
int result = res_create_surface(filename, gInstallationOverlay+i);
|
|
|
|
if (result < 0) {
|
|
|
|
LOGE("Missing bitmap %s\n(Code %d)\n", filename, result);
|
2009-09-15 15:50:04 +00:00
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2011-03-01 22:04:34 +00:00
|
|
|
|
|
|
|
// Adjust the offset to account for the positioning of the
|
|
|
|
// base image on the screen.
|
|
|
|
if (gBackgroundIcon[BACKGROUND_ICON_INSTALLING] != NULL) {
|
|
|
|
gr_surface bg = gBackgroundIcon[BACKGROUND_ICON_INSTALLING];
|
|
|
|
ui_parameters.install_overlay_offset_x +=
|
|
|
|
(gr_fb_width() - gr_get_width(bg)) / 2;
|
|
|
|
ui_parameters.install_overlay_offset_y +=
|
|
|
|
(gr_fb_height() - gr_get_height(bg)) / 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gInstallationOverlay = NULL;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
char enable_key_repeat[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.cwm.enable_key_repeat", enable_key_repeat, "");
|
|
|
|
if (!strcmp(enable_key_repeat, "true") || !strcmp(enable_key_repeat, "1")) {
|
|
|
|
boardEnableKeyRepeat = 1;
|
|
|
|
|
|
|
|
char key_list[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.cwm.repeatable_keys", key_list, "");
|
|
|
|
if (strlen(key_list) == 0) {
|
|
|
|
boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_UP;
|
|
|
|
boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_DOWN;
|
|
|
|
boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_VOLUMEUP;
|
|
|
|
boardRepeatableKeys[boardNumRepeatableKeys++] = KEY_VOLUMEDOWN;
|
|
|
|
} else {
|
|
|
|
char *pch = strtok(key_list, ",");
|
|
|
|
while (pch != NULL) {
|
|
|
|
boardRepeatableKeys[boardNumRepeatableKeys++] = atoi(pch);
|
|
|
|
pch = strtok(NULL, ",");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, NULL, progress_thread, NULL);
|
|
|
|
pthread_create(&t, NULL, input_thread, NULL);
|
|
|
|
}
|
|
|
|
|
2010-07-01 06:17:53 +00:00
|
|
|
char *ui_copy_image(int icon, int *width, int *height, int *bpp) {
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
2012-11-28 20:12:29 +00:00
|
|
|
draw_background_locked(icon);
|
2010-07-01 06:17:53 +00:00
|
|
|
*width = gr_fb_width();
|
|
|
|
*height = gr_fb_height();
|
|
|
|
*bpp = sizeof(gr_pixel) * 8;
|
|
|
|
int size = *width * *height * sizeof(gr_pixel);
|
|
|
|
char *ret = malloc(size);
|
|
|
|
if (ret == NULL) {
|
|
|
|
LOGE("Can't allocate %d bytes for image\n", size);
|
|
|
|
} else {
|
|
|
|
memcpy(ret, gr_fb_data(), size);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
void ui_set_background(int icon)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
2011-03-01 22:04:34 +00:00
|
|
|
gCurrentIcon = icon;
|
2009-03-04 03:28:42 +00:00
|
|
|
update_screen_locked();
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_show_indeterminate_progress()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
if (gProgressBarType != PROGRESSBAR_TYPE_INDETERMINATE) {
|
|
|
|
gProgressBarType = PROGRESSBAR_TYPE_INDETERMINATE;
|
|
|
|
update_progress_locked();
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_show_progress(float portion, int seconds)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
gProgressBarType = PROGRESSBAR_TYPE_NORMAL;
|
|
|
|
gProgressScopeStart += gProgressScopeSize;
|
|
|
|
gProgressScopeSize = portion;
|
2011-03-01 22:04:34 +00:00
|
|
|
gProgressScopeTime = now();
|
2009-03-04 03:28:42 +00:00
|
|
|
gProgressScopeDuration = seconds;
|
|
|
|
gProgress = 0;
|
|
|
|
update_progress_locked();
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_set_progress(float fraction)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
if (fraction < 0.0) fraction = 0.0;
|
|
|
|
if (fraction > 1.0) fraction = 1.0;
|
|
|
|
if (gProgressBarType == PROGRESSBAR_TYPE_NORMAL && fraction > gProgress) {
|
|
|
|
// Skip updates that aren't visibly different.
|
|
|
|
int width = gr_get_width(gProgressBarIndeterminate[0]);
|
|
|
|
float scale = width * gProgressScopeSize;
|
|
|
|
if ((int) (gProgress * scale) != (int) (fraction * scale)) {
|
|
|
|
gProgress = fraction;
|
|
|
|
update_progress_locked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_reset_progress()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
gProgressBarType = PROGRESSBAR_TYPE_NONE;
|
|
|
|
gProgressScopeStart = gProgressScopeSize = 0;
|
|
|
|
gProgressScopeTime = gProgressScopeDuration = 0;
|
|
|
|
gProgress = 0;
|
|
|
|
update_screen_locked();
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
2012-07-03 00:47:50 +00:00
|
|
|
static long delta_milliseconds(struct timeval from, struct timeval to) {
|
|
|
|
long delta_sec = (to.tv_sec - from.tv_sec)*1000;
|
|
|
|
long delta_usec = (to.tv_usec - from.tv_usec)/1000;
|
|
|
|
return (delta_sec + delta_usec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct timeval lastupdate = (struct timeval) {0};
|
|
|
|
static int ui_nice = 0;
|
2012-07-05 03:08:05 +00:00
|
|
|
static int ui_niced = 0;
|
2012-07-03 00:47:50 +00:00
|
|
|
void ui_set_nice(int enabled) {
|
|
|
|
ui_nice = enabled;
|
|
|
|
}
|
2012-07-05 03:08:05 +00:00
|
|
|
#define NICE_INTERVAL 100
|
|
|
|
int ui_was_niced() {
|
|
|
|
return ui_niced;
|
|
|
|
}
|
|
|
|
int ui_get_text_cols() {
|
|
|
|
return text_cols;
|
|
|
|
}
|
2012-07-03 00:47:50 +00:00
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
void ui_print(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, 256, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2011-06-10 18:26:44 +00:00
|
|
|
if (ui_log_stdout)
|
|
|
|
fputs(buf, stdout);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2012-07-03 00:47:50 +00:00
|
|
|
// if we are running 'ui nice' mode, we do not want to force a screen update
|
|
|
|
// for this line if not necessary.
|
2012-07-05 03:08:05 +00:00
|
|
|
ui_niced = 0;
|
2012-07-03 00:47:50 +00:00
|
|
|
if (ui_nice) {
|
|
|
|
struct timeval curtime;
|
|
|
|
gettimeofday(&curtime, NULL);
|
2012-07-15 22:30:43 +00:00
|
|
|
long ms = delta_milliseconds(lastupdate, curtime);
|
2012-07-16 02:41:24 +00:00
|
|
|
if (ms < NICE_INTERVAL && ms >= 0) {
|
2012-07-05 03:08:05 +00:00
|
|
|
ui_niced = 1;
|
2012-07-03 00:47:50 +00:00
|
|
|
return;
|
2012-07-05 03:08:05 +00:00
|
|
|
}
|
2012-07-03 00:47:50 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
// This can get called before ui_init(), so be careful.
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
2012-07-16 02:41:24 +00:00
|
|
|
gettimeofday(&lastupdate, NULL);
|
2009-03-04 03:28:42 +00:00
|
|
|
if (text_rows > 0 && text_cols > 0) {
|
|
|
|
char *ptr;
|
|
|
|
for (ptr = buf; *ptr != '\0'; ++ptr) {
|
|
|
|
if (*ptr == '\n' || text_col >= text_cols) {
|
|
|
|
text[text_row][text_col] = '\0';
|
|
|
|
text_col = 0;
|
|
|
|
text_row = (text_row + 1) % text_rows;
|
|
|
|
if (text_row == text_top) text_top = (text_top + 1) % text_rows;
|
|
|
|
}
|
|
|
|
if (*ptr != '\n') text[text_row][text_col++] = *ptr;
|
|
|
|
}
|
|
|
|
text[text_row][text_col] = '\0';
|
|
|
|
update_screen_locked();
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
2011-06-10 18:26:44 +00:00
|
|
|
void ui_printlogtail(int nb_lines) {
|
|
|
|
char * log_data;
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
FILE * f;
|
|
|
|
int line=0;
|
|
|
|
//don't log output to recovery.log
|
|
|
|
ui_log_stdout=0;
|
|
|
|
sprintf(tmp, "tail -n %d /tmp/recovery.log > /tmp/tail.log", nb_lines);
|
|
|
|
__system(tmp);
|
|
|
|
f = fopen("/tmp/tail.log", "rb");
|
|
|
|
if (f != NULL) {
|
|
|
|
while (line < nb_lines) {
|
|
|
|
log_data = fgets(tmp, PATH_MAX, f);
|
|
|
|
if (log_data == NULL) break;
|
|
|
|
ui_print("%s", tmp);
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
ui_log_stdout=1;
|
|
|
|
}
|
|
|
|
|
2010-02-26 00:51:45 +00:00
|
|
|
#define MENU_ITEM_HEADER " - "
|
|
|
|
#define MENU_ITEM_HEADER_LENGTH strlen(MENU_ITEM_HEADER)
|
|
|
|
|
2010-12-19 01:42:31 +00:00
|
|
|
int ui_start_menu(char** headers, char** items, int initial_selection) {
|
2009-03-04 03:28:42 +00:00
|
|
|
int i;
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
if (text_rows > 0 && text_cols > 0) {
|
|
|
|
for (i = 0; i < text_rows; ++i) {
|
|
|
|
if (headers[i] == NULL) break;
|
|
|
|
strncpy(menu[i], headers[i], text_cols-1);
|
|
|
|
menu[i][text_cols-1] = '\0';
|
|
|
|
}
|
|
|
|
menu_top = i;
|
2010-03-08 15:09:49 +00:00
|
|
|
for (; i < MENU_MAX_ROWS; ++i) {
|
2009-03-04 03:28:42 +00:00
|
|
|
if (items[i-menu_top] == NULL) break;
|
2010-02-26 00:51:45 +00:00
|
|
|
strcpy(menu[i], MENU_ITEM_HEADER);
|
2012-01-27 06:56:00 +00:00
|
|
|
strncpy(menu[i] + MENU_ITEM_HEADER_LENGTH, items[i-menu_top], MENU_MAX_COLS - 1 - MENU_ITEM_HEADER_LENGTH);
|
|
|
|
menu[i][MENU_MAX_COLS-1] = '\0';
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
2010-07-15 01:37:33 +00:00
|
|
|
|
2012-07-18 04:49:23 +00:00
|
|
|
if (gShowBackButton && !ui_root_menu) {
|
2010-07-15 01:37:33 +00:00
|
|
|
strcpy(menu[i], " - +++++Go Back+++++");
|
|
|
|
++i;
|
|
|
|
}
|
2010-03-08 15:09:49 +00:00
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
menu_items = i - menu_top;
|
|
|
|
show_menu = 1;
|
2010-12-19 01:42:31 +00:00
|
|
|
menu_sel = menu_show_start = initial_selection;
|
2009-03-04 03:28:42 +00:00
|
|
|
update_screen_locked();
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
2012-07-18 04:49:23 +00:00
|
|
|
if (gShowBackButton && !ui_root_menu) {
|
2010-07-15 01:37:33 +00:00
|
|
|
return menu_items - 1;
|
|
|
|
}
|
2010-06-09 19:19:41 +00:00
|
|
|
return menu_items;
|
2009-03-04 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ui_menu_select(int sel) {
|
|
|
|
int old_sel;
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
if (show_menu > 0) {
|
|
|
|
old_sel = menu_sel;
|
|
|
|
menu_sel = sel;
|
2010-03-08 15:09:49 +00:00
|
|
|
|
2012-07-18 04:49:23 +00:00
|
|
|
if (menu_sel < 0) menu_sel = menu_items + menu_sel;
|
|
|
|
if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;
|
2010-03-08 15:09:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (menu_sel < menu_show_start && menu_show_start > 0) {
|
2010-05-24 23:43:39 +00:00
|
|
|
menu_show_start = menu_sel;
|
2010-03-08 15:09:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-27 06:56:00 +00:00
|
|
|
if (menu_sel - menu_show_start + menu_top >= max_menu_rows) {
|
|
|
|
menu_show_start = menu_sel + menu_top - max_menu_rows + 1;
|
2010-03-08 15:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
sel = menu_sel;
|
2010-03-08 15:09:49 +00:00
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
if (menu_sel != old_sel) update_screen_locked();
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_end_menu() {
|
|
|
|
int i;
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
if (show_menu > 0 && text_rows > 0 && text_cols > 0) {
|
|
|
|
show_menu = 0;
|
|
|
|
update_screen_locked();
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_text_visible()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
int visible = show_text;
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2011-01-25 21:15:30 +00:00
|
|
|
int ui_text_ever_visible()
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
int ever_visible = show_text_ever;
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
return ever_visible;
|
|
|
|
}
|
|
|
|
|
2010-09-03 18:00:13 +00:00
|
|
|
void ui_show_text(int visible)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
show_text = visible;
|
2011-01-25 21:15:30 +00:00
|
|
|
if (show_text) show_text_ever = 1;
|
2010-09-03 18:00:13 +00:00
|
|
|
update_screen_locked();
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
|
|
|
|
2011-03-08 20:25:05 +00:00
|
|
|
// Return true if USB is connected.
|
|
|
|
static int usb_connected() {
|
2011-06-25 00:54:19 +00:00
|
|
|
int fd = open("/sys/class/android_usb/android0/state", O_RDONLY);
|
2011-03-08 20:25:05 +00:00
|
|
|
if (fd < 0) {
|
2011-06-25 00:54:19 +00:00
|
|
|
printf("failed to open /sys/class/android_usb/android0/state: %s\n",
|
2011-03-08 20:25:05 +00:00
|
|
|
strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf;
|
2011-06-25 00:54:19 +00:00
|
|
|
/* USB is connected if android_usb state is CONNECTED or CONFIGURED */
|
|
|
|
int connected = (read(fd, &buf, 1) == 1) && (buf == 'C');
|
2011-03-08 20:25:05 +00:00
|
|
|
if (close(fd) < 0) {
|
2011-06-25 00:54:19 +00:00
|
|
|
printf("failed to close /sys/class/android_usb/android0/state: %s\n",
|
2011-03-08 20:25:05 +00:00
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
return connected;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
int ui_wait_key()
|
|
|
|
{
|
2012-05-11 07:20:12 +00:00
|
|
|
if (boardEnableKeyRepeat) return ui_wait_key_with_repeat();
|
2009-03-04 03:28:42 +00:00
|
|
|
pthread_mutex_lock(&key_queue_mutex);
|
|
|
|
|
2011-03-08 20:25:05 +00:00
|
|
|
// 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);
|
2009-03-04 03:28:42 +00:00
|
|
|
|
2011-01-25 21:15:30 +00:00
|
|
|
int key = -1;
|
|
|
|
if (key_queue_len > 0) {
|
|
|
|
key = key_queue[0];
|
|
|
|
memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len);
|
|
|
|
}
|
2009-03-04 03:28:42 +00:00
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
// util for ui_wait_key_with_repeat
|
|
|
|
int key_can_repeat(int key)
|
|
|
|
{
|
|
|
|
int k = 0;
|
|
|
|
for (;k < boardNumRepeatableKeys; ++k) {
|
|
|
|
if (boardRepeatableKeys[k] == key) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (k < boardNumRepeatableKeys) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
int ui_wait_key_with_repeat()
|
|
|
|
{
|
|
|
|
int key = -1;
|
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
// Loop to wait for more keys.
|
2012-05-11 07:20:12 +00:00
|
|
|
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;
|
2012-08-17 07:38:01 +00:00
|
|
|
pthread_mutex_lock(&key_queue_mutex);
|
2012-05-11 07:20:12 +00:00
|
|
|
while (key_queue_len == 0 && rc != ETIMEDOUT) {
|
|
|
|
rc = pthread_cond_timedwait(&key_queue_cond, &key_queue_mutex,
|
|
|
|
&timeout);
|
|
|
|
}
|
2012-08-17 07:38:01 +00:00
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
if (rc == ETIMEDOUT && !usb_connected()) {
|
2012-08-18 04:37:26 +00:00
|
|
|
return -1;
|
2012-08-17 07:38:01 +00:00
|
|
|
}
|
2012-05-11 07:20:12 +00:00
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
// Loop to wait wait for more keys, or repeated keys to be ready.
|
|
|
|
while (1) {
|
2012-05-11 07:20:12 +00:00
|
|
|
unsigned long now_msec;
|
|
|
|
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
now_msec = (now.tv_sec * 1000) + (now.tv_usec / 1000);
|
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
pthread_mutex_lock(&key_queue_mutex);
|
|
|
|
|
|
|
|
// Replacement for the while conditional, so we don't have to lock the entire
|
|
|
|
// loop, because that prevents the input system from touching the variables while
|
|
|
|
// the loop is running which causes problems.
|
|
|
|
if (key_queue_len == 0) {
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
key = key_queue[0];
|
|
|
|
memcpy(&key_queue[0], &key_queue[1], sizeof(int) * --key_queue_len);
|
2012-08-17 07:38:01 +00:00
|
|
|
|
|
|
|
// sanity check the returned key.
|
|
|
|
if (key < 0) {
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
return key;
|
|
|
|
}
|
2012-05-11 07:20:12 +00:00
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
// Check for already released keys and drop them if they've repeated.
|
|
|
|
if (!key_pressed[key] && key_last_repeat[key] > 0) {
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
continue;
|
2012-05-11 07:20:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-18 04:37:26 +00:00
|
|
|
if (key_can_repeat(key)) {
|
|
|
|
// Re-add the key if a repeat is expected, since we just popped it. The
|
|
|
|
// if below will determine when the key is actually repeated (returned)
|
|
|
|
// in the mean time, the key will be passed through the queue over and
|
|
|
|
// over and re-evaluated each time.
|
|
|
|
if (key_pressed[key]) {
|
|
|
|
key_queue[key_queue_len] = key;
|
|
|
|
key_queue_len++;
|
2012-05-11 07:20:12 +00:00
|
|
|
}
|
2012-08-18 04:37:26 +00:00
|
|
|
if ((now_msec > key_press_time[key] + UI_KEY_WAIT_REPEAT && now_msec > key_last_repeat[key] + UI_KEY_REPEAT_INTERVAL) ||
|
|
|
|
key_last_repeat[key] == 0) {
|
2012-05-11 07:20:12 +00:00
|
|
|
key_last_repeat[key] = now_msec;
|
2012-08-18 04:37:26 +00:00
|
|
|
} else {
|
|
|
|
// Not ready
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
2012-05-11 07:20:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-08-17 07:38:01 +00:00
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
2012-05-11 07:20:12 +00:00
|
|
|
return key;
|
|
|
|
}
|
2012-08-18 04:37:26 +00:00
|
|
|
} while (1);
|
2012-08-17 07:38:01 +00:00
|
|
|
|
2012-05-11 07:20:12 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:28:42 +00:00
|
|
|
int ui_key_pressed(int key)
|
|
|
|
{
|
|
|
|
// This is a volatile static array, don't bother locking
|
|
|
|
return key_pressed[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_clear_key_queue() {
|
|
|
|
pthread_mutex_lock(&key_queue_mutex);
|
|
|
|
key_queue_len = 0;
|
|
|
|
pthread_mutex_unlock(&key_queue_mutex);
|
|
|
|
}
|
2010-02-19 22:17:22 +00:00
|
|
|
|
2010-02-26 22:14:23 +00:00
|
|
|
void ui_set_show_text(int value) {
|
|
|
|
show_text = value;
|
2010-02-19 22:17:22 +00:00
|
|
|
}
|
2010-07-15 01:37:33 +00:00
|
|
|
|
|
|
|
void ui_set_showing_back_button(int showBackButton) {
|
|
|
|
gShowBackButton = showBackButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_get_showing_back_button() {
|
|
|
|
return gShowBackButton;
|
2010-07-19 15:43:05 +00:00
|
|
|
}
|
2012-07-15 22:30:43 +00:00
|
|
|
|
2012-07-18 04:49:23 +00:00
|
|
|
int ui_is_showing_back_button() {
|
|
|
|
return gShowBackButton && !ui_root_menu;
|
|
|
|
}
|
|
|
|
|
2012-07-15 22:30:43 +00:00
|
|
|
int ui_get_selected_item() {
|
|
|
|
return menu_sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ui_handle_key(int key, int visible) {
|
|
|
|
#ifdef BOARD_TOUCH_RECOVERY
|
|
|
|
return touch_handle_key(key, visible);
|
|
|
|
#else
|
|
|
|
return device_handle_key(key, visible);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_delete_line() {
|
|
|
|
pthread_mutex_lock(&gUpdateMutex);
|
|
|
|
text[text_row][0] = '\0';
|
|
|
|
text_row = (text_row - 1 + text_rows) % text_rows;
|
|
|
|
text_col = 0;
|
|
|
|
pthread_mutex_unlock(&gUpdateMutex);
|
|
|
|
}
|
2012-07-16 02:41:24 +00:00
|
|
|
|
|
|
|
void ui_increment_frame() {
|
|
|
|
gInstallingFrame =
|
|
|
|
(gInstallingFrame + 1) % ui_parameters.installing_frames;
|
2012-08-18 04:37:26 +00:00
|
|
|
}
|