(FFOS Gecko & Gaia) OTA - 又回到UpdatePrompt

  当download完成时,又回到了UpdatePrompt,因为此时需要提示user下载完成,确认apply。

 

1. UpdatePrompt.showUpdateDownloaded

  showUpdateDownloaded: function UP_showUpdateDownloaded(aUpdate, aBackground) {
    if (this._systemUpdateListener) {
      this._systemUpdateListener.onUpdateReady();
    } else {
      this._isPendingUpdateReady = true;
    }

    // The update has been downloaded and staged. We send the update-downloaded
    // event right away. After the user has been idle for a while, we send the
    // update-prompt-restart event, increasing the chances that we can apply the
    // update quietly without user intervention.
    this.sendUpdateEvent("update-downloaded", aUpdate);

    if (Services.idle.idleTime >= this.applyIdleTimeout) {
      this.showApplyPrompt(aUpdate);
      return;
    }

    let applyIdleTimeoutSeconds = this.applyIdleTimeout / 1000;
    // We haven't been idle long enough, so register an observer
    log("Update is ready to apply, registering idle timeout of " +
        applyIdleTimeoutSeconds + " seconds before prompting.");

    this._update = aUpdate;
    this.waitForIdle();
  },

 

2. SystemUpdatable.handleEvent

    case 'update-downloaded':
      this.downloading = false;
      UpdateManager.downloaded(this);
      this.showApplyPrompt(detail.isOSUpdate);
      break;

 

3. SystemUpdatable.showApplyPrompt

// isOsUpdate comes from Gecko's update object passed in the mozChromeEvent
// and is expected to be true in case of an update package that gets applied
// in recovery mode (FOTA). We want to show the battery warning only in this
// case as described in bug 959195
SystemUpdatable.prototype.showApplyPrompt = function(isOsUpdate) {
  var batteryLevel = window.navigator.battery.level * 100;
  // 获取battery状态
  this.getBatteryPercentageThreshold().then(function(threshold) {
    this.showingApplyPrompt = true;
    if (isOsUpdate && batteryLevel < threshold) {
      this.showApplyPromptBatteryNok(threshold);
    } else {
      // battery充足情况下,提示apply
      this.showApplyPromptBatteryOk();
    }
  }.bind(this));
};

 

4. SystemUpdatable.showApplyPromptBatteryOk

SystemUpdatable.prototype.showApplyPromptBatteryOk = function() {
  // Update will be completed after restart
  this.forgetKnownUpdate();

  var cancel = {
    title: 'later',
    callback: this.declineInstallWait.bind(this)
  };

  var confirm = {
    title: 'installNow',
    callback: this.acceptInstall.bind(this),
    recommend: true
  };

  Service.request('UtilityTray:hide');
// 弹出确认对话框,当confirm升级时,调用acceptInstall函数 Service.request(
'showCustomDialog', 'systemUpdateReady', 'wantToInstallNow', cancel, confirm ); };

 

5. SystemUpdatable.acceptInstall

SystemUpdatable.prototype.acceptInstall = function() {
  Service.request('hideCustomDialog');

  // Display a splash-screen so the user knows an update is being applied
  var splash = document.createElement('form');
  splash.id = 'system-update-splash';
  ['label', 'divider', 'icon'].forEach(function(name) {
    var child = document.createElement('div');
    child.id = name;
    splash.appendChild(child);
  });
  splash.firstChild.setAttribute('data-l10n-id', 'systemUpdate');

  var screen = document.getElementById('screen');
  screen.appendChild(splash);

  this._dispatchEvent('update-prompt-apply-result', 'restart');
};

 

6. UpdatePrompt.handleEvent

      case "update-prompt-apply-result":
        this.handleApplyPromptResult(detail);
        break;

 

7. UpdatePrompt.handleApplyPromptResult

  handleApplyPromptResult: function UP_handleApplyPromptResult(aDetail) {
    if (this._applyPromptTimer) {
      this._applyPromptTimer.cancel();
      this._applyPromptTimer = null;
    }

    switch (aDetail.result) {
      // Battery not okay, do not wait for idle to re-prompt
      case "low-battery":
        break;
      case "wait":
        // Wait until the user is idle before prompting to apply the update
        this.waitForIdle();
        break;
      case "restart":
        this.finishUpdate();
        this._update = null;
        break;
    }
  },

 

8. UpdatePrompt.finishUpdate

  这里分两种情况,一种是GOTA,只需要重启b2g进程,还有一种是FOTA,调用UpdateService去完成apply的工作。

  finishUpdate: function UP_finishUpdate() {
    if (!this._update.isOSUpdate) {
      // Standard gecko+gaia updates will just need to restart the process
this.restartProcess(); return; } try { Services.aus.applyOsUpdate(this._update); } catch (e) { this._update.errorCode = Cr.NS_ERROR_FAILURE; this.showUpdateError(this._update); } },

 

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