Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#nestedclasses) \| [Methods](https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#inhmethods)

# VirtualDeviceManager

*** ** * ** ***


`
public

final

class
VirtualDeviceManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.companion.virtual.VirtualDeviceManager |

<br />

*** ** * ** ***

System level service for creation and management of virtual devices.

VirtualDeviceManager enables interactive sharing of capabilities between the host Android
device and a remote device.

A device only supports VirtualDeviceManager if it enables it via `config_enableVirtualDeviceManager`. Otherwise `Context#getSystemService
(VirtualDeviceManager.class)` will return `null`.

VirtualDeviceManager provides support for the ComputerControl feature in Android. For a
device to support the ComputerControl feature, the device needs to:

- Enable support for feature `android.software.activities_on_secondary_displays`
- Enable support for VirtualDeviceManager `config_enableVirtualDeviceManager`
- Preload the ComputerControl extensions library `com.android.extensions
  .computercontrol`
- Preload the platform application `VirtualDeviceManager`

Devices that support the ComputerControl feature:

- MUST only allow applications to use the Computer Controls API if it is listed in the latest version of the agent allowlist.
- MUST NOT allow a Computer Controls Agent to automate any target applications that:
  - Are not included in the latest version of the allowlist OR
  - Are included in the latest version of the Computer Controls denylist OR
  - Do not have explicit opt-in user consent for automation by the requesting Computer Controls Agent
- MAY remove applications from the Computer Controls allowlist, or MAY add applications to the Computer Controls denylist, provided it results in a more restrictive set of automatable applications
- MUST support the per-app consent dialog UI and consent settings UI to allow users to manage consent for each target application per Computer Controls Agent

ComputerControl may only be used by agent applications holding the `https://developer.android.com/` permission and meeting the relevant policy
requirements. Only the current ASSISTANT role holder can use ComputerControl.

Not to be confused with the Android Studio's Virtual Device Manager, which allows
for device emulation.


Restricted for SDK Runtime environment in API level 34.

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager.VirtualDeviceListener` Listener for changes in the available virtual devices. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/companion/virtual/VirtualDevice` | ` https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#getVirtualDevice(int)(int deviceId) ` Returns the details of the virtual device with the given ID, if any. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/companion/virtual/VirtualDevice>` | ` https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#getVirtualDevices()() ` Returns the details of all available virtual devices. |
| ` static boolean` | ` https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#isVirtualCameraSupported()() ` Returns true if virtual cameras can be added to virtual devices on this device. |
| ` void` | ` https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#registerVirtualDeviceListener(java.util.concurrent.Executor,%20android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager.VirtualDeviceListener listener) ` Registers a virtual device listener to receive notifications when virtual devices are created or closed. |
| ` void` | ` https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#unregisterVirtualDeviceListener(android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)(https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager.VirtualDeviceListener listener) ` Unregisters a virtual device listener previously registered with `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#registerVirtualDeviceListener(java.util.concurrent.Executor,%20android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)`. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Public methods

### getVirtualDevice

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VirtualDevice getVirtualDevice (int deviceId)
```

Returns the details of the virtual device with the given ID, if any.

The returned object is a read-only representation of the virtual device that expose its
properties.

Note that if the virtual device is closed and becomes invalid, the returned object will
not be updated and may contain stale values. Use a `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager.VirtualDeviceListener` for real
time updates of the availability of virtual devices.

<br />

<br />

| Parameters ||
|---|---|
| `deviceId` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/companion/virtual/VirtualDevice` | the virtual device with the requested ID, or `null` if no such device exists or it has already been closed. <br /> |

### getVirtualDevices

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<VirtualDevice> getVirtualDevices ()
```

Returns the details of all available virtual devices.

The returned objects are read-only representations that expose the properties of all
existing virtual devices.

Note that if a virtual device is closed and becomes invalid, the returned objects will
not be updated and may contain stale values. Use a `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager.VirtualDeviceListener` for real
time updates of the availability of virtual devices.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/companion/virtual/VirtualDevice>` | This value cannot be `null`. <br /> |

### isVirtualCameraSupported

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static boolean isVirtualCameraSupported ()
```

Returns true if virtual cameras can be added to virtual devices on this device.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### registerVirtualDeviceListener

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void registerVirtualDeviceListener (Executor executor, 
                VirtualDeviceManager.VirtualDeviceListener listener)
```

Registers a virtual device listener to receive notifications when virtual devices are created
or closed.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: The executor where the listener is executed on. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `listener` | `VirtualDeviceManager.VirtualDeviceListener`: The listener to add. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#unregisterVirtualDeviceListener(android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)`

### unregisterVirtualDeviceListener

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void unregisterVirtualDeviceListener (VirtualDeviceManager.VirtualDeviceListener listener)
```

Unregisters a virtual device listener previously registered with
`https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#registerVirtualDeviceListener(java.util.concurrent.Executor,%20android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)`.

<br />

| Parameters ||
|---|---|
| `listener` | `VirtualDeviceManager.VirtualDeviceListener`: The listener to unregister. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/companion/virtual/VirtualDeviceManager#registerVirtualDeviceListener(java.util.concurrent.Executor,%20android.companion.virtual.VirtualDeviceManager.VirtualDeviceListener)`