Android 8.0 OTA 分析——recovery

这里是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
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android OTA(Over-the-Air)代码是指用于进行系统升级和更新的代码。OTA升级是指利用无线通信网络对Android系统进行在线升级和更新,不需要连接到电脑上通过USB进行升级OTA代码的功能主要有两个方面:一是判断是否有新版本可用,二是进行升级和更新操作。 首先,OTA代码需要实现检测新版本的功能。它通过与服务器建立通信,获取最新的版本信息。根据设备信息和当前的系统版本,OTA代码可以向服务器发送请求,查询是否有新版本的可用。服务器会返回包含最新版本信息的XML或JSON格式数据。这些数据中包括了更新的内容、升级的步骤以及升级包的下载链接。 其次,OTA代码需要实现升级和更新的功能。一旦发现有新版本可用,OTA代码会下载升级包,并进行升级操作。升级包通常是一个压缩文件,其中包含了新版本的系统文件和相关的更新配置文件。OTA代码会解压升级包,将其中的系统文件替换现有的系统文件,更新系统的功能或修复已知的问题。在升级的过程中,OTA代码还需要处理系统的备份和恢复、应用程序的兼容性测试等问题,以确保升级过程的顺利进行。 总结来说,Android OTA代码是实现系统在线升级和更新的一套功能的代码。通过与服务器的通信,OTA代码可以检测并获取最新的系统版本信息,然后进行升级的操作。这样,用户可以在无需连接电脑的情况下,通过无线通信网络来方便地更新和升级自己的Android系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值