From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/archive/b2g_os/api/alarm_api/index.html | 218 +++++ .../api/bluetoothstatuschangedevent/index.html | 54 ++ .../zh-cn/archive/b2g_os/api/domrequest/index.html | 139 +++ files/zh-cn/archive/b2g_os/api/index.html | 833 ++++++++++++++++ .../zh-cn/archive/b2g_os/api/navigator/index.html | 12 + .../api/navigator/mozhaspendingmessage/index.html | 117 +++ .../api/navigator/mozsetmessagehandler/index.html | 252 +++++ .../b2g_os/api/navigator/moztelephony/index.html | 85 ++ .../archive/b2g_os/api/permissions_api/index.html | 100 ++ .../archive/b2g_os/api/settingslock/index.html | 55 ++ .../archive/b2g_os/api/settingslock/set/index.html | 80 ++ .../archive/b2g_os/api/settingsmanager/index.html | 66 ++ .../archive/b2g_os/api/tpc_socket_api/index.html | 156 +++ files/zh-cn/archive/b2g_os/apps/index.html | 51 + .../writing_a_web_app_for_firefox_os/index.html | 46 + .../gaia_performance_tests/index.html | 109 +++ .../automated_testing/gaia_unit_tests/index.html | 113 +++ .../archive/b2g_os/automated_testing/index.html | 124 +++ files/zh-cn/archive/b2g_os/building/index.html | 185 ++++ .../b2g_os_update_packages/index.html | 477 +++++++++ .../firefox_os_build_overview/index.html | 105 ++ .../building_and_installing_firefox_os/index.html | 70 ++ .../building_the_b2g_desktop_client/index.html | 262 +++++ .../index.html | 107 ++ .../debugging/debugging_b2g_using_gdb/index.html | 88 ++ .../b2g_os/debugging/debugging_ooms/index.html | 62 ++ .../b2g_os/debugging/developer_settings/index.html | 161 +++ files/zh-cn/archive/b2g_os/debugging/index.html | 80 ++ .../b2g_os/debugging/taking_screenshots/index.html | 69 ++ .../customizing_the_b2g.sh_script/index.html | 44 + .../filing_bugs_against_firefox_os/index.html | 157 +++ .../b2g_os/developing_firefox_os/index.html | 45 + .../market_customizations_guide/index.html | 979 +++++++++++++++++++ .../modifying_hosts_file/index.html | 43 + .../index.html | 193 ++++ .../customizing_build-time_apps/index.html | 117 +++ .../customizing_the_keyboard/index.html | 65 ++ .../different_ways_to_run_gaia/index.html | 72 ++ .../archive/b2g_os/developing_gaia/index.html | 54 ++ .../localizing_firefox_os/index.html | 107 ++ .../make_options_reference/index.html | 186 ++++ .../making_gaia_code_changes/index.html | 58 ++ .../running_the_gaia_codebase/index.html | 81 ++ .../testing_gaia_code_changes/index.html | 119 +++ .../understanding_the_gaia_codebase/index.html | 105 ++ .../archive/b2g_os/events/disabled/index.html | 43 + files/zh-cn/archive/b2g_os/events/index.html | 14 + .../firefox_os_apps/building_blocks/1.x/index.html | 534 ++++++++++ .../1.x/\346\214\211\351\222\256/index.html" | 256 +++++ .../firefox_os_apps/building_blocks/index.html | 187 ++++ .../archive/b2g_os/firefox_os_apps/index.html | 85 ++ .../firefox_os_build_prerequisites/index.html | 267 +++++ .../zh-cn/archive/b2g_os/firefox_os_faq/index.html | 43 + files/zh-cn/archive/b2g_os/index.html | 243 +++++ .../installing_on_a_mobile_device/index.html | 111 +++ files/zh-cn/archive/b2g_os/introduction/index.html | 110 +++ .../index.html | 55 ++ .../archive/b2g_os/phone_guide/flame/index.html | 258 +++++ files/zh-cn/archive/b2g_os/phone_guide/index.html | 35 + .../b2g_os/phone_guide/phone_specs/index.html | 439 +++++++++ .../b2g_os/platform/apps_architecture/index.html | 24 + .../b2g_os/platform/architecture/index.html | 1024 ++++++++++++++++++++ .../platform/feature_support_chart/index.html | 158 +++ .../platform/gaia/build_system_primer/index.html | 68 ++ .../platform/gaia/gaia_apps/browser/index.html | 107 ++ .../b2g_os/platform/gaia/gaia_apps/index.html | 90 ++ .../platform/gaia/gaia_apps/settings/index.html | 78 ++ .../platform/gaia/gaia_apps/system/index.html | 226 +++++ .../gaia/gaia_apps/window_management/index.html | 279 ++++++ .../b2g_os/platform/gaia/hacking/index.html | 542 +++++++++++ .../zh-cn/archive/b2g_os/platform/gaia/index.html | 72 ++ .../platform/gaia/introduction_to_gaia/index.html | 28 + .../index.html" | 105 ++ .../zh-cn/archive/b2g_os/platform/gonk/index.html | 98 ++ files/zh-cn/archive/b2g_os/platform/index.html | 87 ++ .../index.html | 80 ++ .../b2g_os/platform/settings_list/index.html | 716 ++++++++++++++ files/zh-cn/archive/b2g_os/porting/index.html | 120 +++ .../preparing_for_your_first_b2g_build/index.html | 212 ++++ files/zh-cn/archive/b2g_os/quickstart/index.html | 49 + .../b2g_os/quickstart/your_first_app/index.html | 261 +++++ .../index.html" | 87 ++ .../index.html | 58 ++ .../index.html | 219 +++++ .../security/application_security/index.html | 126 +++ files/zh-cn/archive/b2g_os/security/index.html | 70 ++ .../b2g_os/security/security_model/index.html | 285 ++++++ files/zh-cn/archive/b2g_os/simulator/index.html | 240 +++++ .../simulator/simulator_walkthrough/index.html | 269 +++++ .../b2g_os/using_firefox_os_simulator/index.html | 57 ++ .../b2g_os/using_the_app_manager/index.html | 183 ++++ .../b2g_os/using_the_b2g_emulators/index.html | 72 ++ 92 files changed, 15471 insertions(+) create mode 100644 files/zh-cn/archive/b2g_os/api/alarm_api/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/bluetoothstatuschangedevent/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/domrequest/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/navigator/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/navigator/mozhaspendingmessage/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/navigator/mozsetmessagehandler/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/navigator/moztelephony/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/permissions_api/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/settingslock/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/settingslock/set/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/settingsmanager/index.html create mode 100644 files/zh-cn/archive/b2g_os/api/tpc_socket_api/index.html create mode 100644 files/zh-cn/archive/b2g_os/apps/index.html create mode 100644 files/zh-cn/archive/b2g_os/apps/writing_a_web_app_for_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/automated_testing/gaia_performance_tests/index.html create mode 100644 files/zh-cn/archive/b2g_os/automated_testing/gaia_unit_tests/index.html create mode 100644 files/zh-cn/archive/b2g_os/automated_testing/index.html create mode 100644 files/zh-cn/archive/b2g_os/building/index.html create mode 100644 files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/b2g_os_update_packages/index.html create mode 100644 files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_overview/index.html create mode 100644 files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/building_the_b2g_desktop_client/index.html create mode 100644 files/zh-cn/archive/b2g_os/customization_with_the_.userconfig_file/index.html create mode 100644 files/zh-cn/archive/b2g_os/debugging/debugging_b2g_using_gdb/index.html create mode 100644 files/zh-cn/archive/b2g_os/debugging/debugging_ooms/index.html create mode 100644 files/zh-cn/archive/b2g_os/debugging/developer_settings/index.html create mode 100644 files/zh-cn/archive/b2g_os/debugging/index.html create mode 100644 files/zh-cn/archive/b2g_os/debugging/taking_screenshots/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/customizing_the_b2g.sh_script/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/filing_bugs_against_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/market_customizations_guide/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/modifying_hosts_file/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_firefox_os/quickstart_guide_to_gaia_development/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/customizing_build-time_apps/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/customizing_the_keyboard/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/different_ways_to_run_gaia/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/localizing_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/make_options_reference/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/making_gaia_code_changes/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/running_the_gaia_codebase/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/testing_gaia_code_changes/index.html create mode 100644 files/zh-cn/archive/b2g_os/developing_gaia/understanding_the_gaia_codebase/index.html create mode 100644 files/zh-cn/archive/b2g_os/events/disabled/index.html create mode 100644 files/zh-cn/archive/b2g_os/events/index.html create mode 100644 files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/index.html create mode 100644 "files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/\346\214\211\351\222\256/index.html" create mode 100644 files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/index.html create mode 100644 files/zh-cn/archive/b2g_os/firefox_os_apps/index.html create mode 100644 files/zh-cn/archive/b2g_os/firefox_os_build_prerequisites/index.html create mode 100644 files/zh-cn/archive/b2g_os/firefox_os_faq/index.html create mode 100644 files/zh-cn/archive/b2g_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/installing_on_a_mobile_device/index.html create mode 100644 files/zh-cn/archive/b2g_os/introduction/index.html create mode 100644 files/zh-cn/archive/b2g_os/phone_guide/best_practices_open_reference_devices/index.html create mode 100644 files/zh-cn/archive/b2g_os/phone_guide/flame/index.html create mode 100644 files/zh-cn/archive/b2g_os/phone_guide/index.html create mode 100644 files/zh-cn/archive/b2g_os/phone_guide/phone_specs/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/architecture/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html create mode 100644 "files/zh-cn/archive/b2g_os/platform/gaia/weinre\350\277\234\347\250\213\350\260\203\350\257\225\345\267\245\345\205\267/index.html" create mode 100644 files/zh-cn/archive/b2g_os/platform/gonk/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/platform/settings_list/index.html create mode 100644 files/zh-cn/archive/b2g_os/porting/index.html create mode 100644 files/zh-cn/archive/b2g_os/preparing_for_your_first_b2g_build/index.html create mode 100644 files/zh-cn/archive/b2g_os/quickstart/index.html create mode 100644 files/zh-cn/archive/b2g_os/quickstart/your_first_app/index.html create mode 100644 "files/zh-cn/archive/b2g_os/quickstart/\345\274\200\346\272\220web\345\272\224\347\224\250\347\250\213\345\272\217\347\256\200\344\273\213/index.html" create mode 100644 files/zh-cn/archive/b2g_os/running_tests_on_firefox_os_for_developers/index.html create mode 100644 files/zh-cn/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html create mode 100644 files/zh-cn/archive/b2g_os/security/application_security/index.html create mode 100644 files/zh-cn/archive/b2g_os/security/index.html create mode 100644 files/zh-cn/archive/b2g_os/security/security_model/index.html create mode 100644 files/zh-cn/archive/b2g_os/simulator/index.html create mode 100644 files/zh-cn/archive/b2g_os/simulator/simulator_walkthrough/index.html create mode 100644 files/zh-cn/archive/b2g_os/using_firefox_os_simulator/index.html create mode 100644 files/zh-cn/archive/b2g_os/using_the_app_manager/index.html create mode 100644 files/zh-cn/archive/b2g_os/using_the_b2g_emulators/index.html (limited to 'files/zh-cn/archive/b2g_os') diff --git a/files/zh-cn/archive/b2g_os/api/alarm_api/index.html b/files/zh-cn/archive/b2g_os/api/alarm_api/index.html new file mode 100644 index 0000000000..bc686238e2 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/alarm_api/index.html @@ -0,0 +1,218 @@ +--- +title: Alarm API +slug: Archive/B2G_OS/API/Alarm_API +tags: + - API + - Firefox OS + - 警报 +translation_of: Archive/B2G_OS/API/Alarm_API +--- +

{{DefaultAPISidebar("Alarm API")}}{{Non-standard_Header}}

+ +

Alarm API允许应用程序设定将来运行的操作。例如,一些应用程序(如闹钟、日历或自动更新)可能需要使用Alarm API在指定的时间点触发特定的设备行为。

+ +

Alarm API本身只允许调度警报。Alarm 通过系统消息API发送到应用程序,因此希望对警报作出响应的应用程序必须将自己注册到Alarm 消息中。

+ +

Alarm 使用 {{DOMxRef("Navigator.mozAlarms")}}对象设置,该对象是{{DOMxRef("MozAlarmsManager")}}接口的一个实例。

+ +
+

注: 这里的‘“闹钟 ”(Alarm API)并不同于闹铃App。Alarm API 唤醒应用程序, 闹钟叫醒人. 闹钟 使用 Alarm API 设置通知,用来在正确的时间叫醒人。(译者注:疑问脸)

+
+ +

设置闹铃

+ +

使用闹铃时要做的第一件事是设置闹铃。根据时区的不同,有两种警报。在这两种情况下,它都是使用{{DOMxRef("MozAlarmsManager.add()")}}方法完成的。

+ +
+

Note: 如果警报不是针对特定应用程序的,系统会将所有警报发送给所有监听警报的应用程序。

+
+ +
+

Note: 您需要使用相同的URL来设置和接收警报。例如,如果在foo.html或index.html?foo=bar上调用navigator.mozAlarms.add(),但在清单消息字段中有{ "alarm": "/index.html" },您将永远不会收到警报。

+
+ +

Alarms 忽略时区

+ +

这类警报是根据设备的本地时间发出的。如果设备用户更改了时区,将根据新的时区发出警报。例如,如果用户在巴黎,设置了一个应该在CET(中欧时间)下午12点发出的警报,而该用户前往旧金山,那么该警报将在PDT(太平洋夏令时)下午12点发出。

+ +
// 设定闹钟的日期
+var myDate  = new Date("May 15, 2012 16:20:00");
+
+// 传递给警报的任意数据
+var data    = {
+  foo: "bar"
+}
+
+// 使警报忽略"ignoreTimezone"
+var request = navigator.mozAlarms.add(myDate, "ignoreTimezone", data);
+
+request.onsuccess = function () {
+  console.log("The alarm has been scheduled");
+};
+
+request.onerror = function () {
+  console.log("An error occurred: " + this.error.name);
+};
+ +

时区警报

+ +

这些类型的警报是根据定义警报计划时间的时区中的时间发出的。如果由于某种原因,设备的用户更改了时区,将根据原始时区发出警报。例如,如果用户在巴黎,并设置一个闹钟,该闹钟应该在CET(中欧时间)下午12点发出,如果该用户前往旧金山,该闹钟将在太平洋夏令时凌晨3点发出。

+ +
// This the date to schedule the alarm
+var myDate  = new Date("May 15, 2012 16:20:00");
+
+// This is arbitrary data pass to the alarm
+var data    = {
+  foo: "bar"
+}
+
+// The "honorTimezone" string is what make the alarm honoring it
+var request = navigator.mozAlarms.add(myDate, "honorTimezone", data);
+
+request.onsuccess = function () {
+  console.log("The alarm has been scheduled");
+};
+
+request.onerror = function () {
+  console.log("An error occurred: " + this.error.name);
+};
+ +

管理警报

+ +

 

+ +

设定警报后,仍然可以管理它。

+ +

方法将返回应用程序当前调度的警报的完整列表。这个列表是一个{{anch("mozAlarm")}}对象数组。

+ +

 

+ +

 

+ +

mozAlarm

+ +

 

+ +

匿名JavaScript对象,具有以下属性:

+ +

 

+ +

id

+ +

表示警报id

+ +

date

+ +

表示警报的预定时间的日期对象

+ +

respectTimezone

+ +

一个字符串,指示警报是否必须尊重或忽略date对象的时区信息。它的值可以是ignoreTimezonehonorTimezone

+ +

data

+ +

一个JavaScript对象,包含警报存储的所有数据

+ +

 

+ +
var request = navigator.mozAlarms.getAll();
+
+request.onsuccess = function () {
+  this.result.forEach(function (alarm) {
+    console.log('Id: ' + alarm.id);
+    console.log('date: ' + alarm.date);
+    console.log('respectTimezone: ' + alarm.respectTimezone);
+    console.log('data: ' + JSON.stringify(alarm.data));
+  });
+};
+
+request.onerror = function () {
+  console.log("An error occurred: " + this.error.name);
+};
+ +

{{DOMxRef("MozAlarmsManager.remove")}} 用于取消现有警报的调度。

+ +
var alarmId;
+
+// Set an alarm and store it's id
+var request = navigator.mozAlarms.add(new Date("May 15, 2012 16:20:00"), "honorTimezone");
+
+request.onsuccess = function () {
+  alarmId = this.result;
+}
+
+// ...
+
+// Later on, removing the alarm if it exists
+if (alarmId) {
+  navigator.mozAlarms.remove(alarmId);
+}
+ +

处理警报

+ +

 

+ +

当系统发出警报时,任何应用程序都可以作出反应。为了能够处理任何警报,应用程序必须将自己注册为警报处理程序。这是通过系统消息API分两个步骤完成的:

+ +

首先,应用程序必须将alarm包含到其应用程序清单的messages属性中,并提供到文档的URL,文档注册在发出警报时使用的回调函数。

+ +
"messages": [
+  { "alarm": "/index.html" }
+]
+ +

其次,应用程序必须将回调函数与警报消息绑定。这是使用{{DOMxRef("Navigator.mozSetMessageHandler()")}}方法完成的。这个回调函数将接收一个{{Anch("mozAlarm")}}对象,其中包含附加到警报的数据。

+ +
navigator.mozSetMessageHandler("alarm", function (mozAlarm) {
+  alert("alarm fired: " + JSON.stringify(mozAlarm.data));
+});
+ +

如果应用程序想知道系统级别上是否存在挂起的警报,可以使用下面的方法。

+ +
navigator.mozHasPendingMessage("alarm"); 
+ +

权限 Alarm API

+ +

请注意,虽然警报API没有特权或认证,但您仍然应该在清单中包含权限消息条目。当包含在可安装的打开的Web应用程序中的manifest.webapp文件。

+ +
{
+  "permissions": {
+    "alarms": {
+      "description": "Required to schedule alarms"
+    }
+  },
+  "messages": [
+    { "alarm": "/index.html" }
+  ]
+}
+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("Alarm API")}}{{Spec2("Alarm API")}}Initial specification.
+ +

浏览器兼容性

+ +

Supported in Firefox OS 1.0.1.

+ +

另请参阅

+ + diff --git a/files/zh-cn/archive/b2g_os/api/bluetoothstatuschangedevent/index.html b/files/zh-cn/archive/b2g_os/api/bluetoothstatuschangedevent/index.html new file mode 100644 index 0000000000..8003a4414b --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/bluetoothstatuschangedevent/index.html @@ -0,0 +1,54 @@ +--- +title: 蓝牙状态更改事件 +slug: Archive/B2G_OS/API/BluetoothStatusChangedEvent +translation_of: Archive/B2G_OS/API/BluetoothStatusChangedEvent +--- +

概要

+ +

BluetoothStatusChangedEvent API可以访问有关蓝牙设备状态的任何更改的信息。

+ +

当触发以下某个事件时,会发生状态更改:

+ + + +

接口概述

+ +
interface BluetoothStatusChangedEvent: Event
+{
+  readonly attribute DOMString address;
+  readonly attribute boolean status;
+};
+ +

属性

+ +
+
{{domxref("BluetoothStatusChangedEvent.address")}} {{readonlyinline}}
+
表示蓝牙微网中状态发生变化的设备地址的字符串。.
+
{{domxref("BluetoothStatusChangedEvent.status")}} {{readonlyinline}}
+
表示连接当前状态的布尔值。它可以被启用(true)或禁用(false)。
+
+
+ +

方法

+ +

目前没有。

+ +

规范

+ +

还不是任何规范的一部分。它应该作为W3C's System Applications Working Group的一部分进行讨论。

+ +

也可以看看

+ + diff --git a/files/zh-cn/archive/b2g_os/api/domrequest/index.html b/files/zh-cn/archive/b2g_os/api/domrequest/index.html new file mode 100644 index 0000000000..0f4502fac7 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/domrequest/index.html @@ -0,0 +1,139 @@ +--- +title: DOMRequest +slug: Archive/B2G_OS/API/DOMRequest +tags: + - API + - DOM + - 回调 +translation_of: Archive/B2G_OS/API/DOMRequest +--- +
+ +

DOMRequest对象表示正在进行的操作。 它提供在操作完成时调用的回调,以及对操作结果的引用。 启动一个进行中的操作,DOM方法会返回一个DOMRequest对象,您可以使用该对象来监视该操作的进度。

+ +

Note: 此特性在 Web Worker 中可用。

+ +

属性

+ +
+
DOMRequest.onsuccess
+
当由DOMRequest表示的操作完成时调用的回调处理程序。
+
DOMRequest.onerror
+
当处理操作发生错误时调用的回调处理程序。
+
DOMRequest.readyState
+
表示操作是否已完成运行的字符串。 其值为“done”或“pending”。
+
DOMRequest.result
+
操作的结果。
+
DOMRequest.error
+
错误信息(如果有)。
+
+ +

方法

+ +

无.

+ +

例子

+ +

使用DOMRequest对象的onsuccess,onerror,result和error属性的一个示例。

+ +
var pending = navigator.mozApps.install(manifestUrl);
+
+pending.onsuccess = function () {
+  // Save the App object that is returned
+  var appRecord = this.result;
+  alert('Installation successful!');
+};
+pending.onerror = function () {
+  // Display the name of the error
+  alert('Install failed, error: ' + this.error.name);
+};
+ +

规范

+ +

目前不是任何规范的一部分。

+ +

浏览器支持

+ +

We're converting our compatibility data into a machine-readable JSON format. + This compatibility table still uses the old format, + because we haven't yet converted the data it contains. + Find out how you can help!

+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support?13.0 (13.0)???
Available in workers?41.0 (41.0)???
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support??13.0 (13.0)???
Available in workers??41.0 (41.0)???
+
+ +

另见

+ + diff --git a/files/zh-cn/archive/b2g_os/api/index.html b/files/zh-cn/archive/b2g_os/api/index.html new file mode 100644 index 0000000000..6748c09ac8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/index.html @@ -0,0 +1,833 @@ +--- +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 +--- +

B2G OS uses standard Web API's

+ +

+A +B +C +D +E +F +G +H +I + + +K +L +M +N +O +P + + +R +S +T +U +V +W +X + + + + + +

diff --git a/files/zh-cn/archive/b2g_os/api/navigator/index.html b/files/zh-cn/archive/b2g_os/api/navigator/index.html new file mode 100644 index 0000000000..c66a781c5f --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/navigator/index.html @@ -0,0 +1,12 @@ +--- +title: Navigator (Firefox OS extensions) +slug: Archive/B2G_OS/API/Navigator +translation_of: Archive/B2G_OS/API/Navigator +--- +

(zh-CN translation)

+ +

The Navigator interface represents the state and the identity of the user agent. It allows scripts to query it and to register themselves to carry on some activities. This page represents the list of properties and methods added to Navigator on Firefox OS devices. For the list of properties and methods available to any Web sites, consult Navigator.

+ +

A Navigator object can be retrieved using the read-only Window.navigator property.

+ +

Navigator.mozHasPendingMessage()
该方法用来用于判定一个给定类型(type)是否存在未决消息(待处理的消息),返回类型为是(true)或非(false)。
Navigator.mozSetMessageHandler()
该方法用来允许应用为系统消息注册处理程序,对消息作出反应。
Navigator.mozTelephony
返回一个你可以用来从浏览器启动和控制电话呼叫的Telephony对象。

diff --git a/files/zh-cn/archive/b2g_os/api/navigator/mozhaspendingmessage/index.html b/files/zh-cn/archive/b2g_os/api/navigator/mozhaspendingmessage/index.html new file mode 100644 index 0000000000..ea7a00d867 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/navigator/mozhaspendingmessage/index.html @@ -0,0 +1,117 @@ +--- +title: Navigator.mozHasPendingMessage() +slug: Archive/B2G_OS/API/Navigator/mozHasPendingMessage +translation_of: Archive/B2G_OS/API/Navigator/mozHasPendingMessage +--- +

+

此 API 在 Firefox OS网页内容或高权限的应用程序上可用。

+

+ +

概要

+ +

该方法用来用于判定一个给定类型(type)是否存在未决消息(待处理的消息),返回类型为是(true)或非(false)。

+ +

navigator.mozSetMessageHandler() 用于设定一种类型的句柄时,待处理的消息会以异步的方式的传输给应用。 

+ +

语法

+ +
navigator.mozHasPendingMessage(type);
+ +

参数

+ +
+
type
+
类型是字符串,用于表示一个应用注册的处理函数要处理的消息。要获得有效type的完整列表,请参考navigator.mozSetMessageHandler().
+
+ +

返回值

+ +

布尔类型。

+ +

规范

+ + + + + + + + + + + + + + +
规范状态注解
UnknownUnknown定义了系统消息的接口
+ +

浏览器兼容性

+ +

We're converting our compatibility data into a machine-readable JSON format. + This compatibility table still uses the old format, + because we haven't yet converted the data it contains. + Find out how you can help!

+ +
+ + +

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support未实现未实现未实现未实现未实现
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox OSFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support未实现1.0未实现未实现未实现未实现
+
+ +

参见

+ + diff --git a/files/zh-cn/archive/b2g_os/api/navigator/mozsetmessagehandler/index.html b/files/zh-cn/archive/b2g_os/api/navigator/mozsetmessagehandler/index.html new file mode 100644 index 0000000000..9418c598cc --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/navigator/mozsetmessagehandler/index.html @@ -0,0 +1,252 @@ +--- +title: Navigator.mozSetMessageHandler() +slug: Archive/B2G_OS/API/Navigator/mozSetMessageHandler +translation_of: Archive/B2G_OS/API/Navigator/mozSetMessageHandler +--- +

+

此 API 在 Firefox OS网页内容或高权限的应用程序上可用。

+

+ +

概要

+ +

该方法用来允许应用为系统消息注册处理程序,对消息作出反应。

+ +

任何应用都允许注册到任何消息,但一些消息仅仅可以被送到有对应接收权限的应用。不同于DOM事件,如果应用没有针对系统消息的处理程序,它们将留在队列里。如果有排队消息,可以传入一个type参数调用navigator.mozHasPendingMessage()查看,当一个处理程序被设置,待处理消息将异步的地发送到应用。

+ +

语法

+ +
navigator.mozSetMessageHandler(type, handler);
+ +

参数

+ +
+
 
+
type
+
type是一个字符串,表示要为其注册处理函数的一类消息。
+
handler
+
当系统发送消息时,该处理函数被调用,其接收参数由消息类型来确定。
+
+ +

消息类型

+ +

目前Firefox OS允许注册以下消息 :

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Message nameHandler signaturePermission
activityf( MozActivityRequestHandler request ) 
alarmf( object unknown )alarms
bluetooth-cancelf( object unknown )bluetooth
bluetooth-dialer-commandf( object unknown )bluetooth
bluetooth-hfp-status-changedf( object unknown )bluetooth
bluetooth-opp-transfer-startf( object unknown )bluetooth
bluetooth-opp-transfer-completef( object unknown )bluetooth
bluetooth-opp-receiving-file-confirmationf( object unknown )bluetooth
bluetooth-opp-update-progressf( object unknown )bluetooth
bluetooth-pairedstatuschangedf( object unknown )bluetooth
bluetooth-requestconfirmationf( object unknown )bluetooth
bluetooth-requestpincodef( object unknown )bluetooth
bluetooth-requestpasskeyf( object unknown )bluetooth
headset-buttonf( object unknown ) 
icc-stkcommandf( object command )settings
notificationf( object unknown ) 
pushf( object registration )push
push-registerf (  )push
sms-receivedf( SmsMessage sms )sms
sms-sentf( SmsMessage sms )sms
telephony-call-endedf( object call )telephony
telephony-new-callf( )telephony
ussd-receivedf( object ussd )mobileconnection
wappush-receivedf( object wappush )wappush
+ +

规范说明

+ + + + + + + + + + + + + + +
SpecificationStatusComment
UnknownUnknownDefines the system messaging interfaces.
+ +

浏览器兼容性

+ +

We're converting our compatibility data into a machine-readable JSON format. + This compatibility table still uses the old format, + because we haven't yet converted the data it contains. + Find out how you can help!

+ +
+ + +

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support未实现未实现未实现未实现未实现
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox OSFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support未实现1.0未实现未实现未实现未实现
+
+ +

参见

+ + diff --git a/files/zh-cn/archive/b2g_os/api/navigator/moztelephony/index.html b/files/zh-cn/archive/b2g_os/api/navigator/moztelephony/index.html new file mode 100644 index 0000000000..9161c818ba --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/navigator/moztelephony/index.html @@ -0,0 +1,85 @@ +--- +title: Navigator.mozTelephony +slug: Archive/B2G_OS/API/Navigator/MozTelephony +translation_of: Archive/B2G_OS/API/Navigator/MozTelephony +--- +

+ +

+

非标准
+ 该特性是非标准的,请尽量不要在生产环境中使用它!

+

+ +

+

此 API 仅在 Firefox OS内部应用程序中可用。

+

+ +

概要

+ +

返回一个你可以用来从浏览器启动和控制电话呼叫的Telephony对象。

+ +

语法

+ +
var phone = window.navigator.mozTelephony;
+
+ +

+ +

navigator.mozTelephony是一个可以用来控制浏览器正在运行的设备上电话功能的Telephony对象

+ +

详述

+ +

这是一个非标准实现,但正在作为系统应用工作组的一部分被W3C讨论。

+ + + + + + + + + + + + + + + + +
详述状态内容
Web TelephonyDraftEditor Draft (WIP).
+ +

浏览器适应性

+ +

由于诸多原因, 其主要的支持预期在手机浏览器上。

+ +
+ + + + + + + + + + + + + + + + + + + +
功能AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
基本支持未实现12.0 (12.0)未实现未实现未实现
+
+ +

参见

+ + diff --git a/files/zh-cn/archive/b2g_os/api/permissions_api/index.html b/files/zh-cn/archive/b2g_os/api/permissions_api/index.html new file mode 100644 index 0000000000..0459a9c438 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/permissions_api/index.html @@ -0,0 +1,100 @@ +--- +title: Permissions API (Firefox OS) +slug: Archive/B2G_OS/API/Permissions_API +translation_of: Archive/B2G_OS/API/Permissions_API +--- +

+

非标准
+ 该特性是非标准的,请尽量不要在生产环境中使用它!

+

+ +

+

此 API 仅在 Firefox OS内部应用程序中可用。

+

+ +

 

+ +

Permissions API 用于显示应用权限以及让用户管理所有app的使用权限。有了这个API,一个应用可以读取到另一个应用的权限,并且还可以管理其权限范围。 

+ +

权限管理器可以通过navigator.mozPermissionSettings属性访问,该属性是 PermissionSettings 的实例.

+ +

已安装的应用程序权限

+ +


+ 每个应用程序通过其应用清单请求一些权限。 每次应用程序尝试使用需要显式权限的API时,系统都会提示用户授予或拒绝该权限。 如果他选择不再提示,则用户无法改变主意。 使用此API,可以为用户提供一个界面来管理他为任何应用程序提供的所有权限。

+ +

可以通过使用 PermissionSettings.get(), set(), 和isExplicit() 等方法。

+ +

读取权限

+ +

要了解给定权限的当前状态,可以使用PermissionSettings.get() 方法.  方法返回一个字符串,给出特定应用程序权限的当前状态。 可能的值是:

+ +
+
允许
+
该权限已被授予,不需要任何进一步的用户交互。
+
拒绝
+
无论是系统还是用户,权限都被拒绝。
+
提示
+
在需要时,将通过提示明确询问用户。
+
未知
+
应用程序没有要求此权限,甚至无法提示用户获取此权限。
+
+ +
// 检查所有已安装的应用
+var apps = navigator.mozApps.mgmt.getAll();
+
+apps.onsuccess = function () {
+  var permission = navigator.mozPermissionSettings;
+
+  // 检查每个应用的权限
+  apps.result.forEach(function (app) {
+    var request, appName = app.manifest.name;
+
+    for (request in app.manifest.permissions) {
+      // 获取应用程序的每个权限请求的当前权限
+      var p = permission.get(request, app.manifestURL, app.origin, false);
+
+      console.log(appName + ' asked for "' + request + '" permission, which is "' + p + '"')
+    }
+  });
+}
+
+ +

设置权限

+ +

要设置权限,只需使用PermissionSettings.set() 方法。它的值可能与通过get方法检索的值相同。

+ +
+

注意: 根据应用程序的privileges,某些权限是隐式的。 如果由于某种原因应用程序尝试更改隐式的权限,则会引发错误。 为了避免此类错误,可以使用PermissionSettings.isExplicit() 方法.

+
+ +
// 检查所有已安装的应用
+var apps = navigator.mozApps.mgmt.getAll();
+
+apps.onsuccess = function () {
+  var permission = navigator.mozPermissionSettings;
+
+  // 检查每个应用的权限
+  apps.result.forEach(function (app) {
+    var request, appName = app.manifest.name;
+
+    for (request in app.manifest.permissions) {
+      // 如果权限不明确
+      if (!permission.isExplicit(request, app.manifestURL, app.origin, false) {
+        // 询问用户应用程序请求的所有权限
+        permission.set(request, 'prompt', app.manifestURL, app.origin, false);
+      }
+    }
+  });
+}
+ +

规范

+ +

暂无

+ +

再看看

+ + diff --git a/files/zh-cn/archive/b2g_os/api/settingslock/index.html b/files/zh-cn/archive/b2g_os/api/settingslock/index.html new file mode 100644 index 0000000000..50f05a7966 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/settingslock/index.html @@ -0,0 +1,55 @@ +--- +title: SettingsLock +slug: Archive/B2G_OS/API/SettingsLock +tags: + - API + - B2G + - Firefox OS + - NeedsTranslation + - Non-standard + - Settings + - TopicStub +translation_of: Archive/B2G_OS/API/SettingsLock +--- + + +
+

This API is available on Firefox OS for internal applications only.

+
+ +

The SettingsLock interface represents a lock on settings. it allows a script to modify settings asynchronously, but in a safe way: ordering is guaranteed and the no other script will modify the settings until the modification are done (the next lock objects will start processing after it has been closed).

+ +

Each call to SettingsManager.createLock() create a new SettingsLock object.

+ +

All SettingsLock objects are kept in a queue of active locks. When a SettingsLock object is created it's placed at the end of the queue. Calls to get/set places a request against the lock on which it's called. Requests run asynchronously and in the order they are placed against a lock. When the last request for a lock is run, and  the success/error event against it has been fired, the lock is removed from the queue and the next lock start to be processed.

+ +

Properties

+ +
+
SettingsLock.closed
+
Indicates if the lock is no longer the active lock (true) or if it's still the active lock (false)
+
+ +

Methods

+ +
+
SettingsLock.set()
+
Allows to change the values of a set of settings. This method is asychronous and return a DOMRequest object.
+
SettingsLock.get()
+
Allows to retrieve the value of a given setting. This method is asychronous and return a DOMRequest object.
+
SettingsLock.clear()
+
Clears any action that have not been done yet (remember that get and set are asynchronous). This method is added for testing and it deletes the whole settings DB!
+
+ +

Specification

+ +

Not part of any specification yet; however, this API will be discuss at W3C as part of the System Applications Working Group.

+ +

See also

+ + diff --git a/files/zh-cn/archive/b2g_os/api/settingslock/set/index.html b/files/zh-cn/archive/b2g_os/api/settingslock/set/index.html new file mode 100644 index 0000000000..2203fc1169 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/settingslock/set/index.html @@ -0,0 +1,80 @@ +--- +title: SettingsLock.set() +slug: Archive/B2G_OS/API/SettingsLock/set +translation_of: Archive/B2G_OS/API/SettingsLock/set +--- + + + + + + +
+

此API在 Firefox OS 上仅可供 内部程序  使用.

+
+ + + +

摘要

+ +

这个方法用来更改一或多个已提供的设置的值。

+ +

此方法是异步的,返回一个 DOMRequest 对象,用于检测更改何时完成(或是否发生错误),并在更改完成后根据需要执行操作。

+ +

语法

+ +
SettingsLock.set(settings);
+ +

参数

+ +
+
settings
+
一个包含了一组键值对的对象,其中每个键表示给定的设置的字符串名称。可能的字符串的确切列表取决于设备。每个Gaia构建可以有自己的设置列表,有关这些字符串的最新列表,请查看 the Gaia source code.
+
+ +

示例

+ +

这个示例用来打开设备的WIFI。

+ +
var lock = navigator.mozSettings.createLock();
+var result = lock.set({
+  'wifi.enabled': true
+});
+
+result.onsuccess = function () {
+  console.log("The setting has been changed");
+}
+
+result.onerror = function () {
+  console.log("An error occure, the setting remain unchanged");
+}
+
+ +

规范

+ +

这目前还不是任何规范的一部分; 然而, 此 API 将会作为 System Applications Working Group 的一部分参与W3C的讨论。

+ +

其他

+ + diff --git a/files/zh-cn/archive/b2g_os/api/settingsmanager/index.html b/files/zh-cn/archive/b2g_os/api/settingsmanager/index.html new file mode 100644 index 0000000000..946c05f3d6 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/settingsmanager/index.html @@ -0,0 +1,66 @@ +--- +title: SettingsManager +slug: Archive/B2G_OS/API/SettingsManager +tags: + - API + - B2G + - Firefox OS + - Settings +translation_of: Archive/B2G_OS/API/SettingsManager +--- +
+ + +
+

此API在 Firefox OS 上仅适用于 内部程序 

+
+
+ +

提供对设备设置的访问。

+ +

属性

+ +
+
SettingsManager.onsettingchange
+
引用处理程序来管理设置的更改状态。
+
+ +

方法

+ +
+
SettingsManager.createLock()
+
返回一个异步的安全访问设置的 SettingsLock 对象。
+
SettingsManager.addObserver()
+
允许绑定一个函数来对给定的设置进行任意的更改。
+
SettingsManager.removeObserver()
+
允许取消绑定之前使用 addObserver 绑定的处理程序。
+
+ +

标准

+ +

目前还没有成为任何标准的一部分,然而,此API将会作为 System Applications Working Group 的一部分参与W3C的讨论。

+ +

其他

+ + diff --git a/files/zh-cn/archive/b2g_os/api/tpc_socket_api/index.html b/files/zh-cn/archive/b2g_os/api/tpc_socket_api/index.html new file mode 100644 index 0000000000..b2ce9fe405 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/api/tpc_socket_api/index.html @@ -0,0 +1,156 @@ +--- +title: TCP Socket API +slug: Archive/B2G_OS/API/TPC_Socket_API +tags: + - API + - Firefox OS + - TCP套接字 + - WebAPI + - 指导 + - 非标准 +translation_of: Archive/B2G_OS/API/TPC_Socket_API +--- + + +
+

非标准
+ 这个特性不在当前的W3C标准上,但在Firefox OS平台上受支持. 尽管实现方式可能会在将来发生变化,并且不受浏览器的广泛支持, 它适合在专用于Firefox OS应用程序的代码中使用。

+
+ +
+

该API可用于 Firefox OS 上仅适用于 privileged or certified applications.

+
+ +

摘要

+ +

TCPSocket API提供了一个完整的API,用于打开和使用TCP连接。 这使应用程序制造商可以实施TCP之上可用的任何协议,例如IMAP,IRC,POP,HTTP等,甚至可以构建自己的协议来满足他们可能拥有的任何特定需求。

+ +

权限

+ +

为了使用该API,对于所有特权API,都需要在 app manifest 中请求权限。

+ +
"permissions" : {
+  "tcp-socket" : {
+    "description" : "创建TCP套接字并通过它们进行通信。"
+  }
+}
+ +

总览

+ +

This API is available through the Navigator.mozTCPSocket property which is itself a TCPSocket object.

+ +

Opening a socket

+ +

Opening a socket is done with the TCPSocket.open() method. This method expects up to three parameters:

+ +
    +
  1. A string representing the hostname of the server to connect to (it can also be its raw IP address).
  2. +
  3. A number representing the TCP port to be used by the socket (some protocols have a standard port, for example 80 for HTTP, 447 for SSL, 25 for SMTP, etc. Port numbers beyond 1024 are not assigned to any specific protocol and can be used for any purpose.)
  4. +
  5. A optional object containing up to two options: a boolean named useSecureTransport is the socket needed to use SSL, false by default; and a string named binaryType allows to state the type of data retrieved by the application through the data event, with the expected values string or arraybuffer. By default, it is string.
  6. +
+ +
var socket = navigator.mozTCPSocket.open('localhost', 80);
+ +
+

Note: Only certified apps can use a port below 1024.

+
+ +

Listening for connections

+ +

Listening for connections is done with the TCPSocket.listen() Requires FirefoxOS 1.2 method. This method expects up to three parameters:

+ +
    +
  1. A number representing the TCP port to be used to listen for connections.
  2. +
  3. An optional object specifying the details of the socket. This object expects a property called binaryType, which is a string that can have two possible values: "string" or "arraybuffer". If the value is "arraybuffer" then the TCPSocket.send() will use ArrayBuffers and the data received from the remote connection will also be available in that format.
  4. +
  5. A number representing the maximum length that the pending connections queue can grow.
  6. +
+ +
var socket = navigator.mozTCPSocket.listen(8080);
+ +
+

Note: Only certified apps can listen on a port below 1024.

+
+ +

Sending data

+ +

Sending data is done using the TCPSocket.send() method. The data sent can be either a string or a Uint8Array object; however, remember that a TCP socket always deals with binary data. For that reason, it's a lot safer to use Uint8Array instead of a string when sending data.

+ +

As per the TCP protocol, it's a good optimization to send a maximum of 64kb of data at the same time. As long as less than 64kb has been buffered, a call to the send method returns true. Once the buffer is full, the method will return false which indicates the application should make a pause to flush the buffer. Each time the buffer is flushed, a drain event is fired and the application can use it to resume data sending.

+ +

It's possible to know exactly the current amount of data buffered with the TCPSocket.bufferedAmount property.

+ +
function getData() {
+  var data;
+
+  // do stuff that will retrieve data
+
+  return data;
+}
+
+function pushData() {
+  var data;
+
+  do {
+    data = getData();
+  } while (data != null && socket.send(data));
+}
+
+// Each time the buffer is flushed
+// we try to send data again.
+socket.ondrain = pushData;
+
+// Start sending data.
+pushData();
+
+ +

Getting data

+ +

Each time the socket gets some data from the host, it fires a data event. This event will give access to the data from the socket. The type of the data depends on the option set when the socket was opened (see above).

+ +
socket.ondata = function (event) {
+  if (typeof event.data === 'string') {
+    console.log('Get a string: ' + event.data);
+  } else {
+    console.log('Get a Uint8Array');
+  }
+}
+ +

As the data event is fired as much as needed, it can sometimes be necessary to pause the flow of incoming data. To that end, calling the TCPSocket.suspend() method will pause reading incoming data and stop firing the data. It's possible to start reading data and firing events again by calling the TCPSocket.resume() method.

+ +

Closing a socket

+ +

Closing a socket is simply done using TCPSocket.close().

+ +

Standard

+ +

Not part of any specification yet; however, this API is discussed at W3C as part of the System Applications Working Group under the Raw Sockets proposal.

+ +

See also

+ + diff --git a/files/zh-cn/archive/b2g_os/apps/index.html b/files/zh-cn/archive/b2g_os/apps/index.html new file mode 100644 index 0000000000..1fc5f11e62 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/apps/index.html @@ -0,0 +1,51 @@ +--- +title: 制作Firefox OS应用程序 +slug: Archive/B2G_OS/Apps +translation_of: Web/Apps/Fundamentals +--- +

在Firefox OS设备上运行的应用程序其实就是一个Web应用程序,这样的应用程序完全是由开放的Web技术编写的,比如JavaScript,HTML,以及CSS.我们的网站上几乎包含了你所需要的所有知识和文档,下面仅列出一些只针对Firefox OS的技术文档.

+
+
+

文档和教程

+
+
+ 为Firefox OS编写一个应用程序
+
+ 本篇教程可以让你制作出你的第一个Firefox OS应用程序.
+
+ 提示和技巧
+
+ 我们的开发工程师为你提供的各种提示和技巧(还有问题的解决办法)!
+
+

查看更多...

+
+
+

在社区中寻求帮助

+

如果你在开发应用程序的过程中遇到了问题,而且在文档中无法找到解决办法,那么:

+ +

不要忘了"提问的艺术"...

+

工具

+ +

查看更多...

+ + +
+
+

 

diff --git a/files/zh-cn/archive/b2g_os/apps/writing_a_web_app_for_firefox_os/index.html b/files/zh-cn/archive/b2g_os/apps/writing_a_web_app_for_firefox_os/index.html new file mode 100644 index 0000000000..87fe8d36c7 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/apps/writing_a_web_app_for_firefox_os/index.html @@ -0,0 +1,46 @@ +--- +title: 为Firefox OS写一个web app +slug: Archive/B2G_OS/Apps/Writing_a_web_app_for_Firefox_OS +translation_of: Web/Apps/Fundamentals/Quickstart +--- +

B2G应用是一个使用HTML,CSS以及JavaScript写成的网络应用(Web Apps)。就像你发布网站一样,你把它们发布在网络上。为了让这个网站可以像一个网络应用一样被安装在你的移动设备上,你不得不给他们加一个标识 (manifest)和一个链接的安装按钮,下面会解释。

+

下面的主题被推荐为起点:

+ +

当然,你也可以无拘无束的沉浸在Open Web Apps的深处!

+

安装网络应用(Web app)

+

 

+

当你把应用和标识(manifest)发布到网上,你必须要让Gecko意识到它。在安装时,Gecko会检查标识文件(manifest)并且把其中的重要记录添加到主屏幕(home screen)和其他地方。

+

在安装应用时,调用navigator.mozApps.installAPI。下面是一个安装按钮的例子,你可以把他们嵌入到你的应用中:

+

 

+
<button id="install">
+  安装这个给力的应用在你的主屏幕上
+</button>
+
+<script>
+(function(){
+  function install(ev) {
+    ev.preventDefault();
+    // 定义标识文件的网址(define the manifest URL)
+    var manifest_url = "http://my.webapp.com/manifest.webapp";
+    // 安装这个应用(install the app)
+    var myapp = navigator.mozApps.install(manifest_url);
+    myapp.onsuccess = function(data) {
+      // 应用已经被安装,移出按钮(App is installed, remove button)
+      this.parentNode.removeChild(this);
+    };
+    myapp.onerror = function() {
+      // 应用不能被安装(App wasn't installed, info is in)
+      // installapp.error.name
+     };
+  };
+  //获得按钮的信息并且在按钮被点击的时候调用install()(install() get a reference to the button and call install() on click)
+  var button = document.getElementById('install');
+  button.addEventListener('click', install, false);
+})();
+</script>
+
+

注意:这个安装按钮也可以被放在应用市场(app market)中,比如Firefox Marketplace,但是你也可以在你网站的首页放一个非常方便的“安装应用”的按钮

+

现在使用B2G浏览器app浏览你的网站并且点选安装按钮把。

diff --git a/files/zh-cn/archive/b2g_os/automated_testing/gaia_performance_tests/index.html b/files/zh-cn/archive/b2g_os/automated_testing/gaia_performance_tests/index.html new file mode 100644 index 0000000000..12c0633e43 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/automated_testing/gaia_performance_tests/index.html @@ -0,0 +1,109 @@ +--- +title: Gaia 性能测试 +slug: Archive/B2G_OS/Automated_testing/Gaia_performance_tests +translation_of: Archive/B2G_OS/Automated_testing/Gaia_performance_tests +--- +
+

本文主要讲述了有关在 Gaia 上运行性能测试以及如何创建新的测试。

+
+

运行测试

+

The tests are run on a regular basis on Datazilla; however, you can also run them yourself. To do so, you'll need an engineer build with Marionette enabled and remote debugging disabled. See Gaia Build System Primer, Customizing the preferences for more information on how doing this.

+

测试需求

+

Since bug 915156 landed on December 6th 2013, make test-perf requires Node.js on the host to run the tests. The relevant modules should be installed automatically with npm.

+

Prior to running the test, you need to configure a runner host. The runner host is a module that will either run the test in B2G desktop or on a device (real or virtual — like an emulator). By default it runs in B2G desktop, which is not very relevant for performance. To configure the runner just edit the file local.mk in the Gaia top level directory (create it if it doesn't already exist) and put the following line:

+
MARIONETTE_RUNNER_HOST=marionette-device-host
+

This will use the device host runner. The default value is marionette-b2gdesktop-host.

+

The alternative to this is to do:

+
MARIONETTE_RUNNER_HOST=marionette-device-host make test-perf 
+
+

Note: only one device at a time is supported, either an emulator or real device. Make sure you have an up-to-date Gaia version running on it.

+
+

输出

+

By default the test output the data in JSON format. By default it is output to stdout and might be mixed with error message from other commands like npm. This is not a very good idea for automation. So you can redirect this JSON output to a file. Just define MOZPERFOUT for the host runner, either on the command line as an option or in the local.mk file as shown above.

+
MOZPERFOUT=myfile.json
+

There is a "spec" reporter that allow reporting the output in a more human readable format. To use it, set the environment as follow:

+
REPORTER=ConsoleMozPerf
+

This will make the test output something easier to read. Not easier to parse. There is no real syntax.

+

For now, any other value will use the JSON reporter.

+
+

Note: MOZPERFOUT will be honoured whichever reporter you select.

+
+

对所有 app 运行测试

+

In general you can run these test on 1.4 and up from Gaia master. 1.3 might no longer be able to have the tests runs. There is an exception for 1.3t (Tarako). since bug 1006064 landed, if you want to run the tests against Tarako (1.3t), you should run it from the Gaia 1.3t.

+

From 2.0 and onwards, we consider that you should run the test from the same Gaia tree.

+
make test-perf
+

对指定的 app 运行测试

+
APP=browser make test-perf
+

对多个 app 运行测试

+
APPS="browser communications/contacts" make test-perf
+

Setting the number of runs

+

By default, each test is run five times. You can change that by setting the value of RUNS before running the tests. For example, to run each test three times you'd use this option:

+
RUNS=3 make test-perf
+

已知问题

+

When running test on Buri/Hamachi (Alcatel one touch fire), you get:

+
Not enough fields given the number of keys.
+

You can safely ignore the warning. It is just that b2g-info on the device is too old as it comes from 1.2 and we only change Gecko and Gaia on these.

+

Writing new tests

+

With the details of running the test suite out the way, let's now look at how you can write your own performance tests for Gaia.

+

Startup event tests

+

We have setup a standard for app startup events. If you want to test the app startup, please follow the responsiveness guidelines. The startup_event_test.js test will drive it. Make sure to whitelist your app in /tests/performance/startup_events_test.js, by adding it to the list specified by whitelistedApps. Also as a transition measure, you should add it to  whitelistedUnifiedApps which list the apps that use that new method. Once all the apps will be migrated, then we this will disappear - if you can't find it that mean it is not needed anymore.

+
+

Note: this is only implemented in 2.0 and later. If you code use startup-path-done events then it is using the old style and should be updated.

+
+

If you want to measure intermediate launch stages that are not part of the reponsiveness standard, you can dispatch these using the method described below. Dispatching performance events is all you need, they will be collected automatically.

+

其他的 event 基础测试

+

Now if you want to test specific features in your app you can do so by sending events. The test will be in two part. The instrumentation part that lives in the app itself, and the control part that will use marionette to control the app to perform actions.

+

Instrumentation

+

To record the events, all you have to do is dispatch them.

+

First, include our helper in your app:

+
<script defer src='/shared/js/performance_testing_helper.js'></script>
+
+
+

Note: If you use a module loader like RequireJS or Alameda, you might prefer to use that, which is perfectly fine.

+
+

You need to be cautious and make sure you adjust the unit tests so that the PerformaceTestingHelper is either loaded or shimmed. A simple shim is to put this in the unit test source file:

+
var PerformanceTestingHelper = {
+  dispatch: function() { }
+};
+
+

The Travis CI jobs we run out of Github will error if you don't do that properly.

+

Having done that, you can use the helper to dispatch events when it seems appropriate to do so. First you should dispatch a start event. It is important as the 'start' event is sent when we register the listeners, so for your feature you likely want to do this much later. So choose where the feature start and add the proper event dispatch.

+
PerformanceTestingHelper.dispatch('my-feature-start');
+
+

When you're ready to stop collecting data and to report the numbers, you need to send the my-feature-done event, also called the last event, to tell the helper to finish:

+
PerformanceTestingHelper.dispatch('my-feature-done');
+

Also you might want to send intermediate events as appropriate.

+
+

Note: Here we use "my-feature-" as a prefix for the performance event. This is just an example. Please use an obvious name and try to use it consistently.

+
+

Controlling the app

+

The second part is writing a JavaScript to the test framework to perform the test. The filename must end with _test.js and live in apps/<myapp>/test/performance/.

+

It is a lot like a marionette integration test (based on mocha), but with a few twists: in the setup() function you must inject the helper atom that is being used to collect the performance events.

+
PerformanceHelper.injectHelperAtom(client);
+

You must pass a lastEvent parameter to the PerformanceHelper constructor. This will be the last event on which to wait to test your feature.

+

When calling performanceHelper.reportRunDurations() toward the end you must pass the name of the start event you dispatched, otherwise the measurement will be from the start, ie when we inject the helper atom. An easy to figure out the error is if you see the start event in the results. And in that case you'll the the startup events as well as these will be dispatched too.

+
+

Note: you may want to look at existing test to get a better idea.

+
+

Collecting memory statistics

+

You can collect the memory usage for both the b2g process and the current app. Just do

+
var memUsage = performanceHelper.getMemoryUsage(app);
+

app is the application object. memusage will contain several objects enumerating the memory statistics.

+

Running tests from a non-engineering device

+

If you don't have an engineering build on your phone you'll have to do some additional steps:

+
    +
  1. Clone B2G, and build with ./config.sh DEVICE-NAME (e.g. ./config.sh keon)
  2. +
  3. Build the Gecko part via ./build.sh gecko
  4. +
  5. Connect the phone and flash gecko via ./flash.sh gecko
  6. +
  7. Clone Gaia, and create a file build/custom-prefs.js with content user_pref("marionette.defaultPrefs.enabled", true);
  8. +
  9. Enable Remote Debugging on the phone and run make reset-gaia to reset the phone (or make install-gaia if you trust yourself)
  10. +
  11. Disable Remote Debugging and verify that everything is OK by running adb devices. The device should show up.
  12. +
  13. Now running a perf test should work. Verify via RUNS=1 APP=browser make test-perf
  14. +
+

提交 bug

+

Please file bugs in Bugzilla, product "Firefox OS", component "Gaia::PerformanceTest".

+

参考

+ diff --git a/files/zh-cn/archive/b2g_os/automated_testing/gaia_unit_tests/index.html b/files/zh-cn/archive/b2g_os/automated_testing/gaia_unit_tests/index.html new file mode 100644 index 0000000000..f5d1fb609c --- /dev/null +++ b/files/zh-cn/archive/b2g_os/automated_testing/gaia_unit_tests/index.html @@ -0,0 +1,113 @@ +--- +title: Gaia 单元测试 +slug: Archive/B2G_OS/Automated_testing/Gaia_unit_tests +tags: + - B2G + - Firefox OS + - Gaia + - Mobile + - tests + - 单元测试 + - 构建文档 + - 自动化 +translation_of: Archive/B2G_OS/Automated_testing/Gaia_unit_tests +--- +
+

作为 Gaia/B2G 源码的一部分,我们已经创建了多个可运行的单元测试,来测试 Gaia 和 B2G 的不同方面。本文则讲述了如何来访问它们。

+
+
+

注意: 本文假设您已经完全理解 Gaia 和 B2G 是如何工作的。可参考 Hacking Gaia 来开始学习 Gaia。

+
+

运行单元测试

+

您可以在  B2G desktop 或 Firefox Nightly 上运行单元测试。您也需要最新的 Gaia 仓库。为了能够执行绝大部分功能,您必须要安装 Node.js 和 NPM

+
+

注意: 当在安装 test-agent 依赖时,如果下面的命令会因为一种神秘的错误而失败,可能是由于您的 Node.js/NPM 版本太老了。请阅读 通过包管理器来安装 Node.js 以安装最新的版本,并且将 /tools/test-agent/node_modules 文件夹删掉。

+
+

在 Gaia 仓库中有一个 bin/gaia-test 脚本文件, 可以帮助我们以简单的方式运行测试。

+
+

小心: this script will generate a profile suited for unit tests in profile-debug. If you already have another profile in this directory it will be overwritten. Bug 980496 aims to make this configurable.

+
+

在 Firefox 中启动 test runner

+

This will run the test server and launch your default Firefox as found in the path:

+
bin/gaia-test
+

选择 Firefox 二进制

+

You can export the FIREFOX environment variable to your firefox binary. For example, on MacOS X:

+
export FIREFOX=/Applications/FirefoxNightly.app/Contents/MacOS/firefox
+

Alternatively, you can pass it as argument to bin/gaia-test:

+
bin/gaia-test <gaia directory> <firefox path>
+

使用 B2G Desktop 启动 test runner

+

This will download and launch B2G Desktop:

+
bin/gaia-test -d
+

Run the tests from the Web Interface

+

You can simply click on specific tests and then the Execute button.

+

Run the tests from the command line

+

With the WebSocket server running, and the Test Agent app running in B2G Desktop/Firefox Nightly, run the following command:

+
make test-agent-test
+
+

If you only want to run one app's tests you can specify which via the APP env variable:

+
make test-agent-test APP=calendar
+
+

You can also optionally provide a reporter to format the test output:

+
make REPORTER=List test-agent-test
+
+
+ Note: Not all reporters work, since we currently do not support Doc.
+

Run the tests as you save

+

When the server is running, the tests for a file are run automatically when a file is saved or even just touched:

+ +
+

Note: It watches only existing files so if you create a new file, you have to restart the agent.

+
+

Running tests like TBPL does

+

Gaia unit tests in TBPL are run using a separate runner; this explains how to use it.  Please consult the virtualenv docs if you're not familiar with using a Python virtualenv.

+
virtualenv venv
+source venv/bin/activate
+cd $GAIA/tests/python/gaia-unit-tests
+python setup.py develop
+cd gaia_unit_test
+python main.py --binary /path/to/b2g/desktop/build --profile /path/to/gaia/profile
+
+
+

Note: When specifying the path to the B2G desktop build, you should specify the path to b2g-bin, if it exists, otherwise use b2g.

+
+

The Gaia profile must be made using the following:

+
NO_LOCK_SCREEN=1 DEBUG=1 DESKTOP=0 make
+

By default, this profile will be generated in $GAIA/profile-debug. bin/gaia-test generates the same profile so you don't need to regenerate it if you already run gaia-test.

+

Disabling a gaia unit test in TBPL

+

TBPL uses a blacklist to exclude certain gaia unit tests from being run.  To prevent a test from running in TBPL, add its path to https://github.com/mozilla-b2g/gaia/blob/master/tests/python/gaia-unit-tests/gaia_unit_test/disabled.json.

+

设置您的 Gaia 应用

+

Although this guide should help make things easier, the best way to learn how to write, set up, and run tests is currently still to look at the source code; in particular, take a look at the gallery tests.

+

Using mocks

+

TBD

+

进阶: 脚本在做什么?

+

产生一个 profile

+

You need a profile that is generated by this command:

+
NO_LOCK_SCREEN=1 DEBUG=1 DESKTOP=0 make
+
+

This generates a debug profile in gaia/profile-debug, overriding a previous profile if you already have one.

+ +

启动 WebSocket 服务器

+

Test agent (the test runner) ships with a built in WebSocket server that lets you remotely message the browser or device to queue a test run. Often you will want to develop with time saving features like a file watcher that will run your tests when a test file or implementation changes. To take advantage of these features you need to start the server:

+
make test-agent-server
+
+

Using the WebSocket server provides other tools such as a command line reporter for test results (watch the terminal you ran the command from), a Growl reporter, syntax error notifications, and more.

+

The agent also watches for modifications in files, and automatically runs the associated tests. It runs when you save the test or if you save the tested file (we use the convention where the test filename is the tested filename with _test appended, see below for more examples). It watches only existing files so if you create a new file, you have to restart the agent.

+

在 Firefox OS Nightly 运行单元测试

+

You can launch Gaia in Firefox Nightly with the following commands:

+
cd <path to gaia>
+<path to nightly>/firefox --no-remote -profile <path to gaia>/profile-debug/ http://test-agent.gaiamobile.org:8080/
+
+

Note: In Mac OSX, The profile path should be absolute path

+
+

You can use Firebug or the integrated debugger to debug the tests; use the debugger keyword to break in the debugger.

+

使用 B2G Desktop 运行单元测试

+

Launch Gaia and start the "Test Agent" app. From the Test gent app you can select tests to run from the UI.

+

进阶: test-agent 如何工作?

+

The Test Agent lives in its own Github repository. You can have look there to understand how it works under the hood.

diff --git a/files/zh-cn/archive/b2g_os/automated_testing/index.html b/files/zh-cn/archive/b2g_os/automated_testing/index.html new file mode 100644 index 0000000000..a5c2c58f11 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/automated_testing/index.html @@ -0,0 +1,124 @@ +--- +title: Firefox OS 自动化测试 +slug: Archive/B2G_OS/Automated_testing +tags: + - B2G + - QA + - 测试 + - 自动化测试 +translation_of: Archive/B2G_OS/Automated_testing +--- +

+
+

Firefox OS 仍然处在开发中,在可预见的未来中则会对新的硬件加以支持,如何对其进行测试则显得非常重要。 该页面提供的文档主要是对 Firefox OS 多方面进行测试的信息,包括运行不同的测试,自动化,获取报告以及跟踪等。 

+
+

入门

+
+
+ Firefox OS 中运行测试: 开发者指南
+
+ 这是一个运行测试时入门级的快速开发指南。如果您对 Mozilla 测试和自动化系统没有什么接触,则需要从此处开始。有经验者,则可能对如何运行及怎么运行感兴趣,可以跳过该指南,去学习下面更具体的细节知识。
+
+

Gaia 测试

+

这些文章涵盖了主要的 Gaia 测试套件。

+
+
+ Gaia UI 测试
+
+ 主要针对 Gaia UI 交互和特性的 Python 测试。
+
+ Gaia 集成测试
+
+  基于 Marionette, 针对 Gaia 的 JavaScript 的集成测试。
+
+ Gaia 单元测试
+
+ 无 UI 交互的 Gaia 单元测试; 使用 JavaScript 实现,并不基于Marionette。
+
+ Gaia 性能测试
+
+ 基于内部仪器来测量 Gaia app 性能,是树状的测试框架。
+
+

B2G 测试

+

下面的指南涵盖了多个不同的测试框架,用于测试 B2G 功能的各个方面。

+
+
+ Mochitests
+
+ Gecko 功能和API 测试;基于 HTML & JS。没有与 Gaia 交互。
+
+ Reftests
+
+ Gecko 渲染正确性测试。
+
+ WebAPI tests
+
+ Gecko 基于 JS WebAPI 测试;绝大多数需要一个模拟器。
+
+ xpcshell tests
+
+ Gecko XPCOM APIs 无头绪测试
+
+ B2GPerf
+
+ 基于内部仪器来测量 Gaia app 性能。
+
+ Eideticker
+
+ 提供了基于视频捕捉的 Firefox OS 性能测量。
+
+ 耐久性测试
+
+ 长期运行的重复性测试,用于发现内存泄漏和稳定性问题。
+
+ MTBF 测试
+
+ 这是一个基于 non-restart gaia-ui-test 的测试框架。它会试图找到阻碍长时间运行测试的各种问题点。(当前,它由台湾团队来完成,仍然是一个开发中的测试框架)
+
+ 内存测试 — 即将推出
+
+ Repetitive tests run per-commit to mozilla-central, reporting to https://areweslimyet.com/, designed to find problems with memory usage.
+
+

辅助文档

+

This section provides links to some of the supporting technologies that underpin Mozilla's tests, which you may want to find more information about.

+
+
+ Marionette
+
+ 基于 Selenium WebDriver 的远程测试驱动程序。
+
+ Marionette JavaScript tests
+
+ A node.js-based runner for Marionette.
+
+ Marionette Python tests
+
+ A Python runner for Marionette.
+
+
+

Note: If you want to run Marionette against a production build (to run gaia integration tests, gaia-ui-tests, etc.), you can install Marionette as an extension (this currently only works for 1.3 builds, but more support will be added soon.)

+
+

持续性集成测试和结果报告

+

The following articles cover the continuous integration and result reporting mechanisms Mozilla uses to store and intepret test data.

+
+
+ TBPL
+
+ Understand the tests and builds that run on TBPL.
+
+ Jenkins
+
+ Understand the tests that are run on real devices via Jenkins.
+
+ Datazilla
+
+ Understand which performance tests are reporting to the Datazilla dashboard, and what those tests measure.
+
+ Test execution chart
+
+ A chart showing which tests are being run — on what devices and where — and which platforms are supported for each test.
+
+
+
+  
+
diff --git a/files/zh-cn/archive/b2g_os/building/index.html b/files/zh-cn/archive/b2g_os/building/index.html new file mode 100644 index 0000000000..838fe7c56f --- /dev/null +++ b/files/zh-cn/archive/b2g_os/building/index.html @@ -0,0 +1,185 @@ +--- +title: 构建B2G +slug: Archive/B2G_OS/Building +translation_of: Archive/B2G_OS/Building +--- +
+
+
+

一旦建立B2G的构建系统与完成代码的初始化提取和配置,你就可以生成B2G系统了。

+
+

更新代码

+

在生成B2G系统前,如果这不是你第一次构建B2G, 你也许想要获取最新的代码。要实现这一点,你应该使用下面两个命令更新B2G工具和依赖项:

+
git pull
+./repo sync
+
+

You can update a specific make target's repository by specifying its name:

+
./repo sync gaia
+
+

The repo command has other options available that might be interesting; repo help will give you a lot of information.

+

编译

+
+

Note: Before building, you may want to set up a .userconfig file to customize the build. See Customization with the .userconfig file for details.

+
+

To build Boot to Gecko, simply use the build.sh tool:

+
cd B2G
+./build.sh
+
+

Time for another coffee break, or possibly a nap (especially if this is your first build).

+

编译具体的模块

+

If you want to build just a particular module, such as Gecko, you can specify it by name:

+
./build.sh gecko
+
+

To get a list of the modules you can build, you can do:

+
./build.sh modules
+
+

设置所使用的处理器的核心数

+

By default, the B2G build scripts use the number of cores your system has plus two as the number of parallel tasks to run. You can change this by specifying the -j parameter when running build.sh. This can be handy if you're using your system for other things while building in the background and need to reduce CPU load a bit. It's also handy when you're having build problems, as it can make reading error output from the build process easier if you have just one task going at a time!

+

For example, to build using just two parallel tasks:

+
./build.sh -j2
+
+

The most common use case for this, however, is to prevent builds from running in parallel at all. This makes the output of the process much easier to read, making it easier to sort out build problems. To do this:

+
./build.sh -j1
+
+

若你的编译系统在运行测试的时候出了差错

+

Sometimes (especially after build tool or operating system updates) you'll get weird errors like this when the build system runs its post-build tests:

+
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
+

In this situation, try deleting the gaia/xulrunner-sdk directory and re-pulling the code:

+
rm -r gaia/xulrunner-sdk
+
+

This deletes the downloaded, precompiled copy of XULRunner that the build system retrieves automatically; on your next build, a new copy of XULRunner will be automatically retrieved.

+

已知错误

+

“构建错误!”("Build failed!")

+

如果你得到一个普通的“构建错误”信息,你应该尝试重新连接你的手机到电脑上;有时手机可能会因为各种原因被卸载。

+
+

注意不能在Mac上为Keon配置和构建B2G. 你需要使用Linux来为它构建系统。

+
+

美洲狮(Mountain Lion)特定错误

+
+

1.如果你正在OS X 10.8 “美洲狮”(Xcode 4.4.1或更新)上构建并发生了如下错误:

+
external/qemu/android/skin/trackball.c:130:25: error: 'M_PI' undeclared (first use in this function)
+ 编辑文件: B2G/external/qemu/Makefile.android 并在第78行加上:
+
MY_CFLAGS += -DM_PI=3.14159265358979323846264338327950288   #/* B2G_fix: not finding M_PI constant */
+
+
+ 2. If you are on Mountain Lion and you receive an error during ./build.sh like:
+
+
/System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h:797:9: error: too many #pragma options align=reset
+

Replace all instances of '#pragma options align=reset' with '#pragma pack()' inside /System/Library/Frameworks/IOKit.framework/Headers/usb/USB.h

+
+

未定义符号(Undefined symbols )"_sqlite3_androidopt_handle_pragma" 和 "_sqlite3_androidopt_open"

+

这个错误会在你在OS X 10.7 及更新系统上使用 Xcode 4.5 及更新构建使出现,为解决这个问题,请在external/sqlite/dist/Android.mk文件上应用补丁https://groups.google.com/forum/#!msg/android-building/yAfPyUqCsiQ/7zvICk4GWjYJ

+

KeyedVector.h:193:31: error: indexOfKey was not declared in this scope

+

这个错误在你使用较新的gcc版本时出现,安装gcc/g++/g++-multilib 4.6.x版本。详见使用.userconfig文件自定应.

+
+

社区友情提示: 稍微的修改一下B2G的代码(gcc会告诉你如何改),使用gcc 4.7.x也是可能的,但是这并没有任何的帮助,无论是对于修改的代码还是你会遇到的bug来说。

+
+

arm-linux-androideabi-g++: Internal error: Killed (program cc1plus)

+

如果你见到了这样的信息,很有可能是内存不足造成的,在执行./build.sh之前确保你有足够的可用内存,如果你的系统有4GB RAM应该就可以正常运行。

+

"...is referenced by DSO" error

+

如果在构建模拟器时你得到了这样的信息: /usr/bin/ld: out/host/linux-x86/obj/EXECUTABLES/triangleCM_intermediates/triangleCM: hidden symbol `_XGetRequest' in out/host/linux-x86/obj/STATIC_LIBRARIES/libSDL_intermediates/libSDL.a(SDL_x11dyn.o) is referenced by DSO.

+

你可以通过各种版本的二进制包工具获得,如果你使用Debian Stable,你可以通过安装binutils-gold包来使用gold连接器,注意,binutils已经安装了gold连接器,但是并没有默认使用;binutils-gold就是来做这件事的(让它默认使用)。

+

如果你在编译系统运行测试时遇到编译错误

+

有时,特别是编译工具或操作系统升级之后,在编译系统运行编译后测试时,你会遇到一些奇怪的错误。

+
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的预编译副本,在你下一次编译时,系统会自动恢复一个新的副本。

+

(无法获取)Cannot fetch platform/libcore

+

如果你尝试为Nexus S编译B2G(./config.sh nexus-s)并遇到了libcore相关的错误,那是我们使用开源项目git的缘故,为了解决这个问题,像下面这样检出B2G manifest:

+
git clone https://github.com/mozilla-b2g/b2g-manifest.git
+

在这个仓库中编辑文件 nexus-s.xml, 用一个aosp的入口引用来替换开源git的入口,像下面这个样子:

+
<default revision="refs/tags/android-4.0.4_r1.2"
+              remote="aosp"
+              sync-j="4" />
+

提交这些改变并改变B2G主仓库主分支中的config.sh文件,使你的检出指向你本地修改过的manifest而不是Mozilla提供的:

+
GITREPO=${GITREPO:-"file:///home/path/to/my/b2g-manifest"}
+

clang errors when building with Xcode 5 on Mac

+

If you are building on Mac OS X 10.8 with Xcode 5, you will likely see errors like the following:

+
clang: error: argument unused during compilation: '-include system/core/include/arch/darwin-x86/AndroidConfig.h'
+clang: error: argument unused during compilation: '-U DEBUG'
+clang: error: argument unused during compilation: '-U DEBUG'
+clang: error: argument unused during compilation: '-MF out/host/darwin-x86/obj/EXECUTABLES/obbtool_intermediates/Main.d'
+make: *** [out/host/darwin-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
+

This is because Xcode 5 changes the g++ compiler in /usr/bin, which breaks the build process if you try to use it to compile. In order to work around the problem, edit the following line in build/core/combo/HOST_darwin-x86.mk:

+
HOST_CXX := g++
+

to

+
HOST_CXX := g++-4.6
+ifeq (,$(wildcard /usr/local/bin/g++-4.6))
+ HOST_CXX := g++
+endif
+

Next, you'll want to uninstall gcc, using brew (this assumes you've run the Mac OS bootstrap script — if not, you'll need to complete that step before continuing):

+
brew uninstall gcc-4.6
+

Now reinstall gcc with multilib and c++ support:

+
brew install --enable-cxx https://gist.github.com/artlogic/6988658/raw/aeb9d1ea098274ad3f3fe2637b9df7f308a8a120/gcc-4.6.rb
+

Make sure /usr/local/bin is on your PATH. You can do this temporarily by typing the following into the command prompt:

+
export PATH=/usr/local/bin:$PATH
+

You can make the above change permanent by adding it to the .bash_profile file in your home directory.

+

After you've set your PATH, make sure you can run both of the following commands:

+
gcc-4.6 -v
+
+g++-4.6 -v
+

If either of these commands fail, you may need to relink your gcc using brew with the following command:

+
brew link --overwrite gcc-4.6
+

It's also possible that /usr/bin/c++ is not pointing at clang++ as it should be with Xcode 5 installed. You can determine if it is by typing the following:

+
ls -l /usr/bin/c++
+

It should return something that looks like this:

+
lrwxr-xr-x 1 root admin 7 Sep 19 11:40 /usr/bin/c++ -> clang++
+

If c++ is pointing at something other than clang++, update it with the following commands:

+
sudo rm /usr/bin/c++
+
+sudo ln -s /usr/bin/clang++ /usr/bin/c++
+

Cannot pull files from backup directory

+

This could happen when the USB connection is broken while the script pulls data from device to computer.

+

When you run the script again, you'll probably get the following (the example is for the Peak device):

+
Pulling files from ../../../backup-peak
+cat: ../../../backup-peak/system/build.prop: No such file or directory
+Found firmware with build ID
+Pulling "libaudioeq.so"
+cp: cannot stat `../../../backup-peak/system/lib/libaudioeq.so': No such file or directory
+Failed to pull libaudioeq.so. Giving up.
+
+> Build failed! <
+
+Build with |./build.sh -j1| for better messages
+If all else fails, use |rm -rf objdir-gecko| to clobber gecko and |rm -rf out| to clobber everything else.
+

To solve this, it is not necessary to remove the whole objdir-gecko or out directories. Just remove the backup directory, like this (for the example above):

+
$rm -rf backup-peak
+

Emulator build issues

+

If you are making an emulator build, you need to pay attention to these issues:

+
+

First, note that you shouldn't use the x86 emulator — it is hard to install and not well supported.

+
+

Next, the build-system for the emulator builds both 32bit and 64bit versions of the emulator. As the emulator depends on OpenGL, this means that you need to have both 32bit and 64bit versions of OpenGL libraries installed on your system. See the discussion in bug 897727.

+

There are two ways that you can solve this problem:

+ +

If your linux distro has multilib packages for OpenGL libraries, you can attempt installing them. You might then have to manually create some symlinks.

+

For example, here is the situation on Ubuntu 12.04 LTS x86-64. On this distribution, the libgl1-mesa-dev package cannot be installed simultaneously in x86-64 and i386 versions, but you can have the following combination of packages simultaneously installed:

+
sudo apt-get install libgl1-mesa-dev libglapi-mesa:i386 libgl1-mesa-glx:i386
+

After having run this command, you will still have to manually create some symlinks for the emulator build to succeed:

+
sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
+sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
+

Solution #2: just patch the emulator so it only builds 64bit

+

Just apply this patch to the sdk/ git repository under the B2G repo. This will cause the B2G emulator to only attempt to build the 64bit emulator if you're on a 64bit system, thus avoiding any multilib issues. The 32bit emulator is unused anyway on a 64bit system. This is the simplest solution, until this patch eventually bit-rots.

+

下一步

+

After building, your next step depends on whether you built Boot to Gecko for the emulator or for a real mobile device; see the following articles for details:

+ diff --git a/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/b2g_os_update_packages/index.html b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/b2g_os_update_packages/index.html new file mode 100644 index 0000000000..f1198f2f1f --- /dev/null +++ b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/b2g_os_update_packages/index.html @@ -0,0 +1,477 @@ +--- +title: 创建及获取B2G OS更新包 +slug: Archive/B2G_OS/Building_and_installing_Firefox_OS/B2G_OS_update_packages +translation_of: Archive/B2G_OS/Building_and_installing_B2G_OS/B2G_OS_update_packages +--- +
+

待我慢慢来翻译吧。20190416

+ +

 

+ +

你若想让 B2G OS用户很容易地就能在其设备上进行系统更新,你需要给他们创建一个更新包。

+ +

If you want to allow B2G OS users to easily update the version of the system code on their devices, you need to create an update package for them to use. This article goes through the different types of update package available and covers building the package, hosting the updates (and how the system polls for available updates), and applying and verifying those updates.

+
+ +

Creating and applying an update is split into four steps:

+ +
    +
  1. Building incremental update packages from old version(s) to a new version on a build host.
  2. +
  3. Finding the right update package to download on the client.
  4. +
  5. Downloading the update.
  6. +
  7. Applying the update to existing files on the device.
  8. +
+ +

Each of these steps are covered below.

+ +
+

Note: There are a number of useful tools for building and testing Firefox OS system updates, available at b2g/tools/update-tools.

+
+ +

Prerequisites

+ +

To build and apply updates you must ensure that your build has the updater and associated update tools enabled. By default those are enabled only in userdebug and user variants. You can however force building them by adding the following line to your .userconfig file:

+ +
export B2G_UPDATER=1
+ +

To sign update packages you will need a Java runtime environment (JRE) or Java software development kit (JDK) installed and the java command available in the default path.

+ +

Types of update

+ +

There are two types of updates to know about: FOTA (Firmware Over-The-Air) and Gecko/Gaia OTA (Over-The-Air). Let's look at the differences between them.

+ +

FOTA updates

+ +

We can update the entire B2G OS system through FOTA updates, the technology behind which is shared with the Android project. The locations on the phone's hard drive that can be changed using FOTA updates include the system partition, kernel, modem baseband, recovery image used for updating, or any other file on the device.

+ +

B2G OS does not depend on a particular FOTA client; the interface is abstracted through an API we call librecovery. However, we recommend using the GOTA recovery client (see below for more details), and the discussion here assumes GOTA is being used.

+ +

FOTA update packages mainly consist of a file called update.zip. This package consists of

+ + + +

This format and set of files are the same as those used in normal Android updates, except that B2G OS additionally wraps the update.zip package in a mar wrapper (MAR stands for Mozilla ARchive). This mar wrapper allows an additional level of verification, which is explained below.

+ +

Gecko/Gaia OTA updates

+ +

Alteratively we can update just the Gecko and Gaia files on a B2G OS device, through a mechanism we call Gecko/Gaia OTA updates. All of the Gecko and Gaia files — comprising the core Gecko runtime and the device's user interface — are in the /system/b2g directory on the device. This is the only directory that OTA updates can make changes to.

+ +

Gecko/Gaia OTA updates use the same technology that's used to update the Firefox desktop web browser. Much like the FOTA update.zip packages discussed above, OTA updates consist of a MAR file containing a set of binary diffs and new files needed to update the client to a newer software version.

+ +

The Gecko client verifies the integrity of MARs that it downloads, and MARs can be signed by multiple parties.

+ +

Why have two update technologies?

+ +

OTA updates are not as comprehensive as FOTA updates, but they are a lot more user friendly and easy to apply, and will often be fine for what you need to update:

+ + + +

Of course, if you need to update files outside Gecko/Gaia, you will have to go for the full FOTA package route.

+ +

Let's move on and examine the package building process.

+ +

Building update packages

+ +

Building updates is the process of generating the files needed to update B2G OS clients from version X of the software to a newer version Y. The update package that's needed to update the client depends on what files have changed between version X and version Y.

+ + + +

To generate an incremental update package (for both FOTA and Gecko/Gaia OTA updates), our tools require full builds of both version X and version Y. Full build means that the package includes all the files that are needed to Flash a client. When we produce a full build for version X, we don't know which future versions we will be updating to from versionX . Because of that, we build both full FOTA packages and Gecko/Gaia packages for each version. This allows us to generate either a Gecko/Gaia OTA incremental update, or a FOTA incremental update if needed, between version X and all future versions.

+ +

At a high level, the process of building an update looks like this:

+ +
    +
  1. With software version X + +
      +
    • Generate a complete Gecko/Gaia OTA MAR for the contents of /system/b2g.
    • +
    • Generate a complete FOTA target files zip, optionally signing it, for the device partitions. The target files zip is referenced below as DEVICE-target_files-$VARIANT.$USER.zip, and is a zip containing the files to update the phone directories, including SYSTEM/, BOOT/, etc. A full FOTA update.zip can be generated from the target files zip.
    • +
    +
  2. +
  3. With software version Y +
      +
    • Generate a complete Gecko/Gaia OTA MAR for the contents of /system/b2g.
    • +
    • Generate a complete FOTA target files zip, optionally signing it, for the device partitions. The target files zip is referenced below as DEVICE-target_files-$VARIANT.$USER.zip, and is a zip containing the files to update the phone directories, including SYSTEM/, BOOT/, etc. A full FOTA update.zip can be generated from the target files zip.
    • +
    +
  4. +
  5. If only files in /system/b2g have changed, generate an incremental Gecko/Gaia OTA update MAR from version X to version Y.
  6. +
  7. Otherwise, generate an incremental FOTA update.zip from version X to version Y. Wrap the incremental FOTA update.zip in a MAR for delivery to the B2G client.
  8. +
  9. Sign the packages as required by delivery agreements.
  10. +
+ +

The subsections below describe how to use B2G's tools to implement each of these steps.

+ +
+

Note: the steps below assume that you have already set up a b2g build environment at the location $b2g. The commands below reference the $b2g/build.sh helper script, but make can also be used.

+
+ +

Generating a complete Gecko/Gaia OTA update MAR

+ +

To generate a complete OTA update MAR from the last successful b2g build (e.g. that you built yourself), you need to invoke the gecko-update-full target. To place the MAR at $b2g/objdir-gecko/dist/b2g-update/b2g-gecko-update.mar, use the following commands:

+ +
$ cd $b2g
+$ ./build.sh gecko-update-full
+$ cp objdir-gecko/dist/b2g-update/b2g-gecko-update.mar <destination>
+
+ +

Generating a full FOTA update MAR

+ +

To generate a full FOTA update MAR from the last successful b2g build (e.g. that you built yourself), you need to invoke the gecko-update-fota-full target. This includes the contents of the entire /system partition. Here are the commands you need:

+ +
$ cd $b2g
+$ ./build.sh gecko-update-fota-full
+
+ +

This will generate a ZIP file ($PRODUCT_OUT/fota/full/update.zip) and a MAR file ($PRODUCT_OUT/fota-$TARGET_DEVICE-update-full.mar). The ZIP file can be directly used with adb sideload, while the MAR is intended for distribution in the same manner as any other update package.

+ +

Generating a FOTA update MAR plus recovery package

+ +

As of Firefox OS 2.2 (mid April and beyond) we added a new make target, which can be invoked as follows:

+ +
$ cd $b2g
+$ ./build.sh gecko-update-fota-fullimg
+ +

This is used to produce a recovery package that will dump a set of partitions images. The default set is controlled by the variable B2G_FOTA_FULLIMG_PARTS, defined in gonk-misc/Android.mk (along with most of the other new features seen below.) It's a space-separated string of mountpoint:image instances to include. The default value is "/boot:boot.img /system:system.img /recovery:recovery.img /cache:cache.img".

+ +

Along with this we have also introduced some new environment variables to control the production of the two other make targets — gecko-update-fota and gecko-update-fota-full:

+ + + +
+

Note: All of these new features heavily rely on having a proper recovery.fstab file provided for the device in question.

+
+ +

Generating a partial Gecko/Gaia FOTA update MAR

+ +

A partial FOTA update uses the same mechanism as a full FOTA update, but by default only includes Gecko/Gaia updates like a regular OTA update. Additional files outside of Gecko/Gaia (such as fonts) can also be included.

+ +

The rationale for generating a partial FOTA update package is mainly related to licensing issues: when building a complete FOTA update package, the whole system partition (at least) will be included. This may include blobs that you don't have the authorization to redistribute. However, since MAR distribution is useful and Gecko/Gaia themselves are free software, there is no reason we should not be able to distribute them in this manner. A partial FOTA allows you to only update a subset of the system. An OTA update could be used instead in this scenario but it does come at a cost: OTA updates require enough space on the system partition to hold both the existing Gecko/Gaia files as well as the unpacked update files. A partial FOTA update does not suffer from this limitation as it can overwrite the existing files with the updated ones.

+ +

To create a partial FOTA update from the last successful b2g build (e.g. that you built yourself), Invoke the gecko-update-fota target with the following commands:

+ +
$ cd $b2g
+$ ./build.sh gecko-update-fota
+
+ +

This will generate a ZIP file ($PRODUCT_OUT/fota/partial/update.zip) and a MAR file ($PRODUCT_OUT/fota-$TARGET_DEVICE-update.mar). The ZIP file can be directly used with adb sideload, while the MAR is intended for distribution in the same manner as any other update package.

+ +

The construction can be controlled with a couple of environment variables, the most useful of which are documented below:

+ + + + + + + + + + + + + + + + + + + + + + +
VariableMeaning
$B2G_FOTA_DIRSSpace-separated list of directories to include in the update. Defaults to system/b2g.
$TARGET_UPDATE_BINARYBinary used to execute the Edify script inside the package. When none is provided, a pre-built updater binary from ICS is used.
$FOTA_FINGERPRINTSComma-separated list of Android fingerprints to check against. The use case is to be able to distribute Gecko/Gaia update packages on top of a controlled Gonk base system that we cannot legally distribute. For example, Open C community builds are using this.
+ +
+

Note: A complete set of these variables is defined in the Android.mk file of the gonk-misc repository; note that $FOTA_FINGERPRINTS is used in our update_tools.py tool.

+
+ +

Generating a complete FOTA target files zip

+ +

Invoke the target-files-package target to build a target files zip that can be used to generate both incremental and full FOTA update packages. The target files zip can also be signed by custom keys to ensure that only FOTA updates from known sources can be installed. After signing target files, all images and updates (also OTA) need to be generated again to catch the inserted keys.

+ +
+

Note: The target files zip is generated in the location out/target/product/$DEVICE/obj/PACKAGING/target_files_intermediates/$DEVICE-target_files-$VARIANT.$USER.zip

+
+ +

The following commands will carry out this step:

+ +
$ cd $b2g
+$ ./build.sh target-files-package
+$ cp out/target/product/$DEVICE/obj/PACKAGING/target_files_intermediates/$DEVICE-target_files-$VARIANT.$USER.zip <destination>
+
+ +

The variable values in the commands listed above should be filled in as follows:

+ + + + + + + + + + + + + + + + + + + + + + +
VariableMeaning
$DEVICEDevice name for the AOSP product
$VARIANTeng, user, or userdebug
$USERThe build username
+ +

Signing a complete FOTA target files zip

+ +

Proper releases should typically be signed by custom release keys only known to the vendor. Having such keys will prevent FOTA updates where the source is unknown from being installed, hence introducing an extra security layer. For this to work, the images flashed to a device need to include public keys while the updates need to be signed by the corresponding private key. 

+ +

The first step is to generate custom keys and store them in a safe place. The Android Open Source Project has a script for generating these keys. For full compatibility, get this script from the branch corresponding to the Gonk version of the device in question. Here is the master branch version.

+ +

A couple of keys are needed — create them with the following commands. releasekey is the key to use for signing FOTA update packages.

+ +
$ development/tools/make_key releasekey '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
+$ development/tools/make_key platform '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
+$ development/tools/make_key shared '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
+$ development/tools/make_key media '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
+
+ +

With keys present, the target files zip can be signed using the following commands. This will insert the public keys and modify build properties to reflect the fact that it has been signed.

+ +
$ cd $b2g
+$ ./build/tools/releasetools/sign_target_files_apks \
+  --default_key_mappings $RELEASEKEY_FOLDER \
+  --replace_ota_keys \
+  --signapk_path prebuilts/sdk/tools/lib/signapk.jar \
+  $UNSIGNED_TARGET_FILES_ZIP \
+  $SIGNED_TARGET_FILES_ZIP
+ +

The variable values in the commands listed above should be filled in as follows:

+ + + + + + + + + + + + + + + + + + + + + + +
VariableMeaning
$RELEASEKEY_FOLDERThe path to the folder containing the custom keys
$UNSIGNED_TARGET_FILES_ZIPThe FOTA target files zip to sign.
$SIGNED_TARGET_FILES_ZIPThe signed FOTA target files zip to be generated
+ +

Generating an incremental OTA update MAR

+ +

In this example, we're assuming that we're generating an update from software version X to version Y. The location of the full Gecko/Gaia OTA MAR built from software version X using the instructions above will be called $MAR_X below. This might be a path on a build server like /home/build/b2g/versions/X/update.mar. Similarly, the location of the full MAR built from version Y will be called $MAR_Y.

+ +

The tool build-gecko-mar.py will generate an incremental Gecko/Gaia OTA update MAR using $MAR_X and $MAR_Y. We'll call the destination of the generated file $GENERATED_INCREMENTAL_MAR_X_Y. Use the following commands for this step:

+ +
$ cd $b2g
+$ ./tools/update-tools/build-gecko-mar.py --from $MAR_X --to $MAR_Y $GENERATED_INCREMENTAL_MAR_X_Y
+
+ +

Generating an incremental FOTA update zip

+ +

In this example, we're assuming that we're generating an update from software version X to version Y. The location of the full FOTA target zip built from software version X using the instructions above will be called $TARGET_FILES_X below. This might be a path on a build server like /home/build/b2g/versions/X/target_files.zip. Similarly, the location of the full FOTA target zip built from version Y will be called $TARGET_FILES_Y.

+ +

The tool build/tools/releasetools/ota_from_target_files will generate an incremental FOTA update.zip using $TARGET_FILES_X and $TARGET_FILES_Y. We'll call the destination of this intermediate file $INTERMEDIATE_FOTA_UPDATE_FOTA_X_Y.

+ +

After this update.zip is generated, the last step is to wrap it in a MAR for delivery to the B2G client. The tool tools/update-tools/build-fota-mar.p does this step. We'll call the destination of this generated file $GENERATED_INCREMENTAL_FOTA_X_Y.

+ +

Use the following commands to complete this step:

+ +
$ cd $b2g
+$ ./build/tools/releasetools/ota_from_target_files -v \
+    --incremental_from $TARGET_FILES_X \
+    --signapk_path prebuilts/sdk/tools/lib/signapk.jar \
+    --package_key $FOTA_SIGNING_KEY \
+    $TARGET_FILES_Y \
+    $INTERMEDIATE_FOTA_UPDATE_FOTA_X_Y
+$ ./tools/update-tools/build-fota-mar.py $INTERMEDIATE_FOTA_UPDATE_FOTA_X_Y --output=$GENERATED_INCREMENTAL_FOTA_X_Y
+
+ +

The variable values in the commands listed above should be filled in as follows:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableMeaning
$TARGET_FILES_XThe FOTA target files zip for version X
$TARGET_FILES_YThe FOTA target files zip for version Y
$INTERMEDIATE_FOTA_UPDATE_FOTA_X_YA temporary update.zip to generate a MAR from
$GENERATED_INCREMENTAL_FOTA_X_YThe destination incremental update zip wrapped in a MAR for delivery to clients
$FOTA_SIGNING_KEYPath to the prefix for a private key and public cert for signing the update zip. $FOTA_SIGNING_ZIP.pk8 and $FOTA_SIGNING_ZIP.x509.pem should both exist on the file system. If $TARGET_FILES_X is not signed this option can be omitted; the default testkey will still be picked up. In case $TARGET_FILES_X is a custom release key, refer to the target files zip signing section on how to create it, and don't forget to sign $TARGET_FILES_Y.
+ +

Hosting updates and polling for updates on the client side

+ +

B2G OS clients poll for updates by fetching and parsing an update manifest: update.xml. B2G OS clients are configured to poll for updates on specific servers — they query a specially-constructed path on the server. HTTPS is the recommended protocol that the client uses to query the server, however HTTP is also supported. The server and path polled by clients can be changed by shipping an update to existing clients that changes the polling code.

+ +

In the examples below, we'll assume that updates are hosted on the server updates.b2g.com.

+ +

The URL polled by the client commonly contains the following parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterExplanation
PRODUCT_MODELThe name of the device model. This is the ro.product.model value in the B2G property database.
CHANNELThe update "channel". This is useful for testing: servers can be configured to host, for example, "nightly", "beta", and "release" channels.
VERSIONThe client's software version. For example, "18.0.2".
BUILD_IDA unique ID such as a timestamp, configured for a particular build.
+ +

The Firefox client uses the value of its configured update host and these values to construct a URL to poll at runtime. The structure is as follows:

+ +
https://aus4.mozilla.org/update/3/%PRODUCT%/%VERSION%/%BUILD_ID%/%PRODUCT_DEVICE%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/update.xml
+ +

A real example of such a URL is as follows:

+ +
https://aus4.mozilla.org/update/3/B2G/37.0a1/20141214040212/flame/en-US/nightly-b2g37/Boot2Gecko%202.2.0.0-prerelease%20%28SDK%2019%29/default/default/update.xml?force=1
+ +

If the server returns a "404 Not Found" in response to the client's request, then there is no update available. If the server returns a "200" and a manifest file, then there may be an update available. The manifest describes the newly available build; that is, the build the client would update to. An example manifest is:

+ +
<?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"
+          isOSUpdate="true">
+    <patch type="partial" URL="https://updates.b2g.com/release/unagi1/18.0/20121203123456/update.mar"
+           hashFunction="SHA512" hashValue="5111e033875752b7d9b32b4795152dea5ef954cb8a9d4a602dd19a923b464c43521287dcb5781faf3af76e6dc5e8a3dd9c13edea18c1f2c8f3bd89e17d103d6f"
+           size="41901319"/>
+  </update>
+</updates>
+
+ +

This follows the same schema as the B2G build manifest (see updates.xml Format for more details). The fields in the manifest describe:

+ + + +
+

Note: There is a useful update script available at build-update-xml.py, which given a MAR file, builds a B2G OS update.xml for testing.

+
+ +
+

Note: The client device or the user may wish to decline an update.

+
+ +
+

Note:  isOSUpdate="true" is needed for FOTA updates but not for OTA updates.

+
+ +

Using the mechanisms described above, servers can host update packages to update any old client version to the newest version. Or they may host only a "linear update history" in which clients must upgrade through a single path.

+ +

The details of the interaction between build servers and the update host is currently beyond the scope of this document. It is highly dependent on the production environment. You can find some more details on our Software Update wiki page.

+ +

Verifying and applying updates

+ +

After a B2G OS client has successfully polled for an update (handled from within the system), downloaded it, and verified the integrity of the downloaded update package, the final step is to apply the update.

+ +

The first step in applying an update is to verify the signatures embedded in the MAR packages (see Generating an incremental FOTA update zip for how these are created). This is done by the B2G OS client itself after checking the integrity of the downloaded package. The code used for this is the same for both FOTA and Gecko/Gaia OTA updates.

+ +
+

Note: It is not the MAR file that gets signed: it's the FOTA zip file that gets bundled into the MAR that's signed by build/tools/releasetools/ota_from_target_file. The signing of the FOTA update works the same as it does on Android; if you just run the script without specifying the key, it will use the developer key at build/target/product/security/testkeys.*. This is ok for testing but when you create a real update you need a secure key — i.e. one that no-one else knows about. The device will also verify that signature before applying the patch, so a device's initial images will need to contain the key as well.

+
+ +
+

Note: The keys referred to above are found in the Android build systems; we've forked it in our platform_build repo.

+
+ +

After signatures are verified, the process of applying an update diverges between Gecko/Gaia OTA updates and FOTA updates. Let's look at the differences between the two at this point.

+ +

Applying Gecko/Gaia OTA updates

+ +

The B2G OS client applies these using the updater binary. This is part of the Gecko distribution and is the same code used to apply updates to desktop Firefox. As described above, the update is applied while the B2G OS client continues to run normally. Users are able to make and receive calls, run apps, browse the web, etc. while updates are being applied.

+ +

The specific details of the updater binary are beyond the scope of this document, but it works approximately like so:

+ + + +

After the b2g process finishes restarting, the user will be running the new version of the B2G client software.

+ +

Applying FOTA updates

+ +

The FOTA client applies these. The Gecko client "hands off" the update to be applied by calling into the librecovery API. What happens after this step is specific to each FOTA client.

+ +

In the implementation of librecovery used for the GOTA client, the downloaded update package is staged to be applied and special commands are enqueued for the recovery client. librecovery then reboots the device into recovery mode. The recovery client then runs the update script in the update.zip to update files and partitions as needed. The recovery client may need to reboot multiple times in order to update all files.

+ +

After the final reboot, the device will be running the new version of the B2G OS client software.

diff --git a/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_overview/index.html b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_overview/index.html new file mode 100644 index 0000000000..7e27a80e43 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/firefox_os_build_overview/index.html @@ -0,0 +1,105 @@ +--- +title: Firefox OS 的编译综述 +slug: Archive/B2G_OS/Building_and_installing_Firefox_OS/Firefox_OS_build_overview +translation_of: Archive/B2G_OS/Building_and_installing_B2G_OS/B2G_OS_build_process_summary +--- +
+

构建和安装Firefox OS火狐操作系统需要消耗大量的时间,网络带宽,和计算机硬件配置。不幸的是,编译过程中很容易发生错误。本文档大致描述了构建过程及步骤来帮助用户们了解概况。每个步骤的详细信息会在相应的链接页面中给出。

+
+
+

注意: 在Firefox OS火狐操作系统的构建过程中会多次引用到“B2G”或“Boot2Gecko”这个词。 “Boot2Gecko”是Firefox OS项目的始称。

+
+

构建的目标:四个“映像”文件

+

构建过程的总体目的是构建四个可以复制到Firefox OS设备的文件。

+ + + + + + + + + + + + + + + + + + + +
boot.img(启动映像)包含Linux内核和一个主文件系统映像,后者提供一套精简可用的Unix工具。
system.img(系统映像)包含Firefox OS火狐操作系统的核心,包括了Gonk的一部分,Gecko的接口以及B2G的可执行文件。
userdata.img(用户数据映像)包含Gecko的概要界面和设备上的Gaia风格的web应用程序。
recovery.img(还原映像)包含一个Linux内核和一个主文件系统映像,后者附带一个能够让用户修复错误安装的简单工具。
+ +

一旦创建了这四个映像文件,就可以将它们转移到设备里了。

+

Firefox OS 火狐操作系统是建立在Android开源项目(AOSP)的基础之上的。AOSP 的工具—— adbfastboot (快速启动工具)提供了强大的方式来访问和操作设备。很显然,比如,命令行指令 adb reboot-bootloadr 能够使得被控设备重启并停留在bootloader(引导程序)的前期,此时再通过命令行指令 fastboot flash $partition $image 可以把映像文件复制到设备中。

+

启动映像

+

启动映像(boot.img)是由 Linux 内核和一个包含了核心软件和初始化脚本的根分区组成。后者将被复制到设备内存中以便设备的调用,因此被称为“虚拟内存盘”(或者是RAM盘,译者注)。启动映像将被复制到设备的“boot”分区,而设备的文件系统运行时,可以通过工具在根目录下访问RAM盘的内容,比如使用 adb shell访问

+

启动映像还将在根目录的 default.prop 文件中建立超级用户(root user)的权限。

+

启动映像是可以进行修改的——通过检查该文件,再把文件拆分为内核部分和虚拟内存盘映像,提取、修改原先的虚拟内存盘映像中的内容并重新组合为一个能运行的 boot.img 文件。看看这个例子: Alcatel One Touch Fire Hacking (Mini) Guide (无中文)。

+

在被刷入设备之前,可以通过“旁加载”的方法来测试启动映像;启动设备,并停留在bootloadr引导加载程序阶段,然后使用命令fastboot boot /some/path/to/boot.img从启动映像中加载启动并进行测试,这样就不需要安装这个启动映像来进行测试了。

+

系统映像

+

系统映像 (system.img) 提供了 Firefox OS 火狐操作系统的核心:

+ +
+

请参阅 the Firefox OS platform 指南以获得更多关于平台体系结构详细信息。

+
+

系统映像将会被复制到设备的 system(系统分区上,并在设备运行时存取到文件系统上的 /system/ 目录中。

+
+

注意: 系统映像也同样提供了设备所需要的二进制文件,最常见的就是手机无线电模块的 RIL (无线电接口

+
+

用户数据映像

+

用户数据映像(userdata.img提供了设备运行时加载的Gaia应用。

+

用户数据映像将被复制到设备的 userdata 分区上,并在设备运行时存取到文件系统上的 /data/ 目录中。很显然,在 /data/b2g/ 目录中包含了用户设备的 Mozilla Gecko 配置。而 /data/local/webapps/ 目录里包含了真实的给用户使用的网络应用程序

+

还原映像

+

还原映像 (recovery.img含有一个一模一样的内核和一个与当前启动映像类似的虚拟内存盘。可是还原映像使用了一个不同的初始化脚本,当用户使用设备上的硬件按钮时,这个脚本将触发一系列还原命令。

+

还原映像将被复制到设备的 recovery 分区上,这是个文件系统在正常启动时不会被挂载的分区。

+

构建的步骤:准备、配置、构建、安装

+

Firefox OS 的整个编译安装过程分为四个步骤:

+ + + + + + + + + + + + + + + + + + + +
准备获取所有编译过程中用到的工具和程序,比如说合适的编译器和库文件。
配置下载源代码,并创建.configure 文件,这个文件用于定义与编译相关的环境变量 ,包括定义路径和变量
构建构建用户的 Gecko 配置文件和设备的 Gaia 网络应用程序。
安装在设备上安装文件
+ +

 

+

准备

+

最初的准备必须做好,以确保在编译时能够备齐所需的全部软件,比如编译器和编译工具。

+

这个步骤可以手动操作或者使用脚本自动执行。详细请参考 Firefox OS build prerequisites (未翻译)页面。

+
+

注意: 在 Unix 系统或者 类 Unix 系统的机子上,所需的软件可以把它们的程序名作为指令参数使用 unix 的命令行的  which 命令来查找得知。

+
+

配置

+

真正编译始于获取 Firefox OS (或者 B2G)的副本,可以通过在Git上克隆(clone)B2G项目完成。构建配置的过程既包括获取所有构建所需的源代码副本的过程;也包括创建 .config 文件的过程。

+

这需要运行一个 config.sh 脚本。详细请参考 Preparing for your first B2G build (未翻译)页面。

+

配置脚本需要指定构建设备的类型参数,构建名字是指与CPU的架构相关的代号(code names)而不是特定的设备,并且暂时无法指定某个构建过程与具体某个物理设备相对应。可用的代号列表见这里(未翻译)。

+

在配置过程中还会用到AOSP项目的repo工具,用于下载或更新构建过程中所需代码的副本。不同版本的副本会保存在.repo/projects目录下。配置过程将下载大量数据,这需要花费很长的时间。

+

构建

+

构建这一步骤将编译所有源文件,并生成映像文件。

+

这需要运行 build.sh脚本。详细请参考 Building Firefox OS 页面。

+

默认情况下,工具会对所有代码进行尝试构建,从AOSP项目工具到Linux内核,再到Gaia层的网络应用程序。因为这个构建过程是一个整体过程,所以有时当编译失败后,会不知道失败在哪一步。

+

当然为了避免上述情况的发生,也可以只构建整个代码某一特定的部分。比如,Gecko系统部分只在调用有 gecko 参数的构建脚本时才被构建。同样对于Gaia部分也是如此。后面的章节将解释如何在分开编译完成后再安装这些部分到设备上去。

+

同样也可以构建本章在第一部分所提到的几个映像文件。比如说,可以通过命令  ./build.sh out/platform/$target/system.img,构建系统映像system.img,这里 $target 参数要和配置过程中保持一致。

+

安装

+

通过运行脚本 flash.sh将最新编译的代码安装到设备上。

+

独立分开构建的部分可以通过在脚本中添加相应参数进行安装。比如,可以通过指令./flash.sh gaia.只安装Gaia部分的网络应用程序。

diff --git a/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/index.html b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/index.html new file mode 100644 index 0000000000..5adf2904fe --- /dev/null +++ b/files/zh-cn/archive/b2g_os/building_and_installing_firefox_os/index.html @@ -0,0 +1,70 @@ +--- +title: 编译及安装Firefox OS火狐操作系统 +slug: Archive/B2G_OS/Building_and_installing_Firefox_OS +translation_of: Archive/B2G_OS/Building_and_installing_B2G_OS +--- +
+

Firefox OS火狐操作系统正在紧张地开发之中,目前还未正式发布(2013年2月底已向媒体展示实体手机样机),因而保证你能有最新安装版的最优方法,是搭建并安装一个你自己的版本。本页列出的文章将指导你怎样在仿真器或兼容设备上构建和安装Firefox OS,以及火狐浏览器的Gaia用户界面。

+
+ + + + + + + +
+

获取和构建 Firefox OS

+
+
+ Firefox OS 的构建综述
+
+ 构建和安装Firefox OS火狐操作系统需要消耗大量的时间,网络带宽,和计算机硬件配置。此部分将大致描述构建的过程、步骤以及目标,帮助用户自行进行构建。
+
+ 构建 Firefox OS 之前
+
+ 第一次构建 Firefox OS 之前所需要了解和准备的工作。
+
+ 构建 Firefox OS 的准备
+
+ 构建 Firefox OS,你需要获取源代码并配置构建过程所需要的参数。本篇文章将告诉你该怎么做。
+
+ 构建 Firefox OS
+
+ 如何构建Firefox OS。
+
+ 移植 Firefox OS
+
+ 关于如何移植 Firefox OS 到新的设备中。
+
+

全部内容...

+
+

安装 Firefox OS 或者 Gaia

+
+
+ 选择如何运行 Gaia 或 Firefox OS
+
+ 你可以在火狐浏览器中使用 Gaia ,可以在手机上的 Firefox OS 中,也可以在桌面模拟器上。本篇文章将帮助你做出选择。
+
+ 在 Firefox 中使用 Gaia
+
+ 如何在桌面火狐浏览器中使用Gaia。
+
+ 使用 Firefox OS 桌面客户端
+
+ 本篇文章指导你使用桌面客户端版本的Firefox OS;桌面客户端将 Gaia 环境模拟成一个桌面应用程序。这个模拟比在火狐浏览器中使用Gaia要真实,但没有使用模拟器的效果好。
+
+ 使用 Firefox OS 模拟器
+
+ 本篇文章将指导你构建和使用Firefox OS模拟器,以及选择不同的模拟器。
+
+ 在移动设备上安装 Firefox OS
+
+ 如何在手机设备上安装 Firefox OS。
+
+ 在 SGS2 上 实现 Firefox OS 和 Android 双系统引导
+
+ 在三星 Galaxy S2上如何设置Firefox OS和Android双系统启动环境。
+
+
+

 

diff --git a/files/zh-cn/archive/b2g_os/building_the_b2g_desktop_client/index.html b/files/zh-cn/archive/b2g_os/building_the_b2g_desktop_client/index.html new file mode 100644 index 0000000000..89b2385295 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/building_the_b2g_desktop_client/index.html @@ -0,0 +1,262 @@ +--- +title: Building the B2G desktop client +slug: Archive/B2G_OS/Building_the_B2G_desktop_client +translation_of: Archive/B2G_OS/Building_the_B2G_OS_simulator +--- +
+

The B2G OS simulator 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 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. This article covers downloading or building the Firefox OS simulator, as well as how to use it.

+
+ +
+

Note: The easiest way to use the Firefox OS desktop client is to use the Firefox OS Simulator add-on via WebIDE. It does not require you to build the simulator yourself.

+
+ +

Download nightly builds

+ +

Just like Firefox Nightlies, the B2G OS simulator desktop client (identified by b2g-) is automatically built every day from the latest source code. The latest build is available from the Mozilla FTP server. Be sure to pick the latest version and the right archive for your operating system. This lets you bypass having to build it yourself. In addition, you don't have to download Gaia on your own either.

+ +

Be sure to install the application in a writeable location; the application needs to be able to update the included Gaia profile.

+ +

You can now skip ahead to Running the simulator, unless you actually want to build it for yourself. This is necessary if you want to make and test changes to the codebase.

+ +

Building the simulator

+ +

The first thing you need to do is set up a standard Mozilla build environment. Once you have that, you can pull down the code you'll need and configure it to build the Firefox OS desktop client.

+ +

Downloading the code for the first time

+ +

In a directory where you'd like the source code to go, clone the mozilla-central repository that contains all of Gecko:

+ +
 hg clone http://hg.mozilla.org/mozilla-central
+ +

Alternatively, you can download the same code from Github:

+ +
 git clone https://github.com/mozilla/gecko-dev
+ +

Updating the code

+ +

When you do subsequent builds, you should make sure to pull in the latest changes:

+ +
cd mozilla-central
+hg pull -u
+
+ +

or

+ +
cd gecko-dev
+git pull
+
+ +

Create a mozconfig

+ +

Next, you need to create a file called .mozconfig in the mozilla-central directory to configure the build system to build the Boot to Gecko client instead of Firefox. This file should contain the following:

+ +
. "$topsrcdir/b2g/config/mozconfigs/common"
+
+mk_add_options MOZ_OBJDIR=../build # This line should be commented if you use gecko-dev or mozilla-central
+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
+ +

You also need to include the line ENABLE_MARIONETTE=1 in the file if you want to run Mochitests in the B2G desktop client (either mochitest-b2g-desktop or mochitest-plain) or if you want to run Gaia unit tests.

+ +

Building

+ +

Now you can build the desktop client with the following command (run this from inside the mozilla-central directory):

+ +
./mach build
+
+ +

The built client will be placed in the objdir/dist/bin directory (based on the value you specify for MOZ_OBJDIR in the mozconfig file).

+ +
+

Note: If you have any trouble first check the dependencies.

+
+ +

Downloading Gaia

+ +

By default the simulator desktop client will show an empty screen because it doesn't know which web app to load initially as the system app. The collection of system apps and default apps that come with Firefox OS — Gaia — needs to be downloaded.

+ +

To download Gaia for the first time, clone the source code repository on GitHub:

+ +
git clone https://github.com/mozilla-b2g/gaia
+cd gaia
+ +

To update an already existing clone of Gaia, you can pull in the latest changes from GitHub:

+ +
cd gaia
+git pull
+
+ +

Creating a custom-settings.json

+ +

If you know what you're doing and you want to set various config options you can create the file gaia/build/config/custom-settings.json and add them there, for example:

+ +
{
+  "lockscreen.enabled": false,
+  "lockscreen.locked": false,
+  "devtools.debugger.remote-enabled": true
+}
+ +

This example is useful for bypassing the lockscreen, which is otherwise impossible to bypass on desktop because it can't be unlocked using a mouse or trackpad.

+ +

Generating a profile

+ +

Next we need to set up Gaia's apps for the desktop simulator. This includes packaging the Gaia apps in the same way as they would be installed on the device, as well as setting up the permissions for the privileged system apps. We do this by generating a profile. The following command (run in the downloaded gaia directory) will take care of that:

+ +
make DESKTOP_SHIMS=1 NOFTU=1 DEBUG=1
+
+ +

This should create a profile-debug directory below the gaia directory. The new profile contains a customized extension and other configuration details needed to make B2G run properly.

+ +
+

Note: There is currently a bug (bug 1180103) that causes Gaia debug profiles to render with an empty homescreen when run through the Firefox OS Simulator (through WebIDE, or whatever.) This can be worked around by building with DEBUG=1 DESKTOP=0 make instead of DEBUG=1.

+
+ +

Running the simulator

+ +

Once you've built the client (or downloaded and installed the nightly desktop application) and downloaded Gaia , you're ready to fire up the simulator.

+ +

Running on Linux

+ +

To run the simulator on Linux using the embedded Gaia profile, just run the b2g executable. The binary is in the archive you downloaded earlier or in the objdir/dist/bin directory if you built the client yourself.

+ +
b2g -profile gaia/profile-debug
+
+ +

You may experience annoying rendering problems. To avoid them, add the following line to your gaia/profile/user.js file:

+ +
user_pref("layers.acceleration.disabled", true);
+
+ +

Running on Mac

+ +

If you downloaded the Nightly build, you can simply launch it from the Finder as usual. Any console output is visible by running the standard Console utility program included with your Mac.

+ +

If you want to specify a different Gaia profile (such as your separate download Gaia from above), you need to bypass the b2g wrapper program and run the b2g binary. The command line is slightly more complicated due to the location of the b2g binary and the need for absolute paths when specifying the profile directory:

+ +
.../B2G.app/Contents/MacOS/b2g-bin -profile /full/path/to/gaia/profile-debug
+
+ +

Running on Windows

+ +

Running the Nightly build on Windows is as simple as launching b2g.exe. If you want to customize the execution, you can do so by running the b2g.exe executable instead; this bypasses the wrapper program that automatically uses the bundled Gaia.

+ +

Command line options

+ +

There are a number of command line options you can use to adjust the runtime experience while using the desktop simulator. You can get a list by using the -help option. This section covers some of the particularly interesting ones.

+ +

Specifying the screen size

+ +

You can specify the screen size of the device you want to simulate using the -screen option:

+ +
b2g -screen <width>x<height>@<dpi>
+ +

Where <width>, <height>, and <dpi> are fairly self-explanatory parameters: the width and height of the device's screen in pixels and the device resolution in DPI. Here's some real examples:

+ +
b2g -screen 320x480
+b2g -screen 320x480@160
+
+ +

Optionally, you can specify certain devices by name to simulate their screen size and resolution:

+ + + +

These preset devices are defined in screen.js.

+ +

In order to select different screen you probably have to specify the profile path as follow:

+ +
+

./b2g-bin --profile ./gaia/profile/ --screen=galaxy_tab

+
+ +

Opening the JavaScript console

+ +

You can open the JavaScript console when launching the desktop simulator by launching it from the command line with the -jsconsole flag. After building, just do:

+ +
.../b2g -jsconsole -profile /path/to/your/profile
+ +

If you've installed the Nightly build on a Mac, you can do the following:

+ +
/Applications/B2G.app/Contents/MacOS/b2g -jsconsole -profile /path/to/your/profile-debug
+ +
+

Note: On production builds of Firefox OS, console logging (for example console.log()) is disabled by default. In order to enable it, open the Developer settings and enable the Console Enabled preference.

+
+ +

Launching a specific application at startup

+ +

You can specify an application to be launched automatically when b2g starts up in the simulator. This is done as soon as the rest of the system is done loading up. To do this, just use the -runapp option, which takes as a parameter the name of the application to run. For example:

+ +
 .../b2g -profile /path/to/your/gaia/profile-debug -runapp email
+ +
+

Note: The specified name is normalized by converting it to all lower case and removing all dashes and spaces. This normalized name is then compared to similarly normalized names from the manifests of available apps' manifests. For example, the name of the email app is currently "E-mail", but -runapp email will work because of this normalization.

+
+ +

If you specify the -runapp option without an argument, or with an empty argument, the simulator will output to your terminal a list of the known applications as well as a brief usage message.

+ +
+

Note: Using the -runapp option disables the lock screen as a side effect and does not re-enable it. It's assumed that you won't use this command on a profile on which you will be testing the lock screen, or you will turn it back on manually using Settings > Screen Lock. Feel free to contribute a patch to change this behavior if it's a problem.

+
+ +

Usage tips

+ +

This section provides a few helpful tips to using the B2G desktop client.

+ + + +

Troubleshooting: A blank screen when the simulator starts

+ +

When you start b2g using b2g -profile gaia/path/to/gaia/profile a blank screen may show up along with an error "Cannot reach app://system.gaiamobile.org". To fix this there are a couple of things you can check:

+ + + +

Next steps

+ +

Now that you have a simulated build of Boot to Gecko running, you can do testing, development, and other work in it:

+ + + +

+ +

diff --git a/files/zh-cn/archive/b2g_os/customization_with_the_.userconfig_file/index.html b/files/zh-cn/archive/b2g_os/customization_with_the_.userconfig_file/index.html new file mode 100644 index 0000000000..0cfc69ac0b --- /dev/null +++ b/files/zh-cn/archive/b2g_os/customization_with_the_.userconfig_file/index.html @@ -0,0 +1,107 @@ +--- +title: 定制 .userconfig 文件 +slug: Archive/B2G_OS/Customization_with_the_.userconfig_file +tags: + - B2G + - Firefox OS + - build + - userconfig +translation_of: Archive/B2G_OS/Customization_with_the_.userconfig_file +--- +
+

通过将一些 bash 代码放在 B2G 源码 .userconfig 文件中, 您能够对编译过程的一些方面进行定制。 本文将对修改能达到的效果及如何修改进行介绍。

+
+

 .userconfig 文件并没有被源代码控制,因此当您更新源码树时,您的更改不会被覆盖。它需要在   B2G 根目录下被创建; 也就是和 flash.sh, build.sh, 等在一个目录下。在运行您的配置和编译步骤时,需要添加该文件。

+

The .userconfig file, if it exists, is sourced by the load-config.sh script, which is in turn sourced by these scripts: flash.sh, build.sh (through setup.sh), run-gdb.sh, run-emulator.sh and tools/mach_b2g_bootstrap.py. The run-*.sh scripts use it to determine where Gecko is for your build. The mach_b2g_boostrap.py script is used by every B2G related mach command.

+
+

重要: 您的 .userconfig 文件应该在 B2G 源码根目录下,而不是您的 home 目录!

+
+

Changing the Gecko source tree

+

By default, the build uses the gecko tree, which is cloned from a tree in github. Some people like to use mozilla-inbound, or mozilla-central. To do this create your clone whereever you like and add a line to your .userconfig which sets GECKO_PATH, for example:

+
export B2G_DIR=${B2G_DIR:-$(cd $(dirname $0); pwd)}
+echo "B2G_DIR = ${B2G_DIR}"
+
+export GECKO_PATH=${B2G_DIR}/mozilla-inbound
+echo "GECKO_PATH = ${GECKO_PATH}"
+
+
+

Note: if building against a custom Gecko in Mac OS X, the mozilla-central directory must be in a case sensitive file system or else GECKO_PATH will be ignored. You can check whether the file system is case sensitive by running this in a Terminal window:

+
echo -n This file system is case->tmp; echo -n in>>TMP; echo sensitive>>tmp; cat tmp
+

Getting B2G_DIR the way it is above allows your .userconfig to work without having hard-coded paths.

+
+

Changing Gaia settings

+

Sometimes, you'd like to be able to change gaia settings. For example, enabling adb in a user build. The gaia Makefile passes in --override build/custom-settings.json when calling build/settings.py, so we can write some bash which will write {"devtools.debugger.remote-enabled": true} into the custom-settings.json file. We try to avoid changing custom-settings.json if we don't need to, so we actually write into custom-settings.json.new and if the contents differ from custom-settings.json then we'll replace it.

+
export GAIA_PATH=${GAIA_PATH:-$(cd gaia; pwd)}
+export CUSTOM_SETTINGS="${GAIA_PATH}/build/config/custom-settings.json"
+cat > "${CUSTOM_SETTINGS}.new" <<EOF
+{"devtools.debugger.remote-enabled": true}
+EOF
+if [[ -f ${CUSTOM_SETTINGS} ]] && cmp "${CUSTOM_SETTINGS}" "${CUSTOM_SETTINGS}.new" >& /dev/null; then
+  rm "${CUSTOM_SETTINGS}.new"
+else
+  mv "${CUSTOM_SETTINGS}.new" "${CUSTOM_SETTINGS}"
+fi
+
+

Another easier way is to configure a build/config/custom-prefs.js file in the Gaia working directory, so that means in gaia/build/config/custom-prefs.js if you're in the B2G directory. See Gaia Build System Primer, Customizing the preferences.

+
+

Note:  Currently the build is not smart enough to look in a different directory based on GAIA_PATH.  This is different from how GECKO_PATH behaves.  If you wish to use a separate Gaia clone you can manually run make from that directory.

+
+

Create a debug build

+

To build a debug build, put the following line in your .userconfig file:

+
export B2G_DEBUG=1
+

Profiling build

+

To enable profiling (for best results with the built-in (SPS) platform profiler), add the following to your .userconfig file then rebuild:

+
export MOZ_PROFILING=1
+
+

Do NOT pair with B2G_NOOPT. The results will be meaningless!

+
+

Disable the optimizer

+

To disable the optimizer (which may create builds that are easier to debug), add the following to your .userconfig file then rebuild:

+
export B2G_NOOPT=1
+

Disable First Time User experience

+

If you build and reflash a lot, going through the First Time User experience constantly can be annoying. You can disable this by adding the following to your .userconfig:

+
export NOFTU=1
+

Enable gaia developer mode

+

If you plan to develop apps or hack gaia, you can automatically set various usefull settings and preferences to ease working with the device. For example, it will automatically enable the remote debugging feature and disable the prompt when an incoming debugging connection starts.

+

What you need is the following export added to your .userconfig:

+
export DEVICE_DEBUG=1
+

Enable valgrind

+

Valgrind is useful for debugging memory or threading issues with your application. For more information on running valgrind, see Debugging B2G using valgrind [en-US].

+

To use valgrind under B2G, add the following to your .userconfig:

+
export B2G_VALGRIND=1
+

Changing the default host compiler

+

On some recent distributions which use GCC 4.7 as the default compiler you will need to specify an older version in order to be able to build, to do so add two lines to your .userconfig file setting the CC and CXX variables to set the alternate C and C++ compilers respectively. For example to set the GCC 4.6 compiler on Ubuntu 12.10 use:

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

Or if you're using a version built from sources provide the full path to the exectuables:

+
export CC=/opt/gcc-4.6.4/bin/gcc
+export CXX=/opt/gcc-4.6.4/bin/g++
+
+

Specify a custom Gecko object tree location

+

Once you start changing gecko source trees and other build options, you may want to also modify where your objects get stored (so, for example, all of your debug objects go into a different tree from your non-debug objects). So you might do something like:

+
export GECKO_OBJDIR=${GECKO_PATH}/objdir-gonk-debug
+
+

Using ${GECKO_PATH} makes it easy to switch between different gecko trees (eg: central, beta, aurora, etc).

+

Keeping both debug and non-debug objects

+

You can use your .userconfig file to switch back and forth between debug and release builds without having to rebuild everything each time!

+
+
+
export B2G_DIR=${B2G_DIR:-$(cd $(dirname $0); pwd)}
+echo "B2G_DIR = ${B2G_DIR}"
+
+export GECKO_PATH=${B2G_DIR}/mozilla-inbound
+echo "GECKO_PATH = ${GECKO_PATH}"
+
+export B2G_DEBUG=1
+echo "B2G_DEBUG = ${B2G_DEBUG}"
+
+export GECKO_OBJDIR=${GECKO_PATH}/objdir-gonk
+if [[ "${B2G_DEBUG}" != "0" ]]; then
+  export GECKO_OBJDIR=${GECKO_OBJDIR}-debug
+fi
+if [[ "${GECKO_PATH/*mozilla-inbound*/mozilla-inbound}" == "mozilla-inbound" ]]; then
+  export GECKO_OBJDIR=${GECKO_OBJDIR}-m-i
+fi
+echo "GECKO_OBJDIR = ${GECKO_OBJDIR}"
+

The echo commands help remind you what your current settings are. To switch between debug and release builds, simply change the value of B2G_DEBUG on line 7.

diff --git a/files/zh-cn/archive/b2g_os/debugging/debugging_b2g_using_gdb/index.html b/files/zh-cn/archive/b2g_os/debugging/debugging_b2g_using_gdb/index.html new file mode 100644 index 0000000000..b4939ee2f8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/debugging/debugging_b2g_using_gdb/index.html @@ -0,0 +1,88 @@ +--- +title: 使用 gdb 及相关工具调试 B2G +slug: Archive/B2G_OS/Debugging/Debugging_B2G_using_gdb +tags: + - B2G + - Firefox OS + - Mobile + - 调试 +translation_of: Archive/B2G_OS/Debugging/Debugging_B2G_using_gdb +--- +
+

gdb 是一个命令行调试器,提供了许多有用的选项,可以用来调试 Firefox OS 应用程序。其他相关的工具也是同样有效的,比如  b2g-ps, 它是对标准 ps 工具的封装,会显示 B2G 实例中运行的每个进程的名称。本文则描述了如何使用这些工具来执行 Fiefox OS 调试工作。

+
+

在单进程模式下启动调试器

+
+

注意: 在运行调试器前,你可能想要建立一个  .userconfig 文件来自定义一些配置。请查看 Customization with the .userconfig file 获取更多信息。

+
+

要重启 Firefox OS 并在 gdb 控制下运行,只需要简单的运行 run-gdb.sh 脚本就可以了:

+
./run-gdb.sh
+
+
+

注意: 如果你想要在模拟器上调试,请确保并没有连接手机;否则可能会与模拟器上调试 gdb 相冲突。

+
+

如果 Firefox OS 已经在运行,你想要在不重启的情况下附加在上面,也可以这样做:

+
./run-gdb.sh attach
+
+

调试 out-of-process 任务

+

Because of the threaded nature of Firefox OS, 你可能需要掉时除了主 B2G 任务之外的任务。最简单的方式就是使用 b2g-ps 命令来找出你需要调试的进程的 PID:

+
$ adb shell b2g-ps
+b2g              root      106   1     189828 56956 ffffffff 40101330 S /system/b2g/b2g
+Browser          app_0     4308  106   52688  16188 ffffffff 400db330 S /system/b2g/plugin-container
+
+

此处, Browser 是一个子进程用作 browser 应用的 "content process" 。因此如果在本例中,你想要调试  content process, 可以这么做:

+
$ ./run-gdb.sh attach 4308
+

有时候,如果有任何子进程被创建就立刻通知是非常有用的。我们可以在启动  run-gdb.sh  时添加  MOZ_DEBUG_CHILD_PROCESS 环境变量来实现:

+
MOZ_DEBUG_CHILD_PROCESS=1 ./run-gdb.sh
+

运行上面命令后,在 Firefox OS 中启动一个 OOP 应用时,就会输出新任务 plugin-container  的 PID。Having done this, launching an OOP application on Firefox OS will output the PID of the plugin-container for the new task, and will sleep for 30 seconds, enough time for you to run the attach command we saw above:

+
$ ./run-gdb.sh attach 4308
+

If you are trying to debug something that occurs during boot, you have to launch the debugger instance for the new application fairly quickly. Once the new debugger is launched, you should immediately press "c" to continue running the new task.

+

支持

+

What level of functionality to expect

+

The following debugging features at least should definitely work. If they don't, it's likely that a simple tweak to your setup will make them work:

+ +

The following debugging features are not supported. Don't try to use them.

+ +

Troubleshooting

+

Here are a few things to try first whenever GDB is not working as described above.

+

Ensure that your B2G clone is up-to-date

+

Always keep in mind to that to update your B2G clone you must run these two commands:

+
git pull
+./repo sync
+

Forgetting the git pull there is a typical reason why you'd end up with an old run-gdb.sh and not benefit from recent improvements.

+

确保你已经附着在了正确的进程上

+

Attaching to the wrong process (e.g. main B2G process versus Browser process) would explain why your breakpoints don't get hit.

+

Ensure that symbols are correctly read

+
    +
  1. In gdb, use info shared to check that symbols are correctly read: +
    (gdb) info shared
    +From        To          Syms Read   Shared Object Library
    +0xb0001000  0xb0006928  Yes         out/target/product/otoro/symbols/system/bin/linker
    +0x40051100  0x4007ed74  Yes         /hack/b2g/B2G/out/target/product/otoro/symbols/system/lib/libc.so
    +0x401ab934  0x401aba2c  Yes         /hack/b2g/B2G/out/target/product/otoro/symbols/system/lib/libstdc++.so
    +...
    +
  2. +
  3. The Syms Read column should say Yes everywhere. Maybe on some android phone you would see Yes (*) for some system libraries or drivers; that would be OK. You should not see any No.
  4. +
  5. If you do see a No, that is your first problem and you must solve it before looking at anything else.
  6. +
  7. Look for any error messages in the terminal output just after you typed your run-gdb.sh command.
  8. +
  9. Also check in that terminal output that the GDB command is sane. In particular, its last command line argument should be the path to your b2g executable. Here is a sane example: +
    prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-gdb -x /tmp/b2g.gdbinit.bjacob /hack/b2g/B2G/objdir-gecko/dist/bin/b2g
    +
  10. +
  11. Check the value of these GDB variables: solib-search-path and solib-absolute-prefix: +
    (gdb) show solib-search-path
    +The search path for loading non-absolute shared library symbol files is /hack/b2g/B2G/objdir-gecko/dist/bin:out/target/product/otoro/symbols/system/lib:out/target/product/otoro/symbols/system/lib/hw:out/target/product/otoro/symbols/system/lib/egl:out/target/product/otoro/symbols/system/bin:out/target/product/otoro/system/lib:out/target/product/otoro/system/lib/egl:out/target/product/otoro/system/lib/hw:out/target/product/otoro/system/vendor/lib:out/target/product/otoro/system/vendor/lib/hw:out/target/product/otoro/system/vendor/lib/egl.
    +(gdb) show solib-absolute-prefix
    +The current system root is "out/target/product/otoro/symbols".
    +
  12. +
+
+

Note: If you need more help, try the #b2g IRC channel. If you think you found a bug, report it on the B2G issue tracker.

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/debugging/debugging_ooms/index.html b/files/zh-cn/archive/b2g_os/debugging/debugging_ooms/index.html new file mode 100644 index 0000000000..2b6b511092 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/debugging/debugging_ooms/index.html @@ -0,0 +1,62 @@ +--- +title: 调试 Firefox OS 的内存溢出错误 +slug: Archive/B2G_OS/Debugging/Debugging_OOMs +translation_of: Archive/B2G_OS/Debugging/Debugging_OOMs +--- +
+

当 Firefox OS 设备内存溢出时,低内存管理器以及低内存消息系统就会 kill 掉一些进程,从而保持 OS 运行。 当 kernel 选择 kill 掉前台进程时, 就会看到你正在使用的 app 有一个明显的 crash 现象。 本文主要描述了如何理解和调试 OOM crash 问题。

+
+
+

注意: 如果你并不了解内存条件在 Firefox OS 上是如何管理的,请在阅读本文前参考 Out of memory management on Firefox OS

+
+

调试  OOM crash

+

假设你已经复现了你认为是由于手机内存溢出所导致的 crash 问题。下面的步骤可以帮助我们理解这些错误是如何产生的。 

+

步骤 1: 验证确实是 OOM 

+

首先,我们需要检查下是否 crash 是否确实是由于内存溢出所导致的。运行命令  adb shell dmesg 可以查看。如果 app 确实是由于 OOM 被 kill 掉的, 你就会看到下面类似的语句输出:

+
<4>[06-18 07:40:25.291] [2897: Notes+]send sigkill to 2897 (Notes+), adj 2, size 30625
+

这一行表示手机的低内存管理器 kill 掉了  Notes+ app (进程 id 2897), 当被 kill 时,其 oom_adj 2 。size 是以 pages 为单位的,每个 page 表示 4kb。因此,在此情况下,   Notes+ app 使用了 30625 * 4kb = 120mb 的内存。

+

题外话: 如果不是 OOM 

+

如果你在 dmesg 输出中没有看到类似的信息,你的 crash 可能就不是 OOM。下面的步骤就是将  crash 的进程附加在  gdb 上进行调试,并获取 backtrace,就像下面代码所示:

+
$ cd path/to/B2G/checkout
+$ adb shell b2g-ps
+# Note pid of the app that you're going to crash
+$ ./run-gdb.sh attach <pid>
+(gdb) continue
+# crash the app
+(gdb) bt
+

当报出 bug 时, 关注上述命令的输出,同时伴随这  adb logcat 的输出。如果你的 crash  是由于 OOM 导致的,   gdb backtrace 就没有什么用了。 因为 OOM crash 是由发送到 kernel 的信号所触发的,而不是进程中错误代码执行时所导致的。

+

步骤 2: 收集内存报告

+

在您已经验证您的 crash 确实是由于 OOM 导致的,下面要做的就是在 app crash 前收集关于手机的内存报告。内存报告会帮助我们理解内存都在哪些方面被使用了。 这个步骤有点困难, 因为一旦 app 出现 crash, 就没有办法从那个进程获取到内存报告。当然也没有办法在 kernel 试图去 kill 一个进程时,才来出发内存报告,那就太晚了。

+

要从手机上获取内存报告, 首先要更新你的构建树,才能获取到最新版本的相关工具。 repo sync 是不能实现这个要求的;你必须执行  git fetch && git mergegit pull 命令才可以:

+
$ cd path/to/B2G/checkout
+$ git fetch origin
+$ git merge --ff-only origin
+

现在你就可以运行使用下面命令来运行内存报告工具了:

+
$ tools/get_about_memory.py
+

一旦获取了你所想要的内存报告,就可以将问题的目录(名称为  about-memory-N)压缩,并附加在相关的 bug 上。但是,只有在你运行这些命令时,你所关注的 app 还活着,并且耗费了大量的内存时,才是管用的。此时也有一些选项。

+

Step 2, 选项 1: 获取不同的设备Get a different device

+

一般最简单的方式就是使用包含更多 RAM 的设备。从步骤 1 中获知当产生 crashed 时,进程会使用多少内存,因此你可以简单的等待,直到进程使用了那么多的内存时,就获取内存报告。 b2g-info 工具就会显示出不同的 B2G 进程使用了多少内存。你可以使用下面的命令循环的运行这个工具:

+
$ adb shell 'while true; do b2g-info; sleep 1; done'
+

如果在设备上无法获取 b2g-info ,你就可以使用  b2g-procrank 来替代。

+

Step 2, option 2: Fastest finger

+

如果无法获得包含更多 RAM 的设备,就可已尝试着去在 app crash 前运行  get_about_memory.py 。 你也可以向上节一样循环运行 b2g-info 来计算何时运行  get_about_memory.py. 运行内存报告时会将手机上的所有进程冻结一段时间,因此在进程 OOM 之前抓取内存报告并不困难。

+

Step 2, option 3: Use a smaller testcase

+

We often hit OOMs when doing something like "loading a file of at least size X in the app."

+

If the app crashes very quickly with a testcase of size X, you could try running a similar but smaller testcase (say, size X/2) and capturing a memory report after that succeeds.  The memory report generated this way often gives us good insights into the OOM crash that we ultimately care about.

+

Step 2, option 4: Run B2G on your desktop

+

If the worst comes to the worst, you can run B2G on your desktop, which probably has much more RAM than your FxOS phone.  This is tricky because B2G running on a desktop machine is a different in some key ways from B2G running on a phone.

+

In particular, B2G on desktop machines has multiprocess disabled by default.  It doesn't really work 100% correctly anywhere, but it works most accurately on Linux and Mac.  (Follow Bug 923961, Bug 914584, Bug 891882)  You can test on your desktop without multiprocess enabled, but in my experience a lot of our high memory usage issues are caused by our interprocess communication code, so that won't necessarily trigger the bug you're seeing.

+

It's also not as convenient to take memory reports from a B2G desktop process.  On Linux, you can send signal 34 to the main B2G process and it'll write memory-report-*.gz files out to /tmp.
+
+ One advantage to using B2G desktop builds is that you can use your favorite desktop debugging tools, such as Instruments on Mac OSX.  We've had a lot of success with this in the past. To collect a memory report using Instruments on OS X, choose "New -> Mac OS X -> Allocations". Start b2g-desktop and you should see multiple "plugin-container" processes in the activity monitor. You will need 2 Instruments activities: 1 to trace the allocations on the main b2g process and another to trace the allocations on the app you wish to analyze. Attach the instrument activities and execute your test case.

+

To analyze how much memory your app is using, analyze call trees. Check the "Invert Call Tree" tick, and sort by bytes used. This will show you which part of your app is using lots of memory. Below is a screenshot of a sample analysis of memory usage for an app:

+

Screen shot of instruments.
+
+ For more information on setting up B2G desktop builds, read our Hacking Gaia page.

+

步骤 3: 分析内存报告 

+

当运行 get_about_memory.py 时,它就会打开 Firefox 中的内存报告。这个文件包含系统上所有进程的内存使用信息。  Note that you can hover over any leaf node to get a description of what that node describes. 你真正要寻找的是在  crashing 进程中 ”异常变大“ 的事物。此处的 "unusually large" means by capturing a memory report of your app when it's not using a ton of memory and comparing that to the errant memory report.

+

阅读内存报告需要一些实践,因此请在需要的时候就发问吧。这个领域的专家在 #memshrink on IRC.

+

步骤 4: 必要时使用  DMD 重新构建

+

One common line item to stick out in memory reports captured before apps crash is heap-unclassifiedheap-unclassified counts memory allocated by the process that isn't covered by any other memory reporter.  If you have high heap-unclassified, the memory report can't tell you anything else about what that memory belongs to. Our tool for digging into heap-unclassified is called DMD.  This works on B2G, but you must build B2G yourself in order for it to work because DMD requires local symbols that are only kept on the build machine.

+

To find out more information on running DMD and interpreting its output, read the Mozilla Wiki DMD page.
+  

diff --git a/files/zh-cn/archive/b2g_os/debugging/developer_settings/index.html b/files/zh-cn/archive/b2g_os/debugging/developer_settings/index.html new file mode 100644 index 0000000000..0b59d842f7 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/debugging/developer_settings/index.html @@ -0,0 +1,161 @@ +--- +title: Firefox OS 开发者设置 +slug: Archive/B2G_OS/Debugging/Developer_settings +translation_of: Archive/B2G_OS/Debugging/Developer_settings +--- +
+

在 Firefox OS Settings 应用中有一个开发者面板。这个面板提供了许多选项可以使您在 Firefox OS 上调试 open web app 更简单。本文则对有效的选项和如何使用进行了介绍。

+
+

开发者选项的设置面板故意将路径设置的不太好找,这是为了避免不需要这些选项的终端用户无意中打开该选项,从而使设备变得更慢或者在界面中显示出特殊的效果。该面板与下图类似 (下图是一个运行 Firefox OS 2.0 2014 四月版本的 Geeksphone keon ):

+

+

可以通过下面路径找到开发者面板:

+ +

下面的章节则对开发者面板中的每个选项进行了介绍,包括它们是做什么的以及为何有效。

+

开发者工具设置

+

通过 USB 调试

+

“远程调试” 选项会在 Firefox OS 设备上对 远程调试功能 进行使能。同时也使能了 ADB 命令用法。在  Firefox <1.4 版本,只是一个复选框;在 Firefox 1.4  中是一个下拉选框,其中有三个有效的选项:

+ +

开发者 HUD

+

Firefox OS 1.4+ 版本中, 点击该部分会进入开发者 HUD 选择视图。

+

+

在显示开发者信息的 FIrefox OS UI 的顶部,有一个复选框可涌来使能或禁用开发者 HUD 全部的功能,下面有 5 个复选框可以用来启用或禁用:

+ +

每秒帧数(Frames per second)

+

启用该选项会使 Firefox OS 显示界面左上角显示 3 个数字; 这个数字表示的是在滑动窗口中近期的平均值,指瞬时数据,但又是相当精确的。实际上,所有的数字都是推测出来的:

+ +

A screenshot of Firefox OS, showing three numbers in the top left hand corner that are measurements of app framerate.

+

装载时间

+

Firefox OS 也有一个工具可以帮助测量启动时间,尤其是“初次绘制“ 时间。 由工具所显示的值 — 位于 Firefox OS 界面右上角 — 是指从距今最近的应用的启动时间到应用第一次绘制自己 UI 估计值 之间的时间间隔,间隔以毫秒为单位。 这个数字只是接近“第一次真正画界面”的时间,一般会比实际值要小。 然而, 降低这以数值一般与改善真正的启动时间有直接关系, 因此它可以用来快速的测量优化问题。

+

A screenshot of Firefox OS, showing a number in the top right hand corner that is a measurement of the current app startup time, in milliseconds.

+

App 内存

+

它会显示有关 app 所使用内存的信息, 并且允许您启用或禁用使用内存的不同条目以显示当前 app 所使用的内存。 例如,下面的截图显示了只有 App 内存 和 Js 对象勾选了,就会在界面右下角提示 Settings app 中 Js 对象使用了 414.77KB 内存。

+

+

Flash 重绘区域

+

In this mode, every time a region of the screen is painted by Gecko, Gecko blits a random translucent color over the painted region. Ideally, only parts of the screen that visually change between frames will "flash" with a new color. But sometimes more area than is needed is repainted, causing large areas to "flash". This symptom may indicate that application code is forcing too much of its scene to update. It may also indicate bugs in Gecko itself.

+

A screenshot of Firefox OS with a number of transparent overlays, showing the parts of the screen repainted with each new animation frame.

+

Graphics settings

+

Enable APZ for all content (was Async Pan/Zoom)

+

When enabled, the Async Pan/Zoom module allows panning and zooming to be performed on asynchronously, on another thread, with some noticeable differences to rendering behaviour. To find out more, read the MozillaWiki APZ article.

+

Tiling (was Layers: Enable tiles)

+

Introduced in Firefox OS 1.4, this feature enables the painting of content to the screen in smaller chunks ("tiles") rather than painting the whole screen at once. This is mainly useful for platform QA work involving reducing checkerboarding and finding regression windows.

+

Simple tiling (was Layers: Simple tiles)

+

This flips between the two different content painting implementations described in the section above.

+

Hardware composer (was Enable hardware compositing)

+

When enabled, this setting causes the device to use its Hardware Composer to composite visual elements (surfaces) to the screen.

+

Draw tile borders (was Layers: Draw tile borders)

+

This is very similar to the Draw layer borders option, the difference being that it also draws the borders for individual tiles as well as the borders around layers.

+

Draw layer borders

+

When this setting is enabled, a brightly colored border is added around all the different layers painted to the display — great for diagnosing layout issues.

+

A screenshot from Firefox OS showing an opened select form with the draw layers borders option enabled, resulting in colored borders being drawn on all the different rendered layers.

+

Dump layers tree

+

This option causes a copy of the compositor's layer tree to be dumped to logcat on every frame composited to the screen; this is mainly useful for platform graphics performance work, rather than regular web development.

+

Cards View: Screenshots

+

When enabled, this specifies that app screenshots will be taken when the open apps are displayed in card view. If disabled, app icons are shown in the center of blank cards for the card view instead.

+

窗口管理设置

+

Software home button

+

Enabling this option creates a software home button that can provide the same functionality as the equivalent hardware button if it is not available. This is intended for future use on devices that are likely to not have hardware home buttons, like tablets.

+

Home gesture

+

Enabling this option allows you to swipe upwards towards the center from outside the screen to bring up the homescreen. Again, this can provide the same functionality as the equivalent hardware button if it is not available, and is intended for future use on devices that are likely to not have hardware home buttons, like tablets.

+

Edges gesture

+

Enabling this option allows you to swipe left and right from outside the screen towards the center, to navigate to the next and previous sheets (either web pages in the browser, or views inside another app.) This basically works like the browser navigator bar in Firefox.

+

Continuous transition

+

This setting allows you to decide whether app keyboards open immediately or continuously (with a  transition). Disabling such transition effects are useful on low end devices, when they cause performance to suffer.

+

App transition

+

Turn this on and then off again and you will disable all app closing/opening transitions: all apps will now just show immediately, without the smooth animation, and keyboards will also open/close without animation. Like "Continuous transition enabled", this is meant for improving performance on low end devices, but it has more of an effect.

+

App suspending

+

If enabled, this specifies that when an app is killed in the background, it will be kept in history and reopened when you open it from homescreen/card view. If disabled, such apps are not kept in history/card view.

+

Debug settings

+

Log slow animations

+

This tool tries to help developers understand why animations are not offloaded to the compositor to be run efficiently as possible. It reports "bugs" like trying to animate elements that are too large, or trying to animate CSS properties that can't be offloaded. The messages you'll get on the device will look like the following:

+
I/Gecko   ( 5644): Performance warning: Async animation disabled because frame size (1280, 410) is bigger than the viewport (360, 518) [div with id 'views']
+
+

Wi-Fi output in adb

+

Enabling this option adds information about Wi-Fi to the adb logs (error logs from the console can be accessed using adb logcat | grep "Error" in the Terminal.)

+

Bluetooth output in adb

+

Enabling this option adds information about Bluetooth to the adb logs (error logs from the console can be accessed using adb logcat | grep "Error" in the Terminal.)

+

Console enabled

+

When enabled, this option lets you use the Web Console in Firefox to remotely access the console output on the device; without this option enabled, the console.log() function does nothing.

+

Gaia debug traces

+

Enabling this directly enables DEBUG traces in Gaia; see bug 881672 for more details.

+
+

Note: Unfortunately, not every app supports this mechanism to print their debug log. Instead, they control a "DEBUG" flag in code directly, so enabling this flag does NOT ensure that you'll see all debug logs.

+
+

Show accessibility settings

+

This enables the accessibility settings menu, subsequently found at Settings > Accessibility. The options contained within the accessibility settings are as follows:

+

Screen reader

+

Enabling this option turns on Firefox OS's screen reader. This is technology that allows a blind person to use a Firefox OS device. Currently at a very early stage, it changes the way the standard touch events work. When the screen reader is on, you must interact with the screen as follows:

+ +
+

Note: If you have turned the screen reader on and wish to disable it again, you must navigate back to the setting via these new gestures and double-tap the checkbox once it is highlighted to turn it off again. That will restore the touch screen functionality to its default behaviour.

+
+

Note: In Firefox 1.4 and above, there is a quick toggle for the screen reader. Press volume up, then down, three times (up, down, up, down, up, down). The screen reader will instruct you to perform this same action again (volume up, down, up, down, up, down) to turn it on if it is not running, or to turn it off if it is already running. If you do not want to change the current toggle state, simply do something else. That way, you can turn it on and off at will to test your web application for accessibility without having to navigate the accessibility settings menu each time.

+

Speech volume

+

A slider that controls how loud the speech is delivered.

+

Speech rate

+

A slider that controls how fast the speech is delivered.

+

Launch first time use

+

The "Launch first time use" button runs the first-time startup program; this lets you go through the initial setup and tutorial process, and is useful when trying to debug that process, or if you want to re-configure your device from scratch.

+

Obsolete settings

+

This section lists settings that are no longer provided, or no longer exist in the same state, but might still be interesting if you are running an older version of Firefox OS.

+

Accessibility

+

In versions of Firefox earlier than newer 1.4 versions, this controls the accessibility settings, as explained in the Show_accessibility_settings section above.

+

Grid

+

The "Grid" option, when enabled, causes the Firefox OS display to be overlaid with a grid pattern to help you gauge positioning and alignment of items. For example, below we see the Browser app running with the Grid option enabled:

+

+

The grid's heavier lines are 32 pixels apart, both horizontally and vertically.

+

Show frames per second

+

In Firefox OS versions older than newer 1.4, enabling this displays frames per second, as explained in the Frames_per_second section above.

+

Show time to load

+

In Firefox OS versions older than newer 1.4, enabling this displays time to load information, as explained in the Time_to_load section above.

+

Rocketbar enabled

+

In Firefox OS versions older than newer 1.4, this option enables the new Firefox Rocketbar on your device, which provides a useful new way to switch between apps, search, and more. When enabled, you'll find a search icon at the top left of the device, and the RocketBar can be brought up by swiping from the top left of the device towards the bottom left.

+
+

Note: In newer versions of Firefox OS, Rocketbar is enabled automatically and cannot be turned off.

+
+

Contacts debugging output in adb

+

Enabling this option adds debugging information about contacts to the adb logs (error logs from the console can be accessed using adb logcat | grep "Error" in the Terminal.)

+

Progressive paint (was Layers: Progressive paint)

+

This was introduced to help with debugging of the Async Panning/Zoom module (APZ) during its implementation. Now APZ implementation is complete, this option is deprecated, and will be removed from future versions (see bug 1003228).

+

Displayport Heuristics

+ +

These options were introduced to help with debugging of the Async Panning/Zoom module (APZ) during its implementation, specifically to allow QA to experiment with different repainting heuristics to see which resulted in the least amount of checkboarding.. Now APZ implementation is complete, these options are deprecated, and will be removed from future versions (see bug 1003228).

+

Keyboard layouts

+

In addition to the developer-specific options listed above, Firefox OS < 1.4's developer settings featured keyboard layout options. These let you toggle on and off the then-experimental Chinese input methods:

+

+

As of Firefox 1.4, these options have been removed. This is because the Chinese keyboard layout implementations (zhuyin and pinyin) have now been completed.

+
+

Note: For other keyboard layouts still under development, such as Japanese, we now have a build-time config to opt them in.

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/debugging/index.html b/files/zh-cn/archive/b2g_os/debugging/index.html new file mode 100644 index 0000000000..a83bb6ae67 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/debugging/index.html @@ -0,0 +1,80 @@ +--- +title: Debugging on Firefox OS +slug: Archive/B2G_OS/Debugging +tags: + - B2G + - Debugging + - Firefox OS + - NeedsTranslation + - QA + - Testing + - TopicStub +translation_of: Archive/B2G_OS/Debugging +--- +
+

There are two main types of debugging you'll want to with Firefox OS: debugging apps, and debugging other aspects of the system. This section of the site provides articles covering the different tools at your disposal to debug your Firefox OS code.

+
+

Debugging apps

+

When debugging your web apps, the best tool at your disposal is Mozilla's powerful App Manager, which allows you to run your apps directly on a real device or simulator, update any changes instantly, and debug them directly on the device using Mozilla's excellent developer tools. This should be your first choice, especially for app/Gaia debugging.

+
+
+ Using the App Manager
+
+ The App Manager is a new tool available in Firefox for Desktop, which provides a number of useful tools to help you test, deploy and debug HTML5 web apps on Firefox OS phones and the Firefox OS Simulator, directly from your browser.
+
+ Debugging out of memory errors on Firefox OS
+
+ This article describes how B2G's multiprocess architecture affects what the phone does when we run out of memory, and how to understand and debug OOM crashes.
+
+

Debugging Gaia/B2G

+

If you want to debug code from the Gaia apps suite or B2G itself, the following tools will be of use to you.

+
+
+ Debugging using the desktop B2G client
+
+ You can use the dedicated B2G desktop application (and associated tools) to debug multiple aspects of B2G and Gaia.
+
+ Quickstart guide to Gaia development
+
+ This guide provides a very quick easy guide to developing and debugging Gaia apps, including running Gaia inside desktop Firefox, and debugging Gaia with App Manager.
+
+ Debugging B2G using gdb
+
+ The popular gdb debugger can be used to debug Firefox OS and web apps running on a device, or on an emulator. This guide will show you how it's done.
+
+ Debugging B2G using Valgrind
+
+ Valgrind gives developers access to information about memory allocations, threads, and other information important to performance. This guide shows how to run Valgrind either on desktop B2G or select phone hardware.
+
+ Getting NSPR logs in B2G
+
+ You can use NSPR logs to record HTTP and other networking.
+
+ Debugging OpenGL
+
+ How to debug OpenGL code on Firefox OS.
+
+

General setup and information

+

The following articles provide information on individual aspects of setup for Firefox OS development. The chances are that you won't need these, especially if you are just debugging apps using the App Manager. But we have made them available here in case you do.

+
+
+ Developer settings for Firefox OS
+
+ There are a number of settings options available for developers on Firefox OS. This guide explains what they do and how to take advantage of them.
+
+ Installing and using ADB
+
+ Many aspects of Firefox OS development require installation of adb, the Android Debug Bridge. This article explains how to do that, and shares some common useful ADB commands.
+
+ On-device console logging
+
+ How to log to console on a Firefox OS device, and how to access the resulting logs for review on your computer.
+
+ Connecting a Firefox OS device to the desktop
+
+ This short guide explains how to set up your Firefox OS device and your desktop so that the desktop can communicate with the device over USB.
+
+ Setting up to debug Firefox OS code
+
+ Before you can begin using most of the tools integrated into Firefox for debugging code running under Firefox OS, you need to do a little configuration work. This article explains what you need to do.
+
diff --git a/files/zh-cn/archive/b2g_os/debugging/taking_screenshots/index.html b/files/zh-cn/archive/b2g_os/debugging/taking_screenshots/index.html new file mode 100644 index 0000000000..a1ca14b2aa --- /dev/null +++ b/files/zh-cn/archive/b2g_os/debugging/taking_screenshots/index.html @@ -0,0 +1,69 @@ +--- +title: 截屏 +slug: Archive/B2G_OS/Debugging/taking_screenshots +tags: + - Firefox OS + - 截屏 + - 调试 +translation_of: Archive/B2G_OS/Debugging/taking_screenshots +--- +
+

在许多场合下截屏都是非常有用的,例如将你的工作展示给客户端或者在 Marketplace 中发布应用。本文则对在 Firefox OS 手机中如何截屏进行了说明。

+
+
+

Note: Android 会觉得非常熟悉。这些步骤都是类似的。

+
+

准备你的手机

+
    +
  1. 在手机上到 Developer Settings  查看远程调试和终端是否使能
  2. +
  3. 确保你的手机已经  ADB installed 并且正常工作
  4. +
  5. 通过 USB 将手机连接到电脑
  6. +
+

截屏

+

你当前可以有 4 种方式可以实现: 使用终端,在 Eclipse 中使用 DDMS, 在手机上使用手机上的组合按键,或者使用 App Manager。

+

终端

+

打开一个终端窗口,依次输入下面 3 个命令:

+
    +
  1. 使用下面的命令截屏(如果你想要称之为其他的名称,可以修改 screenshot.png
    + adb shell screencap -p /sdcard/screenshot.png
  2. +
  3. 从电脑中获取图片:
    + adb pull /sdcard/screenshot.png
  4. +
  5. 在设备中删除截屏图片
    + adb shell rm /sdcard/screenshot.png
  6. +
+

Alternatively, you can use ffmpeg:

+
    +
  1. Make sure you have ffmpeg installed: +
      +
    1. On Mac, if you use MacPorts, you can do this with sudo port install ffmpeg. For homebrew, do brew install ffmpeg.
    2. +
    3. On Linux (Ubuntu/Debian), use sudo apt-get install ffmpeg.
    4. +
    +
  2. +
  3. cd into the B2G/gaia directory.
  4. +
  5. Use the make screenshot command to take a screenshot.
  6. +
  7. You now have a screenshot called screenshot.png.
  8. +
+

DDMS

+

Open Eclipse.

+
    +
  1. Open DDMS: Window > Open Perspective > Other > DDMS.
  2. +
  3. On the left side panel, in the Devices tab, click the Screen capture button.
  4. +
  5. A new window appears with several options; click on Save button to save your screenshot.
  6. +
+
+

Note: To learn more about DDMS, have a look at the DDMS documentation .

+
+

Phone button combination

+
    +
  1. On Firefox OS versions up to 2.0, simultaneously hold down the Home and Power buttons for a few seconds.
  2. +
  3. On Firefox OS version 2.1 and beyond, simultaneously hold down the Volume Down and Power buttons for a few seconds.
  4. +
+

This takes a screenshot, which is saved in your Gallery. You can now copy the picture from your SDCard to your computer using whatever method suits you best.

+
+

Note: The button combination change was made because many people feel that Home and Power is more difficult to do that it should be, especially with one hand, plus devices with no hardware Home button are not very well supported (you can't use a software Home button in many places in Gaia, such as the lock screen.)

+
+

App Manager/Simulator

+
    +
  1. Go to the App Manager, connect to your phone, and navigate to the Device tab on the left.
  2. +
  3. Click on the Screenshot button at the bottom of the page (is at the same place that you startes the simulator).
  4. +
diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/customizing_the_b2g.sh_script/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/customizing_the_b2g.sh_script/index.html new file mode 100644 index 0000000000..0406de37db --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/customizing_the_b2g.sh_script/index.html @@ -0,0 +1,44 @@ +--- +title: 定制 b2g.sh 脚本 +slug: Archive/B2G_OS/Developing_Firefox_OS/Customizing_the_b2g.sh_script +translation_of: Archive/B2G_OS/Developing_Firefox_OS/Customizing_the_b2g.sh_script +--- +
+

在手机上,  b2g 应用程序 (它提供了 Firefox OS API 以及其他的东西)是通过 /system/bin/b2g.sh 脚本启动的。你可以对这个脚本进行定制,以修改 Firefox OS 的行为,本文则是介绍了这些内容。

+
+

设定环境变量

+

如果你仅仅是想要对单个运行的 B2G 设定环境变量,可以执行下面命令:

+
adb shell stop b2g
+adb shell "export ENV_VAR=value && /system/bin/b2g.sh"
+
+

如果你想要在任何时候都使用相同的环境能够变量,可以向下节描述中对 b2g.sh 进行编辑。

+

编辑 b2g.sh

+

For debugging, you may want to set environment variables to get logging information or to otherwise affect how the b2g program runs. You can do this by editing the b2g.sh script. There aren't any tools included on the phone to edit the file in place, so you'll need to copy it to your computer first.

+
    +
  1. Connect the phone to your computer, open a terminal window, and execute the following command to edit the script: +
    adb pull /system/bin/b2g.sh
    +
  2. +
  3. Edit the script to make the changes you want. For example, suppose you'd like to see some logging output (which requires a debug build), then you might add something like: +
    export NSPR_LOG_FILE=/data/local/tmp/mylog.txt
    +export NSPR_LOG_MODULES=Layers:5
    +
    +
  4. +
  5. Run the following commands to save your updated b2g.sh script to the phone and restart b2g: +
    adb shell stop b2g
    +adb remount
    +adb push b2g.sh /system/bin
    +adb shell chmod 0755 /system/bin/b2g.sh
    +adb shell start b2g
    +
    +
  6. +
+
+

Note: /data/local/tmp is the only place on the filesystem which is writable by content processes.

+
+

参考

+ +

 

diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/filing_bugs_against_firefox_os/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/filing_bugs_against_firefox_os/index.html new file mode 100644 index 0000000000..2e5eb4050c --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/filing_bugs_against_firefox_os/index.html @@ -0,0 +1,157 @@ +--- +title: 为 Firefox OS 提交 Bug +slug: Archive/B2G_OS/Developing_Firefox_OS/Filing_bugs_against_Firefox_OS +translation_of: Archive/B2G_OS/Developing_Firefox_OS/Filing_bugs_against_Firefox_OS +--- +
+

本文是对 Firefox OS 项目提交 Bug 的指南, 包括 Gaia 和 B2G。

+
+ +

Bugzilla

+ +

与 Mozilla 中的大多数项目一样,我们用 Bugzilla 作为软件缺陷的追踪管理。当你发现程序错误时,你可以向 bugzilla 中的 Firefox OS 产品提交 bug 报告,其中包含 GaiaGonk 以及 Firefox OS Gecko 等组件。你可以从这里报告关于Firefox OS、B2G、Gaia 等组件的 bug。

+ +
+

注意: The Mozilla B2G QA Wiki page also has some useful resources on handling Firefox OS bugs; the most useful pages are Bugzilla Usage and Incoming bug triage for Firefox OS.

+
+ +

提交 Bug 

+ +

你可以依照 bug 报告撰写指南中的内容来报告优秀的 bug,你也可以在下面发现更多的细节。

+ +

强制和可选字段

+ +

在报告新 bug 时,有一些必填域:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
字段描述
类别选择这个bug所属的类型,如果你不清楚这个问题所属的类型,你可以将它放到"常规"问题当中。
概要简要描述这个bug的概要。
描述 +

清楚地描述情况,一个好的bug报告应该包含有:1.重现的步骤(STR), 2.预期结果(程序本应该出现的结果)和实际结果(因为bug产生的结果), 3.顺便说明出现bug的频率(即:您多次重复这样的步骤后这个bug出现次数)。

+
版本信息进入 设置>设备信息>更多信息 并且将下列信息与bug一并提交:操作系统版本,内部版本号,平台版本,构建标识,更新方式。(如果你有一台带安装了adb功能的运行Mac或者Linux的电脑,你可以直接运行这个脚本,并且黏贴这个脚本的输出结果到bug报告中)。
截图请抓取一个截图方便我们分析这个bug。(在Flame设备上,可以同时按住电源键和音量下键两秒直至设备显示截屏通知,然后通过USB线传输到电脑上以便提交)。
录制视频如果这个bug的截图不方便传输或者难以通过截图来捕获,请录制一段关于这个bug的视频,你可以将视频文件上传作为bug报告的附件,也可以上传至YouTube网站并且复制视频链接至报告中。
ADB 运行日志如果你的电脑安装了ADB工具,请将你的设备连接到电脑并且在ADB中运行以下命令|adb logcat|。请将这个命令的输出信息复制到一个文本文档中并且附到bug报告中。
+ +

以下是可选域:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
字段描述
依赖/块列出多个bug之间的联系。
关键词为bugzilla列出关键词. 特殊的团队将用它们来追踪。
白板包含标签,为追踪bug添加标签,你不能未经许可就擦除其他的标签。
看点别的有时候,两个问题是相互有关联的,你可以指定它们。
旗子用于追踪的旗子; the most used flag in Firefox OS bugs is blocking-b2g. If a bug is set as blocking-b2g, it means we should pay more attention to it as it threatens to block a release.
SecurityIf a bug is related to personal data security, loss of earnings, and other such issues, you should check the checkbox and it will only be visiable to involved employees.
+ +

To find more information on bugzilla fields, you can view the Bugzilla Fields page on Bugzilla.

+ +

常见关键字

+ +

下面的表格提供了你将在 Firefox OS 的 bug 报告中经常见到的关键字。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
关键字描述
metaIndicates that the bug is a status tracking bug. Mozilla uses this tag to tracking multiple bug or user story implementation statuses. Once marked like this, developers should not land patches on top of such bugs. Please be reminded that project managers and QA staff will use meta bugs for tracking.
qablockerUse this keyword for bugs that are blocking testing (manual or automated testing of a feature) and need to be fixed by the next Beta or RC milestone.
qawantedUse this keyword for bugs that need more info, require reproducing or testcasing, or are duplicates (but you can't find the original bug being duplicated). Required QA work progress is recorded in the whiteboard; you should remove this keyword when the required QA work has been completed.
regressionThis keyword means that the problem was fixed, but then it came back (regressed) and the bug in question is a new bug, filed to track the regression. It can also refer to problems outside those identified in pre-check in and smoke tests, which were found in current builds and that were known to be working in previous builds. Tracking these bugs helps us to identify areas that are fragile, prone to breakage and are good candidates for adding to smoke and pre-check in tests.
regressionwindow-wantedIndicates that the bug is a regression, and would strongly benefit from someone identifying the time period in which it happened, ideally to a specific check in.
steps-wantedHighlights a bug that would greatly benefit from someone identifying the steps to reproduce it.
verifymeMeans that this bug is ok to verify with the latest B2G build by someone other than the QA Contact indicated. The bug has specific machine configuration details indicated for verifying the fix. You should try to reproduce the failure, and, if you agree that the resolution of Fixed is correct, mark the Status as Verified.
+
+ You should always indicate the build/OS/platform(s) used to verify the bug in the bug comments, before you change the Status to Verified. If the bug is reported on all three platforms and you only have one platform to verify the fix on, go ahead and do so and note it in the bug, but do not mark the bug as Verified. All platforms must be checked before moving Status to Verified.
+
+ Finally, if other bugs have been marked as a duplicate of the bug you're verifying, be sure to check and mention those as well. Often developers mark related — but not identical — bugs as duplicates, and these can be overlooked if not checked.
+ +
+

注意:有关 Gaia 开发中对 bug 的处理的更多信息,请见向 Gaia 提交补丁

+
+ +

 

diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/index.html new file mode 100644 index 0000000000..888de98cc8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/index.html @@ -0,0 +1,45 @@ +--- +title: Firefox OS 开发 +slug: Archive/B2G_OS/Developing_Firefox_OS +tags: + - NeedsTranslation + - TopicStub +translation_of: Archive/B2G_OS/Developing_Firefox_OS +--- +
+

本部分提供了许多有用的文档,主要包括在编译和写应用时对Firefox OS修改和定制的不同方式以及您如何能够帮助我们对平台进行开发。

+
+
+
+ Gaia开发快速入门
+
+ Gaia是指web应用的集合,并由这些应用共同组成了 Firefox OS 的前端。在Firefox OS  屏幕上显示的内容都使用了开放web技术,其中包括主屏幕和所有的原生应用 。本指南主要对如何快速使用和修改Gaia层应用进行了简单介绍。
+
+ 系统编译入门
+
+ 文章介绍了Gaia编译系统是如何工作的,包括Makefile文件,编译过程,环境变量以及隐含的自定义配置等。
+
+ Hacking Gaia
+
+ 文章提供了开发和修改Gaia的详细指南。
+
+  Market customizations guide
+
+ Market customizations allow you to specify build-time customization instructions (for example, which apps should be included in your build) in separate directories, without modifying the core Gaia repo. You can include your own customizations in distinct directories, or use the preexisting directories that come with the source. These customizations are specified with build options. In this article we look in detail at how to create and use these customizations.
+
+ Modifying the hosts file
+
+ A guide to what can be achieved by modifying the Firefox OS hosts file.
+
+ Customization with the .userconfig file
+
+ How to customize the build and execution of Firefox OS by changing the .userconfig file.
+
+ Customizing the keyboard in Firefox OS apps
+
+ This guide shows how to customize the keyboard in your Firefox OS apps.
+
+ Firefox OS 本地化
+
+ A guide to localising the Firefox OS platform, making it available in your preferred languages.
+
diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/market_customizations_guide/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/market_customizations_guide/index.html new file mode 100644 index 0000000000..91fc8d5aab --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/market_customizations_guide/index.html @@ -0,0 +1,979 @@ +--- +title: 市场自定义指南 +slug: Archive/B2G_OS/Developing_Firefox_OS/Market_customizations_guide +translation_of: Archive/B2G_OS/Developing_Gaia/Market_customizations_guide +--- +
+

市场定制允许您在独立的文件夹指定构建时定制指令(例如,在构建时哪个app应被包括其中)而不必修改核心的Gaia仓库。您能够将自己的定制项放在不同的目录或使用代码中已存在的目录。这些定制是由 build 选项指定的。本文会对如何创建和使用这些定制项进行深入探讨。

+
+ +

定制概览

+ +

从 1.0.1 开始, Firefox OS 所采用的定制机制都是相同的。
+
+ We have created a full-featured Gaia distribution customization sample as part of the gaia repo: study this to learn first-hand what can be done with build-time customization. It will also be referenced in the article below.

+ +
+

注意: send a pull request to the above referenced Github repo if you have any suggestions for improving the customization sample, or see something that has been changed in this article but not  updated in the code.

+
+ +

Below is the tree structure for the customization sample:

+ +
  customize-sample
+  ├── power
+  │   ├── carrier_power_on.png
+  │   └── carrier_power_off.png
+  ├── ringtones
+  │   ├── list.json
+  │   └── ringer_dream_theme.ogg
+  ├── wallpapers
+  │   ├── customize.png
+  │   └── list.json
+  ├── browser.json
+  ├── calendar.json
+  ├── contacts.json
+  ├── costcontrol.json
+  ├── homescreens.json
+  ├── network.json
+  ├── sensors.json
+  ├── settings.json
+  ├── sms-blacklist.json
+  ├── support.json
+  ├── wapuaprof.json
+  └── apps.list
+ +
+

注意: 所有的文件都是可选的。如果您没有提供这个文件,就会使用系统的默认配置。

+
+ +

We will discuss all these optional customizations in the sections that follow, but first let's see how to apply the customization to Gaia.

+ +

定制步骤

+ +

要将定制样例应用在 Gaia:

+ +
    +
  1. 从 https://github.com/mozilla-b2g/gaia 地址 Clone Gaia 源码
  2. +
  3. 你可以将  gaia/customization/ 文件夹拷贝到新的文件夹来进行你自己的本地化,或者是编辑  gaia/customization/ 文件夹本身。这个路径就是指下面所讲的  <DISTRIBUTION_PATH>; 将该目录更改为你自己的文件路径。
  4. +
  5. 通过 USB 附加在 Firefox OS 设备上,并检查是否它是否可以通过 USB  辨认
  6. +
  7. 构建 Gaia, 使用  GAIA_DISTRIBUTION_DIR 环境变量指定定制样例的位置,如下所示: +
    GAIA_DISTRIBUTION_DIR=<DISTRIBUTION_PATH> make production
    +
  8. +
  9. 现在就应该在你的 Firefox OS 设备上应用了你的定制的修改。
  10. +
+ +

如果你将定制样例文件夹拷贝到了 gaia/distribution/, 就可以在没有指定环境变量运行 make 命令:

+ +
make production
+ +
+

Note: 可通过 Gaia 构建脚本进行定制。 请参考 make options reference 获取构建脚本定制的信息。

+
+ +
+

Note: SIM card-specific customizations are included at build time, but applied at runtime during the First Time Usage experience.

+
+ +

构建时定制

+ +

Let's now go through the different options available in the sample.

+ +

power/

+ +

Custom power on/off animations (or static images) are included here. Files can be MP4 for animations or PNG for static images.

+ +

Valid file names are:

+ + + +

ringtones/

+ +

Custom ringtones are included here. list.json should contain the filenames of the ringtones, like this:

+ +
  {
+    "ringer_classic_courier.opus": "",
+    "ringer_dream_theme.ogg": "",
+    "ringer_loud_windchimes.opus": "",
+    "ringer_bitbounce.opus": ""
+  }
+ +

Custom ringtones are selectable in the Firefox OS settings app through Sound > Ringer. The default ringtone must be set in settings.json, using DataURI, you can use datauri command which is available on node/npm, install it by npm install datauri -g and convert file to DataURI by datauri <FILE>

+ +

wallpapers/

+ +

Custom wallpapers (PNG files) should be included here and listed in list.json, after which they can be selected in the Firefox OS settings app through Display > Wallpaper.

+ +

The default wallpaper must be set in settings.json, using the following line:

+ +
"wallpaper.image": "image location"
+ +
+

Note: The image can be specified as a file path, or a Base 64 encoded data URI.

+
+ +

browser.json

+ +

This file allows you to add customizations into the actual Browser app, such as bookmarks and default search engine. See the section Browser bookmarks & default search engine for more details on what to put in this file.

+ +

calendar.json

+ +

This file allows you to use your own custom calendars in the Firefox OS Calendar app. You'll need to specify your own Google Oauth credentials.  In addition, calendar CalDav API access is needed: To  generate the required API key and secret, you need to apply at Google's creating your client ID page; follow these instructions:

+ +
    +
  1. Open the API console.
  2. +
  3. Create a project and enable Calendar CalDav API in APIs & auth > APIs.
  4. +
  5. Click on Credentials.
  6. +
  7. Click on Create new client ID
  8. +
  9. Set the Application type to Installed application, and Installed application type to Other, then press Create Client ID. This should give you a Client ID and Client secret.
  10. +
  11. Open the calendar.json file, change the client_id and client_secret to the Client ID and Client secret you got from the Google API console, and save and close.
  12. +
+ +
+

Note: API usage is limited to 1,000,000 requests/day

+
+ +

camera.json (Gallery and Camera app image sizes)

+ +
+
{
+  "maxImagePixelSize": 6000000,
+  "maxSnapshotPixelSize": 4000000,
+  "requiredEXIFPreviewSize": {
+    "width": 1200,
+    "height": 1222
+  }
+}
+
+ +

maxImagePixelSize and maxSnapshotPixelSize are maximum pixel sizes of an image Gallery and Camera is allowed to view. Default to 5 mega-pixels (5*220 pixels; 5mp).

+ +

Optionally, you can also define variables to specify the minimum EXIF preview size that will be displayed as a full-screen preview by adding requiredEXIFPreviewSize property. If you do not specify this property then EXIF previews will only be used if they are big enough to fill the screen in either width or height in both landscape and portrait mode.

+ +

contacts.json

+ +

Contacts listed here will be included in the phone's contacts database as soon as Gaia is built.

+ +

Here's an example contacts.json file:

+ +
[
+   {
+     "name": ["John Doe"],
+     "givenName": ["John"],
+     "familyName": ["Doe"],
+     "nickname": ["Johnny"],
+     "category": ["Work", "Racing Team"],
+     "email": [
+       {
+         "type": ["personal"],
+         "value": "john.doe@example.org",
+         "pref": true
+       },
+       {
+         "type": ["work"],
+         "value": "jdoe@example.com"
+       }
+     ],
+     "adr": [
+       {
+         "type": ["personal"],
+         "streetAddress": "123 Foopy St.",
+         "locality": "San Francisco",
+         "region": "Downtown",
+         "postalCode": "94030",
+         "countryName": "US"
+       }
+     ]
+   },
+   {
+     "name": ["CarrierX"],
+     "email": [
+       {
+         "type": ["work"],
+         "value": "support@carrierx.com"
+       }
+     ],
+     "url": [
+       {
+         "type": ["work"],
+         "value": "https://www.carrierx.com"
+       }
+     ]
+   }
+ ]
+ +
+

Note: See the Contacts API page for details on the layout of Contacts objects.

+
+ +
+

Note: For SIM-card dependent customizations, see the Browser bookmarks and default search engine section.

+
+ +

homescreens.json

+ +

homescreens.json defines what apps to show in the Firefox OS dock and homescreen, and in which order. By default the file looks like this:

+ +
{"homescreens": [
+   [
+     ["apps", "communications", "dialer"],
+     ["apps", "sms"],
+     ["apps", "browser"],
+     ["apps", "camera"]
+   ]
+ ]}
+ +

This causes the four described apps to appear in the dock. If we added another array, that set of apps would appear on page 1 of the homescreen, the next set on page 2, etc.

+ +
{"homescreens": [
+   [ // We're in the dock!
+     ["apps", "communications", "dialer"],
+     ["apps", "sms"],
+     ["apps", "browser"],
+     ["apps", "camera"]
+   ],
+   [ // We're on Page 1 of the homescreen
+     ["apps", "email"],
+     ["apps", "settings"],
+     ["apps", "clock"],
+     ["apps", "calendar"]
+   ],
+   [ // We're on Page 2 of the homescreen
+     ["external-apps", "customapp1"],
+     ["external-apps", "customapp2"],
+     ["external-apps", "customapp3"],
+     ["external-apps", "customapp4"]
+   ]
+ ]}
+ +

The first item inside each sub-array is the folder the app appears inside; the second is the app directory name.

+ +

Collections

+ +

Collections are groups of apps that have their own icon that appears on the homescreen. When this icon is tapped, a new screen appears containing all the icons for the apps in the collection. Have a look at the collections directory in the source code to get more of an idea of how these work.

+ +

By default, four Collections are prefilled on the first page of the Gaia homescreen: Social, Games, Music, and Entertainment. In homescreens.json it's possible to define what collections to load, what pages they should appear in and in what order. For example, if we wanted to specify these four default collections to appear, we would write this:

+ +
{"homescreens": [
+   [
+     ["apps/homescreen/collections", "social"],
+     ["apps/homescreen/collections", "games"],
+     ["apps/homescreen/collections", "music"],
+     ["apps/homescreen/collections", "showbiz"]
+   ], [
+     ["apps", "communications", "dialer"],
+     ["apps", "sms"],
+     ["apps", "browser"],
+     ["apps", "camera"]
+   ]
+ ]}
+ +

Each top level array position refers to a page of the homescreen. Here, the collections would appear in the dock, and the individual apps would appear on page 1 of the homescreen.

+ +
+

Note: Collection names are written in lowercase.

+
+ +

Collections can be chosen from the following list:

+ + + +
+

Note: As of Firefox OS 1.3, you can define your own custom collections. You simply create them inside the collections directory as explained below, and point to them inside collections.json as shown above.

+
+ +

What collections contain

+ +

Collections are composed of two types of app.
+
+ Local apps are defined at build time by means of manifest files, located at /apps/homescreen/collections/<collectionName>/manifest.collection. The local apps contained within each collection are defined in the mainfest file. For example, the social collection (contains dialer, sms, contacts and email apps) manifest looks like so:

+ +
{
+  "name": "Social",
+  "role": "collection",
+  "provider_id": "289", // adaptive search identifier
+  "apps": [
+    ["apps", "communications", "dialer"],
+    ["apps", "sms"],
+    ["apps", "communications", "contacts"],
+    ["apps", "email"]
+  ],
+  "default_locale": "en-US",
+  "icons": {
+    "60": "/collections/social/icon.png",
+    "90": "/collections/social/icon@1.5x.png",
+    "120": "/collections/social/icon@2x.png"
+  }
+ }
+ +

Remote apps are supplied by the adaptive search provider at runtimee, when the device is online.

+ +

How to translate collections

+ +

Collection translations have to be defined in locale files in within the homescreen app, in the apps/homescreen/locales/. directory. Each different locale file has a name structure looking like collections.<langCode>.properties — where <langCode> is for example fr for French — and contains simple lines containing the default English string and translated version. An example from the French locale file follows:

+ +
# Add bookmark to homescreen
+add-to-home-screen=Ajouter à l’écran d’accueil
+add-to-home-screen-header=Ajouter un lien
+website-name=Nom du site web
+address=Adresse
+added-to-home-screen=Ajouté à l’écran d’accueil
+ +

network.json (not in customization folder)

+ +
+

Important: This is no longer supported in Firefox OS 1.4.

+
+ +

In Firefox OS < 1.4, this file can be created in gaia/apps/settings/resources, and it allows you to set the network types supported by the device. Firefox OS supports the following types:

+ + + +

An example is as follows:

+ +
{
+  "types":  [
+    "cdma/evdo",
+    "cdma", "evdo"
+  ]
+}
+ +

sensors.json

+ +

Defines the sensor capabilities of the device. By default it contains:

+ +
{ "ambientLight": true }
+ +

You can set the value to false if you want to disable device sensor capabilities.

+ +

settings.json

+ +

This file allows you to set default wallpaper/ringtones, lockscreen enable/disable, bluetooth on/off, etc. You can consult build/config/common-settings.json to find out what settings can be set in settings.json;  for example you can set "wifi.enabled": false to disable wifi by default.

+ +

Customize default Homescreen APP

+ +

homescreen.appName allows you to set specific APP as default Homescreen APP.

+ +
+
{ "homescreen.appName": "homescreen-stingray" }
+
+ +

sms-blacklist.json

+ +

This file contains a custom SMS blacklist: numbers specified in this file can't have SMS message sent to them. This list will overwrite blacklist.json file in the SMS app. The numbers are specified in an array, like so:

+ +
["11223344", "55667788"]
+ +

cellbroadcast

+ +

Listening Channels:

+ + + +

Disable event reporting:

+ + + +
+

Note: Default settings are available in operator_variant.xml.

+
+ +

support.json

+ +

This file contains support contacts, including online support & telephone support. When included, this file will overwrite support.json in the Settings app. Since these customizations will overwrite the default settings, if you want to keep default settings and add some extra resources you should copy those settings from the built-in apps and add your own customization onto them.

+ +

Here's an example of what the JSON should look like:

+ +
{
+   "onlinesupport": {
+     "href": "http://support.mozilla.org/",
+     "title": "Mozilla Support"
+   },
+   "callsupport": [
+     {
+       "href": "tel:12345678",
+       "title": "Call Support 1"
+     },
+     {
+       "href": "tel:87654321",
+       "title": "Call Support 2"
+     }
+   ]
+ }
+ +

WAP user agent profile (wapuaprof.json)

+ +

The WAP user agent profile overrides the user agent information when sending WAP packets. If you want to override the default WAP user agent profile based on MCC/MNC, you can use this one to do it  (further explained in runtime customization).

+ +

apps.list

+ +

This allows you to specify which apps you want to load up at runtime (in a similar manner to variant.json, as explained in the Applications section below.) The applications are specified like so:

+ +
apps/*
+external-apps/*
+outoftree_apps/*
+ +

You can specify individual apps rather than whole folders of apps, like this:

+ +
apps/email
+apps/settings
+ +
+

Note: If you want to include custom external apps as part of your Gaia build, you need to build them in a specific way, and then place them into the gaia/external-apps/ folder. Read Building Prebundled web apps to find out how.

+
+ +
+

Important: Apps that you add as part of a customized Firefox OS build need to be added in agreement with Mozilla's Distribution Agreement.

+
+ +

Other customization options

+ +

There are many other customizations that can be made, which we should explore more. Let's look at them now.

+ +
+

Note: The build script used in many of the below sections can be found in gaia/build/applications-data.js. This gets copied into an init.json file in the browser app directory at build time.

+
+ +

Browser bookmarks and default search engine

+ +

The default bookmarks and default search engine can be customised at build time, with different variants for each country and network in a single build. The customised data is inserted into the browser app the first time it is run, based on the MCC and MNC codes of the SIM card present in the device at the time.

+ +
+

Note: Bookmarks can be customised in Firefox OS 1.0.1+; default search engines can be customised in Firefox OS 1.2+.

+
+ +

The example below (browser.json) shows a configuration for Vivo in Brazil (724006, where 724 is Brazil and 006 is Vivo according to the MCC and MNC codes), along with a default fallback (000000) in case a non-matching SIM card or no SIM card is present.

+ +
content = {
+   '000000': {
+     'bookmarks': [
+       { 'title': 'Mozilla',
+         'uri': 'http://mozilla.org',
+         'iconUri':
+           'data:image/png;base64,AAABAAIAEBAAAAEAIABo[truncated]'
+       },
+       { 'title': 'Firefox OS',
+         'uri': 'http://mozilla.org/firefoxos',
+         'iconUri':
+           'data:image/png;base64,AAABAAIAEBAAAAEA[truncated]'
+       }
+     ],
+     'searchEngines' : [
+        {
+          'title': 'Google',
+          'uri': 'http://www.google.com/search?q={searchTerms}',
+          'iconUri':
+            'data:image/png;base64,AAABAAIAEBAAAAEAIABoBAA[truncated]'
+        }
+      ],
+      'settings' : {
+        'defaultSearchEngine': 'http://www.google.com/search?q={searchTerms}'
+      }
+   },
+
+   '724006': {
+     "bookmarks": [
+       { "title": "Vivo Busca",
+         "uri": "http://www.google.com.br/m/search",
+         "iconUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC[truncated]"
+       },
+       { "title": "Serviços e Downloads",
+         "uri": "http://vds.vivo.com.br",
+         "iconUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACA[truncated]"
+       },
+       {
+         "title": "Site Vivo",
+         "uri": "http://www.vivo.com.br/conteudosmartphone",
+         "iconUri": "data:image/jpg;base64,/9j/4AAQSkZJRg[truncated]"
+       }
+     ],
+     'searchEngines' : [
+        {
+          'title': 'Yahoo',
+          'uri': 'http://search.yahoo.com/search?q={searchTerms}',
+          'iconUri':
+            'data:image/png;base64,AAABAAIAEBAAAAEAIABoBAA[truncated]'
+        }
+      ],
+      'settings' : {
+        'defaultSearchEngine': 'http://search.yahoo.com/search?q={searchTerms}'
+      }
+   }
+ };
+ +

In the example, if a Vivo SIM card from Brazil is entered on first run the user will see Vivo bookmarks and Yahoo as the default search engine. If another SIM card or no SIM card is entered on first run the user will see Mozilla bookmarks and Google as the default search engine. There are a few important parts to note:

+ + + +
+

Note: The browser application will show bookmarks in reverse order, the first bookmark in the json will be shown the last one and so on.

+
+ +

Data and messaging settings

+ +

Device data and messaging settings are runtime customizable.

+ +

To apply specific settings, change gaia/shared/resources/apn/apns_conf_local.xml, simply adding or editing carrier blocks as required:

+ +
 <apn carrier="Test Network"
+      mcc="001"
+      mnc="01"
+      apn="internet"
+      user="user"
+      password="password"
+      proxy="127.0.0.1"
+      port="8080"
+      mmsc="http://127.0.0.1"
+      mmsproxy="127.0.0.1"
+      mmsport="8080"
+      authtype="0"
+      type="default,supl,mms"
+  />
+ +

Voicemail and cell broadcast settings

+ +

To apply specific voicemail and cell broadcast settings, change gaia/shared/resources/apn/operator_variant.xml. Add or edit a carrier block, changing attributes as needed:

+ +
   <operator carrier="Test Network with Operator Variant Settings"
+       mcc="001"
+       mnc="01"
+       cellBroadcastSearchList="0,1,2,3"
+       voicemail="999999"
+   />
+ +

WAP user agent profile

+ +

The WAP user agent profile is another app that supports runtime customization. It overrides the user agent information when sending WAP packets, based on MCC/MNC. The profile overriding has url and tagname parts, but we only support url in our current implementation.

+ +

The WAP user agent profile uses the same coding style for its key as the browser app, although "000000" is used as the default profile. An example follows:

+ +
   {
+     "000000": {
+       "url": "http://example.url/default.xml"
+     },
+     "123001": {
+       "url": "http://example.url/custom123001.xml"
+     }
+   }
+ +

In this example, the url of the default profile is http://example.url/default.xml; for mcc = 123 and mnc = 001, the url is http://example.url/custom123001.xml. If there was another ic card with mcc = 123 and mnc=100, its url would be http://example.url/default.xml.

+ +

If the 000000 is removed from this example, like so:

+ +
  {
+     "123001": {
+       "url": "http://example.url/custom123001.xml"
+     }
+   }
+ +

the url of UA profile of ic card with mcc = 123, mnc = 001 is now overridden as http://example.url/custom123001.xml. No others will be overridden.

+ +

If we have the "000000" as before, but we also have a "123001" case with no url inside it, like so:

+ +
   {
+     "000000": {
+       "url": "http://example.url/default.xml"
+     },
+     "123001": {}
+   }
+ +

All UA profile urls are now overridden as http://example.url/default.xml

+ +

Applications

+ +

Applications installed in Firefox OS can be customized at runtime, in a number of ways (see also Customizing the build-time apps). Perhaps the most powerful way is to edit the variant.json configuration file, which allows apps to be selectively installed and placed in the desired position in the homescreen, depending on the MCC/MNC. The customized applications will be added to the standard applications list.

+ +

The relevant part of the variant.json file typically looks like so.

+ +
   {
+     "apps": {
+       "puzzle":
+         {
+           "manifestURL": "https://owd.tid.es/store/packages/fe8e4a866c518a42db9d2041568684c1.webapp"
+         },
+       "store":
+         {
+           "manifestURL": "https://owd.tid.es/store/manifest.webapp",
+           "installOrigin": "https://www.openwebdevice.com"
+         }
+     },
+     "operators": [
+       {
+         "id": "movistar-co",
+         "mcc-mnc": [
+           "214-01",
+           "214-02"
+         ],
+         "apps": [
+           {
+             "id": "store",
+             "screen": 0,
+             "location": 2
+           }
+         ]
+       },
+       {
+         "id": "movistar-mx",
+         "mcc-mnc": [
+           "215-23"
+         ],
+         "apps": [
+           {
+             "id": "store",
+             "screen": 0,
+             "location": 2
+           },
+           {
+             "id": "puzzle"
+           }
+         ]
+       }
+     ]
+   }
+ + + +

Support contacts, default contacts, wallpaper & ringtone

+ +

The same file variant.json file — used to configure applications at runtime depending on the MCC/MNC — also allows you to configure specific resources by adding some attributes under each operator object. Thus, an operator can have the following settings:

+ +
   { apps: ...
+     "operators": [
+       {
+         "id": "movistar-co",
+           "mcc-mnc": [
+             "214-01",
+             "214-02"
+           ],
+         "apps": [
+           {
+             "id": "store",
+             "screen": 0,
+             "location": 2
+           }
+         ],
+         "support_contacts": "resources/support_contacts_movistar.json",
+         "default_contacts": "resources/contacts_movistar.json",
+         "ringtone": {
+           "path": "resources/Movistar_Mid_ABR_128kbps.ogg",
+           "name": "Tono Movistar"
+         },
+         "wallpaper": "resources/customize.jpg"
+       },
+       ...
+   }
+ +

For each operator:

+ +
    +
  1. support_contacts specifies a path to a file containing contacts to be shown on the help screen (Settings > Help), offering the same functionality as support.json. The file format is: + +
       {
    +     "onlinesupport": {
    +       "title": "Mozilla Support",
    +       "href": "http://test.mozilla.org/support"
    +     },
    +     "callsupport1": {
    +       "title": "Call Support (Primary)",
    +       "href": "tel:14155550001"
    +     },
    +     "callsupport2": {
    +       "title": "Call Support (Secondary)",
    +       "href": "tel:14155550002"
    +     }
    +   }
    +
  2. +
  3. default_contacts contains the path to a file containing contacts that will be preloaded to the Contacts application, depending on the MCC/MNC pair present at run time. The section names are the MCC/MNC pair, and section contents should be an array of contacts following the same format as contacts.json. For example: +
        {
    +        "123123":
    +        [
    +            {name: ["John Doe"]},
    +            // etc
    +        ],
    +    }
    +
    +
  4. +
  5. ringtone sets the default ringtone and contains two attributes, both mandatory: +
      +
    • path: The path to the ringtone audio file.
    • +
    • name: The name to display when the ringtone is shown in settings.
    • +
    +
  6. +
  7. wallpaper contains the path to the image file (PNG) that will be set as a default wallpaper.
  8. +
+ +

Building Prebundled web apps

+ +

Earlier on, we discussed the apps.list file, and how this can be used to add built-in apps to your build. These apps need to be built in a certain way, then added to the gaia/external-apps directory.
+
+ To build Prebundled web apps, you can utilize our gaia-preload-app script, which builds a prebundled webapp from a given .webapp URL. It can accept hosted web app manifests, or packaged app mini-manifests.

+ +

To bundle a single web app

+ +

Find a .webapp URL that want to bundle, and run the command to bundle it, as follows:

+ +
python preload.py http://<webapp url>
+ +

This will generate a directory with the same name as the target webapp's name, e.g. accuweather.

+ +

Batch process to bundle multiple web apps

+ +

You can create a file called list, containing all the app names and .webapp locations you want to bundle all together in a batch. The format is:

+ +
    myFirstApp,https://www.firstapp.com/manifest.webapp
+    mySecondApp,https://www.secondapp.com/manifest.webapp
+    etc.
+ +

You need to save this list file in the same directory as our preload.py script, then run the following command:

+ +
    $ python preload.py
+ +

The preload.py script will parse the list file and do the batch conversion for you.

+ +

Prebundled web app metadata.json

+ +

Every Prebundled webapp should have a metadata.json file contained within its root directory. The Firefox Marketplace counts on this metadata.json file for auto-updating. This file is auto-generated by the preload.py script.
+
+ For a hosted webapp, the properties of metadata.json are:

+ + + +

For a packaged webapp, the properties of metadata.json are:

+ + + +

Packaged web app update.webapp format

+ +

Packaged webapps have an update.webapp file, which is used for auto-updates. The format is similar to manifest.webapp, but you have to include additional attributes:

+ + + +
  {
+    "name": "Game Pack",
+    "icons": {"60": "/icon-60.png", "128": "/icon-128.png"},
+    "version": "1.1.2",
+    "package_path": "/application.zip",
+    "developer": {"url": "http://abc.com", "name": "abc Inc."},
+    "release_notes": "2nd release",
+    "locales": {"es": {"launch_path": "/index-es.html", "description": "show me customization."}},
+    "size": 5460141
+  }
+ +

Pre-bundled web app AppCache format

+ +

If your web app's manifest.webapp has an appcache_path included in it, the preload.py script will fetch the AppCache file  pointed to, and pre-fetch all the resources described in the AppCache file. The Pre-bundled webapp AppCache is a bit different, as Gecko recognizes a different format, but this is auto generated by the preload.py script.

+ +

The translated file structure is:

+ +
    <app name>
+       ├── manifest.webapp
+       └── cache
+             ├── manifest.appcache
+             └── <resources>
+
+ +
+

Note: If a different name is given to the AppCache file in the appcache_path, it needs to be renamed to manifest.appcache and saved in the cache folder.

+
+ +

FAQ

+ +

The following is a list of common questions about market customizations, and their answers.

+ +

What can be customized?

+ + + +

How and where do you define a customized app grid layout?

+ +

This is currently defined in gaia/apps/homescreen/js/init.json. customize.py takes care of building this in the correct format.

+ +

Is it possible to define whether an app is removable in the homescreen configuration?

+ +

No. All apps in /system/b2g are non removable, those in /data are removable. Since all preloaded apps come from /system, we need to move them to /data if we want them to be removable.

+ +

How do you add a preloaded packaged or hosted app to the build?

+ +

These should both be added to gaia/external-apps. customize.py will allow entry of the URL to a packaged app or a hosted app manifest, and will download it into the correct place and create metadata.json. This will serve as the "build step".

+ +

We have different metadata for packaged and hosted apps to distinguish them.

+ +

See Building Prebundled web apps for more details.

+ +

How do you prepare a preloaded hosted app for initial offline support?

+ +

You need to provide all the files to cache in the directory external-apps/MY_APP/cache, along with the AppCache manifest.

+ +

Again, see Building Prebundled web apps for more details.

+ +

What Marketplace Customizations Are Possible?

+ + + +

There are many other considerations when adding a region or carrier.  See Adding Regions and Carriers for more details.

+ +

How do I package and store per-market customization changes?

+ +

Store only the files changed; currently these are in various locations in the filesystem. In B2G v2, we are considering consolidating these into a single location, similar to the branding directories we have for Gecko.

+ +

How do you build the product with a specific market's configuration?

+ +

Copy your changed files into a checkout of Gaia, and build using that modified Gaia. customize.py will provide a UI for setting relevant switches, create the appropriate files in the appropriate places in the gaia checkout, and then build the profile from that gaia.

+ +

How to customize power on / off animation?

+ + diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/modifying_hosts_file/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/modifying_hosts_file/index.html new file mode 100644 index 0000000000..569bd5b114 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/modifying_hosts_file/index.html @@ -0,0 +1,43 @@ +--- +title: 修改 hosts 文件 +slug: Archive/B2G_OS/Developing_Firefox_OS/modifying_hosts_file +tags: + - Android + - B2G + - Firefox OS + - hosts +translation_of: Archive/B2G_OS/Developing_Firefox_OS/modifying_hosts_file +--- +
+

由于遭受攻击,阻止不希望的连接,将请求重定向到一个特定 IP 等原因,有时您需要对机器上的 hosts 文件进行编辑。本文则阐述了如何修改您 Fiefox OS 手机上的 hosts 文件。 在 Linux 系统下,它位于 /system/etc 目录下,而在 Mac OSX 系统下,位于 /etc 目录下。

+
+

准备您的手机

+

打开手机,进入开发者设置面板Developer settings panel 检查一下:

+ +

将手机插入您的电脑上。

+

下面,修改 hosts 文件的步骤就与 Android 相同了。 Android开发者则能够快速的进行设置。

+

终端中的步骤

+
    +
  1. 打开终端窗口
  2. +
  3. 重新装载设备上的 /system 分区,以获得读-写 权限。 +
    adb remount
    +
  4. +
  5. 在电脑上获取 hosts 文件 +
    adb pull /system/etc/hosts /tmp
    +
  6. +
  7. 按照所需修改 /tmp/hosts 文件并保存。例如 : +
    127.0.0.1         localhost
    +ip.to.re.direct   hostName
    +
  8. +
  9. 将修改的 hosts 文件推送到设备 +
    adb push /tmp/hosts /system/etc/hosts
    +
  10. +
+

这样就完成啦,您的 hosts 文件现在就应更新啦。

+
+

注意: 要了解更多关于 ADB 的内容,请参考 ADB 文档

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/developing_firefox_os/quickstart_guide_to_gaia_development/index.html b/files/zh-cn/archive/b2g_os/developing_firefox_os/quickstart_guide_to_gaia_development/index.html new file mode 100644 index 0000000000..6000b95c7d --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_firefox_os/quickstart_guide_to_gaia_development/index.html @@ -0,0 +1,193 @@ +--- +title: Gaia 开发快速入门 +slug: Archive/B2G_OS/Developing_Firefox_OS/Quickstart_guide_to_Gaia_development +translation_of: Firefox_OS/Developing_Gaia +--- +
+

本指南提供了关于Gaia apps调试和开发的快速入门步骤,内容包括在桌面版Firefox中运行Gaia和Firefox OS App Manager中运行Gaia。 在阅读指南之前,您需要具备如下条件: 了解HTML5技术,熟悉MVC设计模式并且对Firefox OS 有着强烈的兴趣。在学习完成本指南后,您能够掌握如下知识: Gaia app的基本架构,修改Gaia apps的基本工作流程以及如何对apps进行测试。

+
+ +

您需要什么?

+ +

有两种方式对Gaia/B2G的开发环境进行配置,分别是配置本地的环境或者使用 FoxBox 编译环境. 下面就让我们分别通过这两种方式来运行Gaia吧!

+ +

配置本地环境

+ +
    +
  1. 首先,您要完成对Git的安装.如果您更喜欢在可视化环境下工作,可以考虑安装下Github客户端 (GitHub for Mac / GitHub for Windows).Git可以更新代码,对更改进行提示以及观察其他开发者的工作,因此十分有必要来熟练掌握它。
  2. +
  3. 然后就是在本地机器上要获得一份Moziila Gaia的仓库: https://github.com/mozilla-b2g/gaia. 最好的方式就是fork这份仓库,并且通过使用命令git clone https://github.com/<your github name>/gaia.git.将您fork的仓库clone到本机的电脑上。由于仓库相当大,大约在700M左右,可能需要花费一些时间。
  4. +
  5. 完成上面的步骤,您就可以在终端中进入仓库 (cd gaia) 并且运行 DEBUG=1 make 命令编译以及配置调试模式下的Gaia仓库。命令运行中会下载 XULRunner -- 我们可以使用它对Mozilla运行时的包进行安装,更新和卸载,还可以使用它执行所需的编译步骤。 +
    Note:如果您想要了解更多,可参考Gaia Make options
    +
  6. +
  7. 在完成工作区的配置后, 就需要来安装Firefox Nightly 版本
  8. +
  9. 在Nightly版本中, 可以选择是使用火狐仿真器扩展插件还是App Manager插件,这主要取决于您到底喜欢哪种工作流程.如果身边没有可用的物理设备,但选择使用APP Manager的方式,虽然 The App Manager 扩展插件已经预安装在nightly 版本中,但是您仍然需要安装 Firefox OS simulator
  10. +
  11. 安装 ADB helper 来调试手机等远程设备。
  12. +
  13. 您可能想要获得一部 Firefox OS 手机. 在手机上可以获取到诸如应用程序的启动事件,帧速率等各种使用信息。同样,一旦能够在设备上运行真实的操作系统,您也可以轻松的对所有支持的设备APIs进行测试。
  14. +
+ +

配置FoxBox虚拟环境

+ +

FoxBox是指包含在VM(虚拟机)中的Firefox OS编译环境,由 Vagrant 和 VirtualBox提供。它有许多优点,最主要的就是在可以为您完成大量的配置工作,从而使您能够专心的进行开发工作。要了解它的完整的内容,可以阅读  FoxBox GitHub repo README.

+ +

现在您已经完成了基本工作区的配置,让我们下面一起向应用进发吧!

+ +

Firefox OS  原生应用

+ +

Gaia 源码中提供的原生的HTML5应用如下所示:

+ + + +

当手机开机时,第一个启动的应用是系统应用(System app)。该应用主要是负责打开和管理主屏幕。在主屏幕界面则可以启动其他的应用以执行以执行各种功能。例如,当用户点击手机图标时,则会从主屏幕启动拨号盘应用 。当用户在拨号时想要查看联系人列表时,又可以启动联系人应用。

+ +

一起来探索下一些应用的结构

+ +

原生应用都存放在 gaia/apps/ 文件夹下. 每个 Gaia 应用的文件夹下都包含下面的组件:

+ + + +

有一些应用还可能有下面的组件:

+ + + +
+

重要: 除了上面列举的文件外,还可能会存在一些额外的文件,比如LazyLoaders以及定制的模板引擎和其他一些关于应用的优化。你也可能会注意到,在不同的应用或者 .js 文件中使用的模式也不尽相同。 记住,这是一个开源的app/OS, 它是由很多人编码而成的,因此这些应用也是使用不同的模式和编程风格而完成的。

+
+ +
+

注意:本节是对Gaia应用总体布局的介绍。您自己在创建web应用时,当前必须要创建的文件只有  manifest.webapp文件;其他的文件都是可选的。

+
+ +

我相信,如果您有关于web开发的经验,就会尽其所能的对一些app进行修改,从而使它们不断得到完善。

+ +

我们一起来启动一些应用吧

+ +

在对这些应用进行修改后,如果想立刻看到修改后带来的变化,可以通过下面的几种方式来实现:在  Firefox Nightly中运行,将应用推送到物理设备端,或者通过Firefox OS 应用管理器(可以在模拟器上或者真实设备上)运行。

+ +

运行在Firefox Nightly中

+ +

要在Firefox Nightly中运行Gaia以及查看应用 , 需要使用下面的结构来运行命令:

+ +
/path/to/firefoxnightly -profile /path/to/B2G/gaia/profile-debug -no-remote
+ +

例如在Mac OS X中,可以运行下面的命令:

+ +
/Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /Users/bob/git/gaia/profile-debug -no-remote
+ +
+

Note: -no-remote 是用来阻止使用已存在的Firefox实例,从而创建一个新的Firfox应用来运行定制的Gaia配置文件。 profile-debug 是指运行Gaia调试模式下的配置文件,该文件是使用之前步骤中的 DEBUG=1  make command 命令生成。

+
+ +

在启动时会耗费一些时间,但是最终Gaia实例以及许多控制选项会在一个新的浏览器窗口中运行。

+ +

A UI screen showing the Gaia user interface running in Firefox nightly: a phone screen and number of tool bar controls.

+ +

另外如果您只想在浏览器中运行一个应用,一个更加快速的方法就是在浏览器中通过file://URL的格式简单的输入应用的根HTML文件(例如在浏览器中打开index.html)。然后可以使用 Responsive Design View 工具观察在小屏幕分辨率的效果. 如果想要做一些快速UI开发/调试的工作,这是一个非常有用的方法,而且在实例装载方面也有许多优势。此时,火狐开发者工具也是十分有用的,例如测试CSS调整的效果。

+ +
+

注意: 由于该方法并不能对硬件设备进行访问,因此有许多功能都无法工作,再加上你无法看到app启动的过程,在主屏幕看到图标等弊端,比较而言,运行在物理设备上还是最好的办法,这在下面章节中有介绍。

+
+ +

运行在物理设备上

+ +

要将更改后的Gaia推送到物理Firefox OS 设备,您需要:

+ +
    +
  1. 已完成对 adb 的安装或者安装了前面描述的l ADB helper .
  2. +
  3. 在终端中输入adb devices命令来检查您的手机是否和电脑通过 adb 命令建立了成功的连接。
  4. +
  5. 在Gaia目录下输入make reset-gaia 命令从而通adb推送到手机
  6. +
+ +

这种方式会耗费些时间,如果使用App manager则会更快一些。

+ +

在 App Manager中运行

+ +

只要您的Firefox 版本在1.2以上,就可以在App Manager中运行更改后的app,在下节会对该部分内容进行介绍。

+ +

使用 App Manager来调试

+ +

在完成对应用的更改后(或者创建新的应用 ),就可以在App Manager来调试它们。

+ +

在调试之前,需要具备下面的条件: App Manager和设备之间能够正常通信,如果没有物理设备可以使用 Firefox OS 仿真器。这些条件在使用App Manager 有详细阐述。

+ +

下面就是选择想要调试的应用了 — 在 App Manager中添加包应用控制,并选择要调试的应用的文件夹。首次操作应用时,需要点击“Start”按钮将应用安装在 设备端/模拟器端并启动它。之后就可以点击“Update”按钮将更新推送到设备/模拟器端,而且使用Mozilla的开发工具在设备端对应用直接调试。

+ +

例如,下面就是在App Manager中运行 Contacts 应用的图示。

+ +

A card showing details of the Gaia contacts app: a simple contacts application.

+ +

同时也可以去尝试下调试的一些功能,例如,运行一些终端命令或者对更改CSS特性。

+ +

A screenshot of the Mozilla App Manager

+ +

为项目贡献代码

+ +

只要您对自己在Gaia仓库中的更改感到满意,就可以向GitHub上的代码库提交pull请求。如果您不知道怎么做,可以去参考GitHub 帮助页面的 Using Pull Requests

+ +

实际上,您的pull请求如果没有经过Gaia开发团队的讨论和认可是不会被接受的。 您可以在 dev-gaia@lists.mozilla.org 邮件列表, 或者是在 Mozilla IRC.的 #gaia IRC 通道与Gaia 开发团队进行联系。

+ +

另外一个课程就是如何在Mozilla Bugzilla 系统中提交Bug。在提交Bug时,要使用  Firefox OS project bug form (选择 Gai或者一个合适的子集作为component). 但在提交Bug前,首先要在Bugzilla 中搜寻下问题是否已经被其他人提过。 如果没有,就需要考虑下面两点:

+ + + +
+

注意:如果您不知道到底该怎么提bug,就是想要寻找一些相关的bug进行处理, 可以寻求 Josh Matthews' Bugs Ahoy 应用来帮忙。

+
+ +

常见问题

+ +

下面的内容是对在桌面上使用Gaia调试应用的一些常见问题的答案。

+ +
+

Note: 多参考 Hacking gaia 中关于可以设置的make选项对调试Gaia是非常有帮助的。

+
+ +

我能够在火狐桌面版浏览器中对高分辨率的设备进行仿真吗?

+ +

必须的!

+ +
    +
  1. 首先可以运行下面命令来确保在qHD和WVGA设备上图片是不失真的 +
    GAIA_DEV_PIXELS_PER_PX=1.5 DEBUG=1 make
    +
  2. +
  3. 然后,在火狐中打开 about:config页面,通过将layout.css.devPixelsPerPx 标志位变为1.5来更改浏览器的密度。
  4. +
  5. 最后,可以使用 Responsive Design View 变为320 x 533 px (这种设置与设备上 CSS  480 x 800 像素的效果是等价的 .)
  6. +
diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/customizing_build-time_apps/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/customizing_build-time_apps/index.html new file mode 100644 index 0000000000..573e3ac09a --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/customizing_build-time_apps/index.html @@ -0,0 +1,117 @@ +--- +title: 定制构建时 apps +slug: Archive/B2G_OS/Developing_Gaia/Customizing_build-time_apps +tags: + - Apps + - B2G + - Firefox OS + - Gaia + - 'l10n:priority' + - 定制 + - 指南 +translation_of: Archive/B2G_OS/Developing_Gaia/Customizing_build-time_apps +--- +
+

作为一个开发者或设备厂商,您可能由于各种原因想要对 Friefox OS 首次启动时的 app 进行定制。本文则说明了完成该需求的不同机制。

+
+ +

Gaia 中的 App 存放位置

+ +

运行在 Firefox OS 中的 app 都位于 Gaia 源码树下,共有两个存储位置:

+ + + +

如果您想要在编译 Gaia/B2G 时忽略或添加这些 app, 有下面几种方式可以实现:

+ +

野蛮的定制方法

+ +

所谓“野蛮”的方法是指在编译前, 将不想要参与编译的 app 直接删除即可。

+ +

编辑配置列表

+ +

相比而言,更优雅的方法则是编辑 apps-*.list 文件 (位于不同的设备目录下,在  gaia/build/config/ 内部,如 phone/tablet/) ,将需要编译的 app 路径包括进去。例如,   gaia/build/config/phone/apps-production.list 格式如下所示:

+ +
apps/bluetooth
+apps/bookmark
+apps/browser
+apps/calendar
+apps/callscreen
+etc.
+ +

注意,您也可以使用如下代码指定目录下的所有 app:

+ +
apps/*
+ +

至于在编译时,具体选择哪个  apps-*.list 文件的代码在 gaia/Makefile 文件中指定来,其形式如下所示:

+ +
GAIA_DEVICE_TYPE?=phone
+  ...
+GAIA_APP_TARGET?=engineering
+  ...
+ifeq ($(MAKECMDGOALS), demo)
+GAIA_DOMAIN=thisdomaindoesnotexist.org
+GAIA_APP_TARGET=demo
+else ifeq ($(MAKECMDGOALS), dogfood)
+DOGFOOD=1
+else ifeq ($(MAKECMDGOALS), production)
+PRODUCTION=1
+endif
+  ...
+ifeq ($(PRODUCTION), 1)
+GAIA_OPTIMIZE=1
+GAIA_APP_TARGET=production
+endif
+
+ifeq ($(DOGFOOD), 1)
+GAIA_APP_TARGET=dogfood
+endif
+  ...
+ifndef GAIA_APP_CONFIG
+GAIA_APP_CONFIG=build$(SEP)config$(SEP)apps-$(GAIA_APP_TARGET).list
+endif
+ +

最初, GAIA_APP_TARGET 变2量被设置为 engineeringGAIA_DEVICE_TYPE 变量被设置成  phone, 因此默认情况下编译 Gaia 时会使用 gaia/config/phone/app-engineering.list (其中包括所有的测试,deomo 等)。

+ +

要指定其他应用程序列表的用法,请在运行make命令时指定不同的选项。比如用 gaia/build/config/phone/apps-production.list 进行构建, 比如,你要使用:

+ +
PRODUCTION=1 make
+ +

如果你专门指定DEMO=1进行构建, 那么它将使用apps-demo.list. 如果你专门指定DOGFOOD=1进行构建, 则它将会使用apps-dogfood.list.

+ +

你可以完全覆盖该决定通过编辑 GAIA_APP_CONFIG 文件在 gaia/Makefile目录中, 并提供你自己的 apps-*.list 文件.

+ +

gaia/Android.mk 包括下面命令:

+ +
ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
+GAIA_MAKE_FLAGS += PRODUCTION=1
+B2G_SYSTEM_APPS := 1
+endif
+ +

当你构建的时候, 如果 VARIANT=user 或者 VARIANT=userdebug 被设定 (这些将会在 TARGET_BUILD_VARIANT 变量中反映), PRODUCTION=1 在构建Gaia时会自动设置.

+ +
+

注意: 要了解其他有效的 make 选项,请参考 make options 参考文档

+
+ +

使用市场化定制

+ +

第三种也是最完善(但最复杂)的方法是使用自定义方式.这将允许您在单独的目录中指定构建时的自定义说明,而无需修改Gaia的核心存储库。 您可以再不同的目录中包括自己的自定义项,或者使用源附带的目录。

+ +

例如,使用GAIA_DISTRIBUTION_DIR 这个环境变量来指定自定义示例的位置, 像这样:

+ +
GAIA_DISTRIBUTION_DIR=<DISTRIBUTION_PATH> make production
+ +

更多有关分发机制的自定义实例请参考以下网页https://github.com/mozilla-b2g/gaia/tree/master/customization

+ +

定制完全属于您的个人主题,要了解更多信息,欢迎访问我们的市场定制指南Market Customizations guide.

+ +
+

注意: 如果您希望在 Gaia 编译时包含一些自定义的外部 app, 则需要以指定的方式编译它们,并且将它们放在  gaia/dev-apps/ 文件夹中。请参考 Building Prebundled web apps  获取更多内容。

+
+ +
+

重要: 如果您是创建自定义B2G/Gaia 版本进行分发的设备供应商,则需要满足一些条件才能将firefox marketplace应用程序包含在手机/平板电脑等设备中。有关更多详细信息,欢迎联系Mozilla!

+
diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/customizing_the_keyboard/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/customizing_the_keyboard/index.html new file mode 100644 index 0000000000..64b9152bc5 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/customizing_the_keyboard/index.html @@ -0,0 +1,65 @@ +--- +title: 在 Firefox OS 中定制键盘 +slug: Archive/B2G_OS/Developing_Gaia/Customizing_the_keyboard +translation_of: Archive/B2G_OS/Developing_Gaia/Customizing_the_keyboard +--- +
+

This document explains how to add custom keyboard layouts containing their own languages/scripts to Firefox OS v1.2 and up.

+
+

Gaia 内置键盘 app 状态 & system 架构

+

Two major features have been implemented in Firefox OS, as of October 2013.

+ +

To come up with a new keyboard layout, you can put a layout file in Gaia, build the keyboard app using a build config, or come up with your own keyboard app and install it on the phone.

+

如何生成一个键盘应用 (keyboard app)

+

You can use Gaia's built-in keyboard app as a template, or fork it. The basic ideas are:

+ +

After that, you can install your keyboard, and it will show up on the bottom half of the screen whenever the user is focused to an input field. The space issues that arise from this can be dealt with by:

+ +
+

TBD: provide sample code and/or a small template app

+
+

How to add a custom layout to your template in the Gaia keyboard app

+
    +
  1. See the keyboard CONFIGURE details for more information. Depending on the language you might want to add a dictionary, or include an interactive IME (for Asian languages).
  2. +
  3. If you add layouts for a newly supported language, you may want to add them as default layouts for that language in build/config/keyboard-layouts.json.
  4. +
+

Spell check / word suggestion dictionary

+
+

TBD

+
+

Asian IME

+

East Asian languages (Chinese, Japanese, and Korean) use a fairly complex script that involves thousands of characters. As there is no way to put thousands of keys on a hardware or software keyboard, users rely on an indexing program called input method, or IME for short, to convert a series of symbols into selections of characters.
+
+ How symbols should be converted and how "smart" the IME should be depends on the method chosen, implementation itself, and often NLP science, which is outside the scope of this document. Note that it is highly recommended to put the database part into IndexedDB, in order to conserve memory on a mobile device.

+

IM Engine interface in Gaia keyboard app

+

Assuming you have an IME library readily available for converting symbols into characters (''IM Engine'' in our terminology), you would need to use the defined interface within the Gaia Keyboard app to receive symbols from the layout and output the characters. The current API is documented on Github.

+

We invite implementations in order to further refine this API within Gaia.

+

Make your IM engine work with your layout

+

To get your IM engine working with your keyboard layout:

+
    +
  1. Put a new layout in layout.js as described in the previous section.
  2. +
  3. Reference the IM engine with the imEngine property. When your layout is enabled, the keyboard app will start loading the script located at keyboard/js/imes/<imEngine>/<imEngine>.js.
  4. +
  5. Set up the APIs to receive and send the keys/characters when the script is loaded and init'd.
  6. +
  7. Do whatever you want in response to the user input. When the user taps any keys on the keyboard, it would typically get sent to the IM engine.
  8. +
+

Known implementations

+ +

讨论和问答

+

Please come to the dev-gaia mailing list or the #gaia channel on irc.mozilla.org. #mozilla-taiwan is the de-facto Chinese-language channel for this topic.
+
+  

diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/different_ways_to_run_gaia/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/different_ways_to_run_gaia/index.html new file mode 100644 index 0000000000..c77e27efea --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/different_ways_to_run_gaia/index.html @@ -0,0 +1,72 @@ +--- +title: 运行 Gaia 的不同方式 +slug: Archive/B2G_OS/Developing_Gaia/Different_ways_to_run_Gaia +translation_of: Archive/B2G_OS/Developing_Gaia/Different_ways_to_run_Gaia +--- +
+

您可以通过 App Manager中,在 Desktop Firefox 中直接运行,作为专用桌面版本(Desktop B2G), 在仿真器中, 或在可兼容的移动设备中运行 Gaia。本文则对上述每个方式如何实现的进行总结,以及链接到更深的内容。

+
+

它与真实的东西有多接近?

+

Some of the solutions for running Gaia detailed in this article are closer to the experience on a real device than others. The order of ease for running is as follows:

+
    +
  1. Gaia in simulator
  2. +
  3. Gaia in Desktop Firefox
  4. +
  5. Gaia in B2G Desktop
  6. +
  7. Gaia in Emulator
  8. +
  9. Gaia flashed on phone
  10. +
  11. Gaia+Gecko flashed on phone
  12. +
+

The order of “how close it is to the shipped product” is exactly the opposite of this. Depending on the feature you’re working on, you’ll have to find the environment that suits the problem.

+

在 App Manager/Firefox OS simulator 中使用 Gaia

+

The quickest way to try Gaia is via the Firefox App Manager.
+
+ App Manager is a developer tool available in Firefox for Desktop. It provides a number of useful tools to help you test, deploy and debug HTML5 web apps on Firefox OS phones and the Firefox OS Simulator, directly from your browser.
+
+ In desktop Firefox Browser 26+, open the App Manager using Tools > Web Developer > App Manager. Tap Start Simulator (once you've installed it) and you are ready to experience Firefox OS.

+

B2G Desktop

+

B2G Desktop is a desktop build of the app runtime used on Firefox OS devices which you can use to run Gaia on your desktop computer.

+

You can download a nightly build of B2G desktop from the Firefox Nightly site. Depending on what version you are targeting, you may want a specific version of latest-mozilla-b2g18. There are builds for Linux (32 bit and 64 bit), Mac OS X and Windows.

+

Nightly builds come packaged with a recent version of gaia. Once you've downloaded the archive, all you need to do is extract it to a folder and run the b2g binary from the extracted folder.

+
$ cd b2g
+$ ./b2g
+

To run B2G with your own version of Gaia for development purposes you first need to build a profile from your clone:

+
$ cd /path/to/gaia
+$ DEBUG=1 DESKTOP=0 make
+

This will generate a directory in your gaia directory called profile. The DEBUG part runs Gaia as hosted apps on a built-in web server, rather than the default packaged apps which have to be re-packaged after every change. You can find the path to the profile directory by taking a look at last line of output after running the above command, which should look like:

+
Profile Ready: please run [b2g|firefox] -profile /path/to/gaia/profile
+

You can then run B2G Desktop with your generated profile like so:

+
$ ./b2g /path/to/gaia/profile
+

If you want to you can build your own B2G desktop from source.

+
+

Note: On Mac OS X, the b2g binary will be inside B2G.app. To run B2G Desktop on this platform you will need the following command:
+ ./B2G.app/Contents/MacOS/b2g /path/to/gaia/profile

+
+

在 Desktop Firefox 中使用 Gaia

+

It's also possible to run Gaia inside of Firefox. This gives you the advantages of having a rapid development cycle, as well as standard web development tools and debuggers. See Running the Gaia codebase for details on how to do this.

+
+

Note: FoxBox is a Firefox OS build environment contained in a VM (Virtual Machine), powered by Vagrant and VirtualBox. This has many advantages, but the main one is that it does a lot of configuration for you, leaving you to get on with development work. For full instructions, read the FoxBox GitHub repo README.

+
+

在真实设备中烧写 Gaia

+

要在真实设备上烧写新版本的 Gaia 需要下列步骤:

+
    +
  1. 首先请确认您本地的电脑上有 Gaia 仓库,并且 ADB 已安装。
  2. +
  3. 确认您已经使能  Debugging via USB 选项。
  4. +
  5. 通过 USB 将您的设备连接到电脑上。
  6. +
  7. 如果您有一个连接的设备,可以继续下面的命令。或者您( Windows 或 Linux 系统的用户)可能需要检查下 OEM USB 驱动页面来对您电脑中的 USB 驱动进行正确配置。
  8. +
  9. 在 Gaia 仓库中运行下面命令以对手机进行复位以及更新您的 Gaia 源码: +
    $ make reset-gaia
    +
  10. +
  11. 要测试非 System app, 您可以在不重启设备情况下运行下面命令来安装: +
    $ make install-gaia
    +
  12. +
  13. 如果您只是想安装一个指定的 app, 可以通过 APP 变量来完成, 就如下面的命令: +
    $ make install-gaia APP=browser
    +
  14. +
+

要检查您的设备是否已正确的通过 USB 连接, 可以键入下面命令:

+
$ adb devices
+

您应该获取到如下类似的结果:

+
List of devices attached
+emulator-5554  device
+

编译 Gecko 和 Gaia 并在仿真器或真实设备中使用

+

如果您有一个可兼容的移动设备,则可以 编译和安装您自己的 Firefox OS 版本 并且将其运行在仿真器或推送到实际设备上。

diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/index.html new file mode 100644 index 0000000000..ea781858de --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/index.html @@ -0,0 +1,54 @@ +--- +title: Gaia 开发 +slug: Archive/B2G_OS/Developing_Gaia +translation_of: Archive/B2G_OS/Developing_Gaia +--- +
+

Gaia 是 Firefox OS 用户界面及一套原生app:它包括 lock screen, home screen, dialer, 以及其他应用。简而言之,Gaia是运行在Firefox OS 平台的一个复杂的web应用集合 。这组文档会涵盖为Gaia工程贡献代码所需要的所有知识。

+
+

在本指南中,我们会带您为 Gaia 贡献代码的有效的工作流程—此处的贡献是指为 Gaia 代码库添加新的功能以及为 Gaia 工程解决bug。第一组文档是需要顺序阅读的,但如果您需要更新下您在特定步骤的知识,也可以阅读指定的章节。

+

后面,我们就会提供包括额外主题的参考资料和信息。

+

+

基础

+
    +
  1. 运行 Gaia 代码库
  2. +
  3. 理解 Gaia 代码库
  4. +
  5. 修改 Gaia 代码
  6. +
  7. 测试 Gaia 变化的代码
  8. +
  9. 提交 Gaia patch
  10. +
+

Gaia 构建参考

+ +

参考

+ +

+ +
+

加入 Gaia 社区

+
+
请选择你喜欢的方式加入我们:
+ +
+
+ +
+
+

diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/localizing_firefox_os/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/localizing_firefox_os/index.html new file mode 100644 index 0000000000..dfd446cac6 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/localizing_firefox_os/index.html @@ -0,0 +1,107 @@ +--- +title: Firefox OS 本地化 +slug: Archive/B2G_OS/Developing_Gaia/Localizing_Firefox_OS +translation_of: Archive/B2G_OS/Developing_Gaia/Localizing_B2G_OS +--- +
+

在本指南中,我们会告诉您如何简单的对 Firefox OS 进行本地化,尤其是 Gaia 接口和 apps。我们会从帮助您从配置电脑开始,继而描述如何本地化 Gaia 字符串, 最后介绍如何在您的工作中执行 l10n 测试。

+
+

准备您的工具

+

为了能获得 Gaia 的源码并在您的电脑中测试本地化字符串, 您需要确保在电脑中已安装了下面的工具和语言:

+
+
+ GNU make
+
+ make 是一个有用的小工具,用来从源码中创建构建操作。当您准备好在电脑上进行 l10n 测试时,它就会排上用场。下载和安装 make 工具是非常简单的,可以直接借助 GNU 网站完成。 如果您在使用 Mac OSX, 则需要从  App Store 中安装 XCode 和 XCode's 命令行工具。
+
+ git
+
+ git 是一个版本控制系统,用来存储正在积极开发的 Gaia 源代码。下载和安装 git 是非常简单的,能够直接借助它们的网站来完成。
+
+ Python
+
+ Python 是一种编程语言,将帮助您创建对 l10n 测试的 Firefox OS 构建过程。 下载和安装 Python 是非常简单的,可以直接通过它们的网站来完成。
+
+ Mercurial (hg)
+
+ Mercurial (hg) 也是一个版本控制系统, 会收藏稳定的 Gaia版本以用于 l10n, 本地仓库也是一样。 下载和安装 Mercurial 是非常简单的,能够直接通过 直接通过它们的网站来完成
+
+ compare-locales
+
+ compare-locales 是一个 Python 脚本,可以帮助本地化工作者评估它们的工作并将需要本地化的内容与已经本地化的内容分离(称之为 diff) 。 下载和安装 compare-locales 是非常简单的,可以  done 直接通过 compare-locales wiki 页面完成。请注意,如果您仅仅使用命令行或文本编辑器,该工具是必须的。如果您使用 pootel, Tansifex 或 Pontoon 等工具,则不需要使用它。
+
+

配置本地化仓库

+

在您确认已经完成对上面软件列表的下载和安装后,就可以在您的电脑中获取源码并本地化字符串了。

+
    +
  1. 请在命令行下,进入您存储 Gaia 代码和本地化字符串的目录
  2. +
  3. 使用 hg,  将 en-US 仓库 clone 到本地, 请使用下面的命令完成。
    +
    hg clone https://hg.mozilla.org/gaia-l10n/en-US
    +
    +
  4. +
  5. 现在,使用带有下面结构的命令 clone 您的本地化仓库。下面例子中,第二行命令则是指将繁体中文 clone 到对应的文件夹中。 
    +
    hg clone https://hg.mozilla.org/gaia-l10n/your-locale-code
    +hg clone https://hg.mozilla.org/gaia-l10n/zh-TW/ B2G/gaia/locales/zh-TW
    +
  6. +
  7. 现在运行下面的命令:
    +
    LOCALE_BASEDIR=locales/ LOCALES_FILE=locales/languages_mine.json make
    +
  8. +
+

本地化文件会在 languages_mine.json 文件中列出,其结构如下所示:

+
{
+  "en-US" : "English (US)",
+  "fr" : "Français (fr)"
+}
+

在此文件中,您应该有一个列表的字符串去翻译!请注意, 如果您开始对 Friefox OS 新的语言进行本地化,则不需要创建一个 diff, 因为所有的字符串都是新字串,都需要我们来翻译。

+
+

注意: 在本地构建自动化脚本时,请参考  这个要点 gist

+
+

 

+

翻译 Gaia 字符串

+

The workflow for translating Gaia strings largely depends upon the tools you're using to translate. This part of the process is similar to the regular translation phase for other Mozilla products. The Translation Phase page of the Localization Quick Start Guide contains a list of all the tools used to translate strings within Mozilla products along with tutorials on how to translate with those tools. This page will be useful to you whether you're part of a l10n team trying to decide what tool to use to translate Gaia strings or you're looking for the right tutorial for the tool your team currently uses.

+

Firefox OS L10n 测试

+

There are two main methods for performing l10n testing on Firefox OS: desktop builds and mobile builds. Currently, the desktop method is the most widely used method for l10n testing.

+

Desktop l10n testing

+
    +
  1. Download and install the latest boot2gecko nightly desktop build by visiting http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-b2g18/and downloading the package that corresponds to your operating system. Look for the packages that contain the word localizer in them. This indicates that the build has all of the locales listed on languages-all.json enabled.
  2. +
  3. Clone the latest version of Gaia by navigating to the directory on your desktop where you would like it to download and entering this command in the command line utility: git clone git://github.com/mozilla-b2g/gaia.git
  4. +
  5. If your team is localizing Firefox OS for the first time, you'll need to enable your locale. If not, grab yourself a drink while everyone else enables their locale. +
      +
    1. While in the command line, navigate inside your gaia clone and run this command to clone your locale's repo: hg clone ssh://hg.mozilla.org/gaia-l10n/your-locale-code
    2. +
    3. Open the languages.json file located in the shared/resources directory in the gaia repository you just cloned.
    4. +
    5. Add your locale information according to this format: "en-US" : "English (US)", and save the file.
    6. +
    7. Finally, run the command: make multilocale This enables your locale on your desktop build.
    8. +
    +
  6. +
  7. Create your Gaia profile by running this command: DEBUG=1 make -C gaia profile
  8. +
  9. Finally, you can run Firefox OS with your locale profile and begin testing. Do this by entering this command: b2g/b2g -profile gaia/profile. If you're using Mac OS X, run this command: /Applications/B2G.app/Contents/MacOS/b2g -profile gaia/profile
  10. +
  11. To update your desktop builds, simply navigate to your Gaia repo clone and enter this command: git pull
  12. +
+

Mobile l10n testing

+

+ + This section will grow as more devices that support Firefox OS become available to localizers. +

+

What to look for when l10n testing

+

Localization testing for a mobile operating system has some similarites to localization testing for a desktop application. Here are some guidelines on what to look for when performing localization testing on your work:

+
    +
  1. See if your translations fit inside UI text elements.
  2. +
  3. Ensure that the tone, style, and terminology are consistant throughout the entire product.
  4. +
  5. Look for untranslated English strings in the UI. These may be hard-coded into Gaia or they may caused by element ID errors.
  6. +
  7. Make sure that time and dates display according your regions standards.
  8. +
+

发现本地化相关 bugs

+

Here are some links to bugzilla in order to give you examples of bugs that have been encountered while using the phones. This will give you an idea of where to look at for bugs as well as an example in filing these kinds of bugs.

+ +

General rules when filing a Localization bug:

+ +

For those of you who use Moztrap, looking at the existing test cases under the FirefoxOS "localization" tags and seeing if you can pass the tests on your device is also a good way to test Firefox OS localizations.

+

下面要做的

+

Now you're ready to start localizing! So open up your favorite l10n tool and go for it! As always, if you have questions that are not covered in this document, please send them to the mozilla.dev.l10n newsgroup.

diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/make_options_reference/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/make_options_reference/index.html new file mode 100644 index 0000000000..19e5b61e40 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/make_options_reference/index.html @@ -0,0 +1,186 @@ +--- +title: make 选项参考 +slug: Archive/B2G_OS/Developing_Gaia/make_options_reference +translation_of: Archive/B2G_OS/Developing_Gaia/make_options_reference +--- +
+

在Gaia仓库下的执行make命令会创建一个Gaia配置文件,继而装载到您的设备端或运行在 B2G Desktop 中。本文会对make不同的选项详细探究。

+
+
+

注意: 在Makefile文件中有许多环境变量,不要太依赖它们,因为在将来可能会去掉。

+
+

创建的配置文件一般存放在gaia的根目录下,例如 /gaia/profile 文件夹,其中包括下面的条目: 

+ +
+

注意: 当您已经生成了一个配置文件而且想要构建一个新的文件,就必须在构建新的配置文件前,将原有的删除。

+
+

默认命令

+
make
+

该命令只是给您一个非调试下的默认编译。 对于一个带有品牌的构建,您需要使用Official Mozilla branding make命令; 对于调试构建,您需要使用 Debug make命令。

+

推送到设备端

+
make install-gaia
+
+make reset-gaia
+
+

使用 ADB (Android Debug Bridge) 安装工具,上面的make命令会将Gaia推送到设备端。  install-gaia 会将Gaia更新从您工作的文件夹推送到设备端。 reset-gaia 在将Gaia推送到手机前会清除所有现存的配置,配置文件,web 应用以及数据库信息。

+

编译特定的应用

+
APP=system make
+
+APP=system make install-gaia
+

当一个配置文件已存在时, APP 参数允许您指定特定的app重新打包,而不是对所有的Gaia应用重新打包和重新发布。

+

指定自定义的profile文件夹

+

您可以指定一个自定义的文件夹来构建您的profile文件。例如使用 PROFILE_FOLDER:

+
PROFILE_FOLDER=profile-b2g-desktop make
+

不同设备的编译

+

下面几个 make 选项是不同的设备进行编译,其用途也会不同。

+

创建Gaia的手机端编译

+
GAIA_DEVICE_TYPE=phone make
+

此次编译是从 /gaia/build/config/phone/apps-engineering.list 文件获取app的。

+

创建Gaia的平板端编译

+
GAIA_DEVICE_TYPE=tablet make
+

此次编译是从 /gaia/build/config/tablet/apps-engineering.list 文件获取app的。

+

不同的编译类型

+

有些选项可以创建出不同的编译类型,其目的也有所不同。

+

Production make

+
PRODUCTION=1 make
+

它会创建 Gaia 的生产型编译版本

+ +
+

注意: 您也可以使用  make production 替换该命令。

+
+

Debug make

+
DEBUG=1 make
+

The DEBUG variable runs Gaia as hosted apps on a built-in web server on a specific GAIA_PORT, rather than the default of packaged apps which have to be re-packaged after every change; this makes things easier to test. Launching the profile with the latest Firefox Nightly will also give you nice B2G specific panels on the Firefox Developer Tools.

+

In addition:

+ +

Device debug make

+
DEVICE_DEBUG=1 make
+

它可以禁用设备的锁屏, 并且启用 ADB 工具,因此在设备调试时是非常有用的。

+

在 Firefox OS version > 1.2 以上版本,当想要使用 App Manager 调试 Firefox OS webapps 时指定这个参数。

+

Debug desktop make

+
DEBUG=1 DESKTOP=0 make
+

这个选项可以创建一个 desktop 调试版本, 在 B2G desktop 中运行。

+

官方 Mozilla 分支 make

+
MOZILLA_OFFICIAL=1 make
+

Use this to make an official Mozilla-branded build.

+

Dogfood make

+
DOGFOOD=1 make
+

Dogfooding options and utilities are turned on, for example the Feedback app, which allows doog fooders to easily submit feedback on the OS.

+

System apps make

+
B2G_SYSTEM_APPS=1 make
+

这个环境变量能将 app 推送到 /system/b2g 而不是 /data/local。当进行 user 编译时应使用这个命令。 当运行  make production 这个命令会自动设置。可用作install-gaia 或 reset-gaia

+

发布和市场化定制编译

+
GAIA_DISTRIBUTION_DIR=./dir
+
+

注意: Read Market Customizations for more details.

+
+

开发者/调试选项

+

There are also make options for adding/removing features or changing settings, for debugging purposes.

+

使能远程调试

+
REMOTE_DEBUGGER=1
+

This enables remote debugging on the device, the same as using the option in the developer settings.

+

JavaScript 优化 make

+
GAIA_OPTIMIZE=1 make
+

This triggers an optimization pass on Gaia's JavaScript, concatenating/compressing the files. This is automatically set when running make production. This can be used for install-gaia or reset-gaia too.

+

高分辨率图片资源

+
GAIA_DEV_PIXELS_PER_PX=1.5 make
+

When packaging the app, this option replaces images with their *@1.5x.(gif|jpg|png) equivalents if such images exist. You need to use the above option as part of a standard make command, for example:

+
GAIA_DEV_PIXELS_PER_PX=1.5 make reset-gaia
+
+GAIA_DEV_PIXELS_PER_PX=1.5 make install-gaia
+

Gaia is currently targetting the following screen resolutions:

+ +

use GAIA_DEV_PIXELS_PER_PX to make sure the images looks sharp on qHD and WVGA devices. see A pixel is not a pixel for more information about device pixels per css pixels.

+

低内存 profile 编译

+
GAIA_MEMORY_PROFILE=low make
+

This variable generates a low memory profile version of Gaia, aimed at low memory devices like the Tarako.

+

Haida features

+
HAIDA=1 make reset-gaia
+

This build enables the Haida feature set, which is currently limited to rocketbar and edge gestures, but will likely include other features in the near future.

+

禁用初次用户体验 (FTU)

+
NOFTU=1
+
+

使用这个环境变量可以禁用 FTU。

+

禁用锁屏

+

您可以使用 NO_LOCK_SCREEN 选项禁用 Firefox OS 的锁屏功能,例如:

+
NO_LOCK_SCREEN=1 make
+

参考工作负载 Reference Workloads

+

参考工作负载(Reference workloads)能够使开发者在一些应用中快速装载大量的数据,尤其是对新烧的机器。 

+

在 Gaia 目录下可执行下面命令:

+
make reference-workload-light
+ +
make reference-workload-medium
+ +
make reference-workload-heavy
+ +
make reference-workload-x-heavy
+ +

这些命令可以接受 APP 环境变量或者是 APPS 环境变量(需要使用空格将各 app 名称分开)。例如:

+
APP=sms make reference-workload-light
+APPS="sms communications/contacts" make reference-workload-heavy
+
+

The apps available are:

+
APPS="gallery music video communications/contacts sms communications/dialer"
+

为了能够使用参考工作负载 (reference workloads), 必须安装 mid3v2 工具。 这个工具可以使用下面命令安装: 

+
sudo apt-get install python-mutagen
+

如果您使用的是 Fedora 或 RHEL 操作系统,请使用下面命令:

+
sudo yum install python-mutagen
+

make 文档

+

Gaia 文档可以通过 jsdoc3 进行编译。要产生文档,可以使用下面的命令:

+
make docs
+

启用 IME 布局和词典

+

要启用键盘 IME 布局和词典, 请使用下面的命令结构:

+
GAIA_KEYBOARD_LAYOUTS=en,zh-Hant-Zhuyin,el,de,fr,zh-Hans-Pinyin make
diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/making_gaia_code_changes/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/making_gaia_code_changes/index.html new file mode 100644 index 0000000000..48f28d2bb8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/making_gaia_code_changes/index.html @@ -0,0 +1,58 @@ +--- +title: 修改 Gaia 代码 +slug: Archive/B2G_OS/Developing_Gaia/Making_Gaia_code_changes +translation_of: Archive/B2G_OS/Developing_Gaia/Making_Gaia_code_changes +--- +
+

现在您已经在桌面上运行 Gaia, 并且对源代码的工作方式有了一定程度的理解,下一步就应该准备好为项目做贡献了。本文则描述了如何修改代码以及如何在代码中找到 bug 出现的位置。 

+
+

Git 最佳实践

+
    +
  1. 当对 Gaia 修改时, 首先需要从 master 上获取最新的代码: +
    cd path/to/gaia
    +git checkout master
    +git pull 
    +
  2. +
  3. 下面切换到您解决问题的分支: +
    git checkout -b my-code-fix
    +
  4. +
  5. 最后,到 gaia/apps 目录下,可以修改对应的文件了。
  6. +
+
+

注意: 在 gaia/profile-debug/ 目录下,您会找到  webapps/, 但其中只包含需要运行的 app 的manifest 文件,而 app 是存在于  gaia/apps/ 目录下的。

+
+

简单的代码修改示例

+

您可以按照需求对代码作出修改,保存修改,在 Firefox 桌面中运行 Gaia 并刷新 tab 页以查看效果。  Let's do something simple like change the text colour of the clock on the lock screen:

+

Gaia lockscreen showing the clock display in white text

+
    +
  1. The best way to find how this style is set is to use the developer tools. Ctrl/right + click on the clock in Firefox Desktop and select Inspect Element from the context menu.
  2. +
  3. You can then work out which CSS file to edit — gaia/apps/system/style/lockscreen.css in this case — and then make your changes in the CSS styles on the right hand side of the display to get it to the state you want.
  4. +
  5. When you are happy with the change, go and make the change in the file directly.
  6. +
  7. Next, refresh the tab (or use the Reload application button) and the HTTP server serves the changes instantly:
  8. +
+

Gaia lockscreen showing the clock display modified from white to red text
+
+
+ Limitations of Gaia Desktop Firefox rendering:

+ +

发现 bug 出现的地方

+

The best way to find Firefox OS bugs to work on is to consult Josh Matthews' Bugs Ahoy app — this pulls in bugs directly from Mozilla's Bugzilla and displays them in an easy to search and browse way. One you have found a bug that you want to work on, go to its Bugzilla page, enter yourself in the "assigned to" field, and start work, as indicated above.

+

有用的提示

+ +

https://bugzilla.mozilla.org/buglist.cgi?columnlist=product%2Ccf_blocking_b2g%2Cbug_status%2Cresolution%2Cshort_desc&resolution=---&query_based_on=CLOCK&query_format=advanced&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&component=Gaia%3A%3AClock&product=Boot2Gecko&known_name=CLOCK&list_id=9776392

+

参考

+ diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/running_the_gaia_codebase/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/running_the_gaia_codebase/index.html new file mode 100644 index 0000000000..30fc71b5f9 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/running_the_gaia_codebase/index.html @@ -0,0 +1,81 @@ +--- +title: 运行 Gaia 代码 +slug: Archive/B2G_OS/Developing_Gaia/Running_the_Gaia_codebase +translation_of: Archive/B2G_OS/Developing_Gaia/Running_the_Gaia_codebase +--- +
+

本文对如何在本地运行 Gaia 代码以及在设置过程中的有效工具进行了深入讲解。

+
+ +

首先,我们应该指出,在操作Gaia 时,您并不需要编译 Gecko 或 B2G。您只需要将 Gaia 源代码下载到本地,以一定的方式运行和编辑它。

+ +


+ 共有下面几种方式来运行 Gaia:

+ + + +

你能在我们的 用多种方法运行Gaia 页面找到关于以多种方法运行Gaia的简略信息以及到更详细信息的链接。一般来说,这些信息是由从复杂问题(最常需要的信息)到简单问题(最少需要的信息)排序的。

+ +

在这篇文章里,我们会使用Firefox Mulet或WebIDE来运行Gaia -- 对于大部分你想对于Gaia代码库进行的更改,它们提供了最快捷的调试你的更新的方式。但显然,为了使用一些功能(如调试设备API或者与手机硬件进行交互等),你需要一个真正的设备。

+ +
+

注意: 如需得到更深入的帮助, 最好的地方就是 #gaia IRC 频道 (参见 Mozilla IRC 以获取更多信息) 以及 Gaia开发邮件单

+
+ +

运行 Gaia 

+ +
    +
  1. 首先,fork我们在Github上的主项目存档库 Gaia.
  2. +
  3. 然后,在本地clone它: +
    git clone https://github.com/your-username/gaia.git
    +
  4. +
  5. 之后,再加入一个像这样的upstream: +
    cd gaia
    +git remote add upstream https://github.com/mozilla-b2g/gaia
    +
  6. +
  7. 最后, 在你的系统上安装 Fira Sans 字体:这是在真实设备上Gaia使用的字体, 所以在桌面上运行 Gaia 时也使用它是十分有用的,尤其是当你测试有关重叠或字体大小的功能时。
  8. +
  9. +

    现在你需要为Gaia创建一个调试档案。 在你的Gaia存档库文件夹内运行DEBUG=1 make指令就会在profile-debug目录下创建一个档案(profile),这个档案是为了做到最优调试而创建的。它会创建未压缩(即主机调试版本)的Gaia应用,可以通过Firefox桌面版内置的扩展HTTPD服务器直接进行调试。当你对你的应用做了一个改变时,你只需要刷新你的浏览器窗口就可以看到结果,而不用再进行重新编译文件、重新推送到设备等等繁杂的过程。这对于快速的CSS/JS/HTMl修改尤其有用。

    +
  10. +
  11. With your debug profile built, run it in your desktop Firefox build (we'd recommend you use Firefox Nightly) from the command line, using a command with the following structure: +
    /path/to/firefoxnightly -profile /path/to/B2G/gaia/profile-debug -no-remote
    + For example, on Mac OS X, we ran the following command: + +
    /Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /Users/bob/git/gaia/profile-debug -no-remote
    +
  12. +
+ +

This should load up your Gaia profile running in a desktop Firefox tab, like so (you'll notice that the URL is http://system.gaiamobile.org:8080/):

+ +

A screenshot of Firefox OS Gaia being run inside a desktop Firefox nightly build.

+ +
+

Note: If you open a tab in the Firefox desktop window Gaia is running in, enter about:config, and search for "gaia", you'll find a number of extensions.gaia.* prefs — which the httpd.js extension is using. You'll also be able to find the network.dns.localDomains pref, which is the trick that makes http://system.gaiamobile.org:8080 connect on your localhost.

+
+ +
+

Note: The make command is run inside the Gaia directory to create a profile (including apps, setting, etc.) that can be loaded on a phone, run inside an emulator, etc. The make command has a number of options to create different kinds of build. Just running make creates a standard production profile inside gaia/make, with packaged apps, which is not set up for optimum modification and debugging.

+
+ +

有效的工具

+ +

You'll see that this view has a number of different tools available, including:

+ + diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/testing_gaia_code_changes/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/testing_gaia_code_changes/index.html new file mode 100644 index 0000000000..3f2aa1a408 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/testing_gaia_code_changes/index.html @@ -0,0 +1,119 @@ +--- +title: 测试 Gaia 代码修改 +slug: Archive/B2G_OS/Developing_Gaia/Testing_Gaia_code_changes +tags: + - B2G + - Firefox OS + - Gaia + - UI + - 'l10n:priority' + - 指南 + - 测试 + - 贡献 + - 集成 +translation_of: Archive/B2G_OS/Developing_Gaia/Testing_Gaia_code_changes +--- +
+

当您完成对 Gaia 代码库的修改并且结果看起来正常时, 下面的步骤就是通过测试程序的验证,从而确保在将 patch 提交到工程之前,您的修改可以真正的工作— 也就是对其他的 Gaia 代码也是有效的。本文所讲的就是这些内容。

+
+

测试步骤一般包括:

+ +

下面让我们来对这两部分进行分析:

+

标准调试

+

如果您是一位有经验的 web 开发者,那么对调试 Gaia 代码的步骤也不会陌生。 我们已经讨论了如何在桌面 Firefox 中运行Gaia,以及如何做 基本的修改。要获取更复杂的代码库添加的知识,则需要在桌面 Firefox 中对 Firefox 调试工具多多使用才好。

+
+

注意: 要获取更多使用工具方面的指令,请参考我们的 Tools zone.

+
+

自动化测试

+

在提交 patch 前,您同样应该在 Gaia 中运行标准测试套件,以保证您的代码更改不会对现有的手机功能造成影响。需要运行的测试包括:

+ +

在提交 patch 前,我们一般会要求运行测试;如果这是您第一次为 gaia 做贡献,可以在提交前不经过测试的环节,但后续则必须要进行测试。在运行测试前,为保证您的代码是最新的,需要更新 Gaia 仓库。 

+
+

注意: 要获取更多有关测试的内容,请参考 Firefox OS 自动化测试页面

+
+
+

注意: 如果可能的话,您需要考虑下运行在真实设备上运行每一项测试 (一些功能/硬件在仿真器上并不支持),否则就在 B2G 桌面仿真器或 Firefox Nightly 中运行。

+
+

单元测试

+

单元测试是指在大型应用中测试对每个独立的代码单元进行测试 — 对 Gaia 而言,就是指单独的 app。Gaia 使用:

+ +

您可以运行下面的命令来下载,安装和作为一个单元测试服务器(运行该命令需要一些时间,不妨先喝杯茶休息一下):

+
make test-agent-server
+

下面,打开一个新的终端窗口,在 Nightly 中将  test-agent app 装载进去

+
    +
  1. 运行下面命令:
    +
    make DEBUG=1
    +/Applications/FirefoxNightly.app/Contents/MacOS/firefox -profile /Users/bob/git/gaia/profile-debug -no-remote
    +
  2. +
  3. 点击 homescreen 上的 Test Aagent app
  4. +
+

使用下面命令来运行所有测试

+
make test-agent-test
+
+

注意: 由于要运行很多测试,可能要花费一个小时或更多的时间,因此您可能只想要对您所修改的 app 进行测试。此时,就可以将 APP=<app folder name>  添加在命令后面来实现,如  APP=settings.

+
+
+

注意: 您也可以阅读 Gaia Unit Tests 获取更多单元测试的信息。

+
+

集成测试

+

Integration testing involves testing different units of code together in a group to see how well they work together, and is the logical next step after unit testing. Gaia Integration tests are driven by a marionette script written in JavaScript and a python-based server. It can communicate with Gecko so it’s possible to control both the browser and Firefox OS device, and get them interacting with each other.

+

You can run the following command to trigger the integration tests:

+
make test-integration
+
+

Note: As with the unit tests, running the whole integration test suite can be very time consuming, so you can append APP=<app folder name> onto the above command to test a single app, for example APP=calendar.

+
+

性能测试

+

Gaia 性能测试会触发 B2G 桌面,多次启动 apps, 并且计算平均 app 装载时间。在运行测试后,性能框架会也会收集 app 和 系统进程(b2g) 的内存使用情况。

+

要运行这个测试,需要安装上 B2G Desktop, 并运行下面命令

+
make test-perf
+
+

注意: 当涉及到其他的测试类型时,你可以在上面命令后添加 APP=<app folder name> 来测试单个 app, 例如 APP=settings.

+
+

整体的平均值会在 mozPerfDurationsAverage 中表示:

+
"mozPerfDurationsAverage": 225.5
+

这是以毫秒为单位的平均 app 装载时间。为了优化用户体验,你应该将目标设为 1 s 一下。 性能测试同样会返回一些详细的内存使用值:

+
{
+  "app": {
+    "name": "Settings",
+    "uss": 16.6,
+    "pss": 19.5,
+    "rss": 32.9,
+    "vsize": 73.3
+  },
+  "system": {
+    "name": "b2g",
+    "uss": 50.1,
+    "pss": 53.2,
+    "rss": 67,
+    "vsize": 148.1
+  }
+},
+

test-pref 的整体原则是 ”数值越低越好“, 上面的这些值分别表示:

+ +

Generally vsize >= rss >= pss >= uss . vsize and rss don’t accurately reflect a process’s usage of pages shared with other processes. So the two numbers you want to watch are the pss and uss.
+
+ uss 是指进程所独自完整占用的内存。如果应用程序当前终止的话,这些内存都可以被释放掉。这是用来评价的关键指标。
+
+ pss 是进程共享库按比例所分享的大小。如果进程终止,这些内存也不能释放。
+  

+
+

注意: 要获取更多性能测试的信息,请参考 Gaia performance tests.

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/developing_gaia/understanding_the_gaia_codebase/index.html b/files/zh-cn/archive/b2g_os/developing_gaia/understanding_the_gaia_codebase/index.html new file mode 100644 index 0000000000..8a0695b970 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/developing_gaia/understanding_the_gaia_codebase/index.html @@ -0,0 +1,105 @@ +--- +title: 理解 Gaia 代码库 +slug: Archive/B2G_OS/Developing_Gaia/Understanding_the_Gaia_codebase +tags: + - B2G + - Code + - Firefox OS + - Gaia + - Guide + - JavaScript + - contribution +translation_of: Archive/B2G_OS/Developing_Gaia/Understanding_the_Gaia_codebase +--- +
+

在对 Gaia codebase作出您自己的修改之前,您需要理解下Gaia 的基本构成以及使用的编码规则。本文则涵盖了这些这些方面。

+
+

Gaia 代码库结构

+

下面的部分则概述了 Gaia 代码库最重要的部分。

+

apps/

+

此目录包括所有的主 Gaia apps, 在 homescreen 中显示的 app(如 calendar 和 camera)和底层 app(如 system, homescreen 和 keyboard ) 。
+
+ app 工作方式略有不同,但有许多公共的特点,包括:

+ +
+

注意: 在 Gaia 应用指南 一文中可获得更多关于 app 工作的内容。

+
+

build/

+

包含编译脚本。

+

dev_apps/

+

文件夹中包含自定义的一些应用。例如,您可以包含一些自定义的 app。

+
+

注意: 要获取更多关于 Gaia 自定义项的知识,请参考  Market customizations guide.

+
+

keyboard/

+

 keyboard 文件夹包含了 keyboard 词典以及不同语言的布局。

+

locales/

+

包含一个 JSON 文件,languages_all.json,  该文件定义了 Gaia 所支持的语言。要更深入的了解 apps 是如何本地化的,请参考  Getting started with app localization.

+

shared/

+

此目录包含了多个应用使用的大量的资源文件;其中最重要的部分为:

+ +

tools/

+

tools 目录包含编译脚本和测试的工具。

+

Gaia 编码风格

+

Gaia 遵循 Google JavaScript coding style.

+

背景知识:

+ +

具体规则

+
    +
  1. 确保 HTML 文件都带有 <!DOCTYPE html>  声明(也就是 HTML5 文档)。如果您不这么做, Internet Explorer 9 以及后续的版本会以兼容模式来装载它们。
  2. +
  3. 包含 "use strict"; 这个语句(就像刚才写的一样,包含双引号)放在 Js 文件头部,会使 js 进入 strict 模式。
  4. +
  5. 使用两个空格来缩进,而不是使用 tabs。
  6. +
  7. 请使用换行符来分隔代码逻辑!
  8. +
  9. 多单词的文件名称应该使用下划线字符来分隔单词,如like_this.js
  10. +
  11. 使用单引号而不是双引号来表示字符串。
  12. +
  13. 使用扩展的条件结构: +
    Bad
    +if (expression) doSomething();
    +
    +Correct
    +if (expression) {
    +  doSomething();
    +}
    +
  14. +
  15. 如果您修改 System app,请阅读  guidance listed here.
  16. +
+

每笔提交编码风格检查

+

在每个 commit 之前,通过调用  git pre-commit hook, Gaia 会使用  jshint 工具会自动对JS 编码风格进行检查。一旦您提交了对 Gaia 仓库的 Pull Request,  Travis (Github Continuous Integration) 服务器会运行这个工具来重复检查样式是否正确。

+

 precommit hook 脚本在gaia/tools/pre-commit 下,一旦  make 命令执行就会复制到 .git/hooks 文件夹 下。

+
+

注意: 我们以前会使用  gjslint 来检查编码风格,但已将其弃用;而是使用 jshint 来产生更严格和更好的效果。从 Firefox OS 1.4 开始就一直使用 JSHint,  gjslint 只被用来检查一些还没有使用 JSHint 的旧文件。

+
+

通过 Gaia 来手动运行 linting 检查

+

在提交 path 前我们推荐您在 patch 上手动运行 JSHint 来检查是否有任何样式上的错误。
+
+ 您应该在 gaia/build/jshint 目录下获取更多关于 Gaia 中 jshint 的细节;Gaia 为您提供了一个构建脚本,您可运行:

+
$ make lint
+

来自动进行 gjshint 和 jshint 样式的检查。 或者您运行

+
$ make hint
+

只运行 jshint 样式检查。

+
+

注意: 如果您想要在不是用 Gaia 的情况下,自己安装 Jshint,可运行如下命令:

+
npm install jshint -g
+jshint myfile.js
+
+
+

 

diff --git a/files/zh-cn/archive/b2g_os/events/disabled/index.html b/files/zh-cn/archive/b2g_os/events/disabled/index.html new file mode 100644 index 0000000000..0a6370bcfb --- /dev/null +++ b/files/zh-cn/archive/b2g_os/events/disabled/index.html @@ -0,0 +1,43 @@ +--- +title: disabled +slug: Archive/B2G_OS/Events/disabled +translation_of: Archive/B2G_OS/Events/disabled +--- +

禁用时,无线网络连接的设备上禁用事件引发的。

+ +

基本信息

+ +
+
规范
+
Wifi(特定于Firefox OS)WifiDirect(特定于Firefox OS)
+
接口
+
事件
+
泡泡
+
没有
+
可取消
+
没有
+
目标
+
WifiManager和MozWifiP2pManager
+
默认动作
+
没有
+
+ +

物产

+ +

未知

+ +

+ +
navigator.mozWifiManager.ondisabled = function(){
+  console.log("Wifi已被禁用");
+};
+
+ +

相关活动

+ + diff --git a/files/zh-cn/archive/b2g_os/events/index.html b/files/zh-cn/archive/b2g_os/events/index.html new file mode 100644 index 0000000000..6805ee5749 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/events/index.html @@ -0,0 +1,14 @@ +--- +title: B2G OS events +slug: Archive/B2G_OS/Events +tags: + - Archive + - B2G + - NeedsTranslation + - TopicStub + - events +translation_of: Archive/B2G_OS/Events +--- +

Archived event pages related to B2G OS.

+ +
connected
The connected event callback is executed when a call has been connected.
connectioninfoupdate
The connectionInfoUpdate handler is executed when information about the signal strength and the link speed have been updated.
contactchange
The contactchange event is fired each time a contact is added, updated or removed from the device's contact database.
disabled
The disabled event is raised when WiFi is disabled on the device.
enabled
The enabled handler is executed when Wifi is enabled on the device.
localized
The localized event is triggered after the webL10n library has finished localizing the document and detecting language.
message
The message handler is executed when data is received from a child (i)frame or parent window.
diff --git a/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/index.html b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/index.html new file mode 100644 index 0000000000..e872f21b11 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/index.html @@ -0,0 +1,534 @@ +--- +title: Firefox OS 1.x building blocks +slug: Archive/B2G_OS/Firefox_OS_apps/Building_blocks/1.x +tags: + - Apps + - B2G + - Firefox OS + - Firefox OS UX + - NeedsTranslation + - TopicStub + - UX +translation_of: Archive/B2G_OS/Firefox_OS_apps/Building_blocks/1.x +--- +
+

Important: The descriptions on this page and its subpages are old descriptions written around the first few versions of Firefox OS (1.0.1–1.3), so are out of date. You'll only find these useful if you are writing an app specifically aimed at an old version of Firefox OS, or fixing a bug on an old branch of Gaia. If you want to find more up to date building block information, go to our main Firefox OS building blocks landing page.

+
+ +
+

This page provides links to the Firefox OS 1.x building blocks.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Action menu

+
+


+  Details
+ Coding guide

+
+

An action menu presents a list of actions, related to the app's content, from which the user may make a selection. See the Coding guide for details on how to implement an action menu in your app.

+ +

 

+ +

Characteristics

+ +
    +
  • Opened from buttons within app content; these buttons are often inside toolbars (for example, the Browser app's "Share" button).
  • +
  • Action menus contain one or more items.
  • +
  • These menus expand in height to accomodate their items, to a maximum of the screen's height. Once that maximum height is reached, the content becomes scrollable vertically. Generally, the best practice is to try to include no more than five items plus a menu title.
  • +
  • The title string is optional.
  • +
  • The menu is closed by one of: +
      +
    • Selecting one of the actions.
    • +
    • Tapping the "Cancel" button.
    • +
    +
  • +
+ +

 

+
+

Button

+
+

+ +

Details
+ Coding guide

+
+

Performs an action when tapped by the user. These are highly flexible user interface objects that have a wide variety of styles. See the Coding guide for information on how to implement buttons that look like those described here.

+ +

 

+ +

Characteristics

+ +
    +
  • Buttons have two components: a visual target and a hit target. The hit target is always larger, in order to reduce targeting errors by making the button easier to tap.
  • +
  • Buttons have two states: normal and pressed.
  • +
  • Buttons can also be disabled, which means they can't be activated by the user, and are displayed dimmed to indicate that they're disabled.
  • +
+ +

There are several types of buttons:

+ +
+
Action buttons
+
Used when there are only a few actions and a list isn't needed. The main action button uses a special highlight color to indicate that it's the primary option.
+
List buttons
+
Used when displaying a list of actions, or to trigger the display of a value selector.
+
Input field buttons
+
Used to perform actions with input fields.
+
Special/custom buttons
+
These are used to provide specific actions including recording, dialing, and the like.
+
+ +

 

+
+

Confirmation

+
+

+ +

Details
+ Coding guide
+  

+
+

A confirmation prompt asks the user to take or confirm an action, such as responding to a system event such as asking the user to restart the device after swapping SIM cards, or to ask the user to grant or deny permission to perform a task. See the Coding guide for information about how to implement these prompts in your app.

+ +

 

+ +

Characteristics

+ +
    +
  • Confirmation prompts are modal; they occupy the entire screen, and require user input to close them.
  • +
  • Confirmation prompts consist of: +
      +
    • Title (optional)
    • +
    • Body
    • +
    • Icon (optional)
    • +
    • A Confirmation input button, whose label can be customized
    • +
    • An optional Cancel input button, whose label can be customized
    • +
    +
  • +
+ +

 

+
+

Filter

+
+

+ +

Details

+
+

Filters can be used for two purposes: data filtering, in which the user can view a single set of data in different ways (for example, the Calendar app uses filters to select the time scale to use when viewing data (that is, by day, week, or month); and secondary navigation (presenting a second set of tabs when tabs are already present in your user interface).

+ +

 

+ +

Characteristics

+ +
    +
  • Filters are presented as a horizontal sequence of buttons.
  • +
  • Only one button is focused at a time.
  • +
  • The best practice is to place filters within toolbars, so that they don't flow with content.
  • +
  • Left, middle, and right buttons can be styled uniquely. This lets you make, for example, the left and right ends of your bar take on a "sheen," or to make the bar rounded on the ends.
  • +
  • Filter buttons' widths vary depending on the number of filters in a single set.
  • +
  • You must have at least two and no more than five filters in a set.
  • +
  • A given set of filters may be labeled with either text or icons, but not both. Because filters' heights are relatively small compared to tabs, text is typically the best practice.
  • +
+ +

 

+
+ +
+

+ +

Details
+ Coding guide

+
+

A header labels the active view. In addition, it can contain top-level navigation and inputs for the active view. See the Coding guide for information on implementing headers in your apps.

+ +

 

+ +

Characteristics

+ +
    +
  • A header is a horizontal bar the full width of the screen, which appears at the top of the screen in most apps.
  • +
  • Headers float above content, with the option of flowing with content in special instances, such as in the Browser app.
  • +
  • The heading's text provides the name of the current view.
  • +
  • The heading may optionally include additional text; for example, in an email app, the number of unread messages may be displayed.
  • +
  • Headers may include inputs for navigating and manipulating the current view.
  • +
  • Most apps (full-screen games being an obvious exception) have a header.
  • +
+ +

 

+
+

Input area

+
+

+ +

Details

+
+

An input area is a data entry field. There are many variations on what an input area can look like; they can be as simple as a text entry field, and as complex as a multi-part entry field with text entry, value selectors, and buttons.

+ +

Details coming soon.

+
+

List

+
+

+ +

Details

+
+

Lists are used to display a set of consecutive items, such as a list of contacts or a list of messages.

+ +

 

+ +

Characteristics

+ +
    +
  • List items may vary in height (from one to three rows in a single item).
  • +
  • List items may be as simple as just a text string, to including images, text, and buttons.
  • +
  • Lists are comprised of rows, with optional section headers.
  • +
+ +

There are several types of list rows:

+ +
+
Action row
+
An action row is one in which a tap anywhere in the row triggers the row.
+
Status indicator row
+
Need details.
+
Button row
+
Need details.
+
Link row
+
Need details.
+
+ +

 

+
+

Object menu

+
+

+ +

Details

+
+

 

+ +

An object menu is a menu that lets the user directly manipulate objects without having to open them and navigate deeper into a view hierarchy.

+ +
    +
  • Deleting a photo by selecting its thumbnail, instead of by opening the full image first.
  • +
  • Flagging an email by selecting its preview instead of by first opening the email.
  • +
  • Calling a contact by selecting their name, instead of by opening their detailed contact information then pressing a "Call" button.
  • +
+ +

Object menus are currently implemented as a special case of action menu; this will evolve over time. For now, see the action menu coding guide for information on how to implement an object menu.

+ +

 

+ +

Characteristics

+ +
    +
  • Object menus are accessed using a "press-and-hold" gesture on a selectable object, such as a list row, phone number, URL, or the like.
  • +
  • An object menu contains one or more items.
  • +
  • Object menus expand in height to accomodate their contents, to a maximum of the height of the screen; at that point, the contents of the menu scroll. As a rule of thumb, you should try to avoid having more than five items in the menu.
  • +
  • Unlike action menus, object menus do not have titles.
  • +
  • You implement object menus using the same code and style as for action menus.
  • +
+ +

 

+ +

 

+
+

Progress and activity indicator

+
+

+ +

Details

+
+

Progress and activity indicators are used to provide visual feedback that a process is active.

+ +

 

+ +

Characteristics

+ +
    +
  • May include an animated visual element, a text label, or both.
  • +
  • Progress and activity indicators may be used in modal windows, or inline either with content or adjacent to content.
  • +
  • An activity indicator is used to show that an activity is ongoing without indicating how long the task is expected to take; these can be "barberpole" style indicators, or spinners.
  • +
  • A progress indicator is used to show how much out of 100% of an activity has been completed.
  • +
+ +

 

+
+

Scrolling

+
+

+ +

Details

+
+

Scrolling areas are used to let the user move text and/or images across the device's display.

+ +

 

+ +

Characteristics

+ +

There are two types of scrolling areas: scrollbars and index scrolling.

+ +

 

+
+

Seek bar

+
+

+ +

Details

+
+

Seek bars have a draggable thumb the user can touch and drag back and forth to scroll through content (such as to set playback position in a media file) or to set a new value for a given control, such as sound volume or display brightness.

+ +

 

+ +

Characteristics

+ +
    +
  • A seek bar consists of a track with a knob that indicates the current playback position.
  • +
  • The knob has both normal and "pressed" states.
  • +
  • The values for the ends of the seek bar can be specified as either text or images.
  • +
  • Seek bars may be oriented either horizontally or vertically.
  • +
+ +

 

+
+

Status

+
+


+ Details
+ Coding guide

+
+

Relays information to the user in a transitory fashion, typically to confirm a user action or to alert the user to a system event. See the Coding guide for details on how to implement a status bar. Sometimes status bars are referred to as "banners."

+ +

 

+ +

Characteristics

+ +
    +
  • Examples include deleting multiple photos in Gallery, or deleting or moving multiple emails.
  • +
  • Positioned at the bottom of the screen, covering underlying content.
  • +
  • Closing: Status bars automatically disappear, typically after a few seconds for short messages. This can be longer, though, depending on the message and context.
  • +
  • Can include an input, such as an "Undo" option; this is optional.
  • +
  • Can optionally include an image.
  • +
  • Can either be part of an app (such as a "Photos deleted" banner in the Gallery app) or in the System (such as a "Low battery" alert).
  • +
  • Avoid displaying more than one status bar at the same time. If two status bars appear at the same time, the newer status bar replaces the older one.
  • +
+ +

 

+
+

Switch

+
+

+ +

Details
+ Coding guide

+
+

A switch is any control which presents two mutually exclusive options or states. Switches are also used to select items within lists. See the Coding guide for details on implementing switches in your apps.

+ +

 

+ +

Characteristics

+ +
    +
  • A switch presents two mutually exclusive choices or states.
  • +
  • There are three types of switch: +
      +
    • On/Off toggle switches
    • +
    • Checkboxes
    • +
    • Radio buttons
    • +
    +
  • +
+ +

 

+
+

Tabs

+
+

+ +

Details
+ Coding guide

+
+

Tabs are used as a navigational widget that let the user switch among sets of views. This way, a window may contain multiple views. See the Coding guide for details on how to implement tabs in your apps.

+ +

 

+ +

Characteristics

+ +
    +
  • Tab bars always fill the full horizontal width of the screen.
  • +
  • You may have up to (but no more than) five tabs in a tab bar.
  • +
  • Tab bars should be positioned at the very bottom of the screen, unless doing so would result in excessive clutter due to multiple bars of controls at the bottom of the screen.
  • +
  • Tabs can contain a variety of elements, such as buttons, filters, indicators, and the like.
  • +
  • Tabs' labels may be text, text with an icon, or just an icon.
  • +
+ +

 

+
+

Toolbar

+
+

+ +

Details
+ Coding guide

+
+

Toolbars contain actions, indicators, and navigation elements associated with the current view. These may include things such as buttons to delete the currently selected items, a filter to enter edit mode, or a filter to show only "favorite" contacts. See the Coding guide for details on how to implement toolbars in your apps.

+ +

 

+ +

Characteristics

+ +
    +
  • Toolbars are always the full width of the screen, and are always the same height.
  • +
  • Toolbars never scroll with content; instead, they float above content.
  • +
  • Toolbars should always be positioned at the very bottom edge of the screen unless tabs are also present, in which case the toolbar is positioned at the top of the screen instead.
  • +
  • Toolbars may contain a wide variety of elements, including buttons, filters, progress/activity indicators, and so forth.
  • +
+ +

 

+
+

Value selector

+
+

+ +

Details
+ Coding Guide

+
+

Value selectors let the user choose one of a number of possible values, and are typically used from a form interface. For example, value selectors could be used to choose the month or day for a calendar event. These are presented automatically for the values of the <input> element's type attribute.

+ +

 

+ +

Characteristics

+ +
    +
  • Value selectors may have an optional title.
  • +
  • The following types of value selectors are provided: +
      +
    • Date
    • +
    • Time
    • +
    • SIngle-select list
    • +
    • Multiple-select list
    • +
    +
  • +
+ +

 

+
+ +

 

diff --git "a/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/\346\214\211\351\222\256/index.html" "b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/\346\214\211\351\222\256/index.html" new file mode 100644 index 0000000000..76a4f69227 --- /dev/null +++ "b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/1.x/\346\214\211\351\222\256/index.html" @@ -0,0 +1,256 @@ +--- +title: 按钮 +slug: Archive/B2G_OS/Firefox_OS_apps/Building_blocks/1.x/按钮 +translation_of: Archive/B2G_OS/Firefox_OS_apps/Building_blocks/1.x/Button +--- +

当用户点击时执行操作。这些是高度灵活的用户界面对象,具有多种样式。有关如何实现类似于此处描述的按钮的信息,请参见编码指南

+ +

特点

+ + + +

有几种类型的按钮:

+ +
+
动作按钮
+
仅在执行少量操作且不需要列表时使用。主操作按钮使用特殊的突出显示颜色来指示它是主要选项。
+
列表按钮
+
在显示操作列表或触发值选择器显示时使用。
+
输入栏按钮
+
用于对输入字段执行操作。
+
特殊/自定义按钮
+
这些用于提供特定的操作,包括记录、拨号等。
+
+ +

Visuals

+ +

Here are some visual examples of what buttons should look like. Don't forget that you can use the style sheet and image resources provided in the Coding guide to implement these.

+ +

Action buttons

+ +

Action buttons are used when there are only a few actions and you don't need a full list. The main action button uses a special highlight color to indicate that it's the primary action.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Primary actionSecondary actionDelete
Normal
Pressed
Disabled
+ +

On a dark background, disabled buttons have a special appearance, as seen below.

+ + + + + + + + + + + + + + + + +
Primary actionSecondary action
Disabled
+ +

List buttons

+ +

List buttons are used to display a list of actions, to trigger the display of a value selector.

+ +

Triggering actions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Trigger an action in the current viewTrigger an action in a new viewDisplay a value selector
Normal
Pressed
Disabled
+ +

Value selectors

+ +

Once a value selector has been opened, you will need at least one button on the value selector panel to dismiss the value selector. These buttons should look like the following:

+ + + + + + + + + + + + + + + + +
NormalPressedDisabled
+ +

Input field buttons

+ +

Input field buttons are buttons associated with an input field, which when pressed perform an action related to that input field.

+ + + + + + + + + + + + + + + + +
NormalPressedDisabled
+ +

Special buttons

+ +

The special buttons are visual icon-style buttons used for special purposes, such as operating the device's camera, answering and hanging up the phone, and activating the keypad dialer. You may of course find other uses for this style of button.

+ +

Camera buttons

+ +

These buttons don't have a disabled state; you simply don't display them if the ability to take photos isn't available.

+ + + + + + + + + + + + + + + + + + + + + + + + +
Record videoStop recording videoCapture photo
Normal
Pressed
+ +

Phone buttons

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Pick upHang upHide keypad
Normal
Pressed
Disabled
+ +

Custom buttons

+ +

These are examples of custom buttons; in this case, for adding a contact.

+ + + + + + + + + + + + + + + + +
Normal
Pressed
Disabled
+ +

See also

+ + diff --git a/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/index.html b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/index.html new file mode 100644 index 0000000000..0b20e0c329 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/firefox_os_apps/building_blocks/index.html @@ -0,0 +1,187 @@ +--- +title: Firefox OS Building Blocks +slug: Archive/B2G_OS/Firefox_OS_apps/Building_blocks +tags: + - Design + - Design patterns + - Firefox OS + - NeedsTranslation + - TopicStub + - UI + - building blocks +translation_of: Archive/B2G_OS/Firefox_OS_apps/Building_blocks +--- + + +
+

The Firefox OS Building Blocks are reusable UI components (also called 'common controls') that reflect OS-wide design patterns. Building Blocks are used to create the interfaces of all Gaia default apps. You are free to make use of these components in your own Firefox OS apps, or general Web apps.

+
+ +

Using the Firefox OS Building Blocks

+ +

The code for the Firefox OS Building Blocks can be found in the Gaia Github repo under shared/style. Here, you can find a CSS file that contains the CSS for that particular Building Block, and a sub directory containing the HTML fragments and image assets. If you are creating your own standalone Web app, you can simply copy the CSS, HTML and image asset files across into your own project; if your app is intended to be installed on Firefox OS only (or you want to use these features only when the app is being used on Firefox OS), then you can link to the versions available inside Gaia.

+ +

The pages for the individual Building Block implementations can be found under the pages for each building block — see next section. These contain instructions on how to implement each one.

+ +
+

Note: The version 2.0 building block code is used in Firefox OS releases 2.0 through 2.2. Version 2.3 sees an update, with the building blocks being reimplemented using Web components — these provide the same functionality, but implemented in a much more powerful, flexible way. You'll see 2.3 pages appear underneath the main building block pages covering these Web components as soon as the information is available.

+
+ +
+

Note: We also have an old guide covering the v1.x building blocks used in older versions of Firefox OS. This is mainly for legacy information.

+
+ +

Web components preliminary setup

+ +

This section details the preliminary setup needed to use Gaia Web components.

+ +

Web components browser support

+ +

To use Gaia Web components at all, you need to run them using a browser that supports Web components. The state of support is as follows:

+ + + +

Web components are supported in Firefox OS from v2.1 onwards, although most of them weren't actually implemented until v2.3. Be aware also that currently Web components won't work for Firefox OS apps below internal (certified) level. This restriction should be lessened in the future.

+ +
+

Note: If your app is certified, the components will just work. You don't need to set a specific manifest permission.

+
+ +

Web components installation notes

+ +

Gaia Web components are installed in your app using the Bower package manager. To install this, you first need Node.js/npm and Git installed. Once they are installed you can install Bower with

+ +
npm install -g bower
+ +

At this point you could also install the Gaia Fira Sans font that Firefox OS uses in your app , with the following command:

+ +
bower install gaia-components/gaia-fonts
+ +

You can then make use of the font by including the following in your head (along with a font-family of FiraSans):

+ +
<link rel="stylesheet" type="text/css" href="bower_components/gaia-fonts/style.css"></link>
+ +

Firefox OS Building Blocks

+ +
+
+
+
Action menu
+
An action menu presents a list of actions, related to the app's content, from which the user may make a selection.
+
Banners
+
Banners (Status, in older versions of Firefox OS) provide information to the user in a transitory fashion, typically to confirm an action or to alert the user to a system event.
+
Buttons
+
Buttons are used to perform explicit actions. Buttons may be text or images.
+
Context menu
+
Accessed via a tap and hold gesture (sometimes called a long press), the Context Menu (called the Object Menu in older versions of Firefox OS) allows users to perform actions on objects without having to leave their current view.
+
Dialog
+
A Dialog (Confirm, in older versions of Firefox OS) provides the user with some important information, asks the user to take or confirm an action, or allows the user to make a choice or enter some information.
+
Drawer
+
The drawer is a scalable way for users to navigate between views or filter views. The drawer can also include links to app settings or other tools.
+
Header
+
A header is a dedicated space at the top of the screen, most often used to display the view title. It can also include navigation, action buttons and other controls.
+
Input area
+
An input area is a data entry field, and can be as simple as a text only entry field, or as complex as a multipart entry field with text entry, value selections, and buttons.
+
Layout
+
The Layout utility will help you to create common layout structures for your Firefox OS apps. Note that Layout is only available in Firefox OS 2.1 and above.
+
List items
+
List items are typically used to navigate to a new screen, or to display information or controls.
+
+
+ +
+
+
Picker
+
The Picker is designed to select a group of items as attachments for messaging and email.
+
Progress and activity
+
Progress and activity indicators provide the user with visual feedback that a process (such as a resource loading) is active.
+
Scrolling
+
Scrolling areas allow the user to move text and/or images across the device's display.
+
Search
+
Search is used to filter a list or find context-specific content.
+
Slider
+
A Slider (which was called Seekbar in older Firefox OS versions) is used to select a value from a continuous or discrete range of values by dragging the handle.
+
Select mode
+
Select Mode (which was called Edit Mode in older Firefox OS versions) is designed to select and perform actions on items.
+
Subheader
+
Subheaders are used to describe a subsection of content.
+
Switches
+
Switches (such as checkboxes, etc.) allow users to activate and deactivate items. Switches are also used to select items within a list.
+
Tab/Filter
+
A Tab/Filter gives the user a way to easily switch between views or to filter a set of data.
+
Toolbars
+
Toolbars contain actions, indicators and navigation elements associated with the current view.
+
Value selector
+
Value Selectors let the user choose from among a list of possible values.
+
+
+
+ +
+

Note: For a detailed guide to the design pattern followed by the building blocks when the Arabic locale (bidirectional) is selected, read Firefox OS in Arabic.

+
+ +

Cross browser CSS

+ +

Arnau March wrote a CSS file called cross browser CSS, containing rules to allow Firefox 2.0 building blocks to render properly across different browsers (ie 9, Firefox 18, Chrome 24, Safari 5.1.) If you want to write hosted apps that look ok across different browsers, include this CSS in your project.

+ +

Browse Firefox OS Building Block implementations by version

+ +

The pages below list links to pages covering the Firefox OS Building Block implementations as they appear in different versions of Firefox OS.

+ + diff --git a/files/zh-cn/archive/b2g_os/firefox_os_apps/index.html b/files/zh-cn/archive/b2g_os/firefox_os_apps/index.html new file mode 100644 index 0000000000..370236dd14 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/firefox_os_apps/index.html @@ -0,0 +1,85 @@ +--- +title: Firefox OS apps +slug: Archive/B2G_OS/Firefox_OS_apps +tags: + - Apps + - Building + - Components + - Firefox OS + - Installing + - NeedsTranslation + - TopicStub + - device APIs +translation_of: Archive/B2G_OS/Firefox_OS_apps +--- +

This section of the Firefox OS docs covers the specific techniques required — and available tools — for building Firefox OS apps. You'll find a number of details below, from Firefox OS building blocks/web components, to device APIs and App installation.

+ +

Building Firefox OS apps

+ +
+
Building apps for Firefox OS
+
Firefox OS/Firefox platform app specifics, including App installation and management APIs, manifest files, packaged and hosted apps, handling API permissions.
+
Localization
+
This set of articles provides information for developers wishing to provide localized versions of their apps.
+
Performance
+
This page lists performance-related topics specific to Firefox OS.
+
Firefox Accounts on Firefox OS
+
This article provides an overview of using Firefox Accounts in Firefox OS.
+
Reference apps
+
This page lists a number of sample apps we've put together for you to download, install, play with and learn from. Have fun!
+
Screencast series: App Basics for Firefox OS
+
In this collection of short videos, developers from Mozilla and Telenor explain in a few steps how you can get started with building applications for Firefox OS.
+
+ +

Building blocks

+ +
+
Building Blocks
+
The Firefox OS Building Blocks are reusable UI components (also called 'common controls') that reflect OS-wide design patterns. Building Blocks are used to create the interfaces of all Gaia default apps. You are free to make use of these components in your own Firefox OS apps, or general Web apps.
+
+ +

Styleguides

+ +
+
Firefox OS Visual styleguide
+
Our style guide for Firefox OS visual design, covering colours, typeface, backgrounds, app icons, and the design of specific UI elements.
+
Firefox OS Copy styleguide
+
This guide outlines the rules we follow for writing Firefox OS app copy, but can be used as a general guide to writing good copy for any app interfaces.
+
Firefox OS in Arabic
+
A guide to the specific UX design implementation Firefox OS has in place for dealing with Arabic (and other RTL languages.)
+
+ +

Assets

+ +
+
Firefox OS design asset library
+
In this section you'll find design assets, artwork, graphic templates, fonts and other materials that will be helpful as you design Firefox OS/Gaia apps.
+
Firefox OS icon font
+
Firefox OS has its own icon font set available: this article explains how to use it in your own apps.
+
Firefox OS transitions
+
A reference to some of the transitions used in Firefox OS to move between different states in apps, including animated GIFs demonstrating the animations used, plus code samples to show the CSS animation code needed to implement these animations.
+
+ +

References

+ +
+
Firefox OS device APIs
+
This article provides a list of pages covering those APIs, as well as the app manifest permissions for each one.
+
Firefox OS app tools
+
This page provides a list of useful tools, libraries, examples, etc. that are useful for Firefox OS app developers, whether you want a code template to copy, or need help with adding a specific feature to your Firefox OS app.
+
+ +

Other app topics

+ +
+
Porting Chrome apps to Firefox OS Apps
+
This article discusses the differences between Chrome apps and Firefox OS Apps, and how you can convert between the two.
+
App development FAQ
+
This FAQ is a compilation of answers to common app development questions.
+
+ +

See also

+ + diff --git a/files/zh-cn/archive/b2g_os/firefox_os_build_prerequisites/index.html b/files/zh-cn/archive/b2g_os/firefox_os_build_prerequisites/index.html new file mode 100644 index 0000000000..8cca33fd04 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/firefox_os_build_prerequisites/index.html @@ -0,0 +1,267 @@ +--- +title: 编译Firefox OS的系统需求 +slug: Archive/B2G_OS/Firefox_OS_build_prerequisites +translation_of: Archive/B2G_OS/B2G_OS_build_prerequisites +--- +

在获取用于编译Firefox OS的代码之前,你需要设置好所需的编译环境。目前可在64位Linux或Mac OS X下编译Firefox OS。

+

注意:要构建firefox OS到手机上,开始时不要把你的手机连接到电脑上,当需要连接的时候我们会告诉你把手机插入到电脑上。

+

使用兼容的硬件或使用模拟器

+

尽管我们支持一些手机,其中一些还有多种变体产品,但我们当前支持一些特定的产品而且有些设备比其他的有更好的支持:

+

等级 1

+

等级1设备表示用于开发的主要设备,而且常常会是最先收到漏洞修复和功能更新。

+
+
+ Unagi
+
+ Unagi是被用来作为中低端智能手机测试和开发平台的一个手机,许多核心Firefox OS开发者都使用Unagi。
+
+ Otoro
+
+ Otoro是被用来作为中低端智能手机测试和开发平台的一个手机,许多核心Firefox OS开发者都使用Otoro。
+
+ 开发平台Pandaboard
+
+ Pandaboard是一个基于OMAP(开放式多媒体应用平台,Open Multimedia Application Platform)4架构的开发用电路板,用于移动平台上的开发工作。
+
+ 模拟器(ARM和x86)Emulator (ARM and x86)
+
+ 有两种可用的模拟器:一个模拟ARM代码(指令集),而另一个运行在x86代码(指令集)上。
+
+ 桌面
+
+ 你也可以构建Firefox OS的桌面版本;这种方式在XULRunner应用中运行Gecko,接着你就可以在其中使用Gaia用户界面了。
+
+

当然,你也可以构建桌面客户端或者使用模拟器

+

等级2

+

等级2设备为一般功能性设备,许多开发者(特别是应用开发者)都是用这样的设备,所以他们往往在之后选择更新。

+
+
+ Samsung Nexus S
+
+ 已知的Nexus S设备中可用的产品型号为GT-I9020A和GT-I9023,其他型号也许可以用。
+
+ Samsung Nexus S 4G
+
+ SPH-D720作为等级2设备支持。
+
+

等级3

+

Firefox OS可以在这些设备上构建,但是他们并不是核心开发者积极工作的基础设备。他们的可靠性和功能设置可能会明显的落后于等级1设备甚至于等级2设备。

+
+
+ Samsung Galaxy S2
+
+ 唯一可用的产品型号是i9100;没有其他的同类型变体具有官方兼容性。(i9100P可能可用,因为它唯一的改变是增加了一个NFC芯片)
+
+ Samsung Galaxy Nexus
+
+ 现在所知的没有任何变体产品可以兼容。
+
+
+ 重点: 仅支持至少运行Android 4(又称Ice Cream Sandwich)的设备,如果你的设备在上面列出来了,但是运行的是低版本的安卓系统,请先升级在进行操作。
+

Linux系统需求

+

在Linux系统下构建Firefox OS,要求如下:

+

To build on Linux, you'll need to have a system configured with:

+ +

This is more than the bare minimum, but sometimes building fails just because it's missing resources.【这已经超过最低限度,但是有时构建失败只是因为缺少资源】

+

It's possible to use other distributions, but we recommend Ubuntu 12.04 since it's the most common system people use successfully. Distributions that might not work: 32 bit distros and recent distros ( Ubuntu 12.10, Fedora 17/18, Arch Linux because of gcc 4.7).【可以使用其他发行版本,但是我们建议使用Ubuntu 12.04,因为他是人们成功使用最常用的。可能无法正常工作的发行版有:32位和最近发型版本(Ubuntu 12.10,Fedora 17/18,因为linux分支gcc 4.7-可能版本过高吧)】

+

You will also need the following tools installed:

+

【你还需要安装一下工具:】

+ +

64 bit install examples:

+

Ubuntu 12.04 / Linux Mint 13 / Debian 6

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

When building on 64-bit Ubuntu, you may find that you need to add symlinks for the 32-bit versions of libX11.so and libGL.so:

+
$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
+$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
+

Ubuntu 12.10

+
$ 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 steps above needed to fix issues with the 32-bit versions of the libX11.so and libGL.so libraries, you will need to specify GCC 4.6 as the default host compiler before building. After having retrieved the sources, see here how to do it.

+

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

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

Fedora 16:

+
$ 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
+

Fedora 17/18:

+
$ 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
+

In addition to the above you will need GCC 4.4 in order to compile the project. You can find a pre-compiled version here. Download it and install it to /opt with the following command:

+
$ wget http://people.mozilla.org/~gsvelto/gcc-4.4.7-bin.tar.xz
+$ sudo tar -x -a -C /opt -f gcc-4.4.7-bin.tar.xz
+
+

You will need to specify this compiler as the default host compiler before building. After having retrieved the sources, see here how to do it.

+

 

+

Arch Linux (not functional yet):

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

By default, Arch Linux uses Python3. You'll have to force it to use the old python2:

+
$ cd /usr/bin
+
+$ sudo ln -fs python2 python
+

Mac OS X系统需求

+

To build Firefox OS on Mac OS X, you need to install Xcode's Command Line Utilities.

+

You can download just the Command Line Utilities from Apple's developer downloads page for your particular version of OS X.

+

However, if you would like the entire Xcode suite of applications, you can install Xcode through the Mac App Store. 

+

Install Command Line Utilities via XCode 4.3.1 and newer

+

Xcode 4.3.1 (OS X 10.7 "Lion") and other newer versions such as 4.4.1+ (that is, Mac OS X10.8 "Mountain Lion"), won't necessarily include the required Command Line Utilities. When you install Xcode, make sure to go into Preferences, then the Downloads panel, and install the Command Line Utilities. In addition, make sure you have at least 20 GB of free disk space.

+

Screenshot of Xcode Downloads Command Line Tools

+
+ Note: The Firefox OS emulator requires a Core 2 Duo processor or later; that is, a system that is compatible with Mac OS X 10.7 "Lion." You do not actually have to be running Lion, you just have to be compatible with it. You can, however, build any Firefox OS build on many older Macs.
+

Firefox OS Mac Bootstrap

+

Open a terminal and run the following command:

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

It 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. The script will check for and install the following items:

+ +
+

Xcode

+

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
+ Next to that be sure that you have the Mac OS X 10.6 SDK 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 the Xcode 4.3 DMG file which is available at the Apple Developer portal. You can use the utility Pacifist to extract the 10.6 SDK. Be sure to add a symlink to it to the /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ directory. (We can drop the 10.6 SDK requirement after bug 784227 has been fixed, and our version of platform_build has been updated.)

+

Mountain Lion

+
+

If you are building on OS X 10.8 "Mountain Lion" (Xcode 4.4.1 or later) and encounter the following error:

+
external/qemu/android/skin/trackball.c:130:25: error: 'M_PI' undeclared (first use in this function)
+ Edit the file: B2G/external/qemu/Makefile.android and add in line 78:
+
MY_CFLAGS += -DM_PI=3.14159265358979323846264338327950288   #/* B2G_fix: not finding M_PI constant */
+
+
+ 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
+
+

Samsung Galaxy S2

+

If you plan to build for the Samsung Galaxy S2, you will also need to install heimdall. See 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.
+
+ Note: Mac OS X uses a case insensitive filesystem by default, which will prevent you from building Firefox OS down the road (EDITOR'S NOTE: I have never had a problem with this).  You should create a case sensitive sparse disk image work from within that directory.  To buld the case sensitive disk image:
+
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/firefoxos.dmg
+

Mount the drive with:

+
open ~/firefoxos.dmg
+

Change into the mouted drive with:

+
cd /Volumes/untitled/
+

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.

+

安装adb

+

在构建B2G之前,需要从手机的安卓安装上拷贝下来二进制对象(当然,除非你要构建模拟器)。为此,你需要安装adb,安卓调试桥(Android Debug Bridge)。安装adb这篇文件中讲解了如何安装adb。

+
+

在你将来使用adb时请注意:为了调试你的手机,adb需要手机的锁屏处于解锁状态(至少在最新的Firefox OS中是这样的)。你最好禁用锁屏(我们在以后的构建指导中说明如何来做)。

+
+

安装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:

+ +
+

Note: Building the latest Heimdall from source currently produces errors. It is better to instead use the 64bit packaged version from the Ubuntu 14.04 repos. i.e. don't use heimdall-flash:i386 if you can avoid it.

+
+

配置 ccache

+

B2G构建过程使用ccache,ccache的默认缓存大小是1GB,但是B2G构建很容易就会占满这个缓存;建议把缓存调整到10G左右。你可以通过在终端中运行下面这个命令来配置你的缓存:

+
ccache --max-size 10GB
+

针对Linux:为你的手机配置udev 规则

+
+

注意: 这一节是针对Linux用户;OS X用户已经安装了必要的设备权限。

+
+

接下来,你需要为你的手机配置udev规则。

+

你可以通过运行lsusb来获得你插入的手机的 USB供应商编号(USB vendor ID) ,通常是Google 18d1, Samsung 04e8, ZTE 19d2, Geeksphone/Qualcomm 05c6。

+

在文件/etc/udev/rules.d/android.rules中加上这一行(使用你的设备供应商ID替换XXXX):

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

以中兴手机作为例子,android.rules的内容如下:

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

对于Firefox Flame,内容如下:

+
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev"
+

请注意fastboot设备(flash时使用)可能有一个不同的供应商ID(vendor ID),故你需要为它添加一条规则。例如Firefox Flame也需要谷歌的供应商ID

+
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
+
+

如果文件不存在则创建,通常,rules.d目录默认为只读,所以你可能要使用chmod来使目录、文件或两者可写。

+
+

一旦你保存了文件就关闭它,让文件可读:

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

由于udev规则更新了,重启udev守护进程。

+

Ubuntu

+
sudo service udev restart
+

Fedora 20

+
sudo systemctl restart systemd-udevd.service
+

ARCH

+
sudo udevadm control --reload-rules
+
+

注意: 这也许需要稍长的时间,取决于你的发行版本,类似于:
+
+ sudo vi /etc/udev/rules.d/android.rules
+ sudo service udev restart
+ sudo /etc/init.d/udev restart
+ sudo reload udev
+ sudo udevadm trigger

+
+

最后,拔掉USB接口但是不要重新插上,因为我们要先启动手机上的远程调试。

+

启动远程调试

+

在你把你的手机插回USB端口上之前,让其处于USB开发者模式,这允许你调试并更新(flash)你的手机,在你的手机上启动开发者设置 中的 远程调试(在老版本中称为开发者模式)来启动开发者模式。一旦勾选了这个选项,远程调试即启动,然后你就可以继续了。

+

现在,通过USB连接你的手机和电脑(如果你在之前创建了一个udev规则,这将会触发udev检测你的手机并创建相应权限的设备节点)。现在你可以检查你是否可以通过adb devices命令来列出你的设备(谨记adb只可以在你的手机处于解锁时看到它)。如果一切OK,你应该可以看到类似于下面的输出(下面这个是对于一个极客手机Keon来说):

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

如果设备没有列出来,检查文件名称和脚本是否正确(详见之前的小节),然后重启电脑并重新输入命令,还要注意你的设备是否使用fastboot,引导程序可能会识别为一个不同的供应商ID而不是你正常用设备引导看到的那个。

+

备份手机system分区

+
+

注意: 如果你没有已存在的系统备份,在构建系统之前你必须做这一步,因为在构建期间有许多库会被引用,这些库可能是专有的以至于我们不能在基础代码中提供他们。

+
+

建议你备份手机上的整个安卓系统分区。

+

你可以使用这份安卓二进制对象副本,以防后面你会删除你的B2G树,运行:

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

 你可能还需要拷贝出/data 和/或 /vendor目录,不过这取决于手机:

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

如果pull命令因“权限不足”而失败,尝试下面的步骤:

+ +

On to the next step

+

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

diff --git a/files/zh-cn/archive/b2g_os/firefox_os_faq/index.html b/files/zh-cn/archive/b2g_os/firefox_os_faq/index.html new file mode 100644 index 0000000000..079c31f3fa --- /dev/null +++ b/files/zh-cn/archive/b2g_os/firefox_os_faq/index.html @@ -0,0 +1,43 @@ +--- +title: Firefox OS FAQ +slug: Archive/B2G_OS/Firefox_OS_FAQ +tags: + - B2G + - FAQ + - Firefox OS +translation_of: Archive/B2G_OS/Introduction +--- +
+
+ 我如何能获取到一个开发者预览版的Firefox OS手机?
+
+ 它们即将在Geeksphone网站上首发。
+
+ 如果我不想买一个新的手机,我还能为Firefox OS手机开发一个App吗?
+
+ 当然可以!你可以在你的Android手机上测试你的App(配合Marketplace for Firefox)或者在电脑上使用Firefox OS模拟器.
+
+ 预览版和最终版的手机会有什么区别?
+
+ 关于该手机何时进入普通消费市场,我们正在和其他几个合作伙伴进行沟通.这些手机的硬件配置如何,我们到时候再讨论.
+
+ 我从哪里可以下载到Firefox OS?
+
+ https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Building_and_installing_Firefox_OS
+
+ 如何测试我的Firefox OS App?
+
+ 使用Android或Firefox OS模拟器.
+
+ 什么是Firefox OS?
+
+ 它是一个全新的手机操作系统,采用了完全开放的Web标准实现.即使是用HTML5开发的Web App,页能使用到设备的每个基础功能(比如打电话,发短信,浏览本地文件等),而其他手机操作系统下,只有原生App能实现这些需求.
+
+ 哪里有一个完整的Web API列表?准备把这些API进行标准化吗?
+
+ Firefox OS的最初版本将会实现大量的Web API.完成的列表可以在这里找到:https://wiki.mozilla.org/WebAPI#APIs.标准化工作也正在进行中.
+
+ 这些Web API标准化之后可以跨平台使用吗?
+
+ 是的,这些API是在我们和其他几个合作伙伴以及经销商的共同合作下产生的,其中一些API已经应用在了其他的平台上.如何能让Web App访问到最终用户的硬件,这几乎是所有的技术公司都在面临的问题,我们正是做了一个好的开始.
+
diff --git a/files/zh-cn/archive/b2g_os/index.html b/files/zh-cn/archive/b2g_os/index.html new file mode 100644 index 0000000000..850f1933e0 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/index.html @@ -0,0 +1,243 @@ +--- +title: B2G OS +slug: Archive/B2G_OS +tags: + - B2G + - Firefox OS + - Gaia + - NeedsTranslation + - TopicStub + - 火狐OS +translation_of: Archive/B2G_OS +--- +
+

Firefox OS 是由 Mozilla 打造的全新移动操作系统,基于 Linux 系统和驱动火狐浏览器的强大 Gecko 渲染引擎开发。

+
+ +
+

Firefox OS 是完全开源的,因而避免了专有技术。她能为应用开发人员提供有力的支持以创造优秀的产品。此外,这款灵活的操作系统能够创造优异的用户体验。

+ +

对 web 开发者而言,最重要的部分莫过于理解 Firefox OS 的整个用户界面就是一个 web 应用,而且这个 web 应用具有启动并展现其他 web 应用的能力。尽管提高了对移动设备硬件和服务的访问,但是您对用户界面的改动和您开发的任何在 Firefox OS 上运行的 web 应用使用的都是 HTML、CSS 和 JavaScript。

+ +

从产品的角度看,Firefox OS 是 Mozilla 公司(以及其 OEM 合作伙伴)的品牌,它基于 Boot to Gecko (B2G),Boot to Gecko 是 Firefox OS 操作系统的工程代号,它是由 Mozilla 内部的一组工程师团队和 Mozilla 开源社区的众多外部贡献人员共同开发的。

+
+ +
+

开发 Firefox OS 应用

+ +

访问我们的应用中心,获取开发 Firefox OS 应用所需要的各种信息!

+
+ +
+
+

平台指南

+ +

为平台开发者提供的指南,主要讲述了FIrefox OS 平台的不同组件是如何组合在一起并工作的。

+ + +
+ +
+

构建与安装

+ +

在模拟器,兼容设备或桌面模拟器上编译及安装 Firefox OS 的指南。

+ + +
+ +
+

开发者手机

+ +

针对开发者手机的相关信息,如微调、更新、恢复和购买。

+ + +
+
+ +
+
+

Firefox OS 书籍

+有若干涵盖 Firefox 开发各方面的书籍已经出版或正在编写中。要想详细了解,请访问 Firefox OS Books
+ + +
+ +
+

注:如果您想要为 Firefox OS 中文文档做贡献,请查看 Firefox OS 文档翻译进度

+
+ +

+ +
+

加入 Firefox OS 社区

+
+
请选择你喜欢的方式加入我们:
+ +
+
+ +
+
+

+ + + +
    +
  1. 介绍
  2. +
  3. 平台指南 +
      +
    1. 平台指南概述
    2. +
    3. 架构概述
    4. +
    5. 应用架构
    6. +
    7. Gonk
    8. +
    9. Gecko
    10. +
    11. Gaia
    12. +
    13. Gaia 应用指南
    14. +
    15. 安全 +
        +
      1. Firefox OS 安全模型
      2. +
      3. 系统安全
      4. +
      5. Firefox OS 中的应用程序安全
      6. +
      7. 安全地安装和更新应用程序
      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. 移植 Firefox OS
    12. +
    13. 用哪种方式运行 Gaia 和 Firefox OS
    14. +
    15. 使用 Firefox OS 桌面客户端
    16. +
    17. 使用 Firefox OS 模拟器
    18. +
    19. 安装 Firefox OS 到移动设备端
    20. +
    21. 创建和应用 Firefox OS 更新包
    22. +
    23. 运行时工具
    24. +
    +
  6. +
  7. Firefox OS 开发 +
      +
    1. Firefox OS 开发概述
    2. +
    3. 提交 Firefox OS 相关 bug
    4. +
    5. 修改 hosts 文件
    6. +
    7. 定制 .userconfig 文件
    8. +
    9. 定制 b2g.sh 脚本
    10. +
    +
  8. +
  9. Gaia 开发 +
      +
    1. Gaia 开发概述
    2. +
    3. 运行 Gaia 代码库
    4. +
    5. 理解 Gaia 代码库
    6. +
    7. 修改 Gaia 代码
    8. +
    9. 测试 Gaia 代码修改
    10. +
    11. 为 Gaia 提交 patch
    12. +
    13. Gaia 构建系统入门
    14. +
    15. 定制 build-time 应用
    16. +
    17. 市场定制指南 
    18. +
    19. 在 Firefox OS 应用中定制键盘
    20. +
    21. Firefox OS 本地化
    22. +
    23. Make 选项参考文档
    24. +
    25. Gaia 工具参考
    26. +
    +
  10. +
  11. Firefox OS 设备指南 +
      +
    1. 开发者手机指南概述
    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. TBPL
    28. +
    29. Jenkins
    30. +
    +
  16. +
  17. 调试 +
      +
    1. Firefox OS 调试概述
    2. +
    3. Firefox OS 开发相关设置
    4. +
    5. 连接 Firefox OS 设备到电脑
    6. +
    7. 使用 Firefox 开发者工具调试 Firefox OS
    8. +
    9. 如何在移动设备上打印日志
    10. +
    11. 安装和使用 ADB
    12. +
    13. 截屏
    14. +
    15. 使用 WebIDE
    16. +
    17. 使用 Firefox OS 应用管理器
    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-cn/archive/b2g_os/installing_on_a_mobile_device/index.html b/files/zh-cn/archive/b2g_os/installing_on_a_mobile_device/index.html new file mode 100644 index 0000000000..390c5e9e73 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/installing_on_a_mobile_device/index.html @@ -0,0 +1,111 @@ +--- +title: 在移动设备上安装 Firefox OS +slug: Archive/B2G_OS/Installing_on_a_mobile_device +tags: + - Ch +translation_of: Archive/B2G_OS/Installing_on_a_mobile_device +--- +

+ +

Once you've built Boot to Gecko for a supported mobile device, you can install it. This article will guide you through the process.

+ +
Note: The first time you flash your phone, it must have Android 4 (Ice Cream Sandwich) installed. The process will not work correctly otherwise. Once you've done your first install of B2G, however, you can simply update on top of it.
+ +

刷机

+ +

To flash everything to your phone, simply connect your phone and type:

+ +
./flash.sh
+
+ +

That's it. The B2G you've currently got built will flash onto your device.

+ +

Configuring the udev rule for your device

+ +

On Linux, if you get this,

+ +
< waiting for device >
+ +

that probably means that you haven't added a udev rule for the fastboot device, which is not the same as the one for adb. You can get the USB vendor ID by running lsusb now, but typically it's Google's: 18d1, so adding this line in your /etc/udev/rules.d/51-android.rules would work:

+ +
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
+ +
Note: If you get a very helpful libusb error "-3" on Linux, it means you need to be root to have the needed access to the USB device. Run the script again using sudo.
+ +
Note 2: If you have an Unagi or a Geeksphone Keon phone, you need two lines like this - one for the original phone vendor's ID, and one for Google's.
+ +

Special notes for Hamachi, Helix, and Leo devices

+ +

If your phone is a hamachi, helix or leo device, the ./flash.sh script will now default to flashing only gecko and gaia.  It is recommended that you flash with the OEM as a base build to get the firmware and the gonk layers and then flash the gecko and gaia on top.  If you want to flash using the images, there is an override flash where you can ./flash.sh -f and it will use the image files to flash your device.

+ +

Special notes for the Samsung Galaxy S2

+ +

If your phone is a Galaxy S2 and you are using heimdall 1.3.2 (the latest version; use heimdall version to check), you may see an alarming error "FACTORYFS upload failed!" followed by "Heimdall flashing failed" and some additional information. This is actually a success condition, and you can ignore the advice.

+ +

To get rid of this strange behavior, grab a source copy of heimdall, downgrading to the 1.3.1 release ("git checkout fbbed42c1e5719cc7a4dceeba098981f19f37c06"), then compile it  according to the README, then install that to make the error go away. However, this isn't strictly necessary.

+ +

All versions of heimdall are unable to flash a system.img larger than 100MB. Do:

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

to see how big yours is. If it's too large, ask in IRC for advice; there are ways to do it in two stages.

+ +

Added step for the Samsung Galaxy S2

+ +

If you're flashing onto the Galaxy S2, there is an additional step to follow. Gaia does not get flashed automatically by the flash.sh script; you'll need to also do:

+ +
./flash.sh gaia
+
+ +

Flashing specific partitions to fastboot phones

+ +

You can flash specific partitions to fastboot phones (that is, any phone other than the Samsung Galaxy S2). For example:

+ +
./flash.sh system
+./flash.sh boot
+./flash.sh user
+
+ +

Updating specific modules

+ +

You can update specific components of B2G by specifying their names when flashing. For example:

+ +
./flash.sh gaia
+./flash.sh gecko
+
+ +

In order to update only one application you can use BUILD_APP_NAME environment variable:

+ +
BUILD_APP_NAME=calendar ./flash.sh gaia
+ +

If your phone is not for developer (you aren't interested on test apps and/or require optimization), you can update gaia using:

+ +
VARIANT=user ./flash.sh gaia
+ +

Next steps

+ +

At this point, your phone should be running Boot to Gecko! It's time to experiment, write some code, test, or do some debugging!

+ +
Note: A helpful usage tip: if your build of B2G starts up with the lock screen requesting a pass code to unlock the phone, the default code is 0000.
+ +

Troubleshooting

+ +

Here are a some tips for what to do if your device doesn't work right after installing B2G, or updating it to a new version

+ +

If the UI doesn't start up

+ +

If you update your phone and the user interface doesn't start up, you can reset it to clear out out-of-date configuration and the like. This may bring it back to life. Here's how:

+ +
cd gaia
+make reset-gaia
+
+ +

If you want change from developer to production mode

+ +
cd gaia
+make reset-gaia PRODUCTION=1
+ +

"image is too large" error message on ./flash.sh execution

+ +

It might mean that you phone needs to be rooted first before flashing it. As b2g needs to be written on root partition, your phone needs to be rooted in order to install it.

diff --git a/files/zh-cn/archive/b2g_os/introduction/index.html b/files/zh-cn/archive/b2g_os/introduction/index.html new file mode 100644 index 0000000000..5652a42443 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/introduction/index.html @@ -0,0 +1,110 @@ +--- +title: Firefox OS简介 +slug: Archive/B2G_OS/Introduction +tags: + - B2G + - Firefox OS + - Gaia + - 介绍 + - 社区 +translation_of: Archive/B2G_OS/Introduction +--- +

 

+ +
+

Firefox OS 致力于推进关于手机完全运行web的可能性和允许新的手机使用用户完全的在线使用他们的首部智能手机的范围. 它是一个开放源码的基于Linux的移动操作系统, 开放的Web标准和Mozilla的Gecko引擎科技提供的关于对手机移动平台的重新定义. 通过关于WebAPI对硬件调用的能力的介绍和提供用户一个直观的, 简洁并且优雅的智能手机体验, Mozilla相信对开发者来讲Web将会提供巨大的机遇去得到用户的青睐用优秀的Web软件.

+
+ +

目标读者

+ +

这套文档是针对于那些想要学习知道Firefox OS的工作机制,怎样去开发项目,怎样去编译和安装他们自己开发的软件的web和平台开发者们. 对那些想要创建和发布他们的web应用的开发者来说, App CenterMarketplace Zone是理想的去处. 

+ +

Firefox OS 的基本承诺

+ +

对于Web/平台开发者来讲, 最重要的部分是理解整个用户调用接口层其实就是一个能够显示和发布其他Web应用的Web应用. 即使对移动设备的硬件和服务可访问性增强了, 但是任何对于用户接口的修改和你在Firfox OS上新建的应用都还是将会引用标准的web技术. 从一个产品的远景来看, Firefox OS是支持用Gecko(操作系统的产品工程研发代号)去启动系统后运行服务的Mozilla平台品牌.  Firefox OS的用户接口层叫做Gaia, 其中包含了系统的默认的应用和系统函数. 想要发现更多关于平台的架构, 请访问 平台指南.  

+ +

当前和未来的计划

+ +

Firefox 0S 2.0正在开发中, 将要出来1.3/1.4 稳定的编译版本. 在开发者和消费者中有很多各种型号不同的手机. 可以知道的更多通过阅读下面的几点:

+ + + +

发布周期

+ +

Since Firefox OS 1.2, the Firefox OS release cycle has been aligned as closely as possible with the Gecko and Firefox desktop version release cycle (6 weeks). A new Firefox OS version is released new every three months, so there will be a Firefox OS release for every two Gecko (Firefox browser core) releases.

+ +

For example. Gecko 30 is bundled with Firefox 1.4, bypassing Gecko 29, and Gecko 32 is bundled with Firefox 2.0 (was 1.5), bypassing Gecko 31.

+ +
+

Note: Check out our rapid release calendar to check the corresponding versions between Firefox OS and Gecko / Desktop Firefox, and read Firefox OS Release Milestones for more information on how our releases are managed.

+
+ +

社区

+ +

Boot to Gecko and Gaia are developed by teams of engineers inside Mozilla, plus, many external contributors from the wider Mozilla/open source community. If you want to talk to the community about any aspect of Firefox OS or Gaia development, a good place to start is our mailing lists and IRC channels, detailed in the below info box.

+ +

+ +
+

加入 Firefox OS 社区

+
+
请选择你喜欢的方式加入我们:
+ +
+
+ +
+
+

+ +

To file bugs, use our Bugzilla system, and file bugs against the Firefox OS components. If you are not sure what component to file a bug against, feel free to ask.

+ +
+

Note: If you have a question or a point to raise about a specific part of the B2G/Gaia source code (for example, a specific Gaia app), you can find more specific contact details on ourFirefox Modules page.

+
+ +

构建一个操作系统

+ +

The B2G operating system is based on Mozilla's Gecko rendering engine, and sits on top of a Linux kernel and userspace hardware abstraction layer (HAL) called Gonk. The Gecko talked about here is basically the same Gecko used in Firefox for Android, or Windows, or Mac OS X, etc. Gonk is basically another porting target of Gecko.

+ +

To learn how to build and install Firefox OS, consult our guide to Building and installing Firefox OS. You can find the B2G source code on Github.

+ +

为 Gaia 做贡献

+ +

To contribute to Gaia, you don't need much more than a solid knowledge of web development. To learn about getting Gaia up and running, consult our Quickstart guide to Gaia development.

+ +

There are a number of useful tools available to you for debugging Gaia and other web apps running on Firefox OS. To learn about these and much more, consult our guide to Hacking Gaia.

+ +

为 Firefox OS 开发 app

+ +

Firefox OS apps are built using standard web technologies — HTML, CSS, JavaScript, etc. — so if you are a web developer you will also have most of what you need. There are a few special JavaScript APIs to know about, which allow you to access device hardware and key features (for example camera, gyroscope, light sensor, contacts, system alarms and notifications...), but these are all well documented on our App Center and Web Platform pages.

+ +
+

Note: If you are a beginner to building open web/Firefox OS apps, or if you want a concise account of the differences between web apps and traditional web pages, the best place to start is our apps Quickstart guide.

+
+ +

支持跨 Firefox OS 版本的应用

+ +

Note that when developing apps for Firefox OS, you need to bear in mind what platform versions will be available on the devices your customers will have (see our available phones table for a list.) Remember that it is not as simple to update phone platform software as it is desktop software — users tend to be at the mercy of the network providers. You therefore need to develop apps to support these versions. As an example, multiline Flexbox doesn't work on Firefox OS versions below 1.3, so you may need to use a simpler layout method or provide a fallback for older versions.

+ +

This issue should go away soon, as more consumer Firefox OS devices appear, equipped with newer versions of Firefox OS out of the box.

+ +
+

The current baseline platform we recommended developing for is Firefox 1.1.

+
+ +
+

Note: MDN's web platform reference pages include browser/platform support information, plus you can find support information for more App-specific technologies on our Apps API Reference.

+
+ +

 

diff --git a/files/zh-cn/archive/b2g_os/phone_guide/best_practices_open_reference_devices/index.html b/files/zh-cn/archive/b2g_os/phone_guide/best_practices_open_reference_devices/index.html new file mode 100644 index 0000000000..3e92766166 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/phone_guide/best_practices_open_reference_devices/index.html @@ -0,0 +1,55 @@ +--- +title: 开放参考设备最佳实践 +slug: Archive/B2G_OS/Phone_guide/Best_practices_open_reference_devices +translation_of: Archive/B2G_OS/Phone_guide/Best_practices_open_reference_devices +--- +
+

The following article aims to provide a set of best practices that we believe should come highly recommended for any widely available open reference devices. All of the recent Firefox OS reference devices have followed these practices, including the forthcoming Flame.

+
+

Devices should have:

+ +

Easily accessible and installable builds

+

Reference devices are largely aimed at developers and other groups with a greater degree of technical knowledge than average device consumers. But even so, we shouldn't expect users of these devices to compile their own builds if they don't wish to — for many of them this is a complete waste of time.

+

Open reference devices should have a maintained set of unlocked builds for current and future releases that are easy to access and install. This means having multiple tiers of builds available, at least:

+ +

They should be made easily available on a dedicated download page, and updated regularly and often. Devices should also have OTA updates made available to them.

+

The OEMs should be responsible for providing these builds since they are the only ones who can legally distribute all the required binaries, etc.

+

It may make sense to follow a similar model to the Firefox browser, where each of the release, stable and nightly channels are based on subsequent versions of the source code.

+

Completely unlocked operating system

+

The device operating system platform should be completely unlocked, so that app and platform developers can have the necessary freedom of control available over their devices to perform any desired tests and development work. This includes:

+ +

Worldwide availability

+

If you want your reference devices to be a universal standard, then it follows that you should make them available worldwide. If this is not the case, people in different locales will have to make do with different devices, which may carry different behaviours.

+

Feature support equivalent to consumer phones

+

There is no point in creating a reference device that does not have support for the same technologies and associated features as the consumer devices you will ultimately be distributing Firefox OS builds and open web apps on.

+

These include:

+ +

Availability of replacement batteries

+

Replacement batteries can often be really hard to obtain for different devices, and can lead to otherwise useful devices being rendered useless. It is therefore a good idea to make replacement batteries as available as possible.

+

Easily enabled language choices

+

Since these device will be distributed worldwide, it is important to make localised builds available for as many languages as possible,  taking into account availability of resources and most popular target market locales.

+

The most likely solution to this is localised Gaia builds or language packs that can be flashed onto the device separately, and Mozilla is working on a solution to make creation and installation of these as easy as possible.

diff --git a/files/zh-cn/archive/b2g_os/phone_guide/flame/index.html b/files/zh-cn/archive/b2g_os/phone_guide/flame/index.html new file mode 100644 index 0000000000..91947e54fd --- /dev/null +++ b/files/zh-cn/archive/b2g_os/phone_guide/flame/index.html @@ -0,0 +1,258 @@ +--- +title: Flame +slug: Archive/B2G_OS/Phone_guide/Flame +translation_of: Archive/B2G_OS/Phone_guide/Flame +--- +

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

+ +

Available to order

+ +

The Flame developer reference phone is a milestone in Firefox OS device releases. The Flame hardware offers a representative set of specs — including FWVGA display and dual-core processor — to help developers build great content and experiences. A single hardware platform is also good for testers, making it easier to test and address specific software issues without having to worry about device model-specific bugs, etc.

+ +

If you have your phone in hand and want to start playing with it, developing and distributing apps, or contributing to the Firefox platform, the following links will get you where you need to go:

+ + + +

If you’d like to find out more about updating the operating system, recovering it, pushing apps to it, or phone specs, you’ll find the information you need below.

+ +

Purchasing a device

+ +

Our device manufacturer partner has made the device available to order on everbuying.com, for US$170 including global shipping (device cost is $145, shipping is $25 and custom fees may still apply, depending on the destination country). The device is bootloader and carrier unlocked, and it utilizes a quad-band GSM+UMTS radio so that it can work with a wide variety of operators/carriers.

+ +
+

Note: Another option for getting hold of a Flame is to participate in our Flames for Apps scheme, aimed at experienced HTML5 app developers wishing to port their highly-rated apps onto Firefox OS.

+
+ +

Updating your Flame's software

+ +

We will have two main "channels" of Firefox OS software version releases for the Flame phone:

+ + + +
+

Note: Windows users will need to install a driver to enable USB communication with their phones. See how to do this in the Windows section below. Linux users may need to add a udev rule; see the Linux and Mac section.

+
+ +

While our partners are working out a final storage solution for the software builds, you can get recovery files and tools at the following Onedrive storage locations:

+ + + +

To install the base image on your device:

+ +
    +
  1. Install ADB on your computer.
  2. +
  3. If you are on Windows, install the driver, as explained in the Windows section below.
  4. +
  5. Make sure remote debugging is enabled on your Flame, using the Remote debugging/Debugging via USB option in the device's Developer settings (the option is different, depending on whether you have Firefox 1.3 and under, or Firefox 1.4+ installed).
  6. +
  7. Connect your Flame to your computer via a USB cable. Verify that the computer is connected to the device by running the adb devices command in a terminal.
  8. +
  9. Download and Extract the software appropriate for your system listed above (the .zip in the case of Mac / Linux, the .exe in the case of Windows)
  10. +
  11. Go into the directory you extracted the software into and run it: +
      +
    • On Windows, simply run the executable.
    • +
    • On Linux / OSX, use the terminal to enter the directory, then run the flash.sh script using sudo ./flash.sh (if you don't run it using sudo, the flash script may fail to see your device, and it won't work).
    • +
    +
  12. +
+ +
+

Note: You are also welcome to build your own builds to install on the Flame: see Building and installing Firefox OS.

+
+ +

Updating your Flame to a nightly build

+ +
+

Note: For this current build, Nightly development builds of Firefox OS do not support A-GPS, which may lead to slow performance of GPS functionality. We plan to resolve this in an updated future Nightly channel.

+
+ +
    +
  1. Before updating your phone to a nightly build you should flash the latest base image to make sure the underlying systems are up to date. Download a base image and use it to update your device's software, as explained above.
  2. +
  3. Because the above step installs a fresh operating system on your device, you'll need to enable remote debugging on your Flame again, using the Remote debugging option in the device's Developer settings.
  4. +
  5. Next, choose a Nightly build to install. You can find nightly builds on http://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/. You'll want one of the following: + +
  6. +
  7. Pick a version and download both the b2g-XX.XX.en-US.android-arm.tar.gz and gaia.zip files.
  8. +
  9. Download the shallow flash script and save it in a sensible place (such as the same directory as the above two files.)
  10. +
  11. Flash the builds to your phone using the following command: +

    Mac

    + +
    ./shallow_flash.sh -g /path/to/gaia.zip -G /path/to/b2g-XX.XX.en-US.android-arm.tar.gz
    + +

    Linux

    + +
    ./shallow_flash.sh -g/path/to/gaia.zip -G/path/to/b2g-XX.XX.en-US.android-arm.tar.gz
    +
  12. +
+ +
+

Note: If you get a "permission denied" error when running the above command, your shell script probably doesn't have the right permissions. Running chmod +x shallow_flash.sh on it should solve this problem.

+
+ +
+

Note: A "shallow flash" only updates Gecko and Gaia, as opposed to a full flash, which updates Gecko/Gaia, but also the underlying Gonk layer and associated binaries particular to that device type. This is why it is a good idea to update to the official base image first, as suggested above, then to shallow flash over the top of that, once you've got the Gonk/binary layer right.

+
+ +
+

Shallow flash flashes more than just Gecko and Gaia so all the data on the device is lost!

+
+ +

Once the install procedure finishes the phone should reboot into the updated build and the first time user workflow.

+ +

Font fix

+ +

After updating Gecko and Gaia to nightly with the v123 base image, there will be a mismatch between the fonts that Gecko and Gaia expects and what the base image provides. To fix this, download our font update package, extract it, navigate into the directory created by extracting, and run the supplied flash.sh script.

+ +

Fastboot mode

+ +

If flashing a new build to your phone fails to work, your phone may becomes unresponsive, and the phone may always reboot in recovery mode. The recovery mode allows you a few actions (reboot, update from adb, wipe data, wipe cache, update from sdcard). Unfortunately, selecting update from adb triggers a sideload mode and you cannot use the other adb commands, only adb sideload would work but the various flash scripts rely on other adb commands.

+ +

In this case, you can probably force fastboot mode as follows:

+ +
    +
  1. power off the phone (which may involve removing the battery in extreme cases...),
  2. +
  3. plug in the USB cable
  4. +
  5. power the phone up again by pressing the Volume Down and Power buttons together.
  6. +
+ +

The phone should only display the very first static logo and stay there, without displaying the boot animation. It seems stuck but is not really: it is in fastboot mode and is waiting for something on the USB cable. At this step, a computer on the other side of the USB cable should see the phone when running fastboot devices to list the connected devices. Note that regular adb would not see the device, only fastboot sees it. In this mode, you can use the flash script to install v123 as explained above. As the script does use both adb and fastboot commands, you may see some initial error and warnings from adb, but eventually the device should be flashed properly at the end.

+ +

Emergency download mode

+ +

If flashing a new build to your phone fails to work, your phone becomes unresponsive, and the phone cannot enter fastboot mode, you can use emergency mode for recovery. A USB cable and the Emergency Download Tool are required to enter emergency download mode. Install this tool and follow the instructions.

+ +

Recovery mode

+ +

You can enter recovery mode to clear your phone data or manually update the firmware. There are two ways to enter this mode:

+ + + +

When in recovery mode, press the Volume up/down keys to move the selection highlight, and the Power key to select. Make sure you have your phone data (Contacts, SMS, etc.) backed up before clearing data, and your upgrade packages downloaded before updating.

+ +

Pushing apps to your Flame

+ +

The App Manager tool makes it easy to push apps to your phone, for testing, etc. Full instructions are available in the article Using the App Manager.

+ +
+

Important: Additional platform-specific instructions are available below. Follow these first before attempting to use the App Manager.

+
+ +

Linux and Mac

+ +

No additional steps should be required if you are using a Linux or Mac system, although depending on your Linux distro, you might need to add a udev rule for your phone, which will look something like the following:

+ +
SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", ATTRS{idProduct}=="9025", GROUP="users", MODE="0666"
+ +

Make sure to --reload-rules, then unplug and replug and your device before continuing.

+ +

Windows

+ +

To access the Flame device with the App Manager/ADB, a USB driver is required. Follow the steps outlined in the below sections to install it.

+ +

Downloading the driver

+ +

Download the Windows driver from this location. Once downloaded, extract the contents of the ZIP file to a suitable place on your hard drive.

+ +
+

Note: The Android Debug Bridge (ADB) must be already installed.

+
+ +

Installing the USB Driver

+ +

At this point, connect your Flame device to your computer using a USB cable.

+ +

To install the driver, open the Alcatel_USB_Driver_Q_4.0.0_2013_11_11_noinstall directory within the extracted ZIP file and double click on the DriverInstaller.exe executable. You may receive a warning at this point that the executable is from an unknown publisher. If so, select the Yes button and the executable will be launched.

+ +

Simple dialog box showing a picture of a phone along with install and uninstall buttons.

+ +

Click on the Install button to install the driver.

+ +

After the driver installs, you can check that it is working by opening a command line window and typing adb devices. This should list the connected device with an output something like:

+ +
List of devices attached
+3561d02a          device
+ +

If your device is not showing up here, check in the Windows Device Manager. Your Flame may be showing up as "ACER ADB Interface". You can confirm this by unplugging the device and seeing if it disappears from the device manager. Uninstall the driver software by right-clicking on "ACER ADB Interface" and clicking uninstall.  Be sure to check the box in the dialog to delete the driver software.  Now re-run the installer above. It is advisable to set the screen timeout on your Flame to something high (Settings > Display > Screen timeout) as Windows sometimes appears to reinstall the default drivers when the screen turns off.

+ +

RAM adjustment

+ +

You can adjust the available RAM capacity to see how apps perform on Firefox OS phones with lower memory footprints.

+ +

This is accomplished by entering fastboot mode (install fastboot first, which is available on the same SDK page as ADB) and typing:

+ +
adb reboot bootloader
+fastboot oem mem [0|256-1024]
+ +

“0” is the memory automatically detected and “256-1024” is the number of megabytes. For example, if you want to adjust device RAM capacity to 512M, enter fastboot oem mem 512.

+ +

You'll need to then reboot your device for the settings to take effect. This can be done using:

+ +
fastboot reboot
+ +

The current memory size can be returned by entering fastboot mode and typing:

+ +
fastboot getvar mem
+
+ +

Network and Device specs

+ +

Network:

+ + + +

Hardware: You can find more of the hardware features listed on our Phone and device specs page.

+ +

Additional features include:

+ + + +

See also

+ + + +
+ +
+ +

 

diff --git a/files/zh-cn/archive/b2g_os/phone_guide/index.html b/files/zh-cn/archive/b2g_os/phone_guide/index.html new file mode 100644 index 0000000000..ff0395cc14 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/phone_guide/index.html @@ -0,0 +1,35 @@ +--- +title: Firefox OS 开发者手机指南 +slug: Archive/B2G_OS/Phone_guide +translation_of: Archive/B2G_OS/Phone_guide +--- +
+

本节包含了运行Firefox OS 的指定手机相关的开发者信息。我们已经有关于  Building and installing Firefox OS 和 Hacking Firefox OS  的文章,因此请到那里获取关于编译和安装的信息。 但与特定手机相关的开发人员会发现下面的文档是非常有用的。

+
+ +

特定的设备信息

+ +
+
Firefox OS phone data
+
在这篇文章中我们列举出了能够得到的Firefox OS手机的信息。比如型号,什么时候能够得到还有一些硬件特性之类的信息都能在这里找到。
+
Flame
+
Information on Mozilla's high-end Firefox OS reference phone, codenamed the Flame, and produced in partnership with T2Mobile.
+
Geeksphone
+
In this article we cover some basic tips on how to keep your Geeksphone up-to-date and how to tweak the system Gaia applications.
+
ZTE OPEN
+
This article contains information on the ZTE OPEN Firefox OS device.
+
ZTE OPEN C
+
The ZTE Open C is an updated ZTE-produced Firefox OS device, with higher end hardware and newer software.
+
 
+
+ +

一般的  Firefox OS 信息

+ +
+
General device features
+
This page lists typical Firefox OS hardware features and minimum hardware requirements.
+
Troubleshooting
+
This article provides tips for resolving common problems you may have while using Firefox OS.
+
Best practices for open reference devices
+
A set of best practices that we believe should come highly recommended for any widely available open reference devices. All of the recent Firefox OS reference devices have followed these practices.
+
diff --git a/files/zh-cn/archive/b2g_os/phone_guide/phone_specs/index.html b/files/zh-cn/archive/b2g_os/phone_guide/phone_specs/index.html new file mode 100644 index 0000000000..04faf7017e --- /dev/null +++ b/files/zh-cn/archive/b2g_os/phone_guide/phone_specs/index.html @@ -0,0 +1,439 @@ +--- +title: Phone and device data +slug: Archive/B2G_OS/Phone_guide/Phone_specs +translation_of: Archive/B2G_OS/Phone_guide/Phone_specs +--- +
+

这篇文章提供有关Firefox OS设备的信息,包括特定的硬件规格,代号,默认安装Firefox OS的版本等等。

+
+ +

可使用的Firefox OS手机

+ +

下面的表格列举了可使用的或已经可用的Firefox OS设备模型。

+ +
+

注意:关于可使用的商业手机的信息,包括可得到手机的国家和经营者,请查阅我们的发现你附近的Firefox OS网页。

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称/代号释放日期最初版本可否获得备注
+

Alcatel One Touch Fire

+ +

hamachi, buri

+
2013年7月12日1.0.1在售 +

在巴西、乌拉圭、意大利、德国、希腊、塞尔维亚、匈牙利和波兰公开发售。

+ +

可由eBay上的经销商获得。

+
Alcatel One Touch Fire E2014年7月18日1.3.0在售在捷克、德国、匈牙利、波兰、俄罗斯公开发售。
otoro, unagi, inari   在ZTE Open之前的用于开发的ZTE非定制机。
+

ZTE Open

+ +

ikura

+
2013年7月2日1.0.1在售和inari相似,在eBay公开发售。
+

LG Fireweb

+ +

leo

+
2013年10月24日1.1在售在巴西公开发售。
+

Geeksphone Keon

+ +

keon

+
2013年4月24日1.0.1已脱销专为开发者提供的设备。
+

Geeksphone Peak

+ +

peak

+
2013年4月24日1.0.1已脱销过去一段时间的代号为“twist",专为开发者提供的设备。
Geeksphone Peak+  不再发售已被取消
Geeksphone Revolution2014年3月4日1.3pre在售在线发售
+

LG Google Nexus 4

+ +

nexus-4

+
   实验性,不再被Google和LG支持,硬件停止开发
+

Flame

+ +

"the reference device"

+
2014年4月晚些时候1.3  +

可以预订

+ +

在2014年12月售完

+
+

Spreadtrum

+ +

tarako

+
2014年第二季度末期 马上销售 
+

ZTE Open C

+
2014年5月13日1.3在售在线发售
Symphony GoFox F152014年9月16日1.4在售仅可通过孟加拉国格莱珉电话公司(Grameenphone)的通道获得。
Intex Cloud Fx 1.3在售仅可由印度的Snapdeal公司获得
Spice Fire One (Mi-FX1) 1.3在售仅可由印度的Snapdeal公司获得
Alcatel OneTouch FireC 4020D2014年10月1日1.3在售Filpkart销售
Zen Fire 1052014年10月16日1.3在售Homeshop18销售
Cherry Mobile Ace2014年11月1.3T在售在菲律宾公开发售
Fx02014年12月2.0在售消费者电话,在日本(KDDI.)公开发售
+ +

Firefox OS版本

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
版本特性完成(FC)日期合作伙伴释放日期代号Gecko版本包括的安全补丁释放版标记
1.02012年12月22日2013年2月21日TEFGecko 18Gecko 18 
1.0.12013年1月15日2013年9月6日ShiraGecko 18Gecko 20Developer
+ Consumer
1.12013年3月29日2013年10月9日LeoGecko 18+ (new APIs)Gecko 23Developer
+ Consumer
1.1.1 TBDHDSame as 1.1.0 with WVGAGecko 23 
1.22013年9月15日2013年12月9日KoiGecko 26Gecko 26Developer
+ Consumer
1.32013年12月9日TBD Gecko 28Gecko 28Developer
+ Consumer
1.42014年3月17日TBD Gecko 30Gecko 30Developer
+ Consumer (TBD)
2.02014年11月TBD Gecko 32Gecko 32Developer
+ Consumer (TBD)
+ +

设备规格

+ +

注意:由于某些原因,有一款即将出现的设备没有被说明,但是我们将分享这些设备的代号和一些性能。不要放额外的设备信息,除非Andreas Gal或者其他同样可以公开说明已公开的信息的人的同意。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameCodenameVersionsResolutionRAMStorage
Alcatel One Touch Firehamachi, buriv1.0.1/v1.1 +

320 x 480
+ PX=1

+
256M/data: probably the same as inari; specs say 160MB "end user memory"
+ Probably no built-in DeviceStorage, MicroSD card (up to 32GB) required
+  
ZTE Open / variantsikurav1.0.1 (as shipped)320 x 480
+ PX=1
256M +

/data: 152M
+ No built-in DeviceStorage, MicroSD card required

+
LG Firewebleov1.1320 x 480
+ PX=1
  +

/data: 1007.90M
+ built-in DeviceStorage: yes, size unsure. possibly 3.7G, but that might be bad math.  (On an unhapy device /sys/devices/platform/msm_sdcc.3/mmc_host/mmc0/mmc0:0001/block/mmcblk0/block is 7733248, and then assuming a 512 byte block size, we get 3.7G)

+
Geeksphone Keonkeon +

v1.0.1 - nightly
+ downloads here

+
320 x 480
+ PX=1
512M +

/data: 1.5G
+ built-in DeviceStorage: 1023.4M

+
Geeksphone Peakpeakv1.0.1 - nightly
+ downloads here
540 x 960
+ PX=1.5
512Mprobably the same as the keon based on specs.
Nexus 4nexus-4v1.3 - nightly768 x 12802GBeverything exists in one big soup, there is no external (MicroSD) storage.  The size of the soup varies based on what model Nexus 4 you got.
some tablet thingflatfish    
some phone thingfuguv1.2f (branch) per320 x 480256MB 
some 128MB platform thingtarakov1.3 per320 x 480128MB (zram) 
+ +

列行解释:

+ + diff --git a/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html b/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html new file mode 100644 index 0000000000..0960f1d970 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/apps_architecture/index.html @@ -0,0 +1,24 @@ +--- +title: Firefox OS apps 架构 +slug: Archive/B2G_OS/Platform/Apps_architecture +translation_of: Archive/B2G_OS/Platform/Apps_architecture +--- +
+

本文讲述了Firefox OS 应用启动和管理的内部原理。对 Firefox OS 平台开发者和将操作系统移植到硬件的团队是有用的。如果您仅仅是一个应用开发者,则不用了解这些细节,但又何妨一读,因为它是十分有趣的过程。

+
+

app启动过程

+

当用户选择他们想要启动或需要启动的应用时, home screen app会通过App API,获取到一个app的引用,之后会调用 App.launch() 方法启动这个应用。 

+

Gecko 接收到请求后会向携带着 app 详情 向System app发送 mozChromeEvent 事件。 System app 对事件进行处理:向 DOM tree中插入一个新的 <iframe> ,并且在这个新的 <iframe> 中装载 app。 此后 frame 就会是 app 的  home 了,直到 app终止。

+

每个 app都需要一个 manifest文件来对 app进行描述,并且在它的包中有一个特定的文件结构。要了解更多详情,请参阅文章 App manifest

+

与 Gecko 通信

+

Gecko 和 Gaia 系统应用之间的通信是通过 mozChromeEventmozContentEvent 完成的。mozChromeEvent 是从 chrome 到 content 的广播;而   mozContentEvents 是从 content 到  chrome 的广播。 这种通信过程用来控制可信任UI 的创建和关闭,以及为通知和其他工作注入需要的功能,如告诉System app 启动一个 app 。

+
+

注意:  通过阅读  System app documentation 您可以获取到关于这些事件工作的更多的内容。 通过阅读 b2g/chrome/content/shell.js 您也可已获取到更多使用的细节。 

+
+

参见

+ diff --git a/files/zh-cn/archive/b2g_os/platform/architecture/index.html b/files/zh-cn/archive/b2g_os/platform/architecture/index.html new file mode 100644 index 0000000000..4b57f44ada --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/architecture/index.html @@ -0,0 +1,1024 @@ +--- +title: Firefox OS架构 +slug: Archive/B2G_OS/Platform/Architecture +tags: + - Architecture + - B2G + - Firefox OS + - Guide + - IPC + - IPDL +translation_of: Archive/B2G_OS/Architecture +--- +

 

+ +
+

草案
+ 本页尚未完工.

+
+ +

 

+ +

这篇文章是对Firefox OS平台的高度概览,介绍了一些关键的概念以及组件如何交互的过程。

+ +
+

Note: Firefox OS 仍然是未发布的产品,这里描述的架构并不是最终版本。

+
+ +

Firefox OS 术语

+ +

在进一步学习 Firefox OS 文档前,请先了解下面的术语。

+ +

架构框图

+ +
+
B2G
+
Boot to Gecko 的简称。
+
Boot to Gecko
+
Firefox OS 操作系统的工程代号。 因为在该项目拥有官方名称之前B2G已经使用了很久的原因,它经常用于指代 Firefox OS。
+
Firefox OS
+
FIrefox OS 基本上是指 Mozilla及合作伙伴应用在 B2G上的品牌和服务支持, 最终将创建一个发布的产品。
+
Gaia
+
Firefox OS 平台的用户接口层。屏幕启动时渲染到屏幕上的一切都是Gaia层的产物。Gaia 实现了 lock screen, home screen, 和所有你所期待在智能手机上看到的标准应用。Gaia 完全使用 HTML, CSS, 和 JavaScript实现。Web APIs 是Gaia层到底层系统的唯一入口,Web APIs 是由Gecko 层实现的。第三方应用可以安装在Gaia层。
+
Gecko
+
Firefox OS 应用的运行环境;该层提供了对: HTML, CSS, and JavaScript三个标准的支持,它能确保APIs能够在gecko支持的系统上良好工作。也就是说,它包括了网络栈,图形栈,布局引擎,js虚拟机和端口层。
+
Gonk
+
Gonk 是Firefox OS平台更低层的系统,包括了 Linux kernel (基于 AOSP)和用户空间硬件抽象层 (HAL)。内核和一些用户空间库都是公共的开源项目:linux, libusb, bluez等。其他的一些硬件抽象层部分是与android项目共享的:GPS, camera等。你可以认为 Gonk 是一个非常简单的 Linux 版本。Gonk 是 Gecko 层的端口目标;也就是说 Gecko 层有到 Gonk 的端口,就像Gecko 到 Mac OS X, Windows, 和 Android 一样。因为Firefox OS 对 Gonk 拥有完全的控制权,相比其他操作系统,我们可以释放更多的接口到 Gecko。例如,Gecko 拥有到 Gonk 电话栈和帧缓冲区的直接入口,但在其他操作系统却没有。
+
Jank
+
这个术语经常用在移动app空间的讨论中,主要是指在app中缓慢/低效的代码操作会导致 block UI的更新甚至出现无响应状态。我们的gaia工程师会不惜一切代价使用各种优化技术来避免这一问题。
+
 
+
 
+
Firefox OS Architecture
+
+ +

 

+ +

Firefox OS 启动步骤

+ +

本节主要描述了FIrefox OS 设备启动以及各模块交互的过程。简而言之,整个系统的启动流程是从内核空间的bootloaders开始,继而对native code初始化,到B2G至用户空间的Gecko,最后会到 Gaia 层 system app,window manager,homescreen app。而其他应用都是在它们上面执行的。

+ +

Firefox os bootup

+ +

自启动过程

+ +

当Firefox OS 设备启动时,执行过程从主要的引导装载程序(primary bootloader)开始。此时,会以常用的方式装载主操作系统。在这个链条中,一级级的装载会触发更高层次的迭代。这个过程最终是交由 Linux 内核处理。

+ +

关于启动过程,这里有几点需要注意的地方:

+ + + +

Linux 内核

+ +

Gonk使用的 Linux内核与原生Linux派生出的AOSP是非常相似的。与AOSP (Android Open Source Project )相比,它还有一些小的变化。另外,厂商还可能会对内核进行修改,并将这些变化按照自身的要求来设定。 一般而言, Linux内核是非常相近的。

+ +

网络上对 startup process for Linux 有许多详细的介绍,此处不会再赘述。

+ +

Linux内核会带动设备的启动并且运行基本的过程。它会先执行 init.rc 中的步骤,继而运行 init.b2g.rc 来启动必须的步骤, 如包含的Gecko内的Firefox OS 基本过程以及 rild (电话相关由不同芯片组相关的进程)— 下面会有更详细的说明。 在过程结束时,正如绝大多数 UNIX-like 操作系统一样, 用户空间 init 进程会被启动。

+ +

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 进程会处理文件系统的加载请求以及派生的系统服务。在此之后,它会作为进程的管理器而存在。这与其他的 UNIX-like操作系统是非常类似的。它会 将init*.rc 脚本文件解释成包含启动各种服务的命令的集合。Firefox OS init.b2g.rc 其实就是在 Android init.rc 文件的基础上添加一些关于启动Firefox OS的命令的文件。

+ +

init 进程启动过程中一个关键任务就是启动 b2g 进程,它是 Firefox OS 操作系统的核心所在。

+ +

init.b2g.rc 文件中启动b2g进程的命令如下所示:

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

您也可以查看下 init.b2g.rc 文件内容,它是添加在 Android init.rc 文件后用来启动b2g进程的。

+ +
+

注意: 对\不同的设备而言init.rc 与 Android 的 对应文件间的差别也是不同的。,init.b2g.rc 只是简单的附加在文件后面的,有时候 patch 文件显得会更重要些。

+
+ +

userspace 进程架构

+ +

现在如果概览一下Firefox OS的不同组件是如何组合在一起并与其他组件交互的过程是非常有用的。下图则包含了 Firefox OS 主要的 usersapce 进程。

+ +

Userspace diagram

+ +
+

注意: 我们应当知道,由于 FIrefox OS 正处在活跃开发阶段,这个框图可能会发生变化,不会那么准确。

+
+ +

b2g 进程是主要的系统进程。它会以非常高的优先级运行,并且会访问绝大多数的硬件设备。b2g 会和 modem 进行通信, 会在 display framerbuffer上绘图, 与 GPS, Camera 以及其他硬件交互。 b2g 内部运行在Gecko层(由 libxul.so 实现)。查看 Gecko 可以获得 Gecko层如何工作, b2g 与Gecko如何通信的细节。

+ +

b2g

+ +

b2g 进程可能会反过来孵化一些低优先级的 content processes。 这些进程都是关于 web 应用或其他的 web 内容装载的过程。这些进程会和Gecko server主进程通过 IPDL 消息传送系统进行通信。

+ +

rild

+ +

rild 进程是 modem 处理器的接口。 rild 是实现 Radio Interface Layer (RIL) 的守护进程。 它是一个专有的代码,由硬件供应商与自己的modem 硬件实现。rild 使客户端代码连接它所绑定的 UNIX域的 socket成为可能。它会由 init 脚本中的如下代码启动:

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

rilproxy

+ +

在Firefox OS 中, rild 客户端就是 rilproxy 进程。它在 rildb2g 扮演着简单的转发代理服务器的角色。这个代理需要的是实现的细节,可以说,这确实是非常必要的。riproxy 代码可以在Github上找到。

+ +

mediaserver

+ +

mediaserver 进程控制着音频和视频的播放。Gecko会通过 Android远程过程调用机制(RPC)与 其通信。Gecko可以播放的多媒体(OGG Vorbis 音频, OGG Theora 视频,以及 WebM 视频)都是由 Gecko解码并直接发送给 mediaserver 进程。其他的多媒体文件是由 libstagefright 解码的,它能够访问专用编码器和硬件编码器。

+ +
+

注意: mediaserver 进程时一个临时的Firefox OS组件, 对我们初始的开发会有帮助,但最终会离开。然而在 Firefox OS 2.0 之前,可能不会发生。

+
+ +

netd

+ +

netd 进程用来对网络接口进行配置。

+ +

wpa_supplicant

+ +

wpa_supplicant 进程是标准的 UNIX样式的守护进程,会处理 WIFI 的连接。

+ +

dbus-daemon

+ +

dbus-daemon 实现了 D-Bus( DBus 是指Firefox OS 用于蓝牙通信的一种消息总线系统)。

+ +

 

+ +

Gecko

+ +

Gecko,正如之前提到的,是对 web标准( HTML, CSS, andJavaScript)的实现,用于实现用户在Firefox OS 上看到的一切界面。

+ +
+

注意: 您可以使用 http://dxr.mozilla.org 来查找Gecko代码库。这个网站非常有趣,并且提供了较好的参照特性,但是代码库的数量有限。或者您可以尝试下传统的 http://mxr.mozilla.org ,其中会包括更多的Mozilla 项目。

+
+ +

与Firefox OS 相关的 Gecko 文件

+ +

b2g/

+ +

b2g 文件夹会包含了一些主要的Firefox OS 相关的功能。.

+ +
b2g/chrome/content
+ +

包含了在system app 之上运行的 Javascript 文件。

+ +
b2g/chrome/content/shell.html
+ +

Gaia的入口 — system app的html。 shell.html 会加载 settings.js 和 shell.js:

+ +
<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 quota, RemoteDebugger, keyboard helper, 和screenshot 工具。

+ +

但是shell.js 最重要的功能就是启动了 Gaia system app, 之后又将整个系统相关的管理工作移交给了 Gaia 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 user.js文件覆写。

+ +

dom/{API}

+ +

新的 API 实现(post-b2g)放置在 dom/ 文件夹中;而旧的API 的 dom/base 文件夹中,如 navigator.cpp。

+ +
dom/apps
+ +

.jsm 文件会被加载,是对.js API 的实现,如 webapp.js 等。

+ +
dom/apps/src/
+ +

所有的权限信息都在 PermissionsTable.jsm 文件中定义。

+ +

dom/webidl

+ +

WebIDL 是一种用来定义 web APIs 的语言。可查看 WebIDL_bindings 文件来获取它所支持的特性。

+ +

hal/gonk

+ +

这个文件夹包含了 gonk 接口层的相关文件。

+ +

Generated files

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

包含所有的配置文件。

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

包含了设备中的资源样式包。

+ +

输入事件处理

+ +

在Gekco层绝大多数动作都是由用户行为触发的。这些动作是由输入事件所表示的(如按钮点击,触屏设备的触控,等等)。这些事件是通过 nsIAppShellGonk implementation 传入的,这个接口用来表示Gecko 应用的最初入口点。也就是说, 输入设备会调用 nspAppShell对象的方法,来表示 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 使用了 light abstraction layer 来覆写它;它也提供了较好的特性如事件过滤机制。 您可以在 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 events 分发到web 应用中进一步处理

+ +

图像

+ +

在底层, Gecko 会使用 OpenGL ES 2.0 to draw to a GL context that wraps the hardware frame buffers. 这是由 Gonk 层nsWindow 实现的,代码如下:

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

FramebufferNativeWindow 类是直接 从Android拿过来的,可参考 FramebufferNativeWindow.cpp。为了能够将缓存从帧缓存设备映射到内存中,它使用了 gralloc API 来访问图像驱动。

+ +

Gecko 使用了 Layers 系统来将复合后的内容画在屏幕上。总结一些,基本步骤是:

+ +
    +
  1. Gecko draws separate regions of pages into memory buffers. Sometimes these buffers are in system memory; other times, they're textures mapped into Gecko's address space, which means that Gecko is drawing directly into video memory. This is typically done in the method BasicThebesLayer::PaintThebes().
  2. +
  3. Gecko then composites all of these textures to the screen using OpenGL commands. This composition occurs in ThebesLayerOGL::RenderTo().
  4. +
+ +

The details of how Gecko handles the rendering of web content is outside the scope of this document.

+ +

硬件抽象层 (HAL)

+ +

The Gecko hardware abstraction layer is one of the porting layers of Gecko. It handles low-level access to system interfaces across multiple platforms using a C++ API that's accessible to the higher levels of Gecko. These APIs are implemented on a per-platform basis inside the Gecko HAL itself. This hardware abstraction layer is not exposed directly to JavaScript code in Gecko.

+ +

How the HAL works

+ +

Let's consider the Vibration API as an example. The Gecko HAL for this API is defined in hal/Hal.h. In essence (simplifying the method signature for clarity's sake), you have this function:

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

This is the function called by Gecko code to turn on vibration of the device according to the specified pattern; a corresponding function exists to cancel any ongoing vibration. The Gonk implementation of this method is in hal/gonk/GonkHal.cpp:

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

This code sends the request to start vibrating the device to another thread, which is implemented in VibratorRunnable::Run(). This thread's main loop looks like this:

+ +
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() is the Gonk HAL API that turns on the vibrator motor. Internally, this method sends a message to the kernel driver by writing a value to a kernel object usingsysfs.

+ +

Fallback HAL API implementations

+ +

The Gecko HAL APIs are supported across all platforms. When Gecko is built for a platform that doesn't expose an interface to vibration motors (such as a desktop computer), then a fallback implementation of the HAL API is used. For vibration, this is implemented in hal/fallback/FallbackVibration.cpp.

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

Sandbox implementations

+ +

Because most web content runs in content processes with low privileges, we can't assume those processes have the privileges needed to be able to (for example), turn on and off the vibration motor. In addition, we want to have a central location for handling potential race conditions. In the Gecko HAL, this is done through a "sandbox" implementation of the HAL. This sandbox implementation simply proxies requests made by content processes and forwards them to the "Gecko server" process. The proxy requests are sent using IPDL.

+ +

For vibration, this is handled by the Vibrate() function implemented in hal/sandbox/SandboxHal.cpp:

+ +
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()));
+}
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +

This sends a message defined by the PHal interface, described by IPDL in hal/sandbox/PHal.ipdl. This method is described more or less as follows:

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

The receiver of this message is the HalParent::RecvVibrate() method in hal/sandbox/SandboxHal.cpp, which looks like this:

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

This omits some details that aren't relevant to this discussion; however, it shows how the message progresses from a content process through Gecko to Gonk, then to the Gonk HAL implementation of Vibrate(), and eventually to the Vibration driver.

+ +

DOM APIs

+ +

DOM interfaces 从本质上说,是指web内容与Gecko的如何通信的。当然此处会涉及到更多的内容,如果您对更多的细节感兴趣,可以参考 about the DOM 。. DOM 接口是使用 IDL 定义的,包括外部功能接口(FFI) 和使用JavaScript 和 C++ 的对象模型(OM)。

+ +

震动API是通过IDL接口暴露给web内容的,IDL接口定义在nsIDOMNavigator.idl:

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

jsval 参数表示 mozVibrate() (这个未定版的震动规范是以我们的厂商作为前缀实现的)会接受任何输入的JavaScript值。 IDL编译器 xpidl 会产生一个C++接口,这个接口由 定义在 Navigator.cpp 文件中的 Navigator实现。

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

您在这个方法中看到的源码要比这里要多,但这并非我们此次讨论的目的。关键点在于此处会调用 hal::Vibrate() 将控制行为从DOM层传送到GECKO HAL层。 在那里,我们会进入 在之前一节HAL 实现的讨论,并会一直走到图形驱动层。最重要的是,DOM的实现并不会关心它运行在那个平台 (Gonk, Windows, Mac OS X, 或者其他)。、它也不会关心这些代码时运行在 content 进程或者是 Gecko 服务器进程。这些细节都会由系统底层处理。

+ +

震动 API 非常简单, 可以作为一个好的例子来讲解。 SMS API 则比较复杂会使用到自身的“远程”层级连接content 进程到服务器。

+ +

Radio Interface Layer (RIL)

+ +

The RIL was mentioned in the section The userspace process architecture. This section will examine how the various pieces of this layer interact in a bit more detail.

+ +

The main components involved in the RIL are:

+ +
+
rild
+
The daemon that talks to the proprietary modem firmware.
+
rilproxy
+
The daemon that proxies messages between rild and Gecko (which is implemented in the b2g process). This overcomes the permission problem that arises when trying to talk to rild directly, since rild can only be communicated with from within the radiogroup.
+
b2g
+
This process, also known as the chrome process, implements Gecko. The portions of it that relate to the Radio Interface Layer are dom/system/gonk/ril_worker.js (which implements a worker thread that talks to rild through rilproxy and implements the radio state machine; and the nsIRadioInterfaceLayer interface, which is the main thread's XPCOMservice that acts primarily as a message exchange between the ril_worker.js thread and various other Gecko components, including the Gecko content process.
+
Gecko's content process
+
Within Gecko's content process, the nsIRILContentHelper interface provides an XPCOM service that lets code implementing parts of the DOM, such as theTelephony and SMS APIs talk to the radio interface, which is in the chrome process.
+
+ +

Example: Communicating from rild to the DOM

+ +

Let's take a look at an example of how the lower level parts of the system communicate with DOM code. When the modem receives an incoming call, it notifies rild using a proprietary mechanism. rild then prepares a message for its client according to the "open" protocol, which is described in ril.h. In the case of an incoming call, aRIL_UNSOL_RESPONSE_CALL_STATE_CHANGED message is generated and sent by rild torilproxy.

+ +

rilproxy, implemented in rilproxy.c, receives this message in its main loop, which polls its connection to rild using code like this:

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

Once the message is received from rild, it's then forwarded along to Gecko on the socket that connects rilproxy to Gecko. Gecko receives the forwarded message on its IPC thread:

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

The consumer of these messages is SystemWorkerManager, which repackages the messages and dispatches them to theril_worker.js thread that implements the RIL state machine; this is done in theRILReceiver::MessageReceived() method:

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

The task posted to that thread in turn calls the onRILMessage() function, which is implemented in JavaScript. This is done using the JavaScript API functionJS_CallFunctionName():

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

onRILMessage() is implemented in dom/system/gonk/ril_worker.js, which processes the message bytes and chops them into parcels. Each complete parcel is then dispatched to individual handler methods as appropriate:

+ +
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);
+  }
+}
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +

This code works by getting the request type from the object, making sure it's defined as a function in the JavaScript code, then calling the method. Since ril_worker.js implements each request type in a method given the same name as the request type, this is very simple.

+ +

In our example, RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, the following handler is called:

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

As you see in the code above, when notification is received that the call state has changed, the state machine simply fetches the current call state by calling thegetCurrentCall() method:

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

This sends a request back to rild to request the state of all currently active calls. The request flows back along a similar path the RIL_UNSOL_RESPONSE_CALL_STATE_CHANGEDmessage followed, but in the opposite direction (that is, from ril_worker.js toSystemWorkerManager to Ril.cpp, then rilproxy and finally to the rild socket). rildthen responds in kind, back along the same path, eventually arriving in ril_worker.js's handler for the REQUEST_GET_CURRENT_CALLS message. And thus bidirectional communication occurs.

+ +

The call state is then processed and compared to the previous state; if there's a change of state, ril_worker.js notifies the nsIRadioInterfaceLayer service on the main thread:

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

nsIRadioInterfaceLayer is implemented in dom/system/gonk/RadioInterfaceLayer.js; the message is received by itsonmessage() method:

+ +
 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;
+   ...
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +

All this really does is dispatch the message to the content process using the Parent Process Message Manager (PPMM):

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

In the content process, the message is received by receiveMessage() method in the nsIRILContentHelper service, from the 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;
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +

This, in turn, calls the nsIRILTelephonyCallback.callStateChanged() methods on every registered telephony callback object. Every web application that accesses the window.navigator.mozTelephony API has registered one such callback object that dispatches events to the JavaScript code in the web application, either as a state change of an existing call object or a new incoming call event.

+ +
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;
+}
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +
 
+ +

Applications can receive these events and update their user interface and so forth:

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

Take a look at the implementation of handleEvent() in the Dialer application as an extended example.

+ +

3G data

+ +

There is a RIL message that initiates a "data call" to the cellular service; this enables data transfer mode in the modem. This data call ends up creating and activating a Point-to-Point Protocol (PPP) interface device in the Linux kernel that can be configured using the usual interfaces.

+ +
+

Note: This section needs to be written.

+
+ + + +

This section lists DOM APIs that are related to RIL communications:

+ + + +

WiFi

+ +

Firefox OS 的WIFI后台只是简单的借助 wpa_supplicant 来完成绝大部分工作。也就是说,后台的主要工作就是对 supplicant 的简单管理以及一些初始化的工作,如装载WiFi 驱动和使能或禁止网络接口。后台本质上只是一个跟随supplicant 状态而变化的状态机。

+ +
+

注意: 在WIFI中发生的绝大部分事情会取决于 wpa_supplicant 进程状态的变化。

+
+ +

WIFI组件的实现可以分成两个文件:

+ +
+
dom/wifi/DOMWifiManager.js
+
实现了暴露给web 内容的API,这些API是定义在 nsIWifi.idl中的。
+
dom/wifi/WifiWorker.js
+
实现了关于 supplicant 的状态机和驱动代码。
+
+ +

这两个文件之间使用 message manager 通信。消息的后台监听需要特定的动作触发,如 "associate", 当动作执行完成时也会返回一个消息。

+ +

对响应方法的DOM侧监听与一些事件消息一样,都表示状态的变化和信息的更新。

+ +
+

Note: 任何同步的 DOM APIs 都是通过管道一侧的缓存数据实现的。如果可能的话,要尽量避免使用同步消息。

+
+ +

WifiWorker.js

+ +

This file implements the main logic behind the WiFi interface. It runs in the chrome process (in multi-process builds) and is instantiated by the SystemWorkerManager. The file is generally broken into two sections: a giant anonymous function and WifiWorker(and its prototype). The anonymous function ends up being the WifiManager by providing a local API, including notifications for events such as connection to the supplicant and scan results being available. In general, it contains little logic and lets its sole consumer control its actions while it simply responds with the requested information and controls the details of the connection with the supplicant.

+ +

The WifiWorker object sits between the WifiManager and the DOM. It reacts to events and forwards them to the DOM; in turn, it receives requests from the DOM and performs the appropriate actions on the supplicant. It also maintains state information about the supplicant and what it needs to do next.

+ +

DOMWifiManager.js

+ +

This implements the DOM API, transmitting messages back and forth between callers and the actual WiFi worker. There's very little logic involved.

+ +
+

Note: In order to avoid synchronous messages to the chrome process, the WiFi Manager does need to cache the state based on the received event.

+
+ +

There's a single synchronous message, which is sent at the time the DOM API is instantiated, in order to get the current state of the supplicant.

+ +

DHCP

+ +

DHCP and DNS are handled by dhcpcd, the standard Linux DHCP client. However, it's not able to react when the network connection is lost. Because of this, Firefox OS kills and restarts dhcpcd each time it connects to a given wireless network.

+ +

dhcpcd is also responsible for setting the default route; we call into the network manager to tell the kernel about DNS servers.

+ +

网络管理器

+ +

网络管理器会对由3G数据和WIFI组件打开的网络接口进行配置。

+ +
+

注意: 这部分内容需要完善。

+
+ +

进程和线程

+ +

Firefox OS 操作系统使用 POSIX 线程机制实现所有的应用线程,包括每个应用的主线程,Web workers和辅助线程。优先值是由标准的Linux内核调度程序决定用来表示进程和线程执行时的优先级。根据进程的状态不同,我们设定了不同的优先值。当前共有7个等级:

+ +

进程优先级等级

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PriorityNiceUsed for
MASTER0b2g 主进程
FOREGROUND_HIGH0持有 CPU wakelock 的应用
FOREGROUND1前台应用
FOREGROUND_KEYBOARD1键盘应用
BACKGROUND_PERCEIVABLE7播放音乐的后台应用
BACKGROUND_HOMESCREEN18homescreen 应用
BACKGROUND18运行在后台的所有其他应用
+ +

有些等级优先值是相同的,这是因为这些等级是低内存查杀机制处理的方式是不同的。所有的优先级都可以在构建时通过参数配置进行调整。您可以在 b2g/app/b2g.js文件中找到相关实体。

+ +
+

注意: 要获取更多关于内存溢出(out-of-memory killer)以及 Firefoex OS 是如何管理低内存状态的内容,可以参阅 Out of memory management on Firefox OS.

+
+ +

在一个进程内部,主线程继承了进程的优先值,同时则给定了web worker线程比主线程高一个值的优先值。因此web worker 线程优先级与主线程相比要低一些。之所以这么做是为了避免 CPU密集性的工作降低主线程的处理速度。当比较重要的事件(如一个应用转到前台或后台,启动一个新的应用或一个已存在的应用获得 CPU wakelock)发生时,进程优先级就会发生变化。当一个进程优先级发生变化时,其中所有的线程优先级就会对应的作出调整。

+ +
+

注意: cgroups 当前并没有用于资源的管理,它们在特定的设备及内核中显得并不可靠。

+
+ +

 

diff --git a/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html b/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html new file mode 100644 index 0000000000..591d5e7bb6 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/feature_support_chart/index.html @@ -0,0 +1,158 @@ +--- +title: 功能支持图表 +slug: Archive/B2G_OS/Platform/Feature_support_chart +tags: + - B2G + - QA + - Testing +translation_of: Archive/B2G_OS/Platform/Feature_support_chart +--- +

+
+

这里有许多不同的 Firefox OS 编译版本,您可以选择下载或者由自己编译,在每个设备上所支持的功能都会有所区别。下面的图表则可以帮助我们理解在不同设备上所支持或不支持的功能。

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
功能设备模拟器桌面版本
DialerAllUI only, no networkUI only, no network
ContactsAllAllAll
SMSAllUI only, no networkUI only, no network
CameraAllUI only, no camera supportUI only, unsure about desktop camera support at this time
GalleryAllAllAll
VideoAllUI onlyAll
MusicAll All
FM RadioAllAllUI only
EmailAllAllAll
CalculatorAllAllAll
BrowserAllAllAll
MarketplaceAllAllAll
ClockAllAllAll
CalendarAllAllAll
Home ScreenAllAllAll
Lock ScreenAllAllAll
KeyboardAllAllAll
Task ManagerAllAllAll
First-RunAll??
NotificationAllAllAll
Status BarAll一些网络状态不能被测试一些网络状态不能被测试
SettingsAllAllAll
+

 

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html new file mode 100644 index 0000000000..85d101cf3a --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/build_system_primer/index.html @@ -0,0 +1,68 @@ +--- +title: 构建系统入门 +slug: Archive/B2G_OS/Platform/Gaia/Build_System_Primer +translation_of: Archive/B2G_OS/Developing_Gaia/Build_System_Primer +--- +

本文介绍了Gaia构建系统是如何工作的,包括 makefile, 构建过程,环境变量及潜在定制。 

+

在构建步骤中绝大多数有意义的工作都是由存放在Gaia子文件夹 build/ 下的脚本执行的,它们主要是使用make, node.js , XPCShell (也称作JS Shell)以及 XULRunner [zh-CN]执行的。Gaia构建系统中包含许多帮助工具,可以将webapp安装,测试,定位和打包到实际设备上。它同样允许开发者通过诸如更改默认壁纸,铃声,应用和设置的方式来对Gaia自定义。

+

Makefile文件

+

 Makefile文件中包含许多有用的命令,本节会对最有用的一些命令进行解释: 

+

install-gaia

+

该命令会将Gaia层所有的应用推送到设备端。如果想要推送特定的应用,可以使用APP 标志位:

+
APP=calendar make install-gaia
+

运行上面命令时所在的位置必须是Gaia  apps 下的文件夹(例如  apps).

+

reset-gaia

+

该命令会对设备中的应用进行清理并且在安装完成应用后会设置权限的默认值,除此之外与 install-gaia 命令作用是相同的. 在构建工程时,应用会存放在 /data/local类似的目录. 它同样也会将测试和调试的应用推送到手机中。

+
+

注意: 如果在使用 reset-gaia 时加入 APP 环境变量,会使您的手机不可用(此时可以通过再次执行不带 APP 变量的命令恢复). 因此请不要这样做.

+
+

production

+

该命令会将web应用安装在/system/b2g 下,而不是/data/local,除此之外与 reset-gaia 作用是相同的。这个命令能够使您对user版本进行仿真,这个命令同样会将一系列的应用安装在user版本上

+

 

+

参考工作负载

+

These goals push variously sized workloads to the device, helping us with debugging and fixing the performance and scalability issues we might have. These goals accept the APP environment variable, or an APPS environment variable that should contain the app names separated by a space, e.g.,

+
APP=sms make reference-workload-light
+APPS="sms communications/contacts" make reference-workload-heavy
+
+  
+
+  
+
+

注意: For more information, read Hacking Gaia: Reference workloads.

+
+

环境变量

+

一些环境变量能够让你控制在设备上的构建与安装的一些方面:

+

B2G_SYSTEM_APPS=1

+

这个环境变量能够让你把应用推送到 /system/b2g 而不是 /data/local。 You should use that when you work with a user build. This variable is automatically set when running make production. This can be used for install-gaia or reset-gaia too.

+

GAIA_OPTIMIZE=1

+

This triggers an optimization pass on the JavaScript files. This is automatically set when running make production. This can be used for install-gaia or reset-gaia too.

+

PRODUCTION=1

+

This is basically an alias for make production (or is it the other way around ?).

+

DEBUG=1

+

This lets you generate a debug profile to use with the unit tests or to develop your Firefox OS app in Firefox. You must delete the existing profile directory before trying to generate a new one.

+

GAIA_DEV_PIXELS_PER_PX=1.5

+

This generates a profile suitable for running on WVGA devices.

+

Customizing the preferences

+

If you find that you have a set of custom preferences you need to set each time you flash your device, create a file called custom-prefs.js inside the build directory and store them in there. This keeps them from being overwritten and out of source control.

+

Here are some useful preferences:

+
// this enables marionette which lets you run performance tests
+// see https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS/Platform/Testing/Gaia_performance_tests
+user_pref("marionette.defaultPrefs.enabled", true);
+
+// this sets the port for remote debugging your application on the device
+user_pref("devtools.debugger.remote-port", 60000);
+
+// this enables the remote debugger
+user_pref("devtools.debugger.remote-enabled", true);
+
+// this outputs debug information about the Radio Interface Layer in logcat
+user_pref("ril.debugging.enabled", true);
+
+

This file is read each time you generate a profile. The safest way to be sure that everything is generated is to delete your profile first:

+
rm -rf profile && make profile
+

Then you can safely use the install-gaia goal.

+

FAQ

+

1) The device remains black after a flash

+

This can sometimes happen if you flash the device while it is idle. To remedy this just restart B2G by issuing the following command from the command line:

+

adb shell stop b2g && adb shell start b2g

+

 

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html new file mode 100644 index 0000000000..856090aaca --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/browser/index.html @@ -0,0 +1,107 @@ +--- +title: Browser +slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Browser +tags: + - Apps + - B2G + - Firefox OS + - Gaia + - 指南 + - 浏览器 +translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Browser +--- +
+

Browser app (当前是 System 的一部分) 提供了浏览器相关的功能 — 包括页面导航,搜索和书签。本文介绍了 Browser app 的基本工作以及它是如何融合进更大的 System中的。

+
+

由于 Gaia 运行 Gecko 的上层, 在基于 Gekco 实例之上,启动一个 Browser app/ System 浏览器进行常规的页面是非常容易做到的。它是由  mozBrowser API 实现的。

+
+

注意:  Firefox OS 2.1 之后, Browser app 就是 System app 的一部分了。这意味着可以同时通过点击浏览器图标启动 Browser app 或通过全局搜索以及导航的能力来进行 web 浏览。 app 和 浏览器 tab 页此后会有共同的公共体验, 它们会作为 Haida 用户体验 的一部分,存在于任务管理器和表视图中(用于边缘手势)。

+
+

System 浏览器 (浏览器框架)

+

当 Firefox OS 用户将一个 web 页面添加为标签时, 它就会显示在 homescreen 上, 这个 web 页面后续就会打开 System 浏览器而不是 Browser app。在页面底部会有一个工具栏, 包括 向前/向后/刷新的功能。在 Gaia 中,它被称之为浏览器框架或包装器( wrapper)。您可以在下面图片的右手侧看到。

+

A diagram showing that when a web page is opened in the system browser, it is given a toolbar.

+

如果想要使您的 web 页面仍具有 后退/前进/刷新 的功能, 您可以在 app 表单文件中包含下面声明来使能浏览器框架。

+
declare { chrome: { navigation: true } }
+
+

注意:  浏览器框架工具栏会影响到内容的高度,因此当在设计 web 页面布局时将其考虑进去。

+
+

代码流程

+

当在 Firefox OS 中打开一个新的 web 页面时,调用流程如下

+
Gecko > WrapperFactory > Window Manager > AppWindow > BrowserFrame
+

Wrappers inheriting from system/js/wrapper_factory will receive the mozbrowseropenwindow event for a bookmarked web page.

+

In the handleEvent section, the handler will check the event to decide whether the web page should be opened as an app or in browser chrome.

+

Finally, launchWrapper is called to launch the corresponding window.

+

全局搜索 & 导航

+

With the new search and navigation bar, users can get to their favorites, type in a URL, or discover a new app, from anywhere in Firefox OS. The search bar lives at the top of the screen, and users can just tap or swipe to open it.

+

Think of it as a combination of the Awesome Bar from the browser and the adaptive app search from the homescreen. Because Firefox OS uses web apps, when you find what you want, even if it’s a new app, it opens right away. You don’t need to install anything, because everything is instant and web—like.

+

Browser App

+

The Browser app is a certified webapp that provides a general web browser experience. The main function is located in apps/browser/js/browser.js:

+
var Browser = {
+  init: function browser_init() {
+    this.getAllElements();
+      ...
+    BrowserDB.init((function() {
+      ...
+    }
+  }
+};
+
+window.addEventListener('load', function browserOnLoad(evt) {
+  window.removeEventListener('load', browserOnLoad);
+  Browser.init();
+});
+

The Browser will call its init() function while the DOM is loaded.

+
getAllElements: function browser_getAllElements() {
+  var elementIDs = [
+    'toolbar—start', ... 'danger—dialog'];
+
+  // Loop and add element with camel style name to Modal Dialog attribute.
+  elementIDs.forEach(function createElementRef(name) {
+    this[this.toCamelCase(name)] = document.getElementById(name);
+  }, this);
+},
+

The getAllElements function is used to get all camelCase element handlers, after which the apps/browser/js/browser_db.js  is called, to prepare for adding the default search engine and bookmarks.

+

书签

+

From Firefox OS 2.0 apps/bookmark is used to handle bookmark save/remove activities.

+

The most interesting parts apps/bookmark/webapp.manifest looks like so:

+
"activities": {
+  "save—bookmark": {
+    "filters": {
+      "type": "url",
+      "url": { "required":true, "pattern":"https?:.{1,16384}" }
+    },
+    "disposition": "inline",
+    "href": "/save.html",
+    "returnValue": true
+  },
+  "remove—bookmark": {
+    "filters": {
+      "type": "url",
+      "url": { "required":true, "pattern":"https?:.{1,16384}" }
+    },
+    "disposition": "inline",
+    "href": "/remove.html",
+    "returnValue": true
+  }
+},
+

As seen above, the activity is handled by save.html and remove.html. Both operations are delegated to apps/bookmark/js/activity_handler.js:

+
var ActivityHandler = {
+  'save—bookmark': function ah_save(activity) {
+  },
+
+  'remove—bookmark': function ah_remove(activity) {
+  }
+};
+
+navigator.mozSetMessageHandler('activity', function onActivity(activity) {
+  var name = activity.source.name;
+  switch (name) {
+    case 'save—bookmark':
+    case 'remove—bookmark':
+      if (activity.source.data.type === 'url') {
+        ActivityHandler[name](activity);
+      }
+    ...
+  }
+}
+

When the message handler listener navigator.mozSetMessageHandler('activity') receives the save-bookmark or remove-bookmark activities, the ActivityHandler function is triggered to handle correspondent operations.

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html new file mode 100644 index 0000000000..c8a36a6477 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/index.html @@ -0,0 +1,90 @@ +--- +title: Gaia应用 +slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps +tags: + - Apps + - B2G + - Firefox OS + - Gaia + - 架构 +translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps +--- +
+

Gaia是Firefox OS 的前端, 它包括系统管理的功能以及附带在Firefox OS上的一些内置应用。所有的Gaia源代码(包括system和键盘IMEs)都完全由HTML5 ( HTML + CSS + JavaScript )  & 开放Web API实现的。 本文介绍了在Gaia家族工作的每一个可获得的应用的信息。

+
+

Gaia 功能性分类

+

Gaia中的应用大致可分成下面几类。

+
+

注意: 许多关于解释单个应用如何工作的页面都是链接自 Gaia Github repo 中的README文件。这是因为许多app都处在快速开发周期内,会迅速的变化(通常是每天),因此如果使MDN页面根据这些变化快速的更新是没有什么意义的。工程师维护的README页面则是当前信息最准确的来源。

+
+

平台

+

包括系统(System),设置(Settings),锁屏(Lockscreen),编译脚本(build scripts) 以及蓝牙(Bluetooth) 应用。

+

+

平台应用:进一步讲解

+
+
+ System
+
+ System app是在Firefox OS启动过程中由Gecko装载的第一个web应用。它会担负许多责任,一般都是系统运行所需要的,因此不会局限于对某一个web应用。
+
+ Browser
+
+ Browser app(当前是System 的一部分)会提供一些浏览器类似的功能—包括页面导航,搜索和书签等。
+
+ Window Management
+
+ Firefox OS的窗口管理功能 — 包括应用的生命周期和交互、通知、动画以及其他 — 是由System app的特定部分所处理的。本文会着眼于Firefox OS 窗口管理的细节问题。
+
+ Settings
+
+ Firefox OS 用户可以通过 Settings 应用来配置设备的设置信息,响应传入的活动(带有config名称的Web activities),这种传入的活动可以使其他应用跳转到Settings应用的不同的界面来处理需要的配置(例如,当没有数据链接时,会显示wifi设置界面)。
+
+
+
+  
+
+

通信

+

包括 Dialer, Contact, SMS 以及 FTU应用.

+

+

通信应用:进一步讲解

+

TBD(有待讨论)

+

生产力应用

+

包括 Email, Calendar, 以及 Clock 应用。

+

+

生产力应用:进一步讲解

+
+
+ Calendar
+
+ Firefox OS内置的日历应用。
+
+ Clock
+
+ Firefox OS原生的始终应用,包括闹钟,定时器,跑表功能。
+
+ Email
+
+ Gaia e-mail 应用。
+
+

多媒体

+

包括相机(Camera),  图库(Gallery), 音乐播放器(Music), 视频播放器(Video)应用以及一些多媒体相关的功能比如DRM和壁纸(wallpapers)。

+

+

多媒体:进一步讲解

+
+
+ Video
+
+ Video 是视频播放应用,它能够播放在您Firefox OS 设备中存储的多媒体
+
+ Camera
+
+ 用户可以使用Camera来从设备摄像头中捕捉和管理视频和图片,而且还能够响应其他应用想要使用摄像头功能来获取多媒体时发出的pick类型的 Web activitie
+
+

其他的Gaia 功能

+

除了这些功能,还有其他一些主要的功能例如 browser, homescreen, marketplace, test framework, PDF viewer,以及 app manager,这些都是和Gaia一起紧密开发的。

+
+
+ pdf.js
+
+ pdf.js 是基于HTML5的PDF阅读器,用于在Gaia内阅读PDF文件。注意 pdf.js是在Gaia外一个独立的仓库维护的。
+
diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html new file mode 100644 index 0000000000..2d14f5798f --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/settings/index.html @@ -0,0 +1,78 @@ +--- +title: 系统设置 (Settings) +slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Settings +translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Settings +--- +
+

Settings app 允许用户来配置设备的系统设置信息,同时会对传入的 activities作出响应,即允许app开发者在app中显示特定的settings 视图(例如, 如果没有有效的数据链接,显示 wifi设置面板)。本文主要讲述了它是如何工作的。

+
+

mozSettings API 和 Data 绑定

+

从技术上讲, Settings app 是一个向用户提供对认证 window.navigator.mozSettings API 访问的UI界面。

+

 Settings app 会自动的处理基本的系统设置操作,如绑定数据字段和  mozSettings 值 — 所有基本操作,如勾选一项设置或改变输入值将会使相关的 mozSettings 值也会改变。

+

window.navigator.mozSettings API 会从Gecko 中获取系统设置的数据。 使用方式如下所示:

+
navigator.mozSettings.createLock().set(values);
+

上面是设置数据信息。

+
+

注意: 在读或写任何 mozSettings, 我们需要使用 createLock() 方法来锁定settings。

+
+

要检索数据,我们可以使用获取或设置一个回调函数的方式启动对数据的操作:

+
var reqTimerGoBack =
+window.navigator.mozSettings.createLock().get('icc.goBackTimeout');
+reqTimerGoBack.onsuccess = function icc_getTimerGoBackSuccess() {
+  goBackTimer.timeout = reqTimerGoBack.result['icc.goBackTimeout'];
+    ...
+};
+

数据会存储在一个名为 instance.result 词典下。

+

Firefox OS 2.0 开始, mozSettings 实例可以通过 js/modules/settings_cache.js 实例被重复使用:

+
var SettingsCache = require('modules/settings_cache');
+
+SettingsCache.getSettings(function(result){
+  var onlineSupportTitle = result['support.onlinesupport.title'];
+    ...
+});
+

导航

+

当用户打开  Settings app, 在概览页面会显示多个面板,这个页面则是一个功能性的独立页面。SettingsService.navigate (js/module/settings_service.js) 则会控制这些页面间的导航。

+
+

注意: For legacy panels (which are not yet ported to the new structure), settings.currentPanel is used instead of SettingsService.navigate to navigate
+ between panels.

+
+

Since Firefox OS will support tablet devices as well as mobiles, the Settings app has two different types of navigation model implemented:

+ +

While called, SettingsService.navigate determines what navigation model to use via the following code:

+
if (_isTabletAndLandscape()) {
+  PageTransitions.twoColumn(oldPanel, newPanel, callback);
+} else {
+  PageTransitions.oneColumn(oldPanel, newPanel, callback);
+}
+

面板

+

From Firefox OS 2.0 onwards, the basic panel structure is defined in js/modules/panel.js. It defines six lifecycle stats:

+ +

All new settings panels are inherited from SettingsPanel, which extends Panel’s functionalities. The code is contained in js/modules/settings_panel.js:

+
onInit: function(panel, initOptions) {
+  ...
+
+  PanelUtils.activate(panel);
+},
+
+onBeforeShow: function(panel, beforeShowOptions) {
+  // Preset the panel every time when it is presented.
+  PanelUtils.preset(panel);
+  _addListeners(panel);
+  ...
+},
+

PanelUtils.activate — defined in js/modules/panel_utils.js — is used to parse all links in the panel and adds corresponding handlers in onInit stat, and PanelUtils.preset is used to preset elements with the settings values in the onBeforeShow stat.

+

All new settings panels are defined in the js/panels folder.

+

AMD 模块和编译时间优化

+

From Firefox OS 2.0 onwards, the Settings app uses the AMD modules pattern to implement each panel. The AMD modules are loaded via Alemeda (a lighter version of RequireJS) and built/optimized using r.js (the RequireJS optimizer). The Settings app still had dependencies on files (shared/js) which aren’t AMD modules. For those it uses the shim options defined in settings/js/config/require.js.

+

参考

+

 Settings app has a build-in README ,这个文件可以用来获取 Settings (大部分内容是由  Arthur Chen and Fred Lin 完成的)。

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html new file mode 100644 index 0000000000..853dd41fbb --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/system/index.html @@ -0,0 +1,226 @@ +--- +title: System +slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/System +translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/System +--- +
+

System app 是在 Firefox OS 启动过程 中由Gecko装载的第一个 web 应用,  它会处理许多运行系统所需要的任务,因此不会局限于某一个单独的 web 应用。 这篇文档主要是讲解 Sytem如何工作。

+
+
+

任何一个可以用 JavaScript 编写的应用, 会最终使用 JavaScript 构建的。 -- Atwood's Law

+
+
+

注意: 您可以在 Gaia Github 仓库中获取到 source code for the System app

+
+

system app 是如何启动的

+

当 Gecko 试图启动System应用时, 它会解析System's manifest.webapp 文件,并根据 launch_path 参数(该参数在Gaia应用中一般是 /index.html) 装载 index.html 文件。 要管理整个的移动系统,Sytem app需要装载很多资源文件。  

+

整个启动过程是从  bootstrap.js 中的下面代码开始的: 

+
window.addEventListener('load', function startup() {
+// define safelyLaunchFTU
+function safelyLaunchFTU() {
+  ...
+}
+
+if (Applications.ready) {
+  safelyLaunchFTU();
+} else {
+  ...
+}
+
+window.addEventListener('ftudone', function doneWithFTU() {
+  window.removeEventListener('ftudone', doneWithFTU);
+
+  var lock = window.navigator.mozSettings.createLock();
+  lock.set({
+    'gaia.system.checkForUpdates': true
+  });
+}
+
+  ...
+
+// With all important event handlers in place, we can now notify
+// Gecko that we're ready for certain system services to send us
+// messages (e.g. the radio).
+var evt = new CustomEvent('mozContentEvent',
+{ bubbles: true, cancelable: false,
+  detail: { type: 'system-message-listener-ready' } });
+  window.dispatchEvent(evt);
+}
+

这段代码是这样工作的:

+
    +
  1. System 是运行在浏览器引擎中真正的web应用, 并需要所有它依赖的资源都装载进去 — 包括 图片(images)和样式(styles)。 因此一旦 window.onload 事件触发, 我们就要开始这些工作。
  2. +
  3. 首先,我们要使用 safelyLaunchFTU() 函数准备启动首次启动体验(FTU)  。顾名思义, 只有当用户首次启动 Firefox OS 时, FTU才会出现。
  4. +
  5. 当用户在 FTU中点击 “完成” 时, 会启动 ftudone 自定义事件,  bootstrap.js 会监听和处理这个事件。
  6. +
  7. 下一步, 我们会使用 Settings API (navigator.mozSettings)  将  gaia.system.checkForUpdates 设置成 true,  表示系统会检查更新。
  8. +
  9. 最后,我们会通过 CustomEvent 运行自定义的 window.dispatchEvent。这是Gaia 使用的一个非常重要的设计模式, 用于系统消息的处理以及与Gecko层的通信。上面方法是指 Gaia System app 通知 Gecko层, 它已经准备好监听和处理事件了。 
  10. +
+

实现模块化

+

为了实现更好的模块化和灵活性,system 应用本身也在不断的改进。 从1.4 版本开始, 专门发起了一个关于 refactor the system module as instantiable object 的倡议来讨论该问题。

+

在所有上述代码运行后,每个对 bootstrap.js  中的系统组件的引用都是是如下的形式:

+
window.telephonySettings = new TelephonySettings();
+window.telephonySettings.start();
+

 TelephonySettings() 的源代码框架如下:

+
(function(exports) {
+  'use strict';
+  function TelephonySettings() {
+    this.init_param = false;
+  }
+
+  TelephonySettings.prototype = {
+    // Initialzes all settings.
+    start: function() {
+      ...
+    },
+
+    // Clean all settings.
+    stop: function() {
+      ...
+    },
+
+    1st_method: function ts_1st_method() {
+      ...
+    },
+
+    2nd_method: function ts_2nd_method() {
+      ...
+    }
+  };
+
+  exports.TelephonySettings = TelephonySettings;
+
+}(window));
+

这种模式可以帮助每个系统组件实现模块化,并使它们的可测性更强。

+

开机和关机动画

+

本部分会讲解 System app是如何控制开机动画和关机动画的。 init_logo_handler.js 和 sleep_menu.js 文件会对 system 开机动画和关机动画进行处理。

+

开机动画

+

开机动画当前并没有包含在主引导程序中,而是要借助于检查 EventListeners。

+

在 init_logo_handler.js 文件中的开机启动代码如下所示:

+

一旦Gecko准备将一些东西画在屏幕上时, 会选择 logo或者是动画。当DOM装载完成时, 我们会运行合适的系统处理程序来完成log或动画。当 ftudone 或者 ftuskip 运行时会将logo隐藏。 包含在  init_logo_handler.js 中的 _appendCarrierPowerOn 方法表示了如何通过监听DOMContentLoaded事件来启动动画或启动logo。logoLoader 方法则在 logo_loader.js 中定义。

+
var self = this;
+document.addEventListener('DOMContentLoaded', function() {
+  self.carrierLogo.appendChild(self.logoLoader.element);
+  self._setReady();
+});
+

一旦准备好 logo, 系统会调用 _setReady() 方法,  在方法中会建立一个监听器来监听特殊的 mozChromeEvent事件,这个事件会带有 system-first-paint 类型,表示系统系统已经准备好向屏幕绘图。

+
var elem = this.logoLoader.element;
+  ...
+window.addEventListener('mozChromeEvent', function startVideo(e) {
+  if (e.detail.type == 'system-first-paint') {
+    window.removeEventListener('mozChromeEvent', startVideo);
+    if (elem &amp;&amp; elem.ended === false) {
+      elem.play();
+    }
+  }
+});
+

此时图形元素开始运行。一旦启动 ftuopen 或 ftuskip 事件,  init_logo_handler.js 会调用默认的 handleEvent() 方法反过来触发 animate() 方法来以淡出的效果隐藏动画。

+
init: function ilh_init(logoLoader) {
+  window.addEventListener('ftuopen', this);
+  window.addEventListener('ftuskip', this);
+    ...
+},
+
+handleEvent: function ilh_handleEvent() {
+  this.animate();
+},
+

关机动画

+

当系统准备就绪时,长按电源(power)按键,会触发定义在 hardware_button.js 文件中的 holdsleep 事件。 hardware_button.js 文件会处理所有“物理按键点击“的事件,包括电源(休眠)键,home键,音量增/减键等。

+
HardwareButtonsSleepState.prototype.enter = function() {
+  this.timer = setTimeout(function() {
+    / * When the user holds Sleep button more than HOLD_INTERVAL. */
+    this.hardwareButtons.publish('holdsleep');
+    this.hardwareButtons.setState('base');
+  }.bind(this), this.hardwareButtons.HOLD_INTERVAL);
+};
+

关机动画是由 sleep_menu.js 处理的;这个脚本文件会监听 holdsleep 事件,并且当它触发时会显示菜单对话框。

+
init: function sm_init() {
+    ...
+  window.addEventListener('holdsleep', this.show.bind(this));
+    ...
+}
+

如果用户通过重启和关机菜单选项选择关机,会触发 startPowerOff() 方法, 它反过来会触发 LogoLoader() 函数来对关机动画进行处理。

+
handleEvent: function sm_handleEvent(evt) {
+  switch (evt.type) {
+    case 'click':
+      ...
+    this.handler(action);
+    break;
+    ...
+  }
+}
+
+handler: function sm_handler(action) {
+  switch (action) {
+    ...
+    case 'restart':
+      this.startPowerOff(true);
+      break;
+
+    case 'power':
+      this.startPowerOff(false);
+      break;
+    ...
+  }
+}
+

System 的功能

+

 System app 会负责许多功能和任务, 你可能还会对能在其职权范围内找到而惊讶。系统应用负责的范围包括:状态栏( statusbar)和 实用工具盘管理(utility tray management), SIM卡锁(SIM lock), 更新管理(update manager), 主屏幕启动(homescreen launcher),webapp 窗口管理(webapp window) 等。 本节会对System 提供的一些最重要的功能进行探究。

+

状态栏(Statusbar)和实用工具盘(utility tray)

+

系统状态栏和下拉菜单 (Gaia 通常称之为 utility tray; Android 称之为 notification bar) 是由 statusbar.js 和 utility_tray.js 来处理的。 在应用的 index.html 中,状态栏条目是在 <div id="statusbar" data-z-index-level="statusbar">  中定义的,而实用工具盘条目在下面的结构中定义:

+
<div id="utility-tray" data-z-index-level="utility-tray">
+  <div id="notifications-container">
+    ...
+  </div>
+</div>
+

实用工具盘(utility tray)中会有一些特殊的面板,如更新管理器,紧急回调管理器,存储监视通知,媒体播放通知和控制,蓝牙传输状态,按键输入法(IME)切换。与之相关联的处理程序和样式放置在  js/ 和style/ 文件夹中。

+

特殊的应用launcher

+

System app 有三个特殊的launchers,  在需要时会调用单独的web应用程序。

+ +

锁屏

+

Lockscreen app 的主要入口文件是 system/js/lockscreen.js。用户可以在这个界面解锁,启动相机以及音乐播放器。

+

紧急拨号器

+

紧急拨号器的代码是在 gaia/apps/system/emergency-call/ 文件夹下的。 它是拨号应用的简化版本,允许用户可以访问 SIM PIN unlock dialog 实现紧急拨号服务。

+

全系统(System-wide)UI

+

System应用会处理绝大多数的全系统(system-wide) UI, 其中大部分包括的是一些对话框,如音量警告对话框,SIM PIN解锁对话框,小区广播(cell broadcast)对话框,还包括一些影响窗口行为的UI元素,如 software home按键。

+

z-index level

+

在System 应用的 index.html 文件中,许多组件都带有 data-z-index-level 属性,例如

+
<div id="sleep-menu" data-z-index-level="sleep-menu">
+  ...
+</div>
+

对应 z-index-levels 定义在 system/style/zindex.css 文件中,如

+
#screen > [data-z-index-level="sleep-menu"] {
+  z-index: 65536;
+}
+
+...
+
+#screen > [data-z-index-level="app"] > .appWindow {
+  z-index: 3;
+}
+

z-index 设置是根据元素在屏幕上显示的顺序进行排列的 — 如果元素需要在视觉层次中比较高的元素数值也会较高。这就是System app在基本水平上窗口管理的方式。 

+

software home 按键

+

 software home 按键是 home按键的一种替代,会在缺少物理 home按键的情况下自动启动。例如在 Nexus 4 中。 要控制它的外观,Gecko提供了一个专有的媒体功能称为  -moz-physical-home-button, 它能够在媒体查询时使用基于硬件Home按键的外观。 如果需要,窗口管理会为 software home按键分配一些屏幕的空间。

+

在 system/style/window.css (以及许多其他的系统样式文件中), 可以看到

+
@media not all and (-moz-physical-home-button) {
+  #screen:not(.software-button-disabled) > #windows > .appWindow {
+    bottom: 5rem;
+  }
+ }
+

Home 手势 (从屏幕底部向上滑动)

+

home 手势是另外一个硬件home按键的替代;它可以在 开发者设置  中使能,而控制代码在 system/js/home_gesture.js 文件中。例如,这个手势涉及到从屏幕底部清扫,可以用来关闭应用。

+

这个手势能够在 Firefox OS 平板设备中自动使能。 而 gaia/shared/js/screen_layout.js 是专门用于检测设备是否是平板的。

+

音量警告对话框

+

在 system/js/sound_manager.js. 中包含控制音量警告对话框的代码。如果下面所有条件都满足,则会弹出音量警告对话框:

+ +

SIM PIN 解锁对话框

+

控制SIM PIN 解锁对话框的代码在 system/js/simcard_dialog.js 中 — 当Passcode lock选项使能时,对话框会在锁屏界面显示。开放的应用必须要在  manifest.webapp 中包含 telephony 权限中(System app中含有该权限)。

+
+

注意:  当手机在飞行模式时,不会显示SIM PIN 解锁对话框

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html new file mode 100644 index 0000000000..c0871e3130 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/gaia_apps/window_management/index.html @@ -0,0 +1,279 @@ +--- +title: 窗口管理(Window Management) +slug: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Window_Management +translation_of: Archive/B2G_OS/Platform/Gaia/Gaia_apps/Window_Management +--- +
+

一般来说,window manager 是应用的一部分,会在图形用户界面中控制窗口的放置和外观。本文会对Firefox OS是如何进行窗口管理的内容进行探究。

+
+

Firefox OS中, Window Management是System app的一部分,主要负责:

+ +

在深入理解上述条目的细节前,让我们来看下应用是如何在Gaia内部启动的。 

+

App在Gaia中的启动

+

app在 Firefox OS 中的启动有几种方式,例如,通过其他app的系统消息,或者在HomeScreen中点击app图标等。 

+

+

控制app开启的事件是由 Gecko引擎和 System App 处理的,下面会有详细阐述。

+

App 结构

+

所有的 Gaia webapps 都是 packaged apps,它们都是基本的zip文件,其中会包含所有的应用程序文件: HTML, CSS, JavaScript, images, manifest, 等等。每个在 Gaia 中的 web 应用都会以下面 的基本结构进行组织:  

+
+
+
apps/[app name]/
+ - js
+ - styles
+ - locales
+ - test
+ - index.html
+ - manifest.webapp
+
+
+
+

+

当一个内嵌的Gaia app 从 homescreen 启动时,Gecko 会试图打开 URL 地址 manifest://[app name].gaiamobile.org:8080, 解析对应的 manifest.webapp 文件,之后运行文件中  launch_path 指定的文件 — 在所有内嵌  webapp中都是  index.html 。index.html 文件会加载所有需要的样式和 JavaScript。

+
+

注意 : 此处有一个非正式的约定,Gaia app的主要 js 入口点一般是  [app name].jsmain.js.

+
+

App启动次序

+

启动事件会发给Gecko。一旦 Gecko 准备就绪,  system/js/app_window_factory.js 文件中的 AppwindowFactory 就会收到一个 app的 webapps-launch 事件或一个用于处理挂起消息的 open-app 事件。

+
window.addEventListener('applicationready', function appReady(e) {
+  window.removeEventListener('applicationready', appReady);
+  window.addEventListener('webapps-launch', self);
+  window.addEventListener('webapps-close', self);
+  window.addEventListener('open-app', self);
+});
+

关于 handleEvent 动作的细节, this.launch(config) 会启动一个 app window 或 activity。一旦app关闭,  Appwindow 会收到 webapps-close 事件。

+

主进程中的  launch() 方法如下:

+
var app = AppWindowManager.getApp(config.origin);
+if (app) {
+  app.reviveBrowser();
+} else if (config.origin !== homescreenLauncher.origin) {
+  new AppWindow(config);
+} else if (config.origin == homescreenLauncher.origin) {
+  homescreenLauncher.getHomescreen().ensure();
+}
+

首先,会检查 app 变量是否存在并试图到Gecko 中恢复app的运行。否则,如果是常规的app,我们会创建一个关于 app 的  AppWindow 实例。另一个特殊的情况是 homescreenLauncher — 此时我们会执行一些必要的操作。

+

AppWindow

+

Firefox OS 会使用专门的  mozBrowser API 使 web 页面看起来像一个 app。 窗口管理的核心只是使用 mozBrowser API 封装来处理 内部的 iFrames (窗口)。之所以创建这个特殊的 moz-browser 类型,主要是为了使iFrame 看起来更像一个真实的浏览器窗口。

+

AppWindow 可以创建,容纳以及管理 mozBrowser iFrame。AppWindow 可以操控所有由 mozBrowser iFrame 本身触发的 mozBrowser 事件并且还可以显示相关的UI特性。

+

App 生命周期管理

+

app整个的生命周期如下:

+ +

启动 app

+

当用户点击 homescreen 上的应用图标时,homescreen 会使用  mozApps API 来通知 Gecko 引擎打开对应的app。当Gecko 准备就绪时,它会发送一个适当的事件给 system app。

+

Killing apps

+

在下面情况下,App 将会被 kill 掉:

+ +

对于活动的应用程序而言,在关闭动画后,被 kill app 的 iFrame 就会从 DOM tree中移除。 对于不活动的应用程序,在它们被kill 后, 对应的 iframe 就会立刻移除。

+

在下面情况下,Apps 会被中断:

+ +

重启 app

+

在下面情况下, Apps 会被重启:

+ +

app是如何被渲染的

+

在启动一个app时,屏幕会分为下面几部分:

+ +

+

App 布局

+

应用 iframe 的主要容器如下:

+
<iframe id="browser2" mozallowfullscreen="true" mozbrowser="true" remote="true"...
+... src="", data-url="" data-frame-type="window" data-frame-origin="...">
+</iframe>
+

iframe 中包括:

+ +

调整 AppWindow大小

+

AppWindow 会在下面几种情况下被调整:

+ +

+

总之,屏幕的大小会受到下面要素的影响:

+ +

+

AppWindow 方向

+

app 的方向可以由每个单独的app或由系统全局控制。您可以在  manifest.webapp 中使用 orientation 属性来设置方向。例如

+
"orientation": "default",
+

您也可以使用orientation API 来锁定和解锁方向:

+
screen.mozLockOrientation([‘portrait-primary’]);
+
+screen.mozUnlockOrientation();
+

可以用下面的属性值来强制对方向进行设定:

+ +

要获取更多的细节,请参考 Screen.lockOrientation , 您也可以在 gaia/test_apps/uitest/js/API/orientation.js. 查看设定的实例。

+

+

App 可见性

+

只有当关掉屏幕时, System app 才会到后台;而正常的 app 到后台要依赖下面几个因素:

+ +
+

注意: 当父 iframe 页面非活动时,页面可见性会被继承。

+
+

在下面情况下,APP通常会在前台运行:

+ +

下面情况下,App 通常会在后台运行:

+ +

对上面的规则而言,有一些意外的情况:

+ +
+

注意: 此处的 Active app 是指当前正在前台运行的应用;而 inactive app是指挡在后台运行的应用(界面不可见)。

+
+

AppWindow 动画和过渡

+

为了让用户获得更顺畅的使用体验,Gaia 的窗口管理器(Window Manager)也会提供 app window 动画和过渡效果。

+

 AppWindow 动画和过渡效果是由下面的状态来管理的:

+ +

在调用 setDisplayedApp() 方法时,  app 会通过下图中列出的状态来启动。

+

+

在控制 Firefox OS app动画流程时,有下面几个技巧:

+ +

+

AppWindow 特定UI

+

有一些特定的 UI 元素只和特定的 app 相关,如  Browser chrome, modal dialogs, context menus, popups, 以及 error pages.

+

下面让我们来讨论下。

+

弹出框(Modal dialogs)

+

在 desktop Firefox  中,,如果您启动了浏览器开发面板, 在其中输入如  alert(), confirm()或 prompt() 等命令,就会在屏幕中心弹出一个对话框,并遮盖了下面的内容。Firefox OS 中的 modle dialogs 和这个效果是相同的。
+
+

+

快捷菜单(Context menu)对话框

+

移动开发者都会非常熟悉 快捷菜单(或长按菜单)。一般在设计app时,为了使用户能够更简便的使用 app,最常用的用户动作应该是对用户可见的。我们可以将一些无法直接放置在UI上,但又经常使用的动作放在快捷菜单中。
+
+

+

授权(Authentication) (https) 对话框

+

定义在 system/js/app_authentication_dialog.js 文件中。

+

值选择,时间,日期对话框

+

定义在 system/js/value_selector/.

+

权限对话框

+

定义在 system/js/permission_manager.jssystem/js/media_recording.js  文件。

+

特定应用

+

有些应用需要一个特殊的 appWindow 对象来处理它们包含的特定功能。其中包括:

+ +

子窗口管理

+

子窗口是由 其他 app/pages 直接或间接打开的。如:

+ +

当子窗口被正常终止时,它的父窗口应该被重新打开。有些自窗口可会也会包含其他的子窗口。父窗口与子窗口间进程优先级的管理也是一个问题。

+

视窗(Attention Window)

+

Attention Windows 用来获取用户的注意力:

+ +

当前这些 attention window 都是被强制使用的默认方向(竖向优先)。

+

委托(Trusted) UI

+

Persona 和 mozPay API 使用的时委托 UI。它们使用特定的尺寸sizing: 80% 显示。在  trusted UI 运行时Homescreen是部分显示的。
+
+

+

历史记录管理 (History Management)

+

本节我们会讲解一些可以在 Firefox 中管理历史记录的组件。

+

任务管理器

+

任务管理器 Task manager (card 视图) 可通过长按 home 按钮触发。它会显示设备上的app历史,此时可以动态的kill一个app。

+

Web activity 处理

+

内嵌 Activities 会创建一个新的引用页面为 activity 提供数据。
+
+ Window Activities 会重复使用已存在的app window 来反映 acitivity 数据。

+

边缘手势 (测试中)

+

这个测试的边缘手势动能在 Firefox 2.0+ 开发模式版本才存在,它会允许您使用手动滑动 设备的 右/左边缘来在app和web页面之间切换。

+

How is the next app to display chosen?

+ +

How is the previous app chosen?

+ +

截屏管理

+

截屏工具会被 任务管理器(卡片视图)所使用,来显示历史记录中的app。当app 关闭动画结束时, 就会获取到一个app的屏幕截图。

+

参考

+

From Browser to Browser

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html new file mode 100644 index 0000000000..6c3633a7a5 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/hacking/index.html @@ -0,0 +1,542 @@ +--- +title: Hacking Gaia +slug: Archive/B2G_OS/Platform/Gaia/Hacking +translation_of: Firefox_OS/Developing_Gaia +--- +
+

该页面是为Gaia开发者写的。如果您在寻找关于如何编译和运行Firefox OS 的信息,可以参考 Building and installing Firefox OS page .

+
+ +
+

Gaia 是web apps 的集合,并且由它组合成  Firefox OS的前端. 在Firefox OS 屏幕上看到的都是由Web技术构建的。其中包括主屏幕和所有的原生app。本文则提供了修改Gaia代码的详细说明。

+
+ +

获取源码

+ +

要获取Gaia的源码, fork us on GitHub 并且使用 git 将您fork的代码clone到本地。

+ +
$ git clone https://github.com/mozilla-b2g/gaia.git
+ +

运行Gaia

+ +

有三种方式可以运行Gaia,分别是在桌面,火狐浏览器或者兼容的移动设备。

+ +

B2G 桌面

+ +

B2G 桌面是在Firefox OS设备上运行应用程序的桌面版本,您可以使用它在电脑桌面上运行Gaia。

+ +

您可以从Firefox Nightly站点上下载B2G桌面的nightly版本。其中有关于Linux (32位 and 64 位), Mac OS X 以及 Windows的版本.

+ +

Nightly 版本都会对近期的gaia版本打包。一旦您下载完成压缩包,只需要解压到文件夹中,并从解压到的文件夹中运行b2g二进制文件就可以了。 

+ +
$ cd b2g
+$ ./b2g
+ +

如果您出于开发的目的来运行带有指定版本Gaia的B2G, 则需要从您clone的代码位置构建一个配置文件:

+ +
$ cd /path/to/gaia
+$ DEBUG=1 DESKTOP=0 make
+ +

上面的命令会在gaia 生成一个名称为profile的文件夹。 DEBUG选项会将 Gaia 作为托管的应用在内置的Web服务器上运行,而不是在每次更改后都需要重新打包的原生应用。在运行上面的命令后,您可以在最后的输出行中找到配置文件夹的路径,大体是 

+ +
Profile Ready: please run [b2g|firefox] -profile /path/to/gaia/profile
+ +

之后则可以指定配置文件来运行B2G。

+ +
$ ./b2g /path/to/gaia/profile
+ +

您用可以从源码中编译出自身的B2G桌面。

+ +
+

注意 : 在 Mac OS X,  b2g 二进制文件会存在于 B2G.app.您需要运行下面命令:

+ +

./B2G.app/Contents/MacOS/b2g /path/to/gaia/profile

+
+ +

在Firefox中运行Gaia

+ +

也可以在Firefox内部运行Gaia。这种方式会让您的开发周期大大缩短,同时也可以使用标准的web开发工具和调试器。 可以参考Gaia开发快速指南 获取更多的信息.

+ +

在设备上运行Gaia

+ +

如果您有一个兼容的移动设备,也可以使用Firefox OS 烧机来运行Gaia。您可以参考编译和安装Firefox OS 获取更多信息. 我们也有关于如何测试Firefox OS的文章。

+ +

单元测试

+ +

参考Gaia单元测试  来获取如何创建和在Gaia层运行单元测试的文章。

+ +

提交bug

+ +

在Bugzilla的 Firefox OS > Gaia 中提交bug。在Gaia组件  (或者是子组件)中提交bug.

+ +

为 Gaia做贡献

+ +

Mozilla依赖开源社区的贡献,以帮助开发Gaia应用,我们也希望您能参与进来。

+ +

我们可以从一些非常好的网址来发现一些bug:

+ + + +

编码风格基本知识

+ + + +

Additional rules

+ +

Bad:

+ +
if (expression) doSomething();
+
+ +

Correct:

+ +
if (expression) {
+  doSomething();
+}
+
+ +

If you're working on the system app, check out the guidance listed here.

+ +

Before submitting a patch we recommend you run gjslint on it to check for any style errors:

+ +
gjslint --nojsdoc my_file.js
+ +

提交一个 patch

+ +

First file or assign a bug to yourself on Bugzilla, you'll need a Bugzilla account.

+ +

Then create a branch on your fork of Gaia:

+ +
$ git branch branchname
+$ git checkout branchname
+ +

Commit your changes:

+ +
$ git add /file/to/add
+$ git commit -m "Bug XXXXX - Fix the broken Gaia and save the world"
+ +

Push your branch:

+ +
$ git push origin branchname
+ +

Send a pull request by navigating to the branch in your fork on GitHub and finding the pull request button.

+ +
+

Note: Except under unusual circumstances, patches should be landing first on the master branch, not a release branch like v1-train, v1.3, etc. If they need to land on a release branch, they must go through the usual approval process as outlined on the B2G Landing wiki page.

+
+ +

To request a review of your patch, attach the pull request to the bug in Bugzilla by referencing the URL of the pull request, and set the review ("r") flag to "?" and enter the bugzilla ID of one of the module owners and peers (very important - otherwise your bug will not likely be seen by anyone). The Github tweaks for bugzilla extension on AMO can help automate this process by automatically creating the attachment and adding it to the bug; you will still need to set the review flag on Bugzilla.

+ +

The reviewer may ask you to make some changes; you may need to amend the original commit and force push it to the original branch/pull request. Once they're happy with your patch, they will merge it into the master branch for you. Before they do this they would prefer it if you could squash all your changes into a single commit, so your contribution can be tracked easily.

+ +

The person who merges the commit (usually the reviewer) would add a r= flag in the comment of the merge commit.

+ +

Make 选项

+ +

you use the make command inside the Gaia repo to create a Gaia profile that can be loaded onto your device or run in a B2G Desktop build. This section looks in detail at the different make options available.

+ +

There are many environment variables present in the Makefile. Do not depend on them as they may be removed in the future.

+ +

Created profiles are stored in /gaia/profile, and contain the following items:

+ + + +
+

Note: When you've already made a profile and you want to build a new one, you must delete the existing profile directory before trying to generate a new one.

+
+ +

Default

+ +
make
+ +

This simply gives you an unbranded, non-debug build. For a branded build build you need to use Official Mozilla branding make; for a debug build you need Debug make.

+ +

推送到设备端

+ +
make install-gaia
+
+make reset-gaia
+
+ +

With ADB (Android Debug Bridge) setup, these make targets will push Gaia to the device. install-gaia will just push updates of Gaia from your working directory to your device. reset-gaia will purge all existing configuration, profiles, web apps and database entries (a new settings database will be initialized) before pushing Gaia.

+ +

编译特定的应用

+ +
APP=system make
+
+APP=system make install-gaia
+ +

When a profile already exists, APP allows you to specify which app to re-package, instead of re-packing and re-pushing all the Gaia apps.

+ +

指定自定义的配置文件夹

+ +

You can specify a custom directory to build your profile in, using PROFILE_FOLDER, for example:

+ +
PROFILE_FOLDER=profile-b2g-desktop make
+ +

不同设备的编译

+ +

There are a few make options that create builds for different devices, with different purposes.

+ +

Create a phone build of Gaia

+ +
GAIA_DEVICE_TYPE=phone make
+ +

This build gets apps from /gaia/build/config/phone/apps-engineering.list.

+ +

Create a tablet build of Gaia

+ +
GAIA_DEVICE_TYPE=tablet make
+ +

This build gets apps from /gaia/build/config/phone/apps-engineering.list.

+ +

不同类型的编译

+ +

There are a few make options that create different types of build, with different purposes.

+ +

Production make

+ +
PRODUCTION=1 make
+ +

This creates a production build of Gaia:

+ + + +
+

Note: You can also use the alias make production.

+
+ +

Debug make

+ +
DEBUG=1 make
+ +

The DEBUG variable runs Gaia as hosted apps on a built-in web server on a specific GAIA_PORT, rather than the default of packaged apps which have to be re-packaged after every change; this makes things easier to test. Launching the profile with the latest Firefox Nightly will also give you nice B2G specific panels on the Firefox Developer Tools.

+ +

In addition:

+ + + +

Device debug make

+ +
DEVICE_DEBUG=1 make
+ +

This disables screen lock on the device, and enables debugging with the ADB tool, so is useful for device debugging.

+ +

In Firefox OS version > 1.2, specify this param when you want to debug Firefox OS webapps with the App Manager.

+ +

Debug desktop make

+ +
DEBUG=1 DESKTOP=0 make
+ +

This option creates a desktop debug version, for running inside B2G desktop.

+ +

Official Mozilla branding make

+ +
MOZILLA_OFFICIAL=1 make
+ +

Use this to make an official Mozilla-branded build.

+ +

Dogfood make

+ +
DOGFOOD=1 make
+ +

Dogfooding options and utilities are turned on, for example the Feedback app, which allows doog fooders to easily submit feedback on the OS.

+ +

System apps make

+ +
B2G_SYSTEM_APPS=1 make
+ +

This environment variable lets you push an app to /system/b2g instead of /data/local. You should use this when you work with a user build. This variable is automatically set when running make production. This can be used for install-gaia or reset-gaia too.

+ +

Distribution and market customization build

+ +
GAIA_DISTRIBUTION_DIR=./dir
+ +
+

Note: Read Market Customizations for more details.

+
+ +

开发/调试选项

+ +

There are also make options for adding/removing features or changing settings, for debugging purposes.

+ +

Enable remote debugging

+ +
REMOTE_DEBUGGER=1
+ +

This enables remote debugging on the device, the same as using the option in the developer settings.

+ +

JavaScript optimization make

+ +
GAIA_OPTIMIZE=1 make
+ +

This triggers an optimization pass on Gaia's JavaScript, concatenating/compressing the files. This is automatically set when running make production. This can be used for install-gaia or reset-gaia too.

+ +

High resolution image assets

+ +
GAIA_DEV_PIXELS_PER_PX=1.5 make
+ +

When packaging the app, this option replaces images with their *@1.5x.(gif|jpg|png) equivalents if such images exist. You need to use the above option as part of a standard make command, for example:

+ +
GAIA_DEV_PIXELS_PER_PX=1.5 make reset-gaia
+
+GAIA_DEV_PIXELS_PER_PX=1.5 make install-gaia
+ +

Gaia is currently targetting the following screen resolutions:

+ + + +

use GAIA_DEV_PIXELS_PER_PX to make sure the images looks sharp on qHD and WVGA devices. see A pixel is not a pixel for more information about device pixels per css pixels.

+ +

Haida features

+ +
HAIDA=1 make reset-gaia
+ +

This build enables the Haida feature set, which is currently limited to rocketbar and edge gestures, but will likely include other features in the near future.

+ +

Disable first time use experience (FTU)

+ +
NOFTU=1
+
+ +

Disable the FTU with this environment variable.

+ +

Disable lockscreen

+ +

You can disable the Firefox OS lockscreen using the NO_LOCK_SCREEN option, for example:

+ +
NO_LOCK_SCREEN=1 make
+ +

Reference Workloads

+ +

Reference workloads allow developers/testers to quickly install a large amount of data in several applications, typically on a newly-flashed phone.

+ +

The commands are (from the gaia directory):

+ +
make reference-workload-light
+ + + +
make reference-workload-medium
+ + + +
make reference-workload-heavy
+ + + +
make reference-workload-x-heavy
+ + + +

These targets accept the APP environment variable, or an APPS environment variable that should contain the app names separated by a space, e.g.:

+ +
APP=sms make reference-workload-light
+APPS="sms communications/contacts" make reference-workload-heavy
+
+ +

The apps available are:

+ +
APPS="gallery music video communications/contacts sms communications/dialer"
+ +

In order to install music (songs) with reference workloads, the utility mid3v2 must be installed. This utility can be installed with:

+ +
sudo apt-get install python-mutagen
+ +

If you run Fedora or RHEL instead, use:

+ +
sudo yum install python-mutagen
+ +

Documentation make

+ +

Gaia docs can be built, via jsdoc3. To generate these, you can use the following command:

+ +
make docs
+ +

Enabling IME layout and dictionaries

+ +

To enable keyboard IME layout and dictionaries enabled, use following command structure:

+ +
GAIA_KEYBOARD_LAYOUTS=en,zh-Hant-Zhuyin,el,de,fr,zh-Hans-Pinyin make
+ +

自定义 build-time 应用

+ +

The apps that run on Firefox OS are all contained within the Gaia source tree, in one of two locations:

+ + + +
+

Note: If you are building B2G rather than Gaia, the paths will of course have B2G/ on the front, e.g. B2G/gaia/apps and B2G/gaia/external-apps.

+
+ +

If you want to omit some of these apps from your build of Gaia/B2G, you can do this in a few different ways:

+ +
    +
  1. +

    The "brute force" method is to simply delete the apps you don't want to be present at build time, before building.

    +
  2. +
  3. +

    The more refined method is to edit the gaia/build/config/apps-*.list files to include the paths to the apps you want to include at build time. For example, gaia/build/config/apps-production.list looks something like this:

    + +
    apps/*
    +external-apps/*
    +outoftree_apps/*
    + +

    But you could also include specific apps rather than just picking them all, for example:

    + +
    apps/clock
    + +

    The mechanism for choosing which apps-*.list file is used during the build to determine the available apps is contained inside gaia/Makefile:

    + +
    GAIA_APP_TARGET?=engineering
    +...
    +ifeq ($(MAKECMDGOALS), demo)
    +GAIA_DOMAIN=thisdomaindoesnotexist.org
    +GAIA_APP_TARGET=demo
    +else ifeq ($(MAKECMDGOALS), dogfood)
    +DOGFOOD=1
    +else ifeq ($(MAKECMDGOALS), production)
    +PRODUCTION=1
    +endif
    +...
    +ifeq ($(PRODUCTION), 1)
    +GAIA_OPTIMIZE=1
    +GAIA_APP_TARGET=production
    +endif
    +
    +ifeq ($(DOGFOOD), 1)
    +GAIA_APP_TARGET=dogfood
    +endif
    +...
    +ifndef GAIA_APP_CONFIG
    +GAIA_APP_CONFIG=build$(SEP)config$(SEP)apps-$(GAIA_APP_TARGET).list
    +endif
    + +

    Initially, the GAIA_APP_TARGET variable is set to engineering, so by default building gaia from source will use app-engineering.list (which includes all the tests, demos, etc.):

    + +
    make
    +
    + +

    To specify usage of a different apps list you specify different options when running the make command. To build with apps-production.list, for example, you'd use

    + +
    PRODUCTION=1 make
    + +
      +
    • If you specifically build with DEMO=1 specified, then it will use apps-demo.list.
    • +
    • If you specifically build with DOGFOOD=1 specified, then it will use apps-dogfood.list.
    • +
    • You can completely override the decision by using GAIA_APP_CONFIG and providing your own apps-*.list file.
    • +
    + +

    gaia/Android.mk contains these lines:

    + +
    ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
    +GAIA_MAKE_FLAGS += PRODUCTION=1
    +B2G_SYSTEM_APPS := 1
    +endif
    + +

    When you build, if VARIANT=user or VARIANT=userdebug are set (these wind up getting reflected in the TARGET_BUILD_VARIANT variable), PRODUCTION=1 is automatically set when building gaia.

    +
  4. +
  5. +

    The third, and most refined (but most complex) method is to use customizations. These allow you to specify build-time customization instructions in separate difrectories, without modifying the core Gaia repo. You can include your own customizations in distinct directories, or use the preexisting directories that come with the source.

    + +

    For example, the basic Firefox tablet customized app list is defined in apps.list under the distribution_tablet folder (gaia/distribution_tablet). These customizations can be applied at build time using options like this:

    + +
    GAIA_DISTRIBUTION_DIR=distribution_tablet make
    + +
    +

    Note: Customizations is its own separate topic entirely. To learn more about it, read Market Customizations.

    +
    + +
    +

    Note: If you want to include custom external apps as part of your Gaia build, you need to build them in a specific way, and then place them into the gaia/external-apps/ folder. Read Building Prebundled web apps to find out how.

    +
    +
  6. +
+ +
+

Important: If you are a device vendor creating a custom B2G/Gaia build for distribution, you need to satisfy certain criteria before you are allowed to include the Firefox Marketplace app on your phones/tablets/etc. Contact Mozilla for more details.

+
+ +

联系小组

+ + diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/index.html new file mode 100644 index 0000000000..698c63da42 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/index.html @@ -0,0 +1,72 @@ +--- +title: Gaia +slug: Archive/B2G_OS/Platform/Gaia +translation_of: Archive/B2G_OS/Platform/Gaia +--- +

Gaia是Firefox OS的用户界面层.在Firefox OS启动之后,显示在屏幕上的一切东西都是由Gaia绘制出来的,包括锁屏,主屏幕,拨号界面,以及其他的应用程序.Gaia完全是由HTML,CSS,和JavaScript编写的.它和底层的操作系统以及硬件进行交互是通过标准的Web API来完成的,这些API是由Gecko实现的.

+

正因为这样的设计,Gaia不仅能直接运行在Firefox OS设备上,还能运行在其他的操作系统以及其他的web浏览器中.

+

和Gaia一起安装在设备上的第三方应用程序也可以由Gaia来启动.

+ + + + + + + +
+

Gaia的相关文档

+
+
+ 介绍Gaia
+
+ Gaia是Firefox OS设备上使用的用户界面应用程序,它仅仅是一个运行在Firefox OS软件栈上的Web应用程序.本指南会详细的介绍Gaia.
+
+
+
+ Gaia应用
+
+ 对Gaia中可获得的默认应用进行介绍,包括如何使用和修改它们。
+
+ Gaia hacking 指南
+
+ 关于hacking和修改Gaia接口的指南。
+
+ Gaia系统构建入门
+
+ 在Gaia build子文件夹下由脚本执行的绝大多数有意以的构建步骤。
+
+ Gaia Hacking提示和常见问题 
+
+ 关于hacking Gaia的一些有用的提示以及常见问题。
+
+

查看更多...

+
+

到社区寻求帮助

+

如果你的工作需要和Gaia打交道,或者正在开发一个Gaia应用程序,有相关的社区资源可以帮助你!

+ +
    +
  • 在Mozilla的Gaia IRC频道上提出你的问题: #gaia
  • +
+

不要忘记"提问的艺术"...

+
+ + +

资源

+ +
+

 

diff --git a/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html b/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html new file mode 100644 index 0000000000..562cb61765 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gaia/introduction_to_gaia/index.html @@ -0,0 +1,28 @@ +--- +title: Gaia简介 +slug: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia +tags: + - Apps + - B2G + - Gaia + - Settings +translation_of: Archive/B2G_OS/Platform/Gaia/Introduction_to_Gaia +--- +
+
+ Gaia 是Boot to Gecko (B2G) 的用户界面; 它是一个web应用的集合,可以本地运行在B2G设备,仿真器,桌面版本或firefox版本上。添加app或规Gaia更改时使用的web技术都是 JavaScriptHTML,和 CSS.
+

 Gaia 锁屏界面

+

锁屏界面会显示网络运营商,当前时间和日期,和一个滑动条可用来解锁手机或直接进入相机拍照。  如果用户有密码锁定设置,锁屏界面会显示一个密码输入窗口。

+

+

注意一些设备默认是使能密码锁定的;这种情况下,默认的解锁PIN码是  "0000"。该功能后续可能会有所改变。

+

默认的Gaia接口

+

Gaia的默认界面,如下图所示,与您在绝大多数智能手机上看到界面是非常相似的。

+

+

这张图片显然是一个预发布版本的操作系统,其中还带有占位符图标和一些测试应用。界面顶端的状态栏放置了一些状态标识,包括当前手机选择的网络运营商(或者没有SIM卡),SIM卡信号强度,WIFI信号强度,电池点亮以及当前时间。

+

界面中间区域显示了应用的图标,滑动屏幕可查看各界面的图标。您可以在Gaia apps 一文中获取更多关于 Gaia 默认 app集合的信息。 

+

屏幕的最下方是是一个快速启动栏,一般会放置一些您最常用到的应用。您也可已从快速启动栏拖动一个app图标到中间的区域。

+

参考

+ diff --git "a/files/zh-cn/archive/b2g_os/platform/gaia/weinre\350\277\234\347\250\213\350\260\203\350\257\225\345\267\245\345\205\267/index.html" "b/files/zh-cn/archive/b2g_os/platform/gaia/weinre\350\277\234\347\250\213\350\260\203\350\257\225\345\267\245\345\205\267/index.html" new file mode 100644 index 0000000000..213a8defb1 --- /dev/null +++ "b/files/zh-cn/archive/b2g_os/platform/gaia/weinre\350\277\234\347\250\213\350\260\203\350\257\225\345\267\245\345\205\267/index.html" @@ -0,0 +1,105 @@ +--- +title: Weinre 远程调试工具 +slug: Archive/B2G_OS/Platform/Gaia/Weinre远程调试工具 +tags: + - weinre +translation_of: Tools/Remote_Debugging +--- +

Weinre 是Apache基础工程之一,是 WEb INspector REmote 的缩写。正如其名,它是和 Firebug 或浏览器调试工具类似,但是能够在远程运行调试web页面。所以如果你使用过火狐开发者工具或Chrome的调试工具,那么上手Weinre就会非常容易,非常自然。

+ +

安装 Weinre

+ +

因为 Weinre 运行在 Node.js 的基础上, your first port of call would be to 安装 Node.js. Node.js comes with NPM (Node Package Manager) bundled nowadays and this is what we are going to use to install Weinre. From a terminal run the following:

+ +
npm -g install weinre
+ +
+

NOTE: The -g flag is used to install Weinre as a global Node.js module for command line goodness but, on Linux and Mac, this means you most likely are going to need to run the above by prepending sudo to the above command.

+
+ +

Once the installation process is complete, we are ready to use Weinre to debug.

+ +

启动 Weinre 服务

+ +

On the terminal enter the following line to start up the Weinre server:

+ +
$ weinre --boundHost 127.0.0.1 --httpPort 9090
+ +

The two parameters passed here are the host to bind to and the port the server should listen on. Once the server has started the terminal should display a line similar to the following:

+ +
2013-01-28T10:42:40.498Z weinre: starting server at http://127.0.0.1:9090
+ +

With that, fire up a browser (NOTE: The UI for Weinre is built specifically for Webkit based browsers so, while it might work to some degree in other browsers, I would suggest you use Chrome) and point it to http://127.0.0.1:9090. Once the landing page loads, click on the link to the debug client user interface. From this portion of the UI you can see connected clients, initially one which is the current instance of the web inspector, some general properties of our server, and your targets.

+ +

设置 Weinre 目标页面

+ +

In Weinre targets are the web pages or apps that you want to debug, and in order for the target to be able to connect, you need to add a one liner to the relevant file of your app. For example, if you wanted to use Weinre to debug the Calendar app in Gaia you would open gaia -> apps -> calendar -> index.html and right before the clong body tag, add the following:

+ +
<script src="http://127.0.0.1:9090/target/target-script-min.js#anonymous"></script>
+ +

Normally that would be all you need to do to set up your target, but for FirefoxOS there is one more step. Gaia uses a Content Security Policy and as part of that, scripts are said to only be allowed to load if from the same origin as the application. So, if we were to try and load the Calendar now, the script from above would be blocked as it is not being loaded from the specified origin.

+ +

To overcome this, we need to temporarily disable CSP. To do this, open up gaia -> build -> preferences.js and add the following line, around line 24:

+ +
prefs.push(["security.csp.enable", false]);
+ +

使用 Weinre 和 B2G Desktop 进行调试

+ +

The first step we need before launching the desktop is to build our Gaia profile:

+ +
DEBUG=1 make
+ +

Once the profile is built, launch B2G desktop:

+ +
+
/Applications/B2G.app/Contents/MacOS/b2g-bin -profile /Users/username/mozilla/projects/gaia/profile
+
+ +

Once B2G launches, unlock the screen and navigate to the Calendar app. Tap the app icon and keep an eye on the Weinre debug client UI. Once the app has launched you should see a target being added. Next we want to start inspecting our code, so click on the 'Elements' tab to open up the HTML and CSS inspector. You can go right ahead and edit either the HTML or the CSS as you normally would and see the changes reflected live. Note that even though the CSS looks grayed out and disabled, it is fully editable. You can also add completely new styles to the current element using the empty element.style block or amending existing rules. You will also notice you have access to the computed styles as well as metrics of the current element.

+ +

使用控制台工作

+ +

The next tab of interest to us is the Console tab. Here you can code away and run any JavaScript you want directly against the current app or execute code exposed by the app. In order to demonstrate the console, we will target the Call Log portion of the dialer and interact with the records stored there. First step then is to move your script src to the Dialer which is located at gaia -> apps – > communication -> dialer -> index.html.

+ +

After it is added, build your profile, launch B2G, and then launch the Dialer. With the Dialer open, click on the call log icon, bottom left. Currently the call log is already populated with some dummy data, but let’s create our own. Click over to the Console tab in Weinre, type the following, and press enter.

+ +
RecentsDBManager.deleteAll();
+ +

To see that our code was executed and worked, we need to refresh the call log:

+ +
Recents.refresh();
+ +

As you can see, our call log is empty. Next step then is to add an entry back. To do this, we will create a dummy call entry Object and then pass this to the add function of the RecentsDBManager to store it:

+ +
// Dummy entry
+var recentCall = {
+    type: 'incoming-refused',
+    number: '555-6677',
+    date: new Date()
+};
+RecentsDBManager.add(recentCall);
+Recents.refresh();
+ +

And as you can see now, the entry we just created has been added to storage, IndexedDB to be exact, and is visible in the call log view. As you might very well have noticed, another of the great features that comes with the console is auto-complete which will further speed up development.

+ +

在移动设备上调试

+ +

The above has focused on using Weinre and B2G desktop, but the process to use Weinre to inspect and debug your code running on a device is exactly the same except for the IP address you will be using. When you want to debug on the device you first need to know the IP address of your host computer. Then you need to start up Weinre using this IP as the boundHost and also as the IP when including the script into your target documents.

+ +
+

On Mac and Linux you can get this address using ifconfig and on Windows it is ipconfig.

+
+ +

Once you have the new IP, just stop the current instance of Weinre and then do the following:

+ +
weinre --boundHost 192.168.1.1 --httpPort 9090
+ +

Then inside your target document add:

+ +
<script src="http://192.168.1.1:9090/target/target-script-min.js#anonymous"></script>
+ +

Make and push your Gaia profile to the device using:

+ +
make install-gaia
+ +

Launch your target app and you are in business!

diff --git a/files/zh-cn/archive/b2g_os/platform/gonk/index.html b/files/zh-cn/archive/b2g_os/platform/gonk/index.html new file mode 100644 index 0000000000..63d02ef70a --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/gonk/index.html @@ -0,0 +1,98 @@ +--- +title: Gonk +slug: Archive/B2G_OS/Platform/Gonk +translation_of: Archive/B2G_OS/Platform/Gonk +--- +
+

Gonk 是 Firefox OS 平台底层的操作系统, 包括基于  Android Open Source Project (AOSP) 的 Linux Kernel 和用户空间硬件抽象层 (HAL) 。本文旨在介绍Gonk的组成;要获取更多有关 Firefox OS 架构和 Gonk 如何在其中适配的知识,请参考 Firefox OS architecture 指南。

+
+ +

Gonk overview

+ +

Gonk 在 Firefox OS stack 中可看作是 kernel 层级的组件,在 Gecko 和 底层硬件中间充当接口的作用。Gonk 对底层的硬件进行控制,并且将硬件信息及操控接口暴露给 Gecko中的 Web APIs。Gonk 可以看作是一个 黑盒, 在屏幕后面做了所有复杂细节的工作用于在硬件层级上对 mobile device 进行控制。

+ +

Gonk 只是一个简单的 Linux 发行版本,其中包括了 Android 的一些组件(如 GPS 和 Camera)以及由  Mozilla 扩展的常用的开源工程,如 libusb, bluez, 进而将所有的层级集成到 Firefox OS 架构中。这种设计方式对 OEM 将软件组件从其他 Android 实现上移植过来是非常方便的。

+ +

Gonk 是一个设备接口层,可看作是 硬件和 Gecko 之间的适配器。 Gonk is a relatively simple Linux distribution that can be treated as a Gecko Port paired with Gecko porting layers — so Gonk is a porting target of Gecko, just like there's a port of Gecko to OS X, Windows, and Android.

+ +
+

Note: Since different mobile devices may have different chipsets and other hardware specs, devices may contain different Gonk distributions.

+
+ +

由于 Firefox OS 工程对 Gonk 的完整控制,我们可以向 Gecko 中暴露一些在其他操作系统中无法实现的接口。例如, Gecko 已经可以直接对 full telephone stack 直接进行发给男问,并在 Gonk 中显示出 frame buffer。

+ +

Gonk 架构

+ +

Each mobile phone model has a specialized combination of Gonk components based on the system libraries, device drivers, and firmware required to operate the device. These components are determined by the OEM in collaboration with chipset manufacturers and ODMs. The following figure shows an example Gonk implementation:

+ +

+ +

This example shows the following main components (which represent only a subset of the possible components in any given Gonk implementation):

+ + + +

Gonk 也会启动,管理以及关闭 b2g process, b2g process 属于 Firefox OS 的 Gecko 层。The b2g process acts as a client to service-level daemons in Gonk that interact directly with the hardware and expose to Gecko the underlying hardware functionality of the phone. Gecko talks with these daemons via inter-process communication (IPC). These components collaboratively exchange commands and protocols to request and provide services.

+ +
+

Note: For more information on Gonk architecture, see the Firefox OS architecture guide.

+
+ +

Porting Gonk

+ +

Because Firefox OS is based on the Android kernel, existing device drivers, firmware, service daemons, and other components can be ported to work with Firefox OS, usually with minimal effort. If a custom component (for example, a custom RIL or new daemon) is needed, or if a modification must be made to an ODM’s reference design, then additional integration and testing effort might be required.

+ +

In b2g, clients communicate with service-level daemons via inter-process communication (IPC). The client initiates a socket connection to the service-level daemon, submits the request (using the server’s request protocol) over that connection, receives the response, and closes the connection. OEMs are responsible for designing and implementing this inter-process communication between clients and servers.

+ +
+

Note: For more information about how the porting process works, see Porting Firefox OS.

+
+ +

How Mozilla works on Gonk ports with OEMs and phone manufacturers

+ +

Every Gonk implementation is the result of collaboration among Mozilla, OEMs, and associated manufacturers (ODMs, chipset manufacturers).

+ +

Mozilla provides source repositories and support files for Gonk in its Firefox OS distributions. The source repositories include the base Linux kernel (with only slight changes) and hooks into Gecko.

+ +

OEMs are responsible for building, compiling, testing, certifying, and distributing the Firefox OS system image for a given device model. For the Gonk portion of the system image, OEMs are responsible for the bulk of the effort in order to ensure the seamless integration between Web API calls and phone hardware functionality. The type and scope of effort required is highly dependent on the specific chipsets and other hardware components used on the phone.

+ +

Device components

+ +

OEMs collaborate with chipset manufacturers and ODMs to provide all of the device-specific components that are needed to run the mobile device. For example, a manufacturer of the Wi-Fi components would provide the chipset and affiliated software. Components might include:

+ + + +

Integration between Gonk and Gecko

+ +

OEMs must ensure that hardware capabilities in the mobile device are correctly and completely exposed to the Web APIs implemented in Gecko. This involves:

+ + + +

Gonk 源代码

+ +

The main B2G repo on Github contains officially supported Gonk ports for a variety of devices, so you can treat it as Gonk’s repository. The list of supported devices is available in B2G/config.sh.

+ +

The b2g process (along with other things), defined in Gonk, can be found at mozilla-b2g/gonk-misc. Modifications to b2g source code are made here.

+ +
+

Note: In the Gecko source there’s a b2g/ folder that contains the Gonk Port of Gecko: this consists of a Linux kernel, HAL, and other OEM-specific libraries.

+
+ +

Gonk 层每天的工作主要集中在 porting system 到不同的板子上,并且确保 Gecko 在不同的设备上能够正常工作。

diff --git a/files/zh-cn/archive/b2g_os/platform/index.html b/files/zh-cn/archive/b2g_os/platform/index.html new file mode 100644 index 0000000000..3f256549c6 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/index.html @@ -0,0 +1,87 @@ +--- +title: Firefox OS 平台 +slug: Archive/B2G_OS/Platform +tags: + - B2G + - Firefox OS + - NeedsTranslation + - TopicStub +translation_of: Archive/B2G_OS/Platform +--- +

FireFox OS 平台包括很多组件。为了构建能够在FF OS中运行的应用,你不需要理解系统内部架构,如果你将要在该平台构建应用程序或者只是简单的好奇,你可能对以下文档感兴趣。

+ + + + + + + + +
+

关于Firefox OS 平台的文件

+ +
+
介绍 Firefox OS
+
关于 OS 如何运作
+
搭建安装 Firefox OS
+
Firefox OS 安装指南。也是在Pc搭建Firefox OS虚拟机指南
+
Gaia
+
FireFox OS 顶层文档
+
Gonk
+
关于Gonk的文档, Gonk比Gaia在操作系统中更加底层, 由Linux内核和Gecko调用的硬件抽象层组成. 
+
Gecko
+
Gecko在Firefox OS为提供标准的开放web标准实现, 像被Firefox和Thunderbird等等许多其他的应用运用着. 
+
图表支持特性                                                                                                                                                               
+
用一张图表就可以把所有Firefox OS编译的类型哪些可用的展现出来. 
+
Firefox OS 架构概述
+
对Firefox OS 架构的概述. 
+
Firefox OS 测试
+
一个Firefox OS的测试指南, 包含如何创建自动化测试. 
+
Firefox OS 端口设置
+
关于Firefox OS在新设备中的端口设置. 
+
.userconfig 文件的配置
+
如何配置Firefox OS的编译和执行通过修改.userconfig文件. 
+
+ +

View All...

+
+

从社区获得帮助

+ +

以下资源助你开发火狐应用

+ + + +
    +
  • Ask your question on Mozilla's Boot to Gecko IRC channel: #b2g
  • +
+ +

Don't forget about the netiquette...

+ + + + + + +

Resources

+ + +
+ +

 

diff --git a/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html b/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html new file mode 100644 index 0000000000..eda111fbc8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/out_of_memory_management_on_firefox_os/index.html @@ -0,0 +1,80 @@ +--- +title: Firefox OS 中的内存溢出管理 +slug: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS +tags: + - B2G + - Firefox OS + - Gaia + - LMK + - OOM + - Out of memory + - oom_adj + - 低内存管理器 + - 低内存通知器 +translation_of: Archive/B2G_OS/Platform/Out_of_memory_management_on_Firefox_OS +--- +
+

Firefox OS 运行在一些严重内存受限的设备上时,就会很容易出现app在运行时将内存耗尽的情况。当一个进程将系统上可用的内存耗尽时, 为了能够释放内存,kernel 层必须要 kill 掉其他的进程。本文则描述了低内存 killer和 低内存通知器是如何工作的 。

+
+ +

FxOS 的操作会涉及到多进程问题—一个“主进程”运行基本的系统服务和潜在众多的“子进程”。FxOS 环境下应用很少会由用户主动关闭,因此当新的 app需要空间或已存在的 app需要额外的内存时, system会自动对应用程序的生命周期进行管理。

+ +

有两个子系统负责这方面的管理:  低内存管理器 Low memory killer (LMK) 和低内存通知器Low memory notifications.

+ +

低内存管理器 Low memory killer

+ +

 LMK 是 Android 内核的子系统,当有获取内存空间的需求时,能够自动的对进程进行查杀。为了能够选择出哪一个进程需要第一个查杀,每个进程都要通过 /proc/<pid>/oom_adj or /proc/<pid>/oom_score_adj files 来设定一个优先级。 每个进程的优先级也可称为调整分数或 oom_adj.  oom_adj ,值越小则表示器进程优先级越高。

+ +

一般来说,进程的调整得分越高,越可能被查杀。 LMK 提供了多个等级,每一个都与一定程度的闲置内存和最小调整分数对应。当闲置内存的数量低于某个特定等级时,所有高于该等级指定的最小调整分数的进程都具有被查杀的可能。LMK会开始查杀这些进程,分数高的会被先杀掉,直到闲置内存再次高于临界值为止。

+ +

Note: When a background app is killed by the LMK, it is made available in the task manager/through edge swipes as a "zombie app": next time you browse to that app, it will be revived. The maximum number of apps that can be kept in this state is currently 10.

+ +
+

注意: 当设备存储器不足(oom) 时杀掉的进程并不一定是导致存储器不足(oom)的原因。

+
+ +

进程优先级

+ +

Firefox OS 中的 app 是以下面的优先级次序策略来管理的,这种策略是根据每个应用的优先级等级和这些等级相关的 OOM 调整分数 (the current values are set in prefs)而制定的: 

+ +
    +
  1. 后台应用会首先被干掉,先从使用最少的应用开始
  2. +
  3. 之后会干掉 homescreen 应用程序
  4. +
  5. 可由用户感知的后台应用会被干掉 (例如, 在后台播放音频的音乐播放器或者持有  high-priority 或 cpu wakelock,并且注册系统消息的处理程序)
  6. +
  7. 如果 keyboard 应用正在运行,会被干掉
  8. +
  9. 前台应用被干掉
  10. +
  11. 最后,已请求  high-priority 或 cpu wakelocks 的前台应用会最后被干掉
  12. +
+ +
+

注意: 当子进程在前台时,会以  oom_adj 2 运行。后台的子进程运行时,其 oom_adj 会在 3 和 6 (包括6) 之间。后台运行的子进程  oom_adj 数值要取决于许多因素,如是否播放音乐,是否是homescreen 等。

+
+ +

也有两个例外的情况:

+ + + +

低内存通知器 Low memory notifications

+ +

释放内存的第二种机制就是低内存通知器。 LMK 提供一个特定的门限值,当超出该值时,会通知用户当前系统已运行在低内存状态。system 应用和常规的用户应用都会持续的等待这个条件,并通过 observer service 发送一个 memory-pressure 方法来响应它。 这个事件只对 C++ 和 chrome JS 代码可见,并非由应用直接发送。通过Gecko 代码库,我们使用该事件可以释放尽可能多的内存— 一般会通过清除内部缓存(图片,DNS,数据库等),丢弃可重新创建的资源(例如, WebGL contexts)以及运行垃圾回收器,生命周期回收器等方式实现。

+ +

当低内存情况发生时, 触发的第一个 memory-pressure 事件会有一个 low-memory 负载。 如果在预订时间(5s) 后, 还处在低内存状态, 会触发另一个 memory-pressure 事件,但此次负载值变为 low-memory-onging 。当一直处在低内存条件下,并且要清除缓存以及做其他简单的内存削减时,该负载会被使用,但应当知道一些繁重的工作,如 GC , 是不能成功的。(此段翻译可能不是太贴切,要深入理解,还请参考英文原文)

+ +

 LMK 和低内存通知器是如何配合工作的

+ +

当前低内存限值设定在后台进程 LMK 等级和 homescreen 之间。 因此当设备在低内存状态下运行时, LMK 和 低内存通知器联合作出的反应如下:

+ +
    +
  1. 以最不经常使用的次序 kill 掉 后台 app
  2. +
  3. 如果我们没有释放足够的内存, 向所有现存的应用发送 memory-pressure 事件
  4. +
  5. 如果低内存情况还在,每个 5 秒重发一次 memory-pressure 事件,但将它们标记为 ongoing , 使 GC/CC 不会对它们动作。
  6. +
  7. Kill 掉 homescreen.
  8. +
  9. Kill 掉可感知的或高优先级的后台应用
  10. +
  11. 如果 keyboard app 正在运行,Kill 掉
  12. +
  13. Kill 掉前台应用
  14. +
  15. Kill 掉高优先级的前台应用
  16. +
  17. Kill 掉 preallocated process
  18. +
diff --git a/files/zh-cn/archive/b2g_os/platform/settings_list/index.html b/files/zh-cn/archive/b2g_os/platform/settings_list/index.html new file mode 100644 index 0000000000..fc834dc10f --- /dev/null +++ b/files/zh-cn/archive/b2g_os/platform/settings_list/index.html @@ -0,0 +1,716 @@ +--- +title: Firefox OS 设置选项列表 +slug: Archive/B2G_OS/Platform/Settings_list +tags: + - API + - B2G + - Firefox OS + - Settings + - WebAPI + - 参考 +translation_of: Archive/B2G_OS/Platform/Settings_list +--- +
+

Firefox OS 提供了许多设置项,用于配置设备以及内嵌的功能。这些设置项可以由 certified apps 通过使用 Settings API 来访问。

+
+
+

注意: 由于不同的 Firefox OS 发行版本及设备提供的功能会有所不同,这个列表可能并不会精确的对每个设备进行匹配。

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
设置项名称类型默认值
accessibility.invertBooleanfalse
accessibility.screenreaderBooleanfalse
alarm.enabledBooleanfalse
app.reportCrashesStringask
app.update.intervalNumber86400
audio.volume.alarmNumber15
audio.volume.bt_scoNumber15
audio.volume.dtmfNumber15
audio.volume.contentNumber15
audio.volume.notificationNumber15
audio.volume.ttsNumber15
audio.volume.telephonyNumber5
bluetooth.enabledBooleanfalse
bluetooth.debugging.enabledBooleanfalse
camera.shutter.enabledBooleantrue
clear.remote-windows.dataBooleanfalse
debug.grid.enabledBooleanfalse
debug.oop.disabledBooleanfalse
debug.fps.enabledBooleanfalse
debug.ttl.enabledBooleanfalse
debug.log-animations.enabledBooleanfalse
debug.paint-flashing.enabledBooleanfalse
debug.peformancedata.sharedBooleanfalse
deviceinfo.firmware_revisionString 
deviceinfo.hardwareString 
deviceinfo.osString 
deviceinfo.platform_build_idString 
deviceinfo.platform_versionString 
deviceinfo.softwareString 
deviceinfo.update_channelString 
gaia.system.checkForUpdatesBooleanfalse
general.useragent.updates.enabledBooleantrue
geolocation.enabledBooleantrue
keyboard.layouts.englishBooleantrue
keyboard.layouts.dvorakBooleanfalse
keyboard.layouts.otherlatinsBooleanfalse
keyboard.layouts.cyrillicBooleanfalse
keyboard.layouts.arabicBooleanfalse
keyboard.layouts.hebrewBooleanfalse
keyboard.layouts.zhuyinBooleanfalse
keyboard.layouts.pinyinBooleanfalse
keyboard.layouts.greekBooleanfalse
keyboard.layouts.japaneseBooleanfalse
keyboard.layouts.polishBooleanfalse
keyboard.layouts.portugueseBooleanfalse
keyboard.layouts.spanishBooleanfalse
keyboard.vibrationBooleanfalse
keyboard.clicksoundBooleanfalse
keyboard.autocorrectBooleantrue
keyboard.wordsuggestionBooleantrue
keyboard.currentStringen
language.currentStringen-US
lockscreen.passcode-lock.codeString0000
lockscreen.passcode-lock.timeoutNumber0
lockscreen.passcode-lock.enabledBooleanfalse
lockscreen.notifications-preview.enabledBooleantrue
lockscreen.enabledBooleantrue
lockscreen.lockedBooleantrue
lockscreen.unlock-sound.enabledBooleanfalse
mail.sent-sound.enabledBooleantrue
message.sent-sound.enabledBooleantrue
operatorvariant.mccString0
operatorvariant.mncString0
ril.iccInfo.mbdnString 
ril.sms.strict7BitEncoding.enabledBooleanfalse
ril.cellbroadcast.searchlistString 
debug.console.enabledBooleanfalse
phone.ring.keypadBooleantrue
powersave.enabledBooleanfalse
powersave.thresholdNumber0
privacy.donottrackheader.enabledBooleanfalse
ril.callwaiting.enabled  
ril.cf.enabledBooleanfalse
ril.data.enabledBooleanfalse
ril.data.apnString 
ril.data.carrierString 
ril.data.defaultServiceIdNumber0
ril.data.passwdString 
ril.data.httpProxyHostString 
ril.data.httpProxyPortNumber0
ril.data.mmscString 
ril.data.mmsproxyString 
ril.data.mmsportNumber0
ril.data.roaming_enabledBooleanfalse
ril.data.userString 
ril.mms.apnString 
ril.mms.carrierString 
ril.mms.httpProxyHostString 
ril.mms.httpProxyPortString 
ril.mms.mmscString 
ril.mms.mmsportString 
ril.mms.mmsproxyString 
ril.mms.passwdString 
ril.mms.userString 
ril.radio.preferredNetworkTypeString 
ril.radio.disabledBooleanfalse
ril.supl.apnString 
ril.supl.carrierString 
ril.supl.httpProxyHostString 
ril.supl.httpProxyPortString 
ril.supl.passwdString 
ril.supl.userString 
ril.sms.strict7BitEncoding.enabledBooleanfalse
ril.sms.defaultServiceIdNumber0
ril.telephony.defaultServiceIdNumber0
ring.enabledBooleantrue
screen.automatic-brightnessBooleantrue
screen.brightnessNumber1
screen.timeoutNumber60
tethering.usb.enabledBooleanfalse
tethering.usb.ipString192.168.0.1
tethering.usb.prefixString24
tethering.usb.dhcpserver.startipString192.168.0.10
tethering.usb.dhcpserver.endipString192.168.0.30
tethering.wifi.enabledBooleanfalse
tethering.wifi.ipString192.168.1.1
tethering.wifi.prefixString24
tethering.wifi.dhcpserver.startipString192.168.1.10
tethering.wifi.dhcpserver.endipString192.168.1.30
tethering.wifi.ssidStringFirefoxHotspot
tethering.wifi.security.typeStringopen
tethering.wifi.security.passwordString1234567890
tethering.wifi.connectedClientsNumber0
tethering.usb.connectedClientsNumber0
time.nitz.automatic-update.enabledBooleantrue
time.timezone  
ums.enabledBooleanfalse
ums.modeNumber0
vibration.enabledBooleantrue
wifi.enabledBooleantrue
wifi.screen_off_timeoutNumber600000
wifi.disabled_by_wakelockBooleanfalse
wifi.notificationBooleanfalse
wifi.connect_via_settingsBooleanfalse
icc.displayTextTimeoutNumber40000
icc.inputTextTimeoutNumber40000
+

参考

+ diff --git a/files/zh-cn/archive/b2g_os/porting/index.html b/files/zh-cn/archive/b2g_os/porting/index.html new file mode 100644 index 0000000000..fb32edac40 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/porting/index.html @@ -0,0 +1,120 @@ +--- +title: 将B2G(Firefox OS)移植到你的手机上 +slug: Archive/B2G_OS/Porting +translation_of: Archive/B2G_OS/Porting_B2G_OS/basics +--- +

Boot to Gecko (Firefox OS)使用 Android的核心驱动, 在之上加上一个基于 Gecko的用户界面,这篇文章提供了移植操作系统到新设备上的一个基本流程。

+

这个指南假设你要移植的新设备上运行的是安卓;如果你要移植到其他设备上,会需要做更多的工作。

+

设置你的编译系统

+

第一步是配置你的编译系统;你可以使用这个指南Firefox OS build prerequisites

+

克隆B2G仓库

+

然后就是克隆B2G仓库

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

创建原安卓系统的本地备份

+

接下来,在你尝试编译B2G之前,应该备份你的安卓系统,另外,这些东西在编译和安装过程中也能用的到。

+
mkdir my_device_backup
+cd my_device_backup
+adb pull /system system
+

在config.sh中添加一个新设备

+

下一步是向config.sh文件中添加一个新设备;你可以使用已存在的设备作为模板,这仅仅是提供编译时获取正确文件的指南。

+

为新设备创建清单文件

+

现在你需要为新设备在称为default.xml的清单文件中添加必须的仓库(repos);在github上的b2g-manifest文件作为一个模板,每一个设备都有它自己的分支,你可以使用galaxy-s2作为一个例子。

+

为新设备创建配置树

+

为新设备创建配置树,这应该在device/<manufacturer>/<device_id>中,这个树中应该至少包括:

+ +

不同设备的这些内容可能会有很大的差别。尤其是BoardConfig.mk 和 extract-files.sh,这部分需要大量的研究,测试和调试才能得到哪些二进制对象应该被提取出来。

+
+

注意: 如果你可以在 CyanogenMod 上为你的设备找到一个已存在的引用,这些信息会加速你的移植过程, XDA Forum 是另一个讨论和寻找资源的好地方.

+
+

重新编译 boot.img

+

一旦你完成了上面所有步骤,你需要重新编译引导镜像,通常情况下,内核本身并不需要它,但是为适应init.rc的变化需要重新编译。

+

init.rc的变化

+

你使用的 init.rc 并不是B2G提供的;而是从你的设备上拷贝下来的。

+

你主要需要修改的是:

+

导入 init.b2g.rc

+

加入下面这些行来导入 init.b2g.rc:

+
on early-init
+    start ueventd
+    import /init.b2g.rc
+

解决权限问题

+

更正文件 /system/b2g/b2g, /system/b2g/updater, /system/b2g/plugin-container 的权限;这些行执行后挂载的系统应该可以读写:

+
chmod 0755 /system/b2g/b2g
+chmod 0755 /system/b2g/updater
+chmod 0755 /system/b2g/plugin-container
+

你可能想要从修改新设备的init.rc开始,而不是使用编译系统提供的init.rc,如果是这样,你要记得设置 BoardConfig.mk中的TARGET_PROVIDES_INIT_RC.

+

预编译核心 vs. 从源代码编译核心

+

你可以使用一个预编译的核心,或者你可以从源代码编译核心,要从源代码编译核心,在设备配置树中添加AndroidKernel.mk和核心配置。

+

旧编译系统 maguro 就是一个从源代码编译系统的例子。

+

提取并修改现存引导镜像

+

通过转存/dev/mtd/mtd1或 /dev/mtd/mtd2设备来恢复手机的引导镜像是可能的,成果镜像文件可以很容易的恢复:

+
adb shell 'cat /dev/mtd/mtd1 > /sdcard/boot.img'
+adb pull /sdcard/boot.img
+
+

 

+

获得了引导镜像文件之后你就可以通过帮助工具像unmkbootimg来解压,这个工具会解压出核心镜像(zImage)和虚拟磁盘(initramfs.cpio.gz),而且还会输出一个用于将原镜像带一些参数重新编译的命令,如:

+
$ unmkbootimg boot.img
+Kernel size 3872576
+Kernel address 0x208000
+Ramdisk size 265102
+Ramdisk address 0x1500000
+Secondary size 0
+Secondary address 0x1100000
+Kernel tags address 0x200100
+Flash page size 2048
+Board name is ""
+Command line "androidboot.hardware=aphone"
+Extracting kernel to file zImage ...
+Extracting root filesystem to file initramfs.cpio.gz ...
+All done.
+---------------
+To recompile this image, use:
+  mkbootimg --kernel zImage --ramdisk initramfs.cpio.gz --base 0x200000 --cmdline 'androidboot.hardware=aphone' -o new_boot.img
+---------------
+
+

 

+

要修改虚拟磁盘文件,创建一个输出文件夹并解压到此:

+
mkdir initramfs_dir
+cd initramfs_dir
+gunzip -c /path/to/your/boot.img | cpio -i
+
+

 

+

完成所有改变(如修改init.rc)并用mkbootfs重新打包虚拟磁盘,确保使用B2G主机工具的版本:

+
/path/to/your/B2G/out/host/linux-x86/bin/mkbootfs initramfs_dir | cpio -o -H newc | gzip > ../newinitramfs.cpio.gz
+
+

 

+

最后使用mkbootimg重新打包引导镜像,也要确保使用的是B2G主机工具的版本:

+
/path/to/your/B2G/out/host/linux-x86/bin/mkbootimg --kernel zImage --ramdisk newinitramfs.cpio.gz --base 0x200000 --cmdline 'androidboot.hardware=aphone' -o new_boot.img
+
+

 

+

如果你现在把新的引导镜像拷贝到 out/target/product/$DEVICE/boot.img ($DEVICE 是你的设备名称)下,它将会在调用 flash.sh时自动写入,或者你可以用下面的命令手动写入手机中:

+
adb reboot bootloader
+fastboot flash boot newboot.img
+fastboot reboot
+
+

 

+

在 flash.sh中添加新设备

+

添加新设备到 flash.sh中,具体细节将取决于写入新设备时所用的工具。

+

配置、编译和写入设备

+

现在你可以尝试编译并写入你的新设备了:

+
ANDROIDFS_DIR=my_device_backup ./config.sh <device_id> default.xml
+./build.sh
+./flash.sh
+

测试和调试

+

待续

+

FAQ

+

Forthcoming

+

See also

+ diff --git a/files/zh-cn/archive/b2g_os/preparing_for_your_first_b2g_build/index.html b/files/zh-cn/archive/b2g_os/preparing_for_your_first_b2g_build/index.html new file mode 100644 index 0000000000..405ff0fc23 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/preparing_for_your_first_b2g_build/index.html @@ -0,0 +1,212 @@ +--- +title: 准备第一次B2G的构建 +slug: Archive/B2G_OS/Preparing_for_your_first_B2G_build +translation_of: Archive/B2G_OS/Preparing_for_your_first_B2G_build +--- +

+ +

在构建B2G之前,你需要下载编译B2G构建的代码库并做配置。本篇就是教你如何完成这一过程。

+ +

配置步骤会需要一些时间来下载构建FirefoxOS的必要文件,时间的长短取决你的网速。(如果网速在150KBps,下载整个Android代码库将要几十个小时)。等待下载是很乏味的过程,如果你读完本页及已经开始配置脚本,可以考虑去配置与试用一下Firefox OS 模拟器,或去熟悉一下应用开发文档(像是如何设计与创建一个应用、了解后续步骤的信息等)。

+ +
+

配置和构建 B2G 的可能需要较长的时间,你可以去做一些其他工作或者和朋友去喝杯咖啡。

+
+ +

如果你在等待代码下载,或者在开始前想体验一把,你可以看下下面的视频,该视频演示了构建Firefox OS准备工作。(大陆地区无法看到该视频。。。)

+ +

+ +

克隆B2G代码库

+ +

第一步,克隆一份 B2G 远程的Git版本库到本地后,才可以开始你的第一个构建。这一步不会获取所有想要的东西!相反,只会获取B2G构建系统和配置的实用工具。最主要的B2G代码都在 Mozilla Mercurial 主仓储中。

+ +

使用 git 来克隆你的版本库:

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

克隆之后(应该会花个几分钟),cd 到 B2G 的目录:

+ +
cd B2G
+
+ +

为你的设备配置专属 B2G

+ +
重要:请注意只支援 Android 4(又名:Ice Cream Sandwich)的移动设备,或是各种支持的IT平台(目前只有 Firefox OS 设备)。请确认你手机运行的是ICS,否则这个步骤很可能会因为驱动程序在某些非Nexus设备上失败。另外,如果你需要将ICS刷入移动设备,请留意有些USB集线器和刷机工具不兼容,因此可能需要将移动设备连接到内建的USB端口。
+ +
重要:如果你在 Ubuntu 12.10+ 或 Fedora 上构建,需要在检索 B2G 源码后指定 GCC4.6 为默认主编译器,(默认情况下发行版使用 GCC4.7)。可以阅读 Changing the default host compiler 了解如何做到这一点。
+ +
注意:在运行任何构建命令之前,请先阅读下面左右指令,以确保你正在做的事是正确的!
+ +

一旦有了构建 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 移植到你的设备,或是等别人完成移植。我们当然比较希望你可以帮忙移植!

+ +
注意:Firefox OS 手机页面上可以找到你手机的设备名。
+ +
注意:对于 Keon 配置和构建在 Mac 上进行是无法工作的。针对该设备的构建你需要使用 Linux。
+ +
注意:如果因为任何原因,你想要编译构建 Gecko 的某个特定版本,请阅读  Building against a custom Gecko,然后再继续。如果你想要构建一个你设备默认以外的分支(例如,建立 B2G 的特定版本),请阅读 Building a branch
+ +
注意:不同设备默认的可能是自己的分支版本,未必是主干(trunk)版本.。
+ +

这将是一个很好的喝咖啡时间,需要将所有所需的代码提取、构建并引导到 Gecko,这一过程会花费很长的时间,你可能需要通过使用 Ctrl-C 停止和稍后重新启动工作。如果你觉得某部分因为终止,而未完成,可以运行 “./repo sync” 来修复任何可能出现的问题。

+ +

为移动设备配置

+ +

首先,连接你的设备,在配置过程中需要访问它。

+ +

如果你的设备被列出,可以通过运行 config.sh 指定你的设备名称再次启动配置程序。例如,要为三星 Google Nexus S 构建,请键入:

+ +
./config.sh nexus-s
+
+ +
注意:如果你得到了一个"fatal: manifest 'nexus-s.xml' not available"的错误提示,这时你只需要指定一个你想要使用的分支 。请阅读 Building a branch了解详情。
+ +

在配置的刚开始,你可能需要设置颜色使用的选项,在这里你可以只选择“Y”,因为可能会想要一个自己的颜色版本。完事之后会继续配置流程。现在就可以去喝个咖啡休息一下,因为你第一次需要把构建 Boot to Gecko 中所有要的程序都抓下来。

+ +

使用系统备份配置构建

+ +

如果你的手机不再使用 Android 且 B2G tree 还没装到手机上,但聪明地作一份/system 分区的备份的话,你可以在系统备份基础上执行构建,像这样:

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

请注意,构建系统将会有默认存放目录,如“backup-inari/system”(取决于设备配置),如果打算把文件存放在默认位置,你不需要特意指定目录。

+ +

注意:如果你的手机原本就运行着 Firefox OS,而从来没有运行过Android,它仍然会细致的把文件挂载到/system 分区,这样会为你指引到正确的文件。

+ +

配置构建一个模拟器

+ +

如果你想要在模拟器中构建,可以选择一款 ARM 设备模拟器作为指定模拟器,或是使用 "emulator-x86" 来打造x86模拟器。后者速度更快,但不能准确的表现出实际移动设备的表现。

+ +

现在,举个例子,构建ARM模拟器,应该这样配置:

+ +
./config.sh emulator
+
+ +

在配置的刚开始,你可能需要设置颜色使用的选项,在这里你可以只选择“Y”,因为可能会想要一个自己的颜色版本。完事之后会继续配置流程。现在就可以去喝个咖啡休息一下,因为你第一次需要把构建 Boot to Gecko 中所有要的程序都抓下来。

+ +

此时你应该准备好开始构建,除非你需要更高级的信息,详情如下。

+ +

注意:模拟器无法在64位 Linux上构建。

+ +
+

注意:./config.sh 可能会比你想想的更耗费时间和网络资源。你可能需要通过使用 Ctrl-C 停止和稍后重新启动工作。如果你觉得某部分因为终止,而未完成,可以运行 “./repo sync” 来修复任何可能出现的问题。

+
+ +

构置定制一个 Gecko

+ +

可能你会想要或需要以好几种版本的 Gecko 来编译 Boot to Gecko(manifest 中预设是一种)。你可以在你抓仓储(在上述的 config.sh 之前),藉由编辑 .userconfig 来做到这件事情在举例来说,如果你要根据 mozilla-central 来编译:

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

注意:如果是在 Mac OS X 中编译自定义版 Gecko 的话,文件系统会区分  mozilla-central 目录的大小写。

+
+ +

注意,可以在你抓仓储之前(也就是在上述的 config.sh 之前)或之后几步。你也可以通过多个 UserConfig 的文件(使用不同的设置 - 当然每个都需要不同 OBJDIR)和编辑,保留多个构建(与调试等)。添加一个符号连接(symlink)指向一个配置(你想要使用哪个构建就指向那个配置)。

+ +

欲了解更多信息,请阅读 Changing the Gecko source tree

+ +

建立一个分支

+ +

如果你想要构建一个非默认的分支(注:默认分支可能不是“主干”),需要调用 config.sh 并前缀分支名称,像这样:

+ +
BRANCH=branch-name ./config.sh <device>
+ +

分支名称应该是合乎逻辑的,主要是按照产品/版本的名称,比如v1-trainv1.0.0、v1.0.1、v1.1、v1.1.0hd、v1.2,以此类推。举个例子,在模拟器上构建 B2G Firefox 1.2,你需要键入:

+ +
BRANCH=v1.2 ./config.sh emulator
+ +

如果你已经运行过 config.sh,可以通过去B2G/.repo/manifests 查看分支名称,或者用 “git branch -a”,使用分支名在行的最尾端即可,如:“v1-train” 或 “master”:

+ +
  remotes/origin/master
+  remotes/origin/v1-train
+  remotes/origin/v1.0.0
+  remotes/origin/v1.0.1
+ +

另外要了解更多关于定制,你可以查看 Customization with the .userconfig file

+ +

复制你的 B2G 树(tree)到一台新机器

+ +

如果你之前已经设置了 B2G tree,如果你又有了一代新电脑,想要把 B2G tree 从一台电脑转移到另一台电脑的话,你会发现至少比起重新配置整个事情更容易。

+ +

要做到这一点,将你旧电脑的硬盘挂载到新电脑,然后敲入下面的命令,就可以了:

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

source 是整个原码树(source tree)的完整路径(包括后面的斜线),而 dest 是你要复制到目标位置(同样也包含后面的斜线,它很重要!)。

+ +
注意:如果你采用把文件从一台电脑复制到另一台电脑的方法,应该确保在开始构建之前运行一次“./build.sh clean”。如果不这样做,可能会遇到编译问题。
+ +

如果你采用了这个方法迁移代码,可以跳过本文余下的部份,然后直接跳到的“构建”部份。

+ +

更新你的B2G树

+ +

当存储库更新到了新版本,你要更新你的B2G tree。./sync 命令不会更新你的B2G树。要做到这一点,你可以运行下面的命令:

+ +
git fetch origin
+git checkout origin/master
+ +

你可以运行一下命令,检查是否工作正常:

+ +
git show HEAD
+ +

并检查提交的版本是否与最新提交版本显示匹配:https://github.com/mozilla-b2g/B2G/commits/master

diff --git a/files/zh-cn/archive/b2g_os/quickstart/index.html b/files/zh-cn/archive/b2g_os/quickstart/index.html new file mode 100644 index 0000000000..ebe1f7c220 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/quickstart/index.html @@ -0,0 +1,49 @@ +--- +title: Build +slug: Archive/B2G_OS/Quickstart +tags: + - NeedsTranslation + - 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-cn/archive/b2g_os/quickstart/your_first_app/index.html b/files/zh-cn/archive/b2g_os/quickstart/your_first_app/index.html new file mode 100644 index 0000000000..63c859ce8a --- /dev/null +++ b/files/zh-cn/archive/b2g_os/quickstart/your_first_app/index.html @@ -0,0 +1,261 @@ +--- +title: 你的第一个应用 +slug: Archive/B2G_OS/Quickstart/Your_first_app +translation_of: Archive/B2G_OS/Quickstart/Your_first_app +--- +
+
+

开放式Web应用让开发人员实现了期盼多年的夙愿:通过Firefox OS这一首款开放式Web应用平台,可以仅仅使用Html、CSS和JavaScript在跨平台的环境中生成可部署的应用。本手册包含了基本的架构和应用构建指南,你能够迅速掌握这些内容并开始创造自己的下一个伟大的应用!

+
+ +

如果你想按照本指南开发,你可以下载我们的快速入门应用模板。还可以参阅应用模板指南找到更多有关其内容的介绍。

+ +

应用架构

+ +

打包型应用 VS. 托管型应用

+ +

开放网络应用有两种类型:打包型和托管型。打包型应用本质上来说就是一个包含各种HTML、CSS、JavaScript、图像、清单(manifest)等应用资源的zip文件。托管型应用在一个给定域名的服务器上运行,就像是一个独立的网站。两种应用都需要有有效的清单。到了要在火狐市场中列出你的应用是,你要上传应用的zip文件或提供托管应用所在的URL

+ +
+

+ +
+

Made in partnership with Treehouse: Check them out!

+
+
+ +

在本指南结束时,你将创建一个寄宿于本机(localhost)地址上的托管型应用。一旦你的应用准备好进入火狐市场,你可以选择把它作为打包应用打包或作为托管应用启动。

+ +

应用清单

+ +

每一个火狐应用都需要一个位于应用根目录下的manifest.webapp文件, 这个文件提供与应用有关的重要信息,如:版本、名称、描述、图标地址、本地字符串、指明应用可以从哪儿被安装等等。只有名称和描述是必须的。应用模板中的简单清单如下所示:

+ +
{
+  "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"
+}
+ +
+

+ +
+

Made in partnership with Treehouse: Check them out!

+
+
+ +

 

+ +

一个基本的清单是你所需要最先上手的地方。关于清单的更多细节,见应用清单

+ +

应用布局&设计

+ +

随着不同设备上屏幕分辨率标准的增多,响应式设计已经变得越来越重要。即使你应用的主要目标平台是移动平台比如Firefox OS,其他设备很有可能也会访问它。CSS媒体选择(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的框架可以用于协助响应式设计和移动应用发展(Bootstrap等),选择最适合你的应用和开发样式的框架即可。

+ +

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,你就可以为chargingchangelevelchange添加时间监听器来更新元素的样式。

+ +

时常检查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. +
  3. 我们使用navigator.mozApps.checkInstalled 来检查这个由http://people.mozilla.com/~cmills/location-finder/manifest.webapp这个清单来定义的应用是否已经安装在设备上。这个测试结果被储存在installCheck这个变量中。
  4. +
  5. 当测试成功完成时,它的成功完成事件被触发,因此installCheck.onsuccess = function() { ... }会被执行。
  6. +
  7. 然后我们用一个if语句判断installCheck.result是否存在。如果存在,以为着应用已经被安装了,隐藏安装按钮。在应用已经被安装的情况下不需要安装按钮(废话>_<!)
  8. +
  9. 如果应用没有被安装,为按钮添加一个单击事件监听器,所以在按钮被单击的时候install()函数会被执行。
  10. +
  11. 当单击按钮并且install()函数执行时,我们把清单位置保存在一个叫manifest_url的变量中,然后利用navigator.mozApps.install(manifest_url)来安装应用,用一个installLocFind变量来储存对那个安装的应用。你会注意到安装也会触发success和error事件,所以你可以根据应用是否成功安装来执行不同的动作。
  12. +
+ +

第一次遇到可安装网络应用时你可能想要核实API的执行状态

+ +
+

注意:可安装开放网络应用有一个“每个来源(origin,感觉就是URL的意思)一个应用”的安全策略;基本上, 你不可以在一个来源上托管多个可安装应用。这会让检测变得有一点复杂,但是仍有很多办法解决这个问题,比如为应用创建多个子域名、用Firefox OS模拟器测试应用、或者在Firefox Aurora/Nightly上安装测试功能,通过这种方式你可以在桌面环境上安装开发网络应用。关于来源的跟多信息详见应用清单FAQ

+
+ +

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": {}
+}
+ +

权限分为下面三个等级:

+ + + +

关于应用权限等级的更多信息,请阅读打包型应用的类型。你可以在应用权限中找到更多关于API要求权限和需要什么样的权限。

+ +
+

有一点需要注意的很重要就是不是所有的Web API都在Firefox OS模拟器中实现了。

+
+ +

工具&测试

+ +

测试在对移动应用的支持中是至关重要的。测试可安装开放网络应用有多种方式。

+ +

Firefox OS 模拟器

+ +

安装和使用Firefox OS模拟器  是启动和运行你的应用最简单的方式。在你安装模拟器之后,可以通过工具->web开发者->Firefox OS模拟器菜单来启动。模拟器启动时会有一个Javascript控制台,这样你就可以在模拟器中调试你的应用。

+ +

应用管理器

+ +

测试工具的新宠儿被称为应用管理器。这个工具允许你通过USB链接桌面火狐浏览器和一个可兼容性设备(或者一个Firefox OS模拟器),直接将应用推送到设备上,验证应用并且像运行在设备上一样的调试。

+ +

单元测试

+ +

当在测试不同设备和版本时,单元测试就会非常有价值。jQuery的QUnit是一个流行的客户端测试工具,当然你也可以使用任何你喜欢的测试工具。

+ +

在设备上安装Firefox OS

+ +

既然Firefox OS是一个开源平台,代码和工具都可以用于在你自己的设备上构建和安装Firefox OS。构建和安装指南以及什么设备可以安装的注意事项可以在MDN上发现。

+ +

特定的Firefox OS开发者预览版设备可以在开发者预览版手机页面找到更多信息。

+ +

应用提交和分发

+ +

一旦你的应用完成,你可以像标准网站或应用一样托管它(更多信息请阅读发布应用),或者可以发布火狐市场。你的应用清单将被验证并且你可以选择你的应用将支持的设备(比如:Firefox OS、桌面版火狐浏览器、移动版火狐浏览器、平板班火狐浏览器)。一旦验证通过,你可以为你的应用添加更多细节(截屏、描述、价格等)并且正式在火狐市场应用列表中提交应用。提交成功后,你的应用可以被任何人购买和安装。

+ +

更多商场&上市信息

+ +
    +
  1. 向Firefox OS商场中提交应用
  2. +
  3. 市场审查标准
  4. +
  5. 应用提交演练视频
  6. +
+
diff --git "a/files/zh-cn/archive/b2g_os/quickstart/\345\274\200\346\272\220web\345\272\224\347\224\250\347\250\213\345\272\217\347\256\200\344\273\213/index.html" "b/files/zh-cn/archive/b2g_os/quickstart/\345\274\200\346\272\220web\345\272\224\347\224\250\347\250\213\345\272\217\347\256\200\344\273\213/index.html" new file mode 100644 index 0000000000..bb2a8127cd --- /dev/null +++ "b/files/zh-cn/archive/b2g_os/quickstart/\345\274\200\346\272\220web\345\272\224\347\224\250\347\250\213\345\272\217\347\256\200\344\273\213/index.html" @@ -0,0 +1,87 @@ +--- +title: 开源Web应用程序简介 +slug: Archive/B2G_OS/Quickstart/开源Web应用程序简介 +translation_of: Archive/B2G_OS/Quickstart/Intro_to_open_web_apps +--- +
+

Note: The Quickstart section has been updated with a new, more focused Quickstart article, which replaces all the previous Quickstart articles. We hope you'll find this more useful, and a quicker learning experience than the older set of articles.

+
+ +

Multi devices

+ +
+

本文的目的是为那些希望学习更多关于开放式Web应用程序的人提供一个良好的起点,无论你是开发人员或者项目经理,或者应用程序开发或交付中的其他角色。在这里我们将提供一个简洁、更深层次的关于Web应用程序的概述,以及其背后的理念。

+
+ +

开放的Web应用程序本质上同标准的网站或页面是没有什么不同的。它们是用标准的开放的网络技术---- HTML,CSS,Javascript 等等。----并且可以使用浏览器访问。主要的区别是它们可以安装到设备并且可以脱机工作,并使用先进的API用于与设备进行交互,如相机,地址簿,和其他类似的东西。此外,它们几乎都是尽可能用开放的技术开发的。区别在于平台技术的实现,努力确保两者都支持,其一:通过不同的平台相结合的特征检测和适当的代码,其二:优美的退化。

+ +

开放式Web应用程序的优势

+ +

我们来看一看关于开放式Web应用程序优势的一些细节:

+ + + +

The following video also looks at general advantages of open web apps, and developing for the Firefox OS platform:

+ +

+ +

The Web is the platform

+ +

An open web app as it exists as installed on a platform like Firefox OS is not a bookmark — it’s a proper part of the system. Open Web Apps hold that great promise. They are an opportunity that we should not miss, otherwise the Web might become fragmented once more. With this in mind it should be made clear that Open Web Apps (OWA in short) are intended to be standardized and to become part of "the Web". If successful, OWA should eventually work on all browsers, operating systems and devices.

+ +

At Mozilla we are working hard to create this apps platform that is backed entirely by the open Web. It’s not intended to be a “Mozilla platform” or a “Firefox platform”. The Web is the platform. We’re creating a set of open APIs and implementations to show how portable apps can exist on the Web without vendor lock-in. Other groups like Facebook and Google Chrome are also working on apps platforms backed by the Web. Facebook apps are meant to hook into Facebook and Chrome apps are designed for Chrome OS devices and Google servers. Chrome apps are the most similar to Open Web Apps. We continue to collaborate with the Google Chrome team as app standards evolve and we definitely share a lot of the same vision. There is tremendous potential for all Web based app platforms to converge and we invite all vendors to help us build the right Open Web App APIs.

+ +

Even though currently you must have a Mozilla Firefox-based engine ("Web runtime") to use Open Web Apps, it is not intended that this always will be the case. Many parts of the Open Web Apps project are still being worked out and it isn't possible to implement everything in all browsers at once. Although many parts of Open Web Apps are already standardized, many other parts are still in flux. It is intended and hoped that Open Web Apps will be a standard capability that is available in all major browsers.

+ +

Therefore, when you read the MDN pages that deal with Open Web Apps, please keep in mind that even though much of the information is specific to Firefox right now, it will hopefully enable you to develop Open Web Apps for all browsers in the future.

+ +

Web standards

+ +

OWA technology is not a single piece, it is an umbrella that groups many different technologies and some of them are very young. At the moment, parts of OWA are standardized (HTML5, CSS, JavaScript, IndexedDB, etc.). Other parts are not yet standardized and the Mozilla implementation is thus specific to Firefox or to some other Mozilla technology. As the Mozilla mission is to share and to empower everyone, this situation is only temporary. That's why in the OWA docs we will try to clearly identify the parts of OWA that are not yet standardized.

+ +

Please also note that there may be some OWA-related proposals and potential standards that are not used by Mozilla.

+ +

Intended eventual standards

+ +

So here are the parts not standardized yet across the different Web platforms and that still are Firefox-only for the moment:

+ + + +

Marketplace

+ +

Buy Once, Run Everywhere

+ +

From the ground up Mozilla has been building an apps system that lets users buy an app once and run it on all of their HTML5 devices. Very soon Mozilla will launch the first Firefox OS phone but that will be just one device on which to run your apps. When you purchase an app through the Firefox Marketplace, the system installs a receipt on your device. The receipt is a JSON Web Token with metadata that links to the Marketplace’s public key and its verification service URL. When an app starts up it can verify the receipt but the receipt on the device is not tied to the Firefox Marketplace. The receipt is just a cryptographically verifiable proof of purchase. Anyone can sell open Web apps if they follow the receipt specs. When you buy an app, it is intended to be portable across any device that supports the Open Web Apps system.

+ +

Mozilla is building the infrastructure needed to run Open Web Apps on any HTML5 device. Firefox for Android will let you install and run apps (you can try it today on the nightly build). Installed app icons go to your home screen just like regular Android apps. You can also install and run Web apps on your Windows, Mac, or Linux desktop using Firefox (this currently works in the nightly build). Currently some version of Firefox is required, but it is intended that the Open Web Apps system will eventually be supported by all major browsers as a set of standards. From day one Mozilla has included all major HTML5 compliant browsers in its proof of concepts; you can take a look at this hosted JavaScript shim for ideas on how to support the apps platform on a non-Firefox browser.

+ +

In the future the Open Web Apps system will support syncing your installed apps across devices. Since receipts are portable you could just sync them yourself if you wanted to. In case it’s not obvious, you can always run a free open Web app in any browser because it is no different than a website. It might, however, use new mobile specific web APIs which are not implemented on all platforms.

+ +

The video below provides a useful overview of the advantages of open marketplaces and an open web approach to app discovery:

+ +

+ +

WebPayment API

+ +

Commerce For Apps

+ +

Part of the success of mobile app platforms like iOS and Android is that they make it very easy to try out new business models through mobile payments. Those models are still evolving but commerce is no doubt something that, at the moment, is awkward on the desktop Web and more natural on mobile. Specifically, it’s very convenient to charge something to your phone bill when you’re already accessing it from your phone anyway. With the launch of Firefox OS, the apps ecosystem will support app purchases and in-app payments through the WebPayment API. Supporting commerce is crucial for the growth of an apps platform. The use of the proposed payment API is completely optional. Mozilla won’t prevent any app from using its own in-app payment system.

+ +

See also

+ + diff --git a/files/zh-cn/archive/b2g_os/running_tests_on_firefox_os_for_developers/index.html b/files/zh-cn/archive/b2g_os/running_tests_on_firefox_os_for_developers/index.html new file mode 100644 index 0000000000..c7b64d1573 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/running_tests_on_firefox_os_for_developers/index.html @@ -0,0 +1,58 @@ +--- +title: '在 Firefox OS 中运行测试程序: 开发者指南' +slug: Archive/B2G_OS/Running_Tests_on_Firefox_OS_for_Developers +translation_of: Archive/B2G_OS/Running_Tests_on_Firefox_OS_for_Developers +--- +
+

在我们自动化测试背后的团队一直在非常努力的对自动化测试的框架进行扩展以及构建了一个专门针对手机系统测试的框架以适应 Firefox OS 的需求。由于 Firefox OS 架构的关系,所有测试框架都可以工作和使用,但是也会使事情变得更复杂. 您时一名开发者,只是想运行一些测试来验证您的 patch 是否能正常工作。本文旨在对 Mozilla 中所有有效的测试资源进行梳理。

+
+

入门

+

如果您是一位 Gecko 开发者,则需要对您已经熟悉的有关 Firefox OS 特定的自动化测试文档进行回顾:  mochitest, reftest, 和 xpcshell.

+

如果您是一位 Gaia App 开发者,或者是一位 Gecko 开发者,但是对更深层次的终端用户样式测试感兴趣,则需要了解下 Gaia 测试套件。 一共有两个主测试套件:

+ +

可以依据您喜爱的工具链,以及测试的内容来决定究竟要选择何种测试。

+

让我们现在来查看和运行这些测试。

+

运行 Gaia UI 测试

+

The Gaia UI Test suite can be run on real devices and B2G Desktop builds, but in this section we'll concentrate on running them on a real device, as real devices are always best where possible.

+

Note that this test is destructive and as such, you should back up anything you care about on the phone before running these tests. Depending on which tests you run, they can also make phone calls. So be aware that you want to be very careful about what you run and how you back up the phone, remove the SIM card, etc.  That said, if you've already created an engineering build they are really easy to get running. Here's how.

+

One Time Set up

+

You only need to perform the following steps once, assuming you do not change the location of your Gaia directory. Create a python virtualenv (install the virtualenv tool first if you haven't already), activate it, and install the gaia UI test tool into your virtualenv. By creating the virtual environment using the steps below, you ensure that you are running the gaia UI test harness code that lives in your Gaia repo (that's useful in case you need to debug anything).

+
$ virtualenv gaia_ui_venv # This will create a gaia_ui_venv directory where the virtual environment lives. It can be anywhere on your system.
+$ source gaia_ui_venv/bin/activate # This activates our virtualenv
+(gaia_ui_venv)$ cd <b2groot>/gaia/tests/python/gaia-ui-tests;python setup.py develop # This installs the gaia ui harness into your virtual environment. 
+

If you have already created a virtual environment for gaia ui tests, you can simply do the following:

+
$ source gaia_ui_venv/bin/activate
+

To Run the Tests

+

First you need to create the testvars file. To do this, copy the standard one over, and add in the attributes to turn off the warnings that this test will destroy all content on your phone. These are good tests, they leave no state around and as such, you will need to make sure your phone is backed up before running them. Instructions from here on will assume you've activated the virtual environment and are working in the gaia/tests/python/gaia-ui-tests directory.

+
(gaia_ui_venv)$ cp gaiatest/testvars_template.json testvars.json
+# Now edit your copy of testvars.json and add in the following attributes into the json:
+"acknowledged_risks": true,
+"skip_warning": true,
+

Now you just need to connect our phone via USB, forward the marionette port so your test runner can access it and run our tests. The tests are in gaiatest/tests and you can pick whichever one you want to run. For example, if you wanted to run contacts tests you would do the following:

+
(gaia_ui_venv)$ adb forward tcp:2828 tcp:2828
+(gaia_ui_venv)$ gaiatest --testvars=testvars.json --address=localhost:2828 gaiatest/tests/functional/contacts/
+
+

注意: To find out what UI tests are available, browse through the gaiatest directories inside the Gaia repo.

+
+

To get out of the python virtualenv, just use the special virtualenv command deactivate:

+
(gaia_ui_venv)$ deactivate
+$
+
+

注意: To learn more about the Gaia UI Tests and find more detailed information, move on to the Gaia UI Tests pages.

+
+

运行 Gaia 集成测试

+

To run the Gaia Integration tests tests you currently have to use a B2G Desktop build (note that these are also going to be available for devices soon as well). Let's look at how this is done.

+

These just require a Gaia tree and NodeJS to be installed on your computer; the following command will do the rest:

+
$ cd gaia $ make test-integration 
+

That's it — this instruction will download a B2G desktop build, and start running the tests in that build.

+
+

注意: To learn more about Gaia Integration Tests, read the Gaia Integration Tests Github repo.

+
+
+

注意: To find out what integration tests are available, look in the apps directory in the Gaia repo; integration tests can be found in test/marionette/ subfolders.

+
+

总结

+

As always, work is underway to make all our tests easier to run both locally for developers as well as in our automation systems. Feel free to drop into the #ateam channel any time you have questions about test automation for Firefox OS or any of the Mozilla automation tools.

diff --git a/files/zh-cn/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html b/files/zh-cn/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html new file mode 100644 index 0000000000..4193506bed --- /dev/null +++ b/files/zh-cn/archive/b2g_os/screencast_series_colon__app_basics_for_firefox_os/index.html @@ -0,0 +1,219 @@ +--- +title: 'Screencast series: App Basics for Firefox OS' +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 is an operating system that brings the Web to mobile devices. Instead of being a new OS with new technologies and development environments it builds on standardised web technologies that have been in use for years now. If you are a web developer and you want to build a mobile app, Firefox OS gives you the tools to do so, without having to change your workflow or learn a totally new development environment. In this collection of short videos, developers from Mozilla and Telenor met in Oslo, Norway to explain in a few steps how you can get started to build applications for Firefox OS.

+
+ +

In this series you’ll learn:

+ + + +
+

Note: Each of the screencasts is short enough to get through in a short break; the whole series should not take more than an hour to watch.

+
+ +

Code and development environment

+ +

In addition to the screencasts, you can download the accompanying code samples from GitHub. If you want to try the code examples out for yourself, you will need to set up a very simple development environment. All you need is:

+ + + +

Introducing the series

+ +

The series features Jan Jongboom (@janjongboom) and Sergi Mansilla (@sergimansilla) of Telenor Digital, and Chris Heilmann (@codepo8) of Mozilla; it was shot in three days in Oslo, Norway at the Telenor head office in February 2014.

+ +

Here are the three of us telling you about the series and what to expect:

+ +

+ +

Section 1: Building your first Firefox OS app and getting it published

+ +

In Section 1's five screencasts we show you how to build a Firefox OS application, how to debug and test it on your computer — and on a real device, and how to get it listed in the Firefox Marketplace. This may sound like a lot of work, but you will soon find out that if you already know how to build a website, you are 90% of the way there already.

+ +

More than a website

+ +

Firefox OS applications are HTML5 applications. In essence, these use the same technologies as websites do. You can start writing a website and turn it into an app simply by giving it a manifest file (see The app manifest for more details). This tells Firefox OS that you are writing an app and allows you to:

+ + + +

In essence, HTML5 applications are supercharged websites and should follow the same rules, such as:

+ + + +

The main difference is that for a web page to become a great application, you should very much consider mobile users. This means first and foremost that your application should:

+ + + +

In many cases, this means you need to slim your web page down a bit and simplify the interface. The good news is that all your users will benefit from that.

+ +

+ +
+

Note: To find out more about how to design a good HTML5 App, check out the App Center on MDN.

+
+ +

The app manifest

+ +

The App Manifest in Firefox OS is a simple JSON file that tells the operating system about your app. In essence, this is what turns a web page into an Open Web App. In it, you define the name in different locales and you ask the operating system to get access to various services and hardware. You can also define the preferred orientation of your app and — if needed — lock it.

+ +

+ +

More information about the manifest and tools that can help you:

+ + + +

The App Manager

+ +

The simplest way to get started with Firefox OS is to try out the App Manager. This tool stands alongside the Firefox developer tools for desktop and allows you to connect to a Firefox OS simulator running on your computer, or a real Firefox OS device if you have one available. From there, you can play with Firefox OS, install apps straight onto the simulator or real device, and debug them as they are running on Firefox OS — seeing the live changes immediately without needing to uninstall or update apps.

+ +

The following video provides first steps with using the App Manager along with the simulator:

+ +

+ +
+

Note: The App Manager allows you to debug your own applications even when you're offline, without any hassle.

+
+ +

More information about the App Manager:

+ + + +

Testing on a Real Device

+ +

Testing your applications in the simulator is nice, but it only gets you as far as a simulated environment can. If you want to test the performance of the app interaction, or react to things like device orientation, you need a real device. Together with the developer tools and the App Manager, you can use the device and get detailed insight into what happens to your application as you use it.

+ +

+ +

Publishing to Marketplace

+ +

The Firefox OS Marketplace is the most convenient place to list your application and make it available to people on their devices and the Web. The Marketplace also allows you to list your app for other platforms like Firefox Desktop and Firefox for Android. You can also allow users to rate your app, give you feedback, and buy your application using a simple checkout process. Getting your app listed is simple:

+ + + +

+ +

Applications submitted to the Marketplace are reviewed by Mozilla's app review team and you will be notified of the state of your submission within a few days. If there are issues with your application you will get a validation message during the submission but you might also get a human readable explanation of what is wrong and how to fix it.

+ +
+

Note: Read Submitting an application to the Firefox Marketplace for more information about the submittion process.

+
+ +

Section 2: Advanced Firefox OS topics

+ +

In the first few videos we introduced you to Firefox OS and how to build your first app. We also covered how to debug your application on desktop — and on a real device — and how to get your app listed in the Firefox Marketplace. In the remaining five videos we’ll deep-dive into the technologies that enable Firefox OS apps to go that extra mile and give you access to the functionality that makes developing for a smartphone or tablet interesting to developers. Whilst some of these technologies are currently only working in Firefox OS, they are all open source and submitting as standards proposals. Working with these APIs today will mean you are ready for other devices and platforms emerging in the near future.

+ +

Web APIs

+ +

Smartphones are full of great technology — cameras, accelerometer, and GPS to name but a few. The problem was that all of these were not accessible by web technologies — if you wanted to access them, you needed to write native applications. To fix this, Mozilla and partners defined a set of APIs to allow developers to reach deep into the hardware of a mobile devices using JavaScript in a secure manner. These are called Web APIs and are defined in the open and available for others to implement. Firefox OS is the first platform that uses them; the below screencast explains more:

+ +

+ +

More information about Web APIs:

+ + + +

Web Activities

+ +

Web Activities are an alternative way to access the hardware of a device. Instead of getting an API to speak to the device directly, Web Activities allow you to create an ecosystem of applications on the device that talk to each other and share capabilities. For example, instead of trying to access the camera directly, your app can use a Web Activity to ask for an image and the user of the device can use their favourite application to take a photo, which is then returned to the app that requested it.

+ +

Instead of asking the users for access to their hardware (which is important in terms of security), you allow them to use applications they already trust to carry out such functions. Furthermore, you can register your application as the go-to application for certain tasks in the operating system. You can think of Web Activities as being equivalent to right/Ctrl + clicking on a file in a Desktop OS and choosing which application to open the file with. You are given several choices, plus on option to tell the OS to always use this app to open this file type from now on.

+ +

Web Activities allow apps to talk to each other — on the device, without any need for a server in between. All they transmit from one app to the other is the final data.

+ +

+ +

More information about Web Actitivies:

+ + + +

Push Notifications

+ +

Push Notifications — invoked using the SimplePush Web API — are a way to make applications wake up when a device receives a certain message. This allows you to build applications that can stay closed — thus saving battery — until they are needed. Notifications created this way also have the benefit of carrying no data, thus Mozilla will never get the information of your app and attackers won't be able to listen in.

+ +

+ +

More information about Push Notifcations using SimplePush:

+ + + +

Offline functionality

+ +

Apps are not much use if they don't work offline. That's partly why users prefer installed apps to just opening a browser and looking for content on their device's web browser; the term "web application" even sounds like it needs a web connection to be usable. Our users will be offline sometimes — on a plane, underground or with no data left on their SIM — and we need to ensure that our apps are still usable when this happens. HTML5 offers a few technologies that allow for offline functionality, mainly AppCache and DOMStorage.

+ +

+ +

More information about offline functionality:

+ + + +

Where to find more

+ +

We hope that this video series gave you a clear introduction to building your first open web apps. If you are interested in learning more, there are a few resources and channels you can use:

+ +

+ + + +

Hope to see you there,

+ +

Chris, Sergi and Jan

diff --git a/files/zh-cn/archive/b2g_os/security/application_security/index.html b/files/zh-cn/archive/b2g_os/security/application_security/index.html new file mode 100644 index 0000000000..cb986bfc9d --- /dev/null +++ b/files/zh-cn/archive/b2g_os/security/application_security/index.html @@ -0,0 +1,126 @@ +--- +title: 应用安全 +slug: Archive/B2G_OS/Security/Application_security +translation_of: Archive/B2G_OS/Security/Application_security +--- +
+

本文对Firefox OS 应用安全进行了详细阐述。

+
+

由Firefox OS 引入的关键性Web应用控制包含如下几个方面: 

+ +

应用安全

+

FirefoxOS 支持三种类型的web应用: "web", "privileged" 以及 "certified".一个应用的类型是在它的  manifest 中声明的,同时也就决定了它能请求的权限列表。 

+ +
+

注意: 要进一步的了解这三种类型,可以参考 App Manifest 文档。

+
+

应用交付

+

在Firefox OS 中,应用可以通过托管和打包这两种不同的机制交付。常规的web应用可以使用任何一种方式交付,而 privileged 和 certified 应用则必须要打包才能交付。

+

托管的应用

+

托管的应用程序中在开发者web服务器中只包含一个应用程序manifest文件,而这个文件会指向应用的index文件(通常会被称作安装路径)。通常manifest文件也会指向一个appcache manifest文件:这个文件会将应用的信息缓存起来,从而使应用启动时更加快速而且能够离线使用;同时这个文件在其他方面则不会对应用造成任何影响。 从安全的角度来看,托管的应用更像是通常的web站点。当托管应用加载时,加载页面的URL其实就是这些页面在它们web服务器的一般的URL地址。因此要链接应用中一个特定的页面或资源, 使用的URL地址与在web站点链接到那个页面的URL地址是相同的。

+

打包的应用

+

一个打包的应用 是一个开放的Web应用,会在本地zip文件中存放有关应用的所有资源(包括  HTML, CSS, JavaScript, app manifest 等) contained in a zip file, 而不是将资源存放在web服务器上。要了解更多的细节,可参考 Packaged apps

+

应用安装

+

应用是通过 Apps Javascript API 来安装的:

+ +

为了能保证一个应用能够想要作为一个web应用来安装,我们必须确保不能使一个网站假冒托管的应用程序清单。 我们会要求manifest要提供一个具体的mime-type application/x-web-app-manifest+json。当manifest应用和和应用 manifest请求的页面相同,都是请求应用安装的页面时,这种限制才是放开的。

+

更新

+

有关应用更新的过程是在 Updating apps 有详细描述。

+

权限

+

应用可以被授予在正常的网页最高权限之外的权限。默认情况下,应用会和正常的web页面拥有同样的权限,为了能够得到额外的权限,第一步就是在应用程序maifest文件中列出它想要的额外权限。 

+

Manifest 声明

+

对每一个应用需要的额外权限,manifest文件必须要在manifest中列出该权限,并且以人类可阅读的描述解释为什么应用需要访问这个权限。例如,如果应用需要使用 navigator.geolocation API, 它就必须在manifest中如下声明:

+
"permissions": {
+  "geolocation":{
+    "description": "Required for autocompletion in the share screen",
+  }
+},
+
+

This allows the app to then prompt for the geolocation permission, in the same way that a web page normally would. For further detail on manifests, see App manifest.

+
+

Note: Currently permissions usage intentions are not exposed to the user — see bug 823385.

+
+

授予权限

+

When permissions are requested in the manifest, the permission is either set to allow or prompt, depending on the permissions. Allow permissions are granted by virtue of being declared in the manifest with no further approval needed. For prompt permissions, the user is prompted the first time the user accesses the related API, and has to make a choice prior to the API being granted. In general, Firefox OS only prompts users for permissions that have a privacy impact, and it is reasonable for the user to understand what they are being asked. For example, access to contacts is prompted, but access to make a raw TCP connection is implicitly granted since it is not reasonable for a user to understand the security implications of allowing this permission. Use of allow permissions is reviewed as part of Marketplace security review processes to ensure users are protected.

+

撤销权限

+

Users are allowed to change their mind about prompt permissions at any time, and can revoke these permissions via the Firefox OS settings app. Allow permissions are not user configurable, however.

+

Web 应用沙箱

+

Data stored per app

+

Each app runs in as a separate sandbox, meaning that all data stored by an app is separate from all data stored by another app. This includes things like cookie data, localStorage data, indexedDB data, and site permissions.

+

A diagram showing three Firefox OS apps all open is separate sandboxes, so none of them can affect each other.

+

This means that if the user has two apps installed, App A and App B, these apps will have a completely different set of cookies, different local data, and different permissions. This even applies if both of these apps open an <iframe> that points to the same origin. i.e. if both App A and App B open an <iframe> pointing to "http://www.mozilla.org", they will both render the website, however the website will be fetched and rendered with different cookies in the two apps.

+

A result of this is that if the user logs in to, for example, Facebook while using App A, this in no way affects App B's ability to interact with the user's account on Facebook. The login cookie that Facebook sets when the user logs in using App A is only available in App A. If App B opens an <iframe> to Facebook, the cookie wouldn't be there and so when App B opens Facebook, it receives the Facebook login page rather than the user's account.

+

Apps can't open each other

+

This means that apps can't open other apps by using iframes. If App A creates an <iframe> with the src set to the URL of App B, this won't actually open App B in the <iframe>. It will simply open the website located at that URL. It will not use any of App B's cookies and so it will behave no differently than if App B wasn't installed on the user's device.

+

This applies even for packaged apps (more about them below). If App A tries to open the packaged App B using an <iframe> pointing to the app:// URL of App B, this will simply fail to load. If this results in a 404 or some other type of error is still to be determined, but it will definitely fail to load. And it will fail in the same way no matter if App B is installed on the user's device or not, as to make it impossible for App A to determine if App B is installed.

+

The same thing happens if the top-level frame of App A is navigated to a URL for App B. We always know for a given frame which app is opened in it, therefore when attempting to load the App B URL in the App A frame, this will behave exactly like the two situations described above, i.e. in no way will App B's resources, like cookies or other local data, be used.

+

Motivation

+

There are both benefits and downsides to this approach. The downside is that if the user interacts with the same web site through several apps, he/she will have to log in to every app. Likewise, if a web site wants to store data locally, and the user interacts with this web site in several apps, the data will end up getting duplicated in each app, which could be a problem if it's a large amount of data.

+

The main benefit of this approach is that it's a more stable model. There is no way that several apps could interact with each other through a third-party website in unexpected ways such that installing an app causes another app to stop working. When an app is uninstalled there is no way that data for another app could be lost, or that another app will stop working due to functional dependence on the uninstalled app.

+

There are also large security benefits. A user can safely use his AwesomeSocial app to log in to Facebook without having to worry that the SketchGame app can mount any type of attack for getting at the user's Facebook data by exploiting bugs or other shortcomings in the Facebook web site.

+

There are also good privacy benefits. The user can safely install the PoliticalPartyPlus app without having to worry that MegaCorpEmployeeApp will be able to detect that the app was installed or what data it has created.

+

Sandboxed 权限

+

In the same way that web site data is sandboxed per app, so is permission data. If App A loads a page from http://maps.google.com and that page requests to use geolocation and the user says "yes, and remember this decision for all times", this only means that http://maps.google.com has access to geolocation within App A. If App B then opens http://maps.google.com, that page won't have access to geolocation unless the user grants that permission again.

+

And just like in the normal browser, permissions are separated by origin. If App A is granted permission to use Geolocation, this does not mean that all origins running in App A have the permission to use Geolocation. If App A opens an <iframe> to http://maps.google.com, then http://docs.google.com still has to ask the user for permission before geolocation access is granted.

+

浏览器 API 沙箱

+

To additionally secure applications that open a large set of URLs, such as browsers, we have added a browserContent flag. The browserContent flag allows each app to have not one, but two sandboxes: one for the app itself, and one for any "web content" that it opens. For example:

+

Say that the MyBrowser app is loaded from the https://mybrowser.com domain. This is the domain the scripts and resources are loaded within. The scripts and resources + + belong + to this domain.

+

Now, if a page in this app creates an <iframe mozbrowser>, a different sandbox is created and used for this <iframe>, which is different from the sandbox used by the app. So for example if this <iframe> is navigated to https://mybrowser.com, it will result in different cookies being used inside the <iframe mozbrowser>. Likewise, the contents inside the <iframe mozbrowser> will see different IndexedDB and localStorage databases from the ones opened by the app.

+

This also applies if the MyBrowser app wants to create integration with, for example, Google Maps to implement location-based browsing. If the app opens an <iframe> to http://maps.google.com, it will receive a set of cookies for the http://maps.google.com website. If the user then navigates inside the <iframe mozbrowser> containing http://maps.google.com, this will use different cookies and different permissions to the top level app.

+

Another example where this is useful is in a Yelp-like app. Yelp has the ability to visit a restaurant's website directly in the app. By using <iframe mozbrowser> to open the restaurant website, the Yelp app ensures that the restaurant website can't contain an <iframe> pointing back to Yelp's app (which points to http://yelp.com). If it does, the website will only receive the Yelp website, rather than the Yelp app. So there is no way that the restaurant website can mount an attack against the app since the contained Yelp website won't share any permissions or data with the Yelp app.

+

应用安全小结

+

The table below summarizes the different types of Firefox OS apps, and describes the format, installation, and update processes for open web apps running on Firefox OS.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Web App Types
TypeDeliveryPermission ModelInstallationUpdates
WebHosted or PackagedLess sensitive permissions, which are not dangerous to expose to unvalidated web content.Installed from anywhereCan be updated transparently to user or explicitly via a marketplace, depending on where the app was installed from, and the delivery mechanism.
PrivilegedPackaged & SignedPrivileged APIs requiring validation and authentication of the app.Installed from a trusted marketplaceUpdated via a trusted marketplace, user prompted to approve download and installation of updates.
CertifiedPackagedPowerful and dangerous APIs not available to third-party apps.Pre-installed on the deviceUpdated only as part of system level updates.
+
+

Note: For version 1.0 of Firefox OS, although web apps can be installed from any website/marketplace, privileged apps can only be installed from the Mozilla Marketplace, as support for multiple trusted marketplaces is not yet complete.

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/security/index.html b/files/zh-cn/archive/b2g_os/security/index.html new file mode 100644 index 0000000000..18730f4b81 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/security/index.html @@ -0,0 +1,70 @@ +--- +title: Firefox OS security +slug: Archive/B2G_OS/Security +tags: + - B2G + - Firefox OS + - Mobile + - NeedsTranslation + - Security + - TopicStub +translation_of: Archive/B2G_OS/Security +--- +

下面文章介绍了 Firefox OS 安全相关的主题。其中包括安全特征概要,应用安全以及如果使安装进程保证安全。

+ + + + + + + +
+

Firefox OS 安全文档 

+
+
+ Firefox OS 安全模型
+
+ Firefox OS 安全模型
+
+ 系统安全
+
+ FirefoxOS 运行时内部的安全控制细节
+
+ Firefox OS 中的应用安全
+
+ 在 Firefox OS 如何使应用安全概要
+
+ 安全安装和更新应用
+
+ Firefox OS 如何安全的安装和更新应用
+
+ 对 Firefox OS 的调试和安全测试 
+
+ 本指南介绍了基本的安全测试步骤,从打开远程的 JavaScript 调试器到在Firefox OS 桌面版本中设置一个拦截 HTTP(S) 代理
+
+

查看全部...

+
+

从社区获得帮助

+

如果您正在为 Firefox OS 工作或者开发一个运行在 Firefox OS 设备上的应用,这里有一些社区资源可以帮助您!

+ +

不要忘记提问的艺术...

+
+ + +
+

 

+
+
+ Firefox OS
diff --git a/files/zh-cn/archive/b2g_os/security/security_model/index.html b/files/zh-cn/archive/b2g_os/security/security_model/index.html new file mode 100644 index 0000000000..f7c2247523 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/security/security_model/index.html @@ -0,0 +1,285 @@ +--- +title: Firefox OS security overview +slug: Archive/B2G_OS/Security/Security_model +tags: + - B2G + - Firefox OS + - IPC + - IPDL + - Mobile + - 安全 + - 指南 +translation_of: Archive/B2G_OS/Security/Security_model +--- +
+

本文对 Mozilla Firefox OS 安全架构进行了概述,包括包括保护移动设备不受平台, apps 和 数据的威胁。在 Firefox OS 中,Mozilla 实现了完整,多层次的安全模型,为移动电话提供了绝佳的防护效果。

+
+

平台安全

+

Firefox OS 平台使用了多层次的安全模型,可将各层级的开发风险降至最低。第一线的保护机制与深入防护策略相结合,进而为移动电话提供了完成的防护效果。

+

安全架构

+

Firefox OS 将基于网页的应用与底层的硬件结合起来了。这个集成技术栈包括下面几个等级:

+

+ +

Gecko 扮演的是守门人的角色,为避免对移动设备的误用,它会强制执行安全策略。 Gecko 层 web  apps(Gaia 层)与 手机之间的中间阶层。Gonk 则可将移动手机底层的硬件功能直接给 Gecko 层使用。 只有在 Gecko 允许访问请求时, Web apps 才可以通过 Web APIs 访问移动手机的功能 — 而不会有直接存取或走后门的情况产生。Gecko 会强制执行权限并阻止对未授权请求的访问。

+

部署安全系统

+

将 Firefox OS 安装在智能手机上。原始系统的镜像文件是由已知,可信任的源所创建的 — 通常是设备 OEM — 它主要负责装配 构建 测试对发布包进行签名。

+

整个技术层都需要经过安全验证。文件系统权限检查是由 Linux's 访问控制清单 (ACLs) 所强制执行的。系统应用都安装在一个只读的空间中(除了更新过程外,这是可能是短暂的可读写的);一般而言,只有包含用户内容的区域才可能可读写。Various components within the device hardware have built-in protections that are implemented by default as standard industry practice — chipset manufacturers, for example, employ hardening techniques to reduce vulnerabilities. The core platform (Gecko and Gonk) is hardened to strengthen its defense against potential threats, and hardening features of the compiler are used where applicable. For further details see Runtime security.

+

更新安全系统

+

Subsequent upgrades and patches to the Firefox OS platform are deployed using a secure Mozilla process that ensures the ongoing integrity of the system image on the mobile phone. The update is created by a known, trusted source — usually the device OEM — that is responsible for assembling, building, testing, and digitally signing the update package.

+

System updates can involve all or a portion of the Firefox OS stack. If changes to Gonk are included in the update, then FOTA (Firmware Over the Air) is the install process used. FOTA updates can also include any other part of the Firefox OS stack, including device management (FOTA, firmware / drivers), settings management (Firefox OS settings), security updates, Gaia, Gecko, and other patches.

+

Updates that do not involve Gonk can be done using the Mozilla System Update Utility. Firefox OS uses the same update framework, processes, and Mozilla ARchive (MAR) format (used for update packages) as the Firefox Desktop product.

+

A built-in update service — which may be provided by the OEM — on the mobile phone periodically checks for system updates. Once a system package becomes available and is detected by the update service, the user is prompted to confirm installation. Before updates are installed on the mobile device, the device storage is checked for sufficient space to apply the update, and the distribution is verified for:

+ +

在更新过程中会使用下面的安全措施:

+ +

Rigorous checks are in place to ensure that the update is applied properly to the mobile phone.

+
+

Note: For more information on how thee updates work and how to create and distribute updates, read Creating and applying Firefox OS update packages.

+
+

App 安全

+

Firefox OS uses a defense-in-depth security strategy to protect the mobile phone from intrusive or malicious applications. This strategy employs a variety of mechanisms, including implicit permission levels based on an app trust model, sandboxed execution at run time, API-only access to the underlying mobile phone hardware, a robust permissions model, and secure installation and update processes. For technical details, refer to Application security.

+

In Firefox OS, all applications are web apps — programs written using HTML5, JavaScript, CSS, media, and other open web technologies (pages running within the browser are not referred to as web apps in this context). Because there are no binary ("native") applications installed by the user, all system access is mediated strictly through the Web APIs. Even access to the file system happens only through Web APIs and a back-end SQLite database — there is no direct access from apps to files stored on the SD card.

+

Firefox OS limits and enforces the scope of resources that can be accessed or used by an app, while also supporting a wide range of apps with varying permission levels. Mozilla has implemented tight control over what type of applications can access which APIs. For example, only certified apps (shipped with the phone) can have access to the Telephony API. The Dialer app has privileges to access the Telephony API in order to make phone calls, but not all certified apps can access this API.

+

This prevents a situation, for example, in which an arbitrary third-party app gets installed, dials a pay-per-use phone number (900 and 910), and racks up a large cell phone bill.

+

Other OEM apps might be selectively given access to the Telephony API, however. For example, an operator might provide a systems management application that allows a customer to manage their account, including the ability to phone the Operator’s billing or support office directly.

+

受信任(Trusted)和不受信任 (Untrusted)的 App

+

Firefox OS 根据下面的类型对 app 进行分类

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+

Type

+
+

Trust Level

+
+

Description

+
+

Certified

+
+

Highly Trusted

+
+

System apps that have been approved by the Operator or OEM (due to risk of device corruption or risk to critical functionality). System apps and services only; not intended for third-party applications.
+ This designation is reserved for just a small number of critical applications. Examples: SMS, Bluetooth, camera, system clock, telephony, and the default dialer (to ensure that emergency services are always accessible).

+
+

Privileged

+
+

Trusted

+
+

Third-party apps that have been reviewed, approved, and digitally signed by an authorized Marketplace.

+
+

Web (everything else)

+
+

Untrusted

+
+

Regular web content. Includes both installed apps (stored on the mobile phone) and hosted apps (stored remotely, with only an app manifest stored on the mobile phone). The manifest for hosted apps can be obtained through a Marketplace.

+
+

An application’s trust level determines, in part, its ability to access mobile phone functionality.

+ +

Some operations, such as network access, are assumed to be an implicit permission for all apps. In general, the more sensitive the operation (for example, dialing a phone number or accessing the Contacts list), the higher the app trust level required to execute it.

+
+

注意: for more information on the APIs available and their permission levels, consult App permissions.

+
+

Principle of Least Permissions

+

For web apps, the Firefox OS security framework follows the principle of least permissions: start with the absolute minimum permissions, then selectively grant additional privileges only when required and reasonable. By default, an app starts with very low permissions, which is comparable to untrusted web content. If the app makes Web API calls that require additional permissions, it must enumerate these additional permissions in its manifest (described later in this document). Gecko will consider granting Web API access to an application only if the applicable privileges are explicitly requested in its manifest. Gecko will grant the requested permission only if the type of the Web App (certified, trusted, or web) is sufficiently qualified for access.

+

Review Process for Privileged Apps in the Marketplace

+

In order for an app to become privileged, the app provider must submit it for consideration to an authorized Marketplace. The Marketplace subjects the app to a rigorous code review process: verifying its authenticity and integrity, ensuring that requested permissions are used for the purposes stated (in the permission rationale), verifying that the use of implicit permissions is appropriate, and validating that any interfaces between privileged app content and unprivileged external content have the appropriate mitigations to prevent elevation of privilege attacks. The Marketplace has the responsibility to ensure that the web app will not behave maliciously with the permissions that it is granted.

+

After an app passes this review, it is approved for use, its app manifest is digitally signed by the Marketplace, and it is made available for mobile users to download. The signature ensures that, if the web store were somehow hacked, the hacker could not get away with installing arbitrary content or malicious code on users’ phones. Due to this vetting process, Firefox OS gives privileged apps obtained from a Marketplace a higher degree of trust than everyday (untrusted) web content.

+
+

Note: to find out more about Marketplaces including the Firefox Marketplace, go to the Marketplace zone.

+
+

封装式(Packaged)和托管式(Hosted) Apps

+

Apps for Firefox OS can be either packaged (stored on the mobile phone) or hosted (stored on a remote web server, with just a manifest stored on the mobile phone). There are some differences in the way in which security is managed for each. Nonetheless, packaged and hosted apps are both subject to application sandboxing, which is described later in this document.

+
+

Note: You can find out more about hosted and packaged apps at App publishing options.

+
+

封装式(Packaged) Apps

+

A packaged app consists of a ZIP file containing application resources (HTML5, CSS, JavaScript, images, media), as well as a manifest that provides an explicit list of assets and their corresponding hashes. Certified and privileged apps must be packaged apps because the app manifest needs to be digitally signed. When a user obtains a packaged app, the ZIP file is downloaded onto the mobile phone, and the manifest is read from a known location inside the ZIP file. During the install process, app assets are verified and remain stored locally in the package. All explicit permissions are requested at runtime, showing the user the app's data usage intentions, and persisted by default.

+

To refer to app resources in a packaged app, the URL begins with app: using the following format:

+

app://identifier/path_within_zipfile/file.html

+

where app:// represents the mount point for the ZIP file, and identifier is a UUID that is generated when the app is installed on the mobile phone. This mechanism ensures that resources referred to with an app: URL are contained in the ZIP file. The path within an app: is relative, so relative links to resources in the ZIP file are allowed.

+

While packaged apps are primarily intended to be used for Certified or Privileged apps, regular web apps can also be packaged. However, they do not gain any increase in trust or permissions access simply because they are packaged.

+

托管式(Hosted) Apps

+

Hosted apps are located on a web server and loaded via HTTP. Only the app manifest is stored on the mobile phone. Everything else is stored remotely. Certain APIs are available only to privileged and certified apps, which requires the app to be packaged due to signing requirements. Therefore, a hosted app will not have access to any of the Web API operations that require privileged or certified app status.

+

From a security point of view, hosted apps work very much like normal websites. A hosted app is loaded by invoking a hard-coded, fully-qualified URL that points to the startup page in the root directory of the app on that web server. Once a hosted app is loaded, the mobile phone links to pages using the same URLs that are used when browsing the web site.

+

App Manifest

+

An Open Web App manifest contains information that a Web browser needs in order to interact with an app. A manifest is a JSON file with (at a minimum) a name and description for the app. For further details, refer to FAQs about app manifests.

+

Manifest 示例

+

The following code listing shows an example manifest with just basic settings:

+
{
+  "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"
+}
+

App Manifest 的安全设置

+

The manifest can also contain other settings, including the following security settings:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+

Field

+
+

Description

+
+

permissions

+
+

Permissions required by the app. An app must list every Web API it intends to use that requires user permission. Most permissions make sense for privileged apps or certified apps, but not for hosted apps. Properties per API:

+
    +
  • description: A string specifying the intent behind requesting use of this API. Required.
  • +
  • access: A string specifying the type of access required for the permission. Implicit permissions are granted at install time. Required for only a few APIs. Accepted values: read, readwrite, readcreate, and createonly.
  • +
+
+

installs_allowed_from

+
+

The Origin of the app; can be singular or an array of origins (scheme+unique hostname) that are allowed to trigger installation of this app. Allows app providers to restrict installs from only an authorized Marketplace (such as https://marketplace.firefox.com/).

+
+

csp

+
+

Content Security Policy (CSP). Applied to all pages loaded in the app. Used to harden the app against bugs that would allow an attacker to inject code into the app. If unspecified, privileged and certified apps have system-defined defaults. Syntax:
+ https://developer.mozilla.org/en-US/docs/Apps/Manifest#csp

+

Note that this directive can only increase the CSP applied. You cannot use it, for example, to reduce the CSP applied to a privileged App.

+
+

type

+
+

Type of application (web, privileged, or certified).

+
+

Firefox OS requires that the manifest be served with a specific mime-type (application/x-web-app-manifest+json) and from the same fully-qualified host name (origin) from which the app is served. This restriction is relaxed when the manifest app (and thus the app manifest) is same-origin with the page that requested the app to be installed. This mechanism is used to ensure that it's not possible to trick a website into hosting an application manifest.

+

沙盒技术 Sandboxed Execution

+

This section describes application and execution sandboxes.

+

Application Sandbox

+

The Firefox OS security framework uses sandboxing as a defense-in-depth strategy to mitigate risks and protect the mobile phone, platform, and data. Sandboxing is a way of putting boundaries and restrictions around an app during run-time execution. Each app runs in its own worker space and it has access only to the Web APIs and the data it is permitted to access, as well as the resources associated with that worker space (IndexedDB databases, cookies, offline storage, and so on).

+

The following figure provides an overview of this security model.

+

+

By isolating each app, its impact is contained within its own worker space and it cannot interfere with anything (such as other apps or their data) outside of that worker space.

+

Execution Sandbox

+

B2G (Gecko) runs in a highly-privileged system process that has access to hardware features in the mobile phone. At runtime, each app runs inside an execution environment that is a child process of the B2G system process. Each child process has a restricted set of OS privileges — for example, a child process cannot directly read or write arbitrary files on the file system. Privileged access is provided through Web APIs, which are mediated by the parent B2G process. The parent ensures that, when a child process requests a privileged API, it has the necessary permission to perform this action.

+

Apps communicate only with the B2G core process, not with other processes or apps. Apps do not run independently of B2G, nor can apps open each other. The only “communication” between apps is indirect (for example, when one app sets a system alarm and another app triggers a system notification as a result of it), and is mediated through the B2G process.

+

仅通过 Web API 才能硬件访问

+

Web apps have only one entry point to access mobile phone functionality: the Firefox OS Web APIs, which are implemented in Gecko. Gecko provides the sole gateway to the mobile device and underlying services. The only way to access device hardware functionality is to make a Web API call. There is no “native” API and there are no other routes (no “back doors”) to bypass this mechanism and interact directly with the hardware or penetrate into low-level software layer.

+

安全基础架构

+

The following figure shows the components of the Firefox OS security framework:

+

+ +

权限管理与执行

+

Firefox OS security is designed to verify and enforce the permissions granted to web apps.

+

The system grants a particular permission to an app only if the content requests it, and only if it has the appropriate permissions requested in the app’s manifest. Some permissions require further authorization from the user, who is prompted to grant permission (as in the case of an app requesting access to the user’s current location). This app-centric framework provides more granular control over permissions than traditional role-centric approaches (in which individual roles are each assigned a set of permissions).

+

A given Web API has a set of actions and listeners. Each Web API has a required level of permission. Every time a Web API is called, Gecko checks permission requirements (role lookup) based on:

+ +

If the request does not meet the permission criteria, then Gecko rejects the request. For example, untrusted apps cannot execute any Web APIs that are reserved for trusted apps.

+

要求用户权限许可

+

In addition to permissions that are implicitly associated with the web apps, certain operations require explicit permission from the user before they can be executed (for example, "can the web app access your camera?"). For these operations, web apps are required to specify, in their manifest, their justification for requiring this permission. This data usage intention informs users about what the web app intends to do with this data if permission is granted, as well as any risk involved. This allows users to make informed decisions and maintain control over their data.

+

安全 App 更新过程

+

+

For app upgrades and patches to a privileged app, app providers submit the updated package to an authorized Marketplace, where it is reviewed and, if approved, signed and made available to users. On Firefox OS devices, an App Update Utility periodically checks for app updates. If an update is available, then the user is asked whether they want to install it. Before a update is installed on the mobile device, the package is verified for:

+ +

Rigorous checks are in place to ensure that the update is applied properly to the mobile phone. The complete update package must be downloaded in a specific and secure location before the update process begins. Installation does not overwrite any user data.

+
+

Note: For more information on app updates, read Updating apps.

+
+

设备安全 (硬件)

+

Security mechanisms for the mobile device hardware are typically handled by the OEM. For example, an OEM might offer SIM (Subscriber Identity Module) card locks, along with PUK (PIN Unlock Key) codes to unlock SIM cards that have become locked following incorrect PIN entries. Contact your OEM for details. Firefox OS does allow users to configure passcodes and timeout screens, which are described in the next section.

+

数据安全

+

Users can store personal data on their phone that they want to keep private, including contacts, financial information (bank & credit card details), passwords, calendars, and so on. Firefox OS is designed to protect against malicious apps that could steal, exploit, or destroy sensitive data.

+

密码和超时锁屏

+

Firefox OS allows users to set a passcode to their mobile phone so only those who supply the passcode can use the phone. Firefox OS also provides a timeout screen that is displayed after a configurable period of phone inactivity, requiring passcode authentication before resuming use of the phone.

+

沙盒数据 Sandboxed Data

+

As described earlier, apps are sandboxed at runtime. This prevents apps from accessing data that belongs to other apps unless that data is explicitly shared, and the app has sufficient permissions to access it.

+

串行数据 Serialized Data

+

Web apps do not have direct read and write access to the file system. Instead, all access to storage occurs only through Web APIs. Web APIs read from, and write to, storage via an intermediary SQLite database. There is no direct I/O access. Each app has its own data store, which is serialized to disk by the database.

+

数据破坏

+

When a user uninstalls an app, all of the data (cookies, localStorage, IndexedDB, and so on) associated with that application is deleted.

+

隐私

+

Mozilla is committed to protecting user privacy and user data according to its privacy principles (https://www.mozilla.org/privacy/), which stem from the Mozilla Manifesto (https://www.mozilla.org/about/manifesto.html). The Mozilla Firefox Privacy Policy describes how Mozilla collects and uses information about users of the Mozilla Firefox web browser, including what Firefox sends to websites, what Mozilla does to secure data, Mozilla data practices, and so on. For more information, see:

+ +

Firefox OS implements these principles by putting the control of the user data in the hands of the user, who gets to decide where this personal information goes. Firefox OS provides the following features:

+ diff --git a/files/zh-cn/archive/b2g_os/simulator/index.html b/files/zh-cn/archive/b2g_os/simulator/index.html new file mode 100644 index 0000000000..908b5a4049 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/simulator/index.html @@ -0,0 +1,240 @@ +--- +title: Firefox OS 模拟器 +slug: Archive/B2G_OS/Simulator +translation_of: Archive/B2G_OS/Simulator +--- +
+

Firefox OS 模拟器目前还处于开发早期,还没有那么我们想的那么稳定和功能齐备。

+

如果你发现了bug,请 在 GitHub 上面提交,如果你有任何问题,可以在 dev-developer-tools 邮件列表 或者 irc.mozilla.org 上的 #devtools on 提问。

+

你还可阅读“获取帮助”章节中的 how to enable verbose loggingget the latest preview build

+
+

Firefox OS 模拟器(Simulator)给你提供一个在桌面系统下测试和调试 Firefox OS 应用的环境,使得 code-test-debug(编码-测试-调试)的流程比使用实体设备更加快捷。当然你并不需要一个实体设备来运行这个模拟器。

+

本质上来讲,模拟器是由下面两个部分组成的:

+ +

下面的这个截图展示了一个使用模拟器调试应用的过程。

+

右上的那个截图是信息中心,它运行在一个Firefox 标签页中。 我们已经添加了一个名为“where am I?" 的打包应用。左上截图显示的是该应用正运行在模拟器中。而且我们也连接了调试工具,也就是底部的那个面板。可以看到控制台面板显示了有关该应用的一些信息。

+

+

该指南包含了下面的内容:

+ +
+ 想从头到尾了解如何使用模拟器调试Web应用,请参见 Firefox OS 简易攻略 一文。
+

安装模拟器

+

模拟器是以Firefox 附加组件的形式打包和分发的。安装步骤:

+
    +
  1. 使用Firefox访问 the Simulator's page on addons.mozilla.org
  2. +
  3. 点击 "添加到Firefox(Add to Firefox)"。
  4. +
  5. 下载完成后会提示你是否需要安装,点击:  "现在安装(Install Now)".
  6. +
+

鉴于该组件的体积,在安装过程中,Firefox可能会出现假死的情况。可能会出现一个对话框"警告:script无响应(Warning: Unresponsive script)"。加入你看到该对话框,点击"继续"以完成安装。这种情况不会在Firefox27以上版本中出现。

+

安装完成后,Firefox会检查是否有该组件的更新版本,如果有的话,会自动更新至最新版本。

+

安装完成后,信息中心会自动打开。当然你也可以从"Firefox" 菜单(或者“工具“菜单)-Web开发者-Firefox OS 模拟器打开。

+

+

通过信息中心,你可以把你的应用添加到模拟器并且运行该应用。下面的截图就是信息中心的样子:

+

添加,移除和刷新应用

+

添加应用

+

怎样把打包应用添加到模拟器?打开信息中心,点击 "添加文件夹(Add Directory)" ,然后选择 manifest 文件
+
+ 如果要添加基于服务器端的 Web 应用(hosted app),在有”URL for page or manifest.webapp"提示的输入框中输入,然后点击“添加 URL”(Add URL). 如果链接指向的是manifest文件,那么就会使用这个manifest文件。如果链接指向的不是manifest文件,信息中心就会为该URL生成一个manifest文件: 所以通过输入网站的URL,你就可以把该网站以应用的形式添加进来。

+

在你添加应用之后,信息中心对你的manifest文件进行一系列的测试,查找一些常见的问题。具体会进行那些测试,参阅 Manifest Validation(Manifest 验证)。

+

如果在Manifest验证阶段没有发现任何错误,信息中心则会在模拟器中自动运行你的应用。

+

管理应用

+

在你添加应用之后,该应用会出现在已安装应用的管理列表中:
+
+ 每条记录都告诉我们关于应用的一些信息:

+ +

同时我们也可以看到4个命令:

+ +
+

在模拟器窗口中刷新应用: 在应用运行的状态下,通过模拟器窗口的 菜单或者是与之绑定的快捷方式 更新和重新加载该应用。

+
+

Manifest 验证

+

加入你提供了 manifest 文件,管理器会对该文件进行一些验证并且会针对下列3类问题给出报告:

+ +

这些问题会列出来,点击错误提示你会看到这些问题的详细信息。

+

Manifest 错误

+

信息中心会把下列情形当成错误,意味着如果不修复他们就无法运行你的的应用:

+ +

这里是尝试添加一个没有”name"属性的manifest文件的结果:
+

+

Manifest 警告

+

信息中心会把下列情形当成警告:

+ +

针对模拟器的警告

+

最后,如果应用使用了还没有被Firefox OS完全支持的特性,管理器会对此弹出警告:

+ +

运行模拟器

+

可以通过两种不同的方法启动模拟器:

+ +

不管是哪种方法,只要模拟器一开始运行,标签为“Stopped"按钮就会变成绿色,同时标签也会变成”Running"(运行中)。要停止模拟器的运行,只需要再次点击这个按钮。

+

模拟器会在独立的窗口中运行,屏幕区域为320*480pixels, 在底部的工具栏(toolbar)顶部的菜单栏(menubar) 还包括一些额外的功能:

+

+

你可以通过点击鼠标和按下鼠标键之后的拖拽来模拟触屏事件。所以通过在主屏的点击和从右到左的拖拽,你就会看到内置的应用和你自己添加的应用:

+

+

模拟器工具栏(Simulator toolbar)

+

在底部的工具栏中,从左到右,分别是主屏(Home)按钮, 屏幕旋转(screen Rotation)按钮和地理位置(Geolocation)按钮.

+ +

+

模拟器菜单栏

+

通过顶部的菜单栏,你可以更方便快捷的运行一些有用的命令。这会使你的开发工作更有效率。

+

+ +

键盘上 "App Refresh" 的快捷方式使得从表面上来看开发一个应用就像是开发一个网页(浏览器中刷新一个页面的快捷方式也是Ctrl/Cmd-R):

+ +
+

"刷新应用并清除数据(强制刷新)" 隐藏的快捷方式:有些时候清除掉模拟器存储的应用数据会非常有用。所以模拟器实际上有一个隐藏的快捷方式 Shift - Ctrl/Cmd - R, 该快捷方式在刷新应用的同时,也会清除下列数据:

+ +
+

调用开发者工具

+

在模拟器中你可以调用开发者工具,以帮助你调试应用。目前你可以调用 JavaScript调试器, Web控制台, 样式编辑器, 分析器 以及网络,但是我们会努力支持更多的 开发者工具

+
+

某些工具只适用于Firefox的Beta, Aurora或者是Nightly版本。

+
+

点击应用的 "Connect"(连接)按钮来调用开发者工具

+

+

接着信息中心会在标签页底部打开开发者工具面板,并且连接到该应用:

+

+

Web控制台

+

The app can log to this console using the global console object, and it displays various other messages generated by the app: network requests, CSS and JS warnings/errors, and security errors. (Learn more about the Web Console.)

+

调试器

+

Using the Debugger, you can step through JavaScript code that is running in the connected app, manage breakpoints, and watch expressions to track down errors and problems faster. (Learn more about the Debugger.)

+

样式编辑器

+

You can view and edit CSS files referenced in the app using the connected Style Editor. Your changes will be applied to the app in real time, without needing to refresh the app. (Learn more about the Style Editor.)

+

分析器

+

Using the Profiler tool connected to the app, you can to find out where your JavaScript code is spending too much time. The Profiler periodically samples the current JavaScript call stack and compiles statistics about the samples. (Learn more about the Profiler.)

+

网络监控

+

Thanks to the new Network Monitor, you can analyze the status, headers, content and timing of all the network requests initiated by the app through a friendly interface. (Learn more about the Network Monitor.)

+

收据(Receipts)

+

如果你正在开发付费应用,那么你也应该使用有效(加密签名)的收据测试一下你的收据确认码(receipt validation code) (收据确认码是用来确认一个用户是否已经购买该应用或者用户已申请退款,然后根据这两种情况来锁定或者解锁应用)。

+

通过信息中心的"Receipts" 菜单,你可以安装"Valid"(有效的), "Invalid"(无效的), 或者 "Refunded"(退款) 的测试收据。选择你希望测试的收据类型,信息中心会从市场(Marketplace)的收据服务中心获取该类型的收据,然后在模拟器中重新安装该应用,同时也会安装该收据。:

+

+

推送到设备

+

如果你有安装Firefox OS系统的实体设备,你可以把该设备连接到模拟器,然后可以把应用从信息中心推送到设备上。

+

连接设备

+

关于如何把设备连接到信息中心,请参阅 connecting a Firefox OS device to the desktop. 请注意你并不需要安装ADB(Android Debug Bridge), 因为模拟器的附加组件中已经包含了它。

+

把应用推送到设备

+

在你设置后设备和桌面后,通过USB把设备连接到桌面系统,你会看到"Device connected"(设备已连接)的提示 ,同时你也会看到一个标签为“Push"(推送)的按钮:

+

+

点击 "Push", 应用就会安装到你的Firefox OS 设备上。

+
+

手动操作步骤:

+ +
+

Firefox OS 设备连接确认

+

每次重启设备后的第一次”推送“需要你在设备上确认一下:

+

+

Linux系统下的问题

+

在创建udev规则后,如果你不能连接设备,请参见bug

+

模拟器的局限

+

请注意Firefox OS 模拟器目前并不完美。

+

硬件的局限

+

除了屏幕尺寸外,模拟器无法模拟Firefox OS设备的硬件换件,比如内存,CPU。

+

Audio/video 解码

+

下面列出的编码依赖于硬件加速的解码,所以目前还没被支持:

+ +

这意味目前还无法测试依赖于这些编码的应用以及像Youtube这类网站的视频回放功能

+

不支持的APIs

+

在实体设备上被支持的某些API在模拟器中并没有被支持。通常是因为桌面环境中并没有支持这些API的硬件。我们模拟出了想地理位置的一些API,希望在以后的版本中可以支持更多的API。不管怎么说,目前模拟器尚未支持下面列出的这些API。如果你使用他们,可能会弹出错误或者返回不正确的结果:

+ +

帮助

+

Firefox OS模拟器目前还处于开发的早期阶段,所以在稳定性和功能完整性方面还不尽人意。

+

如果你发现任何bug,请 在GitHub上面提交. 如果你有任何问题,也可以在 dev-developer-tools mailing list 或者 #devtools on irc.mozilla.org 提问。

+

如何启用详细记录

+

使用 about:config 打开偏好设置。
+ extensions.r2d2b2g@mozilla.org.sdk.console.logLevel, 把值设为0,然后 禁用/开启 这个插件。然后关于模拟器运行操作的详细信息就会现在在错误控制台(Error Console) (较新版本的Firefox里面叫浏览器控制台(Browser Console) ).

+

如何获得最新的预览版本

+

正如在 section on installing the Simulator 所解释, 你可以从 addons.mozilla.org获得模拟器的最新版本。.

+

你可能想在我们正式发布前体验最新的特性,那么你可以从下面的链接中获取预览版本:

+ +

但是请注意,相比正式版,预览版并没有被完全测试,在稳定性方面也稍差一些。

diff --git a/files/zh-cn/archive/b2g_os/simulator/simulator_walkthrough/index.html b/files/zh-cn/archive/b2g_os/simulator/simulator_walkthrough/index.html new file mode 100644 index 0000000000..40fee1e3bf --- /dev/null +++ b/files/zh-cn/archive/b2g_os/simulator/simulator_walkthrough/index.html @@ -0,0 +1,269 @@ +--- +title: Firefox OS 模拟器简易攻略 +slug: Archive/B2G_OS/Simulator/Simulator_Walkthrough +translation_of: Archive/B2G_OS/Simulator/Simulator_Walkthrough +--- +

In this page we'll debug a very simple (but very buggy!) web app using the Firefox OS Simulator.

+

The walkthrough is structured into six parts: each part uses a different diagnostic/debugging tool, specifically, manifest validation, the Web Console, the JavaScript Debugger, the Network Monitor, the Style Editor and the Test Receipts.

+

It's intended that each part should be self-contained, so it should be possible to read only that part and have it make sense.

+

Using manifest validation

+
+

If you want to follow along, the various revisions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the whereami-1 version of the app.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

The walkthrough assumes that you've installed the Simulator and opened the Dashboard.

+
+

First we'll add the app to the Dashboard by clicking "Add Directory" and selecting the manifest. We'll see this:

+


+
+ Clicking on "(2 errors and 0 warnings)"  we see this:

+


+ This error message is pretty clear, and if we look at "manifest.webapp", we can see that it's missing a "name":

+
{
+  "description": "A simple web app",
+  "launch_path": "/index.html",
+  "icons": {
+    "128": "/style/icons/earth.png"
+  }
+}
+


+ Add the "name" field to the manifest file, save it, and click "Refresh" in the Dashboard:

+
{
+  "name": "Where am I?",
+  "description": "A simple web app",
+  "launch_path": "/index.html",
+  "icons": {
+    "128": "/style/icons/earth.png"
+  }
+}
+


+ This time the Dashboard should tell us that we have no errors, and should run the app:

+

+

But when you click the button, nothing happens. In the next section, we'll try using the WebConsole to diagnose this problem.

+

Using the WebConsole

+
+

If you haven't followed along from the start of this walkthrough:

+

In this section we'll debug a very simple (but very buggy!) web app using the Firefox OS Simulator. The various versions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the whereami-2 version.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

But in this version, when we click the button nothing happens. In this section of the walkthrough, we'll use the WebConsole to try to diagnose the problem.

+ The walkthrough assumes that you've installed the Simulator, opened the Dashboard, and added the app by clicking "Add Directory" in the Dashboard, then selecting the app's "manifest.webapp" file.
+

Over in the Dashboard, you have to click the button labeled "Connect":

+

+

A Simulator window will open automatically and run the app (if it's not already), and the WebConsole should appear into the Simulator Dashboard tab.

+

In the console output you might see a few errors, warnings, and messages, but the last one in particular looks relevant:
+
+
+
+ This is obviously a problem in our app's script, "whereami.js". Here are the first few lines of the script:

+
var whereami = document.getElementById('whereami');
+
+whereami.onclick = function() {
+  navigator.geolocation.getCurrentPosition(getMap, error);
+};
+


+ Comparing this with our app's "index.html", the problem's obvious:

+
<!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>
+


+ In the HTML, the button is assigned an ID of "where-am-i", but in the JavaScript, we're trying to use "whereami". So let's fix that:

+
var whereami = document.getElementById('where-am-i');
+
+whereami.onclick = function() {
+  navigator.geolocation.getCurrentPosition(getMap, error);
+};
+

Now the app starts up without any errors, but when we click the button, the map doesn't appear, and we get a new message in the WebConsole:

+

+

This message is logged by our "whereami.js" script, and indicates that the geolocation API has returned an error - but it unhelpfully doesn't tell us what the error was. We can use the JavaScript Debugger to figure that out.

+

Using the JavaScript Debugger

+
+

If you haven't followed along from the start of this walkthrough:

+

In this section we'll debug a very simple (but very buggy!) web app using the Firefox OS Simulator. The various versions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the whereami-3 version.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

But in this version, when we click the button the Geolocation API returns an error. In this section of the walkthrough, we'll use the JavaScript Debugger to figure out exactly which error is returned.

+

The walkthrough assumes that you've installed the Simulator, opened the Dashboard, and added the app by clicking "Add Directory" in the Dashboard, then selecting the app's "manifest.webapp" file.

+
+

In the WebConsole connected to the app, click the link on the right of the geolocation error log:

+


+ Clicking on the "whereami.js:8" link, the JavaScript Debugger will be automatically loaded and pointed to the related file and line number.

+

According to the Geolocation API reference, the specific error is given by the code property of the error object that's passed into the error handler error(). So set a breakpoint inside error() by clicking to the left of line 8:

+

+

In the app, click "Where am I?". Execution should stop at the breakpoint:

+

+

Click where it says "Add watch expression" and type "error.code", and you'll immediately see its value, "1":

+


+ According to the Geolocation API documentation, "1" means "Permission denied". This is an error web apps get if they have not requested the geolocation permission, or if the permission wasn't granted by the user.
+
+ Looking at the "manifest.webapp" file, we'll see that we didn't ask for the permission:

+
{
+  "name": "Where am I?",
+  "description": "A simple web app",
+  "launch_path": "/index.html",
+  "icons": {
+    "128": "/style/icons/earth.png"
+  }
+}
+


+ Let's fix that:

+
{
+  "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"
+      }
+  }
+}
+


+ Save "manifest.webapp", and click "Refresh" in the Dashboard one more time. Remember to resume the Debugger as it is still at the breakpoint. This time the app runs, and when you click "Where am I?" it asks you to share your location, and if you allow it, the map doesn't appear and we get a new message in the WebConsole:

+

+

This message indicates that the MapQuest API, which we have included into our app using a tag script, is not loaded correctly. We can use the Network Monitor to figure that out.

+

Using the Network Monitor

+
+

If you haven't followed along from the start of this walkthrough:

+

In this section we'll inspect network request from a very simple (but very buggy!) web app using the Firefox OS Simulator. The various versions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the whereami-4 version.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

But in this version, when we click the button the WebConsole shows a "MQA is not defined" error. In this section of the walkthrough, we'll use the Network Monitor to figure out exactly why the MapQuest API is not loaded.

+

The walkthrough assumes that you've installed the Simulator, opened the Dashboard, and added the app by clicking "Add Directory" in the Dashboard, then selecting the app's "manifest.webapp" file.

+
+
+

Warning: the Network Monitor is available for Firefox >= 23.0 (which is currently Firefox Beta)

+
+

In the Developer Tools panel connected to the app, click the Network tab and the following panel will be presented to you, where you see that requests for the "mqa.toolkit.js" resource from the "open.mapquestap.com" domain are never completed successfully:

+

+

Successful requests are green colored, if we click on one of the requests to the "open.mapquestap.com" domain (dark grey colored) and select the Timings detail panel, we can figure out that the request never reached the Connecting status, because DNS resolution did not succeed.

+

Looking at the "index.html" file, we'll see that the script tag points to the wrong domain.

+

Let's fix this bug, changing the script tag to use the correct domain: open.mapquestapi.com (add the missing 'i' to the domain name):

+
<!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>
+

Save "index.html", and click "Refresh" in the Dashboard one more time. This time the app runs, and when you click "Where am I?" it asks you to share your location, and if you allow it, the app finally displays the map:
+

+

Using the Style Editor

+
+

If you haven't followed along from the start of this walkthrough:

+

In this section we'll customizing the app stylesheets using the Firefox OS Simulator. The various versions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the version whereami-5.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

In this version all the previous bugs are already fixed, and we're going to use the Style Editor to change the style real time on the running app and save it back when we're satisfied.

+

The walkthrough assumes that you've installed the Simulator, opened the Dashboard, and added the app by clicking "Add Directory" in the Dashboard, then selecting the app's "manifest.webapp" file.

+
+
+

Warning: the Style Editor is available for Firefox >= 23.0 (which is currently Firefox Beta)

+
+

In the Developer Tools connected to the app, click the Style Editor tab and the following panel will be presented to you:

+

+

Select "style/style.css" from the style sheets list on the left and make some changes to the CSS rules. The new rules will be applied to the connected app immediately:

+

+

Now you can click on the "Save" link just below "style/style.css" in the style sheets list to save it back into the project.

+

Using the Test Receipts

+
+

If you haven't followed along from the start of this walkthrough:

+

In this section we'll add payment receipt validation code to a web app using the Firefox OS Simulator. The various versions of the app are in the firefoxos-simulator-walkthrough repository on GitHub, and you can pick the walkthrough up at this point by starting with the whereami-6 version.

+

The app displays a single button labeled "Where am I?". When the user clicks the button, the app fetches the user's current location using the Geolocation API, and displays it on a map.

+

In this version we're going to change it to became a paid web app.

+

The walkthrough assumes that you've installed the Simulator, opened the Dashboard, and added the app by clicking "Add Directory" in the Dashboard, then selecting the app's "manifest.webapp" file.

+
+

Now that your app is bug-free and properly styled, you can add payment receipt validation to ensure that users of your app have purchased it.

+

Mozilla has released a small JavaScript library which will help an app check its receipts: http://github.com/mozilla/receiptverifier

+

Let's add receiptverifier to the app, e.g. adding a new script tag to its "index.html" file:

+
<!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>
+

and check the receipts in the "scripts/whereami.js" using the "mozmarket.receipts.Verifier" API (e.g. checking the receipts on the button click or on the app loading):

+
...
+
+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);
+    }
+  });
+};
+
+

Receipts are cryptographically signed (by the Marketplace and the Payment services), but you can use the Simulator to install your app with a test receipt by selecting the type of receipt to install (which defaults to "None") using the "Receipts" menu in the app entry:

+

+

Now you can test how the app will behave with "Valid", "Invalid", and "Refunded" receipts (or when there isn't any receipt) and observe the results by looking at the logs produced by the receiptverifier library in the Web Console:

+

 

+

+

+
+

Note: You can get the completed app from the whereami-7 version.

+
+

 

diff --git a/files/zh-cn/archive/b2g_os/using_firefox_os_simulator/index.html b/files/zh-cn/archive/b2g_os/using_firefox_os_simulator/index.html new file mode 100644 index 0000000000..1abeb853a8 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/using_firefox_os_simulator/index.html @@ -0,0 +1,57 @@ +--- +title: 使用Firefox OS模拟器 +slug: Archive/B2G_OS/Using_Firefox_OS_Simulator +translation_of: Archive/B2G_OS/Simulator +--- +

The Firefox OS Simulator is a desktop platform tool that shows you what apps will look like on a phone that is running the Firefox OS. It is the easiest way to try out apps on Firefox OS before submitting them to the Firefox Marketplace. The Firefox OS Simulator was formerly called "r2d2b2g", but that name is too difficult.

+

The Simulator is packaged as a desktop Firefox add-on. You can use any recent version of Firefox from Firefox 17 onward.

+

Although there are other ways to run the Firefox OS desktop, the best and most convenient way for app developers is this one. If you're a core Firefox OS platform developer, or are working on localization, there are other tools that are better suited for your needs. The Simulator add-on includes support for adding apps to the test environment, and is configured to support remote debugging, remote Web console, and other features. It also provides a visible Home button you can click, and sets the user-agent string to the one used by Firefox OS on devices. The result is, in nearly every way, a better environment for app developers.

+

安装Firefox OS模拟器

+
    +
  1. Using Firefox, go to this link: https://addons.mozilla.org/addon/firefox-os-simulator/
  2. +
  3. Click Add to Firefox. It's a large download. Follow the prompts that appear.
  4. +
+
+

Because of the size of the add-on, Firefox may freeze for several seconds while installing it, and its unresponsive script dialog may appear, due to bug 814505. If it does, just click the Continue button, and Firefox will continue installing the add-on.

+
+

Starting the Simulator

+
    +
  1. On the Firefox menu (Windows) or the Tools menu (Mac, Linux), go to Web Developer and click Firefox OS Simulator. The dashboard appears. +

    Dashboard

    +
  2. +
  3. Click the Stopped button. It changes into the Running button and Firefox OS boots up in its own window. The default size for this window is 320x480. +

    Simulator

    +

    To stop the Simulator, click the Running button in the dashboard, or just close the Simulator window.

    +
  4. +
+
+

Note: You can also start and stop the Simulator in the Developer Toolbar command line using firefoxos start and firefoxos stop.

+
+ +

Imitate swipe motions in the Simulator by clicking and dragging with the mouse. The mouse scroll wheel will move a list up and down, such as in the Settings app. Click and hold down the mouse button to simulate a long press.

+

To get back to the home screen, click the home button at the bottom of the Simulator, or press the Home key on your keyboard. On Mac keyboards without a Home key, use Fn + Left Arrow.

+

Console checkbox

+

Click the Console check box before you start the Simulator to open an error console so you can spot errors that might occur while you're working on your app.

+

Web APIs in the Simulator

+

Mozilla is working on many Web APIs to make native platform capabilities available to Open Web Apps. The Web APIs currently supported in the Simulator are:

+ +

Installing an app in the Simulator

+

To install a hosted app in the Simulator, type the URL to the app's manifest in the URL box, and click Add Manifest. This will install the app in the Simulator. Here is a simple weather app that you can use as a test:

+
http://jlongster.github.com/weatherme/manifest.webapp
+

The app's icon will be added to one of the home screens in the Simulator.

+

You can also install a plain website in the same way. Just type the website's URL in the box and click Add URL, and an icon for the site will be added to a home screen. Autocompletion works if you have the website open in another tab.

+

To install a packaged app in the Simulator, click the Add Directory button, then select the mini-manifest of the app on your local filesystem.

+

To remove an app from the Simulator, click the Remove link for the app in the dashboard. You may have to restart the Simulator to see it gone.

+

Updating an app

+

If you are working on an app and need to update it in the Simulator, click the app's Update button in the dashboard. You will have to restart the Simulator. Hosted apps follow the usual rules for Website caching and working with appcache.

+

Reporting bugs

+

Remember that the Simulator is a brand-new tool and is still heavily under development. Please let us know if you find any bugs.

+

More information

+

The Simulator itself is the Firefox OS desktop client (also called the B2G desktop client), which is a build of Firefox OS that runs on Windows, Mac, and Linux. Firefox OS Simulator makes it easier to test apps on Firefox OS desktop because it includes functionality for adding apps to the environment and is configured/extended in a variety of ways to better meet the needs of app developers.

+

However, because the Simulator uses the Firefox OS desktop client, the documentation for B2G Desktop, Gaia, and B2G generally will also apply to the Simulator to some extent. Here are a couple of those docs:

+

Using the Firefox OS desktop client

+

Hacking Gaia

diff --git a/files/zh-cn/archive/b2g_os/using_the_app_manager/index.html b/files/zh-cn/archive/b2g_os/using_the_app_manager/index.html new file mode 100644 index 0000000000..35b8506eed --- /dev/null +++ b/files/zh-cn/archive/b2g_os/using_the_app_manager/index.html @@ -0,0 +1,183 @@ +--- +title: 使用应用管理器 +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 的测试、布署、调试等工作。

+

App Manager是为使用Firefox OS 1.2 及之后的版本的开发者服务的,如果您正在Firefox OS 1.1 版本上开发app,则需要参考有关Firefox OS 1.1 仿真器的介绍。

+
+

 

+

应用管理器具备下列组件:

+ +

快速设置:

+

本节的目的是让开发者尽快的设置和应用工具。如果你需要一些更详细的资料,则可以请跳过本节,直接从《设备和系统配置》阅读。如遇到任何问题,也可参阅《疑难排除》获取帮助。

+
    +
  1. 确保已安装了桌面版Firefox 26+
  2. +
  3. 打开应用管理器(在地址栏输入 about:app-manager
  4. +
  5. 如果你没有实际的 Firefox OS 设备: +
      +
    1. 安装 Firefox OS 模拟器 (Firefox OS Simulator)
    2. +
    3. 在应用管理器底部的工具栏中,点击“启动模拟器” ,然后再点击模拟器名称(已安装的模拟器均应出现)。
    4. +
    +
  6. +
  7. 如果你拥有 Firefox OS 设备: +
      +
    1. 请确保你的设备运行Firefox OS 1.2+
    2. +
    3. 在Windows上,请安装你的手机制造商提供的驱动程序
    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. 底部工具栏应显示 “连接到: xxx”
  10. +
  11. 点选 “应用”面板 并新增应用(打包或托管应用皆可)
  12. +
  13. “刷新”按钮将验证该 App 并安装到模拟器/设备中
  14. +
  15. 调试按钮连接开发者工具到运行中的 App
  16. +
  17. 如遇到麻烦,请参阅 疑难排除章节以得到更多帮助
  18. +
+

设备和系统配置

+

使用应用管理器前的第一件事,就是要确保你的系统和手机的设定是正确的。接着就是按照本节说明的各个步骤运行。

+

需要Firefox 1.2+

+

请确保你的设备运行Firefox OS1.2/Boot2Gecko1.2或更高版本。要检查当前 Firefox OS 版本,则可进入 Settings > Device Information > Software

+

如果您没有安装足够高版本的 Firefox OS,则你需要根据手机型号的不同,安装 Firefox 1.2+ nightly 版本,或通过源代码配置和构建自己的版本。

+

可用的构建:

+ +
+

注意:要构建自己的 Firefox OS 1.2+,请参阅 编译及安装Firefox OS火狐操作系统 说明,并从 编译Firefox OS的系统需求 着手。

+
+

远程调试

+

接下来,你需要在 Firefox OS 中启用远程调试,开启方法为:进入 Settings > Device information > More information > Developer,并勾选 Remote Debugging 复选框即可。

+

ADB 或 ADB helper

+

通过 Android Debug Bridge (ADB) 连接设备与电脑并通信。有两个运行ADB的方式:

+ +
+

注意:如果安装了 ADB Helper 扩展,就不需执行此指令。

+
+

将设备连接到应用管理器

+

所有配置完成之后,就可将设备连上电脑并启动应用管理器:

+
    +
  1. 通过USB接口连接电脑。
  2. +
  3. 在你设备上禁用锁屏,方法是 Settings > Screen Lock 并 取消 Lock Screen 勾选。这是非常必要的,因为当屏幕锁定后,手机和电脑的连接就会中断,这样就无法调试了。
  4. +
  5. 启动应用管理器(App Manager)  — 在桌面版 Firefox 菜单中点击 Tools > Web Developer > App Manage 启动,或在通过地址栏输入”about:app-manager“启动。
  6. +
  7. 应用管理器标签页底部,会看到连接状态栏(见下图)。您应该能够通过点击“连接到 localhost:6000”按钮即可连线设备。
  8. +
  9. 如连接成功,就会有“An incoming request to permit remote debugging connection was detected. Allow connection?”对话框。点击“OK”钮(你可能需要按下手机的电源键,才能看到该对话框)。这时连接状态栏应该更新为”连接到 B2G“,如想断开连接,可以按”断开“连接。
  10. +
+

+
+

注意:在连线状态栏中有其他控件,允许你通过模拟器连接到应用管理器 ,我们将在下一节中说明。另外要更改连接端口,则需要启动”端口映射“功能,可参阅上节的《端口映射》。

+
+

使用 Firefox OS Simulator 附加组件

+

如果你没有实际的 Firefox OS 设备来配合 App Manager,可以使用 FirefoxOS 模拟器。不过要选择适合自己操作系统的模拟器版本:

+

安装 Firefox 模拟器

+
+

注意:目前只有 Firefox OS 1.2 模拟器,未来将提供更多版本选择。

+
+

一旦你安装了模拟器,就可以在应用管理器底部栏找到并点击 ”启动模拟器“按钮。接着将出现 3 个按钮:

+ +

“应用”面板

+

现在一切设定完毕,我们了解一下应用管理器的功能吧。首先是“应用”面板。在这里你可以导入现有应用到设置,便于调试。

+ +

在窗口右侧会显示你应用的相关信息,如下图所示:

+

+

Manifest 编辑器

+

从 Firefox 28 开始,“应用”面板包含一个应用 manifest  编辑器:

+

+

调试

+

点击“更新”(安装)按钮,则更新(安装)应用到设备中。点击“调试”按钮将调用工具箱,让你直接来调试应用源代码。

+

+
+

注意:你可以尝试玩一下工具盒 — 比如,尝试修改DOM,CSS等等,你会立即看到实时反映到了设备上。这些修改被保存到已安装的应用代码里,在你下次在设备上打开应用后会看到改变。

+
+

在 Firefox 28 之前,这个工具都是在单独窗口中启动。从 Firefox 28 开始,这些工具都会在应用管理器中的“应用”和“设备”面板标签旁边,以标签形式出现。该标签很容易找打,该标签卡会出现应用的图标。

+

+

错误

+

如果应用没有被成功添加(例如,URL不正确,或者打包了一个错误文件夹)— 即使引入了一个错误的应用,也会被包括错误信息。

+

+

你可以在上图中删除一个应用,把鼠标悬停在左侧窗口应用名/描述上,然后按出现的“X”按钮即可。然而,这并没有真正把设备上的应用删除了,你仍然需要在设备上手动删除应用。

+

“设备”面板

+

“设备”面板显示已连接设备的相关信息。在“已安装应用”窗口中可以启动和调试设备上的应用。

+

+
+

注:Certified Apps 默认不列出。可参阅 Certified App 的调试方式

+
+

“权限”窗口显示当前设备的各种 Web API 所需要的权限。

+

+

最后,你可以点击“截图”按钮,截下当前设置显示的画面,截图会显示在 Firefox 的新标签页中,你可以另存该图。

+

调试 Certified Apps

+

目前仅限搭载 Firefox OS 1.2 开发版本的设备,才能进行 Certified Apps 的调试。若你的设备正运行开发版本,则可将首选项中的“ devtools.debugger.forbid-certified-apps”变更为“false”,即可开始 Certified Apps 的调试。具体请按照下列步骤操作:

+
    +
  1. +

    在电脑的终端/控制台中输入下列指令,以进入设备的文件系统:

    +
    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. +

    this will return you to your normal terminal prompt.使用 exit 命令退出 android 的文件系统;就会返回到正常的终端提示符画面。

    +
  12. +
  13. +

    接下来,重新连接到应用管理器,你应该可以看到 Certified Apps 出现,就可以进行调试了。

    +
  14. +
+
+

注意:如果你想把这个偏好设定加入自己的 Gaia 版本,且即使重设手机也能让该设定保持启用状态,则可将此偏好设定加入 build/custom-prefs.js 再执行 make reset-gaia 即可。

+
+

疑难排除

+

如果设备无法识别:

+ +

无法将设备连接到应用管理器或启动模拟器?请让我们知道反馈错误

diff --git a/files/zh-cn/archive/b2g_os/using_the_b2g_emulators/index.html b/files/zh-cn/archive/b2g_os/using_the_b2g_emulators/index.html new file mode 100644 index 0000000000..5b7b9bb025 --- /dev/null +++ b/files/zh-cn/archive/b2g_os/using_the_b2g_emulators/index.html @@ -0,0 +1,72 @@ +--- +title: 使用B2G仿真器 +slug: Archive/B2G_OS/Using_the_B2G_emulators +translation_of: Archive/B2G_OS/Using_the_B2G_emulators +--- +

+

This article provides a brief guide to some key things you should know when using the Boot to Gecko emulators. This doesn't purport to be a complete user manual; instead, it simply tells you a few useful things that you might not learn on your own.

+

This guide assumes you've already built one of the emulators; if you haven't, rewind to Building and installing Boot to Gecko!

+

About the B2G emulators

+

There are two B2G emulators. The first, built by configuring for "emulator-x86" when running config.sh, is an x86 device emulator. While this is much faster than emulating the ARM processor, it's not as accurate a representation of what an actual device will work like. Configuring for "emulator" when running config.sh gets you the ARM device emulator.

+
+ Note: In recent months the Automation Team has stopped using the x86 emulator due to stability issues. As such, there's a fair chance that things might just not work at all on emulator-x86. Use the ARM emulator unless you have a good reason to do otherwise.
+

Once you've selected, configured, and built an emulator, the rest works the same way from a user standpoint, so the rest of this guide is common to both.

+
+ Note: On Mac OS X, the B2G emulator requires a Core 2 Duo processor or later; that is, a system that is compatible with Mac OS X 10.7 "Lion." You do not actually have to be running Lion, you just have to be compatible with it.
+

Starting the emulator

+

To start the B2G emulator, type the following command:

+
./run-emulator.sh
+
+

This will handle all the emulator startup tasks for you. Now wait patiently while the emulator starts up and Boot to Gecko boots up on it. It can take a couple of minutes, so be patient.

+

When the emulator doesn't work

+

Sometimes the emulator fails to start up. Welcome to the bleeding edge of technology! Here are some tips for resolving problems.

+

Make sure the adb server is running

+

This usually happens because the adb server that handles interacting with the emulated device is either not running or has malfunctioned.

+
+

Note: If you're using the adb built by the B2G build system (which you probably are), it's located in the $B2G/out/host/<platform>/bin directory. On Mac, this is $B2G/out/host/darwin-x86/bin, for example.

+
+

Look to see if adb is even running by doing:

+
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
+
+

Then try running the emulator again. If it's still not working, time to drop in on #b2g on irc.mozilla.org for help.

+

Erase configuration settings

+

Sometimes, out of date configuration settings on your emulated device can cause it to misbehave. You can delete the IndexedDB database fix this, as follows:

+
    +
  1. Make sure adb is running, as described in Make sure the adb server is running.
  2. +
  3. Start up the emulator.
  4. +
  5. in the terminal on the host computer, go into the root code build directory for your emulator, then type: out/host/<platform>/bin/adb -e shell; on Mac, this would be out/host/darwin-x86/bin/adb -e shell.
  6. +
  7. Now you're in the adb shell, and can execute shell commands on your emulated device. Let's stop B2G on the device: stop b2g.
  8. +
  9. Delete the IndexedDB database: rm -rf /data/local/indexedDB.
  10. +
  11. Restart B2G on the emulated device: start b2g.
  12. +
+

Hopefully at this point you will wind up in the Gaia interface and all will be well.

+

Configuring the emulator

+

There are several options you can change to adjust the emulator to be more similar to the device you want to emulate. This section provides some basic information on how to do that. You can adjust the emulator's configuration by editing the run-emulator.sh script (or, ideally, a copy of it). Only a few of the most useful parameters are discussed here; you'll want to look at the qemu site for details on the others.

+
+ Tip: Create one copy of run-emulator.sh for each device you want to simulate; this makes it easy to start up with different configurations.
+

Changing skins

+

By default, the emulator starts up in HVGA mode; that's half-VGA, or 320x480 pixels. This is specified by the -skin parameter given to the emulator when started up. You can switch to a different display mode by editing the run-emulator.sh script (or, ideally, a copy of it). The provided skins are:

+ +

The skins are located in the B2G/development/tools/emulator/skins directory. It's worth noting that the format for skins is quite simple; if you look at them, they're simply folders filled with PNG files for the various user interface objects and a text file called layout which describes the layout of the interface and screen area. It's fairly simple to create custom skins if needed.

+

Changing memory size

+

Another option you may wish or need to configure is the device memory size. The default is 512 MB; however, if the device you're emulating has more or less memory, it is likely important that you adjust this setting to match, to ensure your app will run on the baseline device you want to work on. To do this, change the value of the -memory parameter to the size you need in megabytes. Other than the 512 MB default, 256 MB and 1024 MB are likely ones you'll want to test with.

+

To change the amount of emulated storage capacity for the device (that is, the storage space for local data, like the flash storage on a mobile phone or the hard drive on a computer), change the value of the -partition-size parameter. The default is 512 MB, but you can specify any size in MB you need in order to simulate the kind of device you need to test for.

+

Network Connectivity

+

If for some reason you cannot connect your emulator to the internet you can run the following command from your commandline:

+
adb shell setprop net.dns1 10.0.2.3
-- cgit v1.2.3-54-g00ecf