# DevicePerformance

# DevicePerformance

Artifact:[androidx.core:core-performance](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/performance/DevicePerformance.kt+class:androidx.core.performance.DevicePerformance)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/performance/DevicePerformance "View this page in Java")

<br />

```
interface DevicePerformance
```

<br />

Known direct subclasses  
[DefaultDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/DefaultDevicePerformance),[FakeDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/testing/FakeDevicePerformance),[PlayServicesDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/play/services/PlayServicesDevicePerformance)  

|-------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| [DefaultDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/DefaultDevicePerformance)                         | Reports the media performance class of the device.                                           |
| [FakeDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/testing/FakeDevicePerformance)                       | A DevicePerformance that immediately returns the`mediaPerformanceClass`.                     |
| [PlayServicesDevicePerformance](https://developer.android.com/reference/kotlin/androidx/core/performance/play/services/PlayServicesDevicePerformance) | A DevicePerformance that uses Google Play Services to retrieve media performance class data. |

*** ** * ** ***

Reports the media performance class of the device.

Create an instance of DevicePerformance in your[android.app.Application.onCreate](https://developer.android.com/reference/android/app/Application.html#onCreate())and use the[mediaPerformanceClass](https://developer.android.com/reference/kotlin/androidx/core/performance/DevicePerformance#mediaPerformanceClass())value any time it is needed.  

```kotlin
import androidx.core.performance.DevicePerformance
import androidx.core.performance.play.services.PlayServicesDevicePerformance

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

    override fun onCreate() {
        // use a DevicePerformance derived class
        devicePerformance = PlayServicesDevicePerformance(applicationContext)
    }
}

class MyActivity : Activity() {
    private lateinit var devicePerformance: DevicePerformance

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Production applications should 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 -> {
                // Provide the most premium experience for highest performing devices
            }
            devicePerformance.mediaPerformanceClass == Build.VERSION_CODES.R -> {
                // Provide a high quality experience
            }
            else -> {
                // Remove extras to keep experience functional
            }
        }
    }
}
```

## Summary

|                            ### Public properties                            |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [mediaPerformanceClass](https://developer.android.com/reference/kotlin/androidx/core/performance/DevicePerformance#mediaPerformanceClass()) The media performance class of the device or 0 if none. |

## Public properties

### mediaPerformanceClass

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
val mediaPerformanceClass: Int
```

The media performance class of the device or 0 if none.

If this value is not`0`, the device conforms to the media performance class definition of the SDK version of this value. This value is stable for the duration of the process.

Possible non-zero values are defined in[Build.VERSION_CODES](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html)starting with[VERSION_CODES.R](https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#R()).

Defaults to[VERSION.MEDIA_PERFORMANCE_CLASS](https://developer.android.com/reference/android/os/Build.VERSION.html#MEDIA_PERFORMANCE_CLASS())