文章目录
1.Recovery流程
2.Recovery UI初始化流程分析
之前讲过Recovery 的流程。那么在定制化的过程当中,可能涉及到Recovery UI的改动。下面就介绍一下Recovery UI的一些东西。
首先还是从recovery的main函数开始分析;
int main(int argc, char **argv){
//中间处理命令的部分省略
1.这里就是开始创建UI的一个对象
Device* device = make_device();
ui = device->GetUI();
gCurrentUI = ui;
ui->SetLocale(locale);
//实例完之后开始进行初始化
ui->Init();//开启thread,监听按键
...
if (update_package != NULL) {
status = install_package(update_package, &should_wipe_cache, TEMPORARY_INSTALL_FILE, mount_required);
...
if (status != INSTALL_SUCCESS) {
ui->Print("Installation aborted.\n");
// If this is an eng or userdebug build, then automatically
// turn the text display on if the script fails so the error
// message is visible.
if (is_ro_debuggable()) {
//如果是debug版的话就显示升级的log
ui->ShowText(true);
}
}
}
}
下面将上面分为两部分来分析:
1.UI部分分析
首先看一下make_device里面做了什么事情
Device* make_device() {
return new Device(new ScreenRecoveryUI);
}
实现很简单,就是new了一个ScreenRecoveryUI的对象。
看一下ScreenRecoveryUI是如何实现的:
bootable/recovery/screen_ui.h
class ScreenRecoveryUI : public RecoveryUI {}
ScreenRecoveryUI继承自RecoveryUI。ScreenRecoveryUI中实现了画图所需要的各种接口.
下面看一下上面涉及到的接口
void ScreenRecoveryUI::Init() {
gr_init();//初始化显示设备,加载字体
gr_font_size(&char_width, &char_height);
text_rows_ = gr_fb_height() / char_height;
text_cols_ = gr_fb_width() / char_width;
text_ = Alloc2d(text_rows_, text_cols_ + 1);
file_viewer_text_ = Alloc2d(text_rows_, text_cols_ + 1);
menu_ = Alloc2d(text_rows_, text_cols_ + 1);
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]);
backgroundIcon[NO_COMMAND] = backgroundIcon[ERROR];
LoadBitmap("progress_empty", &progressBarEmpty);
LoadBitmap("progress_fill", &progressBarFill);
LoadBitmap("stage_empty", &stageMarkerEmpty);
LoadBitmap("stage_fill", &stageMarkerFill);
LoadLocalizedBitmap("installing_text", &backgroundText[INSTALLING_UPDATE]);
LoadLocalizedBitmap("erasing_text", &backgroundText[ERASING]);
LoadLocalizedBitmap("no_command_text", &backgroundText[NO_COMMAND]);
LoadLocalizedBitmap("error_text", &backgroundText[ERROR]);
pthread_create(&progress_thread_, nullptr, ProgressThreadStartRoutine, this);
//调用父类的初始化函数。
RecoveryUI::Init();
}
3.字体加载函数gr_init
int gr_init(void)