// runs the program and redirects it's output to the screen using ui_print int graphsh_main(int argc, char** argv) { if (argc>=2) { ui_init(); ui_print(EXPAND(RECOVERY_VERSION)" - script runner\n"); ui_set_show_text(1); FILE* f = popen(argv[1],"r"); char buff[255]; int l; if (!f) { ui_print("Could not open process\n"); sleep(1); gr_exit(); ev_exit(); return -1; } while(fgets(buff,250,f)) { ui_print("%s",buff); } pclose(f); gr_exit(); ev_exit(); return 0; } else { printf("Usage: graphsh command\n command with it's optional parameter(s) must be in quotes.\n"); return -1; } }
static void *input_thread_work(void *cookie) { ev_init(); struct input_event ev; memset(mt_events, 0, sizeof(mt_events)); key_itr = 10; mt_slot = 0; int res; while(input_run) { while(ev_get(&ev, 1) == 0) { switch(ev.type) { case EV_KEY: handle_key_event(&ev); break; case EV_ABS: handle_abs_event(&ev); break; case EV_SYN: handle_syn_event(&ev); break; } } usleep(10000); } ev_exit(); pthread_exit(NULL); return NULL; }
// runs the program and redirects it's output to the screen using ui_print int graphchoice_main(int argc, char** argv) { if (argc>=2) { ui_init(); ui_print(EXPAND(RECOVERY_VERSION)" - choice app\n"); ui_set_show_text(1); ui_reset_progress(); ui_clear_key_queue(); char** headers; char** list; headers = malloc(sizeof(char*)*3); headers[0] = argv[1]; headers[1] = ""; headers[2] = NULL; list = malloc(sizeof(char*)*(argc+2)); list[0] = NULL; list[1] = NULL; int i=2; while (argv[i]) { list[i-2] = argv[i]; list[i-1] = NULL; i++; } int chosen_item = GO_BACK; while (chosen_item == GO_BACK) { chosen_item = get_menu_selection(headers,list,0,0); } gr_exit(); ev_exit(); return chosen_item; } else { printf("Usage: graphchoice question [option1] [option2] [option3] [...].\n"); return -1; } }
int lagfixer_main(int argc, char** argv) { ui_init(); ui_print(EXPAND(RECOVERY_VERSION)" - lagfixer\n"); create_fstab(); ui_set_show_text(1); int res; int opts = 0; if ((argc>=2)&&(strcmp(argv[1],"fr")==0)) { opts=2; } else if ((argc>=2)&&(strcmp(argv[1],"b")==0)) { opts=1; } res = do_lagfix(opts); if (res) { ui_print("Something went wrong while doing the lagfix, sorry.\n"); } else { ui_print("Done. Your device will reboot soon or enter recovery mode to debug.\n"); } sleep(5); gr_exit(); ev_exit(); return 0; }
//* //* Release All Resources //* void a_release_all(){ //-- Release All ag_closefonts(); //-- Release Fonts ev_exit(); //-- Release Input Engine az_close(); //-- Release Zip Handler ag_close(); //-- Release Graph Engine }
//* //* Release All Resources //* void a_release_all(){ //-- Release All ag_closefonts(); //-- Release Fonts LOGS("Font Released\n"); ev_exit(); //-- Release Input Engine LOGS("Input Released\n"); az_close(); //-- Release Zip Handler LOGS("Archive Released\n"); ag_close(); //-- Release Graph Engine LOGS("Graph Released\n"); }
void *bootmgr_input_thread(void *cookie) { ev_init(); struct input_event ev; uint16_t x, y; pthread_mutex_init(bootmgr_input_mutex, NULL); struct timeval tv; struct timeval tv_last; gettimeofday(&tv_last, NULL); while(bootmgr_input_run) { ev_get(&ev, 0); if(ev.type == EV_KEY && (!ev.value || ev.code == KEY_POWER) && ev.code <= KEY_MAX) { pthread_mutex_lock(bootmgr_input_mutex); if(bootmgr_key_itr > 0 && ev.code != -1) bootmgr_key_queue[--bootmgr_key_itr] = ev.code; pthread_mutex_unlock(bootmgr_input_mutex); } else if(!sleep_mode && ev.type == EV_ABS && ev.code == 0x30 && ev.value) //#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ { gettimeofday(&tv, NULL); int32_t ms = (tv.tv_sec - tv_last.tv_sec)*1000+(tv.tv_usec-tv_last.tv_usec)/1000; if(ms >= 200) { do { ev_get(&ev, 0); } while(ev.type != EV_ABS); x = ev.value; do { ev_get(&ev, 0); } while(ev.type != EV_ABS); y = ev.value; do { ev_get(&ev, 0); } while(ev.type != EV_SYN && ev.code != SYN_REPORT); // Wait for touch seq end pthread_mutex_lock(bootmgr_input_mutex); if(bootmgr_touch_itr > 0) { bootmgr_touch_queue[--bootmgr_touch_itr][0] = x; bootmgr_touch_queue[ bootmgr_touch_itr][1] = y; } pthread_mutex_unlock(bootmgr_input_mutex); tv_last.tv_sec = tv.tv_sec; tv_last.tv_usec = tv.tv_usec; } else do { ev_get(&ev, 0); } while(ev.type != EV_SYN && ev.code != SYN_REPORT); // Wait for touch seq end } } ev_exit(); pthread_mutex_destroy(bootmgr_input_mutex); return NULL; }
int ev_get(struct input_event *ev, unsigned dont_wait) { int r; unsigned n; struct timeval curr; do { gettimeofday(&curr, NULL); if(curr.tv_sec - lastInputStat.tv_sec >= 2) { struct stat st; stat("/dev/input", &st); if (st.st_mtime > lastInputMTime) { LOGI("Reloading input devices\n"); ev_exit(); ev_init(); lastInputMTime = st.st_mtime; } lastInputStat = curr; } r = poll(ev_fds, ev_count, 0); if(r > 0) { for(n = 0; n < ev_count; n++) { if(ev_fds[n].revents & POLLIN) { r = read(ev_fds[n].fd, ev, sizeof(*ev)); if(r == sizeof(*ev)) { if (!vk_modify(&evs[n], ev)) return 0; } } } } usleep(1000); } while(dont_wait == 0); return -1; }
int ev_get(struct input_event *ev, int timeout_ms) { int r; unsigned n; struct timespec curr; clock_gettime(CLOCK_MONOTONIC, &curr); if (curr.tv_sec - lastInputStat.tv_sec >= 2) { struct stat st; stat("/dev/input", &st); if (st.st_mtime > lastInputMTime) { printf("Reloading input devices\n"); ev_exit(); ev_init(); lastInputMTime = st.st_mtime; } lastInputStat = curr; } r = poll(ev_fds, ev_count, timeout_ms); if (r > 0) { for (n = 0; n < ev_count; n++) { if (ev_fds[n].revents & POLLIN) { r = read(ev_fds[n].fd, ev, sizeof(*ev)); if (r == sizeof(*ev)) { if (!vk_modify(&evs[n], ev)) { return 0; } } } } return -1; } return -2; }
int main(int argc, char **argv) { int key_code = -1; int input = false; int opt; long int timeout = NEXT_TIMEOUT_MS; int64_t start; while ((opt = getopt(argc, argv, "t:")) != -1) { switch (opt) { case 't': timeout = strtol(optarg, NULL, 0); if (timeout < 0 || timeout >= LONG_MAX) { timeout = NEXT_TIMEOUT_MS; LOGE("invalid timeout %s, defaulting to %ld\n", optarg, timeout); } break; default: return usage(); } } if (optind >= argc) { return usage(); } if (gr_init() == -1 || ev_init(input_cb, &key_code) == -1) { LOGE("failed to initialize minui\n"); return EXIT_FAILURE; } /* display all images except the last one, switch to next image after * timeout or user input */ while (optind < argc - 1) { draw(argv[optind++]); start = android::uptimeMillis(); long int timeout_remaining = timeout; do { if (ev_wait(timeout_remaining) == 0) { ev_dispatch(); if (key_code != -1) { input = true; break; } } timeout_remaining -= android::uptimeMillis() - start; } while (timeout_remaining > 0); }; /* if there was user input while showing the images, display the last * image and wait until the power button is pressed or LAST_TIMEOUT_MS * has elapsed */ if (input) { start = android::uptimeMillis(); draw(argv[optind]); do { if (ev_wait(timeout) == 0) { ev_dispatch(); } if (android::uptimeMillis() - start >= LAST_TIMEOUT_MS) { break; } } while (key_code != KEY_POWER); } clear(); gr_exit(); ev_exit(); return EXIT_SUCCESS; }
int main() { struct device_state old_state; get_device_state(&old_state); if (screen_init() < 0) goto err1; ev_init(); led_init(); sleep(3); /* Set battery LED, initialize image, screen brightness */ power_event(1); screen_brightness_animation_start(); while (!quit) { int r, delay = alarm_get_time_until_next(); if (delay < 1) { alarm_process(); continue; } r = ev_get(delay); /* Press below keys will wake the display and repeat the display cycle: Power key, Volume up/down key, Camera key. Long press Power key will reboot the device. */ switch (r) { /* Power key */ case EVENT_POWER_KEY_DOWN: if (powerup) alarm_set_relative(power_key_alarm, NULL, 1000); break; case EVENT_POWER_KEY_UP: alarm_cancel(power_key_alarm); update_screen_on_wakeup_key(); break; /* Other keys */ case EVENT_VOLUMEDOWN_KEY_DOWN: update_screen_on_wakeup_key2(); break; case EVENT_VOLUMEUP_KEY_DOWN: update_screen_on_wakeup_key2(); break; case EVENT_CAMERA_KEY_DOWN: update_screen_on_wakeup_key2(); break; /* Battery events */ case EVENT_BATTERY: power_event(1); break; /* Others */ case EVENT_QUIT: quit = 1; break; default: break; } } led_uninit(); ev_exit(); screen_uninit(); return 0; err1: return -1; }