(FFOS Gecko & Gaia) OTA - 入口

  OTA的入口在settings app中,settings -> Device Information -> System Updates。这里可以设置update check周期,也可以check now主动检测更新。我们按照check now的流程来分析。

  代码位置:gaia/apps/settings/js/panels/about/update_check.js

 

1. 监听CheckNow click event:

init: function uc_init(elements) {
  this._elements = elements;

  this._loadLastUpdated();

  this._elements.checkUpdateNow.addEventListener('click',
    this._checkForUpdates.bind(this));
},

2. Do check

_checkForUpdates: function uc__checkForUpdates() {
  if (!navigator.onLine) {
    alert(this._('no-network-when-update'));
    return;
  }

  this._elements.updateStatus.classList.add('checking', 'visible');

  /* remove whatever was there before */
  this._elements.systemStatus.textContent = '';

  for (var setting in this._checkStatus) {
    this._checkStatus[setting].cb =
      this._onUpdateStatus.bind(this, setting);
    this._settings.addObserver(setting, this._checkStatus[setting].cb);
  }

  this._settings.createLock().set({
    'gaia.system.checkForUpdates': true
  });
}

  这里并没有做什么真正check的工作,而是通过_settings将'gaia.system.checkForUpdates'设置为true,这个_settings就是window.navigator.mozSettings。那么为什么不直接进行check的工作呢?并不是因为settings作为一个content process没有权限,而是希望复用gecko中针对于desktop browser已经有的updater组件。

  这种通过window.navigator.mozSettings来进行modules之间通信的方式,请参考"(FFOS Gecko & Gaia) IPC - 一种“猥琐的”IPC方式"。

 

posted @ 2015-08-04 15:44  coding4范儿  阅读(301)  评论(0编辑  收藏  举报