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

Commit 59f9d24c authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge "Public API for getting a persistent VD ID."

parents 008b0587 ae903e05
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9609,6 +9609,7 @@ package android.companion.virtual {
    method public int describeContents();
    method public int getDeviceId();
    method @Nullable public String getName();
    method @Nullable public String getPersistentDeviceId();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.companion.virtual.VirtualDevice> CREATOR;
  }
+1 −0
Original line number Diff line number Diff line
@@ -3200,6 +3200,7 @@ package android.companion.virtual {
    method @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualTouchscreen createVirtualTouchscreen(@NonNull android.hardware.input.VirtualTouchscreenConfig);
    method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public android.hardware.input.VirtualTouchscreen createVirtualTouchscreen(@NonNull android.hardware.display.VirtualDisplay, @NonNull String, int, int);
    method public int getDeviceId();
    method @Nullable public String getPersistentDeviceId();
    method @NonNull public java.util.List<android.companion.virtual.sensor.VirtualSensor> getVirtualSensorList();
    method public void launchPendingIntent(int, @NonNull android.app.PendingIntent, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.IntConsumer);
    method @RequiresPermission(android.Manifest.permission.CREATE_VIRTUAL_DEVICE) public void registerIntentInterceptor(@NonNull android.content.IntentFilter, @NonNull java.util.concurrent.Executor, @NonNull android.companion.virtual.VirtualDeviceManager.IntentInterceptorCallback);
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ interface IVirtualDevice {
     */
    int getDeviceId();

    /**
     * Returns the persistent ID of this virtual device.
     */
    String getPersistentDeviceId();

    /**
     * Closes the virtual device and frees all associated resources.
     */
+34 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.Objects;
public final class VirtualDevice implements Parcelable {

    private final int mId;
    private final @Nullable String mPersistentId;
    private final @Nullable String mName;

    /**
@@ -43,27 +44,54 @@ public final class VirtualDevice implements Parcelable {
     *
     * @hide
     */
    public VirtualDevice(int id, @Nullable String name) {
    public VirtualDevice(int id, @Nullable String persistentId, @Nullable String name) {
        if (id <= Context.DEVICE_ID_DEFAULT) {
            throw new IllegalArgumentException("VirtualDevice ID mist be greater than "
            throw new IllegalArgumentException("VirtualDevice ID must be greater than "
                    + Context.DEVICE_ID_DEFAULT);
        }
        mId = id;
        mPersistentId = persistentId;
        mName = name;
    }

    private VirtualDevice(@NonNull Parcel parcel) {
        mId = parcel.readInt();
        mPersistentId = parcel.readString8();
        mName = parcel.readString8();
    }

    /**
     * Returns the unique ID of the virtual device.
     *
     * <p>This identifier corresponds to {@link Context#getDeviceId()} and can be used to access
     * device-specific system capabilities.
     *
     * <p class="note">This identifier is ephemeral and should not be used for persisting any data
     * per device.
     *
     * @see Context#createDeviceContext
     * @see #getPersistentDeviceId
     */
    public int getDeviceId() {
        return mId;
    }

    /**
     * Returns the persistent identifier of this virtual device, if any.
     *
     * <p> If there is no stable identifier for this virtual device, then this returns {@code null}.

     * <p>This identifier may correspond to a physical device. In that case it remains valid for as
     * long as that physical device is associated with the host device and may be used to persist
     * data per device.
     *
     * <p class="note">This identifier may not be unique across virtual devices, in case there are
     * more than one virtual devices corresponding to the same physical device.
     */
    public @Nullable String getPersistentDeviceId() {
        return mPersistentId;
    }

    /**
     * Returns the name of the virtual device (optionally) provided during its creation.
     *
@@ -81,6 +109,7 @@ public final class VirtualDevice implements Parcelable {
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mId);
        dest.writeString8(mPersistentId);
        dest.writeString8(mName);
    }

@@ -94,12 +123,13 @@ public final class VirtualDevice implements Parcelable {
        }
        VirtualDevice that = (VirtualDevice) o;
        return mId == that.mId
                && Objects.equals(mPersistentId, that.mPersistentId)
                && Objects.equals(mName, that.mName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mId, mName);
        return Objects.hash(mId, mPersistentId, mName);
    }

    @Override
@@ -107,6 +137,7 @@ public final class VirtualDevice implements Parcelable {
    public String toString() {
        return "VirtualDevice("
                + " mId=" + mId
                + " mPersistentId=" + mPersistentId
                + " mName=" + mName
                + ")";
    }
+8 −0
Original line number Diff line number Diff line
@@ -160,6 +160,14 @@ public class VirtualDeviceInternal {
        }
    }

    @Nullable String getPersistentDeviceId() {
        try {
            return mVirtualDevice.getPersistentDeviceId();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @NonNull Context createContext() {
        try {
            return mContext.createDeviceContext(mVirtualDevice.getDeviceId());
Loading