Class performa

Class performa adalah standar pertama yang diperkenalkan di Android 12. Class performa menentukan serangkaian kemampuan perangkat yang tidak sekadar memenuhi persyaratan dasar Android.

Setiap versi Android memiliki class performanya masing-masing yang ditentukan dalam Compatibility Definition Document (CDD) Android versi tersebut. Compatibility Test Suite (CTS) Android memverifikasi persyaratan CDD.

Setiap perangkat yang didukung Android mendeklarasikan class performa yang didukungnya. Developer dapat menemukan class performa perangkat saat runtime dan memberikan upgrade pengalaman guna memanfaatkan kemampuan perangkat secara penuh.

Untuk menemukan level class performa perangkat, gunakan library Jetpack Core Performance. Library ini melaporkan class performa media perangkat seperti yang dideklarasikan dalam informasi versi build atau berdasarkan data dari layanan Google Play.

Mulailah dengan menambahkan dependensi untuk modul yang relevan dalam file gradle Anda:

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-beta02")
// Enable APIs to query Google Play Services for performance class.
implementation("androidx.core:core-performance-play-services:1.0.0-beta02")

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-beta02'
// Enable APIs to query Google Play Services for performance class.
implementation 'androidx.core:core-performance-play-services:1.0.0-beta02'

Then, create an instance of a DevicePerformance implementation, such as PlayServicesDevicePerformance, in the onCreate() lifecycle event of your Application. This should only be done once in your app.

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);
  }
}

Selanjutnya, Anda dapat mengambil properti mediaPerformanceClass untuk menyesuaikan pengalaman aplikasi berdasarkan kemampuan perangkat:

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.TIRAMISU -> {
        // Performance class level 13 and later.
        // Provide the most premium experience for the highest performing devices.
      }
      devicePerformance.mediaPerformanceClass == Build.VERSION_CODES.S -> {
        // Performance class level 12.
        // Provide a high quality experience.
      }
      else -> {
        // Performance class level 11 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.TIRAMISU) {
      // Performance class level 13 and later.
      // Provide the most premium experience for the highest performing devices.
    } else if (devicePerformance.getMediaPerformanceClass() == Build.VERSION_CODES.S) {
      // Performance class level 12.
      // Provide a high quality experience.
    } else {
      // Performance class level 11 or undefined.
      // Remove extras to keep experience functional.
    }
  }
}

Class performa memiliki performa yang kompatibel dengan versi yang lebih baru. Perangkat dapat melakukan upgrade ke versi platform yang lebih baru tanpa mengupdate class performanya. Misalnya, perangkat yang awalnya mendukung class performa 12 dapat meng-upgrade versi ke Android 13 dan terus melaporkannya untuk mendukung class 12 jika tidak memenuhi persyaratan class 13. Ini berarti class performa menyediakan cara untuk mengelompokkan perangkat tanpa bergantung pada versi Android tertentu.

Gambar 1. Perangkat dapat mengupgrade versi Android dan terus melaporkan bahwa perangkat tersebut mendukung class yang awalnya didukung.

Class performa 14

Class performa 14 dibuat berdasarkan persyaratan yang diperkenalkan di class performa 13. Persyaratan class performa tertentu dipublikasikan di CDD Android. Selain meningkatkan persyaratan untuk item dari class performa 13, CDD ini akan menentukan persyaratan dalam area berikut:

Media

  • Dukungan efek film grain dalam decoder hardware AV1
  • Profil Dasar Pengukuran AVIF
  • Performa encoder AV1
  • Codec video HDR
  • Format warna RGBA_1010102
  • Pengambilan sampel tekstur YUV
  • Kualitas encoding video
  • Mixing audio multisaluran

Kamera

  • Ekstensi mode malam
  • Kamera utama berkemampuan HDR
  • Mode adegan deteksi wajah

Generik

  • Overlay hardware
  • Layar HDR

Class performa 13

Class performa 13 dibuat berdasarkan persyaratan yang diperkenalkan di class performa 12. Persyaratan class performa tertentu dipublikasikan di CDD Android. Selain meningkatkan persyaratan untuk item dari class performa 12, CDD ini akan menentukan persyaratan baru dalam area berikut:

Media

  • Decoder hardware AV1
  • Decoder hardware aman
  • Latensi inisialisasi decoder
  • Latensi audio bolak-balik
  • Headset berkabel dan perangkat audio USB
  • Perangkat MIDI
  • Trusted execution environment yang didukung hardware

Kamera

  • Stabilisasi pratinjau
  • Perekaman gerakan lambat
  • Rasio zoom minimum untuk kamera ultrawide
  • Kamera serentak
  • Multi-kamera logis
  • Kasus penggunaan streaming

Class performa 12

Class performa 12 berfokus pada kasus penggunaan media. Persyaratan class performa tertentu dipublikasikan di CDD Android. CDD menentukan persyaratan di area berikut:

Media

  • Sesi codec video serentak
  • Latensi inisialisasi encoder
  • Penurunan frame decoder
  • Kualitas encoding

Kamera

  • Resolusi dan kecepatan frame
  • Latensi startup dan pengambilan gambar
  • FULL atau level hardware yang lebih baik
  • Sumber stempel waktu bersifat realtime
  • Kemampuan RAW

Generik

  • Memori
  • Performa operasi baca dan tulis
  • Resolusi layar
  • Kepadatan layar

Class performa 11

Class performa 11 menyertakan subset persyaratan untuk class performa 12, sehingga developer dapat memberikan pengalaman yang disesuaikan di perangkat yang lebih awal tetapi masih memiliki kemampuan tinggi. Persyaratan class performa tertentu dipublikasikan di CDD Android.