版权所有 © 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.蓝牙
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.