Merge "Update the VDM documentation." into udc-dev am: 8b3f7da4a3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22356787

Change-Id: If93cfa1b45a6a0d95b0000694221eaa1043e3c72
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vladimir Komsiyski
2023-03-31 12:01:10 +00:00
committed by Automerger Merge Worker
15 changed files with 256 additions and 127 deletions

View File

@@ -39,21 +39,22 @@ import android.hardware.input.VirtualNavigationTouchpadConfig;
import android.os.ResultReceiver; import android.os.ResultReceiver;
/** /**
* Interface for a virtual device. * Interface for a virtual device for communication between the system server and the process of
* the owner of the virtual device.
* *
* @hide * @hide
*/ */
interface IVirtualDevice { interface IVirtualDevice {
/** /**
* Returns the association ID for this virtual device. * Returns the CDM association ID of this virtual device.
* *
* @see AssociationInfo#getId() * @see AssociationInfo#getId()
*/ */
int getAssociationId(); int getAssociationId();
/** /**
* Returns the unique device ID for this virtual device. * Returns the unique ID of this virtual device.
*/ */
int getDeviceId(); int getDeviceId();
@@ -64,55 +65,99 @@ interface IVirtualDevice {
void close(); void close();
/** /**
* Notifies of an audio session being started. * Notifies that an audio session being started.
*/ */
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void onAudioSessionStarting( void onAudioSessionStarting(int displayId, IAudioRoutingCallback routingCallback,
int displayId,
IAudioRoutingCallback routingCallback,
IAudioConfigChangedCallback configChangedCallback); IAudioConfigChangedCallback configChangedCallback);
/**
* Notifies that an audio session has ended.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void onAudioSessionEnded(); void onAudioSessionEnded();
/**
* Creates a new dpad and registers it with the input framework with the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void createVirtualDpad( void createVirtualDpad(in VirtualDpadConfig config, IBinder token);
in VirtualDpadConfig config,
IBinder token); /**
* Creates a new keyboard and registers it with the input framework with the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void createVirtualKeyboard( void createVirtualKeyboard(in VirtualKeyboardConfig config, IBinder token);
in VirtualKeyboardConfig config,
IBinder token); /**
* Creates a new mouse and registers it with the input framework with the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void createVirtualMouse( void createVirtualMouse(in VirtualMouseConfig config, IBinder token);
in VirtualMouseConfig config,
IBinder token); /**
* Creates a new touchscreen and registers it with the input framework with the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void createVirtualTouchscreen( void createVirtualTouchscreen(in VirtualTouchscreenConfig config, IBinder token);
in VirtualTouchscreenConfig config,
IBinder token); /**
* Creates a new navigation touchpad and registers it with the input framework with the given
* token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void createVirtualNavigationTouchpad( void createVirtualNavigationTouchpad(in VirtualNavigationTouchpadConfig config, IBinder token);
in VirtualNavigationTouchpadConfig config,
IBinder token); /**
* Removes the input device corresponding to the given token from the framework.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void unregisterInputDevice(IBinder token); void unregisterInputDevice(IBinder token);
/**
* Returns the ID of the device corresponding to the given token, as registered with the input
* framework.
*/
int getInputDeviceId(IBinder token); int getInputDeviceId(IBinder token);
/**
* Injects a key event to the virtual dpad corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event); boolean sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event);
/**
* Injects a key event to the virtual keyboard corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendKeyEvent(IBinder token, in VirtualKeyEvent event); boolean sendKeyEvent(IBinder token, in VirtualKeyEvent event);
/**
* Injects a button event to the virtual mouse corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendButtonEvent(IBinder token, in VirtualMouseButtonEvent event); boolean sendButtonEvent(IBinder token, in VirtualMouseButtonEvent event);
/**
* Injects a relative event to the virtual mouse corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event); boolean sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event);
/**
* Injects a scroll event to the virtual mouse corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event); boolean sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event);
/**
* Injects a touch event to the virtual touch input device corresponding to the given token.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
boolean sendTouchEvent(IBinder token, in VirtualTouchEvent event); boolean sendTouchEvent(IBinder token, in VirtualTouchEvent event);
/** /**
* Returns all virtual sensors for this device. * Returns all virtual sensors created for this device.
*/ */
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
List<VirtualSensor> getVirtualSensorList(); List<VirtualSensor> getVirtualSensorList();
@@ -126,8 +171,13 @@ interface IVirtualDevice {
/** /**
* Launches a pending intent on the given display that is owned by this virtual device. * Launches a pending intent on the given display that is owned by this virtual device.
*/ */
void launchPendingIntent( void launchPendingIntent(int displayId, in PendingIntent pendingIntent,
int displayId, in PendingIntent pendingIntent, in ResultReceiver resultReceiver); in ResultReceiver resultReceiver);
/**
* Returns the current cursor position of the mouse corresponding to the given token, in x and y
* coordinates.
*/
PointF getCursorPosition(IBinder token); PointF getCursorPosition(IBinder token);
/** Sets whether to show or hide the cursor while this virtual device is active. */ /** Sets whether to show or hide the cursor while this virtual device is active. */
@@ -140,8 +190,12 @@ interface IVirtualDevice {
* intent. * intent.
*/ */
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void registerIntentInterceptor( void registerIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor,
in IVirtualDeviceIntentInterceptor intentInterceptor, in IntentFilter filter); in IntentFilter filter);
/**
* Unregisters a previously registered intent interceptor.
*/
@EnforcePermission("CREATE_VIRTUAL_DEVICE") @EnforcePermission("CREATE_VIRTUAL_DEVICE")
void unregisterIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor); void unregisterIntentInterceptor(in IVirtualDeviceIntentInterceptor intentInterceptor);
} }

View File

@@ -101,7 +101,7 @@ interface IVirtualDeviceManager {
* *
* @param deviceId id of the virtual device. * @param deviceId id of the virtual device.
* @param sound effect type corresponding to * @param sound effect type corresponding to
* {@code android.media.AudioManager.SystemSoundEffect} * {@code android.media.AudioManager.SystemSoundEffect}
*/ */
void playSoundEffect(int deviceId, int effectType); void playSoundEffect(int deviceId, int effectType);
} }

