Re-implement boot error messages and auto-boot
This commit is contained in:
		
							
								
								
									
										211
									
								
								multirom_ui.c
									
									
									
									
									
								
							
							
						
						
									
										211
									
								
								multirom_ui.c
									
									
									
									
									
								
							@@ -39,6 +39,7 @@
 | 
			
		||||
#include "hooks.h"
 | 
			
		||||
#include "containers.h"
 | 
			
		||||
#include "animation.h"
 | 
			
		||||
#include "notification_card.h"
 | 
			
		||||
 | 
			
		||||
static struct multirom_status *mrom_status = NULL;
 | 
			
		||||
static struct multirom_rom *selected_rom = NULL;
 | 
			
		||||
@@ -134,11 +135,10 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
    multirom_set_brightness(s->brightness);
 | 
			
		||||
 | 
			
		||||
    fb_freeze(0);
 | 
			
		||||
    fb_force_draw();
 | 
			
		||||
 | 
			
		||||
    if(s->auto_boot_rom && s->auto_boot_seconds > 0)
 | 
			
		||||
        multirom_ui_auto_boot();
 | 
			
		||||
    else
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
 | 
			
		||||
    while(1)
 | 
			
		||||
    {
 | 
			
		||||
@@ -202,24 +202,37 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
 | 
			
		||||
    rm_touch_handler(&multirom_ui_touch_handler, NULL);
 | 
			
		||||
 | 
			
		||||
    ncard_builder *b = ncard_create_builder();
 | 
			
		||||
    ncard_set_pos(b, NCARD_POS_CENTER);
 | 
			
		||||
 | 
			
		||||
    switch(exit_ui_code)
 | 
			
		||||
    {
 | 
			
		||||
        case UI_EXIT_BOOT_ROM:
 | 
			
		||||
        {
 | 
			
		||||
            *to_boot = selected_rom;
 | 
			
		||||
            //fb_msgbox_add_text(-1, 40*DPI_MUL, SIZE_BIG, "Booting ROM...");
 | 
			
		||||
            //fb_msgbox_add_text(-1, -1, SIZE_NORMAL, selected_rom->name);
 | 
			
		||||
            ncard_set_title(b, "Booting...");
 | 
			
		||||
 | 
			
		||||
            char buff[64];
 | 
			
		||||
            snprintf(buff, sizeof(buff), "%s", selected_rom->name);
 | 
			
		||||
            ncard_set_text(b, buff);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case UI_EXIT_REBOOT:
 | 
			
		||||
            ncard_set_text(b, "\nRebooting...\n\n");
 | 
			
		||||
            break;
 | 
			
		||||
        case UI_EXIT_REBOOT_RECOVERY:
 | 
			
		||||
            ncard_set_text(b, "\nRebooting to recovery...\n\n");
 | 
			
		||||
            break;
 | 
			
		||||
        case UI_EXIT_REBOOT_BOOTLOADER:
 | 
			
		||||
            //fb_msgbox_add_text(-1, -1, SIZE_BIG, "Rebooting...");
 | 
			
		||||
            ncard_set_text(b, "\nRebooting to bootloader...\n\n");
 | 
			
		||||
            break;
 | 
			
		||||
        case UI_EXIT_SHUTDOWN:
 | 
			
		||||
            //fb_msgbox_add_text(-1, -1, SIZE_BIG, "Shutting down...");
 | 
			
		||||
            ncard_set_text(b, "\nShutting down...\n\n");
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    ncard_show(b, 1);
 | 
			
		||||
    anim_stop(1);
 | 
			
		||||
    fb_freeze(1);
 | 
			
		||||
 | 
			
		||||
    cur_theme->destroy(themes_info->data);
 | 
			
		||||
@@ -233,8 +246,6 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
 | 
			
		||||
    stop_input_thread();
 | 
			
		||||
 | 
			
		||||
    anim_stop();
 | 
			
		||||
 | 
			
		||||
    multirom_ui_destroy_tab(themes_info->data->selected_tab);
 | 
			
		||||
    multirom_ui_free_themes(themes_info);
 | 
			
		||||
    themes_info = NULL;
 | 
			
		||||
@@ -254,7 +265,7 @@ void multirom_ui_setup_colors(int clr, uint32_t *primary, uint32_t *secondary)
 | 
			
		||||
{
 | 
			
		||||
    static const int clrs[][2] = {
 | 
			
		||||
        // Primary,   Secondary - OxAAGGBBRR
 | 
			
		||||
        { 0xFF2F2FF7,     0xFF2F2FF7},     // CLRS_BLUE
 | 
			
		||||
        { 0xFF2F2FF7, 0xFF2F2FF7 }, // CLRS_BLUE
 | 
			
		||||
        { 0xFFCC66AA, 0xFFCC89B6 }, // CLRS_PURPLE
 | 
			
		||||
        { 0xFF00BD8A, 0xFF51F2C9 }, // CLRS_GREEN
 | 
			
		||||
        { 0xFF008AFF, 0xFF51AEFF }, // CLRS_ORANGE
 | 
			
		||||
@@ -362,11 +373,6 @@ void multirom_ui_fill_rom_list(listview *view, int mask)
 | 
			
		||||
        if(rom->id == last_selected_int_rom)
 | 
			
		||||
            select = it;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
/*    if(select)
 | 
			
		||||
        listview_select_item(view, select);
 | 
			
		||||
    else if(view->items != NULL)
 | 
			
		||||
        listview_select_item(view, view->items[0]);*/
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int multirom_ui_touch_handler(touch_event *ev, void *data)
 | 
			
		||||
@@ -387,56 +393,73 @@ int multirom_ui_touch_handler(touch_event *ev, void *data)
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_auto_boot(void)
 | 
			
		||||
struct auto_boot_data
 | 
			
		||||
{
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    /*
 | 
			
		||||
    int seconds = mrom_status->auto_boot_seconds*1000;
 | 
			
		||||
    active_msgbox = fb_create_msgbox(500*DPI_MUL, 300*DPI_MUL, CLR_PRIMARY);
 | 
			
		||||
    ncard_builder *b;
 | 
			
		||||
    int seconds;
 | 
			
		||||
    uint32_t anim_id;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
    fb_msgbox_add_text(-1, 40*DPI_MUL, SIZE_BIG, "Auto-boot");
 | 
			
		||||
    fb_msgbox_add_text(-1, active_msgbox->h-100*DPI_MUL, SIZE_NORMAL, "%s", mrom_status->auto_boot_rom->name);
 | 
			
		||||
    fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to cancel");
 | 
			
		||||
static void multirom_ui_auto_boot_hidden(void *data)
 | 
			
		||||
{
 | 
			
		||||
    struct auto_boot_data *d = data;
 | 
			
		||||
    anim_cancel(d->anim_id, 0);
 | 
			
		||||
    ncard_destroy_builder(d->b);
 | 
			
		||||
    free(d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    fb_text *sec_text = fb_msgbox_add_text(-1, -1, SIZE_BIG, "%d", seconds/1000);
 | 
			
		||||
static void multirom_ui_auto_boot_now(void *data)
 | 
			
		||||
{
 | 
			
		||||
    multirom_ui_auto_boot_hidden(data);
 | 
			
		||||
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    fb_freeze(1);
 | 
			
		||||
    pthread_mutex_lock(&exit_code_mutex);
 | 
			
		||||
    selected_rom = mrom_status->auto_boot_rom;
 | 
			
		||||
    exit_ui_code = UI_EXIT_BOOT_ROM;
 | 
			
		||||
    pthread_mutex_unlock(&exit_code_mutex);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    while(1)
 | 
			
		||||
static void multirom_ui_auto_boot_tick(void *data)
 | 
			
		||||
{
 | 
			
		||||
    char buff[128];
 | 
			
		||||
    struct auto_boot_data *d = data;
 | 
			
		||||
 | 
			
		||||
    if(--d->seconds == 0)
 | 
			
		||||
    {
 | 
			
		||||
        pthread_mutex_lock(&exit_code_mutex);
 | 
			
		||||
        if(!active_msgbox)
 | 
			
		||||
        {
 | 
			
		||||
            pthread_mutex_unlock(&exit_code_mutex);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        selected_rom = mrom_status->auto_boot_rom;
 | 
			
		||||
        exit_ui_code = UI_EXIT_BOOT_ROM;
 | 
			
		||||
        pthread_mutex_unlock(&exit_code_mutex);
 | 
			
		||||
 | 
			
		||||
        seconds -= 50;
 | 
			
		||||
        if(seconds <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            pthread_mutex_lock(&exit_code_mutex);
 | 
			
		||||
            selected_rom = mrom_status->auto_boot_rom;
 | 
			
		||||
            active_msgbox = NULL;
 | 
			
		||||
            exit_ui_code = UI_EXIT_BOOT_ROM;
 | 
			
		||||
            pthread_mutex_unlock(&exit_code_mutex);
 | 
			
		||||
            fb_destroy_msgbox();
 | 
			
		||||
            fb_freeze(0);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        else if((seconds+50)/1000 != seconds/1000)
 | 
			
		||||
        {
 | 
			
		||||
            fb_msgbox_rm_text(sec_text);
 | 
			
		||||
            sec_text = fb_msgbox_add_text(-1, -1, SIZE_BIG, "%d", seconds/1000);
 | 
			
		||||
 | 
			
		||||
            fb_freeze(0);
 | 
			
		||||
            fb_force_draw();
 | 
			
		||||
            fb_freeze(1);
 | 
			
		||||
        }
 | 
			
		||||
        usleep(50000);
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        snprintf(buff, sizeof(buff), "Booting in %d second%s.", d->seconds, d->seconds != 1 ? "s" : "");
 | 
			
		||||
        ncard_set_text(d->b, buff);
 | 
			
		||||
        ncard_show(d->b, 0);
 | 
			
		||||
 | 
			
		||||
        call_anim *a = call_anim_create(NULL, NULL, 1000, INTERPOLATOR_LINEAR);
 | 
			
		||||
        d->anim_id = a->id;
 | 
			
		||||
        a->on_finished_call = multirom_ui_auto_boot_tick;
 | 
			
		||||
        a->on_finished_data = d;
 | 
			
		||||
        call_anim_add(a);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_auto_boot(void)
 | 
			
		||||
{
 | 
			
		||||
    ncard_builder *b = ncard_create_builder();
 | 
			
		||||
 | 
			
		||||
    struct auto_boot_data *d = mzalloc(sizeof(struct auto_boot_data));
 | 
			
		||||
    d->b = b;
 | 
			
		||||
    d->seconds = mrom_status->auto_boot_seconds + 1;
 | 
			
		||||
 | 
			
		||||
    ncard_set_pos(b, NCARD_POS_CENTER);
 | 
			
		||||
    ncard_set_cancelable(b, 1);
 | 
			
		||||
    ncard_set_title(b, mrom_status->auto_boot_rom->name);
 | 
			
		||||
    ncard_add_btn(b, BTN_NEGATIVE, "Cancel", ncard_hide_callback, NULL);
 | 
			
		||||
    ncard_add_btn(b, BTN_POSITIVE, "Boot now", multirom_ui_auto_boot_now, d);
 | 
			
		||||
    ncard_set_on_hidden(b, multirom_ui_auto_boot_hidden, d);
 | 
			
		||||
 | 
			
		||||
    multirom_ui_auto_boot_tick(d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_refresh_usb_handler(void)
 | 
			
		||||
@@ -550,48 +573,38 @@ void multirom_ui_tab_rom_boot_btn(int action)
 | 
			
		||||
    if(!rom)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    int error = 0;
 | 
			
		||||
    ncard_builder *b = ncard_create_builder();
 | 
			
		||||
    ncard_set_pos(b, NCARD_POS_CENTER);
 | 
			
		||||
    ncard_add_btn(b, BTN_NEGATIVE, "ok", ncard_hide_callback, NULL);
 | 
			
		||||
    ncard_set_cancelable(b, 1);
 | 
			
		||||
    ncard_set_title(b, "Error");
 | 
			
		||||
 | 
			
		||||
    int m = M(rom->type);
 | 
			
		||||
    if(m & MASK_UNSUPPORTED)
 | 
			
		||||
    {
 | 
			
		||||
       /* active_msgbox = fb_create_msgbox(550*DPI_MUL, 360*DPI_MUL, DRED);
 | 
			
		||||
        fb_msgbox_add_text(-1, 30*DPI_MUL, SIZE_BIG, "Error");
 | 
			
		||||
        fb_msgbox_add_text(-1, 90*DPI_MUL, SIZE_NORMAL, "Unsupported ROM type.");
 | 
			
		||||
        fb_msgbox_add_text(-1, 180*DPI_MUL, SIZE_NORMAL, "See XDA thread for more info.");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);*/
 | 
			
		||||
        return;
 | 
			
		||||
        ncard_set_text(b, "Unsupported ROM type, see XDA thread for more info!");
 | 
			
		||||
        error = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (((m & MASK_KEXEC) || ((m & MASK_ANDROID) && rom->has_bootimg)) &&
 | 
			
		||||
    else if (((m & MASK_KEXEC) || ((m & MASK_ANDROID) && rom->has_bootimg)) &&
 | 
			
		||||
        multirom_has_kexec() != 0)
 | 
			
		||||
    {
 | 
			
		||||
        /*active_msgbox = fb_create_msgbox(550*DPI_MUL, 360*DPI_MUL, DRED);
 | 
			
		||||
        fb_msgbox_add_text(-1, 30*DPI_MUL, SIZE_BIG, "Error");
 | 
			
		||||
        fb_msgbox_add_text(-1, 90*DPI_MUL, SIZE_NORMAL, "Kexec-hardboot support");
 | 
			
		||||
        fb_msgbox_add_text(-1, 125*DPI_MUL, SIZE_NORMAL, "required to boot this ROM.");
 | 
			
		||||
        fb_msgbox_add_text(-1, 180*DPI_MUL, SIZE_NORMAL, "Use kernel with");
 | 
			
		||||
        fb_msgbox_add_text(-1, 215*DPI_MUL, SIZE_NORMAL, "kexec-hardboot support.");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);*/
 | 
			
		||||
        return;
 | 
			
		||||
        ncard_set_text(b, "Kexec-hardboot support is required to boot this ROM.\n\nInstall kernel with kexec-hardboot support to your Internal ROM!");
 | 
			
		||||
        error = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if((m & MASK_KEXEC) && strchr(rom->name, ' '))
 | 
			
		||||
    else if((m & MASK_KEXEC) && strchr(rom->name, ' '))
 | 
			
		||||
    {
 | 
			
		||||
        /*active_msgbox = fb_create_msgbox(550*DPI_MUL, 360*DPI_MUL, DRED);
 | 
			
		||||
        fb_msgbox_add_text(-1, 30*DPI_MUL, SIZE_BIG, "Error");
 | 
			
		||||
        fb_msgbox_add_text(-1, 90*DPI_MUL, SIZE_NORMAL, "ROM's name contains spaces");
 | 
			
		||||
        fb_msgbox_add_text(-1, 180*DPI_MUL, SIZE_NORMAL, "Remove spaces from ROM's name");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
        ncard_set_text(b, "ROM's name contains spaces. Please remove spaces from this ROM's name");
 | 
			
		||||
        error = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);*/
 | 
			
		||||
    if(error)
 | 
			
		||||
    {
 | 
			
		||||
        ncard_show(b, 1);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
        ncard_destroy_builder(b);
 | 
			
		||||
 | 
			
		||||
    pthread_mutex_lock(&exit_code_mutex);
 | 
			
		||||
    selected_rom = rom;
 | 
			
		||||
@@ -631,12 +644,14 @@ void multirom_ui_tab_rom_set_empty(void *data, int empty)
 | 
			
		||||
 | 
			
		||||
    if(empty && !t->usb_text)
 | 
			
		||||
    {
 | 
			
		||||
        fb_text_proto *p = fb_text_create(0, 0, WHITE, SIZE_NORMAL, "This list is refreshed automagically,\njust plug in the USB drive and wait.");
 | 
			
		||||
        fb_text_proto *p = fb_text_create(0, 0, BLACK, SIZE_NORMAL, "This list is refreshed automagically, just plug in the USB drive and wait.");
 | 
			
		||||
        p->wrap_w = t->list->w - 100*DPI_MUL;
 | 
			
		||||
        p->justify = JUSTIFY_CENTER;
 | 
			
		||||
        t->usb_text = fb_text_finalize(p);
 | 
			
		||||
        list_add(t->usb_text, &t->ui_elements);
 | 
			
		||||
 | 
			
		||||
        center_text(t->usb_text, t->list->x, t->list->y, width, t->list->h);
 | 
			
		||||
        center_text(t->usb_text, t->list->x, -1, width, -1);
 | 
			
		||||
        t->usb_text->y = t->list->y + t->list->h*0.2;
 | 
			
		||||
 | 
			
		||||
        int x = t->list->x + ((width/2) - (PROGDOTS_W/2));
 | 
			
		||||
        t->usb_prog = progdots_create(x, t->usb_text->y+100*DPI_MUL);
 | 
			
		||||
@@ -692,15 +707,13 @@ void multirom_ui_tab_misc_copy_log(int action)
 | 
			
		||||
 | 
			
		||||
    int res = multirom_copy_log(NULL, "../multirom_log.txt");
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
    static const char *text[] = { "Failed to copy log to sdcard!", "Successfully copied error log!" };
 | 
			
		||||
    static const char *text[] = { "Failed to copy log to sdcard!", "Error log was saved to: \n/sdcard/multirom_log.txt" };
 | 
			
		||||
 | 
			
		||||
    active_msgbox = fb_create_msgbox(550*DPI_MUL, 260*DPI_MUL, res ? DRED : CLR_PRIMARY);
 | 
			
		||||
    fb_msgbox_add_text(-1, 50*DPI_MUL, SIZE_NORMAL, (char*)text[res+1]);
 | 
			
		||||
    if(res == 0)
 | 
			
		||||
        fb_msgbox_add_text(-1, -1, SIZE_NORMAL, "/sdcard/multirom_log.txt");
 | 
			
		||||
    fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    fb_freeze(1);*/
 | 
			
		||||
    ncard_builder *b = ncard_create_builder();
 | 
			
		||||
    ncard_set_pos(b, NCARD_POS_CENTER);
 | 
			
		||||
    ncard_add_btn(b, BTN_NEGATIVE, "ok", ncard_hide_callback, NULL);
 | 
			
		||||
    ncard_set_title(b, "Save error log");
 | 
			
		||||
    ncard_set_text(b, text[res+1]);
 | 
			
		||||
    ncard_set_cancelable(b, 1);
 | 
			
		||||
    ncard_show(b, 1);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user