(FFOS Gecko & Gaia) OTA - 处理check结果

  当通过Checker检测到update以后,会通知UpdatePrompt中的updateCheckListener。

 

1. UpdateCheckListener.onCheckComplete

onCheckComplete: function UCL_onCheckComplete(request, updates, updateCount) {
  if (Services.um.activeUpdate) {
    // We're actively downloading an update, that's the update the user should
    // see, even if a newer update is available.
    this._updatePrompt.setUpdateStatus("active-update");
    this._updatePrompt.showUpdateAvailable(Services.um.activeUpdate);
    return;
  }

  if (updateCount == 0) {
    this._updatePrompt.setUpdateStatus("no-updates");

    if (this._updatePrompt._systemUpdateListener) {
      this._updatePrompt._systemUpdateListener.onError("no-updates");
    }

    return;
  }

 // Service.aus就是nsUpdateService.js里的UpdateService对象
// selectUpdate会通过一些预设的policy,返回updates中的某一个合适的update对象
let update
= Services.aus.selectUpdate(updates, updateCount); if (!update) { this._updatePrompt.setUpdateStatus("already-latest-version"); if (this._updatePrompt._systemUpdateListener) { this._updatePrompt._systemUpdateListener.onError("already-latest-version"); } return; } this._updatePrompt.setUpdateStatus("check-complete");
// 通知UpdatePrompt有可用的update
this._updatePrompt.showUpdateAvailable(update); },

 

2. UpdatePrompt.showUpdateAvailable(update)

showUpdateAvailable: function UP_showUpdateAvailable(aUpdate) {
  let packageInfo = {};
  packageInfo.version = aUpdate.displayVersion;
  packageInfo.description = aUpdate.statusText;
  packageInfo.buildDate = aUpdate.buildID;
  // 返回一个被选择的patch,或者第一个patch
  let patch = aUpdate.selectedPatch;
  if (!patch && aUpdate.patchCount > 0) {
    // For now we just check the first patch to get size information if a
    // patch hasn't been selected yet.
    patch = aUpdate.getPatchAt(0);
  }

  if (patch) {
    packageInfo.size = patch.size;
    packageInfo.type = patch.type;
  } else {
    log("Warning: no patches available in update");
  }

  this._pendingUpdateAvailablePackageInfo = packageInfo;

  if (this._systemUpdateListener) {
    this._systemUpdateListener.onUpdateAvailable(packageInfo.type,
                                           packageInfo.version,
                                           packageInfo.description,
                                           packageInfo.buildDate,
                                           packageInfo.size);
    // Set null since the event is fired.
    this._pendingUpdateAvailablePackageInfo = null;
  }

// 发送'update-available' event,其实就是通过SystemAppProxy发送一个'mozChromeEvent',
// 还有发送一些附带信息,比如selected patch size和patch type。接收方是谁呢?可以猜到,就是前几篇分析的SystemApp中的UpdateManager。
if (!this.sendUpdateEvent("update-available", aUpdate)) { log("Unable to prompt for available update, forcing download"); this.downloadUpdate(aUpdate); } },

 

  

posted @ 2015-08-05 11:11  coding4范儿  阅读(367)  评论(0编辑  收藏  举报