View File

@@ -28,7 +28,7 @@ oneway interface IVirtualDeviceSoundEffectListener {
* Called when there's sound effect to be played on Virtual Device. * Called when there's sound effect to be played on Virtual Device.
* *
* @param sound effect type corresponding to * @param sound effect type corresponding to
* {@code android.media.AudioManager.SystemSoundEffect} * {@code android.media.AudioManager.SystemSoundEffect}
*/ */
void onPlaySoundEffect(int effectType); void onPlaySoundEffect(int effectType);
} }

View File

@@ -26,6 +26,11 @@ import java.util.Objects;
/** /**
* Details of a particular virtual device. * Details of a particular virtual device.
*
* <p>Read-only device representation exposing the properties of an existing virtual device.
*
* <p class="note">Not to be confused with {@link VirtualDeviceManager.VirtualDevice}, which is used
* by the virtual device creator and allows them to manage the device.
*/ */
public final class VirtualDevice implements Parcelable { public final class VirtualDevice implements Parcelable {

View File

@@ -68,7 +68,13 @@ import java.util.concurrent.Executor;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
/** /**
* System level service for managing virtual devices. * System level service for creation and management of virtual devices.
*
* <p>VirtualDeviceManager enables interactive sharing of capabilities between the host Android
* device and a remote device.
*
* <p class="note">Not to be confused with the Android Studio's Virtual Device Manager, which allows
* for device emulation.
*/ */
@SystemService(Context.VIRTUAL_DEVICE_SERVICE) @SystemService(Context.VIRTUAL_DEVICE_SERVICE)
public final class VirtualDeviceManager { public final class VirtualDeviceManager {
@@ -174,6 +180,9 @@ public final class VirtualDeviceManager {
/** /**
* Returns the details of all available virtual devices. * Returns the details of all available virtual devices.
*
* <p>The returned objects are read-only representations that expose the properties of all
* existing virtual devices.
*/ */
@NonNull @NonNull
public List<android.companion.virtual.VirtualDevice> getVirtualDevices() { public List<android.companion.virtual.VirtualDevice> getVirtualDevices() {
@@ -252,11 +261,12 @@ public final class VirtualDeviceManager {
* *
* @param deviceId - id of the virtual audio device * @param deviceId - id of the virtual audio device
* @return Device specific session id to be used for audio playback (see * @return Device specific session id to be used for audio playback (see
* {@link android.media.AudioManager.generateAudioSessionId}) if virtual device has * {@link AudioManager#generateAudioSessionId}) if virtual device has
* {@link VirtualDeviceParams.POLICY_TYPE_AUDIO} set to * {@link VirtualDeviceParams#POLICY_TYPE_AUDIO} set to
* {@link VirtualDeviceParams.DEVICE_POLICY_CUSTOM} and Virtual Audio Device * {@link VirtualDeviceParams#DEVICE_POLICY_CUSTOM} and Virtual Audio Device
* is configured in context-aware mode. * is configured in context-aware mode. Otherwise
* Otherwise {@link AUDIO_SESSION_ID_GENERATE} constant is returned. * {@link AudioManager#AUDIO_SESSION_ID_GENERATE} constant is returned.
*
* @hide * @hide
*/ */
public int getAudioPlaybackSessionId(int deviceId) { public int getAudioPlaybackSessionId(int deviceId) {
@@ -275,11 +285,12 @@ public final class VirtualDeviceManager {
* *
* @param deviceId - id of the virtual audio device * @param deviceId - id of the virtual audio device
* @return Device specific session id to be used for audio recording (see * @return Device specific session id to be used for audio recording (see
* {@link android.media.AudioManager.generateAudioSessionId}) if virtual device has * {@link AudioManager#generateAudioSessionId}) if virtual device has
* {@link VirtualDeviceParams.POLICY_TYPE_AUDIO} set to * {@link VirtualDeviceParams#POLICY_TYPE_AUDIO} set to
* {@link VirtualDeviceParams.DEVICE_POLICY_CUSTOM} and Virtual Audio Device * {@link VirtualDeviceParams#DEVICE_POLICY_CUSTOM} and Virtual Audio Device
* is configured in context-aware mode. * is configured in context-aware mode. Otherwise
* Otherwise {@link AUDIO_SESSION_ID_GENERATE} constant is returned. * {@link AudioManager#AUDIO_SESSION_ID_GENERATE} constant is returned.
*
* @hide * @hide
*/ */
public int getAudioRecordingSessionId(int deviceId) { public int getAudioRecordingSessionId(int deviceId) {
@@ -296,10 +307,11 @@ public final class VirtualDeviceManager {
/** /**
* Requests sound effect to be played on virtual device. * Requests sound effect to be played on virtual device.
* *
* @see android.media.AudioManager#playSoundEffect(int) * @see AudioManager#playSoundEffect(int)
* *
* @param deviceId - id of the virtual audio device * @param deviceId - id of the virtual audio device
* @param effectType the type of sound effect * @param effectType the type of sound effect
*
* @hide * @hide
*/ */
public void playSoundEffect(int deviceId, @AudioManager.SystemSoundEffect int effectType) { public void playSoundEffect(int deviceId, @AudioManager.SystemSoundEffect int effectType) {
@@ -315,11 +327,18 @@ public final class VirtualDeviceManager {
} }
/** /**
* A virtual device has its own virtual display, audio output, microphone, sensors, etc. The * A representation of a virtual device.
* creator of a virtual device can take the output from the virtual display and stream it over
* to another device, and inject input events that are received from the remote device.
* *
* TODO(b/204081582): Consider using a builder pattern for the input APIs. * <p>A virtual device can have its own virtual displays, audio input/output, sensors, etc.
* The creator of a virtual device can take the output from the virtual display and stream it
* over to another device, and inject input and sensor events that are received from the remote
* device.
*
* <p>This object is only used by the virtual device creator and allows them to manage the
* device's behavior, peripherals, and the user interaction with that device.
*
* <p class="note">Not to be confused with {@link android.companion.virtual.VirtualDevice},
* which is a read-only representation exposing the properties of an existing virtual device.
* *
* @hide * @hide
*/ */
@@ -346,8 +365,10 @@ public final class VirtualDeviceManager {
} }
/** /**
* @return A new Context bound to this device. This is a convenience method equivalent to * Returns a new context bound to this device.
* calling {@link Context#createDeviceContext(int)} with the device id of this device. *
* <p>This is a convenience method equivalent to calling
* {@link Context#createDeviceContext(int)} with the id of this device.
*/ */
public @NonNull Context createContext() { public @NonNull Context createContext() {
return mVirtualDeviceInternal.createContext(); return mVirtualDeviceInternal.createContext();
@@ -400,20 +421,19 @@ public final class VirtualDeviceManager {
* @param height The height of the virtual display in pixels, must be greater than 0. * @param height The height of the virtual display in pixels, must be greater than 0.
* @param densityDpi The density of the virtual display in dpi, must be greater than 0. * @param densityDpi The density of the virtual display in dpi, must be greater than 0.
* @param surface The surface to which the content of the virtual display should * @param surface The surface to which the content of the virtual display should
* be rendered, or null if there is none initially. The surface can also be set later using * be rendered, or null if there is none initially. The surface can also be set later
* {@link VirtualDisplay#setSurface(Surface)}. * using {@link VirtualDisplay#setSurface(Surface)}.
* @param flags A combination of virtual display flags accepted by * @param flags A combination of virtual display flags accepted by
* {@link DisplayManager#createVirtualDisplay}. In addition, the following flags are * {@link DisplayManager#createVirtualDisplay}. In addition, the following flags are
* automatically set for all virtual devices: * automatically set for all virtual devices:
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC VIRTUAL_DISPLAY_FLAG_PUBLIC} and * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_PUBLIC} and
* {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY * {@link DisplayManager#VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
* VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
* @param executor The executor on which {@code callback} will be invoked. This is ignored * @param executor The executor on which {@code callback} will be invoked. This is ignored
* if {@code callback} is {@code null}. If {@code callback} is specified, this executor must * if {@code callback} is {@code null}. If {@code callback} is specified, this executor
* not be null. * must not be null.
* @param callback Callback to call when the state of the {@link VirtualDisplay} changes * @param callback Callback to call when the state of the {@link VirtualDisplay} changes
* @return The newly created virtual display, or {@code null} if the application could * @return The newly created virtual display, or {@code null} if the application could
* not create the virtual display. * not create the virtual display.
* *
* @see DisplayManager#createVirtualDisplay * @see DisplayManager#createVirtualDisplay
* *
@@ -450,11 +470,11 @@ public final class VirtualDeviceManager {
* *
* @param config The configuration of the display. * @param config The configuration of the display.
* @param executor The executor on which {@code callback} will be invoked. This is ignored * @param executor The executor on which {@code callback} will be invoked. This is ignored
* if {@code callback} is {@code null}. If {@code callback} is specified, this executor must * if {@code callback} is {@code null}. If {@code callback} is specified, this executor
* not be null. * must not be null.
* @param callback Callback to call when the state of the {@link VirtualDisplay} changes * @param callback Callback to call when the state of the {@link VirtualDisplay} changes
* @return The newly created virtual display, or {@code null} if the application could * @return The newly created virtual display, or {@code null} if the application could
* not create the virtual display. * not create the virtual display.
* *
* @see DisplayManager#createVirtualDisplay * @see DisplayManager#createVirtualDisplay
*/ */
@@ -478,7 +498,7 @@ public final class VirtualDeviceManager {
/** /**
* Creates a virtual dpad. * Creates a virtual dpad.
* *
* @param config the configurations of the virtual Dpad. * @param config the configurations of the virtual dpad.
*/ */
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@NonNull @NonNull
@@ -500,11 +520,10 @@ public final class VirtualDeviceManager {
/** /**
* Creates a virtual keyboard. * Creates a virtual keyboard.
* *
* @param display the display that the events inputted through this device should * @param display the display that the events inputted through this device should target.
* target * @param inputDeviceName the name of this keyboard device.
* @param inputDeviceName the name to call this input device * @param vendorId the PCI vendor id.
* @param vendorId the PCI vendor id * @param productId the product id, as defined by the vendor.
* @param productId the product id, as defined by the vendor
* @see #createVirtualKeyboard(VirtualKeyboardConfig config) * @see #createVirtualKeyboard(VirtualKeyboardConfig config)
* @deprecated Use {@link #createVirtualKeyboard(VirtualKeyboardConfig config)} instead * @deprecated Use {@link #createVirtualKeyboard(VirtualKeyboardConfig config)} instead
*/ */
@@ -537,14 +556,12 @@ public final class VirtualDeviceManager {
/** /**
* Creates a virtual mouse. * Creates a virtual mouse.
* *
* @param display the display that the events inputted through this device should * @param display the display that the events inputted through this device should target.
* target * @param inputDeviceName the name of this mouse.
* @param inputDeviceName the name to call this input device * @param vendorId the PCI vendor id.
* @param vendorId the PCI vendor id * @param productId the product id, as defined by the vendor.
* @param productId the product id, as defined by the vendor
* @see #createVirtualMouse(VirtualMouseConfig config) * @see #createVirtualMouse(VirtualMouseConfig config)
* @deprecated Use {@link #createVirtualMouse(VirtualMouseConfig config)} instead * @deprecated Use {@link #createVirtualMouse(VirtualMouseConfig config)} instead
* *
*/ */
@Deprecated @Deprecated
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@@ -576,11 +593,10 @@ public final class VirtualDeviceManager {
/** /**
* Creates a virtual touchscreen. * Creates a virtual touchscreen.
* *
* @param display the display that the events inputted through this device should * @param display the display that the events inputted through this device should target.
* target * @param inputDeviceName the name of this touchscreen device.
* @param inputDeviceName the name to call this input device * @param vendorId the PCI vendor id.
* @param vendorId the PCI vendor id * @param productId the product id, as defined by the vendor.
* @param productId the product id, as defined by the vendor
* @see #createVirtualTouchscreen(VirtualTouchscreenConfig config) * @see #createVirtualTouchscreen(VirtualTouchscreenConfig config)
* @deprecated Use {@link #createVirtualTouchscreen(VirtualTouchscreenConfig config)} * @deprecated Use {@link #createVirtualTouchscreen(VirtualTouchscreenConfig config)}
* instead * instead
@@ -605,11 +621,13 @@ public final class VirtualDeviceManager {
/** /**
* Creates a virtual touchpad in navigation mode. * Creates a virtual touchpad in navigation mode.
* *
* A touchpad in navigation mode means that its events are interpreted as navigation events * <p>A touchpad in navigation mode means that its events are interpreted as navigation
* (up, down, etc) instead of using them to update a cursor's absolute position. If the * events (up, down, etc) instead of using them to update a cursor's absolute position. If
* events are not consumed they are converted to DPAD events. * the events are not consumed they are converted to DPAD events and delivered to the target
* again.
* *
* @param config the configurations of the virtual navigation touchpad. * @param config the configurations of the virtual navigation touchpad.
* @see android.view.InputDevice#SOURCE_TOUCH_NAVIGATION
*/ */
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@NonNull @NonNull
@@ -629,10 +647,10 @@ public final class VirtualDeviceManager {
* *
* @param display The target virtual display to capture from and inject into. * @param display The target virtual display to capture from and inject into.
* @param executor The {@link Executor} object for the thread on which to execute * @param executor The {@link Executor} object for the thread on which to execute
* the callback. If <code>null</code>, the {@link Executor} associated with * the callback. If <code>null</code>, the {@link Executor} associated with the main
* the main {@link Looper} will be used. * {@link Looper} will be used.
* @param callback Interface to be notified when playback or recording configuration of * @param callback Interface to be notified when playback or recording configuration of
* applications running on virtual display is changed. * applications running on virtual display is changed.
* @return A {@link VirtualAudioDevice} instance. * @return A {@link VirtualAudioDevice} instance.
*/ */
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@@ -648,7 +666,7 @@ public final class VirtualDeviceManager {
* Sets the visibility of the pointer icon for this VirtualDevice's associated displays. * Sets the visibility of the pointer icon for this VirtualDevice's associated displays.
* *
* @param showPointerIcon True if the pointer should be shown; false otherwise. The default * @param showPointerIcon True if the pointer should be shown; false otherwise. The default
* visibility is true. * visibility is true.
*/ */
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@NonNull @NonNull
@@ -670,8 +688,7 @@ public final class VirtualDeviceManager {
} }
/** /**
* Removes an activity listener previously added with * Removes an activity listener previously added with {@link #addActivityListener}.
* {@link #addActivityListener}.
* *
* @param listener The listener to remove. * @param listener The listener to remove.
* @see #addActivityListener(Executor, ActivityListener) * @see #addActivityListener(Executor, ActivityListener)
@@ -693,10 +710,10 @@ public final class VirtualDeviceManager {
} }
/** /**
* Removes a sound effect listener previously added with {@link #addActivityListener}. * Removes a sound effect listener previously added with {@link #addSoundEffectListener}.
* *
* @param soundEffectListener The listener to remove. * @param soundEffectListener The listener to remove.
* @see #addActivityListener(Executor, ActivityListener) * @see #addSoundEffectListener(Executor, SoundEffectListener)
*/ */
public void removeSoundEffectListener(@NonNull SoundEffectListener soundEffectListener) { public void removeSoundEffectListener(@NonNull SoundEffectListener soundEffectListener) {
mVirtualDeviceInternal.removeSoundEffectListener(soundEffectListener); mVirtualDeviceInternal.removeSoundEffectListener(soundEffectListener);
@@ -723,7 +740,7 @@ public final class VirtualDeviceManager {
} }
/** /**
* Unregisters the intent interceptorCallback previously registered with * Unregisters the intent interceptor previously registered with
* {@link #registerIntentInterceptor}. * {@link #registerIntentInterceptor}.
*/ */
@RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE)
@@ -761,9 +778,9 @@ public final class VirtualDeviceManager {
* {@link #onDisplayEmpty(int)} will be called. If the value topActivity is cached, it * {@link #onDisplayEmpty(int)} will be called. If the value topActivity is cached, it
* should be cleared when {@link #onDisplayEmpty(int)} is called. * should be cleared when {@link #onDisplayEmpty(int)} is called.
* *
* @param displayId The display ID on which the activity change happened. * @param displayId The display ID on which the activity change happened.
* @param topActivity The component name of the top activity. * @param topActivity The component name of the top activity.
* @param userId The user ID associated with the top activity. * @param userId The user ID associated with the top activity.
*/ */
default void onTopActivityChanged(int displayId, @NonNull ComponentName topActivity, default void onTopActivityChanged(int displayId, @NonNull ComponentName topActivity,
@UserIdInt int userId) {} @UserIdInt int userId) {}
@@ -800,6 +817,7 @@ public final class VirtualDeviceManager {
/** /**
* Listener for system sound effect playback on virtual device. * Listener for system sound effect playback on virtual device.
*
* @hide * @hide
*/ */
@SystemApi @SystemApi
@@ -808,8 +826,8 @@ public final class VirtualDeviceManager {
/** /**
* Called when there's a system sound effect to be played on virtual device. * Called when there's a system sound effect to be played on virtual device.
* *
* @param effectType - system sound effect type, see * @param effectType - system sound effect type
* {@code android.media.AudioManager.SystemSoundEffect} * @see android.media.AudioManager.SystemSoundEffect
*/ */
void onPlaySoundEffect(@AudioManager.SystemSoundEffect int effectType); void onPlaySoundEffect(@AudioManager.SystemSoundEffect int effectType);
} }

View File

@@ -34,6 +34,7 @@ import android.companion.virtual.sensor.VirtualSensorCallback;
import android.companion.virtual.sensor.VirtualSensorConfig; import android.companion.virtual.sensor.VirtualSensorConfig;
import android.companion.virtual.sensor.VirtualSensorDirectChannelCallback; import android.companion.virtual.sensor.VirtualSensorDirectChannelCallback;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.SharedMemory; import android.os.SharedMemory;
@@ -680,7 +681,7 @@ public final class VirtualDeviceParams implements Parcelable {
* {@link #NAVIGATION_POLICY_DEFAULT_ALLOWED}, meaning activities are allowed to launch * {@link #NAVIGATION_POLICY_DEFAULT_ALLOWED}, meaning activities are allowed to launch
* unless they are in {@code blockedCrossTaskNavigations}. * unless they are in {@code blockedCrossTaskNavigations}.
* *
* <p> This method must not be called if {@link #setAllowedCrossTaskNavigations(Set)} has * <p>This method must not be called if {@link #setAllowedCrossTaskNavigations(Set)} has
* been called. * been called.
* *
* @throws IllegalArgumentException if {@link #setAllowedCrossTaskNavigations(Set)} has * @throws IllegalArgumentException if {@link #setAllowedCrossTaskNavigations(Set)} has
@@ -847,11 +848,11 @@ public final class VirtualDeviceParams implements Parcelable {
* <p>Requires {@link #DEVICE_POLICY_CUSTOM} to be set for {@link #POLICY_TYPE_AUDIO}, * <p>Requires {@link #DEVICE_POLICY_CUSTOM} to be set for {@link #POLICY_TYPE_AUDIO},
* otherwise {@link #build()} method will throw {@link IllegalArgumentException} if * otherwise {@link #build()} method will throw {@link IllegalArgumentException} if
* the playback session id is set to value other than * the playback session id is set to value other than
* {@link android.media.AudioManager.AUDIO_SESSION_ID_GENERATE}. * {@link android.media.AudioManager#AUDIO_SESSION_ID_GENERATE}.
* *
* @param playbackSessionId requested device-specific audio session id for playback * @param playbackSessionId requested device-specific audio session id for playback
* @see android.media.AudioManager.generateAudioSessionId() * @see android.media.AudioManager#generateAudioSessionId()
* @see android.media.AudioTrack.Builder.setContext(Context) * @see android.media.AudioTrack.Builder#setContext(Context)
*/ */
@NonNull @NonNull
public Builder setAudioPlaybackSessionId(int playbackSessionId) { public Builder setAudioPlaybackSessionId(int playbackSessionId) {
@@ -871,11 +872,11 @@ public final class VirtualDeviceParams implements Parcelable {
* <p>Requires {@link #DEVICE_POLICY_CUSTOM} to be set for {@link #POLICY_TYPE_AUDIO}, * <p>Requires {@link #DEVICE_POLICY_CUSTOM} to be set for {@link #POLICY_TYPE_AUDIO},
* otherwise {@link #build()} method will throw {@link IllegalArgumentException} if * otherwise {@link #build()} method will throw {@link IllegalArgumentException} if
* the recording session id is set to value other than * the recording session id is set to value other than
* {@link android.media.AudioManager.AUDIO_SESSION_ID_GENERATE}. * {@link android.media.AudioManager#AUDIO_SESSION_ID_GENERATE}.
* *
* @param recordingSessionId requested device-specific audio session id for playback * @param recordingSessionId requested device-specific audio session id for playback
* @see android.media.AudioManager.generateAudioSessionId() * @see android.media.AudioManager#generateAudioSessionId()
* @see android.media.AudioRecord.Builder.setContext(Context) * @see android.media.AudioRecord.Builder#setContext(Context)
*/ */
@NonNull @NonNull
public Builder setAudioRecordingSessionId(int recordingSessionId) { public Builder setAudioRecordingSessionId(int recordingSessionId) {

View File

@@ -56,12 +56,12 @@ public final class AudioCapture {
/** /**
* Sets the {@link AudioRecord} to handle audio capturing. * Sets the {@link AudioRecord} to handle audio capturing.
* Callers may call this multiple times with different audio records to change
* the underlying {@link AudioRecord} without stopping and re-starting recording.
* *
* @param audioRecord The underlying {@link AudioRecord} to use for capture, * <p>Callers may call this multiple times with different audio records to change the underlying
* or null if no audio (i.e. silence) should be captured while still keeping the * {@link AudioRecord} without stopping and re-starting recording.
* record in a recording state. *
* @param audioRecord The underlying {@link AudioRecord} to use for capture, or null if no audio
* (i.e. silence) should be captured while still keeping the record in a recording state.
*/ */
void setAudioRecord(@Nullable AudioRecord audioRecord) { void setAudioRecord(@Nullable AudioRecord audioRecord) {
Log.d(TAG, "set AudioRecord with " + audioRecord); Log.d(TAG, "set AudioRecord with " + audioRecord);

View File

@@ -65,12 +65,12 @@ public final class AudioInjection {
/** /**
* Sets the {@link AudioTrack} to handle audio injection. * Sets the {@link AudioTrack} to handle audio injection.
* Callers may call this multiple times with different audio tracks to change
* the underlying {@link AudioTrack} without stopping and re-starting injection.
* *
* @param audioTrack The underlying {@link AudioTrack} to use for injection, * <p>Callers may call this multiple times with different audio tracks to change the underlying
* or null if no audio (i.e. silence) should be injected while still keeping the * {@link AudioTrack} without stopping and re-starting injection.
* record in a playing state. *
* @param audioTrack The underlying {@link AudioTrack} to use for injection, or null if no audio
* (i.e. silence) should be injected while still keeping the record in a playing state.
*/ */
void setAudioTrack(@Nullable AudioTrack audioTrack) { void setAudioTrack(@Nullable AudioTrack audioTrack) {
Log.d(TAG, "set AudioTrack with " + audioTrack); Log.d(TAG, "set AudioTrack with " + audioTrack);

View File

@@ -33,7 +33,7 @@ oneway interface IVirtualSensorCallback {
* @param enabled Whether the sensor is enabled. * @param enabled Whether the sensor is enabled.
* @param samplingPeriodMicros The requested sensor's sampling period in microseconds. * @param samplingPeriodMicros The requested sensor's sampling period in microseconds.
* @param batchReportingLatencyMicros The requested maximum time interval in microseconds * @param batchReportingLatencyMicros The requested maximum time interval in microseconds
* between the delivery of two batches of sensor events. * between the delivery of two batches of sensor events.
*/ */
void onConfigurationChanged(in VirtualSensor sensor, boolean enabled, int samplingPeriodMicros, void onConfigurationChanged(in VirtualSensor sensor, boolean enabled, int samplingPeriodMicros,
int batchReportLatencyMicros); int batchReportLatencyMicros);
@@ -60,7 +60,7 @@ oneway interface IVirtualSensorCallback {
* @param sensor The sensor, for which the channel was configured. * @param sensor The sensor, for which the channel was configured.
* @param rateLevel The rate level used to configure the direct sensor channel. * @param rateLevel The rate level used to configure the direct sensor channel.
* @param reportToken A positive sensor report token, used to differentiate between events from * @param reportToken A positive sensor report token, used to differentiate between events from
* different sensors within the same channel. * different sensors within the same channel.
*/ */
void onDirectChannelConfigured(int channelHandle, in VirtualSensor sensor, int rateLevel, void onDirectChannelConfigured(int channelHandle, in VirtualSensor sensor, int rateLevel,
int reportToken); int reportToken);

View File

@@ -30,7 +30,7 @@ import android.os.RemoteException;
* Representation of a sensor on a remote device, capable of sending events, such as an * Representation of a sensor on a remote device, capable of sending events, such as an
* accelerometer or a gyroscope. * accelerometer or a gyroscope.
* *
* This registers the sensor device with the sensor framework as a runtime sensor. * <p>A virtual sensor device is registered with the sensor framework as a runtime sensor.
* *
* @hide * @hide
*/ */

View File

@@ -45,10 +45,10 @@ public interface VirtualSensorCallback {
* *
* @param sensor The sensor whose requested injection parameters have changed. * @param sensor The sensor whose requested injection parameters have changed.
* @param enabled Whether the sensor is enabled. True if any listeners are currently registered, * @param enabled Whether the sensor is enabled. True if any listeners are currently registered,
* and false otherwise. * and false otherwise.
* @param samplingPeriod The requested sampling period of the sensor. * @param samplingPeriod The requested sampling period of the sensor.
* @param batchReportLatency The requested maximum time interval between the delivery of two * @param batchReportLatency The requested maximum time interval between the delivery of two
* batches of sensor events. * batches of sensor events.
*/ */
void onConfigurationChanged(@NonNull VirtualSensor sensor, boolean enabled, void onConfigurationChanged(@NonNull VirtualSensor sensor, boolean enabled,
@NonNull Duration samplingPeriod, @NonNull Duration batchReportLatency); @NonNull Duration samplingPeriod, @NonNull Duration batchReportLatency);

View File

@@ -31,7 +31,9 @@ import java.util.Objects;
/** /**
* Configuration for creation of a virtual sensor. * Configuration for creation of a virtual sensor.
*
* @see VirtualSensor * @see VirtualSensor
*
* @hide * @hide
*/ */
@SystemApi @SystemApi
@@ -122,6 +124,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Returns the vendor string of the sensor. * Returns the vendor string of the sensor.
*
* @see Builder#setVendor * @see Builder#setVendor
*/ */
@Nullable @Nullable
@@ -130,7 +133,8 @@ public final class VirtualSensorConfig implements Parcelable {
} }
/** /**
* Returns maximum range of the sensor in the sensor's unit. * Returns the maximum range of the sensor in the sensor's unit.
*
* @see Sensor#getMaximumRange * @see Sensor#getMaximumRange
*/ */
public float getMaximumRange() { public float getMaximumRange() {
@@ -138,7 +142,8 @@ public final class VirtualSensorConfig implements Parcelable {
} }
/** /**
* Returns The resolution of the sensor in the sensor's unit. * Returns the resolution of the sensor in the sensor's unit.
*
* @see Sensor#getResolution * @see Sensor#getResolution
*/ */
public float getResolution() { public float getResolution() {
@@ -146,7 +151,8 @@ public final class VirtualSensorConfig implements Parcelable {
} }
/** /**
* Returns The power in mA used by this sensor while in use. * Returns the power in mA used by this sensor while in use.
*
* @see Sensor#getPower * @see Sensor#getPower
*/ */
public float getPower() { public float getPower() {
@@ -154,8 +160,9 @@ public final class VirtualSensorConfig implements Parcelable {
} }
/** /**
* Returns The minimum delay allowed between two events in microseconds, or zero depending on * Returns the minimum delay allowed between two events in microseconds, or zero depending on
* the sensor type. * the sensor type.
*
* @see Sensor#getMinDelay * @see Sensor#getMinDelay
*/ */
public int getMinDelay() { public int getMinDelay() {
@@ -163,7 +170,8 @@ public final class VirtualSensorConfig implements Parcelable {
} }
/** /**
* Returns The maximum delay between two sensor events in microseconds. * Returns the maximum delay between two sensor events in microseconds.
*
* @see Sensor#getMaxDelay * @see Sensor#getMaxDelay
*/ */
public int getMaxDelay() { public int getMaxDelay() {
@@ -201,6 +209,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Returns the sensor flags. * Returns the sensor flags.
*
* @hide * @hide
*/ */
public int getFlags() { public int getFlags() {
@@ -233,7 +242,7 @@ public final class VirtualSensorConfig implements Parcelable {
* *
* @param type The type of the sensor, matching {@link Sensor#getType}. * @param type The type of the sensor, matching {@link Sensor#getType}.
* @param name The name of the sensor. Must be unique among all sensors with the same type * @param name The name of the sensor. Must be unique among all sensors with the same type
* that belong to the same virtual device. * that belong to the same virtual device.
*/ */
public Builder(@IntRange(from = 1) int type, @NonNull String name) { public Builder(@IntRange(from = 1) int type, @NonNull String name) {
if (type <= 0) { if (type <= 0) {
@@ -275,6 +284,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Sets the maximum range of the sensor in the sensor's unit. * Sets the maximum range of the sensor in the sensor's unit.
*
* @see Sensor#getMaximumRange * @see Sensor#getMaximumRange
*/ */
@NonNull @NonNull
@@ -285,6 +295,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Sets the resolution of the sensor in the sensor's unit. * Sets the resolution of the sensor in the sensor's unit.
*
* @see Sensor#getResolution * @see Sensor#getResolution
*/ */
@NonNull @NonNull
@@ -295,6 +306,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Sets the power in mA used by this sensor while in use. * Sets the power in mA used by this sensor while in use.
*
* @see Sensor#getPower * @see Sensor#getPower
*/ */
@NonNull @NonNull
@@ -305,6 +317,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Sets the minimum delay allowed between two events in microseconds. * Sets the minimum delay allowed between two events in microseconds.
*
* @see Sensor#getMinDelay * @see Sensor#getMinDelay
*/ */
@NonNull @NonNull
@@ -315,6 +328,7 @@ public final class VirtualSensorConfig implements Parcelable {
/** /**
* Sets the maximum delay between two sensor events in microseconds. * Sets the maximum delay between two sensor events in microseconds.
*
* @see Sensor#getMaxDelay * @see Sensor#getMaxDelay
*/ */
@NonNull @NonNull
@@ -339,11 +353,11 @@ public final class VirtualSensorConfig implements Parcelable {
* Sets whether direct sensor channel of the given types is supported. * Sets whether direct sensor channel of the given types is supported.
* *
* @param memoryTypes A combination of {@link SensorDirectChannel.MemoryType} flags * @param memoryTypes A combination of {@link SensorDirectChannel.MemoryType} flags
* indicating the types of shared memory supported for creating direct channels. Only * indicating the types of shared memory supported for creating direct channels. Only
* {@link SensorDirectChannel#TYPE_MEMORY_FILE} direct channels may be supported for virtual * {@link SensorDirectChannel#TYPE_MEMORY_FILE} direct channels may be supported for
* sensors. * virtual sensors.
* @throws IllegalArgumentException if {@link SensorDirectChannel#TYPE_HARDWARE_BUFFER} is * @throws IllegalArgumentException if {@link SensorDirectChannel#TYPE_HARDWARE_BUFFER} is
* set to be supported. * set to be supported.
*/ */
@NonNull @NonNull
public VirtualSensorConfig.Builder setDirectChannelTypesSupported( public VirtualSensorConfig.Builder setDirectChannelTypesSupported(

View File

@@ -45,6 +45,8 @@ import android.os.SharedMemory;
* <p>The callback is tied to the VirtualDevice's lifetime as the virtual sensors are created when * <p>The callback is tied to the VirtualDevice's lifetime as the virtual sensors are created when
* the device is created and destroyed when the device is destroyed. * the device is created and destroyed when the device is destroyed.
* *
* @see VirtualSensorDirectChannelWriter
*
* @hide * @hide
*/ */
@SystemApi @SystemApi
@@ -94,7 +96,7 @@ public interface VirtualSensorDirectChannelCallback {
* @param sensor The sensor, for which the channel was configured. * @param sensor The sensor, for which the channel was configured.
* @param rateLevel The rate level used to configure the direct sensor channel. * @param rateLevel The rate level used to configure the direct sensor channel.
* @param reportToken A positive sensor report token, used to differentiate between events from * @param reportToken A positive sensor report token, used to differentiate between events from
* different sensors within the same channel. * different sensors within the same channel.
* *
* @see VirtualSensorConfig.Builder#setHighestDirectReportRateLevel(int) * @see VirtualSensorConfig.Builder#setHighestDirectReportRateLevel(int)
* @see VirtualSensorConfig.Builder#setDirectChannelTypesSupported(int) * @see VirtualSensorConfig.Builder#setDirectChannelTypesSupported(int)

View File

@@ -41,6 +41,41 @@ import java.util.concurrent.atomic.AtomicLong;
* write the events from the relevant sensors directly to the shared memory regions of the * write the events from the relevant sensors directly to the shared memory regions of the
* corresponding {@link SensorDirectChannel} instances. * corresponding {@link SensorDirectChannel} instances.
* *
* <p>Example:
* <p>During sensor and virtual device creation:
* <pre>
* VirtualSensorDirectChannelWriter writer = new VirtualSensorDirectChannelWriter();
* VirtualSensorDirectChannelCallback callback = new VirtualSensorDirectChannelCallback() {
* @Override
* public void onDirectChannelCreated(int channelHandle, SharedMemory sharedMemory) {
* writer.addChannel(channelHandle, sharedMemory);
* }
* @Override
* public void onDirectChannelDestroyed(int channelHandle);
* writer.removeChannel(channelHandle);
* }
* @Override
* public void onDirectChannelConfigured(int channelHandle, VirtualSensor sensor, int rateLevel,
* int reportToken)
* if (!writer.configureChannel(channelHandle, sensor, rateLevel, reportToken)) {
* // handle error
* }
* }
* }
* </pre>
* <p>During the virtual device lifetime:
* <pre>
* VirtualSensor sensor = ...
* while (shouldInjectEvents(sensor)) {
* if (!writer.writeSensorEvent(sensor, event)) {
* // handle error
* }
* }
* writer.close();
* </pre>
* <p>Note that the virtual device owner should take the currently configured rate level into
* account when deciding whether and how often to inject events for a particular sensor.
*
* @see android.hardware.SensorDirectChannel#configure * @see android.hardware.SensorDirectChannel#configure
* @see VirtualSensorDirectChannelCallback * @see VirtualSensorDirectChannelCallback
* *

View File

@@ -121,7 +121,7 @@ public final class VirtualSensorEvent implements Parcelable {
* monotonically increasing using the same time base as * monotonically increasing using the same time base as
* {@link android.os.SystemClock#elapsedRealtimeNanos()}. * {@link android.os.SystemClock#elapsedRealtimeNanos()}.
* *
* If not explicitly set, the current timestamp is used for the sensor event. * <p>If not explicitly set, the current timestamp is used for the sensor event.
* *
* @see android.hardware.SensorEvent#timestamp * @see android.hardware.SensorEvent#timestamp
*/ */