void ScreenRecoveryUI::SetProgress(float fraction)
{
    pthread_mutex_lock(&updateMutex);
    if (fraction < 0.0) fraction = 0.0;
    if (fraction > 1.0) fraction = 1.0;
    if (progressBarType == DETERMINATE && fraction > progress) {
        // Skip updates that aren't visibly different.
        int width = gr_get_width(progressBarEmpty);
        float scale = width * progressScopeSize;
        if ((int) (progress * scale) != (int) (fraction * scale)) {
            progress = fraction;
            update_screen_locked();
        }
    }
    pthread_mutex_unlock(&updateMutex);
}
int ScreenRecoveryUI::SelectMenu(int sel) {
    pthread_mutex_lock(&updateMutex);
    if (show_menu) {
        int old_sel = menu_sel;
        menu_sel = sel;

        // Wrap at top and bottom.
        if (menu_sel < 0) menu_sel = menu_items - 1;
        if (menu_sel >= menu_items) menu_sel = 0;

        sel = menu_sel;
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
Ejemplo n.º 3
0
void ui_print(const char *fmt, ...)
{
    char buf[256];
    va_list ap;
    char *locale_fmt = "";

    locale_fmt = ui_translate(fmt);
    va_start(ap, locale_fmt);
    vsnprintf(buf, 256, locale_fmt, ap);
    va_end(ap);

    if (ui_log_stdout)
        fputs(buf, stdout);

    // if we are running 'ui nice' mode, we do not want to force a screen update
    // for this line if not necessary.
    ui_niced = 0;
    if (ui_nice) {
        struct timeval curtime;
        gettimeofday(&curtime, NULL);
        long ms = delta_milliseconds(lastupdate, curtime);
        if (ms < NICE_INTERVAL && ms >= 0) {
            ui_niced = 1;
            return;
        }
    }

    // This can get called before ui_init(), so be careful.
    pthread_mutex_lock(&gUpdateMutex);
    gettimeofday(&lastupdate, NULL);
    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);
}
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
                                 int initial_selection) {
    pthread_mutex_lock(&updateMutex);
    if (text_rows_ > 0 && text_cols_ > 0) {
        menu_headers_ = headers;
        size_t i = 0;
        for (; i < text_rows_ && items[i] != nullptr; ++i) {
            strncpy(menu_[i], items[i], text_cols_ - 1);
            menu_[i][text_cols_ - 1] = '\0';
        }
        menu_items = i;
        show_menu = true;
        menu_sel = initial_selection;
        update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
}
Ejemplo n.º 5
0
int ui_start_menu(const char** headers, char** items, int initial_selection) {
#ifdef PHILZ_TOUCH_RECOVERY
    ui_friendly_log(0);
#endif
    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;

            int offset = 1;
#ifdef PHILZ_TOUCH_RECOVERY
            if (i == 0)
                offset = ui_menu_header_offset();
#endif
            strncpy(menu[i], headers[i], text_cols - offset);
            menu[i][text_cols - offset] = '\0';
        }

        menu_top = i;
        for (; i < MENU_MAX_ROWS; ++i) {
            if (items[i-menu_top] == NULL) break;
            strcpy(menu[i], MENU_ITEM_HEADER);
            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';
        }

        if (gShowBackButton && !ui_root_menu) {
            strcpy(menu[i], " - +++++Go Back+++++");
            ++i;
        }

        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = menu_show_start = initial_selection;
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    if (gShowBackButton && !ui_root_menu) {
        return menu_items - 1;
    }
    return menu_items;
}
Ejemplo n.º 6
0
int ui_menu_select(int sel) {
    int old_sel;
    pthread_mutex_lock(&gUpdateMutex);
    if (show_menu > 0) {
        menu_sel = sel;
        if (menu_sel < 0) {
	    menu_sel = 0;
	    old_sel = ui_scroll_menu(-1);
	}
        if (menu_sel > menu_items-1) {
	    menu_sel = menu_items-1;
	    old_sel = ui_scroll_menu(1);
	}
        sel = menu_sel;
        if (old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    return sel;
}
int ui_menu_select(int sel) {
    int old_sel;
    pthread_mutex_lock(&gUpdateMutex);
    if (show_menu > 0) {
        old_sel = menu_sel;
        menu_sel = sel;
/*        if (menu_sel < 0) menu_sel = 0;
          if (menu_sel >= menu_items) menu_sel = menu_items-1;
//        if (menu_sel < 0) menu_sel = menu_items-1;
//        if (menu_sel >= menu_items) menu_sel = 0;

        if (menu_sel < menu_show_start && menu_show_start > 0) {
            menu_show_start--;
        }

        if (menu_sel - menu_show_start + menu_top >= text_rows) {
            menu_show_start++;
        }

        sel = menu_sel;
        if (menu_sel != old_sel) update_screen_locked();
*/

        if (menu_sel < 0) menu_sel = menu_items + menu_sel;
        if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;


        if (menu_sel < menu_show_start && menu_show_start > 0) {
            menu_show_start = menu_sel;
        }

        if (menu_sel - menu_show_start + menu_top >= text_rows) {
            menu_show_start = menu_sel + menu_top - text_rows + 1;
        }

        sel = menu_sel;

        if (menu_sel != old_sel) update_screen_locked();

    }
    pthread_mutex_unlock(&gUpdateMutex);
    return sel;
}
void ScreenRecoveryUI::SetBackground(Icon icon)
{
    pthread_mutex_lock(&updateMutex);

    // Adjust the offset to account for the positioning of the
    // base image on the screen.
    if (backgroundIcon[icon] != NULL) {
        gr_surface bg = backgroundIcon[icon];
        gr_surface text = backgroundText[icon];
        overlay_offset_x = install_overlay_offset_x + (gr_fb_width() - gr_get_width(bg)) / 2;
        overlay_offset_y = install_overlay_offset_y +
            (gr_fb_height() - (gr_get_height(bg) + gr_get_height(text) + 40)) / 2;
    }

    currentIcon = icon;
    update_screen_locked();

    pthread_mutex_unlock(&updateMutex);
}
Ejemplo n.º 9
0
int ui_menu_select(int sel) {
    int old_sel;
    pthread_mutex_lock(&gUpdateMutex);
    if (show_menu > 0) {
        old_sel = menu_sel;
        menu_sel = sel;
        if (menu_sel < 0) menu_sel = menu_items + menu_sel;
        if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;

        //move the display starting point up the screen as the selection moves up
        if (menu_show_start > 0 && menu_sel < menu_show_start) menu_show_start = menu_sel;

        //move display starting point down one past the end of the current screen as the selection moves back end of screen
        if (menu_sel - menu_show_start + menu_top >= text_rows) menu_show_start = menu_sel + menu_top - text_rows + 1;

        sel = menu_sel;
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    return sel;
}
Ejemplo n.º 10
0
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
                                 int initial_selection) {
    int i = 0;
    pthread_mutex_lock(&updateMutex);
    if (text_rows > 0 && text_cols > 0) {
        for (; i < kMaxMenuRows; ++i) {
            if (items[i] == NULL) break;
            strncpy(menu[i], items[i], text_cols-1);
            menu[i][text_cols-1] = '\0';
        }
        menu_items = i;
        show_menu = 1;
        menu_sel = initial_selection;
        if (menu_show_start <= menu_sel - max_menu_rows ||
                menu_show_start > menu_sel) {
            menu_show_start = menu_sel;
        }
        update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
}
int ScreenRecoveryUI::SelectMenu(int sel, bool abs) {
    int old_sel;
    pthread_mutex_lock(&updateMutex);
    if (abs) {
        sel += menu_show_start;
    }
    if (show_menu > 0) {
        old_sel = menu_sel;
        menu_sel = sel;
        if (rainbow) {
            if (menu_sel > old_sel) {
                move_rainbow(1);
            } else if (menu_sel < old_sel) {
                move_rainbow(-1);
            }
        }
        if (menu_sel < 0) {
            // Wraparound from top to bottom
            menu_sel = menu_items + menu_sel;
        }
        if (menu_sel >= menu_items) {
            // Wraparound back up from the bottom
            menu_sel = menu_sel - menu_items;
        }
        if (menu_sel < menu_show_start && menu_show_start > 0) {
            // We scrolled up
            menu_show_start = menu_sel;
        }
        if (menu_sel - menu_show_start >= max_menu_rows) {
            // We scrolled down
            menu_show_start = menu_sel - max_menu_rows + 1;
        }
        sel = menu_sel;
        if (menu_sel != old_sel) {
            update_screen_locked();
        }
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
Ejemplo n.º 12
0
int ScreenRecoveryUI::SelectMenu(int sel) {
    int wrapped = 0;
    pthread_mutex_lock(&updateMutex);
    if (show_menu) {
        int old_sel = menu_sel;
        menu_sel = sel;

        // Wrap at top and bottom.
        if (rainbow) {
            if (menu_sel > old_sel) {
                move_rainbow(1);
            } else if (menu_sel < old_sel) {
                move_rainbow(-1);
            }
        }
        if (menu_sel < 0) {
            wrapped = -1;
            menu_sel = menu_items - 1;
        }
        if (menu_sel >= menu_items) {
            wrapped = 1;
            menu_sel = 0;
        }
        sel = menu_sel;
        if (wrapped != 0) {
            if (wrap_count / wrapped > 0) {
                wrap_count += wrapped;
            } else {
                wrap_count = wrapped;
            }
            if (wrap_count / wrapped >= 5) {
                wrap_count = 0;
                OMGRainbows();
            }
        }
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
Ejemplo n.º 13
0
int ScreenRecoveryUI::SelectMenu(int sel) {
    int old_sel;
    pthread_mutex_lock(&updateMutex);
    if (show_menu > 0) {
        old_sel = menu_sel;
        menu_sel = sel;
#if 0 //wschen 2012-07-10
        if (menu_sel < 0) menu_sel = 0;
        if (menu_sel >= menu_items) menu_sel = menu_items-1;
#else
        if (menu_sel < 0) {
            menu_sel = menu_items - 1;
        } else if (menu_sel >= menu_items) {
            menu_sel = 0;
        }
#endif
        sel = menu_sel;
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
Ejemplo n.º 14
0
void ui_start_menu(char** headers, char** items, int sel) {
    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;
        for (; i < text_rows; ++i) {
            if (items[i-menu_top] == NULL) break;
            strncpy(menu[i], items[i-menu_top], text_cols-1);
            menu[i][text_cols-1] = '\0';
        }
        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = sel;
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
}
Ejemplo n.º 15
0
int ScreenRecoveryUI::SelectMenu(int sel, bool abs) {
    pthread_mutex_lock(&updateMutex);
    if (abs) {
        sel += menu_show_start;
    }
    if (show_menu > 0) {
        int old_sel = menu_sel;
        menu_sel = sel;
        if (menu_sel < 0) menu_sel = menu_items + menu_sel;
        if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;
        if (menu_sel < menu_show_start && menu_show_start > 0) {
            menu_show_start = menu_sel;
        }
        if (menu_sel - menu_show_start >= max_menu_rows) {
            menu_show_start = menu_sel - max_menu_rows + 1;
        }
        sel = menu_sel;
        if (menu_sel != old_sel) update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
    return sel;
}
void ScreenRecoveryUI::StartMenu(const char* const * headers, const char* const * items,
                                 int initial_selection) {
    int i;
    pthread_mutex_lock(&updateMutex);
    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;
        for (; i < text_rows; ++i) {
            if (items[i-menu_top] == NULL) break;
            strncpy(menu[i], items[i-menu_top], text_cols-1);
            menu[i][text_cols-1] = '\0';
        }
        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = initial_selection;
        update_screen_locked();
    }
    pthread_mutex_unlock(&updateMutex);
}
Ejemplo n.º 17
0
int ui_start_menu(char** headers, char** items) {
    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;
        for (; i < MENU_MAX_ROWS; ++i) {
            if (items[i-menu_top] == NULL) break;
            if (items[i-menu_top][0] != 0)
            	strcpy(menu[i], MENU_ITEM_HEADER);
            else
            	strcpy(menu[i], MENU_ITEM_HEADER_DIV);

            strncpy(menu[i] + MENU_ITEM_HEADER_LENGTH, items[i-menu_top], text_cols-1 - MENU_ITEM_HEADER_LENGTH);
            menu[i][text_cols-1] = '\0';
        }

        if (gShowBackButton) {
            strcpy(menu[i], " - +++++Go Back+++++");
            ++i;
        }

        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = menu_show_start = 0;
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    if (gShowBackButton) {
        return menu_items - 1;
    }
    return menu_items;
}
Ejemplo n.º 18
0
void ui_init(void)
{
    gr_init();
    ev_init();

    text_col = text_row = 0;
    text_rows = gr_fb_height() / CHAR_HEIGHT;
    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) {
            if (result == -2) {
                LOGI("Bitmap %s missing header\n", BITMAPS[i].name);
            } else {
                LOGE("Missing bitmap %s\n(Code %d)\n", BITMAPS[i].name, result);
            }
            *BITMAPS[i].surface = NULL;
        }
    }

    pthread_t t;
    pthread_create(&t, NULL, progress_thread, NULL);
    pthread_create(&t, NULL, input_thread, NULL);

    pthread_mutex_lock(&gUpdateMutex);
    show_text = !show_text;
    update_screen_locked();
    pthread_mutex_unlock(&gUpdateMutex);

}
void ScreenRecoveryUI::PrintV(const char* fmt, bool copy_to_stdout, va_list ap) {
    std::string str;
    android::base::StringAppendV(&str, fmt, ap);

    if (copy_to_stdout) {
        fputs(str.c_str(), stdout);
    }

    pthread_mutex_lock(&updateMutex);
    if (text_rows_ > 0 && text_cols_ > 0) {
        for (const char* ptr = str.c_str(); *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(&updateMutex);
}
Ejemplo n.º 20
0
int ui_start_menu(char** headers, char** items, int initial_selection) {
    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;
        for (; i < MENU_MAX_ROWS; ++i) {
            if (items[i-menu_top] == NULL) break;
            strcpy(menu[i], MENU_ITEM_HEADER);
            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';
        }

        if (gShowBackButton && ui_menu_level > 0) {
            strcpy(menu[i], " < Go Back");
            ++i;
        }
        
        strcpy(menu[i], " ");
        ++i;

        menu_items = i - menu_top;
        show_menu = 1;
        menu_sel = menu_show_start = initial_selection;
        update_screen_locked();
    }
    pthread_mutex_unlock(&gUpdateMutex);
    if (gShowBackButton && ui_menu_level > 0) {
        return menu_items - 1;
    }
    return menu_items;
}
Ejemplo n.º 21
0
static int input_callback(int fd, short revents, void *data)
{
    struct input_event ev;
    int ret;
    int fake_key = 0;

    ret = ev_get_input(fd, revents, &ev);
    if (ret)
        return -1;

#ifdef BOARD_TOUCH_RECOVERY
    if (touch_handle_input(fd, ev))
      return 0;
#endif

    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;
                rel_sum = 0;
            }
        }
    } else {
        rel_sum = 0;
    }

    if (ev.type != EV_KEY || ev.code > KEY_MAX)
        return 0;

    if (ev.value == 2) {
        boardEnableKeyRepeat = 0;
    }

    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;

        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;
        }

        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;
}
Ejemplo n.º 22
0
// Reads input events, handles special hot keys, and adds to the key queue.
static void *input_thread(void *cookie)
{
    int rel_sum = 0;
    int fake_key = 0;
    for (;;) {
        // wait for the next key event
        struct input_event ev;
        do {
            ev_get(&ev, 0);

            if (ev.type == EV_SYN) {
                continue;
            } 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;
                        rel_sum = 0;
                    }
                }
            } else {
                rel_sum = 0;
            }
        } while (ev.type != EV_KEY || ev.code > KEY_MAX);

        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;
        }
        fake_key = 0;
        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;
            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;
            update_screen_locked();
            pthread_mutex_unlock(&gUpdateMutex);
        }

        if (ev.value > 0 && device_reboot_now(key_pressed, ev.code)) {
            reboot(RB_AUTOBOOT);
        }
    }
    return NULL;
}
Ejemplo n.º 23
0
// Reads input events, handles special hot keys, and adds to the key queue.
static void *input_thread(void *cookie)
{
    int rel_sum = 0;
    int fake_key = 0;
    for (;;) {
        // wait for the next key event
        struct input_event ev;
        do {
            ev_get(&ev, 0);
			if (ev.value == 1) {/* <[email protected]> */
				ev.value = 0;
			} else if (ev.value == 0) {
				ev.value = 1;
			}
			if(ev.type == EV_KEY || ev.type == EV_SW) {
				if (ev.value == 0 && ev.code == 115) {	//item up
					ev.code = KEY_VOLUMEUP;
					ev.value = 1;
					break;
				} else if (ev.value == 0 && ev.code == 114 ) {	//item down
					ev.code = KEY_VOLUMEDOWN;
					ev.value = 1;
					break;
				} else if (ev.value == 0 && ev.code == 116 ) {	//item select
					ev.code = KEY_ENTER;
					ev.value = 1;
					break;
				} else if (ev.value == 1 && ev.code == 8 ) {	//usb in
					ev.code = USB_IN;
					ev.value = 1;
					break;
				} else if (ev.value == 0 && ev.code == 8 ) {	//usb out
					ev.code = USB_OUT;
					ev.value = 1;
					break;
				}
			} else {
				continue;
			}
		} while (ev.value != 0);	// key up

        pthread_mutex_lock(&key_queue_mutex);
        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;
            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;
            update_screen_locked();
            pthread_mutex_unlock(&gUpdateMutex);
        }

        if (ev.value > 0 && device_reboot_now(key_pressed, ev.code)) {
            reboot(RB_AUTOBOOT);
        }
    }
    return NULL;
}
Ejemplo n.º 24
0
void ui_print(const char *fmt, ...) {
    char buf[256];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, 256, fmt, ap);
    va_end(ap);

    if (ui_log_stdout)
        fputs(buf, stdout);

    // This can get called before ui_init(), so be careful.
    pthread_mutex_lock(&gUpdateMutex);
    if (text_rows > 0 && text_cols > 0) {
        char *ptr;
#ifdef USE_CHINESE_FONT
        int fwidth = 0, fwidth_sum = 0;
#endif
        for (ptr = buf; *ptr != '\0'; ++ptr) {
#ifdef USE_CHINESE_FONT
            fwidth = gr_measure(&*ptr);
            //LOGI("%d \n", fwidth);
            fwidth_sum += fwidth;

            if (*ptr == '\n' || fwidth_sum >= gr_fb_width()) {
                fwidth_sum = 0;
#else
            if (*ptr == '\n' || text_col >= text_cols) {
#endif
                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);
}

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_print("Return to menu with any key.\n");
    ui_log_stdout=1;
}
Ejemplo n.º 25
0
static int input_callback(int fd, short revents, void *data)
{
    struct input_event ev;
    int ret;
    int fake_key = 0;
    gr_surface surface = gVirtualKeys;

    ret = ev_get_input(fd, revents, &ev);
    if (ret)
        return -1;

#ifdef BOARD_TOUCH_RECOVERY
    if (touch_handle_input(fd, ev))
      return 0;
#endif

    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;
                rel_sum = 0;
            }
        }
    } else {
        rel_sum = 0;
    }

    if (ev.type == 3 && ev.code == 48 && ev.value != 0) {
        if (in_touch == 0) {
            in_touch = 1; //starting to track touch...
            reset_gestures();
        }
    } else if (ev.type == 3 && ev.code == 48 && ev.value == 0) {
            //finger lifted! lets run with this
            ev.type = EV_KEY; //touch panel support!!!
            int keywidth = gr_get_width(surface) / 4;
            int keyoffset = (gr_fb_width() - gr_get_width(surface)) / 2;
            if (touch_y > (gr_fb_height() - gr_get_height(surface)) && touch_x > 0) {
                //they lifted in the touch panel region
                if (touch_x < (keywidth + keyoffset)) {
                    //down button
                    ev.code = KEY_DOWN;
                    reset_gestures();
                } else if (touch_x < ((keywidth * 2) + keyoffset)) {
                    //up button
                    ev.code = KEY_UP;
                    reset_gestures();
                } else if (touch_x < ((keywidth * 3) + keyoffset)) {
                    //back button
                    ev.code = KEY_BACK;
                    reset_gestures();
                } else {
                    //enter key
                    ev.code = KEY_ENTER;
                    reset_gestures();
                }
                vibrate(VIBRATOR_TIME_MS);
            }
            if (slide_right == 1) {
                ev.code = KEY_ENTER;
                slide_right = 0;
            } else if (slide_left == 1) {
                ev.code = KEY_BACK;
                slide_left = 0;
            }

            ev.value = 1;
            in_touch = 0;
            reset_gestures();
    } else if (ev.type == 3 && ev.code == 53) {
        old_x = touch_x;
        touch_x = ev.value;
        if (old_x != 0)
            diff_x += touch_x - old_x;

	if (touch_y < (gr_fb_height() - gr_get_height(surface))) {
            if (diff_x > (gr_fb_width() / 4)) {
                slide_right = 1;
                reset_gestures();
    } else if(diff_x < ((gr_fb_width() / 4) * -1)) {
                slide_left = 1;
                reset_gestures();
            }
        } else {
            input_buttons();
            //reset_gestures();
        }
    } else if (ev.type == 3 && ev.code == 54) {
        old_y = touch_y;
        touch_y = ev.value;
        if (old_y != 0)
            diff_y += touch_y - old_y;

    if (touch_y < (gr_fb_height() - gr_get_height(surface))) {
            if (diff_y > 25) {
                ev.code = KEY_DOWN;
                ev.type = EV_KEY;
                reset_gestures();
	} else if (diff_y < -25) {
                ev.code = KEY_UP;
                ev.type = EV_KEY;
                reset_gestures();
            }
        } else {
            input_buttons();
            //reset_gestures();
        }
    }

    if (ev.type != EV_KEY || ev.code > KEY_MAX)
        return 0;

    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;

        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;
        }

        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;
}
Ejemplo n.º 26
0
void ui_set_background(int icon) {
    pthread_mutex_lock(&gUpdateMutex);
    gCurrentIcon = icon;
    update_screen_locked();
    pthread_mutex_unlock(&gUpdateMutex);
}
Ejemplo n.º 27
0
// Reads input events, handles special hot keys, and adds to the key queue.
static void *input_thread(void *cookie)
{
    int rel_sum = 0;
    int fake_key = 0;
    for (;;) {
        // wait for the next key event
        struct input_event ev;
        do {
            ev_get(&ev, 0);

            if (ev.type == EV_SYN) {
                continue;
            } 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;
                        rel_sum = 0;
                    }
                }
            } else {
                rel_sum = 0;
            }
        } while (ev.type != EV_KEY || ev.code > KEY_MAX);

        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;
        }
        fake_key = 0;
        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;
            pthread_cond_signal(&key_queue_cond);
        }
        pthread_mutex_unlock(&key_queue_mutex);

        // Alt+L or Home+End: toggle log display
        int alt = key_pressed[KEY_LEFTALT] || key_pressed[KEY_RIGHTALT];
        if ((alt && ev.code == KEY_L && ev.value > 0) ||
            (key_pressed[KEY_HOME] && ev.code == KEY_END && ev.value > 0)) {
            pthread_mutex_lock(&gUpdateMutex);
            show_text = !show_text;
            update_screen_locked();
            pthread_mutex_unlock(&gUpdateMutex);
        }

        // Green+Menu+Red: reboot immediately
        if (ev.code == KEY_DREAM_RED &&
            key_pressed[KEY_DREAM_MENU] &&
            key_pressed[KEY_DREAM_GREEN]) {
            reboot(RB_AUTOBOOT);
        }
    }
    return NULL;
}
void ScreenRecoveryUI::Redraw()
{
    pthread_mutex_lock(&updateMutex);
    update_screen_locked();
    pthread_mutex_unlock(&updateMutex);
}
Ejemplo n.º 29
0
void ui_print(const char *fmt, ...)
{
    char buf[256];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, 256, fmt, ap);
    va_end(ap);

    // check if we need to exclude some line from write to log file
    // first line is line 0
    if (ui_log_stdout && no_stdout_line >= 0) {
        char str[256];
        char buf2[256];
        char buf3[256] = "";

        // copy the buffer to modify it
        strcpy(buf2, buf);
        char *ptr = strtok(buf2, "\n");
        int i = 0;
        while(ptr != NULL) {
            // parse the buffer and exclude the line we do not want to write to recovery.log file
            if (i != no_stdout_line) {
                strcpy(str, ptr);
                // log only nandroid non empty lines
                if (strcmp(str, " ") != 0) {
                    strcat(str, "\n");
                    strcat(buf3, str);
                }
            }
            ptr = strtok(NULL, "\n");
            ++i;
        }
        fputs(buf3, stdout);
    }
    else if (ui_log_stdout)
        fputs(buf, stdout);

    // if we are running 'ui nice' mode, we do not want to force a screen update
    // for this line if not necessary.
    ui_niced = 0;
    if (ui_nice) {
        struct timeval curtime;
        gettimeofday(&curtime, NULL);
        long ms = delta_milliseconds(lastupdate, curtime);
        if (ms < NICE_INTERVAL && ms >= 0) {
            ui_niced = 1;
            return;
        }
    }

    // This can get called before ui_init(), so be careful.
    pthread_mutex_lock(&gUpdateMutex);
    gettimeofday(&lastupdate, NULL);
    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);
}