Android Recovery Ui Analysis

Source: Internet
Author: User
Tags clear screen strcmp

AndroidRecovery and Android are essentially two independent rootfs, just recovery the meaning of this rootfs existence is for Android this rootfs service, so it is interpreted as part of the Android system. Recovery as a simple rootfs, provides a very limited number of features, contains only a few simple libraries, the UI is displayed in the form of direct brush framebuffer, as the Android framework and the app layer of the Code farm, the form of relatively unfamiliar, Special time to comb some. First, look at the UI-related statements in the main function code of Reocvery
Main (int argc, char **argv) {    ...    device* device = Make_device ();            UI = Device->getui ();    Gcurrentui = UI;    Ui->init ();    Ui->setlocale (locale);    Ui->setbackground (recoveryui::none);    if (Show_text) Ui->showtext (true);    ......    if (Status! = Install_success | | ui->istextvisible ()) {        prompt_and_wait (device, status);    }    ......}
1, the first new object of a device class, the device class encapsulates a number of operations, including UI Operation 2, call the device Class Getui () to return a Defaultui object, recovery involves three UI classes, three classes are an inheritance relationship , Defaultui, Screenrecoveryui, Recoveryui 3, call Init () of the Defaultui class, and the Defaultui class does not have the init () method, So will call its parent class Screenrecoveryui's Init () 4, similarly, call the Screenrecoveryui class of setlocale () to identify a few more special areas 5, the same, Call the SetBackground () of the Screenrecoveryui class to set the initial state of the background Figure 6, display the recovery main interface, that is, a selection menu

