版權所有 © 2010,谷歌公司。保留所有權利。
兼容性@android.com
一、簡介
本文檔列舉了為使手機與 Android 2.1 兼容而必須滿足的要求。
“必須”、“不得”、“要求”、“應”、“不應”、“應該”、“不應”、“推薦”、“可能”和“可選”的使用符合 IETF 標準在 RFC2119 [資源,1 ] 中定義。
在本文檔中,“設備實施者”或“實施者”是指開發運行 Android 2.1 的硬件/軟件解決方案的個人或組織。 “設備實現”或“實現”是這樣開發的硬件/軟件解決方案。
要被視為與 Android 2.1 兼容,設備實現:
- 必須滿足本兼容性定義中提出的要求,包括通過引用併入的任何文檔。
- 必須通過設備實施軟件完成時可用的最新版本的 Android 兼容性測試套件 (CTS)。 (CTS 作為 Android 開源項目 [資源,2 ] 的一部分提供。)CTS 測試了本文檔中列出的許多(但不是全部)組件。
如果此定義或 CTS 不明確、模棱兩可或不完整,則設備實現者有責任確保與現有實現的兼容性。出於這個原因,Android 開源項目 [ Resources, 3 ] 既是 Android 的參考實現,也是首選實現。強烈建議設備實施者基於 Android 開源項目提供的“上游”源代碼實現其實施。雖然假設某些組件可以替換為替代實現,但強烈建議不要這樣做,因為通過 CTS 測試將變得更加困難。實施者有責任確保與標準 Android 實施的行為完全兼容,包括和超越兼容性測試套件。最後,請注意,本文檔明確禁止某些組件替換和修改。
2. 資源
- IETF RFC2119 要求級別: http ://www.ietf.org/rfc/rfc2119.txt
- Android 兼容性計劃概述:http: //source.android.com/compatibility/index.html
- Android 開源項目:http: //source.android.com/
- API 定義和文檔:http: //developer.android.com/reference/packages.html
- Android 權限參考:http: //developer.android.com/reference/android/Manifest.permission.html
- android.os.Build 參考:http: //developer.android.com/reference/android/os/Build.html
- Android 2.1 允許的版本字符串:http: //source.android.com/compatibility/2.1/versions.html
- android.webkit.WebView 類:http: //developer.android.com/reference/android/webkit/WebView.html
- HTML5:http: //www.whatwg.org/specs/web-apps/current-work/multipage/
- Dalvik 虛擬機規範:可在 Android 源代碼中找到,位於 dalvik/docs
- AppWidgets:http: //developer.android.com/guide/practices/ui_guidelines/widget_design.html
- 通知:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html
- 應用資源: http ://code.google.com/android/reference/available-resources.html
- 狀態欄圖標樣式指南:http: //developer.android.com/guide/practices/ui_guideline/icon_design.html#statusbarstructure
- 搜索管理器:http: //developer.android.com/reference/android/app/SearchManager.html
- 祝酒詞:http: //developer.android.com/reference/android/widget/Toast.html
- 動態壁紙:http: //developer.android.com/resources/articles/live-wallpapers.html
- 適用於 Android 的應用程序: http ://code.google.com/p/apps-for-android
- 參考工具文檔(用於 adb、aapt、ddms):http: //developer.android.com/guide/developing/tools/index.html
- Android apk 文件說明:http: //developer.android.com/guide/topics/fundamentals.html
- 清單文件:http: //developer.android.com/guide/topics/manifest/manifest-intro.html
- 猴子測試工具:http: //developer.android.com/guide/developing/tools/monkey.html
- 支持多屏:http: //developer.android.com/guide/practices/screens_support.html
- android.content.res.Configuration:http: //developer.android.com/reference/android/content/res/Configuration.html
- android.util.DisplayMetrics:http: //developer.android.com/reference/android/util/DisplayMetrics.html
- android.hardware.Camera:http://developer.android.com/reference/android/hardware/Camera.html
- 傳感器坐標空間:http: //developer.android.com/reference/android/hardware/SensorEvent.html
- Android 安全和權限參考:http: //developer.android.com/guide/topics/security/security.html
- 藍牙 API:http: //developer.android.com/reference/android/bluetooth/package-summary.html
3. 軟件
3.1。託管 API 兼容性
託管(基於 Dalvik)的執行環境是 Android 應用程序的主要工具。 Android 應用程序編程接口 (API) 是向在託管 VM 環境中運行的應用程序公開的一組 Android 平台接口。設備實現必須提供 Android 2.1 SDK [資源,4 ] 公開的任何已記錄 API 的完整實施,包括所有已記錄的行為。
設備實現不得省略任何託管 API、更改 API 接口或簽名、偏離記錄的行為或包含無操作,除非此兼容性定義特別允許。
3.2.軟 API 兼容性
3.2.1。權限
設備實現者必須支持並強制執行權限參考頁 [資源,5 ] 中記錄的所有權限常量。請注意,第 10 節列出了與 Android 安全模型相關的其他要求。
3.2.2.構建參數
Android API 在android.os.Build
類 [ Resources, 6 ] 上包含許多常量,用於描述當前設備。為了在設備實現中提供一致、有意義的值,下表包含了對設備實現必須遵守的這些值的格式的額外限制。
3.2.3。意圖兼容性
3.2.3.1。核心應用意圖
Android 上游項目定義了一些核心應用,例如電話撥號器、日曆、通訊錄、音樂播放器等。設備實施者可以用替代版本替換這些應用程序。
但是,任何此類替代版本都必須遵循上游項目提供的相同 Intent 模式。例如,如果設備包含替代音樂播放器,它仍必須遵循第三方應用程序發布的 Intent 模式來挑選歌曲。
- 台鐘
- 瀏覽器
- 日曆
- 計算器
- 相機
- 聯繫人
- 電子郵件
- 畫廊
- 全球搜索
- 啟動器
- LivePicker(即動態壁紙選擇器應用程序;如果設備不支持動態壁紙,則可以省略,根據第 3.8.5 節。)
- 消息(又名“彩信”)
- 音樂
- 電話
- 設置
- 錄音機
核心 Android 系統應用程序包括各種被視為“公共”的 Activity 或 Service 組件。也就是說,屬性“android:exported”可能不存在,或者可能具有值“true”。
換句話說,設備實現可能會取代核心的 Android 系統應用程序;但是,如果支持,設備實現必須支持每個被替換的核心 Android 系統應用程序定義的所有 Intent 模式。
3.2.3.2。意圖覆蓋
3.2.3.3。意圖命名空間
這種禁止類似於第 3.6 節中為 Java 語言類指定的禁止。
3.2.3.4。廣播意圖
第三方應用程序依靠平台廣播某些 Intent 來通知他們硬件或軟件環境的變化。 Android 兼容設備必須廣播公共廣播 Intent 以響應適當的系統事件。廣播意圖在 SDK 文檔中進行了描述。
3.3.原生 API 兼容性
本機代碼兼容性具有挑戰性。出於這個原因,應該重申的是,強烈鼓勵設備實現者使用上面列出的庫的上游實現,以幫助確保兼容性。
3.4. Web API 兼容性
許多開發人員和應用程序的用戶界面依賴於android.webkit.WebView
類 [資源,8 ] 的行為,因此 WebView 實現必須在 Android 實現之間兼容。 Android 開源實現使用 WebKit 渲染引擎來實現 WebView。
因為為 Web 瀏覽器開發一個全面的測試套件是不可行的,設備實現者必須在 WebView 實現中使用特定的上游構建的 WebKit。具體來說:
- WebView 必須使用來自 Android 2.1 的上游 Android 開源樹的 530.17 WebKit 構建。此版本包括一組特定的 WebView 功能和安全修復程序。
- WebView 報告的用戶代理字符串必須採用以下格式:
Mozilla/5.0 (Linux; U; Android $(VERSION); $(LOCALE); $(MODEL) Build/$(BUILD)) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17
WebView 配置必須包括對 HTML5 數據庫、應用程序緩存和地理定位 API [資源,9 ] 的支持。 WebView 必須以某種形式包含對 HTML5 <video>
標記的支持。獨立的瀏覽器應用程序(無論是基於上游 WebKit 瀏覽器應用程序還是第三方替代品)必須包含對剛剛為 WebView 列出的相同 HTML5 功能的支持。
3.5. API 行為兼容性
每種 API 類型(託管、軟、本機和 Web)的行為必須與上游 Android 開源項目 [參考資料,3 ] 的首選實現一致。一些特定的兼容性領域是:
上面的列表並不全面,設備實現者有責任確保行為兼容性。出於這個原因,設備實現者應該盡可能使用通過 Android 開源項目提供的源代碼,而不是重新實現系統的重要部分。
兼容性測試套件 (CTS) 測試平台的重要部分的行為兼容性,但不是全部。實施者有責任確保與 Android 開源項目的行為兼容性。
3.6. API 命名空間
Android 遵循 Java 編程語言定義的包和類命名空間約定。為確保與第三方應用程序的兼容性,設備實施者不得對這些包命名空間進行任何禁止的修改(見下文):
- 設備實現不得通過更改任何方法或類簽名或刪除類或類字段來修改 Android 平台上公開的 API。
- 設備實現者可以修改 API 的底層實現,但此類修改不得影響任何公開公開的 API 的聲明行為和 Java 語言簽名。
- 設備實現者不得將任何公開暴露的元素(例如類或接口,或現有類或接口的字段或方法)添加到上述 API。
請注意,上述限制對應於 Java 編程語言中命名 API 的標準約定;本節旨在通過包含在此兼容性定義中來加強這些約定並使其具有約束力。
3.7.虛擬機兼容性
設備實現必須支持完整的 Dalvik Executable (DEX) 字節碼規範和 Dalvik 虛擬機語義 [資源,10 ]。
3.8.用戶界面兼容性
Android 平台包含一些開發人員 API,允許開發人員連接到系統用戶界面。設備實現必須將這些標準 UI API 合併到他們開發的自定義用戶界面中,如下所述。
3.8.1.小部件
Android 定義了一個組件類型和相應的 API 和生命週期,允許應用程序向最終用戶公開一個“AppWidget”[參考資料,11 ]。 Android 開源參考版本包括一個 Launcher 應用程序,該應用程序包含用戶界面元素,允許用戶從主屏幕添加、查看和刪除 AppWidget。
3.8.2.通知
Android 包含允許開發人員通知用戶重要事件的 API [參考資料,12 ]。設備實現者必須為如此定義的每一類通知提供支持;具體來說:聲音、振動、燈光和狀態欄。
此外,實現必須正確呈現 API [資源,13 ] 或狀態欄圖標樣式指南 [資源,14 ] 中提供的所有資源(圖標、聲音文件等)。設備實現者可以為通知提供一種替代的用戶體驗,而不是參考 Android 開源實現提供的體驗;然而,這樣的替代通知系統必須支持現有的通知資源,如上所述。
3.8.3.搜索
Android 包含 API [參考資料,15 ],允許開發人員將搜索合併到他們的應用程序中,並將他們的應用程序數據公開到全局系統搜索中。一般而言,此功能由一個單一的、系統範圍的用戶界面組成,允許用戶輸入查詢、在用戶鍵入時顯示建議並顯示結果。 Android API 允許開發人員重用此接口以在他們自己的應用程序中提供搜索,並允許開發人員將結果提供給通用的全局搜索用戶界面。
設備實現可以提供替代的搜索用戶界面,但應該包括一個硬或軟專用搜索按鈕,可以在任何應用程序中隨時使用它來調用搜索框架,其行為在 API 文檔中提供。
3.8.4.敬酒
應用程序可以使用“Toast”API(在 [參考資料,16 ] 中定義)向最終用戶顯示簡短的非模態字符串,這些字符串會在短暫的一段時間後消失。設備實現必須以某種高可見度的方式從應用程序向最終用戶顯示 Toast。
3.8.5。動態壁紙
Android 定義了一種組件類型和相應的 API 和生命週期,允許應用程序向最終用戶公開一個或多個“動態壁紙”[參考資料,17 ]。動態壁紙是具有有限輸入功能的動畫、圖案或類似圖像,在其他應用程序後面顯示為壁紙。
如上所述,能夠可靠運行動態壁紙的設備實現應該實現動態壁紙。如上所述確定不能可靠運行動態壁紙的設備實現不得實現動態壁紙。
4. 參考軟件兼容性
上面的每個應用程序都必須在實現上啟動並正確運行,才能使實現被認為是兼容的。
此外,設備實現必須測試每個冒煙測試應用程序的每個菜單項(包括所有子菜單):
5. 應用程序封裝兼容性
設備實現必須安裝並運行由官方 Android SDK [資源,19 ] 中包含的“aapt”工俱生成的 Android“.apk”文件。
設備實現不得擴展 .apk [ Resources, 20 ]、Android Manifest [ Resources, 21 ] 或 Dalvik 字節碼 [ Resources, 10 ] 格式,以防止這些文件在其他兼容設備上正確安裝和運行.設備實現者應該使用 Dalvik 的參考上游實現,以及參考實現的包管理系統。
6. 多媒體兼容性
設備實現必須支持以下多媒體編解碼器。所有這些編解碼器都作為軟件實現在 Android 開源項目的首選 Android 實現中提供。
7. Developer Tool Compatibility
- Android Debug Bridge (known as adb) [ Resources, 19 ]
Device implementations MUST support alladb
functions as documented in the Android SDK. The device-sideadb
daemon SHOULD be inactive by default, but there MUST be a user-accessible mechanism to turn on the Android Debug Bridge. - Dalvik Debug Monitor Service (known as ddms) [ Resources, 19 ]
Device implementations MUST support allddms
features as documented in the Android SDK. Asddms
usesadb
, support forddms
SHOULD be inactive by default, but MUST be supported whenever the user has activated the Android Debug Bridge, as above. - Monkey [ Resources, 22 ]
Device implementations MUST include the Monkey framework, and make it available for applications to use.
8. Hardware Compatibility
- class definitions for the component's APIs MUST be present
- the API's behaviors MUST be implemented as no-ops in some reasonable fashion
- API methods MUST return null values where permitted by the SDK documentation
- API methods MUST return no-op implementations of classes where null values are not permitted by the SDK documentation
8.1. Display
Android 2.1 includes facilities that perform certain automatic scaling and transformation operations under some circumstances, to ensure that third-party applications run reasonably well on a variety of hardware configurations [ Resources, 23 ]. Devices MUST properly implement these behaviors, as detailed in this section.
For Android 2.1, this are the most common display configurations:
Device implementations corresponding to one of the standard configurations above MUST be configured to report the indicated screen size to applications via the android.content.res.Configuration
[ Resources, 24 ] class.
- Device implementations MUST interpret resources in a .apk that lack a density qualifier as defaulting to "medium" (known as "mdpi" in the SDK documentation.)
- When operating on a "low" density screen, device implementations MUST scale down medium/mdpi assets by a factor of 0.75.
- When operating on a "high" density screen, device implementations MUST scale up medium/mdpi assets by a factor of 1.5.
- Device implementations MUST NOT scale assets within a density range, and MUST scale assets by exactly these factors between density ranges.
8.1.2. Non-Standard Display Configurations
8.1.3. Display Metrics
Device implementations MUST report correct valuesfor all display metrics defined in android.util.DisplayMetrics
[ Resources, 25 ].
8.2. Keyboard
- MUST include support for the Input Management Framework (which allows third party developers to create Input Management Engines -- ie soft keyboard) as detailed at developer.android.com
- MUST provide at least one soft keyboard implementation (regardless of whether a hard keyboard is present)
- MAY include additional soft keyboard implementations
- MAY include a hardware keyboard
- MUST NOT include a hardware keyboard that does not match one of the formats specified in
android.content.res.Configuration.keyboard
[ Resources, 24 ] (that is, QWERTY, or 12-key)
8.3. Non-touch Navigation
- MAY omit a non-touch navigation options (that is, may omit a trackball, d-pad, or wheel)
- MUST report the correct value for
android.content.res.Configuration.navigation
[ Resources, 24 ]
8.4. Screen Orientation
8.5. Touchscreen input
- MUST have a touchscreen
- MAY have either capacative or resistive touchscreen
- MUST report the value of
android.content.res.Configuration
[ Resources, 24 ] reflecting corresponding to the type of the specific touchscreen on the device
8.6. USB
- MUST implement a USB client, connectable to a USB host with a standard USB-A port
- MUST implement the Android Debug Bridge over USB (as described in Section 7)
- MUST implement the USB mass storage specification, to allow a host connected to the device to access the contents of the /sdcard volume
- SHOULD use the micro USB form factor on the device side
- MAY include a non-standard port on the device side, but if so MUST ship with a cable capable of connecting the custom pinout to standard USB-A port
8.7. Navigation keys
8.8. Wireless Data Networking
8.9. Camera
Device implementations MUST include a camera. The included camera:
- MUST have a resolution of at least 2 megapixels
- SHOULD have either hardware auto-focus, or software auto-focus implemented in the camera driver (transparent to application software)
- MAY have fixed-focus or EDOF (extended depth of field) hardware
- MAY include a flash. If the Camera includes a flash, the flash lamp MUST NOT be lit while an android.hardware.Camera.PreviewCallback instance has been registered on a Camera preview surface, unless the application has explicitly enabled the flash by enabling the
FLASH_MODE_AUTO
orFLASH_MODE_ON
attributes of aCamera.Parameters
object. Note that this constraint does not apply to the device's built-in system camera application, but only to third-party applications usingCamera.PreviewCallback
.
Device implementations MUST implement the following behaviors for the camera-related APIs:
- If an application has never called android.hardware.Camera.Parameters.setPreviewFormat(int), then the device MUST use android.hardware.PixelFormat.YCbCr_420_SP for preview data provided to application callbacks.
- If an application registers an android.hardware.Camera.PreviewCallback instance and the system calls the onPreviewFrame() method when the preview format is YCbCr_420_SP, the data in the byte[] passed into onPreviewFrame() must further be in the NV21 encoding format. (This is the format used natively by the 7k hardware family.) That is, NV21 MUST be the default.
Device implementations MUST implement the full Camera API included in the Android 2.1 SDK documentation [ Resources, 26 ]), regardless of whether the device includes hardware autofocus or other capabilities. For instance, cameras that lack autofocus MUST still call any registered android.hardware.Camera.AutoFocusCallback
instances (even though this has no relevance to a non-autofocus camera.)
8.10. Accelerometer
Device implementations MUST include a 3-axis accelerometer and MUST be able to deliver events at 50 Hz or greater. The coordinate system used by the accelerometer MUST comply with the Android sensor coordinate system as detailed in the Android APIs (see [ Resources, 27 ]).
8.11. Compass
Device implementations MUST include a 3-axis compass and MUST be able to deliver events 10 Hz or greater. The coordinate system used by the compass MUST comply with the Android sensor coordinate system as defined in the Android API (see [ Resources, 27 ]).
8.12. GPS
8.13. Telephony
See also Section 8.8, Wireless Data Networking.
8.14. Memory and Storage
8.15. Application Shared Storage
8.16. Bluetooth
Device implementations MUST include a Bluetooth transceiver. Device implementations MUST enable the RFCOMM-based Bluetooth API as described in the SDK documentation [ Resources, 29 ]. Device implementations SHOULD implement relevant Bluetooth profiles, such as A2DP, AVRCP, OBEX, etc. as appropriate for the device.
9. Performance Compatibility
10. Security Model Compatibility
Device implementations MUST implement a security model consistent with the Android platform security model as defined in Security and Permissions reference document in the APIs [ Resources, 28 ] in the Android developer documentation. Device implementations MUST support installation of self-signed applications without requiring any additional permissions/certificates from any third parties/authorities. Specifically, compatible devices MUST support the security mechanisms described in the follow sub-sections.
10.1. Permissions
Device implementations MUST support the Android permissions model as defined in the Android developer documentation [ Resources, 28 ]. Specifically, implementations MUST enforce each permission defined as described in the SDK documentation; no permissions may be omitted, altered, or ignored. Implementations MAY add additional permissions, provided the new permission ID strings are not in the android.* namespace.
10.2. UID and Process Isolation
Device implementations MUST support the Android application sandbox model, in which each application runs as a unique Unix-style UID and in a separate process. Device implementations MUST support running multiple applications as the same Linux user ID, provided that the applications are properly signed and constructed, as defined in the Security and Permissions reference [ Resources, 28 ].
10.3. Filesystem Permissions
Device implementations MUST support the Android file access permissions model as defined in as defined in the Security and Permissions reference [ Resources, 28 ].
11. Compatibility Test Suite
Device implementations MUST pass the Android Compatibility Test Suite (CTS) [ Resources, 2 ] available from the Android Open Source Project, using the final shipping software on the device. Additionally, device implementers SHOULD use the reference implementation in the Android Open Source tree as much as possible, and MUST ensure compatibility in cases of ambiguity in CTS and for any reimplementations of parts of the reference source code.
12. Updatable Software
- Over-the-air (OTA) downloads with offline update via reboot
- "Tethered" updates over USB from a host PC
- "Offline" updates via a reboot and update from a file on removable storage
13. Contact Us
You can contact the document authors at compatibility@android.com for clarifications and to bring up any issues that you think the document does not cover.