码迷,mamicode.com
首页 > 移动开发 > 详细

(FFOS Gecko & Gaia) OTA - 关键的apply

时间:2015-08-05 20:14:26      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

  这篇分析已经是尾声了,在UpdatePrompt中,调用了UpdateService的applyOsUpdate函数。

 

1. UpdateService.applyOsUpdate

  这个函数很简单,就是获取到update.zip以后,调用recovery service去完成更新。

  applyOsUpdate: function AUS_applyOsUpdate(aUpdate) {
    if (!aUpdate.isOSUpdate || aUpdate.state != STATE_APPLIED) {
      aUpdate.statusText = "fota-state-error";
      throw Cr.NS_ERROR_FAILURE;
    }

    aUpdate.QueryInterface(Ci.nsIWritablePropertyBag);
    let osApplyToDir = aUpdate.getProperty("osApplyToDir");

    if (!osApplyToDir) {
      LOG("UpdateService:applyOsUpdate - Error: osApplyToDir is not defined" +
          "in the nsIUpdate!");
      pingStateAndStatusCodes(aUpdate, false,
                              STATE_FAILED + ": " + FOTA_FILE_OPERATION_ERROR);
      handleUpdateFailure(aUpdate, FOTA_FILE_OPERATION_ERROR);
      return;
    }
    // 获取最终的update.zip
    let updateFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
    updateFile.initWithPath(osApplyToDir + "/update.zip");
    if (!updateFile.exists()) {
      LOG("UpdateService:applyOsUpdate - Error: OS update is not found at " +
          updateFile.path);
      pingStateAndStatusCodes(aUpdate, false,
                              STATE_FAILED + ": " + FOTA_FILE_OPERATION_ERROR);
      handleUpdateFailure(aUpdate, FOTA_FILE_OPERATION_ERROR);
      return;
    }

    writeStatusFile(getUpdatesDir(), aUpdate.state = STATE_APPLIED_OS);
    LOG("UpdateService:applyOsUpdate - Rebooting into recovery to apply " +
        "FOTA update: " + updateFile.path);
    try {
      let recoveryService = Cc["@mozilla.org/recovery-service;1"]
                            .getService(Ci.nsIRecoveryService);
      recoveryService.installFotaUpdate(updateFile.path);
    } catch (e) {
      LOG("UpdateService:applyOsUpdate - Error: Couldn‘t reboot into recovery" +
          " to apply FOTA update " + updateFile.path);
      pingStateAndStatusCodes(aUpdate, false,
                              STATE_FAILED + ": " + FOTA_RECOVERY_ERROR);
      writeStatusFile(getUpdatesDir(), aUpdate.state = STATE_APPLIED);
      handleUpdateFailure(aUpdate, FOTA_RECOVERY_ERROR);
    }
  },

 

2. "@mozilla.org/recovery-service;1"

  这个service就不在这里分析了,很简单,只是对librecovery.so的简单封装,熟悉android OTA的同学一看就懂。

(FFOS Gecko & Gaia) OTA - 关键的apply

标签:

原文地址:http://www.cnblogs.com/code-4-fun/p/4705452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!