From a065e04d529da1d847b5062a12c46d916408bf32 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 21:46:22 -0500 Subject: update based on https://github.com/mdn/yari/issues/2028 --- .../contacts/index.html | 71 -- .../device_storage/index.html | 111 ---- .../geolocation/index.html | 20 - .../3rd_party_app_developer_guide/index.html | 90 --- .../web_activity/index.html | 116 ---- .../index.html" | 70 -- .../index.html" | 78 --- files/zh-tw/archive/b2g_os/add-ons/index.html | 282 -------- files/zh-tw/archive/b2g_os/api/fmradio/index.html | 110 ---- files/zh-tw/archive/b2g_os/api/index.html | 156 ----- files/zh-tw/archive/b2g_os/apps/index.html | 45 -- .../apps/writing_a_web_app_for_b2g/index.html | 25 - files/zh-tw/archive/b2g_os/architecture/index.html | 717 --------------------- .../gaia_ui_tests_run_tests/index.html | 111 ---- .../automated_testing/gaia-ui-tests/index.html | 69 -- .../archive/b2g_os/automated_testing/index.html | 77 --- files/zh-tw/archive/b2g_os/building/index.html | 124 ---- .../firefox_os_build_process_summary/index.html | 108 ---- .../building_and_installing_firefox_os/index.html | 65 -- .../choosing_how_to_run_gaia_or_b2g/index.html | 59 -- files/zh-tw/archive/b2g_os/debugging/index.html | 21 - .../firefox_os_build_prerequisites/index.html | 606 ----------------- files/zh-tw/archive/b2g_os/index.html | 222 ------- .../index.html | 53 -- files/zh-tw/archive/b2g_os/introduction/index.html | 86 --- .../archive/b2g_os/phone_guide/flame/index.html | 50 -- files/zh-tw/archive/b2g_os/phone_guide/index.html | 6 - .../archive/b2g_os/phone_guide/zte_open/index.html | 287 --------- .../b2g_os/platform/apps_architecture/index.html | 24 - .../b2g_os/platform/gaia/gaia_apps/index.html | 78 --- .../zh-tw/archive/b2g_os/platform/gaia/index.html | 68 -- .../platform/gaia/introduction_to_gaia/index.html | 13 - .../zh-tw/archive/b2g_os/platform/gonk/index.html | 22 - files/zh-tw/archive/b2g_os/platform/index.html | 75 --- .../index.html | 53 -- .../preparing_for_your_first_b2g_build/index.html | 138 ---- .../archive/b2g_os/quickstart/app_tools/index.html | 28 - files/zh-tw/archive/b2g_os/quickstart/index.html | 51 -- .../b2g_os/quickstart/your_first_app/index.html | 265 -------- files/zh-tw/archive/b2g_os/releases/1.2/index.html | 465 ------------- files/zh-tw/archive/b2g_os/releases/index.html | 24 - .../index.html | 43 -- .../index.html | 208 ------ .../security/application_security/index.html | 124 ---- files/zh-tw/archive/b2g_os/security/index.html | 70 -- .../b2g_os/security/security_model/index.html | 299 --------- .../b2g_os/security/system_security/index.html | 376 ----------- files/zh-tw/archive/b2g_os/simulator/index.html | 90 --- .../simulator/simulator_walkthrough/index.html | 268 -------- .../b2g_os/using_the_app_manager/index.html | 259 -------- .../b2g_os/using_the_b2g_desktop_client/index.html | 180 ------ .../b2g_os/using_the_b2g_emulators/index.html | 69 -- .../archive/b2g_os/web_telephony_api/index.html | 25 - .../writing_apps_for_boot_to_gecko/index.html | 12 - 54 files changed, 7162 deletions(-) delete mode 100644 files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/contacts/index.html delete mode 100644 files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/device_storage/index.html delete mode 100644 files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/geolocation/index.html delete mode 100644 files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/index.html delete mode 100644 files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/web_activity/index.html delete mode 100644 "files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\345\260\201\345\214\205\345\274\217_(packaged)_app/index.html" delete mode 100644 "files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\346\211\230\347\256\241\346\233\264\346\226\260\344\275\234\346\245\255_(hosting_updates)_/index.html" delete mode 100644 files/zh-tw/archive/b2g_os/add-ons/index.html delete mode 100644 files/zh-tw/archive/b2g_os/api/fmradio/index.html delete mode 100644 files/zh-tw/archive/b2g_os/api/index.html delete mode 100644 files/zh-tw/archive/b2g_os/apps/index.html delete mode 100644 files/zh-tw/archive/b2g_os/apps/writing_a_web_app_for_b2g/index.html delete mode 100644 files/zh-tw/archive/b2g_os/architecture/index.html delete mode 100644 files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/gaia_ui_tests_run_tests/index.html delete mode 100644 files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/index.html delete mode 100644 files/zh-tw/archive/b2g_os/automated_testing/index.html delete mode 100644 files/zh-tw/archive/b2g_os/building/index.html delete mode 100644 files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_process_summary/index.html delete mode 100644 files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/index.html delete mode 100644 files/zh-tw/archive/b2g_os/choosing_how_to_run_gaia_or_b2g/index.html delete mode 100644 files/zh-tw/archive/b2g_os/debugging/index.html delete mode 100644 files/zh-tw/archive/b2g_os/firefox_os_build_prerequisites/index.html delete mode 100644 files/zh-tw/archive/b2g_os/index.html delete mode 100644 files/zh-tw/archive/b2g_os/installing_boot_to_gecko_on_a_mobile_device/index.html delete mode 100644 files/zh-tw/archive/b2g_os/introduction/index.html delete mode 100644 files/zh-tw/archive/b2g_os/phone_guide/flame/index.html delete mode 100644 files/zh-tw/archive/b2g_os/phone_guide/index.html delete mode 100644 files/zh-tw/archive/b2g_os/phone_guide/zte_open/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/apps_architecture/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/gaia/gaia_apps/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/gaia/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/gonk/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/index.html delete mode 100644 files/zh-tw/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html delete mode 100644 files/zh-tw/archive/b2g_os/preparing_for_your_first_b2g_build/index.html delete mode 100644 files/zh-tw/archive/b2g_os/quickstart/app_tools/index.html delete mode 100644 files/zh-tw/archive/b2g_os/quickstart/index.html delete mode 100644 files/zh-tw/archive/b2g_os/quickstart/your_first_app/index.html delete mode 100644 files/zh-tw/archive/b2g_os/releases/1.2/index.html delete mode 100644 files/zh-tw/archive/b2g_os/releases/index.html delete mode 100644 files/zh-tw/archive/b2g_os/running_custom_builds_in_the_app_manager/index.html delete mode 100644 files/zh-tw/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html delete mode 100644 files/zh-tw/archive/b2g_os/security/application_security/index.html delete mode 100644 files/zh-tw/archive/b2g_os/security/index.html delete mode 100644 files/zh-tw/archive/b2g_os/security/security_model/index.html delete mode 100644 files/zh-tw/archive/b2g_os/security/system_security/index.html delete mode 100644 files/zh-tw/archive/b2g_os/simulator/index.html delete mode 100644 files/zh-tw/archive/b2g_os/simulator/simulator_walkthrough/index.html delete mode 100644 files/zh-tw/archive/b2g_os/using_the_app_manager/index.html delete mode 100644 files/zh-tw/archive/b2g_os/using_the_b2g_desktop_client/index.html delete mode 100644 files/zh-tw/archive/b2g_os/using_the_b2g_emulators/index.html delete mode 100644 files/zh-tw/archive/b2g_os/web_telephony_api/index.html delete mode 100644 files/zh-tw/archive/b2g_os/writing_apps_for_boot_to_gecko/index.html (limited to 'files/zh-tw/archive/b2g_os') diff --git a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/contacts/index.html b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/contacts/index.html deleted file mode 100644 index 431f85c5f6..0000000000 --- a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/contacts/index.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: 聯絡人資訊 -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/Contacts ---- -

聯絡人資訊 (contacts)

-

Contacts API 讓您可以取得使用者手機中所儲存的聯絡人列表、聯絡人姓名、電話、… 等資訊。
- 由於它牽涉到使用者私密資訊,目前僅開放審查通過的應用(privileged/certified)能夠使用這個 API。您的應用必須提出使用這個 API 的聲明,並且通過審查方可使用。
-
- 權限宣告:分為 "readonly", "readwrite", "readcreate" 三種級別,分別代表「只讀取」、「讀取與修改」、「讀取與新增」。您可依照應用需求作適當的權限宣告。

-
"permissions": {
-  "contacts":{ "access": "readonly" }
-}
-

1. 讀取聯絡人列表

-
    var options = {
-      sortBy: 'familyName',
-      sortOrder: 'ascending'
-    };
-    var request = navigator.mozContacts.find(options);
-    request.onsuccess = function findSuccess() {
-      var firstContact = request.result[0];
-      console.log('name' + firstContact.name);
-      console.log('tel number' + firstContact.tel[0].value);
-      console.log('update time' + new Date(firstContact.updated));
-    };
-
-    request.onerror = function findError() {
-      console.warn('Error: cannot find any contacts - ' + request.error.name);
-    };
-

2. 新增聯絡人

-
    var myContact = {
-      'name': 'Alice Wang',
-      'givenName': 'Alice',
-      'familyName': 'Wang',
-      'tel': [{'value': '0912345678'}]
-    };
-    var contact = new mozContact();
-    contact.init(myContact);
-    var request = navigator.mozContacts.save(contact);
-    request.onerror = function onerror() {
-      console.warn('Error: save contact - ' + request.error.name);
-    }; 
-

3. 修改聯絡人資訊

-
    var options = {
-      filterBy: ['tel', 'givenName', 'familyName'],
-      filterOp: 'contains',
-      filterValue: 'Alice'
-    };
-    var request = navigator.mozContacts.find(options);
-    request.onsuccess = function findSuccess() {
-      var contact = req.result[0];
-      contact.tel[0].value = '0987654321';
-      var requestUpdate = navigator.mozContacts.save(contact);
-      requestUpdate.onerror = function onerror() {
-        console.warn('Error: update contact - ' + requestUpdate.error.name);
-      };
-    }; 
-

4. 刪除聯絡人

-
    var options = {
-      filterBy: ['id'],
-      filterOp: 'equals',
-      filterValue: '0987654321'
-    };
-    var request = navigator.mozContacts.find(options);
-    request.onsuccess = function findSuccess() {
-      var contact = req.result[0];
-      var requestRemove = navigator.mozContacts.remove(contact);
-      requestRemove.onerror = function onerror() {
-        console.warn('Error: remove contact - ' + requestRemove.error.name);
-      };
-    }; 
-

 

diff --git a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/device_storage/index.html b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/device_storage/index.html deleted file mode 100644 index d8c6fd2916..0000000000 --- a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/device_storage/index.html +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: 儲存裝置資訊 -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/Device_Storage ---- -

儲存裝置資訊 (Device Storage)

-

DeviceStorage API 提供 SD 記憶卡內的資料存取介面,可讀取圖片檔、聲音檔、影片檔,與 SD 記憶卡的其他檔案,並檢視 SD 記憶卡空間的使用率。
- 由於牽涉到使用者的儲存裝置資訊,目前僅開放 Privileged/Certified App 能夠使用此 API。你的 App 必須提出「使用此 API」的聲明,並且通過審查方可使用。
-
- 權限宣告:依照檔案類型 (圖片、影片、聲音、其他) 而有不同宣告方式,這種宣告另分為「readonly」、「readwrite」、「readcreate」共 3 種級別,分別代表「唯讀」、「讀取與修改」、「讀取與創建」。你可依照 App 需求作適當的權限宣告。

-
"permissions": {
-  "device-storage:pictures": { "access": "readonly" },
-  "device-storage:music": { "access": "readcreate" },
-  "device-storage:videos": { "access": "readwrite" },
-  "device-storage:sdcard": { "access": "readonly" }
-}
-

1. 音樂檔案列表

- -
    var type = 'music';
-    var deviceStorage = navigator.getDeviceStorage(type);
-    if (!deviceStorage) {
-      console.warn('Error: cannot get DeviceStorage for ' + type);
-      return;
-    }
-    var request = deviceStorage.enumerate();
-    request.onsuccess = function(e) {
-      var file = request.result;
-      console.log('file name ' + file.name);
-      console.log('file size ' + file.size);
-      console.log('file type ' + file.type);
-      console.log('file last Modified Date ' + file.lastModifiedDate);
-      request.continue();
-    };
-    request.onerror = function() {
-      console.warn('Error: cannot list files in SD card - ' + request.error.name);
-    };
-

2. 讀取某個 SD 卡檔案

- -
    var type = 'pictures';
-    var deviceStorage = navigator.getDeviceStorage(type);
-    if (!deviceStorage) {
-      console.warn('Error: cannot get DeviceStorage for ' + type);
-      return;
-    }
-    var filename = 'downloads/DSC02798.JPG';
-    var request = deviceStorage.get(filename);
-    request.onsuccess = function(e) {
-      var file = request.result;
-      var url = URL.createObjectURL(file);
-      var myImage = document.getElementById('profilePhoto');
-      myImage.src = url;
-    };
-    request.onerror = function() {
-      console.warn('Error: get file from SD card - ' + request.error.name);
-    };
-

3. 寫入檔案到 SD 卡

- -
    var type = 'sdcard';
-    var deviceStorage = navigator.getDeviceStorage(type);
-    if (!deviceStorage) {
-      console.warn('Error: cannot get DeviceStorage for ' + type);
-      return;
-    }
-    var filename = 'test-' + Math.random().toString() + '.txt';
-    var pathname = 'test-tmp/' + filename;
-    console.log('file path: ' + pathname);
-    var blob = new Blob(['hello', 'world'], {type: 'text/plain'});
-    var request = deviceStorage.addNamed(blob, pathname);
-    request.onsuccess = function(e) {
-     // try to get the file
-      var readRequest = deviceStorage.get(pathname);
-      readRequest.onsuccess = function() {
-        var file = readRequest.result;
-        var reader = new FileReader();
-        reader.onload = function(e) {
-          console.log('file content ' + e.target.result);
-        };
-        reader.readAsText(file);
-      };
-      readRequest.onerror = function() {
-        console.warn("Error: read file failure - " + request.error.name);
-      };
-    };
-    request.onerror = function() {
-      console.warn('Error: write file failure - ' + request.error.name);
-    };
-

4. SD 卡空間使用率

- -
    var type = 'sdcard';
-    var deviceStorage = navigator.getDeviceStorage(type);
-    if (!deviceStorage) {
-      console.warn('Error: cannot get DeviceStorage for ' + type);
-      return;
-    }
-    var request = deviceStorage.stat();
-    request.onsuccess = function(e) {
-      var totalSize = e.target.result.totalBytes;
-      var freeBytes = e.target.result.freeBytes;
-      console.log('totalSize ' + totalSize + ', freeBytes ' + freeBytes);
-    };
-    request.onerror = function() {
-      console.warn('Error: cannot get stat of SD card - ' + request.error.name);
-    };
-

 

diff --git a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/geolocation/index.html b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/geolocation/index.html deleted file mode 100644 index 575d719313..0000000000 --- a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/geolocation/index.html +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: 位置資訊 -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/Geolocation ---- -

位置資訊 (geolocation)

-

Geolocation API 讓您可以取得使用者目前所在的地理位置資訊,雖然現今它已是一個 Web 開放標準的 API,但在 Firefox OS 中您必須做權限宣告才可使用。
- 但當您使用這個 API 企圖存取使用者位置時,系統會出現一個視窗詢問使用者是否願意透露位置訊息給您的應用,並且提供一個默認選項記住使用者的選擇。
-
- 權限宣告:需要

-
"permissions": {
-  "geolocation": {}
-}
-

範例:

-
navigator.geolocation.getCurrentPosition(function(position) {
-  console.log('latitude ' + position.coords.latitude);
-  console.log('longitude ' + position.coords.longitude);
-}, function() {
-  console.warn('Error: cannot fetch location');
-});
-
diff --git a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/index.html b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/index.html deleted file mode 100644 index d258c076d5..0000000000 --- a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/index.html +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: 第三方應用開發者指南 -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide ---- -

基本章節

-

快速入門

-

API 說明

- -

其他技術細節

- -

除錯與預覽

- -

測試

- -

應用上架

- -

進階章節

-

樣式參考與範本

- -

調校技巧

- -

Gaia 系統應用 (System App) 細節

- -

其他 Open Web 技術

- diff --git a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/web_activity/index.html b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/web_activity/index.html deleted file mode 100644 index 8b9e1e52ad..0000000000 --- a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/web_activity/index.html +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: Web Activity -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/Web_Activity ---- -

Web Activity

-

許多手機上常見的功能例如:選取聯絡人、撥打電話、照相是您的 App 會需要用到的功能。您可以不必重新發明輪子,而利用「Web Activity」的技術呼叫其他的 App 來完成任務。Web Activity 可以實作兩個 App 間的切換,例如從「相機」切換到「圖片集」,或者是「簡訊」使用「聯絡人」選取一個簡訊發送對象。
-
- 在您的 App 中只需要描述所需的操作,系統會幫您檢查手機中有哪些 App 提供這些操作。以下是一個具體的例子。這是在「相機」中的一段程式碼,用來切換到別的 App 瀏覽相片。

-
  var act = new MozActivity({
-    name: 'browse',
-    data: {
-      type: 'photos'
-    }
-  });
-  act.onerror = function(e) {
-    if (act.error.name === 'NO_PROVIDER') {
-      console.warn('Error: no activity provider');
-    }
-    else {
-      console.warn('Error: unknown activity - ' + act.error.name);
-    }
-  };
-

在這段程式碼中,「相機」新增了一個 MozActivity 物件並在參數物件中聲明該 activity 是「瀏覽(browse)」的動作,瀏覽的資料是「相片(photos)」。請注意它並非直接指定要切換到「圖片集」 ,而是由系統決定哪個 App 提供這樣的行為,若有多個 App 同時提供一樣的行為時,系統會產生一個選單讓使用者選取。
- 參數物件的 'data' 欄位可以提供額外所需的資料內容,讓承接 activity 任務的 App 決定是否根據資料內容做其他處理。
-
- 讓我們來看看提供 Web Activity 的 App 該如何聲明它的 activity 及相關設定。

-
"activities": {
-  "browse": {
-    "filters": {
-      "type": "photos"
-     },
-    "disposition": "window"
-  }
-}
-


- 像「圖片集」這樣的 App 可以在它的 manifest.webapp 檔案中聲明它提供瀏覽相片的 activity,如上所示。它提供一個「瀏覽(browse)」動作的 activity,瀏覽的資料是「相片(photos)」作為篩選條件。這樣的 activity 聲明宣告,便能與上面的 MozActivity 呼叫匹配,成為能承接這個 activity 的對象之一。若手機中只有這一個 App 有這樣的 activity 宣告,那系統預設就會將這個 App 開啓,但若有多個 App 都能夠執行這個任務,系統會產生一個選單讓使用者選取。

-

"disposition": "window"

-

依照不同 App 的需求,目前在 Firefox OS 中有兩種形式的 Web Activity ,一種為「視窗切換」(window disposition) 、一種為「畫面滑入」(inline disposition)。前者視覺上是 App 之間的切換,後者則是承接 activity 的 App 會由下方滑入,覆蓋在目前 App 之上。除了視覺上的效果不同之外,「畫面滑入」的 Web Activity 在 activity 處理結束畫面關閉之後(例如選擇了一張圖片),會回到原本的 App ,而「視窗切換」的 Web Activity 則需要使用者自己手動回到主畫面 (homescreen) 或者 App 列表,才能夠切換回原本的 App 。提供 Web Activity 的 App 可以自行決定提供哪種形式讓其他 App 呼叫。
-
- 除了在 manifest.webapp 宣告 Web Activity 之外,程式碼中當然也要有具體的實作。如下所示是「圖片集」 App 的實作程式碼:

-
  navigator.mozSetMessageHandler('activity', function activityHandler(a) {
-    var activityName = a.source.name;
-    if ( activityName === 'browse') {
-      // If this was a cold start, then the db needs to be initialized.
-      if (!photodb)
-        initDB(true);  // Initialize both the photo and video databases
-      // Always switch to the list of thumbnails.
-      setView(thumbnailListView);
-    }
-  });
-
-

當有 MozActivity 的呼叫發生時,會以系統訊息的方式通知將要被開啓的 App 。因此這個 App 必須要註冊 'activity' 的系統訊息,提供對應的回呼函示 (callback function),明白表示當 MozActivity 的呼叫發生時, App 被開啓後將如何處理這個 activity。這邊「圖片集」 App 執行初始化圖庫、以縮圖方式列出圖庫內的相片。
- 「圖片集」 App 在 manifest.webapp 的聲明中使用 window disposition 的方式處理 activity,表示使用者並不會在完成什麼動作之後回到「相機」 App 。「圖片集」 App 就如同是被使用者手動在主畫面(homescreen)點選開啟一般,由使用者自行決定何時離開。

-

"disposition": "inline"

-

我們來看另一種形式的  Web Activity。同樣以「圖片集」 App 為例,它可以提供一個  Web Activity 供其他 App 挑選照片。挑選照片的 actvity 必須要把被挑選到的相片名稱、路徑…等等的資訊傳回給呼叫方(caller),並且在挑選動作完成後回到呼叫方的 App 。這個情況下,使用 inline disposition 的形式來實作。
- manifest.webapp 的宣告是這樣的:

-
"activities": {
-  "pick": {
-    "filters": {
-      "type": ["image/jpeg", "image/png"]
-    },
-    "disposition": "inline",
-    "returnValue": true,
-    "href": "/index.html#pick"
-  }
-}
-


- 它提供一個「挑選(pick)」動作的 activity,挑選的資料形態以一個陣列作為篩選條件,提供挑選 "image/jpeg" 或 "image/png" 圖檔,並且會回傳挑選的值。
- 由於 inline disposition 的 Web Activity 是以單一畫面滑入的形式被開啓,不同於 window disposition 是整個 App 被開啓,這裡我們可以多指派一個聲明表示要處理這個  Web Activity 的頁面位置 ("href": "/index.html#pick")。
-
- 這個頁面會有具體的程式碼實作如下:

-
  navigator.mozSetMessageHandler('activity', function activityHandler(activityRequest) {
-    var activityName = activityRequest.source.name;
-    if (activityName === 'pick') {
-      var pickType = activityRequest.source.data.type;
-      var width = activityRequest.source.data.width;
-      var height = activityRequest.source.data.height;
-      var blob = startPick(pickType, width, height);
-      if (blob) {
-        activityRequest.postResult({type: pickType, blob: blob});
-      } else {
-        activityRequest.postError('pick cancelled');
-      }
-    }
-  });
-


- 當有 MozActivity 的呼叫發生時,「圖片集」 App 收到 'activity' 的系統訊息,回呼函示 (callback function)會被運行,它可以讀取請求此 activity 的 App 所提供的數據,例如所需的圖片類型、寬度、高度… 等,作為陳列圖片清單的參考。當使用者成功選取了一張圖片,呼叫 activityRequest.postResult 傳回挑選結果。這個結果是個物件,讓呼叫 MozActivity 的 App 能夠知道圖片相關的資訊。
-
- 在「設定」 App 中希望能讓使用者選取一張圖片做為桌布,只需要呼叫 activity 來完成。

-
  var activityRequest = new MozActivity({
-     name: 'pick',
-     data: {
-        type: 'image/jpeg',
-        width: 320,
-        height: 480
-      }
-  });
-  activityRequest.onsuccess = function onPickSuccess() {
-    if (!activityRequest.result.blob)
-      return;
-
-    var reader = new FileReader();
-    reader.readAsDataURL(activityRequest.result.blob);
-    reader.onload = function() {
-       navigator.mozSettings.createLock().set({
-          'wallpaper.image': reader.result
-       });
-       displayImgae(reader.result);
-    };
-  };
-  activityRequest.onerror = function onPickError() {
-     console.warn('pick failed!');
-  };
-
-

在這段程式碼中,「設定」呼叫了一個 MozActivity 並在參數物件中聲明該 activity 是「挑選(pick)」的動作,挑選的是「image/jpeg」檔案,限定寬度與高度為 320 x 480。同樣的,「設定」 App 不知道實際上哪個 App 會被呼叫,它只在意當挑選動作完成時,它的 onsuccess 回呼函示會被執行,取得 blob 內容,並且畫面焦點將回到它身上,讓它可以顯示選取的圖片。系統將決定哪個 App 提供這樣的行為,若有多個 App 同時提供一樣的行為時,系統會產生一個選單讓使用者選取。
-  

diff --git "a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\345\260\201\345\214\205\345\274\217_(packaged)_app/index.html" "b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\345\260\201\345\214\205\345\274\217_(packaged)_app/index.html" deleted file mode 100644 index 80a905ab88..0000000000 --- "a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\345\260\201\345\214\205\345\274\217_(packaged)_app/index.html" +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: 封包式 (Packaged) App -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/封包式_(Packaged)_App ---- -
-

原文出處:https://marketplace.firefox.com/developers/docs/packaged

-
-

封包式 (Packaged) App 屬於 Open Web App,即以 ZIP 壓縮檔納入其 HTML、CSS、JavaScript、app manifest 等所有資源;取代「將資源置於 Web 伺服器之上」的方式。封包式 App 的 ZIP 壓縮檔另將 app manifest 置於其根目錄之下,且此 manifest 檔案必須命名為 manifest.webapp。

-
-

注意:截至 2013 年 1 月為止,Firefox Marketplace 上所提供的封包式 App 限定為 Firefox OS App。

-
-

 

-

封包式 App 之用途

-

若 App 會存取裝置上的 Sensitive API,則最好能透過封包式 App 而達到安全性的需求。App 均必須經過上架商城 (如 Firefox OS Marketplace) 認證方可販售。這些商城將審核 App,確認其是否可行,再以其自有金鑰完成加密簽核。再審核過安全性、隱私性、功能性等的可能問題之後,可為 App 的使用者更多添一份保障。

-

 

-

封包式 App 的類型

-

封包式 App 可分為 3 類:

-

Privileged app

-

Privileged App 是由 Firefox OS Marketplace 以特殊程序核准之後發出。如果任一 App 要存取裝置上的特定 Sensitive API,則可為使用者提供更高的安全性。此種 App 即等同 iOS 或 Android 平台上的 Native App,並具備下列特性:

- -
"default-src *; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'"
- -

Certified app

-

Certified App 將用於重要的系統功能,如智慧型手機上預設的撥號鍵盤,或系統設定用 App;當然亦可用於 Firefox OS 手機上的重要功能。Certified App 並不會用於第三方 App,所以大多數的 App 開發人員可略過此類 App 不管。除了所有的裝置許可均為隱式許可 (Implicit permission,意即不需要外部的使用者許可) 之外,Certified App 與 Privileged App 大部分均屬於相似的封包式 App。而 Certified App 必須取得 OEM 裝置或電信服務供應商裝置的許可,才能讓此隱式 App 使用重要 API。下列即為 Certified App 的 CSP (與 Privileged App 的 CSP 略有不同):

-
"default-src *; script-src 'self'; object-src 'none'; style-src 'self'"
-

若與 Certified App 相較,Privileged App 則針對 inline CSP 的影響而稍微放寬了限制。進一步了解其原因,可參閱預設 CSPBug 768029

-

Plain packaged app

-

當然也可讓一般 App 封裝為 ZIP 壓縮檔。在 Marketplace 簽署之後,並不會執行如 Privileged/Certified App 所需的特殊授權程序。且 Plain Packaged App 並不會使用特定的 Sensitive Web API;同時也不屬於 Privileged/Certified App 所用 CSP 管轄所及。

-

 

-

與托管式 (Hosted) App 的差異

-

封包式 App 的功能,其實與一般網站型態的 Open Web App (即所謂托管式 Hosted App) 功能相同。但封包式 App 的差異在於:

- -
app://550e8400-e29b-41d4-a716-446655440000/index.html
- -

與一般的托管式 App 相同,封包式 App 仍可存取 Web 伺服器上的資料庫。

-

 

-

使用 Sensitive Web API

-

現在有許多惡意 Web API,因此應謹慎存取 Web API。針對 App 所要存取的所有 Sensitive API,你應該在 manifest 檔案permissions 欄位中新增輸入項。

-

一般托管式 App 亦可存取某些 Sensitive API,但其他 API 就限定封包式 (Privileged 或 Certified) App 才可存取。可參閱 App 許可找到相關需求的表格。

-

 

-

封包式 App Firefox Marketplace

-

與托管式 App 相較,Firefox Marketplace 處理封包式 App 的方式較為不同。一旦提交自己的封包式 App 之後,其 ZIP 壓縮檔即儲存於 Marketplace 的伺服器上,且 Marketplace 隨即根據該 ZIP 壓縮檔中的 manifest 檔案,產生新的 manifest 檔案並命名為「mini-manifest」。只要使用者想安裝此 App,就會將 mini-manifest 檔案傳送至 installPackage() 函式以安裝該 App。此 mini-manifest 檔案僅用於安裝與更新作業,與 App 的執行作業無關。

-

 

-

測試封包式 App 的安裝作業

-

透過 Firefox OS 模擬器 (Firefox OS Simulator),即可輕鬆安裝封包式 App。目前 Firefox OS 模擬器亦針對各個平台而提供 WindowsOSXLinux 等不同版本。

-

安裝模擬器時,將於 Firefox 的「網頁開發者 (Web Developer)」功能表中新增「Firefox OS Simulator」項目。在開啟附加元件之後,即可透過「Add Directory」而指定本端 webapp.manifest 檔案的位置。模擬器另可將該 App 封包 (即壓縮該資料夾),再透過剛封包完畢的 App 開啟模擬器。

-

針對 Linux 與 Windows 的使用者,還需要其他步驟才能設定 Android Debug Bridge (adb),以溝通實際裝置。請參閱步驟 3:設定系統以偵測自己的裝置

-

在實際裝置上,可點選 Settings > Device Information > More Information > Developer > Remote Debugging,進而啟動遠端除錯功能。

-

任何時間點均可連上受支援的裝置。一旦連上裝置,模擬器即可偵測並顯示所接上的裝置。而在 App 列表的旁邊,可看到「push」的新按鈕。按下「push」即可將剛封包完畢的 App 傳送至裝置上。

-

 

-

更新封包式 App

-

若要進一步了解更新作業,請參閱更新 App

-

 

diff --git "a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\346\211\230\347\256\241\346\233\264\346\226\260\344\275\234\346\245\255_(hosting_updates)_/index.html" "b/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\346\211\230\347\256\241\346\233\264\346\226\260\344\275\234\346\245\255_(hosting_updates)_/index.html" deleted file mode 100644 index ea5b41073b..0000000000 --- "a/files/zh-tw/archive/b2g_os/3rd_party_app_developer_guide/\346\211\230\347\256\241\346\233\264\346\226\260\344\275\234\346\245\255_(hosting_updates)_/index.html" +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 托管更新作業 (Hosting Updates) -slug: Archive/B2G_OS/3rd_Party_App_Developer_Guide/托管更新作業_(Hosting_Updates)_ ---- -
-

本文節錄自 B2G/Updating

-
-

托管更新作業 (Hosting Updates)

-

其實亦可解釋為:用戶端針對更新檔案所進行的輪詢作業。

-

B2G 用戶端針對更新所執行的輪詢 (Poll),即針對 update manifest 檔案進行提取 (Fetching) 與剖析 (Parsing)。此檔案即稱為「update.xml」。

-

B2G 用戶端均已完成「輪詢特定伺服器上的更新」的設定,亦將查詢伺服器上特別架構而成的路徑。而我們建議透過 HTTPS 協定 (當然 HTTP 亦支援),讓用戶端查詢伺服器。若現有用戶端更改了輪詢程式碼,則只要將一筆更新傳送至此用戶端,即可針對「用戶端所輪詢過的路徑與伺服器」進行變更。

-

在下列範例中,我們假設將更新作業托管 (Hosting) 給 updates.b2g.com 伺服器。

-

則由用戶端所輪詢的 URL,主要可用下列參數呈現:

- - - - - - - - - - - - - - - - - - - -
-

PRODUCT_MODEL

-
-

裝置型號的名稱。此為 B2G 屬性資料庫中的 ro.product.model 數值。

-
-

CHANNEL

-
-

更新「頻道」,有助於測試作業。舉例來說,我們可設定伺服器托管「nightly」、「beta」、「release」等頻道。

-
-

VERSION

-
-

此為用戶端的軟體版本,此以「18.0.2」為例。

-
-

BUILD_ID

-
-

專屬 ID,如針對特定軟體版本 (Build) 所設的時間戳記。

-
-

當然另有許多數值,可為查詢作業建構出更新用的 URL。

-

B2G 用戶端隨後將整合「本身已設定的更新主機」的數值,搭配上述的相關數值,進而建構出 URL,以於執行期間執行輪詢作業。

-

此 URL 範例可為:

-
https://updates.b2g.com/release/unagi1/18.0/20121203123456/update.xml
-
-

 

-

針對用戶端的請求,若伺服器回傳「404 Not Found」,即代表目前並無可用的更新;若回傳「200」與 manifest 檔案,則代表可能有更新。該 manifest 檔案將描述可用的新版本,亦即用戶端目前應該更新的版本。此 manifest 檔案範例為:

-
<?xml version="1.0"?>
-<updates>
-  <update type="major" appVersion="19.0" version="19.0" extensionVersion="19.0" buildID="20121210123456"
-          licenseURL="http://www.mozilla.com/test/sample-eula.html"
-          detailsURL="http://www.mozilla.com/test/sample-details.html">
-    <patch type="partial" URL="https://updates.b2g.com/release/unagi1/18.0/20121203123456/update.mar"
-           hashFunction="SHA512" hashValue="5111e033875752b7d9b32b4795152dea5ef954cb8a9d4a602dd19a923b464c43521287dcb5781faf3af76e6dc5e8a3dd9c13edea18c1f2c8f3bd89e17d103d6f"
-           size="41901319"/>
-  </update>
-</updates>
-
-

而 manifest 檔案中的欄位則描述了:

- -

當然,使用者或用戶端裝置可能會拒絕更新作業。

-

透過這些機制,伺服器將可托管更新封裝,以利舊版用戶端的更新作業。或可僅托管「線性更新歷史紀錄 (Linear update history)」,讓用戶端必須透過單一路徑完成升級。

-

針對「版本 (Build) 伺服器」和「更新主機」之間的互動細節,仍與作業環境息息相關。本文尚不足以詳細解說完畢。

-

 

diff --git a/files/zh-tw/archive/b2g_os/add-ons/index.html b/files/zh-tw/archive/b2g_os/add-ons/index.html deleted file mode 100644 index 13f42518cd..0000000000 --- a/files/zh-tw/archive/b2g_os/add-ons/index.html +++ /dev/null @@ -1,282 +0,0 @@ ---- -title: Firefox OS 附加元件 -slug: Archive/B2G_OS/Add-ons -translation_of: Archive/B2G_OS/Add-ons ---- -
-

重要: 僅 Firefox OS 2.5+ 支援附加元件功能。

-
- -

「附加元件」的概念在 Web 瀏覽器的世界中眾人皆知,而我們也將這個概念帶進 Firefox OS。Firefox OS 的附加元件可以僅僅作用於單一 App 上,也可以指定作用於多個、甚至所有 App 上。本文帶您一步步撰寫自己的 Firefox OS 附加元件,同時提供一些秘訣及其他應該了解的資訊。

- -
-

附註:本文僅重點概略翻譯。

-
- -
-

附註:Firefox OS 附加元件採用 WebExtensions 擴充模式。此模式大部份源自於 Chrome/Blink 擴充套件機制,讓附加元件在開發時能擁有許多互通性與功能上的優勢。詳情可見持續編寫中的 WebExtensions 文件集

-
- -

開發附加元件

- -

Firefox OS 附加元件其實也是個內含 JavaScript / CSS / 其他必備檔案的 App,但不是拿來獨立運作,而是在描述檔中增加特別的說明來定義要在哪些 App 中使用這個附加元件。When apps are launched on a Firefox OS device that has an add-on installed, the add-on is injected into any app that matches the pattern specifed in the filter.

- -

Firefox OS add-ons use the same syntax and structure for their code as the new school of Firefox add-ons developed using the WebExtensions API, which is itself based on the Chrome extensions model.

- -

簡單範例

- -

以下我們以一個簡單的例子說明 Firefox OS 附加元件的程式基礎。這個附加元件會在 system app 放上一塊看板,使用者可以點擊關閉。

- -

firefox os screenshot showing add-on banner

- -

這個附加元件很簡單,但用來作為入門倒是相當足夠了。你可以在 GitHub 上下載範例程式,而後用 WebIDE 裝到你的 Firefox OS 裝置上(參考 {{anch("Testing your add-on using WebIDE")}} 一節)。往後你也可以透過 Firefox Marketplace 來發表自己的附加元件。

- -

Be aware that Firefox OS add-ons can do a lot more than what we've got listed here. The WebExtensions documentation will have more information added as time goes on.

- -

解析 Firefox OS add-on

- -

In this section we'll walkthrough the contents of the sample add-on repo, explaining each piece of content. 目錄結構看起來像這樣:

- - - -

manifest.json

- -

你應該發現了:在這個範例附加元件目錄中,有兩種類似的描述檔。第一個「manifest.json」的結構類似 Chrome 擴充套件,與 CSS、JavaScript 及其他檔案一起放在 {{anch("extensions.zip")}} 當中。It can contain a large variety of instructions (see Chrome Manifest File Format), but for now we're just going to concentrate on a simple subset:

- -
{
-  "manifest_version": 1,
-  "name": "Add-on banner",
-  "description": "Firefox OS add-on example",
-  "version": "1.0",
-  "author": "Chris Mills",
-  "content_scripts": [{
-    "matches": ["app://system.gaiamobile.org/index.html"],
-    "css": ["css/style.css"],
-    "js": ["js/index.js"]
-  }],
-  "icons": {
-    "128": "/icons/128.png"
-  }
-}
- -

Most of these fields are pretty self-explanatory, but we'll cover the last few.

- -

首先以 content_scripts 指定要植入 app 的檔案 — 你可以看到這邊以 cssjs 兩欄分別指定 CSS 樣式檔及 JavaScript 程式檔。matches 欄位則是用以指定該把檔案放入哪些 app 裡,這個欄位的內容形式很多元(參考 Chrome Match Patterns),但我們先簡單指定為 app://system.gaiamobile.org/index.html,讓附加元件僅影響 system app。若想影響所有 app,可以將此欄位寫為 app://*/*

- -
-

Note: You can reference multiple scripts and stylesheets by simply including multiple items in the arrays, for example "css": ["css/style.css", "css/more.css"].

-
- -
-

Note: Firefox OS does not currently support the Chrome <all_urls> keyword.

-
- -

At the bottom of the manifest we've included the icons field; see the next section for more info on this.

- -

update.webapp

- -

update.webapp 則是 Firefox OS 式的描述檔,基本上就是跟打包 app 時用的描述檔格式相同。(參考 Self-publishing packaged apps。)

- -

Our update.webapp file looks like so:

- -
{
-  "name" : "Add-on banner",
-  "description": "Firefox OS add-on example",
-  "developer": { "name": "Chris Mills" },
-  "package_path": "extension.zip",
-  "icons": {
-    "128": "/icons/128.png"
-  }
-}
- -

Again, most of this is fairly self-explanatory.

- -

這邊最重要的欄位該是 package_path,用以指定內含附加元件程式的包裝檔位置。

- -

You'll notice that the icons field is included here, the same as it is in {{anch("manifest.json")}} — update.webapp is the only place you need to have the icons information at the moment, but we'd recommend you include it in both places for now, just in case things change. The icons field points to the add-on icon so it can be used inside the Gaia Settings app, and the Firefox Marketplace when it starts to host add-ons.

- -

指定圖示

- -

你必須在描述檔中至少指定一個圖示,否則描述檔無效。詳情可參考 Manifest 參考文件:圖示 一節。

- -

CSS

- -

There is nothing special about the CSS included in the example. The only thing to bear in mind is that you should make sure your add-on classnames and selectors do not conflict with any of the existing CSS in the app(s) it is applied to.

- -

For example, we wrapped our example banner in a {{htmlelement("div")}} with class fxos-banner. But you could even consider using some kind of unique code for your classname.

- -

JavaScript

- -

Again, the JavaScript file that powers the add-on doesn't have any special functionality inside it (see the JavaScript source on Github.) It is injected into the apps it is applied to along with any CSS specified in the {{anch("manifest.json")}} file.

- -
-

Note: Add-on code is injected every time an app is launched and the match specified in manifest.json pattern matches that app. It is also injected whenever add-ons are enabled. When an add-on is injected into an app because the app is launching, all add-on files are injected into the app before anything in the app is initialized, including the DOM. It is up to the add-on developer to handle the different launch cases cases (immediate injection vs. injection on launch); there is more info on this below.

-
- -

Other main things to note are covered below.

- -

The window object

- -

Add-ons only share a proxied version of the content window. As a result, anything that is written to the window object from an add-on is unavailable to the app code. However, anything on the window object that is set by app code is available to add-ons. Similarly, the DOM is accessible as usual.

- -

Injecting code at the correct time

- -

You must be careful to properly handle cases where an add-on is injected into an app after the app has been loaded. Such a scenario can occur when an app is already running and an add-on that targets it is enabled.

- -

in such a case, a window.onload handler won't work because the DOMContentLoaded event has already occured.

- -

There's no good solution to this problem right now. In the interim, we recommend to check whether or not the DOM has been loaded before setting a DOMContentLoaded callback. This pattern is used in the demo:

- -
// If injecting into an app that was already running at the time
-// the app was enabled, simply initialize it.
-if (document.documentElement) {
-  initialize();
-}
-
-// Otherwise, we need to wait for the DOM to be ready before
-// starting initialization since add-ons are usually (always?)
-// injected *before* `document.documentElement` is defined.
-else {
-  window.addEventListener('DOMContentLoaded', initialize);
-}
-
-function initialize() {
-  // ...
-}
- -

避免重複植入

- -

為避免附加元件的程式碼多次重複植入到同一 App 中,您必須檢查附加元件是否曾經植入過,例如這樣

- -

you should check whether your add-on is already present, like this:

- -
function initialize() {
-  if (document.querySelector('.fxos-banner')) {
-    // Already injected, abort.
-    return;
-  } else {
-    var body = document.querySelector('body');
-    var fxosBanner = document.createElement('div');
-    fxosBanner.classList.add('fxos-banner');
-    var bannerText = document.createElement('p');
-    var closeBtn = document.createElement('button');
-
-    fxosBanner.appendChild(bannerText);
-    fxosBanner.appendChild(closeBtn);
-    body.appendChild(fxosBanner);
-
-    closeBtn.textContent = 'X';
-    bannerText.textContent = 'Wow, you have an extension installed!';
-
-    closeBtn.onclick = function() {
-      fxosBanner.parentNode.removeChild(fxosBanner);
-    }
-  }
-}
- -

So here we are using if (document.querySelector('.fxos-banner')) to check whether the example banner already exists. If so, then we return out of the function. If not, then the querySelector() method returns null, and we run the code block that creates the banner.

- -

App management functions in add-ons

- -

All Apps and Mgmt functions work on add-ons just like they do on apps. Be aware however that the latter are only available to add-ons when they are injected into a certified app that has the webapps-manager permission specified in the manifest.

- -

In addition to these functions, an onenabledstatechange callback is exposed for add-ons being enabled and disabled. This event is fired for all add-ons, so you will have to check which add-on was enabled/disabled before performing initialization or cleanup.

- -
navigator.mozApps.mgmt.onenabledstatechange = function(event) {
-  var app = event.application;
-  if (app.manifestURL === 'https://origin.of.manifest/manifest.webapp') {
-    var wasEnabled = app.enabled;
-    // do something with this information
-  }
-};
- -

extension.zip

- -
-

Note: The extension.zip file has been left in the demo repo mainly for illustrative purposes, so it is clear how the system works. You actually don't need to include the zip in your directory, as WebIDE will generate it for you when you install the add-on. The Firefox Marketplace is likely to do the same when it starts to list add-ons.

-
- -

The extension.zip archive contains the code for the extension, and is referenced in the {{anch("update.webapp")}} package_path field — This is how Gecko finds the code to be installed. Archived inside you'll find:

- - - -

So the manifest.json file sits inside the archive, and serves to reference the files to be injected and specify which apps to affect.

- -

Testing your add-on using WebIDE

- -

Mozilla's WebIDE tool is available in Firefox desktop by default. To use it for installing add-ons on your phone, follow the steps listed below:

- -
    -
  1. Make sure you have Firefox 43 or above installed (this was Nightly at the time of writing), as add-ons are not supported in WebIDE below this version.
  2. -
  3. Open your browser and open the WebIDE tool (press the WebIDE button, or choose Tools > Web Developer > WebIDE from the menu.)
  4. -
  5. Make sure your phone has remote debugging enabled (Settings App > Developer > Set the "Debugging via USB " selection to "ADB and DevTools".)
  6. -
  7. Connect your phone to your computer via a USB cable. Make sure you don't have other phones connected at the same time.
  8. -
  9. In the WebIDE UI, press the Select Runtime option, and select your phone, which should be listed under USB Devices.
  10. -
  11. At this point, your phone should be showing an Allow USB debugging connection? prompt. Choose Allow.
  12. -
  13. Select the Open App option, then choose Open Packaged App...
  14. -
  15. In the resulting file chooser, navigate to the directory that contains your update.webapp manifest file, and press Open.
  16. -
  17. Providing there are no warnings or errors reported, you can install your add-on on the device using the "Play" button in the center (Install and Run.)
  18. -
  19. To see the add-on in action, enable it by choosing Settings app > Add-ons > Add-on example > toggle the checkbox at the top.
  20. -
- -

Add-on settings

- -

You can control the add-ons on your phone by going to Settings app > Add-ons; in here you'll find a list of your installed add-ons, and you can tap each entry to see more information about each add-on.

- -

firefox os screenshot showing a list of installed add-ons in the settings appinformation screen for an individual addon, with a list of apps this add-on affects, and controls to disable and delete the add-on

- -

Enabling/disabling and deleting add-ons

- -

By default, add-ons will be enabled after installation when they are installed form the Firefox Marketplace. When installed via WebIDE however they will be disabled by default.

- -

You can manually enable/disable add-ons via the checkbox at the top of each individual add-on's page (found under Settings app > Add-ons), or programmatically using the navigator.mozApps.mgmt.setEnabled() function (see this setEnabled() usage example on Github.)

- -

You can delete an add-on entirely by tapping the Delete button found on individual app pages.

- -

Apps affected by add-ons

- -

You'll also notice that in the page for each individual add-on there is a section that lists which apps are affected by that add-on. Currently this doesn't seem to work (it always lists This add-on does not affect any installed apps.) This should be fixed soon (see {{Bug(1196386)}} for progress.)

- -

權限

- -

附加元件的權限繼承自其所植入的 App,在描述檔中想多要一點權限是行不通的,也無法以此方式增加其植入對象的權限。

diff --git a/files/zh-tw/archive/b2g_os/api/fmradio/index.html b/files/zh-tw/archive/b2g_os/api/fmradio/index.html deleted file mode 100644 index ec662a0029..0000000000 --- a/files/zh-tw/archive/b2g_os/api/fmradio/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: WebFM -slug: Archive/B2G_OS/API/FMRadio -translation_of: Archive/B2G_OS/API/FMRadio ---- -

WebFM API 可存取裝置上的 FM 收音機功能。此介面可開啟/關閉 FM 收音機,亦可搜尋各個電台。

-

進入點 (Entry point)

-
if (navigator.mozFMRadio)
-  navigator.mozFMRadio.enable();
-
-

API

-
interface FM : EventTarget {
-   readonly attribute boolean enabled;
-   readonly attribute boolean antennaAvailable;
-   readonly attribute double frequency;
-   readonly attribute double frequencyUpperBound;
-   readonly attribute double frequencyLowerBound;
-   readonly attribute double channelWidth;
-
-   attribute Function onantennaavailablechange;
-   attribute Function onfrequencychange;
-   attribute Function onenabled;
-   attribute Function ondisabled;
-
-   DOMRequest enable(double frequency);
-   DOMRequest disable();
-   DOMRequest setFrequency(double frequency);
-   DOMRequest seekUp();
-   DOMRequest seekDown();
-   DOMRequest cancelSeek();
-}
-

屬性 (Attribute)

-
-
- enabled
-
- 表示目前是否開啟收音機
-
- antennaAvailable
-
- 表示是否已插上天線並可使用天線
-
- frequency
-
- 目前的收音機頻率
-
- frequencyUpperBound
-
- 以 seek 函式搜尋收音機電台的最高頻率
-
- frequencyLowerBound
-
- 以 seek 函式搜尋收音機電台的最低頻率
-
- channelWidth
-
- 頻率範圍內的頻寬,以「MHz」為單位。常用數值為 0.05、0.1 (預設)、0.2 其中之一。
-
- 指定了某一頻率之後,就會四捨五入到 channelWidth 所指定的最接近頻率。舉例來說,若 100 Mz 為有效頻率,且 channelWidth 為 0.2,則 100.2 與 99.8 將成為有效頻率。但若是 100.15 將四捨五入為 100.2。
-
-

函式 (Method)

-
-
- enable(frequency)
-
- 開啟收音機並轉為指定頻率。若沒有參數 (Argument) 就呼叫此函式,將隨即丟出錯誤。作業成功或錯誤均將回傳 DOMRequest。
-
- disable()
-
- 關閉收音機。若回傳成功的 DOMRequest,則代表已正確關閉收音機。
-
- setFrenquecy(frequency)
-
- 非同步變更收音機的頻率。此數值必須位於 frequencyLowerBoundfrequencyUpperBound 之間。若嘗試設定此範圍之外,將導致錯誤。
-
- 若回傳成功的 DOMRequest,則代表已正確變更頻率。
-
- seekUp()
-
- 要求收音機尋找新的頻率 (一般搜尋較目前頻率更高的頻率)。若成功搜尋到新的頻率,將隨即啟動 frequencychange 事件。若回傳成功的 DOMRequest,則代表已開始搜尋作業。一旦達到最高頻率,將回到較低頻率開始搜尋。
-
- seekDown()
-
- 與上方函式的功能相同,但將搜尋較目前頻率更低的頻率。一旦達到最低頻率,將回到較高頻率開始搜尋。
-
- cancelSeek()
-
- 取消目前的搜尋作業。若回傳成功的 DOMRequest,則代表已取消搜尋作業。
-
-

事件 (Event)

-
-
- enabled
-
- 開啟收音機時觸發此事件
-
- disabled
-
- 關閉收音機時觸發此事件
-
- antennaavailablechange
-
- 插上/拔除天線時觸發此事件
-
- frequencychange
-
- 只要變更收音機頻率,均將觸發此事件
-
-

另請參閱

-

Gaia radio app

diff --git a/files/zh-tw/archive/b2g_os/api/index.html b/files/zh-tw/archive/b2g_os/api/index.html deleted file mode 100644 index 706080ff54..0000000000 --- a/files/zh-tw/archive/b2g_os/api/index.html +++ /dev/null @@ -1,156 +0,0 @@ ---- -title: B2G OS APIs -slug: Archive/B2G_OS/API -tags: - - API - - B2G API - - NeedsTranslation - - TopicStub - - b2g os api's -translation_of: Archive/B2G_OS/API ---- -

List of B2G OS APIs 

- -

-A -B -C -D - - -F - - -H - - - - - - - - -M -N - - -P - - - - -S -T -U - - -W - - - - - - - -

diff --git a/files/zh-tw/archive/b2g_os/apps/index.html b/files/zh-tw/archive/b2g_os/apps/index.html deleted file mode 100644 index 7c848f3df1..0000000000 --- a/files/zh-tw/archive/b2g_os/apps/index.html +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: 製作 Firefox OS 的 apps -slug: Archive/B2G_OS/Apps -translation_of: Web/Apps/Fundamentals ---- -

Firefox OS 裝置的應用程式其實只是開啟網頁上的Web應用;它們完全由各種開放的Web技術所組成,如 JavaScript, HTML, 和 CSS。雖然我們寫給 apps 的主要文件幾乎涵蓋了您所需要知道的所有事情,這裡列了一些特別著重於開發及測試 Firefox OS的文件。

-
-
-

文件及入門教材

-
-
- 寫一個 Firefox OS 的 Web app
-
- 一份教您製作您的第一個 Firefox OS web 應用程式的入門指南。
-
- 撇步及技巧
-
- 一份我們開發者建議您的撇步及技巧集(像是對於問題的替代方案)。
-
-

全部文章...

-
-
-

尋求社群協助

-

您在 app 相關問題上需要幫助、且無法在文件中找到解法嗎?

-
    -
  • 在 layout 論壇中請教,, 其中涵蓋 CSS 和 HTML: {{ DiscussionList("dev-tech-css", "mozilla.dev.tech.layout") }} -
      -
    • 在 Mozilla IRC channel 裡面提出你的問題: #openwebapps
    • -
    -
  • -
-

請遵守網路禮節...

-

工具

- -

View All...

- - -
-
-

 

diff --git a/files/zh-tw/archive/b2g_os/apps/writing_a_web_app_for_b2g/index.html b/files/zh-tw/archive/b2g_os/apps/writing_a_web_app_for_b2g/index.html deleted file mode 100644 index 4e612e8a87..0000000000 --- a/files/zh-tw/archive/b2g_os/apps/writing_a_web_app_for_b2g/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: 寫一個 Firefox OS 的 Web app -slug: Archive/B2G_OS/Apps/Writing_a_web_app_for_B2G -translation_of: Web/Apps/Fundamentals/Quickstart ---- -

B2G apps 只是用 HTML、CSS、和 Javascript 寫的 Web apps。在網頁上發佈 Web apps 就跟發佈一般的網站一樣。為了讓網站可以像 Web app 一樣可以被安裝在行動裝置上,你只需要加上一個 manifest 以及掛上一個安裝按鈕,如以下說明。

-

建議您從下面的文章著手:

- -

當然,您也可以無拘無束地 沉浸在 Open Web Apps 的深處

-

安裝 Web app

-

在網頁上發佈 app 和 manifest 之後,接著要讓 Gecko 知道這個訊息。像是在安裝時,Gecko 查詢 manifest 並將必須的項目加入到 home 的畫面,等等。

-

安裝 app 需要呼叫 navigator.mozApps.install() API。這裡有個安裝按鈕的範例,當您將 app 置於自己管理的位置時,這個範例可以讓您將按鈕嵌入於您自己的網頁:

-
<script>
-var manifest_url = "http://my.webapp.com/manifest.json";
-</script>
-
-<button onclick="navigator.mozApps.install(manifest_url); return false;">
-  Install this awesome app on your homescreen!
-</button>
-
-

注意:這個安裝按鈕也可以被置於像是 Mozilla Marketplace 的 app market,然而一般而言,在您自己的主要頁面上面也放一個「安裝 web app」的按鈕是非常貼心的。

-

現在請用 B2G 瀏覽器 app 瀏覽您的網站,並且點選安裝按鈕吧。

diff --git a/files/zh-tw/archive/b2g_os/architecture/index.html b/files/zh-tw/archive/b2g_os/architecture/index.html deleted file mode 100644 index a0a649e4f9..0000000000 --- a/files/zh-tw/archive/b2g_os/architecture/index.html +++ /dev/null @@ -1,717 +0,0 @@ ---- -title: Firefox OS 架構 -slug: Archive/B2G_OS/Architecture -translation_of: Archive/B2G_OS/Architecture ---- -
-

本文件是 Firefox OS 平台架構的初步概要介紹,將會簡單地向您介紹 Firefox OS 的重要概念,並解釋元件間如何互動。

-
- -
-

注意:Firefox OS 仍算是開發中的產品。本文說明的架構仍非最後確定的架構,隨時可能修改。

-
- -

Firefox OS 術語

- -

在閱讀 Firefox OS 技術文件之前,建議先了解以下的詞彙:

- -
-
B2G
-
Boot to Gecko 的縮寫。
-
Boot to Gecko
-
Firefox OS 作業系統的工程代號。此代號常常用以代表 Firefox OS。因為在本專案還未定下正式名稱之前,此代號已經用了很長的一段時間,因此常常用以代表 Firefox OS。
-
Firefox OS
-
Firefox OS 即是將 Mozilla (及其 OEM 夥伴) 的品牌與服務,套用至 Boot to Gecko 的基礎之上開發而得的最終產品。
-
Gaia
-
Firefox OS 平台的使用者介面 (UI)。 在啟動 Firefox OS 之後,都是透過 Gaia 層產出螢幕上的任何東西。Gaia 建構出鎖定畫面、主畫面,以及大家預期智慧型手機所應提供的其他標準 App。Gaia 完全使用 HTML、CSS、JavaScript 實作而成。透過實作在 Gecko 層的開放 Web API,與其底層的作業系統溝通。第三方 App 均可安裝於 Gaia 層。
-
Gecko
-
Firefox OS App 的執行環境 (Runtime),也就是本層可支援所有的開放標準:HTML、CSS、JavaScript。本層另必須確保這些 API 可正確運作於 Gecko 支援的所有 OS。意即 Gecko 另包含了網路連線堆疊、圖形堆疊、配置引擎、JavaScript 虛擬機器、移植層。
-
Gonk
-
Gonk 是 Firefox OS 平台的底層作業系統,是由 Linux 核心 (以 Android Open Source Project 為架構),與使用者空間的硬體抽象層 (Hardware abstraction layer,HAL) 所組成。核心以及許多使用者空間的函式庫,均來自常見的開放源碼專案,如 Linux、libusb、bluez 等。HAL 的某些部分是與 AOSP 共享,如 GPS 或相機。你可將 Gonk 當成是簡單的 Linux 分支版本。Gonk 又是 Gecko 的移植目標;意即有一套 Gecko 可在 Gonk 上執行,就像是 Gecko 也有 Mac OS X、Windows、Android 等版本。因為 Firefox OS 可完整控制 Gonk,所以某些不能開放給其他 OS 用的介面,還是可開發給 Gecko 使用。舉例來說,Gecko 可直接存取 Gonk 的完整電話功能堆疊,並於 Gonk 上顯示緩衝區 (Frame buffer),但是其他 OS 不能進行類似的存取。
-
Jank
-
此一詞彙常見於行動 App 領域,指在 APP 中執行了緩慢或沒有效率的程式碼,進而阻礙了 UI 更新並發商系統延遲或無回應的情形。Gaia 開發者使用不同的最佳化方法,要儘力避免此狀況發生。
-
- -

整體架構示意圖

- -

下圖比較了專利平台與 Firefox OS 之間的架構。

- -

on the left is a native mobile architecture stack, on the right is the Firefox OS architecture. they are similarm except that the native stack is all proprietary device functionality, and the Firefox OS stack is all done with open source and web technologies.

- -

Firefox OS 即減去了 OS 與 App 層之間的原生 API 層。這種統合式的設計可減輕平台負擔並簡化安全機制,卻又不致犧牲效能,也不會影響智慧型手機的使用體驗。

- -
    -
  1. Gaia 作為裝置的核心 Web App 與 UI 層,並全以 HTML5、CSS、JavaScript 撰寫而成,並有許多 API 可供 UI 程式碼存取手機硬體與 Gecko 功能。
  2. -
  3. Gecko 即為 Firefox OS 的 Web 引擎與表現層 (Presentation layer),作為 Web 內容與底層裝置的之間介面,進而將硬體接上 HTML。Gecko 亦提供 HTML5 剖析 (Parsing) 與繪圖引擎,並透過程式設計的方式,以安全的 Web API 存取硬體功能、更新作業,以及其他核心服務。
  4. -
  5. Gonk 是 Firefox OS 堆疊中的核心層級元件,作為 Gecko 與底層硬體之間的介面。Gonk 可控制底層硬體,並將硬體功能告知 Gecko 中建構的 Web API。Gonk 可視為「黑盒子」,暗自進行所有複雜又零碎的背景作業,以於硬體層制定請求,進而控制行動裝置。
  6. -
  7. 行動裝置,就是執行 Firefox OS 的行動電話硬體。OEM 廠商則負責提供行動裝置。
  8. -
- -

特殊 Firefox OS 架構

- -

Firefox OS Architecture

- -

Firefox OS 開機流程

- -

本段將說明 Firefox OS 的開機流程,包含整個流程所牽涉的部份,以及相關部分在系統裡的位置。流程順序大致如下:最先從核心空間裡的開機載入器 (Bootloader) 開始,到原生程式碼中開始程序,進入 B2G 再到使用者空間的 Gecko,最後到 Gecko 裡的系統 App、視窗管理器、主畫面 App。而其他 App 也同樣依照上述程序執行。

- -

- -

開機程序

- -

在首次啟動 Firefox OS 裝置時,就會於主要的開機載入器 (bootloader) 中開始作業。自此,就如同一般作業系統程序,更高一階的開機相關載入器會載入執行,然後往上更高一階的載入器又會被接續執行,如此下去形成一串開機載入流程鏈,直到最後程序就會將執行權交到 Linux 核心。

- -

關於開機程序有幾點需要注意:

- - - -

Linux 核心

- -

Gonk 使用 Linux 核心的版本,與 Android 開放源碼專案 (Android Open Source Project,AOSP) 所衍生使用的版本非常相似,但是並未沿用幾項 AOSP 所進行的修改。除外,雖然 Lunix 基本上已經相當穩定,但仍有些製造商會自行修改。

- -

Linux 的啟動程序已經可在網路上找到相當詳盡的文件說明,所以在此不再贅述。

- -

Linux 核心會啟動一些基本的程序 (Process)。在執行 init.rc 中定義的程序後,會再執行 init.b2g.rc 以啟動基本核心程序,如 b2g (Firefox OS 基礎程序,內含 Gecko) 以及 rild (通話功能的相關程序,各晶片組多有不同),請見下方所述細節。和大部分的 Unix 作業系統一樣,最後會啟動使用者空間 (Userspace) 程序。

- -

在啟動 init 程序之後,Linux 核心就會處理由使用者空間傳來的系統呼叫,並中斷來自於硬體裝置的類似呼叫。許多硬體功能均透過 sysfs 揭露給使用者空間,以下便是 Gecko 讀取電池狀態的程式碼片段

- -
FILE *capacityFile = fopen("/sys/class/power_supply/battery/capacity", "r");
-double capacity = dom::battery::kDefaultLevel * 100;
-if (capacityFile) {
-  fscanf(capacityFile, "%lf", &capacity);
-  fclose(capacityFile);
-}
- -

更多有關 init 程序

- -

Gonk 中的 init 程序,將處理必要的檔案系統並產生系統服務,之後就如同程序管理一般繼續待命,並將編譯指令碼 (也就是 init*.rc 檔案);指令碼內的指令則說明在啟動不同服務時所應進行的作業。

- -

init 程序必須處理一個相當關鍵的作業,即啟動 b2g 程序;這也是 Firefox OS 的核心。

- -

以下為 init.rc 中用以啟動 b2g 的程式碼:

- -
service b2g /system/bin/b2g.sh
-    class main
-    onrestart restart media
- -
-

注意:Firefox OS 與 Android 的 init.rc 之間的差異,將各款裝置而有所不同。有時候只是附加 init.b2g.rc,但有時修改的幅度甚大。

-
- -

使用者空間 (Userspace) 的程序架構

- -

現在讓我們來看看高階一點的部分,到底Firefox OS的各個元件之間是如何運作互動的。下圖所描述的是Firefox OS的主要使用者空間程序。

- -

接著可進一步了解 Firefox OS 不同元件是如何運作互動。下圖呈現 Firefox OS 的主要使用者空間程序。

- -

Userspace diagram

- -

 

- -

 

- -

 

- -

 

- -

 

- -

 

- -

 

- -

 

- -

 

- -

 

- -
-

注意:由於 Firefox OS 尚處於開發階段,所以此示意圖可能隨時修改而非完全正確。

-
- -

b2g 程序是主要的系統程序,能以高權限存取大部分的硬體;b2g 可溝通數據機、畫出顯示緩衝區 (Framebuffer),並與 GPS 或相機等硬體溝通。在系統內部,b2g 則執行 Gecko 層 (即以 libxul.so 所實作)。另可參考 Gecko 以了解 Gecko 層的運作方式,以及 b2g 與 Gecko 層溝通的方法。

- -

b2g

- -

b2g 程序會生成許多低權限的內容程序 (Content process),並透過這些程序來載入 Web 的 App 與內容。這些程序會再透過訊息傳遞系統「IPDL」溝通 Gecko 伺服器。

- -

b2g 程序所執行的 libxul,即參照 b2g/app/b2g.js 取得預設偏好設定。透過偏好設定,程序將開啟上述的 HTML 檔案「b2g/chrome/content/shell.html」,即於 omni.ja 檔案中編譯而得。而 shell.html 則包含了 b2g/chrome/content/shell.js 檔案,將觸發 Gaia 的「system」這個 App。

- -

rild

- -

rild 為銜接數據機處理器的介面,也是用以建構無線介面層 (Radio Interface Layer,RIL) 的常駐程式 (Daemon)。往往是由硬體製造商所撰寫的專屬程式碼,以溝通自家的數據機硬體。rild 可讓用戶端程式碼連接 rild 本身綁定的 Unix-domain socket。可經由以下類似的 init 指令碼啟動之:

- -
service ril-daemon /system/bin/rild
-    socket rild stream 660 root radio
- -

rilproxy

- -

在 Firefox OS 中,rild 用戶端即屬於 rilproxy 程序,作為 rildb2g 之間不具功能的傳送代理dumb forwarding proxy。為何需要此代理伺服器,就必須從實作細節來說明了。但簡單來說,proxy 確實有其存在的必要。可到 GitHub 上找到 rilproxy 原始碼

- -

mediaserver

- -

mediaserver 程序用以控制音訊與視訊的播放作業。Gecko 透過 Android 的遠端程序呼叫 (Remote Procedure Call,RPC) 和其溝通。某些可由 Gecko 撥放的媒體檔案 (如 OGG Vorbis 音訊、OGG Theora 視訊、WebM 視訊等),均是由 Gecko 解碼後直接傳送給 mediaserver 程序。其他的媒體檔案則是交由 libstagefright 解碼。libstagefright 可存取特定編碼與硬體編碼器 (Hardware encoder)。

- -
-

注意:mediaserver 程序為 Firefox OS 的「暫時性」元件,主要是協助早期的開發作業。預計最快在 Firefox OS 2.0 階段就會移除。

-
- -

netd

- -

netd 程序可用來設定網路介面。

- -

wpa_supplicant

- -

wpa_supplicant 程序為標準 UNIX 樣式常駐程式,可處理 WiFi 存取點的連線作業。

- -

dbus-daemon

- -

dbus-daemon 用以建構 D-Bus 訊息匯流系統,可供 Firefox OS 進行藍牙通訊作業。

- -

Gecko

- -

如前所述,Gecko 即由 Web 標準 (HTMLCSSJavaScript) 建構而成,並用以打造 Firefox OS 上所顯示的一切,另可控制手機硬體。Web App 則透過安全且受控制的 Web API (同樣以 Gecko 所建構而得) 來將 HTML5 連上硬體。Web API 可透過程式設計的方式,存取底層行動裝置硬體 (如電池或振動) 的功能,或取得儲存的資料 (如行事曆或聯絡資訊)。Web 內容亦可透過content invokes the accessible Web APIs within HTML5.

- -

App 是由相關 HTML5 網頁內容所組成。如果要撰寫 Web App 並於 Firefox OS 行動裝置上執行,則開發者也只要組合、封包、發佈此網頁內容即可。而在執行期間,即交由瀏覽器轉譯、編譯、換至此網頁內容。可參閱應用程式中心 (App Center) 進一步了解。

- -
-

注意:如果要搜尋 Gecko 的 Codebase,則可前往 http://dxr.mozilla.org,功能比較炫、參照功能不錯,但 Repo 較有限。亦可使用傳統的 http://mxr.mozilla.org,內含較多的 Mozilla 專案。

-
- -

Gecko 架構圖

- -

- - - -

和 Firefox OS 相關的 Gecko 檔案

- -

b2g/

- -

b2g 資料夾主要包含 Firefox OS 相關功能。

- -
b2g/chrome/content
- -

內含於系統 App 上運行的 Javascript 檔。

- -
b2g/chrome/content/shell.html
- -

Gaia 的進入點。如前所述,shell.html 會拉進 shell.js 與 settings.js。用於系統 App 的 HTML。

- -
<script type="application/javascript;version=1.8" src="chrome://browser/content/settings.js"> </script>
-<script type="application/javascript;version=1.8" src="chrome://browser/content/shell.js"> </script>
- -

settings.js 裡面是系統預設的設定參數。

- -
b2g/chrome/content/shell.js
- -

shell.js 是載入 Gaia「system」App 的第一個指令碼。

- -

shell.js 將匯入所有必要的模組、註冊關鍵的監聽器、定義 sendCustomEvent 與 sendChromeEvent 以溝通 Gaia、提供 webapp 安裝輔助程式:indexedDB 配額、遠端除錯器、鍵盤助手、螢幕截圖工具。

- -

不過 shell.js 最重要的功能,則是啟動 Gaia 的「system」App,然後將整體系統相關的管理作業交給該「system」App。

- -
let systemAppFrame =
-  document.createElementNS('http://www.w3.org/1999/xhtml', 'html:iframe');
-    ...
-  container.appendChild(systemAppFrame);
- -
b2g/app/b2g.js
- -

此指令碼包含預先定義的設定,就像是瀏覽器的 about:config,以及 Gaia 的 pref.js。這些設定值另可透過「設定 (Settings)」App 變更,也可用 Gaia 建置指令碼中的 Gaia’s user.js 覆寫之。

- -

/dom/{API}

- -

新實作的 API (post-b2g) 會位於 dom/ 資料夾。舊 API 位於 dom/base,例如navigator.cpp

- -
/dom/apps
- -

將載入 .jsm。而 .js API 實作即如 webapp.js 安裝、getSelf 等。

- -
dom/apps/PermissionsTable.jsm
- -

所有的存取權限都定義在 PermissionsTable.jsm 之中。

- -

/dom/webidl

- -

WebIDL是用以定義 Web API 的語言,請參閱 WebIDL_bindings 了解所支援的屬性。

- -

/hal/gonk

- -

此目錄包含 gonk 銜接層 (Port layer) 的相關檔案。

- -

所產生的檔案

- -
module/libpref/src/init/all.js
- -

內有全部的設定檔。

- -
/system/b2g/ omni.ja and omni.js
- -

內有裝置內資源所適用的樣式。

- -

處理輸入事件

- -

Gecko 內絕大多數的行動,都是由使用者的行動所觸發,可用輸入事件為代表 (如按下按鈕、觸碰裝置的螢幕等)。這些事件必須透過 nsIAppShellGonk implementation (為 Gecko 介面之一,作為 Gecko App 的主要進入點),進入到Gecko。也就是說,輸入裝置驅動程式將呼叫 nsAppShell 物件 (代表 Gecko 子系統) 上的函式,來將事件發送到使用者介面。

- -

例如:

- -
void GeckoInputDispatcher::notifyKey(nsecs_t eventTime,
-                                     int32_t deviceId,
-                                     int32_t source,
-                                     uint32_t policyFlags,
-                                     int32_t action,
-                                     int32_t flags,
-                                     int32_t keyCode,
-                                     int32_t scanCode,
-                                     int32_t metaState,
-                                     nsecs_t downTime) {
-  UserInputData data;
-  data.timeMs = nanosecsToMillisecs(eventTime);
-  data.type = UserInputData::KEY_DATA;
-  data.action = action;
-  data.flags = flags;
-  data.metaState = metaState;
-  data.key.keyCode = keyCode;
-  data.key.scanCode = scanCode;
-  {
-    MutexAutoLock lock(mQueueLock);
-    mEventQueue.push(data);
-  }
-  gAppShell->NotifyNativeEvent();
-}
- -

這些事件來自於Linux標準input_event系統. Firefox OS在其上添加了一層簡單的抽象層,提供了一些像是事件過濾等不錯的功能。產生事件的程式碼在widget/gonk/libui/EventHub.cpp裡的EventHub::getEvents()方法。

- -

Gecko接收到事件後,這些事件會透過nsAppShell發送到DOM:

- -
static nsEventStatus sendKeyEventWithMsg(uint32_t keyCode,
-                                         uint32_t msg,
-                                         uint64_t timeMs,
-                                         uint32_t flags) {
-    nsKeyEvent event(true, msg, NULL);
-    event.keyCode = keyCode;
-    event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
-    event.time = timeMs;
-    event.flags |= flags;
-    return nsWindow::DispatchInputEvent(event);
-}
-
- -

之後,事件有可能被Gecko處理掉或是當作DOM事件發送到網頁應用程式做進一步處裡。

- -

影像繪圖

- -

在最底層,Gecko利用 OpenGL ES 2.0 向包有硬體影格緩衝區(frame buffers)的GL context物件繪圖,這是由Gonk所實作的nsWindow完成:

- -
gNativeWindow = new android::FramebufferNativeWindow();
-sGLContext = GLContextProvider::CreateForWindow(this);
- -

FramebufferNativeWindow類別(class)是直接從Android而來,請見FramebufferNativeWindow.cpp;使用了gralloc API存取繪圖驅動,好配對影格緩衝裝置的緩衝到記憶體之中。

- -

Gecko透過圖層(Layers)系統合成螢幕上的影像,大體而言如下:

- -
    -
  1. Gecko將不同部分的記憶體分頁(pages)畫入記憶體緩衝,有時後這些緩衝存在系統記憶體,有時候因為Gecko會直接畫入視訊記憶體(video memory),所以這些緩衝也可能會是配對在Gecko定址空間的材質(textures) ,以上的工作主要是由BasicThebesLayer::PaintThebes()方法完成。
  2. -
  3. Gecko利用OpenGL命令將這些材質合成起來,合成工作由ThebesLayerOGL::RenderTo()方法執行。
  4. -
- -

因為有關Gecko如何處理影像繪圖的作法已經超出本文範圍,所以本文不再做進一步討論了。

- -

硬體抽象層(Hardware Abstraction Layer, HAL)

- -

Gecko HAL是Gecko接口層之一,它使用高階層Gecko能取用的C++ API存取跨平台間的底層系統介面,這些API以每個平台為基礎實作在Gecko HAL之內。Gecko的Javacsript程式碼並不能看到這個HAL層。

- -

HAL如何運作

- -

讓我們先來看看Vibration API。這個Gecko HAL API被定義在hal/Hal.h,基本上你可以看到如下函式(為了說明需要,經過函式簽名(function signature)簡化):

- -
void Vibrate(const nsTArray<uint32> &pattern);
- -

Gecko呼叫這個函式來根據某個特定型態開啟震動(另外有一個對應的函式用來關閉震動)。Gonk對這個函式的實作在hal/gonk/GonkHal.cpp:

- -
void Vibrate(const nsTArray<uint32_t> &pattern) {
-  EnsureVibratorThreadInitialized();
-  sVibratorRunnable->Vibrate(pattern);
-}
-
- -

下面以VibratorRunnable::Run()實作的程式碼發送震動開啟請求到另一個執行緒,其中主要的迴圈部分如下:

- -
while (!mShuttingDown) {
-  if (mIndex < mPattern.Length()) {
-    uint32_t duration = mPattern[mIndex];
-    if (mIndex % 2 == 0) {
-      vibrator_on(duration);
-    }
-    mIndex++;
-    mMonitor.Wait(PR_MillisecondsToInterval(duration));
-  }
-  else {
-    mMonitor.Wait();
-  }
-}
-
- -

vibrator_on()便是打開震動馬達的Gonk HAL API,這個函式透過sysfs向內部核心驅動程式送出訊息,寫入值到核心物件之中。

- -

HAL API退回替代(Fallback)實作

- -

Gecko HAL API 跨平台支援。當為沒有震動馬達的平台(如桌上型電腦)建置Gecko,則另一個HAL退回替代API會被使用,這個替代API實作於hal/fallback/FallbackVibration.cpp:

- -
void Vibrate(const nsTArray<uint32_t> &pattern) {
-}
- -

沙箱(Sandbox)實作

- -

因為大多數的網頁內容都是在低權限的內容程序運行,所以我們無法確保這些程序有權限去,例如,打開震動馬達,除此之外,為了避免出現程序爭相啟動震動的狀況出現,採用中央控制的作法較為理想。在Gecko HAL,透過sandbox作法可以達到中央控制的目標;其實sandbox也就是一個由內容程序發出到Gecko"伺服器"的代理請求,這個代理請求式透過IPDL送出。

- -

以震動為例,這是由hal/sandbox/SandboxHal.cpp所實作的Vibrate()完成:

- -
void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id) {
-  AutoInfallibleTArray<uint32_t, 8> p(pattern);
-
-  WindowIdentifier newID(id);
-  newID.AppendProcessID();
-  Hal()->SendVibrate(p, newID.AsArray(), GetTabChildFrom(newID.GetWindow()));
-}
- -

這會發送一個 PHal 介面定義的訊息,亦即IPDL的hal/sandbox/PHal.ipdl內所描述的。其中呼叫的函式大致如下:

- -
Vibrate(uint32_t[] pattern);
- -

訊息的接收端是HalParent::RecvVibrate()函式,這個函式定義在hal/sandbox/SandboxHal.cpp裡面,大致如下:

- -
virtual bool RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
-            const InfallibleTArray<uint64_t> &id,
-            PBrowserParent *browserParent) MOZ_OVERRIDE {
-
-  hal::Vibrate(pattern, newID);
-  return true;
-}
- -

本段範例雖然有省略一些相關性不高的部分,不過確實的說明訊息傳遞是如何由Gecko到Gonk,再到Gonk HAL實作Vibrate(),最後到震動馬達驅動程式。

- -

DOM APIs

- -

DOM介面是網頁根本上和Gecko溝通的方法,如果想知道更多這方面的細節,請參考關於DOM。 DOM介面是用IDL定義的,其中包括了外部函式介面(foreign function interface, FFI)以及介於javascript和C++的物件模型(object model, OM) 。

- -

像是vibration API便是透過IDL讓網頁內容使用,這部分程式碼定義在nsIDOMNavigator.idl:

- -
[implicit_jscontext] void mozVibrate(in jsval aPattern);
- -

mozVibrate(冠有廠商前綴的函式,這個函式背後的震動規格尚未定案)接受jsval型態的參數,也就是Javascript的值。IDL編譯器xpidl,會產生C++的介面,這個介面會由Navigator.cpp內的Navigator類別實作之。

- -
NS_IMETHODIMP Navigator::MozVibrate(const jsval& aPattern, JSContext* cx) {
-  // ...
-  hal::Vibrate(pattern);
-  return NS_OK;
-}
- -

這個函式最關鍵的部分在於呼叫 hal::Vibreate() 將控制權由DOM移交給Gecko HAL,自此我們便會如前所述地進入HAL層,最後到達驅動程式。在上層的 DOM 並不在意現在是在哪個平台上執行(Gonk, WIndows, Mac OS X等等),DOM 也不在意現在是內容程序的程式碼在跑或是Gecko伺服器的在跑,所有的一切都交由底層系統處理。

- -

vibration API相對單純,適合用於說明,而SMS API 便是比較複雜的API,它用到自己的"遠端"層將內容程序和伺服器連接起來。

- -

無線介面層(Radio Interface Layer, RIL)

- -

The userspace process architecture段落已經提過RIL,這邊我們將更進一步檢視各個元件是如何互動運作。

- -

和RIL有關的元件有:

- -
-
rild
-
和特定數據機韌體溝通的背景程序(daemon)。
-
rilproxy
-
rild和Gecko b2g程序之間訊息傳遞的代理背景程序(daemon)。rilproxy的存在解決了無法和rild直接溝通的問題,因為rild只可以在radio群組內溝通。
-
b2g
-
實作Gecko的程序,又稱為chrome process。其中和RIL相關的部分有dom/system/gonk/ril_worker.js(這是一個worker執行緒,會透過rilproxy和rild溝通,並且實作了無線狀態機(radio state machine))以及nsIRadioInterfaceLayer介面(是主執行緒的XPCOM服務,主要是作為ril_worker.js和Gecko各元件,包括Gecko內容程序,之間的訊息傳遞)。
-
Gecko's content process
-
nsIRILContentHelper介面會提供XPCOM服務,有了這個服務,Gecko內容程序會使用到的DOM API,例如TelephonySMS API,便能夠和Chrome程序的無線介面溝通。
-
- -

範例: Example: Communicating from rild to the DOM

- -

讓我們來看看一段例子,看一下系統底層是如何和DOM程式碼溝通。當數據機接收到來電時,它會透過專屬機制通知rild,rild接著按照ril.h內定義的"open"協定發送訊息到rild客戶端,以來電通話為例,RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 訊息會被rild發送至rilporxy。

- -

實作在rilproxy.c的rilproxy會透過以下程式碼,和rild建立連線:

- -
ret = read(rilproxy_rw, data, 1024);
-
-if(ret > 0) {
-  writeToSocket(rild_rw, data, ret);
-}
- -

一旦從rild那裏取回訊息後,訊息便會經由連接rilproxy和Gecko的socket傳給Gecko,Gecko是藉由IPC thread接收訊息:

- -
int ret = read(fd, mIncoming->Data, 1024);
-// ... handle errors ...
-mIncoming->mSize = ret;
-sConsumer->MessageReceived(mIncoming.forget());
-
- -

訊息的接收端是SystemWorkerManager,然後訊息又會被重新打包發送到{source("dom/system/gonk/ril_worker.js", "ril_worker.js")}}執行緒,這個ril_worker.js實做了RIL狀態機(RIL state machine); 這其中的過程是透過 RILReceiver::MessageReceived()函式完成:

- -
virtual void MessageReceived(RilRawData *aMessage) {
-  nsRefPtr<DispatchRILEvent> dre(new DispatchRILEvent(aMessage));
-  mDispatcher->PostTask(dre);
-}
- -

訊息傳遞到ril_worker.js執行緒後,onRILMessage()函數接著會被呼叫。其中呼叫方法是利用Javascript API函式JS_CallFunctionName():

- -
return JS_CallFunctionName(aCx, obj, "onRILMessage", NS_ARRAY_LENGTH(argv),
-                           argv, argv);
- -

onRILMessage()定義在dom/system/gonk/ril_worker.js中;然後訊息會被切割成包裹,之後每一個包裹會被送給適當的處理函式:

- -
handleParcel: function handleParcel(request_type, length) {
-  let method = this[request_type];
-  if (typeof method == "function") {
-    if (DEBUG) debug("Handling parcel as " + method.name);
-    method.call(this, length);
-  }
-}
-
- -

ril_worker.js對每一個請求類型有實作一個同名的處理函式,所以程式碼能夠簡單地取得請求類型名稱,然後再比對是否有對應的函式存在,如果有便呼叫對應函式起來處理。

- -

RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED為例,下面的處理函式會被呼叫:

- -
RIL[UNSOLICITED_RESPONSE_CALL_STATE_CHANGED] = function UNSOLICITED_RESPONSE_CALL_STATE_CHANGED() {
-  this.getCurrentCalls();
-};
- -

當收到訊息通知後,通話狀態也跟著改變,所以狀態機接著呼叫getCurrentCall()取得目前通話狀態:

- -
getCurrentCalls: function getCurrentCalls() {
-  Buf.simpleRequest(REQUEST_GET_CURRENT_CALLS);
-}
- -

這樣會回傳一個請求給rild,要求目前所有進行中通話的狀態。這個請求會沿著RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED 訊息之前所行進過的路走,只不過方向相反(從 ril_worker.jsSystemWorkerManager 、到 Ril.cpp、再到rilproxy,最後是 rild socket)。 rild 然後會回應請求,再回到ril_worker.js的REQUEST_GET_CURRENT_CALLS訊息處理器,整個過程是雙向溝通。

- -

通話狀態然後會被處理,和之前的狀態比較,如果狀態有變更,ril_worker.js 會再通知在主執行緒上的nsIRadioInterfaceLayer服務:

- -
_handleChangedCallState: function _handleChangedCallState(changedCall) {
-  let message = {type: "callStateChange",
-                 call: changedCall};
-  this.sendDOMMessage(message);
-}
- -

nsIRadioInterfaceLayer實作在dom/system/gonk/RadioInterfaceLayer.js,而訊息是透過onmessage()收到:

- -
 onmessage: function onmessage(event) {
-   let message = event.data;
-   debug("Received message from worker: " + JSON.stringify(message));
-   switch (message.type) {
-     case "callStateChange":
-       // This one will handle its own notifications.
-       this.handleCallStateChange(message.call);
-       break;
-   ...
-
- -

之後訊息會透過父程序訊息管理器(Parent Process Message Manager, PPMM)送到內容程序:

- -
handleCallStateChange: function handleCallStateChange(call) {
-  [some internal state updating]
-  ppmm.sendAsyncMessage("RIL:CallStateChanged", call);
-}
- -

內容程序透過nsIRILContentHelper 服務的receiveMessage()從子程序訊息管理器(Child Process Message Manager, CPMM)那裡接受訊息:

- -
receiveMessage: function receiveMessage(msg) {
-  let request;
-  debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
-  switch (msg.name) {
-    case "RIL:CallStateChanged":
-      this._deliverTelephonyCallback("callStateChanged",
-                                     [msg.json.callIndex, msg.json.state,
-                                     msg.json.number, msg.json.isActive]);
-      break;
- -

接著,每一個電話callback物件的nsIRILTelephonyCallback.callStateChanged()方法會被呼叫;每一個有存取window.navigator.mozTelephony API的網頁應用程式會註冊這樣一個callback物件,這個callback物件會發送事件到網頁應用程式,如現階段通話物件狀態改變或有新通話來電事件。

- -
NS_IMETHODIMP Telephony::CallStateChanged(PRUint32 aCallIndex, PRUint16 aCallState,
-                                          const nsAString& aNumber, bool aIsActive) {
-  [...]
-
-  if (modifiedCall) {
-    // Change state.
-    modifiedCall->ChangeState(aCallState);
-
-    // See if this should replace our current active call.
-    if (aIsActive) {
-      mActiveCall = modifiedCall;
-    }
-
-    return NS_OK;
-  }
-
-  nsRefPtr<TelephonyCall> call =
-          TelephonyCall::Create(this, aNumber, aCallState, aCallIndex);
-  nsRefPtr<CallEvent> event = CallEvent::Create(call);
-  nsresult rv = event->Dispatch(ToIDOMEventTarget(), NS_LITERAL_STRING("incoming"));
-  NS_ENSURE_SUCCESS(rv, rv);
-  return NS_OK;
-}
- -

應用程式收到事件後可以跟著進行更新使用者介面等等:

- -
handleEvent: function fm_handleEvent(evt) {
-  switch (evt.call.state) {
-    case 'connected':
-      this.connected();
-      break;
-    case 'disconnected':
-      this.disconnected();
-      break;
-    default:
-      break;
-  }
-}
- -

更進一步的範例請見撥號應用程式的handleEvent()

- -

3G data

- -

有一個 RIL 訊息會向電信服務(cellular service)發起數據請求(data call),這會啟動數據機的數據傳輸狀態。數據請求會開啟 Linux 核心的Point-to-Point Protocol (PPP) 介面裝置,這個裝置能夠透過使用者介面設定。

- -

相關DOM APIs

- -

以下是和 RIL 溝通相關的DOM APIs:

- - - -

WiFi

- -

Firefox OS 的 WiFi 後端使用 wpa_supplicant 處裡大部份工作。所以說WiFi 後端的主要工作是管理請求者(supplicant),還有輔助一些任務,例如載入 WiFi 驅動程式和開關網路介面;從根本上來看,WiFi 後端就是一個狀態機(state machine),而其狀態會跟隨請求者狀態。

- -
-

Note: 許多 WiFi 有關的有趣東西都和 wpa_supplicant 程序可能的狀態變更息息相關。

-
- -

WiFi 元件的實作可以分成兩份檔案:

- -
-
dom/wifi/DOMWifiManager.js
-
實作網頁內容所看到的API;定義在 nsIWifi.idl.
-
dom/wifi/WifiWorker.js
-
實作狀態機和驅動請求者的程式碼。
-
- -

這兩份檔案利用訊息管理員(message manager) 溝通。 後端聆聽請求訊息,比如說"連接",然後回應訊息當請求行動完成後;DOM 端聆聽回應以及狀態改變和資訊更新的訊息。

- -
-

Note: 任何同步 DOM API 都會藉由快取資料來實作,同步訊息會盡量避免。

-
- -

WifiWorker.js

- -

這份檔案實作了 WiFi 介面背後的主要邏輯,由 SystemWorkerManager 喚起,然後運行在 chrome 程序裡(對多執行緒版本來說)。 WifiWorker.js 可以切成兩塊: 一個巨大無名函式與 WifiWorker;無名函式會產出 WifiManager,為本地提供 API,包含和請求者連線以及可取得的掃描結果等事件通知,它會回應請求的資訊,控管和請求者連線的細節,遵照 API 使用客戶的指示行動。

- -

WifiManager 和 DOM 中間是 WifiWorker 物件。WifiWorker 根據事件行動並且轉傳事件給 DOM,反過來,它也會收到 DOM 傳過來的請求,並且對請求者(supplicant)採取適當的動作,WifiWorker 也會維護請求者的狀態資訊和下不步行動的資訊。

- -

DOMWifiManager.js

- -

實作 DOM API,負責在呼叫方和 WiFi worker 之間傳遞訊息。

- -
-

Note: 為了避免和 chrome 程序之間同步訊息,WiFi Manager 需要根據收到的事件快取狀態。

-
- -

有一個同步訊息,那就是當 DOM API 初始化時為了取得請求者(supplicant)當下的狀態。

- -

DHCP

- -

DHCP 和 DNS 由標準 Linux DHCP 客戶端,dhcpcd,負責。當網路連線中斷後,因為無法運作,Firefox OS 會終止 dhcpcd,直到又重新連上網路,dhcpcd 會被再重啟。dhcpcd 也負責設定預設路徑(route)。

- -

Network Manager

- -

Network Manager 負責設定 3G 數據和 WiFi 元件的網路介面。

- -

程序與執行緒

- -

Firefox OS 採用 POSIX threads 實現所有應用程式的執行緒,這包括了應用成程式主執行緒、Web Worker 和輔助執行緒。Nice值決定了程序和執行緒的執行優先順序,然後再依賴 Linux 核心排程器先後執行;根據程序不同的狀態會有不同的Nice值。目前有7種Nice層級:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
程序執行優先順序
優先順序Nice用於
MASTER0主 b2g process
FOREGROUND_HIGH0持有 CPU wakelock 的程式
FOREGROUND1前景(foreground)程式
FOREGROUND_KEYBOARD1鍵盤程式
BACKGROUND_PERCEIVABLE7音樂播放背景(background)程式
BACKGROUND_HOMESCREEN18主畫面程式
BACKGROUND18其他背景程式
- -

有些層級的 Nice 值雖然一樣,不過記憶體不足時的終止行為不一樣。所有的優先順序可以在建置時調整,相關的程式碼請見b2g/app/b2g.js

- -

一個程序(process)之內,主執行緒繼承了該程序的 Nice 值,而 Web Worker 執行緒所得到的 Nice 值為主執行緒的加一點,所以優先權較低,這麼做是為了避免耗費 CPU 資源的worker 拖慢的主執行續的運作。程序優先順趣會因為事件發生而變化,比如說當一個程式由前景轉到背景時、一個新的程式啟動、現存程式取得 CPU wakelock,一旦程序的執行優先權變動,旗下所屬的執行緒的執行優先權也會跟著變動。

- -
-

Note: cgroups 目前沒有在資源管理用上,因為在某些裝置和核心上並不可靠。

-
- -

 

diff --git a/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/gaia_ui_tests_run_tests/index.html b/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/gaia_ui_tests_run_tests/index.html deleted file mode 100644 index 3924fbf5a6..0000000000 --- a/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/gaia_ui_tests_run_tests/index.html +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: Gaia UI Tests Run Tests -slug: Archive/B2G_OS/Automated_testing/gaia-ui-tests/Gaia_UI_Tests_Run_Tests -translation_of: Archive/B2G_OS/Automated_testing/gaia-ui-tests/Gaia_UI_Tests_Run_Tests ---- -
-

這個頁面尚未完成。請有志一同的夥伴幫忙補充。
- 有任何意見都可以寄到 gaia-ui-automation@mozilla.org。

-
-

Running Tests

-

    Basically, we can run gaia-ui-tests on a device with marionette server, emulators, and desktop B2G. However, please notice again that you should choose the right branch of gaia-ui-tests describing your B2G the best as we talked on previous section.

-

Testing on Devices

-

    First of all, connect your device through USB to computer, and then forward the package from the phone to computer port:

-
adb forward tcp:2828 tcp:2828
-
-

    You might get weird error, such as "no permission", from the command above. In that case, you could try to do the commands below:

-
adb kill-server
-sudo adb devices
-adb forward tcp:2828 tcp:2828
-
-

    It's almost all done before you start to run your tests! Before you start to run the test, read through this warning in order to start gaia-ui-tests correctly.
-     Now, you can send this command to execute all gaiatests:

-
gaiatest <gaia_ui_tests folder>/tests/ --address=localhost:2828 --type=b2g-xfail <your manifest file location>
-
-

    Or, if you want to run solely one file, just do:

-
gaiatest <file> --address=localhost:2828 --type=b2g-xfail <your manifest file location>
-
-

    After the test, you will see all the result on pass/fail. And, for each individual test, it might have more information that you can go through. Here are some common examples you might be able to see:

- - - - - - - - - - - - - - - - - - - - - - - -
Error Message Corresponding Actions
error: [Errno 111] Connection refusedreissue adb forward command
Element ... not visible before timeoutmake sure the element would display on the app you test
TimeoutException: Condition timed outmake sure the condition on the app is the same as your expectations
broken pipmostly bad marionette server issue
-

 

-

Testing on Emulator

-

Automatically launched emulator

-
-

TODO

-
-

Mannually launched emulator

-
-

TODO

-
-

Testing on Desktop B2G

-

    After you downloaded the Gaia UI test from GitHub, you also can use desktop build to run the tests. The Firefox OS desktop client, also called the B2G desktop client,  lets you run Gaia and Web apps in a Gecko-based environment somewhat  similar to an actual device. It doesn't emulate device hardware, so it's  not adequate for testing device APIs, and isn't a replacement for  testing on actual hardware. However, it does have a several APIs enabled  that aren't available on Firefox such as the Contacts and Settings  APIs. It can therefore be useful during the development of your  application, or while working on the Gaia user interface itself.

-

    You can download the latest build of the desktop client from this location, but make sure you download the appropriate file for your operating system.

- -
-

Note 1: Unfortunately, due to Bug 832469 the nightly desktop builds do not currently work on Windows, so you will need either Mac or Linux to continue :

-

Note 2: If you do not have the required operating systems installed on your machine, a virtual machine is fine as well.

-
-

    Once downloaded, you will need to extract the contents to a local folder. For the purposes of the rest of this guide, I’ll refer to this location as $B2G_HOME.
- Add the following line to your gaia/profile/user.js file,

-
user_pref('marionette.force-local', true)
-

which on :

- -

    Because we’re running against the desktop client we must filter out all tests that are unsuitable. To run the tests, use the following command:

-
gaiatest --address=localhost:2828 --type=b2g-antenna-bluetooth-carrier-camera-sdcard-wifi-xfail <your manifest file location>
-
-

Test Variables

-

    There is one warning previously mentioned here. Please do read the warning before you setup your json test variables file.

-

    We use the --testvars option to pass in local variables, particularly those that cannot be checked into the repository. For example in gaia-ui-tests these variables can be your private login credentials, phone number or details of your WiFi connection.

-

    To use it, copy testvars_template.json to a different filename but add it into .gitignore so you don't check it into your repository.

-

    When running your tests add the argument: --testvars=(filename).json

-

Variables

-

this_phone_number (string) The phone number of the SIM card in your device. Prefix the number with '+' and your international dialing code.

-

remote_phone_number (string) A phone number that your device can call during the tests (try not to be a nuisance!). Prefix the number with '+' and your international dialing code.

-

wifi.ssid (string) This is the SSID/name of your WiFi connection. Currently this supports WPA/WEP/etc. You can add WiFi networks by doing the following (remember to replace "KeyManagement" and "wep" with the value your network supports) :

-

"wifi": { "ssid": "MyNetwork", "keyManagement": "WEP", "wep": "MyPassword" }

-

WPA-PSK: "wifi": { "ssid": "MyNetwork", "keyManagement": "WPA-PSK", "psk": "MyPassword" }

-

Marketplace: "marketplace": { "username": "MyUsername", "password": "MyPassword" }

-
-

Due to Bug 775499, WiFi connections via WPA-EAP are not capable at this time.

-
-

 

-

Test Parameters

-

    As you see in the last command we gave out on previous sections, there are many test variables for you to know. You can do this to get more information:

-
gaiatest --help
-

 

-

Test Data Prerequisites

-

Occasionally a test will need data on the hardware that cannot be set during the test setUp. The following tests need data set up before they can be run successfully:

-

test_ftu Requires a single record/contact saved onto the SIM card to test the SIM contact import

-

 

-

Go to "Writing Tests" section

-

 

diff --git a/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/index.html b/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/index.html deleted file mode 100644 index 2c11cea761..0000000000 --- a/files/zh-tw/archive/b2g_os/automated_testing/gaia-ui-tests/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: Gaia UI Tests Guidelines -slug: Archive/B2G_OS/Automated_testing/gaia-ui-tests -translation_of: Archive/B2G_OS/Automated_testing/gaia-ui-tests ---- -
-

Gaia-ui-tests 是 Mozilla 的一套用於自動測試 Gaia UI 的架構。所有的測試都是以 Python 撰寫,佐以少數的 Javascript 來與 Firefox OS 的 API 溝通。此一系列的教學文章將會描述如何設定環境、撰寫及執行測試。

-
-

Gaia-ui-tests uses Gaiatest, a Python package based around Marionette. Gaiatest is designed to wrap HTML locators, Marionette calls and API calls together for interoperble communication and functionality. Marionette is based on the W3C standard developed for the Selenium WebDriver a programming interface for browser automation. If you have used WebDriver and page/app objects before then you will find using Marionette and gaiatest easy.

-

Getting started with Gaia UI tests

-

For those keen to get started with automated testing on Gaia/Firefox OS we have a tutorial series that will help you go from nothing to writing your own tests. Once you've completed this tutorial you'll have enough knowledge of testing, Firefox OS and Marionette to get started as a Mozilla tests contributor. It is highly recommended that you complete this tutorial if you wish to become a contributor.

-
-
- Part 1: Getting started with Marionette and Firefox OS
-
- This article covers installing the tools you need to get started with running tests, such as B2G Desktop, Python and Marionette.
-
- Part 2: Basic interactions with Firefox OS using Marionette
-
- An overview of the basic commands you will use to manipulate Firefox OS via Marionette.
-
- Part 3: Upgrading our code into a reusable test
-
- Moving on, in this article we will assemble some basic commands into a simple test inside a Python file so they can all be run as a single entity.
-
- Part 4: Re-using commands to set up Firefox OS
-
- Here we look at moving some of the commands into Python methods to promote code reuse.
-
- Part 5: Introducing a test runner
-
- A test runner is a central feature of any good test suite, allowing you to run multiple tests and report and aggregate results. In this article we will explore the basics of Python's unittest runner.
-
- Part 6: Using tuples, and Marionette's By class
-
- This time around we explain how to further reduce duplication of code, by storing repeated locators in tuples and simplifying the syntax with Marionette's By class.
-
- Part 7: Writing your own tests
-
- Now the basics and behind you, and it is time to start to writing your own tests! Here we give you some tool recommendations to make the work easier, and suggest some tests to try your hand at writing.
-
- Part 8: Using a base class
-
- In its current state, our test file contains all the test runner code. This is ok for now, but as soon as you start to run many test files it will mean a lot of duplication. Here we solve this problem by abstracting the test runner code into a separate Python class.
-
- Part 9: Reducing duplication with app objects
-
- As a final improvement to the code's maintainability, in this article we explore abstracting code that handles interaction with specific Firefox OS apps out into Python app objects.
-
-

Advanced topics

-

One you've got the basics of writing and running tests under your belt, you way want to move on to some more involved or advanced work, such as running the full gaia-ui-tests tests suite, or logging power draw as the result of a test.

-
-
- Running the gaia-ui-tests
-
- Guides to running the gaia-ui-tests suite against real Firefox OS devices and B2G Desktop in a variety of configurations.
-
- Gathering Power Draw
-
- How to use gaiatest to log power draw while a test is running.
-
-

See also

-

Gaia-ui-tests main repository

-

Questions/Comments/Concerns

-

This project is at a fairly early stage, and your feedback would be greatly appreciated:

- diff --git a/files/zh-tw/archive/b2g_os/automated_testing/index.html b/files/zh-tw/archive/b2g_os/automated_testing/index.html deleted file mode 100644 index 66f4eb520d..0000000000 --- a/files/zh-tw/archive/b2g_os/automated_testing/index.html +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: 測試 Boot to Gecko -slug: Archive/B2G_OS/Automated_testing -translation_of: Archive/B2G_OS/Automated_testing ---- -

因為 Boot to Gecko 還在開發中,不久的將來即將有對新硬體的支援,因此如何做測試就是很重要的事情。這個頁面提供了從多種方面測試 Boot to Gecko 的文章及資訊。

- - - - - - - -
-

Unit testing

- -
-
-

Miscellaneous testing topics

-
-
- Debugging OpenGL
-
- How to debug OpenGL code on Boot to Gecko.
-
- Feature support chart
-
- A chart of what features are supported by the different builds of Boot to Gecko.
-
-

Marionette for Boot to Gecko

- -

Gaia Unit Tests

- -

Marionette Tutorials

- -

Writing Tests For Marionette

- -

View All...

-
-

Getting help from the community

-

If you're working with Boot to Gecko, or developing applications you'd like to run on Boot to Gecko based devices, there are community resources to help you!

- -
    -
  • Ask your question on the Mozilla IRC channel: #b2g
  • -
-

Don't forget about the netiquette...

-
- - -
-

 

diff --git a/files/zh-tw/archive/b2g_os/building/index.html b/files/zh-tw/archive/b2g_os/building/index.html deleted file mode 100644 index 9e5c54202c..0000000000 --- a/files/zh-tw/archive/b2g_os/building/index.html +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: 建置 Boot to Gecko -slug: Archive/B2G_OS/Building -translation_of: Archive/B2G_OS/Building ---- -
-
-

當您已經建立好編譯的系統、第一次成功地抓了程式碼以及設定好程式碼,您就可以編譯 Boot to Gecko。

-

更新程式碼

-

如果您不是第一次編譯B2G,您需要在編譯之前先抓取最新的程式碼。您可以執行以下指令來更新B2G工具及相依套件:

-
git pull
-./repo sync
-
-

您可以藉由指定名稱來更新某部分的倉儲:

-
./repo sync gaia
-
-

repo指令也有其他您可能會有興趣的選項可用;您可執行 repo help 指令來獲取有用的資訊。

-

編譯

-
-

注意:在編譯前,您可以設置一個 .userconfig 檔案來訂製這次編譯。使用 .userconfig 檔案來客製 有更多詳細資訊。

-
-

執行 build.sh 就可以開始編譯 Boot to Gecko:

-
cd B2G
-./build.sh
-
-

是時候該再喝杯咖啡,或小睡一下了(尤其是第一次編譯)。

-

專程編譯某些模組

-

如果您只想要編譯某個模組,例如 Gecko,您可以指定名稱:

-
./build.sh gecko
-
-

您也可以用這個指令來取得您編譯的模組的列表:

-
./build.sh modules
-
-

設定要使用的處理器數目

-

B2G 的編譯 scripts 預設使用系統的 cores 數量加二作為平行工作的數量。您可以再執行 build.sh 的時候指定 -j 參數來改變這個預設值。如果您想要把編譯工作丟到背景、並且減輕 CPU 負載來做其他事情的話,這對您就很方便。當您面臨到編譯問題時,如果您一次就只執行一個編譯工作的話、設定處理器數目也可以讓您更容易讀取編譯的錯誤輸出,真的很方便。

-

舉例來說,設定同時只會有兩個工作來編譯:

-
./build.sh -j2
-
-

對於此對常見的使用案例就是防止不要平行編譯。這會讓編譯的輸出更加容易閱讀,更容易釐清編譯的問題。執行下面指令:

-
./build.sh -j1
-
-

多語系編譯

-

建立多語系的編譯版本:

-

Gaia

-
    -
  1. 決定要用哪個 Gaia 語系檔。這邊我們用 locales/languages_dev.jsonlocales/languages_all.json 當做我們 Gaia 的語系檔。
  2. -
  3. Clone the appropriate locales
  4. -
  5. http://hg.mozilla.org/gaia-l10n 複製適當的語系到目錄下;這裡我們放於 gaia-l10n/ 下。接著您會需要將列於語系檔之內的美個語系的倉儲(repo)都複製下來。
  6. -
  7. 您需要將上面步驟二目錄的絕對路徑設定在 LOCALE_BASEDIR 環境變數中。也要把步驟一中檔案的絕對路徑設定在 LOCALES_FILE 環境變數中。
  8. -
-

如例:

-
export LOCALE_BASEDIR=$PWD/gaia-l10n
-export LOCALES_FILE=$PWD/gecko/gaia/shared/resources/languages-dev.json
-
-

Gecko

-
    -
  1. 決定要用哪個 Gecko 語系檔。這邊我們用 b2g/locales/all-locales 當做我們的 Gecko 語系檔。
  2. -
  3. 複製適當的語系到目錄下;像是 gecko-l10n/ 。 - -
  4. -
  5. 複製 compare-locales.
  6. -
  7. -

    將步驟二目錄的絕對路徑設定在 L10NBASEDIR 環境變數中。將步驟一中的語系以空白分隔方式設定在 MOZ_CHROME_MULTILOCALE 環境變數中。

    -
  8. -
  9. -

    compare-locales/scripts 目錄加入到 PATH 變數、 compare-locales/lib 加入到 PYTHONPATH 變數中.

    - 如例: -
    export L10NBASEDIR=$PWD/gecko-l10n
    -export MOZ_CHROME_MULTILOCALE="ja zh-TW"
    -export PATH="$PATH:$PWD/compare-locales/scripts"
    -export PYTHONPATH="$PWD/compare-locales/lib"
    -
    -

    當您完成這些設定之後,就可以執行 build.sh 了。

    -

    看起來您也可以用 .userconfig 來做這些事情。

    -

    當我們整理好之後,可能會修改這些指令。

    -
  10. -
-

已知的錯誤

- -

當您的 gcc 版本太新的時候會出現這個錯誤。請安裝 gcc/g++/g++-multilib 4.6.x 版本.

-

設置您的編譯環境 有更多資訊。

-
-

社群上的提醒: 用 4.7.x 加上修改一些 B2G 程式碼可能可以 (gcc 會告訴你要改哪些地方) 但是這邊就沒人能幫你了!但是不改就不會碰到這些問題。

-
- -

如果看到這個訊息,通常是代表記憶體不夠。在執行 ./build.sh 之前請確認有足夠的記憶體,如果您的系統記憶體有4G的話,應該可以跑的很順利。

- -

有時候(尤其是在作業系統或是編譯工具更新後)您在編譯系統執行編譯後測試時,會碰到一些靈異現象就像下面這樣:

-
Generating permissions.sqlite...
-test -d profile || mkdir -p profile
-run-js-command  permissions
-WARNING: permission unknown:offline-app
-WARNING: permission unknown:indexedDB-unlimited
-build/permissions.js:122: NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIPermissionManager.add]
-make[1]: *** [permissions] Error 3
-make: *** [gaia/profile.tar.gz] Error 2
-

這種情況下試著刪除 gaia/xulrunner-sdk 目錄然後再重新抓程式碼:

-
rm -r gaia/xulrunner-sdk
-
-

這樣會刪掉由編譯系統自動抓取、預先編譯的 XULRunner;在下一次編譯的時候,XULRunner 會再被自動抓取一份。

-

接著的步驟

-

在編譯後,下個步驟就取決於您編譯的 Boot to Gecko 是給模擬器還是給實體手機;細節請參考下列文章:

- diff --git a/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_process_summary/index.html b/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_process_summary/index.html deleted file mode 100644 index 0dc0cd18b7..0000000000 --- a/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_process_summary/index.html +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: Firefox OS 建置程序摘要 -slug: >- - Archive/B2G_OS/Building_and_installing_Firefox_OS/Firefox_OS_build_process_summary -translation_of: Archive/B2G_OS/Building_and_installing_B2G_OS/B2G_OS_build_process_summary ---- -
-

建置和安裝Firefox OS需要大量的時間,網路頻寬和電腦計算能力。不幸的是,一路上事情很容易出問題,所以此頁面列出了建置的目標和步驟,希望可以在用戶建置的過程中幫上忙至於每一步驟的細節,會在其他文件討論

-
-
-

注:Firefox OS建置過程會提及到“B2G”或“Boot2Gecko”。“Boot2Gecko”是Firefox OS專案的原始代號名稱。

-
-

建置目標:4個“映像”檔

-

建置的目標是建立4個可以被複製到Firefox OS設備的映像檔。

- - - - - - - - - - - - - - - - - - - -
boot.imgLinux核心和根檔案系統映像檔(root filesystem image),後者提供一套可用的基本Unix工具。
system.imgFirefox的操作系統核心,包括部分Gonk,Gecko的接口,可執行b2g檔。
userdata.img -

使用者的Gecko profile以及Gaia網頁應用程式。

-
recovery.imgLinux核心和根檔案系統映像檔,另外還有簡單的工具,好讓使用戶能夠從問題中修復
-

一旦四個映像檔產生好後,它們可以被轉移到一個裝置。

-

Firefox OS是建立在Android開源專案上(Android Open Source Project, AOSP)。AOSP的ADBfastboot工具提供了十分好用的方法來存取和操作設備。值得一提的是adb reboot-bootloader命令可以讓已經連接上的裝置重開機,並且暫停至bootloader早期階段,在這個早期階段中可以下fastboot flash $partition $image命令,把映像檔複製到裝置之上

-

開機映像檔(The Boot image)

-

boot.img(開機映像檔)包含Linux核心和初始根磁碟分區,boot.img提供核心軟體工具和初始化腳本。為了效率考量,初始根磁碟分區會被複製到記憶體之中,因此被稱為“ramdisk”。boot.img將被複製到設備上的“啟動”(boot)分區,而在裝置的檔案系統運作時,ramdisk的內容是可以在根目錄底下看見,比如說下adb shell指令

-

boot.img還在根目錄下的default.prop建立了root用戶的權限

-

另外也可以通過檔案檢查,分割檔案到核心和ramdisk映像檔,修改從ramdisk映像抓出來的內容,並重新組裝ramdisk映像檔,然後重新建置boot.img,這樣來修改現存的開機映像檔 。例如請參考Alcatel One Touch Fire Hacking (Mini)指南。

-

可以在安裝開機映像檔前測試開機映像檔。首先讓裝置開機後暫停於bootloader,然後下fastboot boot /some/path/to/boot.img命令來開機進入尚未安裝的boot.img。

-

系統映像

-

系統映像檔(system.img)是Firefox OS的核心:

- -
-

關於平台架構的更多資訊,請見Firefox OS平台指南。

-
-

system.img會被複製到system分區,而在檔案系統運作時會在/system/目錄底下。

-
-

:system.img提供了許多裝置會用到的二進位大型物件(BLOB),特別是RIL(Radio Interface Layer)的blob控制了設備上的蜂巢式行動網路(cellular radio network)。

-
-

用戶資料映像檔

-

用戶資料應像檔(userdata.img)提供了運行中載入的各種Gaia應用程式。

-

userdata.img會被複製到裝置的userdata分區,然後檔案系統運作時會在/data/目錄底下。值得一提的是/data/b2g/目錄含有使用者的Gecko profile,而/data/local/webapps/目錄則含有使用者實際可以用的網頁應用程式

-

復原映像檔

-

復原映像檔(recovery.img)包含了和boot.img相同的核心和類似的ramdisk。然而,recovery.img採用不同的初始化腳本,所以使用者會被導引到另一個介面,這個介面會有可以透過裝置實體按鍵來操作的復原指令。

-

recovery.img會被複製到recovery分區,檔案系統運作時並不會掛載復原映像檔。

-

構建過程:準備,設定,建置,安裝

-

建置和安裝Firefox OS的整個過程包括四個步驟:

- - - - - - - - - - - - - - - - - - - -
準備取得建置需要的程式和檔案,如正確的編譯器和函式庫。
配置下載原始碼,並創建.configure檔定義環境變數,例如路徑等。
建置 -

建置使用者的Gaia個人檔案和Gaia網頁應用程式。

-
安裝在設備上安裝檔案。
-

 

-

準備

-

一開始需要準備好建置需要的程式和檔案,如正確的編譯器和函式庫

-

這個步驟可以通過手動執行或使用腳本來完成。詳情將在建置Firefox OS的先決條件頁面討論

-
-

:在UNIX和類UNIX的機器,我們可以利用which指令,搭配需要的程式名稱當作變數,來檢查這些需要的工具是否存在。

-
-

設定

-

接著我們需要複製一份Firefox OS(B2G)的原始碼,通常可以透過git從B2G專案那裡複製一份,另外我們也需要產生一份.config檔,這個檔案會定義建置用的變數。

-

設定會執行config.sh腳本。詳情請見準備進行首次B2G建置頁面。

-

configure腳本需要一個參數,指定建置的裝置種類。建置名稱是和CPU架構而非裝置相關的代碼名稱,目前可取得的代碼名稱請見這裡

-

設定步驟也將使用Android開源專案的repo工具,來下載(或更新)建置的原始碼到/repo/project目錄下。這個步驟會下載大量的檔案並且花費不少時間。

-

建置

-

建置步驟實際上將編譯所有的原始碼,並且生成的映像檔。

-

建置會執行build.sh腳本。詳情請見建置Firefox OS頁面。

-

基本上建置十分單調,這個步驟就是從AOSP工具、到Linux核心、到Gaia網頁應用程式把一切都建置起來,而且有時候很不好判斷是那一個環節出錯導致建置失敗。

-

我們可以只建置全部的某一部份,例如執行建置腳本時只帶入gecko參數,就會只建置Gecko系統,相同地,只帶入gaia參數,就只會建置Gaia。這些分別建置的部份可以分別地被安裝到裝置上。

-

另外,也可以建置之前所討論的映像檔,例如建置系統映像檔可以這樣建置./build.sh out/platform/$target/system.img,其中$target參數和設定步驟中所提供的參數相同。

-

安裝

-

安裝的步驟會將新編譯的程式碼放置到設備上。這個步驟會執行flash.sh腳本。

-

如果只要安裝那些在建置步驟中分別被建置的部份,我們可以通過在執行falsh.sh時多帶入一個參數,例如./falsj.sh gaia就只會安裝Gaia網頁應用程式。

diff --git a/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/index.html b/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/index.html deleted file mode 100644 index f01f67100c..0000000000 --- a/files/zh-tw/archive/b2g_os/building_and_installing_firefox_os/index.html +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: 建置並安裝 Firefox OS -slug: Archive/B2G_OS/Building_and_installing_Firefox_OS -translation_of: Archive/B2G_OS/Building_and_installing_B2G_OS ---- -

由於 Firefox OS 現正積極開發中,而且仍處於預先發佈的階段。如果要確保自己安裝的是最新版本,最好能自己動手建置並安裝。透過此頁面所整理的文章,你可在模擬器或相容裝置上建置並安裝 Firefox OS,或於 Firefox 瀏覽器上安裝 Gaia 使用者介面。

-

- - - - - - - -
-

取得並建置 Firefox OS

-
-
- Firefox OS 必備建置條件
-
- 首次建置 Firefox OS 時的必要步驟。
-
- 準備首次建置 Firefox OS
-
- 在建置 Firefox OS 之前,必須先複製 Firefox OS 的 Repo 並完成細部設定。本篇文章將解釋相關細節。
-
- 建置 Firefox OS
-
- 建置 Firefox OS 的方法。
-
- 匯入 Firefox OS
-
- 將 Firefox OS 匯入新裝置的相關資訊。
-
-

全部文章...

-
-

安裝 Firefox OS 及/或 Gaia

-
-
- 選擇 Gaia 或 Firefox OS 的執行方式
-
- 可於 Firefox 中執行 Gaia;亦可於行動裝置或桌面版模擬器中執行 Firefox OS。本篇指南將協助你根據自己需要,找出最適合的方式。
-
- 在 Firefox 中執行 Gaia
-
- 於 Firefox 桌面版瀏覽器中執行 Gaia。
-
- 使用 Firefox OS 桌面用戶端
-
- 執行並使用 Firefox OS 桌面用戶端;即是在桌面版應用程式中模擬 Gaia 環境。相較於 Firefox 中執行 Gaia,此種方式雖然更精確,但仍不如模擬器所達的精確度。
-
- 使用 Firefox OS 模擬器
-
- 本指南將說名 Firefox OS 模擬器的建置與使用方式,及使用何種模擬器的適當時機。
-
- 於行動裝置上安裝 Firefox OS
-
- 在實際的行動裝置上安裝 Firefox OS。
-
- 在 SGS2 上的 Firefox OS 與 Android 雙重開機
-
- 於 Samsung Galaxy S2 上建立 Firefox OS/Android 雙重開機環境的方法。
-
-
-

 

diff --git a/files/zh-tw/archive/b2g_os/choosing_how_to_run_gaia_or_b2g/index.html b/files/zh-tw/archive/b2g_os/choosing_how_to_run_gaia_or_b2g/index.html deleted file mode 100644 index 20566a839b..0000000000 --- a/files/zh-tw/archive/b2g_os/choosing_how_to_run_gaia_or_b2g/index.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: 選擇如何運作 Gaia 或 B2G -slug: Archive/B2G_OS/Choosing_how_to_run_Gaia_or_B2G -translation_of: Archive/B2G_OS/Choosing_how_to_run_Gaia_or_B2G ---- -

根據各別的需求,當您以 Boot to GEcko 或是 Gaia 使用者介面時、您會思考各種選項及組合。您可以挑出接著列出的這些選項;每個選項都需要考慮其優缺點,有些會比其他的更具延展性。

-

在 Firefox 中運作 Gaia

-

如果您很清楚您在做什麼的話,您可以複製 Gaia 的 repository 並且 在 Firefox 15 或以上版本中運作 Gaia.

-

優點

- -

缺點

- -

為什麼要在 Firefox 中運作 Gaia

-

有兩個很重要的理由會讓您不在行動裝置或模擬器、而是在 Firefox 上運作 Gaia;容易開始著手開發和運作、也可以使用 Firefox 中優秀的開發者工具。如同要了解 Gaia 的 hackers 一般,開發者一開始測試 apps 的 UI 和基本功能的時候會享受到這極大的好處。

-
- Note: 在開始配送 app 之前,您絕對會需要在實體的行動裝置上做測試。
-

在桌面環境中運作 B2G (模擬器)

-

可以自己建置一個 Boot to Gecko 模擬器,並且在上面運作 Gaia。這個軟體雖然是以 Firefox 為基礎,但和行動裝置上的 Boot to Gecko 的行為非常類似。現在 Mozilla 提供 nightly 版本的模擬器給開發者,且這項工作在 bug 744008 裡持續追蹤著。如果您熟悉建置 Firefox code-base 或是 C++ 專案的話,您可以 依循這些步驟 自己建置這個應用程式。

-

優點

- -

缺點

- -

為什麼要運作 B2G 模擬器

-

這是一個不錯且折衷的測試和開發解決方案。對於將您的 app 或是其他程式碼放在近似行動裝置的環境中、卻不用再每次測試時都燒進手機而言,是一個不錯的方案。

-
- Note: 在開始配送 app 之前,您絕對會需要在實體的行動裝置上做測試。
-

在行動裝置上運作 B2G

-

對於測試 B2G 或 Gaia 環境、或是您的 web app 而言,最徹底的方式是建置並將 Boot to Gecko 安裝在實體的行動裝置上。同時這也是最複雜的處理程序。

-

優點

- -

缺點

- -

為什麼要在行動裝置上運作 B2G

-

對於在 B2G 或 Gaia 上測試任何程式或網頁專案而言,這毫無疑問地是最精準的方式。經由在實際的行動裝置硬體上執行,您可以確認您的專案表現及顯示都相當良好,並且都可以正確地使用所有的行動裝置 APIs。另外,在您開始配送任何程式之前,您應該一定要在實體行動裝置上測試;沒這樣做的話,一定會不幸地發生一些難以預測的影響。

diff --git a/files/zh-tw/archive/b2g_os/debugging/index.html b/files/zh-tw/archive/b2g_os/debugging/index.html deleted file mode 100644 index 1084a2f201..0000000000 --- a/files/zh-tw/archive/b2g_os/debugging/index.html +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: 在 Boot to Gecko 上除錯 -slug: Archive/B2G_OS/Debugging -translation_of: Archive/B2G_OS/Debugging ---- -

基本上,在 B2G 有兩種除錯的方法。開發者可以在電腦上藉由 Firefox 15 以上的版本來 執行 Gaia (以及很多相容於 B2G 的 web apps )來進行高階的除錯。這樣會讓開發者可以利用 Firefox 裡面優秀的 開發工具 開發工具來幫忙除錯,就像是在抓 web app 的 bug 一樣。

-

開發者也可以在 gdb 除錯器的控制之下,使用自己的行動裝置來執行 B2G。

-

使用 Firefox 除錯 Gaia 和 web apps

-

<快馬加鞭中,請耐心等待>

-

使用 gdb 除錯 B2G

-

用 gdb 來對 Boot to Gecko 除錯很簡單。只要用 run-gdb.sh 這個 script 指令,就會重新啟動 B2G 並在 gdb 的控制之下執行:

-
./run-gdb.sh
-
-

如果 B2G 已經在執行了,而現在只想要 attach,就要執行下面這個 script 指令:

-
./run-gdb.sh attach
-
-

OOP

-

首先,用「MOZ_DEBUG_CHILD_PROCESS=1 ./run-gdb.sh」啟動 b2g,接著當啟動 OOP app 的時候,會顯示 plugin-container 的 PID。使用<./run-gdb.sh attach PID>啟動第二個 gdb instance。

-

必須在很短的時間之內啟動除錯器的第二個 instance,且在啟動的短時間之內,就要按 c 繼續。

-

更多...

-

我們需要在這裡添加更多內容。

diff --git a/files/zh-tw/archive/b2g_os/firefox_os_build_prerequisites/index.html b/files/zh-tw/archive/b2g_os/firefox_os_build_prerequisites/index.html deleted file mode 100644 index dd2fd2efb5..0000000000 --- a/files/zh-tw/archive/b2g_os/firefox_os_build_prerequisites/index.html +++ /dev/null @@ -1,606 +0,0 @@ ---- -title: Firefox OS build prerequisites -slug: Archive/B2G_OS/Firefox_OS_build_prerequisites -translation_of: Archive/B2G_OS/B2G_OS_build_prerequisites ---- -
-

在您開始取得程式碼並建立您的Firefox OS作業系統以前,需要一個設定正確的編譯環境,請參考build system這個頁面,裡面有詳細的說明。這裡簡單的提一下,您可以在64位元的Linux以及OS X上面作編譯。

-
- -
-

: 若您計畫編譯一個Firefox OS並裝載在一隻手機上,請確認該手機在編譯動作開始時"並未"跟您的電腦連接,正確的連結時機會在詳細步驟中說明。

-
- -

支援的裝置或模擬器

- -

您需要一個目標來裝載您建立的Firefox OS,他可以是一個真實的裝置或是一個模擬器。我們支援數種裝置但一個裝製常常有多種的版本,這樣的情況我們只支援特定的版本。另外不同的裝置我們的支援程度也稍有不同。

- -
-

註:Mozilla的B2G source code是一個B2G的參考實現,而手機製造商是可以自由的為他們的手機做出patch以及修改的。舉例來說,您在市場上購買的Alcatel One Touch這隻手機裡面的B2G就是一個製造商的版本。這樣B2G版本的差異安裝在上面的應用程式是沒有差異的,不過在平台這一層是有一些差別的。由於Nexus 4的版本是直接由Mozilla維護的,因此跟其他第三級支援裝置比較起來我們各版本的Gecko應該更能直接在Nexus 4上直接無問題的使用。

-
- -

第一級支援裝置

- -

第一級支援裝置是一些主要開發用的裝置,因此一般來說能得最快的新功能與新的bug fixes。

- -
-
Keon
-
Keon 即為 Geeksphone Keon 裝置, 也是最初的開發機種中的一個。 請注意這個裝置上的Forefox OS是由 Geeksphone提供.
-
Inari
-
Inari 是另外一個測試裝置. 在您建立Firefox OS給ZTE Open的裝置時請使用這個configuration (configuration的細節後面會提到)。注意: 較新版本的Firefox版本可能會無法在ZTE Open手機的default boot partition中開機成功。
-
Flame
-
Flame 是 Mozilla 最新的 Firefox OS 標準參考開發裝置,除了Flame這隻手機以外,在您建立給 ZTE Open C 這個裝置的Firefox OS時請也在configuration 中選用Flame(configuration 的細節後面會提到)。 兩隻手機都用一樣的設定原因是他們都是基於 Android jellybean。
-
模擬器 (ARM 與 x86)
-
有兩種模擬器,一種是模擬ARM code,另外一種直接用x86 code執行所有的功能. 更多相關資訊請參考Learn more about installing and using the emulators.
-
請注意基本上您應該不要使用 x86 模擬器 — 這個模擬器安裝不易而且支援的程度不是很理想。
-
桌面 client 程式
-
您也可以建立一個桌面版本的Firefox OS; 這個版本是讓 Gecko 跑在一個 XULRunner 程式裡面讓您可以使用 Gaia 提供的使用者界面.
-
Flatfish
-
Flatfist 是第一隻 Firefox OS 平板版本,雖然某些功能像是Web Telephony 沒有辦法使用。在編譯 Flatfish 時,會需要一些額外的設定
-
- -

另外雖然可能很顯而易見,還是提一下您在建立 桌面 client 程式 或任意一個 模擬器 時是不需要手機的。

- -

第二級支援裝置

- -

一般來說,Firefox的功能在第二級支援裝置上都是可用的,這一些裝置被許多開發者使用(特別是應用程式開發者),因此並不需要太過即時的得到Firefox OS上新的改變。

- -
-
Samsung Nexus S
-
已知的 Nexus S 支援型號為 GT-I9020A 以及 GT-I9023,其他的型號可能可以支援
-
Samsung Nexus S 4G
-
SPH-D720 這個型號被當作第二級的支援裝置
-
- -

第三級支援裝置

- -

給這一些裝置的Firefox OS是可以被建立的,不過工程師並不會時常用這一些裝置做開發,因此穩定度與功能上面會明顯的比前兩級的支援裝置要不足。

- -
-
Samsung Galaxy S2
-
只有i9100這個型號是被正式支援的。(i9100P 應該也可以支援因為差異只在 NFC 晶片)
-
Samsung Galaxy Nexus
-
現在看起來所有的型號都可以支援
-
Nexus 4
-
有一些在 IRC 上的使用者測試並成功過。 如果機器本身是 Android 4.4 也許需要降回 4.3 (Android images available from Google)
-
Nexus 5
-
一些在 IRC 上的使用者測試並成功過。
-
Tara
-
Tara 是另一之測試裝置. Tara 的 manifest 只在 master branch. 取得 Tara 的 script 為 "BRANCH=master ./config.sh tara"。
-
Unagi
-
Unagi 用來當作中低階智慧型手機的測試與開發裝置。很多 Firefox OS的開發者使用 Unagi 作開發。
-
Pandaboard
-
Pandaboard 是一片基於 OMAP 4 架構的開發板,作為在各種不同行動平台的開發使用。
-
- -
重要: 只有基於 Android 4 (aka Ice Cream Sandwich) 以上的裝置才被支援。若您手上的裝置是上面提到的其中之一但 Android 的版本比較舊,請務必在做任何動作前先將它升級。
- -
-

: 第二級與第三級支援裝置沒有硬體的 Home 按鈕,不過會有一個軟體的 Home 按鈕

- -

所有第一級支援裝置都有一個硬體的 Home 按鈕,這個按鈕可以讓使用者直接回到 Home screen。現在市面上大多數基於 ICS 的 Android 裝置使用在螢幕上的觸碰按鍵。我們現在提供一個虛擬的 Home 按鈕給這一些缺少硬體按鍵的裝置。若您發現這個虛擬的 Home 按鈕沒出現,請打開 Setting 程式,然後到 Developer settings 並選取 Enable software home button

- -

在 Firefox OS 1.4 版有另外一個 developer option 叫做 "Home gesture enabled"; 開啟這的選項表示虛擬的 Home 按鈕將消失,取而代之的是一個由螢幕下方向上滑動的手勢。

-
- -

使用 GNU/Linux 的需求

- -
-

重要: 即使您沒有要編譯自己的 Boot 2 Gecko,而只有要使用到 Gaia's make system,  您仍需要正確版本的 PythonNode.js

-
- -

在 Linux 建立 Firefox OS, 您需要:

- - - -

這其實比最低需求要高不過常常在建立 Firefox OS 的過程出現問題只是因為資源不太夠。一個常見的例子為 "arm-linux-androideabi-g++: Internal error: Killed (program cc1plus)".

- -

下面列出個工具也必須被安裝:

- - - -

64 位元安裝需求

- -

這個部份列出了一些在不同的Linux發行版本中你必須執行的指令, 以利於安裝所有的需求來建構 Firefox OS.

- -

Ubuntu 12.04 / Linux Mint 13 / Debian 6

- -

在終端機中執行下列指令:

- -
sudo apt-get update
-sudo apt-get install autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib git ia32-libs lib32ncurses5-dev lib32z1-dev libasound-dev libgconf2-dev libgl1-mesa-dev libx11-dev lzop make zip
- -

如果您將建構 "Flame" reference device 或是 Nexus 5, 請在終端機執行以下指令:

- -
sudo apt-get install libxml2-utils 
- -

您可以透過這個ppa來安裝 jdk。

- -

And see the above comments about emulator build issues!

- -

Ubuntu 12.10 / Debian 7

- -

在終端機中執行下列指令:

- -
sudo apt-get install autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib gcc-4.6 g++-4.6 g++-4.6-multilib git ia32-libs lib32ncurses5-dev lib32z1-dev libgl1-mesa-dev libx11-dev make zip
- -

In addition to the emulator build issues discussed above, the compiler will default to gcc-4.7, which will fail to build with an error along the following lines:

- -

"KeyedVector.h:193:31: error: indexOfKey was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation"

- -

To fix this, you will need to specify GCC 4.6 as the default host compiler after having retrieved the B2G sources: Read Changing the default host compiler to find out how to do it.

- -

In a fresh Ubuntu 12.10 install, you'll get an error about unmet dependencies for ia32-libs. The following commands fix it:

- -
sudo dpkg --add-architecture i386
-sudo apt-get update
-sudo apt-get install ia32-libs
- -

Ubuntu 13.04

- -

Run the following command in Terminal:

- -
sudo apt-get install --no-install-recommends autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib gcc-4.6 g++-4.6 g++-4.6-multilib git ia32-libs lib32ncurses5-dev lib32z1-dev zlib1g:amd64 zlib1g-dev:amd64 zlib1g:i386 zlib1g-dev:i386 libgl1-mesa-dev libx11-dev make zip
- -

In addition to the emulator build issues discussed above, the compiler will default to gcc-4.7, which will fail to build with an error along the following lines:

- -

"KeyedVector.h:193:31: error: indexOfKey was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation"

- -

To fix this, you will need to specify GCC 4.6 as the default host compiler after having retrieved the B2G sources: Read Changing the default host compiler to find out how to do it.

- -

Ubuntu 13.10

- -

With Ubuntu 13.10, multi-arch packages are now the main way to support multiple architectures (e.g. 32-bit on a 64-bit install).  You must tell your Ubuntu system that you want to support 32-bit packages as well:
-  

- -
sudo dpkg --add-architecture i386
-sudo apt-get update
- -

Once you've completed that, then you can install the necessary packages:

- -
sudo apt-get install --no-install-recommends autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib gcc-4.6 g++-4.6 g++-4.6-multilib git lib32ncurses5-dev lib32z1-dev zlib1g:amd64 zlib1g-dev:amd64 zlib1g:i386 zlib1g-dev:i386 libgl1-mesa-dev libx11-dev make zip libxml2-utils
-
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 1
-
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 2
-
-sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 1
-
-sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 2
-
-sudo update-alternatives --set gcc "/usr/bin/gcc-4.6"
-
-sudo update-alternatives --set g++ "/usr/bin/g++-4.6" 
- -

Ubuntu 14.04

- -

Follow the instructions given for Ubuntu 13.10.

- -

Fedora 17/18/19/20

- -

Run the following command in Terminal:

- -
sudo yum install autoconf213 bison bzip2 ccache curl flex gawk gcc-c++ git glibc-devel glibc-static libstdc++-static libX11-devel make mesa-libGL-devel ncurses-devel patch zlib-devel ncurses-devel.i686 readline-devel.i686 zlib-devel.i686 libX11-devel.i686 mesa-libGL-devel.i686 glibc-devel.i686 libstdc++.i686 libXrandr.i686 zip perl-Digest-SHA wget
- -

In addition to the above you will need GCC 4.6.x in order to compile the project:

- - - -

Download the right version for your Fedora installation, then install it to /opt, with the following command on Fedora 17/18:

- -
curl -O http://people.mozilla.org/~gsvelto/gcc-4.6.4-fc18.tar.xz
-sudo tar -x -a -C /opt -f gcc-4.6.4-fc18.tar.xz
-
- -

And with the following command for Fedora 19/20:

- -
curl -O http://people.mozilla.org/~gsvelto/gcc-4.6.4-fc19.tar.xz
-sudo tar -x -a -C /opt -f gcc-4.6.4-fc19.tar.xz
-
- -

You will need to specify GCC 4.6.x as the default host compiler after having retrieved the B2G sources: Read Changing the default host compiler to find out how to do it.

- -

If build fails with the compiler complaining about not finding libmpc.so.2, install the package compat-libmpc

- -

Arch Linux

- -

Run the following command in Terminal:

- -
sudo pacman -S --needed alsa-lib autoconf2.13 bison ccache curl firefox flex gcc-multilib git gperf libnotify libxt libx11 mesa multilib-devel wget wireless_tools yasm zip lib32-mesa lib32-mesa-libgl lib32-ncurses lib32-readline lib32-zlib
- -

To install the lib32-* packages you need to have the multilib repository enabled.

- -

B2G can only be compiled with gcc4.6.4, and because Arch Linux always has bleeding edge software you will need to install gcc46-multilib from AUR. Note that you will have to edit the PKGBUILD and add staticlibs to the options array, or gcc will be unable to compile B2G and give you a cannot find -lgcc error when compiling. You will also need to add the following to your .userconfig file:

- -
export CC=gcc-4.6.4
-export CXX=g++-4.6.4
- -

By default, Arch Linux uses Python3. You'll have to force it to use the old python2. You can do that by linking the python2 executable to python but this is discouraged and considered error-prone. This will also break python 3 if it is installed on your system. A better way is to use virtualenv/virtualenvwrapper:

- -
sudo pacman -S python-virtualenvwrapper
-source /usr/bin/virtualenvwrapper.sh
-mkvirtualenv -p `which python2` firefoxos
-workon firefoxos
-
- -

Android will complain that you need make 3.81 or make 3.82 instead of 4.0. You can download make 3.81 from AUR.  This will install the make-3.81 binary on your path, you need to create a symlink named make to a location earlier in the PATH variable for the build to use the correct version.

- -
mkdir -p ~/bin
-ln -s `which make-3.81` ~/bin/make
-export PATH=~/bin:$PATH
-
- -

Android also needs the Java6 SDK and Arch only has Java7.  Unfortunately the aur build is broken, but you can still download the Java 6 SDK and install it manually.  You will then need to put it in your path.

- -
cp ~/Downloads/jdk-6u45-linux-x64.bin /opt
-su
-cd /opt
-chmod +x jdk-6u45-linux-x64.bin
-./jdk-6u45-linux-x64.bin
-exit
-ln -s /opt/jdk1.6.0_45/bin/java ~/bin/java
-
-
- -

Gentoo Linux

- -
Installing ccache
- -

You will need to install ccache, a tool for caching partial builds.

- -
# emerge -av ccache
-
- -

Because ccache is known to frequently cause support issues, Gentoo encourages you to use it explicitly and sparingly.

- -

To enable the required use of ccache, on the subsequent step of this guide where the ./build.sh script is called, Gentoo users should instead run the command with an explicitly extended path, ie.

- -
PATH=/usr/lib64/ccache/bin:$PATH ./build.sh
-
- -
Generating Partition Images
- -

If you are building B2G for actual physical hardware, then you may at some point also wish to generate some partition images for upload to your device. (For example, to restore backed up files to the device via the fastboot utility)

- -

The filesystem image format used in this case is YAFFS2 (Yet Another Filesystem 2). Gentoo has support for the very latest (ie. git HEAD) yaffs2-utils userland package in portage. (Note: You will also need kernel patches if you want to mount YAFFS2 images, but this is not really required since you can deconstruct and rebuild them instead.)

- -
# emerge --autounmask-write yaffs2-utils; etc-update; emerge -av yaffs2-utils
- -

In order to generate such an image, simply change to the parent directory of the partition filesystem tree you wish to package, and issue a command like this:

- -
mkyaffs2image system/ system.img
- -

使用 Mac OS X 的需求

- -

要在Mac OS X 上建構 Firefox OS, 您必須遵循一些步驟, 以下將會詳細說明. 我們也會提出一些您可能在特殊情況下會遇到的錯誤, 以及他們的解決方法.

- -
-

Note: Configuring and Building B2G for Keon WON'T WORK on a Mac. You'll need to use Linux to build B2G for this device.

-
- -

版本相容性

- -

XCode 4.2 以下的版本與 Mac OS X 10.9 (a.k.a. "Mavericks") 並不相容, 所以您可能會很驚訝地發現Firefox OS會建構錯誤. 基本上您無法在 Mac OS X 10.9 以上的版本建構 ICS emulator, 並且 flatfish 在XCode 5.x系列會無法建構.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Mac OS X 10.9.x 的版本相容性
 emulator (ICS)flatfish (JB-4.2)emulator-jb (JB-4.3)emulator-kk (KitKat-4.4)
XCode 4.3.3XXXX
XCode 4.4.1XO[1]OO
XCode 4.5.2XO[1]OO
XCode 4.6.3XO[1]OO
XCode 5.0.2XXOO
XCode 5.1.1XXOO
- -
    -
  1. 您必須將設定環境變數 BUILD_MAC_SDK_EXPERIMENTAL=1 並將其 export  以建構 flatfish.
  2. -
- -

安裝 XCode Command Line Utilities

- -

您必須安裝 Xcode's Command Line Utilities. 您可以只下載 Command Line Utilities, 只需要在 Apple's developer downloads page 挑選您的 OS X 版本, 然而如果您想要完整的 Xcode suite, 你可以在 Mac App Store 安裝他們

- -

Xcode 4.3.1 (OS X 10.7 "Lion") 以及其他較新的版本如 4.4.1+ (也就是 Mac OS X 10.8 "Mountain Lion"), 並不會自動包含我們所需的 Command Line Utilities. 當您安裝 Xcode 時, 請確認進入 Preferences, then the Downloads panel, and install the Command Line Utilities. 另外, 請確認您至少有 20 GB 的硬碟空間.

- -

Screenshot of Xcode Downloads Command Line Tools

- -
-

Note: The Firefox OS 模擬器 需要 Core 2 Duo processor 或較新的處理器; 也就是, 一個相容於Mac OS X 10.7 "Lion"的作業系統. 您的作業系統不一定要是OS X Lion, 您只需要與其相容. 也就是您當然可以建構Firefox OS 在較舊版本的Mac 上.

-
- -
-

Note: XCode 4.2.x or older is not compatible with Mac OS X 10.9 or above, and XCode 4.3.x has no platform SDK for 10.8. Please install a newer version. If you're also working on flatfish, please make sure any of XCode 4.4, 4.5, and 4.6 is available.

-
- -

Run Firefox OS Mac Bootstrap

- -

Next, open a terminal and run the following command:

- -
curl -fsSL https://raw.github.com/mozilla-b2g/B2G/master/scripts/bootstrap-mac.sh | bash
- -

This will pull and run a bootstrap script that makes sure you have all the prerequisites met to build the emulator. It will also prompt you for permission to install anything you're missing, and provide warnings and suggested fixes to problems. The script will check for and install the following items:

- - - -

Xcode wrangling

- -

If you have already upgraded to Xcode 4.4+ and get the message that Xcode is outdated, check the Xcode path with:

- -
xcode-select -print-path
- -

If it still points to /Developer you can update the path with:

- -
sudo xcode-select -switch /Applications/Xcode.app
- -

Making the Mac OS X 10.6 SDK available

- -

You also need to have the Mac OS X 10.6 SDK available. The SDK needs to be available at

- -
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
- -

If it cannot be found there you will need to extract and copy it from Xcode 4.3. To do this:

- -
    -
  1. Download the XCode 4.3 .dmg file from the Apple Developer portal (you'll need an Apple Developer account).
  2. -
  3. Download the utility Pacifist and use it to extract the 10.6 SDK from the XCode 4.3 .dmg file. Click on the "Extract Package" button, find the SDK by searching for 10.6 in the search box, then Ctrl + click on the MacOSX10.6.sdk directory and Extract it to a suitable location.
  4. -
  5. Add a symlink from the 10.6 SDK location to the /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ directory. For example, if you put the 10.6 SDK on your desktop, the comment would be
  6. -
- -
ln -s /Users/<yourusername>/Desktop/MacOSX10.6.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
- -
-

Note: This is not necessary for Mac OS X 10.9 or above, because 10.6 SDK is for ICS and ICS doesn't supports Mac OS X 10.9.

-
- -

Be aware of Mac file system case sensitivity

- -

By default, Mac OS X ships with a case-insensitive file system.  This is problematic because the Linux kernel has a number of files with the same name, but different case.  For example, see the header files xt_CONNMARK.h and xt_connmark.h.  This results in a number of files appearing to be modified in /kernel after a fresh ./config.sh.

- -

In many cases you can run the build just fine; for some platforms, however, you may encounter the following error:

- -
ERROR: You have uncommited changes in kernel
-You may force overwriting these changes
-with |source build/envsetup.sh force|
-
-ERROR: Patching of kernel/ failed.
- -

Please see bug 867259 for more discussion and possible fixes for this problem.

- -

Alternatively, it will always be safest to build on a case sensitive file system.  The easiest way to do this is to create a separate, mountable disk image with case-sensitivity enabled.  You can do this using Apple's Disk Utility application or from the command line:

- -
hdiutil create -volname 'firefoxos' -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/firefoxos.sparseimage
- -

Mount the drive with:

- -
open ~/firefoxos.sparseimage
- -

Change into the mounted drive with:

- -
cd /Volumes/firefoxos/
- -

You can then check out the code and compile from this location without worrying about case-sensitivity problems.

- -

Mountain Lion homebrew gotcha

- -
-
If you are on Mountain Lion and you receive an error during the installation of the dependencies via homebrew, such as:
-
- -
-
clang: error: unable to execute command: Segmentation fault: 11
-... try reinstalling the dependency manually adding the --use-gcc flag, for example: - -
brew install mpfr --use-gcc
-
- -

Follow Samsung Galaxy S2 extra steps

- -

If you plan to build for the Samsung Galaxy S2, you will also need to install heimdall. See {{ anch("Installing heimdall") }} for details. This is not done for you by the bootstrap script!

- -
Note: If you have installed the Samsung Kies tool, which is used to manage the contents of many Samsung phones, you will have to remove it before you can flash Firefox OS onto your device. You can use the standard application removal process on Windows; on Mac, the Kies install disk image has a utility to fully remove Kies from your system. Flashing will not work if you have Kies installed. If you forget to remove Kies, the build system will detect it and remind you to uninstall it. Note also that the uninstall tool does not correctly remove the folder ~/Library/Application Support/.FUS, and leaves a reference to a utility there in your user startup items list. You will want to remove these manually.
- -

Fix libmpc dependency if broken

- -

gcc 4.6 was built with libmpc 0.9; if you then use homebrew to update packages, libmpc gets updated to version 1.0, but homebrew doesn't rebuild gcc 4.6 after the library version changes. So you need to create a symlink to make things work again, like this:

- -
cd /usr/local/lib/
-ln -s libmpc.3.dylib libmpc.2.dylib
- -

Optional: Install HAX

- -

Intel provides a special driver that lets the B2G emulator run its code natively on your Mac instead of being emulated, when you're using the x86 emulator. If you wish to use this, you can download and install it. It's not required, but it can improve emulation performance and stability.  

- -

Before you install HAX you will need to install the Android SDK.

- -

Install adb

- -

The build process needs to pull binary blobs from the Android installation on the phone before building B2G (unless you're building the emulator, of course).  For this, you will need adb, the Android Debug Bridge. Our Installing ADB article explains how to get adb installed.

- -
-

Note for future when you start to use adb: adb needs the phone's lock screen to be unlocked in order to see your phone (at least in later versions of Firefox OS). You'll probably want to disable the lock screen (we'll get to how later in the build instructions).

-
- -

Install heimdall

- -

Heimdall is a utility for flashing the Samsung Galaxy S2. It's used by the Boot to Gecko flash utility to replace the contents of the phone with Firefox OS, as well as to flash updated versions of B2G and Gaia onto the device. You'll need it if you want to install Firefox OS on a Galaxy S2; it is not needed for any other device. For other devices, we build and use the fastboot utility instead.

- -
Note: Again, it's important to note that this is only required for installing Firefox OS on the Samsung Galaxy S2.
- -

There are two ways to install heimdall:

- - - -

Configure ccache

- -

The B2G build process uses ccache. The default cache size for ccache is 1GB, but the B2G build easily saturates this; around 3GB is recommended. You can configure your cache by running the following command inside terminal:

- -
$ ccache --max-size 3GB
- -

For Linux: configure the udev rule for your phone

- -
-

Note: This section is specific to Linux; Mac OS X has the necessary device permissions set up already.

-
- -

Next, you need to confingure the udev rule for your phone,

- -

You can get the USB vendor ID by running lsusb with your phone plugged in, but typically it's Google 18d1, Samsung 04e8, ZTE 19d2, Geeksphone/Qualcomm 05c6. Add this line in your /etc/udev/rules.d/android.rules file (replacing XXXX with the ID for your device):

- -

相容的

- -
SUBSYSTEM=="usb", ATTR{idVendor}=="XXXX", MODE="0666", GROUP="plugdev"
- -

Take ZTE for example, the content in android.rules will be

- -
SUBSYSTEM=="usb", ATTR{idVendor}=="19d2", MODE="0666", GROUP="plugdev"
- -
-

If the file doesn't exist, create it. The rules.d directory is usually read only by default, so you may have to use chmod to make the directory writeable, or the file, or both.

-
- -

Once you've saved the file, and closed it,  make the file readable:

- -
sudo chmod a+r /etc/udev/rules.d/android.rules
-
- -

Now that the udev rules have been updated, restart the udev daemon.

- -

Ubuntu

- -
sudo service udev restart
- -

Fedora 20

- -
sudo systemctl restart systemd-udevd.service
- -

Finally, unplug and the USB cable but don't replug it in because we need to enable remote debugging on the phone first.

- -

Enable remote debugging

- -

Before you plug your phone back into your USB port, put it USB developer mode. This allows you to debug and flash the phone. To enable developer mode, on your phone enable Remote Debugging in Developer settings (this was called Developer mode on older versions.) Once the option is checked, remote debugging is enabled, and you are ready to go.

- -

At this point, connect your phone to your computer via a USB cable (if you created the udev rule before, this will trigger udev to detect the phone and create the device node with the right permissions). Now you can check if you can list your device via the adb devices command (remember that adb can only see your phone when the lock screen is unlocked). If everything has worked ok, you should see an output similar to this (the following is for a Geeksphone Keon):

- -
$ adb devices
-List of devices attached
-full_keon       device
- -

If the device did not list as expect, check the file name and the script are all correct (see previous section), then restart the computer and retype the command again. Note also that if your device uses fastboot, the bootloader may identify itself with a different vendor ID than the one you see when the device boots normally.

- -

Backup the phone system partition

- -
-

Note: You have to do this before you build your device if you do not have an existing system backup, because some libraries will be referenced in build time. These library might be proprietary so we can't provide in our code base.

-
- -

It is recommended that you back up the entire Android system partition on your phone.

- -

You can use this copy of the binary blobs for Android in case you later delete your B2G tree. To do this, run:

- -
adb pull /system <backup target dir>/system
-
- -

 Depending on the phone, you may also need to pull the /data and/or /vendor directories:

- -
adb pull /data <backup target dir>/data
-adb pull /vendor <backup target dir>/vendor
-
- -

If the pull commands fail with an "insufficient permission" message, try the following:

- - - -

On to the next step

- -

At this point, you should be ready to fetch the Firefox OS code!

diff --git a/files/zh-tw/archive/b2g_os/index.html b/files/zh-tw/archive/b2g_os/index.html deleted file mode 100644 index 7c258aaeea..0000000000 --- a/files/zh-tw/archive/b2g_os/index.html +++ /dev/null @@ -1,222 +0,0 @@ ---- -title: B2G OS -slug: Archive/B2G_OS -translation_of: Archive/B2G_OS ---- -
-

由 Mozilla 所開發的 Firefox OS 全新行動作業系統,即是以 Linux 與 Firefox 的核心 (Gecko 引擎) 為其架構。

-
- -
-

開放源碼的 Firefox OS 不受任何專利技術的限制,同樣能讓 App 開發者享受 Web 的功能與靈活度,打造出絕佳的消費性 App。

- -

對 Web 開發者而言,首要應先理解「整個使用者介面就是 Web App」,且該 Web App 又能顯示並啟動其他的 Web App。不論是專為 Firefox OS 撰寫的 App,或是對使用者介面所進行的任何修正,都能算是以 HTML、CSS、JavaScript 所建構的 Web App,且亦能存取行動裝置的硬體和服務。

- -

從產品的角度來看,Firefox OS 即是 Mozilla 與其 OEM 夥伴,在 Boot to Gecko (B2G) 技術上所套用的品牌及支援服務。B2G 為作業系統在工程設計時所用的代號,即透過 Mozilla 與其廣大 Mozilla/開放源碼社群的貢獻者所開發。

-
- -
-

開發 Firefox OS

- -

專屬的 App

- -

此為我們的 App 中心,內含資訊可協助開發者撰寫 Open Web App,並安裝於 Firefox OS 之上。

-
- -
-
-

平台指南

- -

平台開發者可了解 Firefox OS 平台的各個元件如何搭配及運作。

- - -
- -
-

建構與安裝

- -

說明應如何於模擬器、相容裝置、桌機版模擬器上建構\安裝 Firefox OS。

- - -
- -
-

開發者手機

- -

關於特定開發者手機的調整、更新、復原、購買等資訊。

- - -
-
- -
-
-

Firefox OS 書籍

- -

有許多已出版與編寫中的書籍,涵蓋了 Firefox OS 多樣的開發面相。可參閱 Firefox OS 書籍

-
- - -
- -
-

注意:我們將透過〈Firefox OS 說明文件狀態〉頁面,持續更新 Firefox OS 相關文件。如果你也想貢獻 Firefox OS 說明文件,請參閱此頁面並看看有哪些需要調整的內容!

-
- - - -
    -
  1. 介紹
  2. -
  3. 平台指南 -
      -
    1. 平台指南概述
    2. -
    3. 架構概述
    4. -
    5. App 架構
    6. -
    7. Gonk
    8. -
    9. Gecko
    10. -
    11. Gaia
    12. -
    13. Gaia App 指南
    14. -
    15. 安全性 -
        -
      1. Firefox OS 安全模型
      2. -
      3. 系統安全
      4. -
      5. Firefox OS 中的 App 安全
      6. -
      7. 安全的安裝\更新 App
      8. -
      -
    16. -
    17. Firefox OS 記憶體耗盡時的管理
    18. -
    19. 支援功能表
    20. -
    21. 設定清單
    22. -
    -
  4. -
  5. 建構並安裝 -
      -
    1. 建構與安裝概述
    2. -
    3. Firefox OS 建構程序摘要
    4. -
    5. 必要建構條件
    6. -
    7. 準備第一次編譯
    8. -
    9. 建構 Firefox OS
    10. -
    11. 於 OSX 上為「Flame」建構適用的 Firefox OS
    12. -
    13. 選擇 Gaia 或 Firefox OS 的執行方式
    14. -
    15. 建構 B2G 桌機用戶端
    16. -
    17. 使用 Firefox OS 模擬器
    18. -
    19. 於行動裝置上安裝 Firefox OS
    20. -
    21. 建構並套用 Firefox OS 更新封包
    22. -
    23. 執行環境 (Runtime) 工具
    24. -
    -
  6. -
  7. 開發 Firefox OS -
      -
    1. Firefox OS 開發概述
    2. -
    3. 提報 Firefox OS 的錯誤
    4. -
    5. 修改主機端的檔案
    6. -
    7. 以 .userconfig 檔案進行自訂
    8. -
    9. 自訂 b2g.sh 指令碼
    10. -
    11. 移植 Firefox OS
    12. -
    -
  8. -
  9. 開發 Gaia -
      -
    1. Gaia 開發概述
    2. -
    3. 執行 Gaia 的 Codebase
    4. -
    5. 了解 Gaia 的 Codebase
    6. -
    7. 更改 Gaia 程式碼
    8. -
    9. 測試更改過的 Gaia 程式碼
    10. -
    11. 提交 Gaia 修正檔
    12. -
    13. Gaia 版本系統入門
    14. -
    15. 自訂「建構時間」App
    16. -
    17. 市場自訂指南
    18. -
    19. 自訂 Firefox OS App 中的鍵盤
    20. -
    21. 本地化 Firefox OS
    22. -
    23. 本地化最佳實例
    24. -
    25. 「make」選擇參考
    26. -
    27. Gaia 工具參考
    28. -
    -
  10. -
  11. Firefox OS 手機指南 -
      -
    1. Firefox OS 手機指南概述
    2. -
    3. 手機與相關裝置的規格
    4. -
    5. Geeksphone
    6. -
    7. ZTE OPEN
    8. -
    9. ZTE OPEN C
    10. -
    11. Flame
    12. -
    13. 一般裝置功能
    14. -
    15. 疑難排解
    16. -
    17. 開放參考裝置的最佳實例
    18. -
    -
  12. -
  13. Firefox OS 版本說明 -
      -
    1. Firefox OS 版本說明概述
    2. -
    3. Firefox OS 2.1 for developers
    4. -
    5. Firefox OS 2.0 for developers
    6. -
    7. Firefox OS 1.4 for developers
    8. -
    9. Firefox OS 1.3 for developers
    10. -
    11. Firefox OS 1.2 for developers
    12. -
    13. Firefox OS 1.1 for developers
    14. -
    15. Firefox OS 1.0.1 for developers
    16. -
    -
  14. -
  15. 自動化測試 -
      -
    1. Firefox OS 自動化測試概述
    2. -
    3. 於 Firefox OS 執行測試作業:開發者指南
    4. -
    5. Gaia UI 測試
    6. -
    7. Gaia 整合測試
    8. -
    9. Gaia 單元測試
    10. -
    11. Gaia 效能測試
    12. -
    13. Mochitests
    14. -
    15. Reftests
    16. -
    17. WebAPI 測試
    18. -
    19. xpcshell 測試
    20. -
    21. 耐久測試
    22. -
    23. MTBF 測試
    24. -
    25. Marionette
    26. -
    27. Treeherder
    28. -
    29. Jenkins
    30. -
    -
  16. -
  17. 除錯 -
      -
    1. Firefox OS 除錯概述
    2. -
    3. Firefox OS 的開發者設定
    4. -
    5. 將 Firefox OS 裝置連上桌機
    6. -
    7. 以 Firefox 開發者工具設定 Firefox OS 的除錯作業
    8. -
    9. 裝置上的 console 記錄
    10. -
    11. 安裝並使用 ADB
    12. -
    13. 螢幕截圖
    14. -
    15. 使用 WebIDE
    16. -
    17. 使用「應用程式管理員 (App Manager)」
    18. -
    19. Firefox OS 當機回報
    20. -
    21. Firefox OS 記憶體耗盡的除錯
    22. -
    23. Firefox OS 安全性測試與除錯
    24. -
    25. 使用 gdb 為 B2G 除錯
    26. -
    27. 使用 Valgrind 為 B2G 除錯
    28. -
    -
  18. -
diff --git a/files/zh-tw/archive/b2g_os/installing_boot_to_gecko_on_a_mobile_device/index.html b/files/zh-tw/archive/b2g_os/installing_boot_to_gecko_on_a_mobile_device/index.html deleted file mode 100644 index 7605d27e06..0000000000 --- a/files/zh-tw/archive/b2g_os/installing_boot_to_gecko_on_a_mobile_device/index.html +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: 將 Boot to Gecko 安裝於行動裝置 -slug: Archive/B2G_OS/Installing_Boot_to_Gecko_on_a_mobile_device -translation_of: Archive/B2G_OS/Installing_on_a_mobile_device ---- -

如果您編譯給行動裝置的 Boot to Gecko 之後,您就將他安裝在行動裝置上。這篇文章會引導您進行這個動作。

-
- Note: 第一次把 B2G 寫入手機時,手機必須安裝 Androidd 4.0 (Ice Cream Sandwich) 版本。否則這個動作就不會正常的運作。而一旦您完成第一次 B2G 的安裝之後,您就可以熟練的更新了。
-

燒錄手機

-

您只要將您的手機連結到電腦上、並打下列指令,就可以燒任何東西到手機上:

-
./flash.sh
-
-

就這樣。您編譯好的 B2G 就會被燒錄到您的行動裝置上。

-

為您的行動裝置設定 udev 規則

-

在 Linux,如果您看到這個訊息,

-
< waiting for device >
-

那或許意味著這個 fastboot 裝置和提供給 adb 裝置的不同,而那個裝置沒有被加入 udev 規則。您現在可以藉由執行 lsusb 來取得 USB 廠商的 ID,但是它會是 Google 的 ID:18d1,所以將下面這一行加入 /etc/udev/rules.d/51-android.rules 這個檔案,然後就會正常運作了:

-
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
-
- Note: 如果您在 Linux 上碰到一個非常有幫助的 libusb 錯誤 "-3"的話,這意味著手機需要被 root 來取得 USB 裝置的權限。請使用 sudo 再執行一次這個 script。
-

Samsung Galaxy S2 要特別注意的地方

-

如果您的手機是 Galaxy S2 且使用 heimdall 1.3.2 (最新版;可以用 heimdall version 指令檢查版本) 的話,您可能會看到一個警告訊息「FACTORYFS upload failed!」、後面接著「Heimdall flashing failed」和一些額外的資訊。實際上這是一個成功的狀況,所以您可以忽略這個建議。

-

為了要擺脫這個奇怪的行為,您可以去抓 heidmall 的 複製的原始碼、並且降級到 1.3.1 release 版 ("git checkout fbbed42c1e5719cc7a4dceeba098981f19f37c06"),接著根據 README 編譯、然後安裝,這樣就不會再看到這個錯誤訊息了。然而,這並不是必須的 (看起來比較爽就是了)。

-

heimdall 的所有版本都無法燒錄超過 100MB 的 system.img。執行下列指令:

-
ls -l ./out/target/product/galaxys2/system.img
-
-

就可以看到您的 system.img 有多大。如果太大的話,先到 IRC 找人問問求救;有幾種方法可以分兩階段來燒錄。

-

Samsung Galaxy S2 額外的步驟

-

如果您正在燒錄到 Galaxy S2 的話,需要遵守一個額外的步驟。因為使用 flash.sh script 不會自動將 Gaia 燒錄上去;您需要也打下列指令:

-
./flash.sh gaia
-
-

燒錄某個分割區(partitions)到具備 fastboot 的手機

-

您可以燒錄某個分割區 (partitions)到 fastboot 的手機 (也就是說,除了 Samsung Galaxy S2 之外的任何其他手機)。指令如下:

-
./flash.sh system
-./flash.sh boot
-./flash.sh user
-
-

更新某個模組

-

在燒錄的時候,您可以藉由指名元件名稱來更新某個 B2G 的元件。如下:

-
./flash.sh gaia
-./flash.sh gecko
-
-

接著,下一步

-

此時,您的手機應該正在運作 Boot to Gecko!是時候該體驗、寫些程式測試、或是 除些錯 了!

-
- Note: 一個有用的技巧:如果您的 B2G 版本啟動的時候有螢幕鎖且需要密碼才能解鎖的話,預設的解鎖密碼是 0000。
-

Troubleshooting

-

如果行動裝置在安裝或更新 B2G 到新版本後不會正常運作的話,這裡還有一些技巧可以參考。

-

如果使用者介面 (Gaia) 沒有啟動

-

如果您更新您的手機導致使用者介面不會啟動的話,您可以重置手機來清除一些過期的設定或是之類的東西。這樣做可能會讓它回過魂來繼續運作。參考及使用下列指令:

-
cd gaia
-make reset-gaia
-
diff --git a/files/zh-tw/archive/b2g_os/introduction/index.html b/files/zh-tw/archive/b2g_os/introduction/index.html deleted file mode 100644 index 5b0319863d..0000000000 --- a/files/zh-tw/archive/b2g_os/introduction/index.html +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: Firefox OS 簡介 -slug: Archive/B2G_OS/Introduction -translation_of: Archive/B2G_OS/Introduction ---- -
-

Firefox OS 正將無限開拓 Web 的行動界線,且要讓擁有第一支智慧型手機的使用者,能獲得全新的網路體驗。此開放源碼的行動作業系統,即以 Linux、Open Web 標準、Mozilla 的 Gecko 技術為基礎,勢將重新定義「行動平台」。

- -

在導入 WebAPI 以存取硬體功能,並提供直覺且豐富的智慧型手機體驗之後,Mozilla 相信 Web 必將成為開發者的絕佳機會,讓更多消費者能觸及有趣且多樣的產品。

-
- -

目標客戶

- -

此一系列說明文件,主要將讓 Web\平台開發者能夠進一步了解 Firefox OS 的運作方式、貢獻專案的方法,並打造自己的客製化軟體版本以利安裝於裝置之上。若是想建立並發佈自己的 Web App,亦可透過 「應用程式中心 (App Center)」Marketplace 的「專區 (Zone)」輕鬆達成。

- -

Firefox OS 的基本承諾

- -

對 Web\平台開發者來說,所應了解的最重要部分就是:整個使用者介面 (UI) 就是 Web App,且此 Web App 又能夠顯示並啟動其他的 Web App。不論是修改 UI、撰寫 Firefox OS 上執行的 App,甚至是存取行動裝置硬體與服務,都是透過標準的 Web 技術進行。

- -

從產品面來看,Firefox OS 已是 Mozilla 的品牌名稱,透過 Boot to Gecko (B2G,為作業系統產品的設計代號) 而提供相關服務。Firefox OS 的 UI 稱為 Gaia,並包含了 OS 的預設 App 與系統功能。

- -

若要進一步了解平台架構,可參閱《平台指南》。

- -

目前與未來的規劃

- -

現正開發 Firefox OS 2.0 版,且 1.3/1.4 版已經趨於穩定。目前市面上已有多款手機,消費者或開發者所適用的型號均有。若要進一步了解,可參閱:

- - - -

版本週期

- -

從 Firefox OS 1.2 開始,Firefox OS 版本週期即已儘量同步於 Gecko 與 Firefox 桌面版的版本週期 (即 6 週)。現每 3 個月即釋出新版本 Firefox OS,因此每 2 個 Gecko (Firefox 瀏覽器核心) 版本週期就會釋出 1 次新版本 Firefox OS。

- -

舉例來說,Gecko 30 即與 Firefox OS 1.4 一同釋出 (跨過 Gecko 29);Gecko 32 即與 Firefox OS 2.0 (本為 1.5) 一同釋出 (跨過 Gecko 31)。

- -
-

注意:可參閱我們的版本釋出排程,確認 Firefox OS 與 Gecko\桌面版 Firefox 之間的對應版本,另可參閱 Firefox OS Release Milestones 進一步了解版本管理的相關細節。

-
- -

社群

- -

Boot to Gecko 與 Gaia 均是由 Mozilla 內部的工程師團隊開發而得,另加上 Mozilla 外部與開放源碼社群的一同貢獻。如果你想聯繫 Firefox OS 或 Gaia 開發的社群,則可利用下列的郵件群組與 IRC 頻道。

- -

同樣的,可使用 Bugzilla 系統提報 Firefox OS 元件的任何問題。如果你不確定哪些元件應該提報問題,歡迎隨時發問。

- -
-

注意:如果你對 B2G/Gaia 原始碼的特定部分 (例如特定的 Gaia App) 有任何問題或意見,則可在 Firefox Modules 頁面上找到特定聯絡細節。

-
- -

打造作業系統

- -

B2G 作業系統是以 Mozilla 的 Gecko 繪圖引擎為基礎,並從 Linux kernel 以及稱為 Gonk 的硬體抽象層 (Hardware Abstraction Layer,HAL) 延伸。這裡所說的 Gecko,基本上就是 Firefox for Android 或 Windows 或 Mac OS X 所用的相同 Gecko。而 Gonk 就是 Gecko 所衍生的另項系統。

- -

若要進一步打造並安裝 Firefox OS,可參閱《建立並安裝 Firefox OS》。你也可以到 Github 找到 B2G 的原始碼

- -

貢獻 Gaia

- -

若想為 Gaia 貢獻,其實並不需要深入了解 Web 的開發概念。如果要入門 Gaia 並執行,可參閱《入門開發 Gaia》。

- -

還有許多有用的工具,可讓你針對 Gaia 與 Firefox OS 的 Web App 進行除錯。若要進一步了解,亦可參閱《Hacking Gaia》。

- -

開發 Firefox OS 的 App

- -

Firefox OS App 同樣是以標準的 Web 技術 (如 HTML、CSS、JavaScript 等等) 所打造而成。如果你本來就是 Web 開發者,就已經具備了大部分的技術。另必須知道數個特定的 JavaScript API,以利存取裝置的硬體與重要功能 (如相機、陀螺儀、光線感測器、聯絡人資訊、系統警示\通知......)。這些也同樣能參閱應用程式中心Web 平台頁面獲得更多資訊。

- -
-

注意:如果你剛開始打造 Open Web/Firefox OS App,或想要初步了解 Web App 與傳統網頁之間的差異,可參閱《App 迅速入門指南》。

-
- -

支援 Firefox OS 的多個版本

- -

在開發 Firefox OS 的 App 時,必須留意消費者手上的裝置到底搭載了哪個版本 (可參閱目前可用手機表)。另請注意,更新手機平台軟體,可不像更新桌面版軟體一樣簡單。消費者往往受制於網路服務供應商。因此開發者應該讓 App 能夠支援不同的版本。舉例來說,multiline 的「Flexbox」就無法在 Firefox OS 1.3 以下的版本中執行。你可能必須使用較簡單的配置函式,或退而使用較舊的版本。

- -

隨著有越來越多消費性的 Firefox OS 裝置上市,並搭載更高版本的 Firefox OS,這個問題很快就能解決。

- -
-

我們目前建議能針對 Firefox OS 1.1 版本的特性來開發 App。

-
- -
-

注意:MDN 上的《Web 平台參考頁面》,包含瀏覽器\平台的支援資訊。另可到《Apps API Reference》找到特定 App 技術的相關資訊。

-
diff --git a/files/zh-tw/archive/b2g_os/phone_guide/flame/index.html b/files/zh-tw/archive/b2g_os/phone_guide/flame/index.html deleted file mode 100644 index 60b3a7ad8f..0000000000 --- a/files/zh-tw/archive/b2g_os/phone_guide/flame/index.html +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: Firefox OS 參考平台手機「Flame」 -slug: Archive/B2G_OS/Phone_guide/Flame -translation_of: Archive/B2G_OS/Phone_guide/Flame ---- -
-

Flame 的更新檔案:我們建議你加入下方的郵件群組,即可收到軟體版本定期更新檔案,以及其他可影響 Flame 效能的檔案:https://mail.mozilla.org/listinfo/flamenews

-
-

A picture of the Flame device, showing the Firefox OS homescreen containing several app icons.

-

Available to order

-

專為開發者所設計的「Flame」參考平台手機,是 Firefox OS 相關裝置的里程碑。Flame 的硬體規格均為一時之選,包含 FWVGA 顯示功能與雙核心處理器,可協助開發者打造絕佳的內容與經驗。且單一硬體平台同樣適合測試人員,可更輕鬆的測試並找出軟體問題,不必擔心裝置型號既有的特定問題。

-

如果你手上有 Flame,也打算開始把玩、開發\發佈 App,或為 Firefox 平台有所貢獻,則應先參閱下列連結:

- -

如果你想進一步了解作業系統的更新程序、探索手機的其他部分、將 App 送入手機,或觀看手機本身的規格,則可從下列 2 篇文章中找到相關資訊:

- -

購買 Flame

-

Flame 銷售已經告一段落。但我們仍為 Mozilla 貢獻者保留了許多機會要免費送出手機,包含第二輪的 Foxtrot 方案。如果你想免費獲得手機,請儘速聯絡 IRC 上的 Asa Dotzler。

-

連線網路與裝置的規格

-

連線網路:

- -

硬體:請透過手機與裝置的規格頁面找到更多硬體特色。

-

其他特色包含:

- -

另請參閱

- diff --git a/files/zh-tw/archive/b2g_os/phone_guide/index.html b/files/zh-tw/archive/b2g_os/phone_guide/index.html deleted file mode 100644 index 7e301af2de..0000000000 --- a/files/zh-tw/archive/b2g_os/phone_guide/index.html +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: Boot to Gecko 開發者手機指南 -slug: Archive/B2G_OS/Phone_guide -translation_of: Archive/B2G_OS/Phone_guide ---- -

如果您已經從 Mozilla 收到了可以運作 B2G 的開發者手機,或是已經有人幫您將 B2G 安裝好在您的手機上的話,這裡有一份 關於手機運作的基礎指南。我們正在改善這個部分,也希望可以快一點放更有效率的指令放上 MSN。如果您對建置/燒錄有興趣,請看 '設定和建置 Boot to Gecko' 章節,裡面有更細節的資訊。

diff --git a/files/zh-tw/archive/b2g_os/phone_guide/zte_open/index.html b/files/zh-tw/archive/b2g_os/phone_guide/zte_open/index.html deleted file mode 100644 index 36ababcb56..0000000000 --- a/files/zh-tw/archive/b2g_os/phone_guide/zte_open/index.html +++ /dev/null @@ -1,287 +0,0 @@ ---- -title: The Firefox OS ZTE OPEN -slug: Archive/B2G_OS/Phone_guide/ZTE_OPEN -translation_of: Archive/B2G_OS/Phone_guide/ZTE_OPEN ---- -
-

Mozilla 與 ZTE 共同合作開發了 ZTE Open。ZTE Open 是一款為開發者和早期接受者所開發的 Firefox OS 裝置,它已解鎖、開放用於測試和實驗。

-
- -
-

Note: 本指南不適用於 ZTE Open C 裝置,針對 ZTE Open C 請參考 ZTE Open C 頁面。

-
- -

購買裝置

- -

請連至 ZTE 美國、歐洲或香港 ebay 商店購買。

- - - -

升級 Firefox OS

- -

接下來我們將提供升級 ZTE Open 的說明指示:

- -

一般

- -

一般 Firefox OS 的建置、更新和測試都是透過用 USB 連接電腦和手機後,利用 ADB (Android Debugging Bridge) 以及 Fastboot 發送指令進行操作,所以我們需要安裝 ADB 以及 fastboot 到電腦上 (可至 Android Developer Toolkit 取得) ,並不需要安裝整個 Android 開發工具包,adb 以及 fastboot 可以到 /platform-tools/ 資料夾找到。

- -

然後,請打開手機的遠端除錯選項,enable remote debugging

- -

Firefox OS 1.1

- -

2013/12/10,ZTE 發佈了 ZTE Open 的 Firefox OS 1.1 更新包,這個更新開啟了 fastboot, 解決了前一個發佈版本這方面的問題。

- -

在升級到 v1.2 前,最好先升級到 v1.1。升級 v1.1 首先先到 OPEN (American StandardOPEN (European Standard) 下載升級包,請注意我們需要下載對應 OS 版本,所以從 v1.0 升級的人請下載 "V1.1.0B02(for V1.0)",下載檔案中同時也含有說明文件。接下來請解開下載檔案按照以下步驟升級你的 ZTE Open。

- -
-

Note: 使用者資料會在 microSD 卡升級過程中被刪除,請先備份你的資料

-
- -

以下是透過 microSD 卡升級步驟:

- -
    -
  1. 關機、打開背蓋、取下電池背後的 microSD 記憶卡。
  2. -
  3. 將 SD 卡插入電腦。
  4. -
  5. 把下載的 US_DEV_FFOS_V1.1.0B04_UNFUS_SD.zipEU_DEV_FFOS_V1.1.0B04_UNFUS_SD.zip (看你下載的版本) 複製到 microSD 卡的 root 底下,請不要解開 zip 檔。
  6. -
  7. 卸除 SD 卡、裝回到手機上。
  8. -
  9. 同時按下音量向上鍵和電源鍵。音量向上鍵位於手機左側長條型按鍵的上半部。兩顆鍵同時按下後會進入 Firefox OS recovery 模式 (注意 Firefox logo 會先出現一陣子再進入 recovery 模式)。
  10. -
  11. 按音量上下鍵再選項間移動,請選擇 “apply update from external storage.”
  12. -
  13. 按電源鍵確認選項後會看見 microSD 卡裡的檔案列表。
  14. -
  15. 再用音量上下鍵選擇你剛剛複製過來的軔體檔 US_DEV_FFOS_V1.1.0B04_UNFUS_SD.zipEU_DEV_FFOS_V1.1.0B04_UNFUS_SD.zip,然後按電源鍵確認。
  16. -
- -

如果一切順利的話,你會看到一連串訊息,當你看到 Install from sdcard complete.” 那就代表升級完成,請選擇 “reboot system now” 重新開機,重新開機後你將會看到手機第一次啟動的設定頁面。

- -

Firefox OS 1.2

- -

2014, 1月,ZTE 發佈了一版 Firefox OS v1.2 beta 版 (fastboot 開啟、擁有 root 權限),此 beta 版本基本上是由 v1.1 baseline + v1.2 Gecko 與 Gaia, 而且不需要把檔案放在 microSD 卡中。

- -

請先確認 v1.1 已經上面說明安裝完成,接著打開 terminal 然後輸入以下指令確認連線建立成功:

- -
adb devices -l
-
- -

如果連線成功,你會看到類似 "roamer2    device usb:2-1.2" 的回應訊息。

- -

請前往 ZTE 建立的 Dropbox 帳戶下載對應 OS: US 版UK 版,,Windows 使用者可以去下載特殊說明還有升級工具來協助安裝新版本。底下的說明指示無需特殊工具、適用於所有作業系統 – Linux, OS X, 和 Windows。

- -

請解開下載好的檔案,開啟 terminal 進入到解開後的檔案資料夾。請注意以下步驟會刪除個人資料,所以請先備份好你的資料,接著輸入下列指令:

- -
adb reboot bootloader
- -

這個指令會讓裝置重開機,由於 fastboot 只在重開機過程中有效,請在重開機中輸入以下指令:

- -
sudo fastboot devices
-
- -

如果看到 "< waiting for device >" 訊息,請按下 Ctrl-C 並且再次輸入指令直到看見 "ROAMER2    fastboot" 之類的訊息回應。

- -

接著請快速在重開機當中輸入下面指令:

- -
fastboot flash boot boot.img
-fastboot flash userdata userdata.img
-fastboot flash system system.img
-fastboot flash recovery recovery.img
-fastboot erase cache
-fastboot reboot
- -
-

Note: 如果一直看到 "< waiting for device >" 訊息,請嘗試在指令開頭前加上 sudo ,例如 "sudo falshboot flash boot boot.img"。

-
- -

如果來不及輸入完指令,請從 "adb reboot bootloader" 指令開始再試一次。

- -

一切順利的話,重開機後又會看到第一次手機啟用頁面,ZTE Open 此刻已經升級到 v1.2,進入系統後會看到許多測試 app ,請隨意自由自由刪除。

- -
-

Note: Upgrading your ZTE Open to Firefox 1.1 or 1.2 (fastboot enabled)Frédéric Harper 所撰寫的文章也提供了有用的安裝步驟說明。

-
- -
-

Note: ZTE Open 的 v1.2 版有一個通知欄無法展開的問題,這個問題可以藉由燒錄最新的 Firefox OS 1.2 工程版解決,請確認 ADB 安裝好了 還有 遠端除錯 開啟,然後在 terminal 輸入下面指令:
-
- git clone -b v1.2 https://github.com/mozilla-b2g/gaia.git gaia_v1.2
- cd gaia_v1.2
- make reset-gaia

-
- -

Firefox OS 1.3 and beyond

- -

ZTE currently haven't released builds for Firefox OS 1.3 and beyond. To get these on your ZTE open you'll have to manually build and install a new Firefox OS/B2G build on it (start at the build prerequisite instructions, and treat the ZTE like it is an Inari device, for the purposes of configuration). You can recover your phone if necessary, using the procedure cited in the {{ anch("I bricked my phone") }} section.

- -

Phone features

- - - -
-

Note: the Hong Kong phones also support tri-band 3G Networks — HSDPA 850/1900/2100 (850/1900 for US, CA, 850/1900/2100 for Asia, AU, and 900/2100 for EU.)

-
- -

Wireless carriers

- -
-

Pricing information is for reference only and may not be accurate. Visit the associated link for official information.

-
- -

US carriers

- -

AT&T

- - - -
Sampling of prepaid AT&T plans
- -

Prepaid GoPhone®, Smartphone Plans

- - - -

Aio

- - - -
Sampling of prepaid Aio plans
- - - -

Good2GO

- - - -
Sampling of prepaid Good2GO plans
- - - -

Other {{ anch("AT&T") }} MVNOs

- -

These carriers do not offer additional 3G data.

- - - -

T-Mobile

- - - -

Canadian carriers

- -

The US version of the ZTE Open also work in Canada on carriers that use the Bell/Telus network, or the Rogers network. Some regional carriers like Sasktel or MTS that have UMTS should work too.

- -

It will not work on carriers that do not use UMTS or GSM, like Public Mobile, nor on the carriers that use the AWS band like WIND Mobile, Mobilicity, Videotron or Eastlink.

- -

Memory card

- -

File system

- -

In order to be recognized by the phone, the MicroSD card must be formatted as a FAT32 file system. If a card is new or has never been reformatted, it should work as is.

- -

Device revisions

- -

Revision 01

- -

Phones produced before 09/27/2013 do not have fastboot enabled and must be updated. Normally, this would be handled by Software Updates, but since some users have reported trouble with this method, ZTE have made SD card packages available to enable fastboot on earlier devices. Flash images for:

- - - -

The zip file is linked under Downloads.  Note that you need to download the version with your OS revision in it (that is, download the "V1.1.0B02(for V1.0)" if you are upgrading from V1.0).  Once the file is downloaded and unzipped, follow the instructions in the bundled PDF to flash the package to your phone.

- -

Related Support Forum Questions:

- - - -

Revision 02

- -

Phones produced on or after 09/27/2013 are fastboot enabled by default. This includes the Hong Kong phones.

- -
-

Note: If you are unsure of your phone's revision, check it in Settings > Device Information > Software. If it is older than the following version numbers, you will need to update your phone using the above SD packages to enable fastboot.

- - -
- -

Device support

- -

Once your phone has {{ anch("Device revisions","fastboot enabled") }}, you will then be able to build and install new Firefox OS/B2G builds on it (start at the build prerequisite instructions, and treat the ZTE like it is an Inari device, for the purposes of configuration), and recover your phone if necessary, using the procedure cited in the {{ anch("I bricked my phone") }} section.

- -

If you encounter errors about setting the system time while flashing a custom build, you may need to download a modified boot image.

- -

I bricked my phone

- -

If you are in the process of modifying your phone and it becomes “unresponsive” you should be able to recover it using fastboot with the following simple procedure.

- -

First remove the USB cable and then remove the battery from the phone for 30 seconds. Then reinsert the battery and press the volume up button while holding the power button for a few seconds. Next reconnect the USB cable and run the following commands from a terminal window in the directory that contains the SD package files described above (it is worth checking for an update to the SD package before you do this):

- -
fastboot flash recovery recovery.img
-fastboot flash boot boot.img
-fastboot flash userdata userdata.img
-fastboot flash system system.img
-fastboot reboot
-
- -

This process should recover your phone. If it doesn't seem to work, you may have to try it a second time.

- -

Headphones not working?

- -

We found that the headset jack is designed by a Chinese manufacturer that has compatibility problems with other brands of headsets that include microphones. You may have voice mute problems when you try to use headsets made by Apple, Samsung, HTC, and others. You can buy a 3.5 mm headset adapter that reverses the microphone and ground pins to avoid this problem. For more information, see {{ Bug("812607") }}.

- -

Other support notes

- -

Some customers have come across an Issue of FOTA updates failing to enable fastboot; this is still under investigation, and we are assisting ZTE to analyze every scenario. We will post more information as it is available.

- -

If your phone was unfortunately damaged during the FOTA update because of ZTE providing false or wrong update files, you can attempt to restore it to factory settings using the appropriate SD image and instructions referenced in {{ anch("Revision 01") }}. Otherwise, send your phone back to the eBay store you purchased it from in exchange for a new one. You may contact the store owner directly via an eBay message.

- -

See also

- -

Official Dev Phone page on Firefox Marketplace

- -

Draft User Manual [en-US] - PDF

diff --git a/files/zh-tw/archive/b2g_os/platform/apps_architecture/index.html b/files/zh-tw/archive/b2g_os/platform/apps_architecture/index.html deleted file mode 100644 index 2524c81d0b..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/apps_architecture/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Firefox OS apps 架構 -slug: Archive/B2G_OS/Platform/Apps_architecture -translation_of: Archive/B2G_OS/Platform/Apps_architecture ---- -
-

本文旨在說明 Firefox OS 內部如何管理和啟動應用程式,主要是針對 Firefox OS 平台開發者以及正在移植 Firefox OS 到新硬體裝置上的開發者,如果你只是一個單純 App 開發者並不會需要知道,不過有興趣的話還是可以看看了解 Firefox OS。

-
-

App 啟動程序

-

當 app 被啟動時,主畫面 app (Home screen app) 會透過 {{domxref("App")}} API 取得 app 的參照,然後呼叫 {{domxref("App.launch()")}} 方法來啟動 app。

-

Gecko 收到相關請求後會發送一個含有 app 詳細資訊的 {{domxref("mozChromeEvent")}} 到系統 app (System app),系統 app 接著會將一個 {{HTMLElement("iframe")}} 加入 DOM 樹(DOM tree)中,然後將 app 載入該 {{HTMLElement("iframe")}} 裡,直到 app 終止前這個 iframe 就是 app 的家。

-

每一支 app 都需要一個描述該 app 的 manifest 檔,app 包也需要遵照特定檔案階層,詳情請見 App manifest

-

和 Gecko 溝通

-

Gecko 和 Gaia' 系統 app 之間的溝通是經由 {{domxref("mozChromeEvent")}} 以及 {{domxref("mozContentEvent")}} 完成。 mozChromeEvents 是從 chrome 廣播到內容,而 mozContentEvents 是從內容廣播到 chrome,這些溝通主要在控管受信任 UI 的創建與終止,還有在為通知和其他任務,包括通知系統 app 啟動某個 app,提供必要的功能。

-
-

Note: 請參考 System app 文件 以取得更多有關這些事件如何運作的細節,同時也可以參考相關的原始碼 {{source("b2g/chrome/content/shell.js")}}。

-
-

延伸閱讀

- diff --git a/files/zh-tw/archive/b2g_os/platform/gaia/gaia_apps/index.html b/files/zh-tw/archive/b2g_os/platform/gaia/gaia_apps/index.html deleted file mode 100644 index 4a284db78e..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/gaia/gaia_apps/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: Gaia apps -slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps -translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps ---- -
-

Gaia 位在 Firefox OS 的上層,其中包含系統管理功能以及一系列 Firefox OS 內建 apps。所有 Gaia 的原始碼 — 即便系統和鍵盤輸入法 — 都是由 HTML5 (HTML + CSS + JavaScript) 和 Open WebAPIs 技術所建構而成的,本文旨在說明 Gaia 內建的 apps 是如何運作之。

-
-

Gaia 功能類別

-

Gaia 內不同的 apps 大致上可以分成以下幾類。

-
-

Note: 許多 app 運作說明都會連結到 Gaia Github repo 上的 README 頁面,那是因為很多 app 都還在快速開發迭代階段,常常會有更動,所以一直更新 MDN 相當不切實際,如果想要進一步獲取最新的資訊,請再參考各 README 頁面。

-
-

平台類

-

包括系統、設定、螢幕鎖定、建置腳本和藍芽 apps。

-

-

平台類 apps:

-
-
- 系統 (System)
-
- System app 是第一個在 Firefox OS 開機程序 中被 Gecko 載入的web app,它負責處理許許多多系統運行工作,所以不算是在一般個別 web app 的範疇內。
-
- 瀏覽器 (Browser)
-
- Browser app (現在算是 System 一部分) 當有相關需求時,如網頁瀏覽、搜尋或書籤標記,提供瀏覽器類的功能。
-
- 視窗管理 (Window Management)
-
- Firefox OS 視窗管理功能 — 包括 app 生命週期和互動、通知、動畫等等 — 由 System app 特定一塊負責。
-
- 設定 (Settings)
-
- Settings app 讓使用者設定裝置、回應當前活動呼叫 (帶有 configure 名稱的 Web 活動),讓其他 app 可以跳轉到 Settings app 其中的設定面板處理需要的設定任務 (例如說顯示 wifi 設定面板當數據傳輸無法使用時)。
-
-

通訊類

-

包括 Dialer, Contact, SMS apps 與 FTU apps.

-

-

生產力類

-

包括 Email, Calendar, 與 Clock apps.

-

-

生產力類 apps:

-
-
- 日歷 (Calendar)
-
- Firefox OS 內建 calendar app.
-
- 時鐘 (Clock)
-
- Firefox OS 預設 Clock app,具備鬧鈴、計時等功能
-
- Email
-
- Gaia e-mail app.
-
-

媒體類

-

包括 Camera, Gallery, Music, 和 Video apps 等等媒體相關功能,如桌布和轉送 DRM 鎖。

-

-

媒體類 apps:

-
-
- 影音 (Video)
-
- Video 是影音媒體撥放器。
-
- 相機 (Camera)
-
- Firefox OS 使用者透過相機照相、錄影,它也會回應 type 為pick 的 Web 活動,讓其他想使用相機功能的 app 使用相機。
-
-

其他 Gaia 特色功能

-

除了上述功能,Gaia 還有其他功能如 browser, homescreen, marketplace, test framework, PDF viewer, 和 app manager 等。

-
-
- pdf.js
-
- pdf.js 是 HTML5 基礎的 PDF 瀏覽器,Gaia 用其來瀏覽 PDF,請注意 pdf.js 的程式碼庫 (repo) 和 Gaia 是分開來的。
-
diff --git a/files/zh-tw/archive/b2g_os/platform/gaia/index.html b/files/zh-tw/archive/b2g_os/platform/gaia/index.html deleted file mode 100644 index d2a4886cf1..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/gaia/index.html +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: Gaia -slug: Archive/B2G_OS/Platform/Gaia -tags: - - B2G - - Gaia - - Mobile - - NeedsTranslation - - TopicStub -translation_of: Archive/B2G_OS/Platform/Gaia ---- -

Gaia is the user interface level of Firefox OS. Everything that appears on the screen after Firefox OS starts up is drawn by Gaia, including the lock screen, home screen, dialer, and other applications. Gaia is written entirely in HTMLCSS, and JavaScript. Its only interface to the underlying operating system and hardware is through standard Web APIs, which are implemented by Gecko.

-

Because of this design, not only can Gaia be run on Firefox OS devices, but also on other operating systems and in other web browsers (Albeit with potentially degraded functionality depending on the capabilities of the browser).

-

Third party applications onto the device installed alongside Gaia can be launched by Gaia.

- - - - - - - -
-

Documentation about Gaia

-
-
- Introduction to Gaia
-
- Gaia is the user interface application for Firefox OS devices; it's simply a Web application running atop the Firefox OS software stack. This guide introduces Gaia at a high level.
-
- Gaia hacking guide
-
- A guide to hacking and modifying the Gaia interface.
-
- Gaia Build System Primer
-
- Most of the meaniful work for the build steps are performed by the scripts that live inside the build/ subdirectory of Gaia.
-
- Gaia Hacking Tips And FAQ
-
- A list of helpful tips and frequently asked questions around hacking on Gaia.
-
-

View All...

-
-

Getting help from the community

-

If you're working with Gaia, or developing Gaia applications, there are community resources to help you!

-
    -
  • Consult the Boot to Gecko project forum: {{ DiscussionList("dev-gaia", "mozilla.dev.gaia") }}
  • -
-

 

-
- - -

Resources

- -
-

 

diff --git a/files/zh-tw/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html b/files/zh-tw/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html deleted file mode 100644 index 27c9ea5ea4..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Gaia 簡介 -slug: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia -translation_of: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia ---- -

Gaia 是 Boot to Gecko (B2G) 的使用者介面;它只是在 B2G 裝置、模擬器、桌上型電腦版本、或是 Firefox 版本上運作的一個網頁應用程式 (Web application)。如果想要在 Gaia 上添加 apps 程式或是做一些改變的話,所有你需要了解的就是網頁科技 (Web Technologies),例如 JavaScriptHTML、和 CSS

-

Gaia 的鎖定畫面

-

鎖定畫面預設是啟動的,而預設解鎖密碼 (PIN) 是「0000」。隨著這個功能會隨著時間愈趨完整。

-

預設的 Gaia 介面

-

Gaia 的預設介面跟大家所見最典型的智慧型手機相仿,如這邊所看到的圖。

-

screenshot.png這是張 prerelease 版本作業系統的圖,有一些暫時使用的圖示(和一些測試的程式)。頂端的狀態條顯示手機正在使用哪個行動網路 (如果行動裝置沒有網路的話,會顯示「No SIM card」)、行動網路強度、WiFi 訊號強度、電池使用狀態、和現在的時間。

-

畫面的中間區域顯示應用程式的圖示;透過螢幕的圖示切換左右頁。

-

在螢幕的底部是一個底座,可以放四個最常用的應用程式。現在底座還不能修改,且被預設顯示播號 (Dialer)、訊息 (Messages)、市集 (Market)、和瀏覽器 (Browser)的程式。

diff --git a/files/zh-tw/archive/b2g_os/platform/gonk/index.html b/files/zh-tw/archive/b2g_os/platform/gonk/index.html deleted file mode 100644 index 71d064ac30..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/gonk/index.html +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Gonk -slug: Archive/B2G_OS/Platform/Gonk -translation_of: Archive/B2G_OS/Platform/Gonk ---- -

{{draft()}}

-
-

Gonk是Firefox OS的底層系統,包含基於Android Open Source Project (AOSP)的Linux核心以及硬體抽象層(hardware abstraction layer, HAL)。本文旨在說明Gonk的組成,更多有關FireFox OS架構以及Gonk是如何配置在其中的細節,請參考Firefox OS架構指南。

-
-

Gonk 概觀

-

在Gecko原始碼中,有一個b2g/資料夾,這個資料夾含有Gonk接口,它為網頁開啟了行動裝置的硬體能力。這其中包含了Linux核心、HAL和其他OEM特定的函式庫(library)。好機個Gonk函式庫是開放原始碼專案,如libusb, bluez等,有些HAL部分則是和Android專案共享,如GPS, camera等。

-

Gonk是裝置接口層,介於硬體和Gecko之間的配接器。Gonk是一個相對簡單的Linux發布版本,可以視為Gecko的配接目標,就像是Gecko和OS X, Windows和Android的接口。

-
-

Note: 由於不同的行動裝置有不同的晶片組與硬體規格,所以可能會有不同的Gonk發布版本。

-
-

Firefox OS專案擁有Gonk百分之百的控制權,所以能夠提供Gecko那些原本在其他作業系統上無法看到的介面,例如,Gecko可以直接存取電話系統框架和Gonk的顯示frame buffer。

-

Gonk 原始碼

-

B2G repo on Github 上有多種裝置的官方Gonk支援移植,可以視為Gonk的檔案庫。至於裝置支援列表,請見B2G/config.sh。

-

大部分Gonk相關的日常工作包括了移植Gonk到不同硬體上,還有確保Gecko能在不同硬體上順利運行。

-
-
-

 

diff --git a/files/zh-tw/archive/b2g_os/platform/index.html b/files/zh-tw/archive/b2g_os/platform/index.html deleted file mode 100644 index fe9474eed5..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/index.html +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: Firefox OS 平台 -slug: Archive/B2G_OS/Platform -translation_of: Archive/B2G_OS/Platform ---- -

Firefox OS 平台是由多樣的元件所組成。如果你只是要撰寫能在 Firefox OS 上執行的 App,其實不太需要通盤了解其架構。但如果你從事平台開發、平台移植,甚或只是單純好奇的話,也許會對以下說明文件感興趣。

- - - - - - - - -
-

關於 Firefox OS 平台的說明文件

- -
-
Firefox OS 架構概述
-
簡單概述 Firefox OS 的內部架構,可供平台開發或移植工程師初步了解 Firefox OS。
-
 
-
Firefox OS 的 App 架構
-
概述 Firefox OS 的 App 模型。
-
Gaia
-
Gaia 是 Firefox OS 裝置的使用者介面 (UI) App,也是在 Firefox OS 軟體堆疊上執行的 Web App。
-
Gonk
-
Gonk 的說明文件。Gonk 屬於 Gaia 之下的作業系統層,包含 Linux kernel 硬體抽象層 (Hardware abstraction layer),且由 Gecko 負責之間的溝通。
-
Gecko
-
Gecko 即為 Firefox、Thunderbird,以及其他許多 App 所使用的相同 Open Web 標準實作。
-
安全性
-
Firefox OS 的安全性說明文件,包含各個面相的裝置安全,適合 App 開發者、裝置整合商等參考。
-
Firefox OS 記憶體耗盡時的管理作業
-
本文將解釋 Firefox OS 記憶體不足時的管理方式,可透過記憶體清理與記憶體不足通知等功能。
-
功能支援表
-
各個 Firefox OS 版本所支援的各項功能特色。
-
Firefox OS 設定清單
-
常見的設定名稱清單,可搭配 Settings API。
-
- -

全部文章...

-
-

尋求社群協助

- -

如果你正在開發 Firefox OS,或是可於 Firefox OS 裝置上執行的 App,則能參閱以下社群資源!

- -
    -
  • Boot to Gecko 論壇:{{ DiscussionList("dev-b2g", "mozilla.dev.b2g") }}
  • -
- -
    -
  • 在「Boot to Gecko」的 IRC 頻道上提問:#b2g
  • -
- -

請遵守網路禮節...

- - - - - - -

相關資源

- - -
- -

 

diff --git a/files/zh-tw/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html b/files/zh-tw/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html deleted file mode 100644 index 5b7f2045cc..0000000000 --- a/files/zh-tw/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: Firefox OS 記憶體管理 -slug: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS -translation_of: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS ---- -
-

Firefox OS 會運行在一些記憶體容量不大的裝置上,當程序用盡了記憶體,系統核心就必須關閉其他程序好釋放出記憶體使用。本文旨在描述記憶體關閉和記憶體不足通知如何運作、如何控制關閉那些程序,以確保當記憶體不夠時,主系統還是可以運作。

-
-

記憶體不足時會有兩個系統介入管理: Low memory killer (LMK) Low memory notifications.

-

Low memory killer

-

LMK 是 Android 核心的次系統,這個次系統負責關閉程序好騰出記憶體使用。為了決定程序關閉優先順序,每一個程序都會透過 /proc/<pid>/oom_adj or /proc/<pid>/oom_score_adj files 被賦予一個優先值,這個優先值為調整分數(adjustment score 或 oom_adj)。

-

一般來說 oom_adj 值越大,程序越容易被刪除,LMK 提供多個層級,每個層級對應到一定容量的可用記憶體以及最小 oom_adj 值。當可用記憶體掉到某一個層級,所有 oom_adj 值大於該層級 oom_adj 值的程序都有可能被關閉,LMK 會從占用最多記憶體的程序開始一個一個關閉,直到可用記憶體回復到安全層級為止。

-
-

Note: 被 LMK 關閉的背景 app 仍然以 "殭屍 app" 的形式存在在程序管理員 (task manager),下次再回到該 app,app 會被重新喚醒。目前最大殭屍 app 的數量是 10。

-
-
-

Note: 為了記憶體不足被關閉的 app 不一定就是造成記憶體不足的原因。

-
-

程序關閉優先順序

-

Firefox OS 關閉 app 的優先順序是由每個 app 給定的優先層級和相關聯的 OOM 調整分數所決定 (現有值都存在 pref):

-
    -
  1. 最先關閉的 app 是背景 app,最近最少使用的。
  2. -
  3. 第二是 homescreen app。
  4. -
  5. 接下來是使用者可察覺的背景 app (例如,在背景撥放音樂的程式,或高優先 (high-priority)、或持有 cpu wakelock 並且註冊有系統訊息處理器(system messages handler) 的 app)。
  6. -
  7. 第四是鍵盤程式。
  8. -
  9. 前景 (Foreground) app 則是第五順位被關閉的 app。
  10. -
  11. 最後則是前景高優先 (high-priority)、或持有 cpu wakelock 的前景 app。
  12. -
-
-

Note: 大部分在前景的子程序持有為 2 的oom_adj,背景子程序則持有 3 ~ 6 的 oom_adj,背景子程序到底會持有多大 oom_adj 值取決於許多因素,比如說是否撥放音月或是否屬於 homescreen app。

-
-

下面是例外:

- -

記憶體過低通知

-

第二個釋放記憶體的機制是記憶體過低通知。當可用記憶體量低過一定的門檻值,LMK 便會向使用者空間 (userspace) 發出記憶體過低通知,系統 app 和一般使用者 app 都會等待這個通知,然後透過觀察器服務 (observer service) 發出 memory-pressure 事件回應之;這個事件 app 不會直接看見,只有 C++ 和 Chrome JS 程式碼會看到,在 Gecko 裡我們從這個事件中會盡一切可能釋放記憶體 — 通常是刪除內部快取 (images, DNS, sqlite, 等等),拋棄可以回復的物件 (比如 WebGL contexts) 還有執行垃圾回收機制。
-
- 當碰到記憶體過低狀況時,第一個發出的 memory-pressure 事件會有 low-memory 負載,倘若經過預定的5秒後我們依然處於記憶體過低狀態,另一個 memory-pressure 事件會發出,不過這一次是帶著 low-memory-ongoing 負載,這個時候我們持續處於記憶體過低狀態,很明顯地像一些垃圾回收機制等大動作的作法也不夠了,所以其他一些更低階的記憶體釋放作法會被採行。

-

LMK 和記憶體過低通知如何協同運作

-

目前記憶體過低門檻介於 LMK 的背景 app 層級(大於)和 homescreen 層級(小於)之間,所以整體記憶體不足的反應機制如下:

-
    -
  1. 關閉最近最不常用的背景 app。
  2. -
  3. 當記憶體依然不足,發出 memory-pressure 事件通知給所有的 app。
  4. -
  5. 當記憶體依然不足,每5秒發出 memory-pressure 事件,但標記為 ongoing 讓垃圾回收機制不要回應。
  6. -
  7. 關閉 homescreen.
  8. -
  9. 關閉使用者可察覺或高優先值的背景 app。
  10. -
  11. 關閉運作中的鍵盤 app。
  12. -
  13. 關閉前景 app。
  14. -
  15. 關閉高優先值的前景 app。
  16. -
  17. 關閉 preallocated 程序。
  18. -
diff --git a/files/zh-tw/archive/b2g_os/preparing_for_your_first_b2g_build/index.html b/files/zh-tw/archive/b2g_os/preparing_for_your_first_b2g_build/index.html deleted file mode 100644 index 1d165926a1..0000000000 --- a/files/zh-tw/archive/b2g_os/preparing_for_your_first_b2g_build/index.html +++ /dev/null @@ -1,138 +0,0 @@ ---- -title: 準備第一次建置 B2G -slug: Archive/B2G_OS/Preparing_for_your_first_B2G_build -translation_of: Archive/B2G_OS/Preparing_for_your_first_B2G_build ---- -

在開始建置 B2G 前,要先複製整個倉儲 (repository)並且作編譯的設定。這篇文章說明要怎麼做。

- -

複製 B2G 倉儲(repository)

- -

在第一次編譯前,要做的第一步就是複製 B2G 的倉儲(repository)。這個步驟將不會把所有東西抓下來!相反地,他會抓 B2G 建置系統和安裝工具。B2G 大部分的程式碼都在主要的 Mozilla Mercurial 倉儲。

- -

用 git 來複製倉儲:

- -
git clone git://github.com/mozilla-b2g/B2G.git
- -

複製了之後(應該會花個幾分鐘),cd 到 B2G 的目錄:

- -
cd B2G
-
- -

複製 B2G 樹(tree)到一台新機器

- -

當您有一台新電腦時(超幸運的!),您會覺得把 B2G tree 從一台電腦轉移到另一台電腦的話,生活會簡單很多。

- -

將您就電腦的磁碟掛上(mount)到新的電腦,然後敲入下面的指令,就可以做到:

- -
rsync -a source/ dest/
-
- -

source 是整個原始碼樹(source tree)的完整路徑 (包括後面的斜線),而 dest 是您要複製的目的位置 (同樣也包含後面的斜線,它很重要!)。

- -

這樣做之後,您可以跳過這篇文章剩下的部份,然後直接跳到的「建置」部份。

- -

設定專屬於您的行動裝置的 B2G

- -
重要:請注意只支援 Android 4 (aka. Ice Cream Sandwich) 的行動裝置。請確認您的手機運作的真的是 ICS,否則這個步驟很可能會失敗於某些非 Nexus 裝置的驅動程式。另外,如果您必須要將行動裝置燒成 ICS,請留意有些 USB hubs 和燒錄工具不相容,因此您可能需要將行動裝置連接到內建的 USB port。
- -

擷取了核心的 B2G 建置系統之後,您需要為了要安裝的行動裝置作設定。您可以使用 config.sh 工具來擷取支援的行動裝置列表,如下:

- -
./config.sh
-
- -

這會顯示支援的行動裝置列表;舉例來說:

- -
Usage: ./config.sh [-cdflnq] (device name)
-Flags are passed through to |./repo sync|.
-
-Valid devices to configure are:
-- galaxy-s2
-- galaxy-nexus
-- nexus-4
-- nexus-4-kk
-- nexus-5
-- nexus-5-l
-- nexus-s
-- nexus-s-4g
-- flo (Nexus 7 2013)
-- otoro
-- unagi
-- inari
-- keon
-- peak
-- hamachi
-- helix
-- tarako
-- dolphin
-- dolphin-512
-- pandaboard
-- vixen
-- flatfish
-- flame
-- flame-kk
-- flame-l
-- rpi (Revision B)
-- emulator
-- emulator-jb
-- emulator-kk
-- emulator-l
-- emulator-x86
-- emulator-x86-jb
-- emulator-x86-kk
-- emulator-x86-l
-> Sony Xperia devices
-- aries (Z3 Compact KK)
-- aries-l (Z3 Compact L)
-- leo-kk (Z3 KK)
-- leo-l (Z3 L)
-- scorpion-l (Z3 Tablet Compact L)
-- sirius-l (Z2 L)
-- tianchi-l (T2U L)
-- flamingo-l (E3 L)
- -

如果您的行動裝置沒被列出,您應該馬上停止來幫忙將 B2G 移植到您的行動裝置,或是等到某個人移植完之後再安裝。我們當然比較希望您可以幫忙移植!

- -
注意:如果因為任何原因您想要編譯某個版本的 Gecko,請在您著手之前先看 Building against a custom Gecko
- -

設定給行動裝置

- -

首先,連接您的裝置;設定的過程會需要存取它。

- -

如果您的裝置有被列出,您可以再執行一次 config.sh 來開始設定的程序,這次需要指名您的行動裝置的名字。舉例來說,如果要編譯給 Samsung Google Nexus S的話,您要打:

- -
./config.sh nexus-s
-
- -

在設定一開始的附近您可能會需要設定使用顏色的選項,而在這之後設定程序會繼續下去。接著可以去喝個咖啡休息一下,因為這個時候您會第一次把建置 Boot to Gecko 中所有需要的程式碼都抓下來。

- -

如果您的手機不再使用 Android 且 B2G tree 還沒裝到手機上,而您又有遵照前幾頁所說、聰明地作了一份 /system 磁區的備份的話,您可以這樣使用它:

- -
ANDROIDFS_DIR=<absolute path to parent dir of system dir> ./config.sh <target>
-
- -

設定來建置模擬器

- -

如果您要編譯模擬器的話,就需要指定 "emulator" 來使用 ARM 的模擬器,或是 "emulator-x86" 來編譯 x86 模擬器。後者比較快,但也因此在表現實際行動裝置上較不準確。
-
- 舉例來說,您要像下面這樣設定來編譯 ARM 模擬器:

- -
./config.sh emulator
-
- -

在設定一開始的附近您可能會需要設定使用顏色的選項,而在這之後設定程序會繼續下去。接著可以去喝個咖啡休息一下,因為這個時候您會第一次把建置 Boot to Gecko 中所有需要的程式碼都抓下來。

- -

編譯客製的 Gecko

- -

可能您會想要或需要以好幾種版本的 Gecko 來編譯 Boot to Gecko (manifest 中預設是一種)。您可以在您抓倉儲 (在上述的 config.sh 之前),藉由編輯 .userconfig 來做到這件事情。舉例來說,如果您要根據 mozilla-central 來編譯:

- -
GECKO_PATH=/path/to/mozilla-central
-GECKO_OBJDIR=/path/to/mozilla-central/objdir-gonk
-
- -
-

注意: 如果是在 Mac OS X 下客製化編譯的話,檔案系統本身會注意 mozilla-central 的大小寫。

-
- -

您可以參考 客製化 .userconfig 設定檔 來客製化更多東西。

- -

接著,開始編譯

diff --git a/files/zh-tw/archive/b2g_os/quickstart/app_tools/index.html b/files/zh-tw/archive/b2g_os/quickstart/app_tools/index.html deleted file mode 100644 index bc539adefa..0000000000 --- a/files/zh-tw/archive/b2g_os/quickstart/app_tools/index.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: App tools -slug: Archive/B2G_OS/Quickstart/App_tools -translation_of: Archive/B2G_OS/Quickstart/App_tools ---- -
-

用什麼來建立開放式Web應用程序?答案是,"你通常會用它來建立網絡'以下是工具和資源的清單,可以幫助您開始開放式Web應用程序他們可以很容易地成您現有的Web開發工作流程,如果你有一個,或者你可以將它們周圍建立為一個新的工作流程

-
-

應用程序驗證程序

-

您的應用程序以準備好進入Firefox市場應用程序驗證器檢查你的清單,並會顯示任何錯誤,它也有可能顯示你沒有考慮過的警告

-

火狐系統模擬器

-

安裝和使用火狐系統模擬器開始和令你的應用程序運行最簡單的方法安裝模擬器,通過 工具-> Web開發 -> 火狐系統模擬器菜單。啟動後, 便會有JavaScript控制台,以便您可以從模擬器試應用程序啟動和刪除錯誤

-

應用程序管理器

-
-
-  
-
-

的測試工具被稱為應用程序管理器這個工具可以讓你通過USB火狐來連接至兼容的設備(或一個火狐系統模擬器應用程序直接存在設備上,驗證的應用程序,設備上刪除錯誤

-

Firefox的開發者工具

-
-
-
-
- 火狐現在提供了一套開發工具,確保了極大的發展經驗,既好用,又高效率。欲了解更多有關這些工具如何運作,看看還有什麼的Mozilla所提供的,請到我們的工具區域
-
-
-
-

 

diff --git a/files/zh-tw/archive/b2g_os/quickstart/index.html b/files/zh-tw/archive/b2g_os/quickstart/index.html deleted file mode 100644 index a5bb4fa406..0000000000 --- a/files/zh-tw/archive/b2g_os/quickstart/index.html +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: Build -slug: Archive/B2G_OS/Quickstart -tags: - - Apps - - NeedsTranslation - - Quickstart - - TopicStub -translation_of: Archive/B2G_OS/Quickstart ---- -
-

Quickstart information on coding open web apps.

-
-
-
- Introduction to open web apps
-
- What are open web apps? How they differ from regular web pages? Why is this significant? This article aims to answer these questions and more.
-
- Your first app
-
- This article takes you through the basic steps and additional knowledge on top of regular web development required to create installable open web apps.
-
- Introduction to Firefox OS
-
- An introduction to Firefox OS, Mozilla's new open web app-based mobile platform.
-
- Introduction to manifests
-
- An FAQ designed to answer any questions you may have about manifests, hosting apps, origins, and other such topics.
-
- App development for web developers
-
- If you're a web developer, how do open web apps differ from what you're used to? This article explains all.
-
- App development for mobile developers
-
- If you're a native mobile application developer, what advantages can open web apps bring to you, and how do they differ from what you are used to? Here are some ideas.
-
- Developing app functionality
-
- This page talks about the kinds of different functionality that you might want to build into your apps, with links to further information.
-
- Payments
-
- How do you build functionality to make people pay for installing your open web apps? Here is the lowdown.
-
- App tools
-
- Last for this section, we provide some links to more information on the tools available to help you develop great open web apps.
-
diff --git a/files/zh-tw/archive/b2g_os/quickstart/your_first_app/index.html b/files/zh-tw/archive/b2g_os/quickstart/your_first_app/index.html deleted file mode 100644 index d40315b16c..0000000000 --- a/files/zh-tw/archive/b2g_os/quickstart/your_first_app/index.html +++ /dev/null @@ -1,265 +0,0 @@ ---- -title: Your first app -slug: Archive/B2G_OS/Quickstart/Your_first_app -translation_of: Archive/B2G_OS/Quickstart/Your_first_app ---- -
-

Note: 快速入門這段章節已經取代先前舊的快速入門章節,更新為最新的及更專注於Firefox OS app essentials 文章。我們希望你將發現這份是比舊文更有用和更快學習經驗的文章。

-
- -
-
-

開放式Web應用讓開發人員實現了期盼多年的夙願:通過Firefox OS這一首款開放式Web應用平台,可以僅僅使用HTML、CSS和JavaScript在跨平台的環境中生成可部署的應用。本手冊包含了基本的架構和應用構建指南,你能夠迅速掌握這些內容並開始創造自己的下一個偉大的應用!

-
- -

如果你想按照本指南開發,你可以下載我們的quick start app template.  或可以藉由參閱我們的Apps template 指南,找到更多有關的內容。

- -

App 結構

- -

打包型 Apps VS. 托管型 Apps

- -

開放網絡應用有兩種類型:打包型和托管型。打包型apps本質上來說就是一個包含各種HTML、CSS、JavaScript、圖像、表單等應用資源的zip文件。托管型apps在一個給定域名的服務器上運行,就像是一個獨立的網站。兩種應用都需要有有效的表單。到了要在火狐市場中列出你的app,你要上傳app zip文件或提供托管app所在的URL。

- -
-

{{EmbedYouTube("Q7x-B13y33Q")}}

- -
-

用Treehouse為製作夥伴: Check them out!

-
-
- -

本指南的目的,會讓你將創建一個於本機(localhost)地址上的托管型app。一旦你的app準備好進入火狐市場,你可以選擇把它作為打包app或作為托管app啓動。

- -

App 表單

- -

每一個火狐app都需要一個位於根目錄下的manifest.webapp文件, 這個manifest.webapp 文件提供app有關的重要信息,如:版本、名稱、描述、圖標位址、本地字符串、指明app可以從哪兒被安裝等等。只有名稱和描述是必須的。app模板中的簡單表單如下所示:

- -
{
-  "version": "0.1",
-  "name": "Open Web App",
-  "description": "Your new awesome Open Web App",
-  "launch_path": "/app-template/index.html",
-  "icons": {
-    "16": "/app-template/app-icons/icon-16.png",
-    "48": "/app-template/app-icons/icon-48.png",
-    "128": "/app-template/app-icons/icon-128.png"
-  },
-  "developer": {
-    "name": "Your Name",
-    "url": "http://yourawesomeapp.com"
-  },
-  "locales": {
-    "es": {
-      "description": "Su nueva aplicación impresionante Open Web",
-      "developer": {
-        "url": "http://yourawesomeapp.com"
-      }
-    },
-    "it": {
-      "description": "La tua nuova fantastica Open Web App",
-      "developer": {
-        "url": "http://yourawesomeapp.com"
-      }
-    }
-  },
-  "default_locale": "en"
-}
- -
-

{{EmbedYouTube("dgAUgHQOm8M")}}

- -
-

Made in partnership with Treehouse: Check them out!

-
-
- -

 

- -

一個基本的表單是你所需要最先上手的地方。關於表單的更多細節,見App Manifest.

- -

App 佈局 & 設計

- -

隨著不同設備上屏幕解析度標準的增多,響應式設計已經變得越來越重要。即使你app的主要目標平台是移動平台比如Firefox OS,其他設備很有可能也會訪問它。CSS media queries 使你可以根據設備調整佈局,如下的CSS樣例中所示的結構:

- -
/* The following are examples of different CSS media queries */
-
-/* Basic desktop/screen width sniff */
-@media only screen and (min-width : 1224px) {
-  /* styles */
-}
-
-/* Traditional iPhone width */
-@media
-  only screen and (-webkit-min-device-pixel-ratio : 1.5),
-  only screen and (min-device-pixel-ratio : 1.5) {
-  /* styles */
-}
-
-/* Device settings at different orientations */
-@media screen and (orientation:portrait) {
-  /* styles */
-}
-@media screen and (orientation:landscape) {
-  /* styles */
-}
- -

有許多JavaScript和CSS的框架可以用於協助響應式設計和移動app發展(Bootstrap等),選擇最適合你的app和開發樣式的框架即可。

- -

Web APIs

- -

JavaScript APIs正隨著設備快速開發,同時地被創造和增強。Mozilla的WebAPI 致力於為JavaScript APIs引入成打的標準移動端特性。設備支援和狀況列表可以在WebAPI 頁面中查看。在下面這個例子中,JavaScript 特徵偵測仍然是最好的例子:

- -
// If this device supports the vibrate API...
-if('vibrate' in navigator) {
-    // ... vibrate for a second
-    navigator.vibrate(1000);
-}
- -

在下面這個例子中,<div>的顯示樣式會根據設備的電池狀態的改變而改變:

- -
// Create the battery indicator listeners
-(function() {
-  var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery,
-      indicator, indicatorPercentage;
-
-  if(battery) {
-    indicator = document.getElementById('indicator'),
-    indicatorPercentage = document.getElementById('indicator-percentage');
-
-    // Set listeners for changes
-    battery.addEventListener('chargingchange', updateBattery);
-    battery.addEventListener('levelchange', updateBattery);
-
-    // Update immediately
-    updateBattery();
-  }
-
-  function updateBattery() {
-    // Update percentage width and text
-    var level = (battery.level * 100) + '%';
-    indicatorPercentage.style.width = level;
-    indicatorPercentage.innerHTML = 'Battery: ' + level;
-    // Update charging status
-    indicator.className = battery.charging ? 'charging' : '';
-  }
-})();
- -

在上面的示例代碼中,一旦你確定設備支持Battery API,你就可以為chargingchange 和 levelchange添加 event listeners 來更新元素的樣式。試試添加下面的指令到快速入門模板,你會看到你的工作效果。

- -

時常檢查WebAPI 頁面以確保更新設備API的狀態。

- -

Install API 功能

- -

在我們的快速入門應用模板範例中,我們已經實現了一個安裝按鈕,可以在你把應用當作一個標準網頁來瀏覽時可以單擊它來把那個網站當作一個應用安裝在Firefox OS上。按鈕標籤並沒有什麼特別的:

- -
<button id="install-btn">Install app</button>
- -

按鈕的功能由Install API實現(見install.js):

- -
var manifest_url = location.href + 'manifest.webapp';
-
-function install(ev) {
-  ev.preventDefault();
-  // define the manifest URL
-  // install the app
-  var installLocFind = navigator.mozApps.install(manifest_url);
-  installLocFind.onsuccess = function(data) {
-    // App is installed, do something
-  };
-  installLocFind.onerror = function() {
-    // App wasn't installed, info is in
-    // installapp.error.name
-    alert(installLocFind.error.name);
-  };
-};
-
-// get a reference to the button and call install() on click if the app isn't already installed. If it is, hide the button.
-var button = document.getElementById('install-btn');
-
-var installCheck = navigator.mozApps.checkInstalled(manifest_url);
-
-installCheck.onsuccess = function() {
-  if(installCheck.result) {
-    button.style.display = "none";
-  } else {
-    button.addEventListener('click', install, false);
-  };
-};
-
- -

我們來簡要的看一下發生了什麼:

- -

1. 我們得到一個安裝按鈕的引用並把它儲存在button變量中。
- 2. 我們使用navigator.mozApps.checkInstalled 來檢查這個由http://people.mozilla.com  /~cmills/location-finder/manifest.webapp 這個表單來定義的應用是否已經安裝在設備上。這個測試結果被儲存在installCheck這個變量中。
-  3. 當測試被成功完成時,它的成功會完成事件被觸發,因此installCheck.onsuccess = function() { ... }會被執行。
-  4. 然後我們用一個if語句判斷installCheck.result是否存在?如果存在,以為著app已經被安裝了,我們就隱藏安裝按鈕。在應用已經被安裝的情況下不需要安裝按鈕。
-  5. 如果app沒有被安裝,為按鈕添加一個單擊事件監聽器。所以在按鈕被單擊的時候,install()函數會被執行。
-  6. 當單擊按鈕並且install()函數執行時,我們把表單檔案位置保存在一個叫manifest_url的變量中,然後利用navigator.mozApps.install(manifest_url)來安裝app,用一個installLocFind變量來儲存對那個安裝的app參考資訊。你會注意到安裝也會觸發success和error事件,所以你可以根據應用是否成功安裝來執行不同的動作。

- -

第一次遇到可安裝web apps時,你可能想要覈實implementation state of the API 的執行狀態。

- -

注意:可安裝開放web apps有一個「每個來源(origin,感覺就是URL的意思)就是一個app」的安全策略;基本上, 你不可以在一個來源上托管多個可安裝apps。這會讓檢測變得有一點複雜,但是仍有很多辦法解決這個問題,比如為應用創建多個子域名、用Firefox OS模擬器測試應用、或者在Firefox Aurora/Nightly上安裝測試功能,通過這種方式你可以在桌面環境上安裝開發web app。關於來源的跟多信息詳見FAQs about apps manifests

- - -

WebRT APIs (基於權限的 APIs)

- -

有些WebAPI雖然可以使用但是需要特定的功能開啓才具有使用的權限。應用可能會像下面這樣在manifest.webapp中記錄權限請求:

- -
// New key in the manifest: "permissions"
-// Request access to any number of APIs
-// Here we request permissions to the systemXHR API
-"permissions": {
-    "systemXHR": {}
-}
- -

權限分為下面三個等級:

- -
    -
  1. -

    一般權限——不需要任何特定訪問權限的API。

    -
  2. -
  3. -

    特殊權限——只要開發者在app表單文件中設置了訪問權限就可以在應用中利用並通過可信任來源進行分發的API。

    -
  4. -
  5. -

    認證權限——控制力設備上關鍵功能的API,比如打電話和發短信的服務。這些一般不允許第三方開發者使用。

    - -

    關於應用權限等級的更多信息,請閱讀Types of packaged apps。你可以在應用權限中找到更多關於API要求權限和需要什麼樣的App permissions.。

    -
  6. -
- -
-

有一點需要注意的很重要就是不是所有的Web API都可以在Firefox OS模擬器中執行。

-
- -

工具 & 測試

- -

測試在對移動應用的支持中是至關重要的。測試可安裝的開放web app有多種方式。

- -

WebIDE 和 Firefox OS 模擬器

- -

安裝和使用Firefox OS模擬器是啓動和運行你的應用最簡單的方式。在你安裝模擬器之後,可以通過工具->web開發者->Firefox OS模擬器菜單來啓動。模擬器啓動時會有一個Javascript控制台,這樣你就可以在模擬器中調試你的應用。

- -

測試工具的新寵兒被稱為app管理器WebIDE。這個工具允許你通過USB鏈接桌面火狐瀏覽器和一個可兼容性設備(或者一個Firefox OS模擬器),直接將app推送到設備上,驗證app並且像運行在設備上一樣的調試。

- -

單元測試

- -

當在測試不同設備和版本時,單元測試就會非常有價值。jQuery的QUnit 是一個流行的客戶端測試工具,當然你也可以使用任何你喜歡的測試工具。

- -

在設備上安裝Firefox OS

- -

既然Firefox OS是一個開源平台,代碼和工具都可以用於在你自己的設備上構建和安裝Firefox OS。構建和安裝指南以及什麼設備可以安裝的注意事項可以在MDN上發現。

- -

特定的Firefox OS開發者預覽版設備可以在Developer preview phone page找到更多信息。
- 應用。

- -

App 提交和分發

- -

一旦你的app完成,你可以像標準網站或app一樣托管它(更多信息請閱讀Self-publishing apps ),或者可以submittedFirefox Marketplace。你的app表單將被驗證並且你可以選擇你的應用將支持的設備(比如:Firefox OS、桌面版火狐瀏覽器、移動版火狐瀏覽器、平板火狐瀏覽器)。一旦驗證通過,你可以為你的app添加更多細節(截屏、描述、價格等)並且正式在火狐市場中提交app列表。提交成功後,你的應用可以被任何人購買和安裝。

- -

更多商場 & 上市信息

- -

    1. 向Firefox OS商場中提交應用 Submitting an App to the Firefox OS Marketplace
-     2. 市場審查標準 Marketplace Review Criteria
-     3. 應用提交演練視頻 App Submission Video Walkthrough

-
diff --git a/files/zh-tw/archive/b2g_os/releases/1.2/index.html b/files/zh-tw/archive/b2g_os/releases/1.2/index.html deleted file mode 100644 index bc8f785f6b..0000000000 --- a/files/zh-tw/archive/b2g_os/releases/1.2/index.html +++ /dev/null @@ -1,465 +0,0 @@ ---- -title: Firefox OS 1.2 for developers -slug: Archive/B2G_OS/Releases/1.2 -translation_of: Archive/B2G_OS/Releases/1.2 ---- -
-

Firefox OS 1.2 is at a pre-release stage right now. Its Gecko component is based on Firefox 26 (encompassing all Gecko additions between Firefox 19 and Firefox 26; see Firefox 26 release notes for developers for the latest.) This page details the developer features newly implemented in Firefox OS 1.2.

-
- -

Developer Tools

- - - -

HTML

- -

General Gecko:

- - - -

CSS

- -

General Gecko:

- - - -

JavaScript

- -

General Gecko:

- -

EcmaScript 6 (Harmony) implementation continues!

- - - -

Telephony-specific additions (mostly API-related)

- - - -

DOM/API

- -

Firefox OS-specific:

- - - -
New WebGL 1 extensions supported in Firefox OS 1.2:
- - - -
-
Note: availability of these extensions depends on device capabilities; not all extensions will be available on all devices.
-
- -

General Gecko:

- - - -

SVG

- -

General Gecko:

- - - -

MathML

- -

General Gecko:

- - - -

Network

- -

General Gecko:

- - - -

Worker

- -

General Gecko:

- - - -

Security

- -

General Gecko:

- - - -

XForms

- -

General Gecko:

- -

Support for XForms has been removed in Firefox 19.

- -

See also

- - - -

Older versions

- -

- -

- -

- -

Share this article: http://mzl.la/1av9ZRr

diff --git a/files/zh-tw/archive/b2g_os/releases/index.html b/files/zh-tw/archive/b2g_os/releases/index.html deleted file mode 100644 index 3edbcd4c75..0000000000 --- a/files/zh-tw/archive/b2g_os/releases/index.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: Firefox OS developer release notes -slug: Archive/B2G_OS/Releases -tags: - - Firefox OS - - NeedsTranslation - - TopicStub -translation_of: Archive/B2G_OS/Releases ---- -

Firefox OS release notes by version

-

This section provides articles covering each new release of Gaia and Gecko for Firefox OS, explaining what features were added and bugs eliminated in each update. There is also a linked summary table showing what APIs are supported by each version of Firefox OS.

-
- {{ListSubpages("",1,0,1)}}
-

Other supporting information

-
-
- Firefox OS API support table
-
- Lists the different APIs available, and what versions of Firefox have support for them.
-
- App permissions
-
- Lists hosted, privileged and certified APIs, along with information on the permissions they need to have set in the App Manifest of your installable apps, such as the manifest permission name, app type required, description, access property, and default permission.
-
diff --git a/files/zh-tw/archive/b2g_os/running_custom_builds_in_the_app_manager/index.html b/files/zh-tw/archive/b2g_os/running_custom_builds_in_the_app_manager/index.html deleted file mode 100644 index be4fefd747..0000000000 --- a/files/zh-tw/archive/b2g_os/running_custom_builds_in_the_app_manager/index.html +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: 在 WebIDE 中執行 Firefox OS/Gaia 自訂版本 -slug: Archive/B2G_OS/Running_custom_builds_in_the_App_Manager -translation_of: Archive/B2G_OS/Developing_Gaia/Running_custom_builds_in_WebIDE ---- -
-

Firefox OS 模擬器 (Firefox OS Simulator) 已於 2014 年 2 月新增功能,可執行自訂的 B2G 執行環境及/或 Gaia 設定檔 (Profile)。本文將說明相關設定方式,並透過 WebIDE 執行模擬器。

-
-
-

注意:在本文發表之時,滑鼠事件尚未能正確對應觸控事件。例如回到主畫面鈕並無法回應滑鼠點擊的動作。但只要使用 B2G Desktop 鍵盤指令,即可解決此問題。可參閱「Using the B2G Desktop client」。

-
-
-

注意:如果你能提交 Try 版本,則可在各個 B2G 桌面平台的版本路徑中產生模擬器附加元件。如此可讓模擬器搭配自訂的 Gecko,或搭配對 Gaia 上進行的修改。在某些使用條件下可選用此較簡易的方式。

-
-

必要條件

-

要在模擬器內執行自訂版本,必須齊備相關工具。

-
    -
  1. 安裝 Firefox 並確定其內有 WebIDE (工具 > 網頁開發者 > WebIDE)。
  2. -
  3. 安裝最新版 B2G Desktop Nightly,或建構自己的版本
  4. -
  5. 安裝最新版 Firefox OS 模擬器套件,即 7.0pre7.20140113 或更高版本。或可將 FXOS_SIMULATOR=1 添增到自己的 mozconfig,並使用 ./mach build && ./mach package,從自己的 B2G Desktop 原始碼來建構。
  6. -
  7. SIMULATOR=1 flag 建立 Gaia 設定檔。舉例來說,你可在自己的 Gaia 路徑中執行 make SIMULATOR=1 PROFILE_FOLDER=profile-b2g profile-b2g 指令 (請參閱 Hacking Gaia 進一步了解)。
  8. -
-

設定自己的模擬器

-

你必須完成某些設定,才能讓模擬器找到你的 B2G Desktop 與自訂的 Gaia。

-
    -
  1. 打開附加元件管理分頁 (工具 > 附加元件;或在網址列中輸入 about:addons)。
  2. -
  3. 點擊「擴充套件 (Extensions)」分頁,可列出現已安裝的套件。
  4. -
  5. 在清單中找到新的 Firefox OS 模擬器擴充套件。應該會顯示如 Firefox OS 1.3 Simulator 7.0pre.7.20140113
  6. -
  7. 點擊此擴充套件內的「選項 (Preferences)」按鈕。
    - the Firefox OS simulator preferences: Preferences, disable and remove.
  8. -
  9. 如果你要使用自訂的可執行檔 (最新的 B2G Desktop 版本),以利於 WebIDE 中執行 Firefox OS,則點擊「Select a custom runtime executable」旁邊的「Browse...」按鈕,在檔案選擇介面中找到自己的 B2G Desktop 可執行檔。如果是 Windows/Linux 環境就很好找;而在 Mac 環境中,只要安裝於 Applications 路徑下,就可於 /Applications/B2G.app/Contents/MacOS/b2g 找到。
  10. -
  11. 你也能在 WebIDE 中執行自訂的 Gaia 設定檔。同樣點擊「Select a custom Gaia profile directory」旁邊的「Browse...」按鈕,找到自訂的設定檔路徑 (應該是 gaia/profile-b2g)。
  12. -
  13. 如果要回到非自訂的模擬器,只要重新設定組態值即可。但不能單純的刪除再重新安裝模擬器附加元件。你必須開啟新的分頁,在網址列中輸入「about:config」,繼續在該頁的搜尋欄位中輸入「fxos」或「simulator」,找到如「extensions.fxos_2_0_simulator@mozilla.org.customRuntime」,或「extensions.fxos_2_0_simulator@mozilla.org.gaiaProfile」。這時按下滑鼠右鍵並點選「Reset」。最後重新啟動模擬器版本,就能使用非自訂版本的模擬器。
  14. -
-

使用自訂的模擬器

-

最後說明該如何使用自訂的模擬器。

-
    -
  1. 啟動 WebIDE (工具 > 網頁開發者 > WebIDE);或可按下「Shift + F8」。
  2. -
  3. 點擊右上方的按鈕,開啟「Runtime」選單。
  4. -
  5. 點擊「Firefox OS 1.3」按鈕 (或你安裝的任何最新版本)。即使你的 B2G desktop/Gaia 版本比較新,仍建議點選 Firefox OS 1.3 版。
  6. -
  7. 接著就會啟動模擬器,將載入 B2G Desktop 並執行你的 B2G Nightly 版本與自訂 Gaia!
  8. -
-

a screenshot of the b2g desktop simulator

diff --git a/files/zh-tw/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html b/files/zh-tw/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html deleted file mode 100644 index ae38c355ea..0000000000 --- a/files/zh-tw/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html +++ /dev/null @@ -1,208 +0,0 @@ ---- -title: 系列影片:Firefox OS App 開發入門 -slug: 'Archive/B2G_OS/Screencast_series:_App_Basics_for_Firefox_OS' -translation_of: 'Archive/B2G_OS/Firefox_OS_apps/Screencast_series:_App_Basics_for_Firefox_OS' ---- -
-

Firefox OS 這款作業系統,就是要將 Web 帶入行動裝置所設計。Firefox OS 不是以新技術或新開發環境所建構的全新 OS;而是以行之有年的標準化 Web 技術所打造而成。如果你本身就是 Web 開發者且想建構行動 App,那麼 Firefox OS 就能提供最適合的工具,且不會要求你改變自己以熟悉的工作流程,也不需再重新學習另一套開發環境。此系列短片是由 Mozilla 與 Telenor 在挪威共同錄製而成,將引領你入門 Firefox OS App 的開發作業。

-
- -

你可透過本系列影片了解:

- - - -
-

注意:每部短片均極為精簡扼要,讓你短暫休息時也能欣賞。一口氣看完整個系列也不會超過一個小時。

-
- -

程式碼與開發環境

- -

除了短片之外,你也能從 GitHub 下載程式碼範例。如果你想自己測試程式碼範例,就必須先設定簡易的開發環境。必備條件如下:

- - - -

系列影片介紹

- -

此系列短片是由 Telenor Digital 的 Jan Jongboom (@janjongboom)Sergi Mansilla (@sergimansilla),以及 Mozilla 的 Chris Heilmann (@codepo8) 於 2014 年 2 月所錄製。地點位於挪威首都奧斯陸的 Telenor Digital 辦公室內。

- -

這三位接下來將為大家簡短介紹系列影片:

- -

{{EmbedYouTube("835Z2RTPdQk")}}

- -

Section 1:建構並發佈

- -

自己的第一款 Firefox OS App

- -

接下來 5 支短片將說明如何建構 Firefox OS App、如何在電腦和實體裝置上測試 App 並除錯、如何將 App 發佈至 Firefox Marketplace 中。這看起來好像很複雜,但其實只要你已經知道怎麼寫網站,就等於能完成 90% 的 App。

- -

不只是網站

- -

Firefox OS App 就是 HTML5 App;其所使用的技術本質上也與網站技術相同。你可以先寫個網站,再提供 manifest 檔案 (可參閱《App manifest》進一步了解) 即可將網站轉為 App。這個動作就等於告知 Firefox OS 你在撰寫 App,並可讓你:

- - - -

HTML5 App 其實是透過網站強化其功能,也同樣遵循相同的規則,如:

- - - -

若要將網頁轉為絕佳的 App,其中的差異就在於開發者就必須考量到行動裝置使用者。也代表 App 首先必須要能:

- - - -

在大多數的情況下,開發者必須稍微讓網頁「瘦身」並簡化介面。而使用者也確實能因此獲得更好的經驗。

- -

{{EmbedYouTube("oUbOw2cQC4k")}}

- -
-

注意:若要進一步設計出絕佳的 HTML5 App,可參閱 MDN 上的《應用程式中心》一文。

-
- -

App 的 Manifest 檔案

- -

Firefox OS App 的 manifest 檔案 (你會在「應用程式管理員 App Manager」看到中文翻譯為「安裝資訊檔」),屬於簡易的 JSON 檔案,將告知作業系統該 App 的相關訊息;另外也可將網頁轉為 Open Web App。開發者可於 manifest 定義 App 不同語系的名稱,也可要求作業系統存取不同的服務與硬體。當然亦可定義該 App 適合的方向 (直幅或橫幅),亦能依需要而鎖定畫面。

- -

{{EmbedYouTube("UTXIVg6sYtA")}}

- -

進一步了解 manifest 檔案與相關工具:

- - - -

應用程式管理員 (App Manager)

- -

要想開始入門 Firefox OS,最簡單的方法就是使用「應用程式管理員 (App Manager)」。應用程式管理員也是桌面版 Firefox 的開發者工具之一,可在電腦上模擬 Firefox OS 裝置。開發者可盡情把玩 Firefox OS,也可像在實際裝置上安裝並測試 App。此外,你也能離線或上線編輯 App,進而體驗 App 並進行除錯,在模擬裝置中即時看到修改之後的結果。

- -

{{EmbedYouTube("oyAlYjpK-PE")}}

- -

若要進一步了解應用程式管理員:

- - - -

在實體裝置上測試

- -

在模擬器上測試 App 當然不錯,但畢竟會受限於模擬的環境。如果想測試 App 互動時的效能或畫面呈現方向,就需要實體裝置。實機同樣可搭配既有的開發者工具,以及「應用程式管理員 (App Manager)」。在實機上使用 App 時,可透過上述 2 種工具進一步了解 App 所發生的作業。而且 App 不必更新,也不必解除安裝,即可即時看到 App 的變化。

- -

{{EmbedYouTube("T8sr9SHKDHE")}}

- -

發佈至 Marketplace

- -

Firefox Marketplace 可供開發者提交 App,並讓消費者能夠接觸到自己的作品。Marketplace 亦可發佈如 Firefox 桌面版與行動版所適用的 App。而消費者只需要簡單的幾個步驟,就能對 App 評分、提出反饋意見、購買自己所需的 App。要發佈自己的 App 真的很簡單:

- - - -

{{EmbedYouTube("kk3gYALtE0Q")}}

- -

App 在提交到 Marketplace 之後,均會由 Mozilla 審查團隊進行審閱,並在幾天內就會通知審查結果。如果 App 有任何問題,在提交期間就會收到相關的檢驗訊息。開發者也有可能收到詳細的問題說明,並獲得修復問題的方法。

- -

Section 2:Firefox OS 進階說明

- -

引言

- -

在前幾支影片中,我們談了 Firefox OS 的基礎概念、打造自己第一個 App 的步驟、在桌機與 Firefox OS 實體裝置上進行 App 除錯,最後把自己的 App 提交到 Marketplace 上。

- -

而接下來的影片會再進一步說明 Firefox OS App 的技術;也會談談存取功能,讓開發者能妥善利用平板電腦與智慧型手機。但這些技術目前僅適用於 Firefox OS,還未能擴及其他平台。Firefox OS 內的所有程式,都是針對標準化與開放源碼的目標所設計。也就是說,我們很快就能在其他裝置或平台上看到 Firefox OS App 的蹤跡。

- -

Web API

- -

智慧型手機具備 GPS、相機、加速規等的多樣高階功能。但問題是 Web 技術並無法碰觸到這些功能技術。如果要存取這些功能,就必須撰寫原生應用程式。為了克服這個問題,Mozilla 與合作夥伴定義了一系列 API,可讓開發者以安全的方式,透過 JavaScript 存取行動裝置所搭載的硬體。這些開放的 API 即所謂的 Web API,同樣也提供給他人建構更多功能。Firefox OS 也是第一個使用 Web API 的平台。開發者不需另外撰寫原生的應用程式,即可存取智慧型手機上所需的功能。

- -

{{EmbedYouTube("QkpH_qugrPk")}}

- -

若要進一步了解 Web API:

- - - -

Web Activities

- -

Web Activities 可視為 Web API 的替代方案,同樣可存取某些特定裝置的硬體。相較於 API 直接與裝置溝通,Web Activities 則是在裝置上建立所有 App 的生態系統,讓 App 彼此相互溝通。舉例來說,App 不會存取相機而是要求圖片,讓使用者可透過自己最愛用的 App 取得圖片。也就是說,App 不要求使用者存取硬體 (偏安全性的考量),而是讓使用者所信賴的 App 去取得圖片。此外,你也可以註冊特定 App 負責處理 OS 中的特定作業。Web Activities 其實就像對桌機裡的檔案按下滑鼠右鍵,你能在右鍵選單中看到有多種 App 可開啟檔案。而使用者可要求 OS 預設特定 App 開啟此一類型的檔案。Web Activities 可讓裝置上的 App 相互溝通,而不需再透過伺服器作為媒介。App 之間傳送的資料均已為最終資料。

- -

{{EmbedYouTube("RQbCyDd9ejE")}}

- -

進一步了解 Web Actitivies:

- - - -

推播通知

- -

使用 SimplePush WebAPI 的推播通知 (Push notification) 功能,可在裝置接收到特定訊息時喚醒 App。如此可在省電狀態下讓 App 保持待機,再隨時根據需求喚醒 App;此功能對行動裝置 App 格外重要。用這種方式所傳送的通知也有其優點:這種通知不會攜帶任何資料,Mozilla 不會取得 App 的資訊,而惡意攻擊者也無法監聽。

- -

{{EmbedYouTube("F5UF4dKojzw")}}

- -

若要進一步了解 SimplePush 所推播的通知:

- - - -

離線功能

- -

如果 App 無法離線作業,那可用性就會大大降低。有部分使用者也因為這個理由,比較喜歡安裝 App 之後只要開啟瀏覽器,就能在裝置的瀏覽器上查看所需的內容。其實「Web App」這個詞看起來會有「需要網路連線才能運作」的感覺。但使用者總是有無法上網的時候:飛機上必須關機、地底下收不到訊號,甚或手機內沒留任何資料。開發者應該要確保自己的 App 能離線運作。而 HTML5 即具備幾項離線作業的技術,主要就是 AppCacheDOMStorage

- -

{{EmbedYouTube("Q_WmkCzEKho")}}

- -

進一步了解離線功能:

- - - -

深入了解

- -

我們希望這一系列的影片,能夠順利帶領開發者建構出自己的第一款 Open Web App。如果你很感興趣也想了解更多細節,也有許多其他資源與管道可供你利用:

- -

{{EmbedYouTube("UVf2EVrLpl8")}}

- - - -

歡迎大家多多交流

- -

影片錄製人:Chris、Sergi、Jan

diff --git a/files/zh-tw/archive/b2g_os/security/application_security/index.html b/files/zh-tw/archive/b2g_os/security/application_security/index.html deleted file mode 100644 index 3e8f8d576e..0000000000 --- a/files/zh-tw/archive/b2g_os/security/application_security/index.html +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: 應用程式安全 -slug: Archive/B2G_OS/Security/Application_security -translation_of: Archive/B2G_OS/Security/Application_security ---- -
-

本文涵蓋 Firefox OS 應用程式安全模型細節內容。

-
-

Firefox OS Web app 核心安全控制如下:

- -

App 類別

-

Firefox OS 支援: "web", "privileged" 和 internal ("certified") 三種類別的 Web app,app 的類別宣告在 manifest 裡 (另外使用權限也在裡面) 。

- -
-

Note: 關於 App 類別,詳細說明請見 App Manifest

-
-

App 下載

-

Firefox OS 共有兩種 App 下載機制:hosted 以及 packaged。一般 web app 兩種方式都能適用,但 privileged 和 certified apps 只能走 packaged 的方式。

-

Hosted(託管式) apps

-

Hosted app 只包含開發者網站伺服器上的 application manifest 檔案,Manifest 檔案裏面有 app 開啟時的啟動頁面路徑。從安全性角度來看 hosted app 和網頁差不多,當打開 hosted app ,載入頁面的 URL 就是網頁在伺服器上的一般 URL,如果之前有 appcache 存檔的話則會從裝置上載入。

-

Packaged(封裝式) apps

-

Packaged app 將所有的資源 (HTML, CSS, JavaScript, app manifest 等等) 包在一份 zip 檔中,而非網頁伺服器,細節請見 Packaged apps

-

App 來源

-

對於 hosted app,application manifest 檔案所在地就是其來源。

-

至於 packaged apps,其來源就是安裝當下決定的應用程式識別,而 Privileged 和 Internal apps 另外可以在 applications manifest 檔案裡用 origin 參數請求使用特定來源。

-

App 安裝

-

App 透過 Apps JavaScript API 安裝:

- -

App manifest 和 App 來源必須一致,這樣避免了未知的第三方冒用 App;另外為了避免網站被不小心或故意被偽裝成有 app manifest,manifest 檔必須以特定 mime-type,application/x-web-app-manifest+json, 發送。

-

更新

-

更新程序請見更新 apps

-

權限

-

App 能夠被授予比一般網頁更多的權限。基本上 app 擁有和網頁同等的權限,如果 app 需要更多額外權限,那麼 app 便需要在 manifest 檔裡明白列出需要的額外權限。

-

Manifest 宣告

-

在 manifest 裡,每一個需要的額外權限必須加入供人閱讀的描述說明為何需要此額外權限,例如 app 想要 navigator.geolocation API 使用權限,manifest 裡就必須如此宣告:

-
"permissions": {
-  "geolocation":{
-    "description": "Required for autocompletion in the share screen",
-  }
-},
-
-

這樣 app 便可以如同網頁一般提示使用者來請求地理位置存取權限。更多細節請見 App manifest

-
-

Note: 目前權限使用目的並不會呈現給使用者看 — 見 bug 823385.

-
-

權限授予

-

當權限需求在 manifest 中宣告後,依據權限不同,可能會直接被同意,但也可能需要在第一次相關 API 被存取時提示使用者徵詢其同意。一般來說會影響到使用者隱私的權限會需要額外徵詢使用者同意,而且這種情況下使用者也有理由知道甚麼權限被請求使用,例如存取通訊錄前會需要徵詢,但存取 TCP 連線則不需要。權限直接同意會經過 Marketplace 安全審核程序以確保安全性。

-

權限駁回

-

使用者可以在任何時候從設定駁回先前授予的權限,但這不包括那些直接同意的權限。

-

Web App Sandbox

-

App 資料獨立

-

每一個 app 都運行在 sandbox 之中,所以所有資料都和其他 app 隔離開來,這涵蓋了 cookie、localStorage、indexedDB 以及網站權限。

-

A diagram showing three Firefox OS apps all open is separate sandboxes, so none of them can affect each other.

-

所以說即使 App A 和 App B 都開啟了指向同一來源 (如 http://www.mozilla.org) 的 {{ htmlelement("iframe") }},但他們兩者的 cookie 資料還是會不同。結果就是當用  App A 登入 Facebook 帳號,開啟了 App B 前往 Facebook 時,因為 App B 無法存取 App A 的 cookie,所以 App B 還是必須要再執行登入作業,如此一來變確保了 App 之間不互相影響、資料安全。

-

Apps 無法啟動彼此

-

App 不能利用 <iframe> 開啟另一個 App,如果 App A 開啟了一個指向 App B URL 的 iframe,這並不會啟動 App B,相反地這只會前往那個 URL 指向的網頁,任何 App B 的 cookie 都無法被存取,這就和 App B 沒有被安裝的情況一樣。

-

就算是 App A 嘗試開啟透過 packaged 式 App B 的 app:// URL,來將 App B 載入到 <iframe> 裡啟動,也會失敗,而且不論 App B 有沒有被安裝,失敗訊息都會一樣,所以說 App A 也無法推敲 App B 的安裝狀態。

-

當 App A 上層的 frame 前往 App B 所在的 URL,結果依然相同。我們永遠知道是哪個 frame 開啟哪個 app,所以說透過上層 frame 開啟其他 app 就和前述一樣會失敗,App 之間資料絕對獨立、無法被盜取。

-

動機

-

資料獨立的做法有好有壞,壞處是使用者必須每開一個 app 都要登錄一次同一個網站,或者是網站有存放一些資料於本地端,每個 app 都會儲存一份資料,同樣的資料可能被重複儲存,如果資料剛好又不小的話,將會相當佔儲存空間。

-

好處是這是比較安全的做法,app 之間不能透過第三方網站互相影響進而導致未預期的行為,或是一個 App A 移除後,另一個 App B 不會因為依賴 App B 的資料或功能而無法運作。更重要的是,資料獨立確保了惡意 app 難以利用漏洞竊取其他網站的資料。

-

最後資料獨立也確保了 app 無法得知使用者是否有裝甚麼其他 app、其他 app 的資料,保護了使用者隱私。

-

權限 Sandbox

-

如同資料在 snadbox 下是獨立隔離開來的,權限亦然。App A 打開了 http://maps.google.com 網頁,而使用者也准許永遠允許 http://maps.google.com 使用地理位置服務,但這也只限於 App A,改天換 App B 打開 http://maps.google.com 網頁,地理位置服務使用權限還是得再徵詢使用者同意。

-

如同一般網頁,每個來源的權限同樣獨立,App A 取得地理位置服務使用權限,但這不代表所有 App A 開啟的網頁都有權使用地理位置服務,如果說 App A 開啟 http://maps.google.comhttp://maps.google.com 照樣需要取得使用者同意才能使用地理位置服務。

-

瀏覽器 API Sandbox

-

對於會開啟大量 URL 的應用程式,如瀏覽器,我們引進了一個 browserContent 旗標來強化安全性,這個 browserContent 讓 app 可以有兩個 sandbox,一個供 app 本身使用,另一個給開啟的網頁使用,例如說:

-

有一個 MyBrowser app 自 https://mybrowser.com 載入,所以程式碼和資源都隸屬於這個網域。

-

當這個 app 建立一個 <iframe mozbrowser>,另一個 sandbox 便會產生,所以說 <iframe mozbrowser> 裡的 cookie、IndexedDB、localStorage 資料都會獨立隔離開來,兩者間不會互相影響。

-

從另一方面來看,如果 MyBrowser app 想要整合 Google Map 的地理位置功能,那麼從一般 <iframe> 裡載入 http://maps.google.com,便可以存取 Google Map 網站的 cookie 資料;但若是從 <iframe mozbrowser> 裡載入的話,便無法取得 Google Map 的 cookie 資料了。

-

假設另一個情況,有一個類似 Yelp、會造訪餐廳網站的 app,這個 app 只要利用 <iframe mozbrowser> 來打開餐廳網站,就可以確保餐廳網站不能含有指回這個 app 的 <iframe> (例如指回 http://yelp.com),如果有的話,該餐廳網站將只能收到 Yelp 網站的資料,而非此 Yelp app,所以該餐廳網站便無法和 Yelp app 共享資料和權限,進而攻擊 Yelp app。

-

App 安全性總結

-

下表總結各類 Firefox OS App 的格式、安裝、更新特性:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Web App 類型
類型發布權限安裝更新
WebHosted 或 Packaged較不敏感的權限,既使未驗證的網站取得也沒關係。可以從各種來源安裝依據安裝來源和發布機制可以背景更新或透過 marketplace 更新。
PrivilegedPackaged 和 Signed需要驗證和審核才可以取得特殊權限 API。從可信任的 marketplace 安裝從可信任的 marketplace 更新,需要使用者同意更新。
InternalPackaged第三方 app 無法存取高度敏感 API裝置預裝跟隨系統層級類別更新。
-
-

Note: 版本 1.0 的 Firefox OS,privileged app 只能從 Mozilla Marketplace 安裝,至於其他多種安全 marketplace 的支援尚未底定。

-
-

 

diff --git a/files/zh-tw/archive/b2g_os/security/index.html b/files/zh-tw/archive/b2g_os/security/index.html deleted file mode 100644 index 468bab0472..0000000000 --- a/files/zh-tw/archive/b2g_os/security/index.html +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: Firefox OS security -slug: Archive/B2G_OS/Security -tags: - - B2G - - Firefox OS - - Mobile - - NeedsTranslation - - Security - - TopicStub -translation_of: Archive/B2G_OS/Security ---- -

The following articles cover security-related topics about Firefox OS. This includes overall security features as well as application security and how the install process is kept secure.

- - - - - - - -
-

Firefox OS security documentation

-
-
- The Firefox OS security model
-
- An overview of the Firefox OS security model.
-
- System security
-
- Details of security controls built-in to the FirefoxOS runtime.
-
- Application security in Firefox OS
-
- An overview of how applications are made secure on Firefox OS.
-
- Securely installing and updating applications
-
- How Firefox OS securely installs and updates applications.
-
- Software permissions in Firefox OS
-
- A guide to what types of software have permission to perform various tasks on Firefox OS.
-
-  Debugging and security testing with Firefox OS
-
- This guide shows you the basic security testing steps, from opening a remote JavaScript debugger to setting up an intercepting HTTP(S) proxy against a desktop version of Firefox OS
-
-

View All...

-
-

Getting help from the community

-

If you're working with Firefox OS, or developing applications you'd like to run on Firefox OS devices, there are community resources to help you!

-
    -
  • Consult the Boot to Gecko project forum: {{ DiscussionList("dev-b2g", "mozilla.dev.b2g") }}
  • -
-
    -
  • Ask your question on Mozilla's Boot to Gecko IRC channel: #b2g
  • -
-

Don't forget about the netiquette...

-
- - -
-

 

-
-
- Firefox OS
diff --git a/files/zh-tw/archive/b2g_os/security/security_model/index.html b/files/zh-tw/archive/b2g_os/security/security_model/index.html deleted file mode 100644 index d71380833f..0000000000 --- a/files/zh-tw/archive/b2g_os/security/security_model/index.html +++ /dev/null @@ -1,299 +0,0 @@ ---- -title: Firefox OS 安全性概述 -slug: Archive/B2G_OS/Security/Security_model -translation_of: Archive/B2G_OS/Security/Security_model ---- -

此篇文章將概述 Firefox OS 的安全架構,可阻絕 App、平台、資料所挾帶的惡意威脅,進而保護行動裝置。Mozilla 建構了完整且多層次的安全模式,為行動電話提供絕佳的防護效果。

-

 

-

平台安全性

-

Firefox OS 平台具備多層次安全模式,可將各層次的開發風險降至最低。第一線的保護機制更整合了深度防禦 (Defense-in-depth) 策略,進而達到完整的防護機制。

-

 

-

安全架構

-

Firefox OS 將銜接網路架構的應用與其底層硬體,而其整合式技術囊括了下列層級:

-

-

行動裝置 (Mobile device) 即是執行 Firefox OS 的智慧型手機。Gonk 則包含 Linux kernel、韌體、系統函式庫、裝置驅動程式。Gecko 屬於應用程式的執行時間層,為 App提供執行框架,另建構 Web API 以存取行動裝置的功能。Gaia 則是網頁 App (包含 HTML5、CSS、JavaScript、圖片、媒體等) 套件,可隨時改善使用者經驗。

-

Gecko 扮演守門人的角色,可強制執行安全策略,避免行動裝置遭到誤用;並可作為網頁 App (位於 Gaia) 之間的中介層 (Intermediary)。Gonk 則可將行動電話底層的硬體功能,直接提供予 Gecko 使用。只有在 Gecko 放行存取請求時,網頁 App 才能透過 Web API 而存取行動電話的功能;而不會有直接存取或「走後門」的情況發生。Gecko 將強制執行許可,並阻擋未經授權的請求。

-

 

-

佈署安全系統

-

手機上的 Firefox OS 系統映像檔 (System image) 是由受信任的來源 (一般為該裝置的 OEM 廠商) 所提供,這些受信任的系統映像檔提供者負責發布檔案的組建、建置、測試以及數位簽章作業。

-

整個技術層均需經過安全驗證。由Linux 的存取控制清單 (ACL) 執行檔案系統的權限控制。系統 App 則安裝於唯讀 (僅於更新期間才暫時轉為可讀寫) 媒體之中;若是使用者相關內容的區域,則可能為讀寫性質。裝置硬體中的不同元件,均已內建了業界標準的防護機制。舉例來說,晶片製造商會加入安全防護技巧來提高安全性,我們同樣強化了核心平台 (Gecko 與 Gonk),以阻絕潛在的可能威脅,亦提升了相關編譯器的功能。可參閱執行期間的安全性進一步了解細節。

-

 

-

更新安全系統

-

Firefox OS 平台的後續升級與修正,將透過安全的 Mozilla 程序完成佈署,並確保行動電話上的系統映像保有其完整性。同樣由已知且受信任的來源 (一般為該裝置的 OEM 廠商) 提供更新作業,並負責更新封裝的組裝、建構、測試、數位簽章等作業。

-

系統更新可能牽涉 Firefox OS 部分或所有的層級。若更新作業必須變更 Gonk,則安裝作業將使用 FOTA (Firmware Over the Air)。FOTA 更新作業亦可能包含 Firefox OS 的其他層級,如 Gaia、Gecko、安全更新、裝置管理 (FOTA/韌體/驅動程式)、設定管理 (Firefox OS 的設定),還有更多修正檔。

-

若更新作業並未牽涉 Gonk,則僅需 Mozilla 系統更新公用程式 (System Update Utility) 即可完成。Firefox OS 所使用之更新架構、程序、Mozilla ARchive (MAR) 格式 (用於更新封裝),與 Firefox 桌面版產品完全相同。可參閱 https://wiki.mozilla.org/Software_Update 以進一步了解。

-

而行動電話所內建的更新服務 (亦可能由 OEM 廠商提供),將定期檢查是否有系統更新。一旦發佈系統封裝,更新服務隨即將偵測到該封裝,並提醒使用者完成安裝作業。在行動裝置安裝更新檔案之前,另將檢查裝置的儲存容量是否足夠,且將驗證下列分配空間:

- -

更新期間應注意下列要點:

- -

請確實完成相關檢查,讓行動電話確實完成更新作業。

-

 

-

App 的安全性

-

Firefox OS 使用深度防禦 (Defense-in-depth) 策略,可保護行動電話免受惡意應用程式的攻擊。此策略必須佈署多種機制,如根據 App 信任模式 (Trust model) 所建構的隱式許可 (Implicit permission) 層級;執行期間的沙箱執行作業 (Sandboxed execution);僅限 API 存取行動電話的底層硬體;健全的許可模型 (Permission model);安全的安裝與更新程序。若要進一步了解相關技術,可參閱應用程式安全性

-

在 Firefox OS 中的所有應用程式,均為 Web App ─ 即以 HTML5、JavaScript、CSS、媒體、其他開放式 Web 技術 (可於瀏覽器中執行的網頁,並不屬於本文所提的 Web App) 所撰寫的程式。由於這些 Web App 並非二進制 ─ 即所謂的「原生 (Native)」─ 應用,因此將由 Web API居中嚴格協調所有的系統存取作業。甚至檔案系統存取都只能透過 Web API 與後端的 SQLite 資料庫, App 不能直接存取 SD 記憶卡上的檔案。

-

Firefox OS 可限制 App 所能存取/使用的資源規模,同時又可針對多樣的 App 而支援不同的許可層級。Mozilla 嚴格控制各類 App 所能存取的 API。舉例來說,僅有 Certified App (隨手機出貨) 可存取 Telephony API。另外,Dialer App 必須存取 Telephony API 才能撥打電話,而非所有 Certified App 均可存取此 API。如此可避免安裝了任何第三方 App 之後,撥打出國際/長途電話而讓帳單金額暴增。但針對其他 OEM App,仍可選擇是否給予 Telephony API 存取權。舉例來說,電信服務商可提供系統管理應用程式,讓客戶能管理自己的帳戶,甚至能直接以電話送出電信服務帳單或支援辦公室作業。

-

 

-

受信任 (Trusted) 與未信任 (Untrusted) 的 App

-

Firefox OS 將 App 分為下列類型:

- - - - - - - - - - - - - - - - - - - - - - - - - -
-

類型

-
-

受信任層級

-
-

說明

-
-

Certified

-
-

受高度信任

-
-

這類系統 App 經過電信服務商或 OEM (起因於裝置毀損或重要功能所產生的風險) 所核可。但僅限系統 App 與相關服務,並無第三方 App。
- 此信任層級僅用於極少部分的重要 App,例如 SMS、藍牙、相機、電話、系統時鐘、預設的電話播號鍵盤 (為了可確實用於緊急電話)。

-
-

Privileged

-
-

受信任

-
-

由授權的商城審視、核可、數位簽章過的第三方 App。

-
-

Web (與其他 App)

-
-

未受信任

-
-

屬於一般網頁內容。包含安裝式 App (儲存於行動電話中) 與托管式 (Hosted,儲存於遠端,僅有 manifest 檔案儲存於行動裝置中) App。另外也可以從 Marketplace 取得托管式 App 的  manifest 檔案。

-
-

App 的受信任層級,某種程度上將決定其所能取用的行動電話功能。

- -

某些作業 (如網路存取) 均先假設為所有 App 的隱式許可。一般來說,越是高敏感性的作業 (如撥打電話號碼或取得通訊錄內容),就僅有更高信任度的 App 才能執行。

-

最小權限原則 (Principle of Least Permissions)

-

針對 Web App,Firefox OS 安全架構則以《最小權限原則 (principle of least permissions)》為架構:先給予最低權限,僅在必要或合理的情況下,才選擇性的提高權限。依預設值,任一 App 均具備最低權限,以因應未受信任的網頁內容。如果 App 所呼叫的 Web API 需要額外權限,則其 manifest 檔案 (本文稍後將敘述) 必須先列舉這些額外權限。而僅在 App 的 manifest 檔案明確要求 App 授權時,Gecko 才會給予 Web API 的存取權。此外,只有在 Web App 的類型 (即上述的 Certified 或 Trusted 或 Web 分類) 符合其存取層級,Gecko 才會給予必要的授權。

-

Marketplace 對 Privileged App 的審核程序

-

若要達到 Privileged App,則 App 開發/供應商必須將之提交予經過授權的 Marketplace。而 Marketplace 隨即開始嚴格的程式碼審核程序:檢視其完整性與穩定性、審查其索取的授權是否符合其載明的用途、確認其隱式許可是否使用合宜、審核「Privileged App 的內容」與「未授權的外部內容」之間的介面,是否具備合適的緩衝,以避免權限提升 (Elevation of privilege) 的影響。Marketplace 另需負責確保 Web App 不會對其給予的權限進行惡意動作。

-

在 App 通過審核之後即許可使用,且 Marketplace 亦將以數位方式簽署其 manifest 檔案,以供行動裝置的使用者下載之。一旦 Marketplace 遭駭,數位簽章可確保駭客無法將任意內容或惡意程式碼,安裝於使用者的行動電話上。也基於此審查程序,Firefox OS 從 Marketplace 取得的 Privileged App,其可信任度亦高於一般的 (未受信任的) 網頁內容。

-

 

-

封裝式 (Packaged) 與托管式 (Hosted) App

-

Firefox OS 可用封裝式 (儲存於行動電話中) 或托管式 (儲存於遠端伺服器中,僅有 manifest 檔案儲存於行動電話中) App。而此 2 種 App 的安全管理方式亦有所不同。封裝式與托管式 App 同可作為應用程式的封閉沙箱,本文稍後將說明。

-

封裝式 (Packaged) App

-

封裝式 App 是以 ZIP 壓縮檔所構成,內含應用程式的相關資源 (HTML5、CSS、JavaScript、影像、媒體),另以 manifest 檔案提供上述資源的清單,與其對應的 雜湊值 (Hash)。由於 Certified 與 Privileged App 的 manifest 檔案均需完成數位簽章,因此Certified/Privileged App 必為封裝式 App。只要使用者取得封裝式 App,就會將 ZIP 檔案下載至行動電話中,另從 ZIP 檔案內的已知位置讀取 manifest 檔案。系統將在安裝過程中驗證 App 的資源,其他則儲存於本端的封裝內。執行期間將請求所有的顯式許可 (Explicit permission)、顯示使用者 App 的資料儲存目標,最後依預設值完成保存。

-

若要清楚指明封裝式 App 中的資源,則 URL 應以 App 開頭並使用下列格式:

-
-

app://identifier/path_within_zipfile/file.html

-
-

這裡的「app://」代表 ZIP 檔案的掛載點 (Mount point)。於行動電話上安裝 App 時,隨即產生「identifier」作為 UUID。如此可確保以 :app 的 URL 指向了特定資源,且已納入於 ZIP 檔案中。而 app: 中的路徑為相對路徑,因此可於 ZIP 檔案中允許資源的相對鏈結。

-

封裝式 App 主要用於 Certified 與 Privileged App,不過一般的 Web App 亦可作為封裝式。但這些 Web App 不會因為封裝格式,就自動提高其信任度或存取權限。

-

托管式 (Hosted) App

-

托管式 App 均儲存於網頁伺服器上,或需透過 HTTP 載入。僅有其 manifest 檔案儲存於行動電話中;其他所有檔案均儲存於遠端。僅 Privileged 與 Certified App 才能使用特定 API,以因應數位簽章作業而必須將 App 封裝。因此,即使 Web API 作業需要 Privileged/Certified App 的狀態,托管式 App 亦不需存取任何 Web API 作業。

-

從安全性的觀點來說,托管式 App 的作業方式比較像一般網頁。在該網頁伺服器上,必須以寫死 (Hard-coded) 的完整 URL 指向 App 根目錄中的起始頁面,才能載入托管式 App。一旦載入托管式 App 之後,行動電話將根據網頁瀏覽時的 URL,跟著連至相同頁面。

-

 

-

App 的 Manifest 檔案

-

Open Web App 的 manifest 檔案,將提供瀏覽器與 App 互動時的必要資訊。而 manifest 即為 JSON 檔案,至少均具備 App 的名稱與描述。可參閱 App 的 manifest 檔案常見問題以進一步了解。

-

Manifest 範例

-

下列程式碼則具備基礎設定的 manifest 範例:

- - - - - - - -
-

1

-

2

-

3

-

4

-

5

-

6

-

7

-

8

-

9

-

10

-

11

-

12

-

13

-
-

{

-

  "name": "My App",

-

  "description": "My elevator pitch goes here",

-

  "launch_path": "/",

-

  "icons": {

-

    "128": "/img/icon-128.png"

-

  },

-

  "developer": {

-

    "name": "Your name or organization",

-

    "url": "http://your-homepage-here.org"

-

  },

-

  "default_locale": "en"

-

}

-
-

Manifest 檔案的安全性設定

-

manifest 檔案亦可具備其他設定,如下列的安全性設定:

- - - - - - - - - - - - - - - - - - - - - - - - - -
-

欄位

-
-

說明

-
-

permissions

-
-

App 的必要許可。任何 App 需列出所要使用的 Web API,以取得使用者的許可。Privileged/Certified App 可識別大多數的許可,但托管式 App 不適用。API 必具備的屬性:

-
    -
  • description ─ 在請求使用此 API 時,此字串將指定其背後的目的地。必填。
  • -
  • access ─ 此字串將指定許可所需的存取類型。安裝時即給予隱式許可 (Implicit permission)。僅數種 API  為必填欄位。僅接受:readreadwritereadcreatecreateonly 等數值。
  • -
-
-

installs_allowed_from

-
-

App 的來源。而構成來源的陣列 (scheme+unique hostname) 則可觸發此 App 的安裝作業。另可讓 App 廠商限制僅授權過的 Marketplace (如 https://marketplace.firefox.com/) 才可安裝 App。

-
-

csp

-
-

內容安全政策 (Content Security Policy),將套用至 App 所載入的所有頁面。可強化 App 而避免遭惡意插入任何程式碼。若未指定 CSP,則 Privileged 與 Certified App 均已預設了系統定義值,其語法為:
- https://developer.mozilla.org/en-US/docs/Apps/Manifest#csp

-

另請注意,此指令僅能增加所套用的 CSP。舉例來說,此指令並無法減少 Privileged App 所套用的 CSP。

-
-

type

-
-

App 的類型,即 Web、Privileged、Certified 等類型。

-
-

Firefox OS 要求 manifest 檔案必須為特定的 mime-type 格式 ("application/x-web-app-manifest+json"),而且必須與該 App 為相同來源的完整主機名稱 (即來源)。若「App 的 manifest 檔案」與「要求安裝 App 的頁面」兩者的來源相同,則將放寬此限制。此機制可確保不能偽裝網站並托管 App 的 manifest 檔案。

-

 

-

隔離式 (Sandboxed) 執行作業

-

本章節將說明 App 與執行作業的沙箱隔離區 (Sandbox)。

-

App 隔離區

-

Firefox OS 的安全架構,即是將隔離區作為深度防禦 (Defense-in-depth,DID) 策略,以減少風險並保護資料、平台、行動電話。在執行期間,隔離區可為 App 產生邊界與限制。各個 App 僅於自己的工作空間 (Working space) 內執行,另僅經過授權可存取的 Web API 與資料,才能存取;工作空間相關的資訊 (IndexedDB 資料庫、Cookies、離線儲存等) 亦然。請參閱 https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Security/Security_model 以進一步了解。

-

下圖則簡略說明了安全模型:

-

-

在隔離各個 App 之後,所產生的影響亦僅限於其工作空間之內,而不會受到工作空間之外的干擾 (如其他 App 或資料)。

-

執行作業隔離區

-

B2G (Gecko) 在一個高授權度的系統程序 (可存取行動電話中的硬體功能) 中執行。在執行期間,各個執行環境裡的 App 皆是 B2G 系統程序的子程序。而各個子程序又具備嚴格的 OS 授權。舉例來說,子程序並無法直接讀寫檔案系統中的任意檔案。必須由 Web API 提供相關存取權限;且該權限又由 B2G 母程序所居中協調。在子程序要求授權過的 API 時,母程序將確認子程序具備必要的許可,以執行相關動作。

-

App 僅能透過 B2G 核心程序 (非其他程序或 App) 而相互溝通。App 無法於 B2G 之外獨立執行;各 App 亦無法互相開放。App 之間僅能間接「溝通」─ 例如接收器 (Listener) 程序偵測到其他程序所產生的事件,且必須由 B2G 程序居中協調。

-

僅透過 Web API 才能存取硬體

-

Web App 若要存取行動電話的功能,唯一管道只有以 Gecko 所建構的 Firefox OS Web API 。Gecko 是行動裝置與底層服務的單一出口,因此必須讓 Web API 進行呼叫作業,才能存取裝置的硬體功能。絕對沒有「原生 (Native)」的 API 或其他途徑可繞過此機制,而直接存取硬體或滲透至初階的軟體層。

-

 

-

安全架構

-

下圖則為安全架構的元件:

-

- -

 

-

許可的管理與強化

-

針對 Web App 所需的許可 (Permission),Firefox OS 安全機制將進一步驗證並強化。
- 僅當內容 (Content) 請求特殊許可,或當內容具備 manifest 所要求的適當許可時,系統才會發出特定許可至 App。若需要使用者進一步的授權,則某些許可亦將提出請求 (例如 App 要存取使用者目前的位置)。與傳統「角色為中心 (Role-centric)」的方式 (各個獨立角色將獲得一系列的許可)相較,這種「應用為中心 (app-centric)」的架構更能嚴密控管許可。

-

現有的 Web API 集合了一系列動作 (Action) 與接收器 (Listener)。各個 Web API 則具備必須的許可層級。每次只要呼叫 Web API,則 Gecko 檢查許可 (角色查找) 的基準為:

- -

若該請求並不符合許可的準則,則 Gecko 隨即拒絕該請求。舉例來說,只要是受信任 App 所保留的 Web API,未受信任的 App 均無法執行。

-

 

-

要求使用者給予許可

-

除了與 Web App 隱性關連 (Implicitly associated) 的許可之外,在執行特定作業之前需要使用者給予顯式許可。針對這些作業,Web App 必須在 manifest 檔案中表示索取許可的理由 (Justification)。這種「資料使用意圖 (Data usage intention)」,可讓使用者在給予許可之後,知道 Web App 處理資料的方式,亦將了解可能的風險,進而能做出決定並控管自己的資料。

-

 

-

安全的 App 更新程序

-

-

針對 Privileged app 的升級與修正,開發/供應商必須將更新封裝提交至授權過的 Marketplace,以供 Marketplace 進一步審查。而在核准之後,隨即完成數位簽章並提供予使用者。在搭載 Firefox OS 的裝置上,亦可透過 App 更新公用程式 (暫譯 App Update Utility) 定期檢查 App 是否有可用的更新。若發現可用的更新,系統隨即會詢問使用者是否安裝。在行動裝置安裝更新檔案之前,必將驗證封裝的:

- -

透過適當且嚴格的檢查,可確保行動電話已正確套用了更新。
- 在開始更新程序之前,必須先下載完整的更新封裝至特定且安全的位置。安裝作業並不會覆寫任何使用者資料。

-

 

-

裝置安全性 (硬體)

-

行動裝置硬體的安全機制,一般均由 OEM 廠商所決定。舉例來說,OEM 廠商可能提供 SIM (Subscriber Identity Module) 卡的鎖定機制,另搭配 PUK (PIN Unlock Key) 密碼,以用於輸入錯誤 PIN 而遭鎖定的 SIM 卡。這部份需聯絡 OEM 廠商以了解細節。Firefox OS 則可讓使用者設定密碼與待機畫面,將於稍後說明。

-

 

-

資料安全性

-

使用者可將個人資料儲存於手機中,並可設定其隱私性,包含聯絡資訊、金融資訊 (銀行與信用卡細節)、密碼、行事曆等。Firefox OS 則針對惡意 App (竊取、挖掘、破壞私密資料) 而設計了防護機制。

-

 

-

密碼與待機畫面

-

Firefox OS 可供使用者設定行動電話的密碼,往後必須輸入正確密碼才能使用該行動電話。Firefox OS 另提供待機畫面的功能。只要設定特定時間內未使用行動電話,隨即顯示待機畫面。此時必須輸入密碼授權才能繼續使用手機。

-

 

-

隔離式 (Sandboxed) 資料

-

如之前所述,執行期間的 App 均進入隔離狀態。如此可避免 App 相互存取其內的資料;除非該筆資料已設為共享資料,且其他 App 擁有夠高的許可層級可存取之。

-

 

-

序列化 (Serialized) 資料

-

Web App 並無法直接讀寫檔案系統。相反的,僅能透過 Web API 而存取儲存媒體。Web API 另將透過 SQLite 資料庫居中協調,才能進一步讀取、寫入儲存媒體。不會直接以 I/O 進行存取作業。各個 App 均擁有自己的資料儲存媒體,將經過資料庫而序列化至磁碟中。

-

 

-

資料銷毀

-

一旦使用者取消安裝 App,則將刪除該 App 所有的相關資料,如 cookies、localStorage、Indexeddb 等。

-

 

-

隱私性

-

根據隱私權原則 (https://www.mozilla.org/privacy/),Mozilla 致力保護使用者隱私與資料,同時可參閱 Mozilla Manifesto (https://www.mozilla.org/about/manifesto.html)。而 Mozilla 的 Firefox Privacy Policy 則說明 Mozilla 將如何蒐集、利用 Mozilla Firefox 瀏覽器的使用者資訊,包含 Firefox 所傳送至網頁的資料、Mozilla 的資料保護方式、Mozilla 資料實務情況等。若要進一步了解相關細節,可參閱:

- -

在擬定 Firefox OS 的原則時,均將使用者資料的控制權交付給使用者本身。而使用者必須自己決定個人資訊的運用方法。Firefox OS 將提供下列功能:

- diff --git a/files/zh-tw/archive/b2g_os/security/system_security/index.html b/files/zh-tw/archive/b2g_os/security/system_security/index.html deleted file mode 100644 index edb0e64697..0000000000 --- a/files/zh-tw/archive/b2g_os/security/system_security/index.html +++ /dev/null @@ -1,376 +0,0 @@ ---- -title: 系統安全 -slug: Archive/B2G_OS/Security/System_security -translation_of: Archive/B2G_OS/Security/System_security ---- -
-

本文旨在提供 Firefox OS 系統安全模型概觀,說明系統是如何保持安全性與實施權限管理。

-
-

名詞解釋

-

在開始之前,有幾個名詞需要了解一下。

-
-
- 網頁應用程式 (Web application)
-
- 網頁應用程式 (web application, web app, open web app, moz app, application) 是運行在 Firefox OS (或其他支援平台)、用 HTML, JavaScript, 以及其他開源網頁技術所寫成的應用程式。所有 B2G 上使用者使用的應用程式都是網頁應用程式,例如撥號程式是一個 web app,但顯示在瀏覽中的網頁並不屬於網頁應用程式的範疇。
-
- b2g 程序 (b2g process)
-
- Firefox OS b2g process 通常會被叫做 "b2g" 或 "Gecko"。b2g 實際上是一個高權限 (root 權限) 應用程式,控制了所有 web app 對資源和硬體的存取。
-
- 內容程序 (Content process)
-
- b2g 產生的子程序,會和 b2g 溝通,代表了 web app。它擁有的權限較低 (一般使用者權限;受限的作業系統資源存取),透過 inter-process communication (IPC) 和 OS 核心溝通。
-
- IPDL
-
- Intercommunication Protocol Definition Language, 請參照 IPDL.
-
- AOSP
-
- Android Open Source Project.
-
- System call
-
- 一個介於使用者空間 (user space) 和核心 (kernel) 的溝通介面,使用者空間只能透過這個介面和核心溝通。
-
- DAC, MAC
-
- 使用者可設定的自主存取控制 (Discretionary Access Control) 和 系統強制的強制存取控制 (Mandatory Access Control)。
-
- FOTA
-
- 自動韌體更新機制 (Firmware Over The Air),透過無線網路"空中"更新韌體。
-
- MSU (Mozilla System Updater), MAR (Mozilla ARchive)
-
- 和 Firefox 桌面產品一樣的更新機制和檔案格式。
-
-

Firefox 作業系統安全模型目標與範疇

-

Firefox OS 安全模型的設計目標:

- -

下面將說明每一個目標以及 Firefox OS 如何達成個目標。

-

權限強制

-

應用程式安全模型描述了使用者如何直接或透過受信任第三方來授予應用程式權限,這些強制加諸於內容程序 (content process) 的權限是透過限制資源存取必須經過和核心程序 (core process) 之間的 IPC call。

- -

內容程序初始化

-

所有的 web app 都運行在低權限、分開的內容程序。當 web app 載入到一個特別的 {{HTMLElement("iframe")}} 型態: <iframe mozapp> 時 b2g 程序會啟動內容程序,這樣會將 web app 和其他內容隔離開來,而且和 web app 的 manifest 高度相關 (請參照 應用程式安全模型),內容程序會在一個稱為 "out of process" (OOP) 的容器裡啟動,這個 OOP 即是 plugin-container 程序,並且和桌面 Firefox 所用的 plugin-container 程序有著相似的原始碼。

-

風險

- -

實作

-

在 b2g 程序裡啟動

-

順序如下:

-
    -
  1. fork()
  2. -
  3. setuid(new, different, unused user id|nobody) (無特權的使用者)
  4. -
  5. chrdir('/')
  6. -
  7. execve('plugin-container')
  8. -
-

這邊的啟動順序確保 OOP 程序運行在隔離的記憶體空間,同時只是低權限使用者,無法提高到 b2g 的高權限。

-

File descriptor (檔案描述子) 管理

-

File descriptors 的管理方法是白名單;一份受允許的 file descriptors (FDs) 清單儲存在 mFileMap 物件,在呼叫 fork() 後 (FDs 複製前) 和呼叫 execve()前 (新 web app 開始運行),LaunchApp() 函數會強制關閉不在白名單上的 FD。

-

不同於傳統的黑名單作法 (close-on-exec flag: CLOEXEC),這種做法確保不會有多餘的開啟 FD,比較可靠。

-

Content process sandboxing (沙箱,低權限內容程序)

-

風險

- -

下表為 sandbox 開啟下可能的威脅列表,附帶前述的可能風險。

-
-

範疇: 當攻擊者以內容程序執行意外執行碼時,會出現下面的威脅,也就是說,攻擊者發現了 Gecko 的安全漏洞。

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
威脅潛在衝擊可能性因子建議對應作法
-

惡意內容程序利用核心安全漏洞

-

"2 steps attack".

-
嚴重:整個裝置都將受到控制: 內容程序只有有限的方法呼叫系統。 -
    -
  • 減少允許的系統呼叫數量到最低需要量。
  • -
  • 用預防性修正檔保護核心,例如 PaX (Protection Against eXecution).
  • -
-
-

提升到父程序權限

-

惡意內容程序利用和父程序之間的 IPDL 安全漏洞

-

"2 steps attack".

-
: 許多敏感的系統呼叫都可以被執行 (資料損失、相機存取、網路存取等等): 父程序大量的程式碼代表大範圍的可能攻擊點。少量的 IPDL 資料消毒,例如傳送指標。 -
    -
  • 以非 root / 非特權使用者執行父程序
  • -
  • 盡可能以 sandbox 方法執行父程序
  • -
-
-

惡意內容程序利用父程序攻擊核心安全漏洞

-

"3 steps attack".

-
嚴重:整個裝置都將受到控制 -

: 需要父程序有可以透過 IPDL 攻擊的 bug。

-

需要核心和父程序之間的系統呼叫可利用的漏洞 (相較內容程序,父程序有更多可行的系統呼叫)

-
-
    -
  • 以非 root / 非特權使用者執行父程序
  • -
  • 盡可能以 sandbox 方法執行父程序
  • -
  • 用預防性修正檔保護核心,例如 PaX (Protection Against eXecution)
  • -
-
-

惡意內容程序、父程序、web app 利用硬體裝置的 bug

-

"1 and 2 steps attack".

-
-

: 可以執行特別權限的作業 (如撥號、傳 SMS 簡訊等)

-

嚴重:整個裝置都將受到控制或執行硬體程式碼。

-
: 需要硬體 bug 以及 IPDL 或系統呼叫授予的硬體溝通管道 -
    -
  • 對硬體裝置實施模糊測試 (Fuzz testing)
  • -
  • 利用核心或父程序 API 修正檔避開問題 (關閉不安全的硬體功能、消毒資料等等)
  • -
-
-
-

Note:

-

* PaX (Protection Against eXecution) 是一個由 GrSecurity (docs) 所發佈的核心修正檔,實作了 PaX 以及額外的保護措施,如 UDEREF 和 SMAP。

-

* 未列出的安全性漏洞代表已被 snadbox 解決掉了。

-
-

實作內容

-

Process Model Sandbox

-
-

Note: 內容程序 (Content Processes) 就是運行中的 web app,也會被限制在 sandbox 環境。

-
-

Gecko APIs 實作

-

內容程序可見的 APIs 絕不應該直接存取檔案系統,取而代的是應該透過 IPDL,所以說會需要存取資源的 API 都需要在父程序中有一個對應的元件代表 API 存取資源。

-

實作相關部分時要特別小心,所有送到父程序的輸入都應該要先消毒,不可以相信內容程序以及來自內容程序的 IPDL 訊息。

-
-

Warning: 任何內容程序取得的受信任授權都可以被用來繞過 sandbox 所加諸的限制。

-
-

何謂 seccomp

-

Seccomp 代表 secure computing mode (安全電腦模式),目前有兩種版本:

-
    -
  1. -

    seccomp, 可見於 Linux kernel 2.6.12 以上版本:

    -
      -
    • -

      開啟 seccomp 會將程序的系統呼叫 (System call) 限制在 read, write, sigreturn, 和 exit

      -
    • -
    • -

      使用 prctl() system call

      -
    • -
    • -

      可以在指定地方、程序初始化後啟動

      -
    • -
    -
  2. -
  3. -

    seccomp-bpf, 又稱為 seccomp mode filter 或 mode 2, 可見於 Linux kernel 3.5 以上版本:

    -
      -
    • -

      如同 seccomp,但多了 BPF 過濾系統呼叫

      -
    • -
    • -

      可以使用系統呼叫白名單和啟動時傳入參數,而非單單預先寫死的作法

      -
    • -
    • -

      更有彈性,可以有"較多自由的 sandbox",對限制性較低的 sandbox 來說很有用,而且也可以移轉到限制性較高的 sandbox

      -
    • -
    • -

      多了一個安全性旗幟避免程序和子程序推翻既有權限限制

      -
    • -
    -
  4. -
-
-

Note: 基於 seccomp-bpf 更有彈性,所以我們決定採用,並且替版本低於3.5 的 kernel (涵蓋了目前大部分的 Android kernel)提供向下相容移植。目前已經有不會造成衝突、可供使用的移植包 (請見 bug 790923).

-
-

Seccomp-bpf 效能

-

seccomp-bpf 會對每一次系統呼叫造成效能負擔,目前沒有一定的效能標竿準則,但我們預估大約最高 1% 的系統呼叫負擔會產生。

-

由於我們的程序模型減少許多系統呼叫,所以實際上我們預估效能負擔將會趨近於無。

-

不過因實作細節而異, IPDL 呼叫卻可能造成效能負擔以及增加延遲,建議對於資源需求密集的 API,如 OpenGL 呼叫,可以看一下 Chromium的實作細節。和 seccomp-bpf 一樣,我們能夠最少化 IPDL 呼叫次數來最小化效能負擔。

-

實作內容

-

seccomp 在 Gecko 以 --enable-content-sandbox 開啟。.

-

預設上系統呼叫拒絕資訊不會被回報,我們可以透過 --enable-content-sandbox-reporter 打開回報機制。

-

程式碼放在 gecko/security/sandbox,白名單放在 gecko/security/sandbox/seccomp_filter.h

-

檔案系統安全強化

-

風險

- -

實作內容

-

原則上只有使用者內容區域可以讀寫 (除非 OS 未來要求新的讀寫區域),而且一定要包含 nodevnosuidnoexec 選項。標準檔案系統掛載點限制如下:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
掛載點檔案系統選項
/rootfsread-only
/devtmpfsread-write, nosuid, noexec, mode=0755
/dev/ptsptsfsread-write, nosuid, noexec, mode=0600
/procprocread-write, nosuid, nodev, noexec
/syssysfsread-write, nosuid, nodev, noexec
/cacheyaffs2 or ext4read-write, nosuid, nodev, noexec
/efsyaffs2 or ext4read-write, nosuid, nodev, noexec
/systemext4read-only, nodev
/dataext4read-write, nosuid, nodev, noexec
/mnt/sdcardext4 or vfatread-write, nosuid, nodev, noexec, uid=1000, fmask=0702, dmask=0702
/acctcgroupread-write, nosuid, nodev, noexec
/dev/cpuctlcgroupread-write, nosuid, nodev, noexec
-
-

Note: 實際的掛載點可能有所變更

-
-

Linux DAC

-

Linux DAC represents 是一個有名的 Linux 檔案系統權限模型。

-
-

Note: 這是傳統的 user/group/others 權限模型,而非 Linux POSIX 1.e ACLs.

-
- -

安全系統更新

-

風險

- -

實作內容

-

Firefox OS 的更新機制使用安全的 Mozilla 程序,更新檔是由受信任,通常是 OEM 廠商,組建、測試、簽署數位簽章。

-

FOTA (Firmware over the air) 更新

-

系統更新可能涵蓋全部或部分 Firefox OS,如果更新涵蓋到 Gonk,那麼 FOTA (Firmware Over the Air) 安裝程序會被採用。FOTA 也可涵蓋到 OS 其他部分,例如裝置管理 (FOTA, firmware / drivers)、設定管理 (Firefox OS settings)、安全更新、Gaia、Gecko 等等。

-

MSU/MAR 更新

-

不牽涉到 Gonk 的更新可以透過 Mozilla 系統更新工具。Firefox OS 使用和桌面 FIrefox 一樣的更新架構、程序 Mozilla ARchive (MAR) 格式 (用於更新包)。

-

更新服務

-
-

Note: 更新服務能由 OEM 廠商提供。

-
-

手機內建的更新系統會定期檢查更新,一但發現新更新,會提示使用者安裝更新,另外安裝前也會檢查手機儲存空間以及驗證發行者身分:

- -

下列安全性作法會用在更新程序:

- -

縝密的更新檢查確保正常地安裝更新。

-
-

Note: 更多有關更新資訊,請見 Creating and applying Firefox OS update packages.

-
-

 

diff --git a/files/zh-tw/archive/b2g_os/simulator/index.html b/files/zh-tw/archive/b2g_os/simulator/index.html deleted file mode 100644 index 3b5677a518..0000000000 --- a/files/zh-tw/archive/b2g_os/simulator/index.html +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: Firefox OS 模擬器 -slug: Archive/B2G_OS/Simulator -translation_of: Archive/B2G_OS/Simulator ---- -
-

本文將針對 Firefox OS 1.2 或更高版本,說明 Firefox OS 模擬器 (Firefox OS Simulator) 相關使用方式。如果開發者目前正開發 Firefox OS 1.1 的 App,則請參閱 Firefox OS 1.1 Simulator 的相關文章。

-
- -

Firefox OS 模擬器可於桌機中模擬 Firefox OS 裝置。開發者不用真的弄到實際設備就能夠測試 App 並進行除錯。模擬器會在視窗中以 Firefox OS 裝置的實際尺寸執行,亦包含 Firefox OS 使用者介面與已內建的 App,進而模擬多樣的 Firefox OS 裝置 API。

- -

Firefox OS 模擬器是以 Firefox 附加元件的格式發佈,可下載並安裝於 Firefox 瀏覽器之上,接著可透過應用程式管理員 (App Manager) 來執行模擬器、將 App 送入模擬器、搭配其他開發者工具。

- -

安裝

- -

直接點擊下方按鈕即可安裝模擬器。現有多個版本可供安裝。我們也建議開發者能安裝所有版本,以達最佳開發靈活度。

- -

安裝 Firefox OS Simulator

- -

另請參閱《應用程式管理員》中的說明來啟動模擬器。一旦模擬器開始執行,開發者即可將 App 送入應用程式管理員進行除錯;就如同使用實際裝置一樣。

- -
-

注意:模擬器 (1.2 與 1.3 版) 目前正回報 1 組錯誤的 Gecko user agent 字串:請參閱 {{ Bug("964598") }} 進一步了解。

-
- -

模擬器的使用者介面 (UI)

- -

模擬器將另外顯示獨立的視窗,且模擬畫面則為 320x480 像素。若要模擬觸控事件,則可按下滑鼠按鈕不放並拖曳。只要在主畫面上按下滑鼠不放並從右向左拖曳,即可看到已內建的 App,還有開發者剛送入的 App:

- -

- -

在模擬器視窗底部的工具列共有 2 個按鈕:

- - - -

模擬器的限制

- -

請注意,Firefox OS 模擬器仍無法提供完美的模擬作業。

- -

硬體限制

- -

模擬器除了螢幕尺寸的限制之外,也無法模擬 Firefox OS 裝置的硬體 (例如 CPU 速度或可用的記憶體容量)。

- -

音訊/視訊編碼

- -

下列編碼 (Codecs) 因硬體加速解碼而有所不同,因此尚未支援:

- - - -

也就是說,若 App 或網站 (如 Youtube) 使用這些編碼,則模擬器將無法測試其中的視訊回播功能。

- -

未支援的 API

- -

一般來說,因為桌上型電腦無法使用支援硬體,所以可於裝置上運作的特定 API,可能無法用於模擬器之上。我們另外針對某些 API (例如 Geolocation 地理位置定位) 建構了模擬功能,未來版本亦將新增更多模擬 API。但目前仍尚未支援下列 API。如果使用了這些 API,也只會得到錯誤的報告或結果:

- - - -

獲得協助

- -

如果有任何問題,請透過 dev-developer-tools 郵件群組或到 #devtools on irc.mozilla.org 上發問。

- -

啟動詳細資訊 (verbose) 記錄的方法

- -

開發者可到網頁主控台 (Web Console) 觀看 App 的記錄訊息,並透過應用程式管理員將記錄附加到 App 上。如果想知道 App 啟動時的早期訊息,甚至早於主控台連線並開始作業的訊息,則開發者可啟動模擬器中的詳細資訊記錄功能。

- -

可透過 about:config 並建立新的 preference 設定。依照模擬器的版本,preference 的名稱也有所差異:

- - - -

針對「附加元件管理員 (Add-on Manager)」中的附加元件,可將字串值設為「all」、停用,再啟用。目前有關模擬器作業的額外訊息,均將出現於瀏覽器主控台 (Browser Console) 中。

diff --git a/files/zh-tw/archive/b2g_os/simulator/simulator_walkthrough/index.html b/files/zh-tw/archive/b2g_os/simulator/simulator_walkthrough/index.html deleted file mode 100644 index 9e7fba8c07..0000000000 --- a/files/zh-tw/archive/b2g_os/simulator/simulator_walkthrough/index.html +++ /dev/null @@ -1,268 +0,0 @@ ---- -title: Firefox OS 模擬器簡易攻略 -slug: Archive/B2G_OS/Simulator/Simulator_Walkthrough -translation_of: Archive/B2G_OS/Simulator/Simulator_Walkthrough ---- -

這裡將透過 Firefox OS 模擬器 (Firefox OS Simulator) 對 Web Apps 進行很簡單的除錯 (但要找的 bug 有點多)。

-

整個簡易攻略分成 6 個部分,各自使用不同的診斷/除錯工具,包含 manifest 檢驗功能網頁主控台 (Web Console)JavaScript 除錯器 (JavaScript Debugger)網路監測器 (Network Monitor)樣式編輯器 (Style Editor)收據 (Receipts) 測試

-

這 6 個部分各自獨立。就算你只挑其中幾段來看,應該也能看得懂而不會有銜接上的問題。

-

manifest 檢驗功能

-
-

GitHub 上的 firefoxos-simulator-walkthrough 現有不同版本的 App。如果你想從第一段開始了解 App 的修正程序,可從 App 的 whereami-1 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator),並開啟了 Dashboard。

-
-

首先我們點選「Add Directory」,將 App 新增至 Dashboard 中,再選擇 manifest 檔案。畫面如下:

-


-
- 點選「(2 errors and 0 warnings)」就會看到:

-


- 畫面將清楚顯示錯誤訊息。此時看到「manifest.webapp」就會發現少了 1 組「name」:

-
{
-  "description": "A simple web app",
-  "launch_path": "/index.html",
-  "icons": {
-    "128": "/style/icons/earth.png"
-  }
-}
-


- 我們把「name」欄位加入 manifest 檔案之後儲存,再點選 Dashboard 中的「Refresh」:

-
{
-  "name": "Where am I?",
-  "description": "A simple web app",
-  "launch_path": "/index.html",
-  "icons": {
-    "128": "/style/icons/earth.png"
-  }
-}
-


- 此時 Dashboard 應該會告知沒有錯誤,也就能執行 App:

-

-

但這時就算你按下按鈕,模擬器也不會有任何動作。我們會在下一段中使用 WebConsole 診斷此問題。

-

使用網頁主控台 (Web Console)

-
-

如果你要從這裡開始研讀攻略:

-

這一段將透過 Firefox OS 模擬器 (Firefox OS Simulator),對很簡單的 Web App 進行除錯。GitHub 上的 firefoxos-simulator-walkthrough 已有不同版本的 App。如果你想從本段開始了解 App 的修正程序,可從 App 的 whereami-2 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

但此版本的 App 不會執行任何作業。本段透過 WebConsole 診斷出問題。

- 此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator)、開啟 Dashboard、點選 Dashboard 中的「Add Directory」而新增了 App,並點選 App 的「manifest.webapp」檔案。
-

這裡必須按下 Dashboard 上的「Connect」按鈕:

-

-

隨即自動開啟模擬器視窗並執行 App。而 Dashboard 分頁另將出現網頁主控台 (WebConsole)。

-

主控台的輸出結果會提示幾項錯誤、警告、訊息。但請注意最後一項:
-
-
-
- 看來是 App 的程式碼「whereami.js」明顯出了問題。這裡列出程式碼的前幾行:

-
var whereami = document.getElementById('whereami');
-
-whereami.onclick = function() {
-  navigator.geolocation.getCurrentPosition(getMap, error);
-};
-


- 若與 App 的「index.html」相較,則問題明顯是:

-
<!DOCTYPE html>
-
-<html>
-
-  <head>
-    <meta charset='utf-8'>
-    <script src="http://open.mapquestap.com/sdk/js/v7.0.s/mqa.toolkit.js"></script>
-    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
-
-  </head>
-
-  <body>
-    <button id ="where-am-i">Where am I?</button>
-    <div id="map"></div>
-    <script src="scripts/whereami.js"></script>
-    <link media="all" href="style/style.css" type="text/css" rel="stylesheet">
-  </body>
-
-</html>
-


- 在 HTML 中的按鈕 ID 是「where-am-i」,而不是我們在前面 JavaScript 中所使用的「whereami」。所以我們修改為:

-
var whereami = document.getElementById('where-am-i');
-
-whereami.onclick = function() {
-  navigator.geolocation.getCurrentPosition(getMap, error);
-};
-

接著啟動 App 時雖然沒有問題,但仍未顯示地圖。這時主控台又出現新的訊息:

-

-

此訊息是由「whereami.js」程式碼所記錄,指出 Geolocation API 回傳了錯誤,卻沒有說明是哪種錯誤。接著我們可用 JavaScript 除錯器 (JavaScript Debugger) 找出錯誤類型。

-

使用 JavaScript 除錯器 (JavaScript Debugger)

-
-

如果你要從這裡開始研讀攻略:

-

這一段將透過 Firefox OS 模擬器 (Firefox OS Simulator),對很簡單的 Web App 進行除錯。GitHub 上的 firefoxos-simulator-walkthrough 已有不同版本的 App。如果你想從本段開始了解 App 的修正程序,可從 App 的 whereami-3 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

此版本 App 的 Geolocation API 將回傳錯誤。所以本段將透過 JavaScript 除錯器 (JavaScript Debugger) 找出到底是哪種問題。

-

此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator)、開啟 Dashboard、點選 Dashboard 中的「Add Directory」而新增了 App,並點選 App 的「manifest.webapp」檔案。

-
-

在連上 App 的網頁主控台 (WebConsole) 中,點選 Geolocation 錯誤記錄的右側鏈結:

-


- 按下「whereami.js:8」鏈結之後,JavaScript 除錯器隨即自動載入相關檔案並跳到有問題的行數。

-

根據這篇 Geolocation API 參考所述,這裡將由錯誤處理器 (Error handler) 的 error() 屬性送入 code 物件,而我們再透過 error 物件的 code 屬性獲知此特定錯誤的詳細資訊。所以我們點選左側行數為 8 的那一行,即可於 error() 之內設定中斷點:

-

-

在 App 之內點選「Where am I?」之後,執行作業就會停在中斷點:

-

-

此時只要按下「Add watch expression」的地方並鍵入「error.code」,就會立刻看到其值為「1」:

-


- 同樣根據 Geolocation API 參考文件所述,「1」即代表「權限已遭否決」。如果 Web Apps 尚未請求 Geolocation 權限,或使用者尚未許可該權限,都會發生這種錯誤。
-
- 這時來看「manifest.webapp」檔案,就會看到我們尚未要求權限:

-
{
-  "name": "Where am I?",
-  "description": "A simple web app",
-  "launch_path": "/index.html",
-  "icons": {
-    "128": "/style/icons/earth.png"
-  }
-}
-


- 接著修復如下:

-
{
-  "name": "Where am I?",
-  "description": "A simple web app",
-  "launch_path": "/index.html",
-  "icons": {
-    "128": "/style/icons/earth.png"
-  },
-  "permissions": {
-    "geolocation": {
-      "description": "Needed to tell the user where they are"
-      }
-  }
-}
-


- 儲存「manifest.webapp」之後,再按下 Dashboard 中的「Refresh」。這裡記得要在除錯器停在中斷點時,才能繼續除錯。而當你點選「Where am I?」,App 隨即會要求你分享你的位置。而你允許分享之後仍看不到地圖,接著又在 WebConsole 中找到新的訊息:

-

-

此訊息指出 MapQuest API (在 App 中以 script 標籤所指定) 並未正確載入。接著可使用網路監測器 (Network Monitor) 找出問題。

-

使用網路監測器 (Network Monitor)

-
-

如果你要從這裡開始研讀攻略:

-

這一段將透過 Firefox OS 模擬器 (Firefox OS Simulator),對很簡單的 Web App 進行除錯。GitHub 上的 firefoxos-simulator-walkthrough 已有不同版本的 App。如果你想從本段開始了解 App 的修正程序,可從 App 的 whereami-4 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

此版本 App 的網頁主控台 (WebConsole) 將顯示「MQA is not defined」錯誤。所以本段將透過網路監測器 (Network Monitor) 找出未載入 MapQuest API 的原因。

-

此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator)、開啟 Dashboard、點選 Dashboard 中的「Add Directory」而新增了 App,並點選 App 的「manifest.webapp」檔案。

-
-
-

警告:需 Firefox 23.0 或更高版本才具備網路監測器功能。

-
-

在連上 App 的開發者工具中,點選「Network」分頁就會看到下列面板。可以看到「open.mapquestap.com」網域針對「mqa.toolkit.js」資源所發出的請求,從未完全成功過:

-

-

成功的請求均標記為綠色。如果我們點選「open.mapquestap.com網域 (深灰色) 的請求之一,點選「Timings」的細節面板,就會看到 DNS 解析 (DNS resolution) 並未成功,因此該請求從未達到「Connecting」的狀態。

-

再看到「index.html」檔案,會發現 script 標籤指向錯誤網域。

-

這裡變更 script 標籤以使用正確的網域:open.mapquestapi.com (於網域名稱內加入缺少的「i」) 之後,即可修復此錯誤。

-
<!DOCTYPE html>
-
-<html>
-
-  <head>
-    <meta charset='utf-8'>
-    <script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"></script>
-    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
-
-  </head>
-
-  <body>
-    <button id ="where-am-i">Where am I?</button>
-    <div id="map"></div>
-    <script src="scripts/whereami.js"></script>
-    <link media="all" href="style/style.css" type="text/css" rel="stylesheet">
-  </body>
-
-</html>
-

儲存「index.html」並點選 Dashboard 中的「Refresh」。在 App 執行時按下「Where am I?」,系統就會要求你分享你的位置。在你允許分享之後,App 終於顯示地圖:
-

-

使用樣式編輯器 (Style Editor)

-
-

如果你要從這裡開始研讀攻略:

-

這一段將透過 Firefox OS 模擬器 (Firefox OS Simulator) 客製化 App 的樣式表 (Stylesheets)。 GitHub 上的 firefoxos-simulator-walkthrough 已有不同版本的 App。如果你想從本段開始了解 App 的修正程序,可從 App 的 whereami-5 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要使用者點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

此版本的 App 已修復前述的所有錯誤。接著我們將透過樣式編輯器 (Style Editor),為執行中的 App 即時變更樣式並儲存之。

-

此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator)、開啟 Dashboard、點選 Dashboard 中的「Add Directory」而新增了 App,並點選 App 的「manifest.webapp」檔案。

-
-
-

警告:必須 Firefox 23.0 或更高版本才具備網路監測器 (目前 Firefox Beta 試用版才是 23.0 版)

-
-

在連上 App 的開發者工具中,點選「Style Editor」分頁就會看到下列面板:

-

-

點選左側樣式表清單中的「style/style.css」,並修改 CSS 規則。新的規則會立刻套用至已連線的 App 上:

-

-

現在點選樣式表「style/style.css」正下方的「Save」,即可將之儲存回專案中。

-

使用收據 (Receipts) 測試功能

-
-

如果你要從這裡開始研讀攻略:

-

這一段將透過 Firefox OS 模擬器 (Firefox OS Simulator),為 Web App 新增付款收據驗證碼。GitHub 上的 firefoxos-simulator-walkthrough 已有不同版本的 App。如果你想從本段開始了解 App 的修正程序,可從 App 的 whereami-6 版本著手,逐步完成此攻略。

-

這個 App 只會顯示 1 個「Where am I?」按鈕。只要點擊按鈕,則 App 就會透過 Geolocation API 取得使用者目前的位置,並於地圖上顯示。

-

我們要把此版本 App 變更為付費 Web App。

-

此處假設你已經安裝了 Firefox OS 模擬器 (Firefox OS Simulator)、開啟 Dashboard、點選 Dashboard 中的「Add Directory」而新增了 App,並點選 App 的「manifest.webapp」檔案。

-
-

目前你已經將 App 修改為無錯誤的 App,並已擁有合適的樣式。現在可新增付款收據驗證 (Payment Receipt Validation) 功能,確保使用者必須購買此 App。

-

Mozilla 另已提供小型的 JavaScript 函式庫,可協助 Apps 檢查自己的收據:http://github.com/mozilla/receiptverifier

-

為 App 新增 receiptverifier (把新的 script 標籤加入「index.html」檔案中):

-
<!DOCTYPE html>
-
-<html>
-
-  <head>
-    <meta charset='utf-8'>
-    <script src="https://raw.github.com/mozilla/receiptverifier/master/receiptverifier.js"></script>
-    <script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js"></script>
-    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
-
-  </head>
-
-  <body>
-    <button id ="where-am-i">Where am I?</button>
-    <div id="map"></div>
-    <script src="scripts/whereami.js"></script>
-    <link media="all" href="style/style.css" type="text/css" rel="stylesheet">
-  </body>
-
-</html>
-

接著再以「mozmarket.receipts.Verifier」API 檢查「scripts/whereami.js」中的收據 (將於按下按鈕,或於載入 App 時檢查收據):

-
...
-
-var verifier = new mozmarket.receipts.Verifier({
-  installs_allowed_from: '*',
-  typsAllowed: 'test-receipt',
-  logLevel: mozmarket.receipts.Verifier.levels.DEBUG,
-  onlog: mozmarket.receipts.Verifier.consoleLogger
-});
-verifier.clearCache();
-
-function verifyPaymentReceipts(cb) {
-  verifier.verify(function (verifier) {
-    if (verifier.state instanceof verifier.states.OK) {
-      cb(null); // valid payment
-    } else {
-      cb("invalid-payment"); // invalid payment
-    }
-  });
-  setTimeout(function checkNoReceipts() {
-    if (verifier.state instanceof verifier.states.NoReceipts) {
-      cb("no-receipts");
-    }
-  }, 2000);
-}
-
-whereami.onclick = function() {
-  verifyPaymentReceipts(function (err) {
-    if (err) {
-      alert("Invalid Payment Receipt.");
-    } else {
-      navigator.geolocation.getCurrentPosition(getMap, error);
-    }
-  });
-};
-
-

正常情況需透過 Marketplace 與 Payment 服務,以加密方式簽署收據。但目前可先用模擬器 App 項目中的「Receipts」選單,點選所要安裝的收據類型 (預設為「None」),即可為 App 安裝測試收據。

-

-

現在即可測試 App 具備「Valid」、「Invalid」、「Refunded」收據,或無收據時的行為。另可於網頁主控台觀看「receiptverifier」函式庫所產生的記錄,藉以了解相關結果:

-

-

-
-

注意:whereami-7 版本即為最終完成的 App。

-
-

 

diff --git a/files/zh-tw/archive/b2g_os/using_the_app_manager/index.html b/files/zh-tw/archive/b2g_os/using_the_app_manager/index.html deleted file mode 100644 index 8486eeb959..0000000000 --- a/files/zh-tw/archive/b2g_os/using_the_app_manager/index.html +++ /dev/null @@ -1,259 +0,0 @@ ---- -title: 應用程式管理員 (App Manager) -slug: Archive/B2G_OS/Using_the_App_Manager -translation_of: Archive/B2G_OS/Using_the_App_Manager ---- -
-

「應用程式管理員 (App Manager)」為 Firefox 桌面版的新工具,具備多樣的有效工具,可透過開發者的瀏覽器,直接於 Firefox OS 手機與 Firefox OS 模擬器 (Firefox OS Simulator) 中進行 HTML5 Web App 的測試、佈署、除錯等作業。

- -

應用程式管理員適用於 Firefox OS 1.2 或更高版本。如果你正為 Firefox OS 1.1 開發 App,則請參閱《Firefox OS 1.1 Simulator》一文。

-
- -

{{EmbedYouTube("z1Bxg1UJVf0")}}

- -

應用程式管理員具備下列元件:

- - - -

快速設定:

- -

本段將協助開發者儘快設定並執行應用程式管理員。如果你需要進一步詳細資訊,則請略過本段文章而直接觀看下一段《裝置與系統設定》。若發生任何問題,亦可參閱本文最後一段《疑難排解》。

- -
    -
  1. 確認已安裝桌面版 Firefox 26 或更高版本
  2. -
  3. 開啟應用程式管理員 (可於網址列中鍵入 about:app-manager)
  4. -
  5. 若你手上並沒有實際的 Firefox OS 裝置: -
      -
    1. 先安裝 Firefox OS 模擬器 (Firefox OS Simulator)
    2. -
    3. 在應用程式管理員底部的工具列中,點選 Start Simulator 再點選已安裝的模擬器名稱 (已安裝的模擬器均應出現)。
    4. -
    -
  6. -
  7. 若你擁有 Firefox OS 實體裝置: -
      -
    1. 確認目前為 Firefox OS 1.2 或更高版本
    2. -
    3. 確認已在視窗系統中安裝該款手機的驅動程式
    4. -
    5. 進入裝置的「Settings」,停用「Screen Lock (Settings > Screen Lock)」並啟用「Remote Debugging (Settings > Device information > More information > Developer)」
    6. -
    7. 另為 Firefox 桌面版安裝 ADB Helper 附加元件
    8. -
    9. 使用 USB 纜線銜接裝置與電腦
    10. -
    11. 接著應可於應用程式管理員的底部看到裝置名稱,點選該裝置
    12. -
    -
  8. -
  9. 底部應顯示「Connected to: xxx」
  10. -
  11. 點選 Apps panel 並新增 App;封裝式 (Packaged) 或托管式 (Hosted) App 均可
  12. -
  13. Refresh 按鈕將驗證該 App 並安裝於裝置/模擬器中
  14. -
  15. Debug 按鈕則銜接開發者工具與執行中的 App
  16. -
  17. 若遇上任何錯誤,可參閱〈疑難排解〉章節
  18. -
- -

裝置與系統設定

- -

使用應用程式管理員前的第一件事,就是必須正確設定現有的系統與手機。本段將逐步說明各個步驟。

- -

需要 Firefox 1.2 或更高版本

- -

確認裝置目前為 Firefox OS 1.2/Boot2Gecko 1.2 或更高版本。若要檢查目前 Firefox OS 版本,可點選 Settings > Device Information > Software

- -

如果尚未安裝必要的 Firefox OS 版本,則根據手機型號的不同,你可能必須安裝 Firefox 1.2 或更高的 nightly 版本,或自行透過原始碼進行設定與建置 (Build)。

- -

目前可用的建置:

- - - -

若要建構自己的 Firefox OS 1.2 或更高版本,請參閱 Building and installing Firefox OS 說明,並從 Firefox OS build prerequisites 著手開始。

- -

遠端除錯 (Remote debugging)

- -

接著必須啟動 Firefox OS 中的遠端除錯 (Remote debugging) 功能。點選Settings > Device information > More information > Developer,最後勾選 Remote Debugging 方塊即可。

- -

ADB 或 ADB helper

- -

透過 Android Debug Bridge (ADB) 處理裝置與電腦之間的連線作業。現有 2 種 ADB 執行方式:

- - - -
-

注意:只要安裝 ADB Helper 附加元件,就不需執行此指令。

-
- -

將裝置連上應用程式管理員

- -

完成所有設定之後,就可將裝置連上電腦並啟動應用程式管理員:

- -
    -
  1. 以 USB 纜線銜接裝置與電腦。
  2. -
  3. 進入 Settings > Screen Lock 並取消勾選 Lock Screen,以停用裝置的螢幕鎖定功能。一旦螢幕鎖定之後,手機與電腦的連線將隨之中斷,也就無法進行除錯作業。因此最好先停用此功能。
  4. -
  5. 啟動應用程式管理員 — 到 Firefox 桌面版中點選「工具 (Tools)」>「網頁開發者 (Web Developer)」>「應用程式管理員 (App Manager)」選單;或於網址列中鍵入 about:app-manager
  6. -
  7. 應用程式管理員分頁的底部可看到連線狀態顯示列 (如下圖所示)。只要點選「Connect to localhost:6000」按鈕即可連線裝置。
  8. -
  9. 若連線成功,裝置畫面隨即出現「An incoming request to permit remote debugging connection was detected. Allow connection?」對話框。按下「OK」鈕 (你可能必須按下手機的電源鍵,才會看到該對話框)。接著應會更新連線狀態列並顯示「Connected to B2G」。此時也將出現「Disconnect」按鈕,以利隨時中斷連線。
  10. -
- -

- -
-

另請注意,位於連線狀態列中的其他控制鈕,可讓你銜接模擬器與應用程式管理員 (將於下一段中說明),並更改連線所使用的通訊埠。若要更改通訊埠,則必須啟動該通訊埠的「轉發通訊埠 (Port forwarding)」功能。可參閱上述的啟動轉發通訊埠

-
- -

使用 Firefox OS Simulator 附加元件

- -

如果你手上還沒有實際的 Firefox OS 裝置可搭配 App Manager,也能透過 Firefox OS 模擬器 (Firefox OS Simulator) 附加元件體驗應用程式管理員。請先為自己的作業系統安裝合適的模擬器:

- -

安裝 Firefox OS 模擬器

- -
-

注意:目前僅有 Firefox OS 1.2 模擬器。未來將提供更多版本選擇。

-
- -

安裝模擬器之後,請透過 about:app-manager 找到應用程式管理員分頁底部的連線狀態列,點選「Start simulator」按鈕。接著將出現至少 3 組按鈕:

- - - -
-

注意:模擬器 (1.2 與 1.3 版) 目前回報 1 組錯誤的 Gecko user agent 字串:可參閱 {{ Bug("964598") }} 進一步了解。

-
- -

「Apps」面板

- -

所有要件設定完畢之後,就從「Apps」面板開始了解應用程式管理員的功能吧。先透過 Apps 面板將現有 App 送入裝置中並進行除錯:

- - - -

視窗右側隨即顯示 App 的相關資訊,如下圖所示:

- -

- -

Manifest 檔案編輯器 (Manifest Editor)

- -

從 Firefox 28 開始,「Apps」面板即包含編輯器功能,可用於 App 的 manifest 檔案:

- -

- -

除錯

- -

此時點選「Update」就會更新 (或安裝) 裝置上的 App。點選「Debug」則會連上工具箱,以利直接對程式碼進行除錯:

- -

- -
-

注意:你可能會玩工具箱玩到上癮 — 快試著修改 DOM、CSS 等。接著就能看到裝置即時反應出更新的效果。相關更新均將儲存於已安裝的 App 程式碼中,下次再開啟裝置中的 App 就能一目了然。

-
- -

若是 Firefox 28 之前的版本,這些工具將顯示於另一個獨立視窗中。從 Firefox 28 開始,這些工具均顯示於應用程式管理員之內的獨立分頁中;就接在「Apps」與「Device」分頁之下。此分頁將顯示目前 App 的圖示,因此極容易辨識:

- -

- -

錯誤

- -

如果新增 App 失敗 (可能是 URL 錯誤,或選到了封裝式 App 的資料夾),則該頁仍會顯示所新增的 App 項目,也會包含錯誤資訊。

- -

- -

另外只要將滑鼠游標移至視窗左邊的 App 名稱/說明之上,在「X」按鈕出現時按下,即可在此畫面中刪除該 App。請注意此動作並不會刪除裝置中的 App。必須從裝置上手動移除 App,才會真正刪除裝置中的 App。

- -

「Device」面板

- -

「Device」面板將顯示已連線裝置的相關資訊。另可透過「Installed Apps」視窗中開啟裝置上的 App 並進行除錯。

- -

- -
-

注意:依預設值,此處並不會顯示 Certified App。可參閱 Certified App 的除錯方式

-
- -

「Permissions」視窗將針對目前裝置上的不同 Web API,顯示必要的權限。

- -

- -

最後可按下「Screenshot」按鈕,即可對目前裝置的顯示項目拍下截圖。此截圖將以 Firefox 的新分頁開啟,讓你決定是否要儲存該圖。

- -

Certified App 的除錯

- -

目前僅限搭載 Firefox OS 1.2 開發版本的裝置,才能進行 Certified Apps 的除錯。若你手上的裝置正執行開發版本,則可將設定檔中的「 devtools.debugger.forbid-certified-apps」變更為「false」,即可開始 Certified App 的除錯。可參閱下列步驟:

- -
    -
  1. -

    在電腦的終端/主控台上輸入下列指令,以進入裝置的 filesystem:

    - -
    adb shell
    - -

    接著命令列提示將轉為 root@android

    -
  2. -
  3. -

    接著以下列指令暫停執行 B2G:

    - -
    stop b2g
    -
  4. -
  5. -

    進入以下目錄:

    - -
    cd /data/b2g/mozilla/*.default/
    -
  6. -
  7. -

    以下列指令更改 prefs.js 檔案:

    - -
    echo 'user_pref("devtools.debugger.forbid-certified-apps", false);' >> prefs.js
    -
  8. -
  9. -

    在完成編輯並儲存檔案之後,再以下列指令重新啟動 B2G:

    - -
    start b2g
    -
  10. -
  11. -

    輸入 exit 指令以退出 Android 的 filesystem 之後,就會回到正常的終端畫面。

    -
  12. -
  13. -

    最後再次連回應用程式管理員,就能看到 Certified App 出現,即可進行除錯。

    -
  14. -
- -
-

注意:如果你想把這個偏好設定加入自己的 Gaia 版本,則可執行 DEVICE_DEBUG=1 reset-gaia

-
- -

在應用程式管理員中執行自訂的版本

- -

只要透過 Firefox OS 模擬器,即可於應用程式管理員中執行自訂的 B2G Desktop 與 Gaia 版本。可參閱《Running custom Firefox OS/Gaia builds in the App Manager》進一步了解。

- -

疑難排解

- -

如果系統無法辨認裝置:

- - - -

還是無法讓自己的裝置連上應用程式管理員或啟動模擬器嗎?快讓我們知道到 bugzilla 回報錯誤

diff --git a/files/zh-tw/archive/b2g_os/using_the_b2g_desktop_client/index.html b/files/zh-tw/archive/b2g_os/using_the_b2g_desktop_client/index.html deleted file mode 100644 index 46fc57a972..0000000000 --- a/files/zh-tw/archive/b2g_os/using_the_b2g_desktop_client/index.html +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: 使用 Firefox OS 的電腦桌面 client 程式 -slug: Archive/B2G_OS/Using_the_B2G_desktop_client -translation_of: Archive/B2G_OS/Building_the_B2G_OS_simulator ---- -

Firefox OS 的 desktop client,也被稱為 B2G desktop client,讓您可以在一個以 Gecko 為基礎的環境-有點類似實際行動裝置的環境下執行 Gaia 和 web apps。它不會模擬行動裝置的硬體,因此它並不適合拿來測試行動裝置的 API,也不能取代在實際硬體上的測試。然而,它的確擁有一些 Firefox 上所沒有 APIs,像是聯絡人(Contacts)和設定(Settings)的 Apis。因此,當我們在開發應用程式、或是在操作 Gaia 使用者介面上可以派上用場。

- -

這篇文章不但涵蓋下載或是建置 Firefox desktop client,也包含了如何使用它。

- -

下載 nightly 版本

- -

如同 Firefox Nightlies 一般,Firefox OS 的 desktop client 每天都會用最新的原始碼編譯出一個版本。最新的版本將 可以從 Mozilla FTP 伺服器取得。請確定挑到最新的版本和對的封存給您的作業系統。

- -

我們現在可以略過下面內容,直接到「執行 desktop client」。

- -

建置 desktop client

- -

我們需要做的地一件事情是架起 Mozilla 的標準建置環境。一旦我們有了這個環境,我們可以降低我們所需要的原始碼,並且設定建置 Firefox OS 的 desktop client。

- -

第一次下載原始碼

- -

在我們要放置程式碼的目錄(資料夾)中,讓我們將包含所有 Gecko 的 mozilla-central 倉儲 (repository)給複製下來。

- -
 hg clone http://hg.mozilla.org/mozilla-central
-
- -

更新程式碼

- -

當我們之後編譯後來的版本時,我們要確定我們有最新的原始碼。下列就是如何拉到最新的更新的指令:

- -
cd mozilla-central
-hg pull -u
-
- -

建立 mozconfig

- -

接著,我們要在 mozilla-central 目錄下新增一個檔案 mozconfig 來設定建置系統去編譯 Boot to Gecko client 程式而不是 Firefox:

- -
mk_add_options MOZ_OBJDIR=../build
-mk_add_options MOZ_MAKE_FLAGS="-j9 -s"
-
-ac_add_options --enable-application=b2g
-ac_add_options --disable-libjpeg-turbo
-
-# This option is required if you want to be able to run Gaia's tests
-ac_add_options --enable-tests
-
-# turn on mozTelephony/mozSms interfaces
-# Only turn this line on if you actually have a dev phone
-# you want to forward to. If you get crashes at startup,
-# make sure this line is commented.
-#ac_add_options --enable-b2g-ril
- -

建置(編譯)

- -

現在我們已經準備好要在目錄 mozilla-central 裡面、透過下面的指令來編譯 desktop client。

- -
./mach build
- -

編譯好的 client 會被放在 ../build/dist 目錄下 (基本上是依照 mozconfig 檔案裡面的 MOZ_OBJDIR 參數所指定的值)。

- -

執行 desktop client

- -

預設 desktop client 會顯示空的畫面,因為它並不知道一開始要載入哪個 web app 來當做系統 app。系統 apps 和 Firefox OS 中預設會有的 apps 就被稱為 Gaia。

- -

下載 Gaia

- -

第一次下載 Gaia、讓我們從 GitHub 上複製原始碼的倉儲 (repository):

- -
 git clone https://github.com/mozilla-b2g/gaia
- -

為了更新成 Gaia 的一個已存在的版本,我們可以從 GitHub 拉最新的更新:

- -
cd gaia
-git pull
-
- -

產生 profile

- -

接著我們需要設定 desktop client 中 Gaia 的 apps。這包括包裝行動裝置上也有的 Gaia apps,以及設定系統 apps 的權限。我們透過產生一個 profile 來做這些事情。接著的指令會做這些事情:新的 profile 包含一個客製的擴充以及其他 B2G 正常運作所需的設定。所以在 gaia 目錄裡執行下面的指令:

- -
cd gaia
-make
-
- -

這應該會在 gaia 目錄下面建立一個 profile 目錄。

- -

在 Linux 上執行

- -

只要在啟動 b2g 執行檔的時候加上 profile 參數,就可以使用我們剛剛產生的 profile 來啟動 desktop client 。如果是自己編譯的話,執行檔的位置會在早先下載下來的 tarball 裡面,如果是自己編譯的話,就會在 ../build/dist/bin 的目錄裡。

- -
.../b2g -profile gaia/profile
-
- -

您可能會碰到惱人的 rendering 問題。只要在 gaia/profile/prefs.js 裡面加上下面這行就可以避開這個問題:

- -
user_pref("layers.acceleration.disabled", true);
-
- -

在 Mac 上執行

- -

在 Mac 上,b2g 執行檔的位置和需要指定 profile 的絕對路徑,因此指令比較複雜:

- -
.../B2G.app/Contents/MacOS/b2g -profile /full/path/to/gaia/profile
-
- -

指令的選項(或參數)

- -

在使用 desktop client 時,你可以使用一些指令的參數來調校執行時的體驗。您可以用 -help 這個參數來列出參數的列表。這一節涵蓋一些特別的參數。

- -

明確指定螢幕大小

- -

您可以用 --screen 來指定您想要模擬的行動裝置的螢幕大小:

- -
b2g --screen=<width>x<height>[@<dpi>]
- -

<width>, <height>, and <dpi> 都是相當不用解釋的參數:行動裝置以 pixels 為單位的長和寬以及 DPI 解析度。舉例來說:

- -
b2g --screen=320x480
-b2g --screen=320x480@160
-
- -

或者,您可以使用某些行動裝置的名字來模擬他們的螢幕大小和解析度:

- - - -

開啟 JavaScript console

- -

在您開啟 B2G 的 desktop client 時,您可以藉由加上 -jsconsole 這個記號來開啟
- JavaSCript console。在編譯之後,只要:

- -
.../b2g -jsconsole -profile /path/to/your/profile
- -

如果您已經在 Mac 上安裝了 nightly 版本的話,您可以照著下面的指令:

- -
/Applications/B2G.app/Contents/MacOS/b2g -jsconsole -profile /path/to/your/profile
- -

在 B2G 啟動時,指定開啟一個應用程式

- -

您現在可以指定一個應用程式在 b2g desktop client 開始運作時,自動執行起來。這會在其他系統程式被掛載起來之後,馬上讓指定的應用程式被執行起來。只要加上 --runapp 這個參數、後面在加上要執行應用程式的名字,就可以做到了。如下:

- -
 .../b2g -profile /path/to/your/gaia/profile --runapp email
- -

在尋找要執行的 app 之前,指定的名字要被正規化為全部小寫、且不能帶有 - 和空白的符號。接著這個正規化過的名字會被拿來和 app 的 manifest 的名字做比較。

- -

舉例來說,現在 email app 的名字是「E-mail」,但是因為正規化的效果, --runapp email 這個參數是 ok可以執行的。

- -

如果您加了 --runapp 參數但是卻沒有帶後面的 app 名字、或是帶了空的名字的話,b2g client 會列出一串列表,其中包括已知的應用程式和簡短的使用訊息。

- -
-

Note:--runapp 參數會有關閉螢幕鎖的副作用,且不會再度啟用螢幕鎖。這是假設您不會用這個指令加上 profile 來測試螢幕鎖,否則您會重新打開這個選項。如果這個行為會造成問題的話,也歡迎提供 patch 來改變這個它。

-
- -

Usage tips

- -

這一節提供一些在使用 B2G desktop client 時,有幫助的技巧。

- - - -

Next steps

- -

現在您有一個執行 Boot to Gecko 的 desktop 版本了,您可以在上面測試、開發以及做其他事情:

- - diff --git a/files/zh-tw/archive/b2g_os/using_the_b2g_emulators/index.html b/files/zh-tw/archive/b2g_os/using_the_b2g_emulators/index.html deleted file mode 100644 index 6dccacbe06..0000000000 --- a/files/zh-tw/archive/b2g_os/using_the_b2g_emulators/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: 使用 B2G 模擬器 -slug: Archive/B2G_OS/Using_the_B2G_emulators -translation_of: Archive/B2G_OS/Using_the_B2G_emulators ---- -

這篇文章提供簡潔的指南,包括使用 Boot to Gecko 模擬器時需要知道的一些重要的事情。這不意味著這是一個完整的使用手冊;相反地,它只告訴您一些有用的事情,讓您不必自己去學。

-

這篇指南假設您已經編譯了一個模擬器;如果您還沒編譯的話,請跳回「建置和安裝 Boot to Gecko」!

-

關於 B2G 模擬器

-

有兩種 B2G 模擬器。第一種是 x86 行動裝置的模擬器,使用 "emulator-x86" 設定以 config.sh 編譯而成。雖然這遠比模擬 ARM 處理器快多了,但是它執行的沒有那麼接近一個實體行動裝置的結果。而第二種則是 ARM 行動裝置的模擬器,使用 "emulator" 的設定編譯。

-

一旦你選擇、設定及編譯模擬器,就使用者而言,剩下來要做的事情都是一樣的,所以這篇導覽剩下的共同部分是兩種模擬器都適用的。

-
- Note: 在 Mac OS X 上,B2G 模擬器需要 Core 2 Duo 或更快 CPU;也就是說,一個相容於 Mac OS X 10.7 "Lion" 的系統。你不必一定得使用 Lion,只是要在和 Lion 相容的系統上面執行就可以了。
-

啟動模擬器

-

執行下列指令,就可以打開 B2G 模擬器了:

-
./run-emulator.sh
-
-

這個指令將會會您操作所有模擬器的起始作業。現在就耐心等模擬器啟動以及 Boot to Gecko 在上面開始運作起來。啟動會花好幾分鐘,所以請耐心等候。

-

當模擬器掛了

-

有時候模擬器會啟動失敗。歡迎來到尖端科技的前緣。這裡有一些派的上用場的技巧,可用來解決問題。

-

確定 adb server 是不是還活著

-

adb server 處理與模擬的行動裝置之間的互動,而這裡常常出問題的原因是 adb server 不是沒在執行就是故障。

-
-

Note: 舉例來說,如果您使用 B2G 版本所編譯出的 adb 的話,它的位置會在 $B2G/out/host/<platform>/bin 目錄裡。在 Mac 上的話,則是在 $B2G/out/host/darwin-x86/bin 目錄下。

-
-

使用下列指令來看 adb 是否還在運作中:

-
ps aux | grep adb
-
-

If it's there, do this to kill it, because it's probably not working correctly.

-
adb kill-server
-
-

If it's not there, do this:

-
adb start-server
-
-

接著試試看再執行模擬器一次看看。如果還是沒辦法運作的話, 就是時候到 irc.mozilla.org 使用 #b2g 搜尋尋求幫助了。

-

抹掉 configuration 設定值

-

有時候,在模擬的行動裝置上使用過期的設定檔的設定值也會讓它暴走。你可以砍掉 indexedDB 資料庫來解決這個問題,如下:

-
    -
  1. 確定 adb 在執行中,如同 Make sure the adb server is running 中所描述的一般。
  2. -
  3. 啟動模擬器。
  4. -
  5. 先打開電腦裡的 terminal,然後切換到編譯模擬器的主目錄 (root code build directory),接著打:「out/host/<platform>/bin/adb -e shell」;在 Mac 上使用「out/host/darwin-x86/bin/adb -e shell」。
  6. -
  7. 現在你已經在 adb 的 shell 裡面、且可以直接在模擬器的行動 裝置上執行 shell 指令 (commands)了。讓我們使用「stop b2g」來停止裝置上的 B2G。
  8. -
  9. 刪除 indexedDB 資料庫:rm -rf /data/local/indexedDB
  10. -
  11. 在模擬的行動裝置上重新啟動 B2G:start b2g
  12. -
-

希望此時您所打開 Gaia 介面一切都恢復正常。

-

設定模擬器

-

如果您想要調整模擬器更接近您想要模擬的裝置的話,有幾個選項可以改改看。這一節提供一些關於「如何調校」的基本資訊。您可以編輯 run-emulator.sh (觀念上還是複製一份來編輯)這個 script 來調校模擬器的設定。這裡指會討論到一些最常用到的參數;您可以 連到 qemu 網站 來看其他部分的細節。

-
- Tip: 您可以為每個想要模擬的裝置建立一個 run-emulator.sh 的複製版本;這會您比較容易以不同的設定啟動模擬器。
-

改變外觀

-

模擬器預設會以 HVGA 模式啟動;VGA 的一半、也就是 320x480 pixels 的外觀。在啟動時,我們可以給模擬器加上 -skin 的參數來指定外觀。您可以編輯 run-emulator.sh 來切換成不同的顯示模式來執行模擬器。可以使用的外觀列表如下:

- -

外觀的存放位置在 B2G/development/tools/emulator/skins 目錄。外觀的格式很簡單;如果您打開來看的話,他們只是一些資料夾,裝著一些使用者介面物件的 PNG 檔案以及一個描述使用者介面的配置及螢幕區域的文字檔 layout。如果需要建立客製化的外觀的話,是還蠻簡單的。

-

改變記憶體的大小

-

另一個您可能想要/需要改變的選項就是行動裝置的記憶體大小。預設是 512MB;然而,如果您要模擬的行動裝置的記憶體比較大或小的話,或許對您而言,將記憶體調整成一樣的大小是很重要的,這樣才能確定您的 app 會在您想要執行的基礎裝置上執行。您可以將 -memory 參數的數值修改成您需要的數字(以 MB 為單位),就可以改變執行時的記憶體大小。除了預設的 512MB 之外,您可能會想要以 256MB 和 1024MB 來做測試。

-

而如果想要改變模擬裝置的儲存容量大小的話 (就是 local 資料的儲存空間,像是行動電話的內建快閃記憶體或是電腦的硬碟),可以改變 -partition-size 參數的數值。預設是 512MB,但是您可以改成任何大小 (以 MB 為單位)來模擬想要測試的行動裝置。

-

網路連線

-

如果因為某些原因,您沒辦法將您的模擬器連上網際網路 (internet)的話,您可以從命令提示字元來執行下面的指令 (commandline):

-
adb shell setprop net.dns1 10.0.2.3
diff --git a/files/zh-tw/archive/b2g_os/web_telephony_api/index.html b/files/zh-tw/archive/b2g_os/web_telephony_api/index.html deleted file mode 100644 index c9e0c9516b..0000000000 --- a/files/zh-tw/archive/b2g_os/web_telephony_api/index.html +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: Web Telephony -slug: Archive/B2G_OS/Web_Telephony_API -translation_of: Archive/B2G_OS/Web_Telephony_API ---- -

WebTelephony API 可透過 JavaScript 程式碼,讓網頁內容處理一般音訊電話。

-

透過 window.navigator.mozTelephony 即可存取此 API。另請參閱下列的完整介面列表:

-

DOM 介面

- -

範例程式碼與介紹

-
- -
-

另可參閱

- diff --git a/files/zh-tw/archive/b2g_os/writing_apps_for_boot_to_gecko/index.html b/files/zh-tw/archive/b2g_os/writing_apps_for_boot_to_gecko/index.html deleted file mode 100644 index a38efda16e..0000000000 --- a/files/zh-tw/archive/b2g_os/writing_apps_for_boot_to_gecko/index.html +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: 寫 Boot to Gecko 的 apps -slug: Archive/B2G_OS/Writing_apps_for_Boot_to_Gecko -translation_of: Archive/B2G_OS/Firefox_OS_apps/Building_apps_for_Firefox_OS ---- -

B2G apps 不外乎是安裝於 B2G 手機的 Open Web apps

- -
- Note: B2G 現在和 Fennec 用相同的 UA (User Agent) 來分辨。例如:"Mozilla/5.0 (Android; Mobile; rv:15.0) Gecko/15.0 Firefox/15.0a1".
-- cgit v1.2.3-54-g00ecf