void Screenrecoveryui::init () {gr_init ();    Gr_font_size (&char_width, &char_height);    Text_col = Text_row = 0;    Text_rows = Gr_fb_height ()/char_height;    if (Text_rows > kmaxrows) text_rows = kmaxrows;    Text_top = 1;    Text_cols = Gr_fb_width ()/char_width;    if (Text_cols > kMaxCols-1) text_cols = kMaxCols-1;    LoadBitmap ("icon_installing", &backgroundicon[installing_update]);    Backgroundicon[erasing] = backgroundicon[installing_update];    LoadBitmap ("Icon_error", &backgroundicon[error]);    Backgroundicon[no_command] = Backgroundicon[error];    LoadBitmap ("Progress_empty", &progressbarempty);    LoadBitmap ("Progress_fill", &progressbarfill);    Loadlocalizedbitmap ("Installing_text", &backgroundtext[installing_update]);    Loadlocalizedbitmap ("Erasing_text", &backgroundtext[erasing]);    Loadlocalizedbitmap ("No_command_text", &backgroundtext[no_command]); Loadlocalizedbitmap ("Error_text", &backgroundtext[error]);    int i; Progressbarindeterminate = (gr_surface*) malloc (Indeterminate_frames * s    Izeof (Gr_surface));                                                   for (i = 0; I 0) {Installationoverlay = (gr_surface*) malloc (Installing_frames *        sizeof (Gr_surface));  for (i = 0; i

1. Gr_init () Initialize the graphics device and allocate the memory rendered by the Pixelflinger library

2. Gr_font_size () assigns the surface width of the font to Char_width and char_height

3. LoadBitmap () Creates a PNG surface, each PNG image corresponds to a surface, and all surface is stored in an array of 4, Loadlocalizedbitmap () The text information in the picture where the area text is located is extracted from the current locale to produce the corresponding surface, so surface is also stored in an array of 6, Pthread_create (&progress_t, NULL, Progress_thread, NULL) creates a thread that is a dead loop in which the task is constantly detecting currenticon and progressbartype to decide whether to update the progress bar. 7. Call Recoveryui init () to initialize the input event processing.

void Screenrecoveryui::setlocale (const char* locale) {    if (locale) {        char* lang = strdup (locale);        for (char* p = lang; *p; ++p) {            if (*p = = ' _ ') {                *p = ' + ');                break;            }        }        A bit Cheesy:keep an explicit list of supported languages        //is RTL.        if (strcmp (lang, "ar") = = 0 | |   Arabic            strcmp (lang, "fa") = = 0 | |   Persian (Farsi)            strcmp (lang, "he") = = 0 | |   Hebrew (new language code)            strcmp (lang, "iw") = = 0 | |   Hebrew (Old language code)            strcmp (lang, "ur") = = 0) {   //Urdu            Rtl_locale = true;        }        Free (lang);    }}

The setlocale of the Screenrecoveryui class, which determines whether the font used by locale belongs to the Arabic language, the Arabic writing habit is from right to left, and if it is an Arabic language, it sets a flag, This flag is followed by the decision to display text or progress bars from right to left. The parameter locale assignment logic for the setlocale is this, which is read from the command file, where the commands for setting the locale are "--locale=ZH_CN ", if there is no incoming locale, an attempt is made to read the locale from the/cache/recovery/last_locale during initialization, and if the file is not, the locale is not assigned, and it is used by default with 中文版.
void Screenrecoveryui::setbackground (icon icon) {    pthread_mutex_lock (&updatemutex);    Adjust the offset to account for the positioning of the    //base image in 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;< c9/>}    Currenticon = icon;    Update_screen_locked ();    Pthread_mutex_unlock (&updatemutex);}
SetBackground function is relatively concise, the key part in update_screen_locked, below we focus on analysis. Update_screen_locked and update_progress_locked are key functions of the UI part of recovery, update_screen_locked is used to update the background, Update_progress_ The locked is used to update the progress bar because the displayed screen is always updated, so the two functions are called repeatedly in different places
void screenrecoveryui::update_screen_locked () {    draw_screen_locked ();    Gr_flip ();}
Update_screen_locked contains two operations, one is to update screen, and the other is to switch between buffer.
void Screenrecoveryui::d raw_screen_locked () {draw_background_locked (Currenticon);    Draw_progress_locked ();        if (show_text) {setcolor (Text_fill);        Gr_fill (0, 0, gr_fb_width (), Gr_fb_height ());        int y = 0;        int i = 0;            if (show_menu) {setcolor (HEADER); In the implementation code of the for (; I y+2 && count draw_background_locked function, several functions beginning with gr_ appear, with functions beginning with gr_ from the Minui library. Minui Library code in the recovery source under the Minui directory, Minui provides the interface to achieve a graphical depiction and fixed-size text display.  Gr_color (unsigned char r, unsigned char g, unsigned char b, unsigned char a);  /* Set the font color */gr_fill (int x, int y, int w, int h);  /* Fills the rectangular area with parameters representing the starting coordinates, the rectangular area size */gr_blit (gr_surface source, int sx, int sy, int w, int h, int dx, int dy); /* Fills the picture specified by source */The draw_background_locked function fills the entire render buffer with black first, then calculates the length and width of the background surface, the length of the text surface,  Combined with the long width of the FB to calculate the background surface and the coordinates of the text surface display, there is a long width and coordinates can call the Pixelflinger interface on render buffer to render.
void Screenrecoveryui::d raw_progress_locked () {if (Currenticon = = ERROR) return;    if (Currenticon = = Installing_update | | currenticon = = erasing) {draw_install_overlay_locked (installingframe);        } if (Progressbartype! = EMPTY) {int iconheight = Gr_get_height (Backgroundicon[installing_update]);        int width = gr_get_width (progressbarempty);        int height = gr_get_height (progressbarempty);        int dx = (gr_fb_width ()-width)/2;        int dy = (3*gr_fb_height () + iconheight-2*height)/4;        Erase Behind the progress bar (in case this is a progress-only update) gr_color (0, 0, 0, 255);        Gr_fill (dx, dy, width, height);            if (Progressbartype = = determinate) {Float p = progressscopestart + progress * progressscopesize;            int pos = (int) (p * width);                if (Rtl_locale) {//Fill the progress bar from right to left. if (pos > 0) {gr_blit (Progressbarfill, Width-pos, 0, pos, height, dx+width-pos, dy);                } if (pos 0) {gr_blit (progressbarfill, 0, 0, pos, height, dx, dy); The IF (POS draw_progress_locked function is similar in principle to the update_screen_locked function, ultimately the surface of the progress bar is output to render buffer, and the picture of each scene in the recovery Surface, which is the overlap of background, text, progress bar, different surface and surface coordinates. The UI code in the recovery main function has been basically analyzed, and the last point of the main menu is to display the text picture through the interfaces described above, so it's no longer a lot to talk about. In general, recovery UI display part of the difficulty, the application layer call Minui Library to achieve the graphics and fixed-size text display, Minui library called the Pixelflinger Library to render. Attach a description of the Minui part of the interface, for reference
int gr_init (void);            /* Initialize the graphical display, mainly to open the device, allocate memory, initialize some parameters */void gr_exit (void);         /* Unregister the graphic display, turn off the device and free the memory */int gr_fb_width (void);        /* Gets the width of the screen */int gr_fb_height (void);    /* Get the height of the screen */Gr_pixel *gr_fb_data (void);            /* Gets the address of the display data cache */void gr_flip (void);  /* Refresh the contents of the display */void Gr_fb_blank (bool blank);  /* Clear screen */void Gr_color (unsigned char r, unsigned char g, unsigned char b, unsigned char a);  /* Set the font color */void Gr_fill (int x, int y, int w, int h);  /* Fills the rectangular area, with the parameters representing the starting coordinates, the rectangular area size */int Gr_text (int x, int y, const char *s), respectively;             /* Display String */int gr_measure (const char *s);         /* Gets the pixel length that the string occupies in the default font */void gr_font_size (int *x, int *y);  /* Gets the current font of a character occupied by the length of */void Gr_blit (gr_surface source, int sx, int sy, int w, int h, int dx, int dy);   /* Fills the picture specified by source */unsigned int gr_get_width (gr_surface surface);  /* Get picture Width */unsigned int gr_get_height (gr_surface surface); /* Get Picture Height */* Create display resource data according to picture, name for picture relative path specified in MK file */int Res_creaTe_surface (const char* name, gr_surface* psurface);       void Res_free_surface (gr_surface surface);   /* Release Resource Data */

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Recovery Ui Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.