自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
硬件评估
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
硬件评估会提供通过用于调用触感反馈的常用方法采样的三种目标触感反馈效果的量化特征。在评估结束时,可以将每种目标触感效果在每台设备上的性能应用于性能图,以得出结论。
性能图显示了当前几款 Android 设备的硬件评估结果。其目的是根据上下文相关比较(而非“通过”或“失败”判断结果)来评估目标设备。围绕该概念产生的具体问题类似于:在考虑到我的手机的价格层级和执行器类型后,与竞争对手相比,其性能如何?结果是否符合我的预期?如果不符合,哪些方面需要改进?
图 1. 触感反馈硬件评估流程概览
该评估会观察 Android 触感反馈框架中三种方法的结果。
效果 1:预定义的短时触感反馈常量
VibrationEffect.EFFECT_CLICK
此常量是在 HAL 和 API 之间映射常量中提供的 HAL-API 映射内的基准效果(即共同标准)。该常量与最常用的效果 HapticFeedbackConstants.KEYBOARD_PRESS
进行映射。评估此效果有助于确定目标设备是否已准备好提供清晰触感反馈。
效果 2:短时自定义触感反馈效果
VibrationEffect.createOneShot(20,255)
对于单次短时自定义脉冲,在指定持续时间时,建议的最大阈值是 20ms。不建议单次脉冲的持续时间超过 20 毫秒,因为这样的脉冲会被视为蜂鸣振动。
图 2. 短时自定义触感反馈效果
效果 3:具有振幅变体的长时自定义触感反馈效果
VibrationEffect.createWaveform(timings[], amplitudes[], int repeat)
能否为自定义触感反馈效果生成不同的振幅是评估设备是否有能力提供丰富触感反馈的指标之一。建议的 timings [ ]
和 amplitudes [ ]
分别为 {500, 500}
和 {128, 255}
。这表示幅度会从 50% 增加到 100%,并且采样周期为 500 毫秒。
图 3. 具有振幅变体的长时自定义触感反馈效果
如需快速检查效果 3 的振幅控制硬件功能,请尝试 Vibrator.hasAmplitudeControl()
。结果必须为 true
,才能按照预期使用不同幅度执行 VibrationEffect.createWaveform
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-10。
[null,null,["最后更新时间 (UTC):2025-03-10。"],[],[],null,["# Hardware assessment\n\nThe hardware assessment delivers quantitative characteristics of three target\nhaptic effects sampled by common methods used to call haptics. At the end of the\nassessment, performance from each device for each target haptic effect can be\napplied to the [performance map](/docs/core/interaction/haptics/compare) to\ndraw conclusions.\n\nThe performance map shows the hardware assessment results from several current\nAndroid devices. The goal is to evaluate the target device using a contextually\nrelative comparison (rather than a pass or fail judgement). Specific questions\nstructured around that notion are: *Given the price tier and\nactuator type of my phone, how is the performance compared to my competitors? Do\nthe results meet my expectations? If not, what needs improvement?*\n\n**Figure 1.** Haptics hardware assessment process overview\n\nThe assessment observes the results of three methods in the Android haptic\nframework.\n\n### Effect 1: Predefined short haptic constants\n\n[`VibrationEffect.EFFECT_CLICK`](https://developer.android.com/reference/android/os/VibrationEffect.html#EFFECT_CLICK)\n\nThis constant is the baseline effect or common denominator in the HAL-API\nmapping provided in\n[Map constants between HAL and API](/docs/core/interaction/haptics/haptics-map-constants).\nIt's mapped with the most commonly used effect\n[`HapticFeedbackConstants.KEYBOARD_PRESS`](https://developer.android.com/reference/android/view/HapticFeedbackConstants#KEYBOARD_PRESS).\nAssessing this effect helps you determine the readiness of your\ntarget device for\n[clear haptics](/docs/core/interaction/haptics/haptics-ux-foundation#clear-haptics).\n\n### Effect 2: Short custom haptic effect\n\n[`VibrationEffect.createOneShot(20,255)`](https://developer.android.com/reference/android/os/VibrationEffect#createOneShot(long,%20int))\n\nFor short single custom impulses, 20 ms is the recommended maximum\nthreshold to define duration. A single impulse that's longer than 20 ms\nisn't recommended because it's perceived as a\n[buzzy vibration](/docs/core/interaction/haptics/haptics-ux-foundation#buzzy-vibration).\n\n**Figure 2.** Short custom haptic effect\n\n### Effect 3: Long custom haptic effect with amplitude variation\n\n[`VibrationEffect.createWaveform(timings[], amplitudes[], int repeat)`](https://developer.android.com/reference/android/os/VibrationEffect#createWaveform(long%5B%5D,%20int%5B%5D,%20int))\n\nThe ability to produce varying amplitudes for custom haptic effects is one of\nthe indicators to evaluate the device's capabilities for\n[rich haptics](/docs/core/interaction/haptics/haptics-ux-foundation#rich-haptics).\nThe recommended `timings [ ]` and `amplitudes [ ]` are `{500, 500}` and\n`{128, 255}`, respectively. This presents an increasing trend of amplitude from\n50% to 100% with a 500 ms sampling rate.\n\n**Figure 3.** Long custom haptic effect with amplitude variation\n\nTo quickly check the hardware capabilities of amplitude control for Effect 3,\ntry\n[`Vibrator.hasAmplitudeControl()`](https://developer.android.com/reference/android/os/Vibrator#hasAmplitudeControl()).\nThe result has to be `true` to execute\n[`VibrationEffect.createWaveform`](https://developer.android.com/reference/android/os/VibrationEffect#createWaveform(long%5B%5D,%20int%5B%5D,%20int))\nwith varying amplitude as intended."]]