Android 8.0 OTA 分析——recovery

本文详细介绍了Android 8.0 OTA更新的recovery模块,包括升级入口、具体升级过程和升级后的扫尾工作。分析了上层写入命令主动升级、SD卡安装以及adb方式更新的流程,重点探讨了升级包的校验、执行及pipe通信在升级过程中的作用。
摘要由CSDN通过智能技术生成

这里是OTA分析的第一部分,主要是recovery模块,后面会对脚本进行分析
如果有分析不到位的地方请指出,共同学习进步

一、首先来看下升级的入口

1.上层写入命令主动升级:

这是最常见的方式,负责升级的APK会向command中写入升级的信息,比如”–update_package”参数和升级包的路径等

[recovery.cpp]
if (update_package != NULL) {
    // It's not entirely true that we will modify the flash. But we want
    // to log the update attempt since update_package is non-NULL.
    modified_flash = true;

    if (!is_battery_ok()) {
        ui->Print("battery capacity is not enough for installing package, needed is %d%%\n",
                  BATTERY_OK_PERCENTAGE);
        // Log the error code to last_install when installation skips due to
        // low battery.
        log_failure_code(kLowBattery, update_package);
        status = INSTALL_SKIPPED;
    } else if (bootreason_in_blacklist()) {
        // Skip update-on-reboot when bootreason is kernel_panic or similar
        ui->Print("bootreason is in the blacklist; skip OTA installation\n");
        log_failure_code(kBootreasonInBlacklist, update_package);
        status = INSTALL_SKIPPED;
    } else {
        status = install_package(update_package, &should_wipe_cache,
                                 TEMPORARY_INSTALL_FILE, true, retry_count);
        if (status == INSTALL_SUCCESS && should_wipe_cache) {
            wipe_cache(false, device);
        }
        if (status != INSTALL_SUCCESS) {
            ui->Print("Installation aborted.\n");
            // When I/O error happens, reboot and retry installation EIO_RETRY_COUNT
            // times before we abandon this OTA update.
            if (status == INSTALL_RETRY && retry_count < EIO_RETRY_COUNT) {
                copy_logs();
                set_retry_bootloader_message(retry_count, args);
                // Print retry count on screen.
                ui->Print("Retry attempt %d\n", retry_count);

                // Reboot and retry the update
                if (!reboot("reboot,recovery")) {
                    ui->Print("Reboot failed\n");
                } else {
                    while (true) {
                        pause();
                    }
                }
            }
            // 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()) {
                ui->ShowText(true);
            }
        }
    }
}

从上面的逻辑可以看到,首先要进行电量的检测,然后是启动原因的检查,最后调用install_package升级

2.从SD卡安装升级包

这是我们调试经常要操作的地方:
在recovery选择菜单上有这一项,在之前Android 8.0 recovery 流程分析中有说到在prompt_and_wait中会检测用户选择:

case Device::APPLY_SDCARD:
{
  bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
  if (adb) {
    status = apply_from_adb(ui, &should_wipe_cache, TEMPORARY_INSTALL_FILE);
  } else {
    status = apply_from_sdcard(device, &should_wipe_cache);
  }

  if (status == INSTALL_SUCCESS && should_wipe_cache) {
    if (!wipe_cache(false, device)) {
      status = INSTALL_ERROR;
    }
  }

  if (status != INSTALL_SUCCESS) {
    ui
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值