设为首页 加入收藏

TOP

Recovery启动流程(2)---UI界面【转】(一)
2019-09-19 18:10:15 】 浏览:95
Tags:Recovery 启动 流程 ---UI 界面

Recovery启动流程系列文章把recvoery目录下文件分成小块讲解,最后再以一条主线贯穿所有的内容。这篇文章主要讲解Recovery-UI的相关内容。

我们知道,当我们通过按键或者应用进入recovery模式,实质是kernel后加载recovery.img,kernel起来后执行的第一个进程就是init,此进程会读入init.rc启动相应的服务。在recovery模式中,启动的服务是执行recovery可执行文件,此文件是bootable/recovery/recovery.cpp文件生成,我们就从recovery.cpp文件开始分析。

bootable/recovery/recovery.cpp

int
main(int argc, char **argv) {

....
    Device* device = make_device();
    ui = device->GetUI();
    gCurrentUI = ui;

    ui->SetLocale(locale);
    ui->Init();

    ui->SetBackground(RecoveryUI::NONE);  
    if (show_text) ui->ShowText(true);  
....
    if (status != INSTALL_SUCCESS || ui->IsTextVisible()) {  
        prompt_and_wait(device, status);  
    }  
....




}
  1. 首先新建了一个Device类的对象, Device类封装了一些操作,包括UI的操作
  2. 调用Device类的GetUI()返回一个RecoveryUI对象

  3. 调用ui->SetLocale(locale)设置语言,调用SetBackground方法设置背景图片

  4. 调用Init()进行初始化。

  5. 这里的Init从代码上看应该是ui.cpp文件中RecoveryUI类的Init()方法,是ScreenRecoveryUI,这里我是按照ScreenRecoveryUI::Init追的代码。其中RecoveryUI是ScreenRecoveryUI的父类。

  6. 显示recovery的主界面,即一个选择菜单

实现头部显示和列表项device.h

static const char* MENU_ITEMS[] = {
    "Reboot system now",
    "Apply update from ADB",
    "Wipe data/factory reset",
    "Wipe cache partition",
    "Reboot to bootloader",
    "Power off",
    "View recovery logs",
    "Apply update from sdcard",
    "Apply update from usbotg",
    "Security unlock", 
    "Download secure info",
    "Download hwc info",
    "Apply OTAconfig update from sdcard",
    "Apply OTAconfig update from usbotg",
    "Apply OTAconfig update from usbotg path",
    
    NULL,
};

static const Device::BuiltinAction MENU_ACTIONS[] = {
    Device::REBOOT,
    Device::APPLY_ADB_SIDELOAD,
    Device::WIPE_DATA,
    Device::WIPE_CACHE,
    Device::REBOOT_BOOTLOADER,
    Device::SHUTDOWN,
    Device::VIEW_RECOVERY_LOGS,
    Device::APPLY_SDCARD,
    Device::APPLY_USB,
    Device::SECURE_UNLOCK,
    Device::DOWNLOAD_SECURE_INFO,
    Device::DOWNLOAD_HWC_INFO,
    Device::APPLY_OTACONFIG_EXT,
    Device::APPLY_OTACONFIG_USB,
    Device::APPLY_OTACONFIG_USB_PATH,

    //Device::MOUNT_SYSTEM,
};
void ScreenRecoveryUI::Init() {
    gr_init();             //初始化图形设备,分配Pixelflinger库渲染的内存

    gr_font_size(&char_width, &char_height);
    text_rows_ = gr_fb_height() / char_height;
    text_cols_ = gr_fb_width() / char_width;

#ifdef SUPPORT_UTF8_MULTILINGUAL
    int ml_cols_ = 6 * text_cols_; //max is 6 char for 1 utf8 character.
    text_ = Alloc2d(text_rows_, ml_cols_ + 1);
    file_viewer_text_ = Alloc2d(text_rows_, ml_cols_ + 1);
    menu_ = Alloc2d(text_rows_, ml_cols_ + 1);
    menu_headers_wrap = Alloc2d(text_rows_, ml_cols_ + 1);
#else
    text_ = Alloc2d(text_rows_, text_cols_ + 1);
    file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
    menu_ = Alloc2d(text_rows_, text_cols_ + 1);
#endif

    text_col_ = text_row_ = 0;
    text_top_ = 1;

    backgroundIcon[NONE] = nullptr;
    LoadBitmapArray("icon_installing", &installing_frames, &installation);
    backgroundIcon[INSTALLING_UPDATE] = installing_frames ? installation[0] : nullptr;
    backgroundIcon[ERASING] = backgroundIcon[INSTALLING_UPDATE];
    LoadBitmap("icon_error", &backgroundIcon[ERROR]);                //LoadBitmap()  将png生成surface, 每个png图片对应一个surface, 所有surface存放在一个数组中
    backgroundIcon[NO_COMMAND] =
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Recovery启动流程--recovery.cpp.. 下一篇makefile学习之函数

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目