# Device

Artifact: [androidx.test.backup:backup-host](https://developer.android.com/jetpack/androidx/releases/test-backup) [View Source](https://cs.android.com/search?q=file:androidx/test/backup/host/Device.kt+class:androidx.test.backup.host.Device) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

*** ** * ** ***


```
@MustBeDocumented
@Retention(value = AnnotationRetention.RUNTIME)
@Target(allowedTargets = [AnnotationTarget.VALUE_PARAMETER])
public annotation Device
```

<br />

*** ** * ** ***

Qualifier annotation used for multi-device orchestration. Instructs the JUnit 5 extension which connected device characteristics to resolve.

A `https://developer.android.com/reference/androidx/test/backup/host/BackupRestoreController` parameter that asks for a serial number, through `https://developer.android.com/reference/androidx/test/backup/host/Device#serial()`, a binding of `https://developer.android.com/reference/androidx/test/backup/host/Device#role()` or a system property, gets the device with that serial number. The other controller parameters of a method or constructor each get a matching online device of their own when there are enough: in the order of the parameters, each takes the first free one by serial number, and an earlier parameter moves to another device that matches it if that frees one. A parameter that can't get a device of its own shares the first device that matches it.

A device matches when its API level is `https://developer.android.com/reference/androidx/test/backup/host/Device#api()`, if set, and from `https://developer.android.com/reference/androidx/test/backup/host/Device#minApi()` to `https://developer.android.com/reference/androidx/test/backup/host/Device#maxApi()`: an exact level such as `api = 34` matches the same devices as `minApi = 34, maxApi = 34`. The system properties `androidx.test.backup.device.apis`, a comma-separated list with an API level for each controller parameter, and `androidx.test.backup.device.api`, one API level for all of them, replace `https://developer.android.com/reference/androidx/test/backup/host/Device#api()` but not `https://developer.android.com/reference/androidx/test/backup/host/Device#minApi()` and `https://developer.android.com/reference/androidx/test/backup/host/Device#maxApi()`. So for parameters whose ranges don't overlap, use the list. In both, 0 means any API level, as it does for `https://developer.android.com/reference/androidx/test/backup/host/Device#api()`. A negative value, a `https://developer.android.com/reference/androidx/test/backup/host/Device#minApi()` above `https://developer.android.com/reference/androidx/test/backup/host/Device#maxApi()`, or an `https://developer.android.com/reference/androidx/test/backup/host/Device#api()` or system property outside them fails the test with an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/test/backup/host/Device#getApi()()` The API level that matches, exactly, such as 31 or 34. |
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/test/backup/host/Device#getMaxApi()()` The highest API level that matches. |
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/test/backup/host/Device#getMinApi()()` The lowest API level that matches. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/backup/host/Device#getRole()()` The role of the device in a multi-device test, such as `"source"` or `"target"`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/test/backup/host/Device#getSerial()()` The specific hardware/emulator serial number to match, or a name that the system property `androidx.test.backup.device.serial.<serial>` binds to a serial number. |

## Public methods

### getApi

```
public final @IntRange(from = 0) int getApi()
```

The API level that matches, exactly, such as 31 or 34. Defaults to 0 (any API level).

### getMaxApi

```
public final @IntRange(from = 0) int getMaxApi()
```

The highest API level that matches. Defaults to `Integer.MAX_VALUE` (no upper bound).

### getMinApi

```
public final @IntRange(from = 0) int getMinApi()
```

The lowest API level that matches. Defaults to 0 (no lower bound).

### getRole

```
public final @NonNull String getRole()
```

The role of the device in a multi-device test, such as `"source"` or `"target"`. The system property `androidx.test.backup.device.serial.<role>` binds the role to the device with that serial number, whatever `https://developer.android.com/reference/androidx/test/backup/host/Device#serial()` and the other device properties ask for. Without the property, the role doesn't change which device is selected. Defaults to "".

### getSerial

```
public final @NonNull String getSerial()
```

The specific hardware/emulator serial number to match, or a name that the system property `androidx.test.backup.device.serial.<serial>` binds to a serial number. The system properties `androidx.test.backup.device.serials` and `androidx.test.backup.device.serial` take precedence over a literal serial number. Defaults to "" (any match).