性能等级

性能等级是 Android 12 中首次引入的标准。性能等级定义超出 Android 基准要求的一组设备功能。

每个 Android 版本都有自己对应的性能等级,这在相应版本的 Android 兼容性定义文档 (CDD) 中进行了定义。Android 兼容性测试套件 (CTS) 会验证 CDD 要求。

每部 Android 设备都会声明其支持的性能等级。开发者可以在运行时检查设备的性能等级,并提供充分利用设备功能的升级体验。

如需了解设备的性能等级,请使用 Jetpack Core Performance 库。此库会根据 build 版本信息中的声明或 Google Play 服务中的数据来报告设备的媒体性能等级 (MPC)。

首先,在 Gradle 文件中为相关模块添加依赖项:

Kotlin

// Implementation of Jetpack Core library.
implementation("androidx.core:core-ktx:1.12.0")
// Enable APIs to query for device-reported performance class.
implementation("androidx.core:core-performance:1.0.0")
// Enable APIs to query Google Play services for performance class.
implementation("androidx.core:core-performance-play-services:1.0.0")

Groovy

// Implementation of Jetpack Core library.
implementation 'androidx.core:core-ktx:1.12.0'
// Enable APIs to query for device-reported performance class.
implementation 'androidx.core:core-performance:1.0.0'
// Enable APIs to query Google Play services for performance class.
implementation 'androidx.core:core-performance-play-services:1.0.0'

然后,在 ApplicationonCreate() 生命周期事件中创建 DevicePerformance 实现的实例,例如 PlayServicesDevicePerformance。此操作应当只在应用中执行 1 次。

Kotlin

import androidx.core.performance.play.services.PlayServicesDevicePerformance

class MyApplication : Application() {
  lateinit var devicePerformance: DevicePerformance

  override fun onCreate() {
    // Use a class derived from the DevicePerformance interface
    devicePerformance = PlayServicesDevicePerformance(applicationContext)
  }
}

Java

import androidx.core.performance.play.services.PlayServicesDevicePerformance;

class MyApplication extends Application {
  DevicePerformance devicePerformance;

  @Override
  public void onCreate() {
    // Use a class derived from the DevicePerformance interface
    devicePerformance = new PlayServicesDevicePerformance(applicationContext);
  }
}

然后,您可以检索 mediaPerformanceClass 属性,以根据设备的功能定制应用体验:

Kotlin

class MyActivity : Activity() {
  private lateinit var devicePerformance: DevicePerformance
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Note: Good app architecture is to use a dependency framework. See
    // https://developer.android.com/training/dependency-injection for more
    // information.
    devicePerformance = (application as MyApplication).devicePerformance
  }

  override fun onResume() {
    super.onResume()
    when {
      devicePerformance.mediaPerformanceClass >= Build.VERSION_CODES.VANILLA_ICE_CREAM -> {
        // MPC level 35 and later.
        // Provide the most premium experience for the highest performing devices.
      }
      devicePerformance.mediaPerformanceClass == Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
        // MPC level 34.
        // Provide a high quality experience.
      }
      else -> {
        // MPC level 33, 31, 30, or undefined.
        // Remove extras to keep experience functional.
      }
    }
  }
}

Java

class MyActivity extends Activity {
  private DevicePerformance devicePerformance;
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Note: Good app architecture is to use a dependency framework. See
    // https://developer.android.com/training/dependency-injection for more
    // information.
    devicePerformance = ((MyApplication) getApplication()).devicePerformance;
  }

  @Override
  public void onResume() {
    super.onResume();
    if (devicePerformance.getMediaPerformanceClass() >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
      // MPC level 35 and later.
      // Provide the most premium experience for the highest performing devices.
    } else if (devicePerformance.getMediaPerformanceClass() == Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
      // MPC level 34.
      // Provide a high quality experience.
    } else {
      // MPC level 33, 31, 30, or undefined.
      // Remove extras to keep experience functional.
    }
  }
}

性能等级向前兼容。设备可以升级到较新的平台版本,而无需更新其性能等级。例如,一部最初支持性能等级 33 的设备可以升级到 Android 14,并在不满足性能等级 34 要求时继续报告其支持性能等级 33。这样一来,您就可以将设备分组,而不依赖于特定的 Android 版本。

图 1. 设备可以升级 Android 版本并继续报告它们支持其最初支持的等级。

媒体性能等级 35

MPC 35 在 Android 15 中引入,基于 MPC 34 中引入的要求。如需了解具体的 MPC 35 要求,请参阅 Android 15 CDD。除了对 MPC 34 中的条目提高了要求之外,CDD 还指定了以下方面的要求:

媒体

  • 解码丢帧
  • HDR 编辑
  • 动态配色方面
  • 纵向宽高比

相机

  • JPEG_R
  • 预览防抖

图形

  • EGL 扩展
  • Vulkan 结构

媒体性能等级 34

MPC 34 在 Android 14 中引入,基于 MPC 33 中引入的要求。如需了解具体的 MPC 34 要求,请参阅 Android 14 CDD。除了对 MPC 33 中的条目提高了要求之外,CDD 还指定了以下方面的要求:

媒体

  • AV1 硬件解码器中的胶片颗粒效果支持
  • AVIF 基准配置文件
  • AV1 编码器性能
  • HDR 视频编解码器
  • RGBA_1010102 颜色格式
  • YUV 纹理采样
  • 视频编码质量
  • 多声道音频混音

摄像头

  • 夜间模式扩展功能
  • 支持 HDR 的主摄像头
  • 人脸检测取景模式

常规

  • 硬件叠加层
  • HDR 显示屏

媒体性能等级 33

MPC 33 在 Android 13 中引入,基于 MPC 31 中引入的要求。如需了解具体的 MPC 33 要求,请参阅 Android 13 CDD。除了对 MPC 31 中的条目提高了要求之外,CDD 还指定了以下方面的要求:

媒体

  • AV1 硬件解码器
  • 安全硬件解码器
  • 解码器初始化延迟时间
  • 往返音频延迟时间
  • 有线头戴式耳机和 USB 音频设备
  • MIDI 设备
  • 由硬件支持的可信执行环境

摄像头

  • 预览防抖
  • 慢镜头录制
  • 超广角摄像头的最小缩放比率
  • 并发摄像头
  • 逻辑多摄像头
  • 数据流用例

媒体性能等级 31

Android 12 中引入了 MPC 31。如需了解具体的 MPC 31 要求,请参阅 Android 12 CDD。CDD 指定了以下几个方面的要求:

媒体

  • 并发视频编解码器会话
  • 编码器初始化延迟时间
  • 解码器丢帧
  • 编码质量

摄像头

  • 分辨率和帧速率
  • 启动和拍摄延迟时间
  • FULL 或更高级别的硬件
  • 实时时间戳来源
  • RAW 功能

常规

  • 内存
  • 读写性能
  • 屏幕分辨率
  • 屏幕密度

媒体性能等级 30

MPC 30 包含 MPC 31 的一部分要求,可让开发者在版本较低但功能依然强大的设备上提供量身定制的体验。如需了解具体的性能等级要求,请参阅 Android 11 CDD

  • 注意:当 JavaScript 处于关闭状态时,系统会显示链接文字
  • 应用启动时间