Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e699cd90 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13551643 from f1d97412 to 25Q3-release

Change-Id: I930d8df5cb5188a0765fe7ae6ab14ff15bc46399
parents 209f4816 f1d97412
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -3658,6 +3658,13 @@ package android.companion.virtual.audio {
package android.companion.virtual.camera {
  @FlaggedApi("android.companion.virtualdevice.flags.virtual_camera_metadata") public final class CameraCharacteristicsBuilder {
    ctor public CameraCharacteristicsBuilder();
    ctor public CameraCharacteristicsBuilder(@NonNull android.hardware.camera2.CameraCharacteristics);
    method @NonNull public android.hardware.camera2.CameraCharacteristics build();
    method @NonNull public <T> android.companion.virtual.camera.CameraCharacteristicsBuilder set(@NonNull android.hardware.camera2.CameraCharacteristics.Key<T>, T);
  }
  public final class VirtualCamera implements java.io.Closeable {
    method public void close();
    method @NonNull public android.companion.virtual.camera.VirtualCameraConfig getConfig();
+10 −78
Original line number Diff line number Diff line
@@ -31,22 +31,14 @@ import android.companion.virtual.camera.VirtualCameraConfig;
import android.content.ComponentName;
import android.content.IntentFilter;
import android.graphics.Point;
import android.graphics.PointF;
import android.hardware.display.IVirtualDisplayCallback;
import android.hardware.display.VirtualDisplayConfig;
import android.hardware.input.IVirtualInputDevice;
import android.hardware.input.VirtualDpadConfig;
import android.hardware.input.VirtualKeyboardConfig;
import android.hardware.input.VirtualKeyEvent;
import android.hardware.input.VirtualMouseButtonEvent;
import android.hardware.input.VirtualMouseConfig;
import android.hardware.input.VirtualMouseRelativeEvent;
import android.hardware.input.VirtualMouseScrollEvent;
import android.hardware.input.VirtualRotaryEncoderConfig;
import android.hardware.input.VirtualRotaryEncoderScrollEvent;
import android.hardware.input.VirtualStylusButtonEvent;
import android.hardware.input.VirtualStylusConfig;
import android.hardware.input.VirtualStylusMotionEvent;
import android.hardware.input.VirtualTouchEvent;
import android.hardware.input.VirtualTouchscreenConfig;
import android.hardware.input.VirtualNavigationTouchpadConfig;
import android.os.ResultReceiver;
@@ -152,94 +144,40 @@ interface IVirtualDevice {
    /**
     * Creates a new dpad and registers it with the input framework with the given token.
     */
    void createVirtualDpad(in VirtualDpadConfig config, IBinder token);
    IVirtualInputDevice createVirtualDpad(in VirtualDpadConfig config, IBinder token);

    /**
     * Creates a new keyboard and registers it with the input framework with the given token.
     */
    void createVirtualKeyboard(in VirtualKeyboardConfig config, IBinder token);
    IVirtualInputDevice createVirtualKeyboard(in VirtualKeyboardConfig config, IBinder token);

    /**
     * Creates a new mouse and registers it with the input framework with the given token.
     */
    void createVirtualMouse(in VirtualMouseConfig config, IBinder token);
    IVirtualInputDevice createVirtualMouse(in VirtualMouseConfig config, IBinder token);

    /**
     * Creates a new touchscreen and registers it with the input framework with the given token.
     */
    void createVirtualTouchscreen(in VirtualTouchscreenConfig config, IBinder token);
    IVirtualInputDevice createVirtualTouchscreen(in VirtualTouchscreenConfig config, IBinder token);

    /**
     * Creates a new navigation touchpad and registers it with the input framework with the given
     * token.
     */
    void createVirtualNavigationTouchpad(in VirtualNavigationTouchpadConfig config, IBinder token);
    IVirtualInputDevice createVirtualNavigationTouchpad(in VirtualNavigationTouchpadConfig config,
            IBinder token);

    /**
     * Creates a new stylus and registers it with the input framework with the given token.
     */
    void createVirtualStylus(in VirtualStylusConfig config, IBinder token);
    IVirtualInputDevice createVirtualStylus(in VirtualStylusConfig config, IBinder token);

    /**
     * Creates a new rotary encoder and registers it with the input framework with the given token.
     */
    void createVirtualRotaryEncoder(in VirtualRotaryEncoderConfig config, IBinder token);

    /**
     * Removes the input device corresponding to the given token from the framework.
     */
    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);

    /**
     * Injects a key event to the virtual dpad corresponding to the given token.
     */
    boolean sendDpadKeyEvent(IBinder token, in VirtualKeyEvent event);

    /**
     * Injects a key event to the virtual keyboard corresponding to the given token.
     */
    boolean sendKeyEvent(IBinder token, in VirtualKeyEvent event);

    /**
     * Injects a button event to the virtual mouse corresponding to the given token.
     */
    boolean sendButtonEvent(IBinder token, in VirtualMouseButtonEvent event);

    /**
     * Injects a relative event to the virtual mouse corresponding to the given token.
     */
    boolean sendRelativeEvent(IBinder token, in VirtualMouseRelativeEvent event);

    /**
     * Injects a scroll event to the virtual mouse corresponding to the given token.
     */
    boolean sendScrollEvent(IBinder token, in VirtualMouseScrollEvent event);

    /**
    * Injects a touch event to the virtual touch input device corresponding to the given token.
    */
    boolean sendTouchEvent(IBinder token, in VirtualTouchEvent event);

    /**
     * Injects a motion event from the virtual stylus input device corresponding to the given token.
     */
    boolean sendStylusMotionEvent(IBinder token, in VirtualStylusMotionEvent event);

    /**
     * Injects a button event from the virtual stylus input device corresponding to the given token.
     */
    boolean sendStylusButtonEvent(IBinder token, in VirtualStylusButtonEvent event);

    /**
     * Injects a scroll event from the virtual rotary encoder corresponding to the given token.
     */
    boolean sendRotaryEncoderScrollEvent(IBinder token, in VirtualRotaryEncoderScrollEvent event);
    IVirtualInputDevice createVirtualRotaryEncoder(in VirtualRotaryEncoderConfig config,
            IBinder token);

    /**
     * Returns all virtual sensors created for this device.
@@ -262,12 +200,6 @@ interface IVirtualDevice {
    void launchPendingIntent(int displayId, in PendingIntent pendingIntent,
            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);

    /** Sets whether to show or hide the cursor while this virtual device is active. */
    void setShowPointerIcon(boolean showPointerIcon);

+16 −14
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.hardware.display.DisplayManagerGlobal;
import android.hardware.display.IVirtualDisplayCallback;
import android.hardware.display.VirtualDisplay;
import android.hardware.display.VirtualDisplayConfig;
import android.hardware.input.IVirtualInputDevice;
import android.hardware.input.VirtualDpad;
import android.hardware.input.VirtualDpadConfig;
import android.hardware.input.VirtualKeyboard;
@@ -400,8 +401,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualDpad:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualDpad(config, token);
            return new VirtualDpad(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualDpad(config, token);
            return new VirtualDpad(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -412,8 +413,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualKeyboard:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualKeyboard(config, token);
            return new VirtualKeyboard(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualKeyboard(config, token);
            return new VirtualKeyboard(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -424,8 +425,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualMouse:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualMouse(config, token);
            return new VirtualMouse(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualMouse(config, token);
            return new VirtualMouse(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -437,8 +438,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualTouchscreen:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualTouchscreen(config, token);
            return new VirtualTouchscreen(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualTouchscreen(config, token);
            return new VirtualTouchscreen(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -449,8 +450,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualStylus:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualStylus(config, token);
            return new VirtualStylus(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualStylus(config, token);
            return new VirtualStylus(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -461,8 +462,8 @@ public class VirtualDeviceInternal {
        try {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualRotaryEncoder:" + config.getInputDeviceName());
            mVirtualDevice.createVirtualRotaryEncoder(config, token);
            return new VirtualRotaryEncoder(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualRotaryEncoder(config, token);
            return new VirtualRotaryEncoder(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -475,8 +476,9 @@ public class VirtualDeviceInternal {
            final IBinder token = new Binder(
                    "android.hardware.input.VirtualNavigationTouchpad:"
                            + config.getInputDeviceName());
            mVirtualDevice.createVirtualNavigationTouchpad(config, token);
            return new VirtualNavigationTouchpad(config, mVirtualDevice, token);
            IVirtualInputDevice device = mVirtualDevice.createVirtualNavigationTouchpad(config,
                    token);
            return new VirtualNavigationTouchpad(config, device);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+84 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.companion.virtual.camera;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.impl.CameraMetadataNative;

/**
 * Builder class for creating {@link CameraCharacteristics} instances to be used in a
 * {@link VirtualCameraConfig}.
 * @hide
 */
// There is no CameraCharacteristics.Builder for now, so this helps VDM clients to build
// CameraCharacteristics instances for their VirtualCameraConfig.
@SuppressLint("TopLevelBuilder")
@SystemApi
@FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIRTUAL_CAMERA_METADATA)
public final class CameraCharacteristicsBuilder {
    private final CameraMetadataNative mNativeMetadata;

    /**
     * Builder for creating {@link CameraCharacteristics} starting from an empty list of keys.
     */
    public CameraCharacteristicsBuilder() {
        mNativeMetadata = new CameraMetadataNative();
    }

    /**
     * Builder for creating {@link CameraCharacteristics} starting from a copy of
     * the passed characteristics.
     */
    public CameraCharacteristicsBuilder(@NonNull CameraCharacteristics characteristics) {
        mNativeMetadata = new CameraMetadataNative(characteristics.getNativeMetadata());
    }

    /**
     * Set a camera characteristics field to a value. The field definitions can be found in
     * {@link CameraCharacteristics}.
     *
     * <p>Setting a field to {@code null} will remove that field from the camera
     * characteristics.
     * Unless the field is optional, removing it will likely produce an error from the camera
     * device when the camera characteristics are set.</p>
     *
     * @param key   The metadata field to write.
     * @param value The value to set the field to, which must be of a matching type to the key.
     */
    @SuppressLint("KotlinOperator")
    @NonNull
    public <T> CameraCharacteristicsBuilder set(@NonNull CameraCharacteristics.Key<T> key,
            T value) {
        mNativeMetadata.set(key, value);
        return this;
    }

    /**
     * Builds the {@link CameraCharacteristics} object with the set
     * {@link CameraCharacteristics.Key}s.
     *
     * @return A new {@link CameraCharacteristics} instance to be set in the
     * {@link VirtualCameraConfig} of a Virtual Camera.
     */
    public @NonNull CameraCharacteristics build() {
        return new CameraCharacteristics(mNativeMetadata);
    }
}
+20 −1
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ public final class VirtualCameraConfig implements Parcelable {
                throw new IllegalArgumentException("Different values are set for "
                        + "lensFacing and CameraCharacteristics.LENS_FACING");
            }
        } else {
            if (lensFacing == LENS_FACING_UNKNOWN) {
                throw new IllegalArgumentException("Lens facing must be set");
            }
        }
        mLensFacing = lensFacing;
        mStreamConfigurations =
@@ -226,6 +230,9 @@ public final class VirtualCameraConfig implements Parcelable {
     */
    @FlaggedApi(Flags.FLAG_VIRTUAL_CAMERA_METADATA)
    public boolean isPerFrameCameraMetadataEnabled() {
        if (!Flags.virtualCameraMetadata()) {
            throw new UnsupportedOperationException("virtual_camera_metadata not enabled!");
        }
        return mPerFrameCameraMetadataEnabled;
    }

@@ -237,6 +244,9 @@ public final class VirtualCameraConfig implements Parcelable {
    @FlaggedApi(Flags.FLAG_VIRTUAL_CAMERA_METADATA)
    @Nullable
    public CameraCharacteristics getCameraCharacteristics() {
        if (!Flags.virtualCameraMetadata()) {
            throw new UnsupportedOperationException("virtual_camera_metadata not enabled!");
        }
        return mCameraCharacteristics;
    }

@@ -247,7 +257,8 @@ public final class VirtualCameraConfig implements Parcelable {
     * <li>At least one stream must be added with {@link #addStreamConfig(int, int, int, int)}.
     * <li>A callback must be set with {@link #setVirtualCameraCallback(Executor,
     *     VirtualCameraCallback)}
     * <li>A lens facing must be set with {@link #setLensFacing(int)}
     * <li>A lens facing must be set with {@link #setLensFacing(int)} or
     * {@link CameraCharacteristics} with {@link #setCameraCharacteristics(CameraCharacteristics)}
     */
    public static final class Builder {

@@ -317,6 +328,7 @@ public final class VirtualCameraConfig implements Parcelable {
        /**
         * Sets the sensor orientation of the virtual camera. This field is optional and can be
         * omitted (defaults to {@link #SENSOR_ORIENTATION_0}).
         * <p>Only used if camera characteristics are not set.
         *
         * @param sensorOrientation The sensor orientation of the camera, which represents the
         *                          clockwise angle (in degrees) through which the output image
@@ -338,6 +350,7 @@ public final class VirtualCameraConfig implements Parcelable {

        /**
         * Sets the lens facing direction of the virtual camera.
         * <p>Only used if camera characteristics are not set.
         *
         * <p>A {@link VirtualDevice} can have at most one {@link VirtualCamera} with
         * {@link CameraMetadata#LENS_FACING_FRONT} and at most one {@link VirtualCamera} with
@@ -384,6 +397,9 @@ public final class VirtualCameraConfig implements Parcelable {
        @FlaggedApi(Flags.FLAG_VIRTUAL_CAMERA_METADATA)
        @NonNull
        public Builder setPerFrameCameraMetadataEnabled(boolean perFrameCameraMetadataEnabled) {
            if (!Flags.virtualCameraMetadata()) {
                throw new UnsupportedOperationException("virtual_camera_metadata not enabled!");
            }
            mPerFrameCameraMetadataEnabled = perFrameCameraMetadataEnabled;
            return this;
        }
@@ -404,6 +420,9 @@ public final class VirtualCameraConfig implements Parcelable {
        @NonNull
        public Builder setCameraCharacteristics(
                @Nullable CameraCharacteristics cameraCharacteristics) {
            if (!Flags.virtualCameraMetadata()) {
                throw new UnsupportedOperationException("virtual_camera_metadata not enabled!");
            }
            mCameraCharacteristics = cameraCharacteristics;
            return this;
        }
Loading