(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);
    }
  },
时间: 2024-12-26 10:00:42

(FFOS Gecko & Gaia) OTA - 又回到UpdatePrompt的相关文章

(FFOS Gecko &amp; Gaia) OTA - Do real check

虽然代码分析了很多,但是还没有真正做check的工作,下面就来找到真正的checker. 代码位置:gecko/toolkit/mozapps/update/nsUpdateService.js.参考之前的(FFOS Gecko & Gaia) OTA - 代码模块总览,nsUpdateService.js中的Checker对象,实现了nsIUpdateChecker这个interface.下面就来分析Checker对象的实现. 1.  checkForUpdates函数: 实现略长,在代码中添

(FFOS Gecko &amp; Gaia) OTA - 进入Gecko层

代码位置:gecko/b2g/components/UpdatePrompt.js SystemApp发出'force-update-check'事件,也就从gaia进入到了gecko层. 1. 首先大概介绍一下UpdatePrompt.js. (a) UpdatePrompt.js里包含了2个对象,分别是UpdatePrompt和UpdateCheckListener. (b) UpdatePrompt实现了“@mozilla.org/updates/update-prompt;1”这个XPC

(FFOS Gecko &amp; Gaia) OTA - 代码模块总览

OTA整体框架里会涉及以下代码,从gaia到gecko都有,而且由于历史原因,复用了desktop browser的一些模块,还有一些冗余代码,分析时走了不少弯路. 1. Gaia部分 (a) gaia/apps/settings/js/panels/about/update_check.js 这个Settings中OTA功能的入口,通过AMD(Asynchronous Module Definition)规范,定义了一个模块UpdateCheck. (b) gaia/apps/system/j

(FFOS Gecko &amp; Gaia) OTA - 重回Gaia层

SystemApp中的UpdateManager作为gaia和gecko的通信桥梁,会接收gecko中UpdatePrompt发送的'update-available'事件. 1. UpdateManager.handleEvent var detail = evt.detail; if (detail.type && detail.type === 'update-available') { // systemUpdatable是在UpdateManager初始化时new出来的,Upda

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

这篇分析已经是尾声了,在UpdatePrompt中,调用了UpdateService的applyOsUpdate函数. 1. UpdateService.applyOsUpdate 这个函数很简单,就是获取到update.zip以后,调用recovery service去完成更新. applyOsUpdate: function AUS_applyOsUpdate(aUpdate) { if (!aUpdate.isOSUpdate || aUpdate.state != STATE_APPLI

(FFOS Gecko &amp; Gaia) OTA - 真正的download

前面分析了这么多,还没有真正的走到download流程.这篇就去了解真正的downloader. 1. UpdateService.downloadUpdate 看来这正的worker就是最后new出来的Downloader. downloadUpdate: function AUS_downloadUpdate(update, background) { if (!update) throw Cr.NS_ERROR_NULL_POINTER; // Don't download the upd

(FFOS Gecko &amp; Gaia) OTA - 转移至System App

代码位置:gaia/apps/system/js/update_manager.js 1. update_manager.js向全局的window对象导出了一个对象UpdateManager,其他的js module可以直接访问UpdateManager. exports.UpdateManager = UpdateManager; 2. UpdateManager监听了settings app中对于‘gaia.system.checkForUpdates’的设置,也就是当‘gaia.syste

(FFOS Gecko &amp; 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,

(FFOS Gecko) - several ways of registering a XPCOM Component

1. JavaScript Component (1) add a CustomComponent.manifest # The {classID} here must match the classID in CustomComponent.js component {e6b866e3-41b2-4f05-a4d2-3d4bde0f7ef8} components/CustomComponent.js contract @foobar/customcomponent;1 {e6b866e3-4