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

Commit 16b4552e authored by Gil Dekel's avatar Gil Dekel Committed by Android (Google) Code Review
Browse files

Merge "DM: Add EDID info and builder to DeviceProductInfo" into main

parents 3d145a6e cbd9df3e
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -21077,18 +21077,44 @@ package android.hardware.display {
    ctor public DeviceProductInfo(@Nullable String, @NonNull String, @NonNull String, @IntRange(from=1990) int, int);
    method public int describeContents();
    method public int getConnectionToSinkType();
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @Nullable public android.hardware.display.DeviceProductInfo.EdidStructureMetadata getEdidStructureMetadata();
    method @IntRange(from=0xffffffff, to=53) public int getManufactureWeek();
    method @IntRange(from=0xffffffff) public int getManufactureYear();
    method @NonNull public String getManufacturerPnpId();
    method @IntRange(from=0xffffffff) public int getModelYear();
    method @Nullable public String getName();
    method @NonNull public String getProductId();
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public int getVideoInputType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final int CONNECTION_TO_SINK_BUILT_IN = 1; // 0x1
    field public static final int CONNECTION_TO_SINK_DIRECT = 2; // 0x2
    field public static final int CONNECTION_TO_SINK_TRANSITIVE = 3; // 0x3
    field public static final int CONNECTION_TO_SINK_UNKNOWN = 0; // 0x0
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.display.DeviceProductInfo> CREATOR;
    field @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final int VIDEO_INPUT_TYPE_ANALOG = 0; // 0x0
    field @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final int VIDEO_INPUT_TYPE_DIGITAL = 1; // 0x1
    field @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final int VIDEO_INPUT_TYPE_UNKNOWN = -1; // 0xffffffff
  }
  @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final class DeviceProductInfo.Builder {
    ctor @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public DeviceProductInfo.Builder(@NonNull String, @NonNull String);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo build();
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setConnectionToSinkType(int);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setEdidStructureMetadata(@IntRange(from=0) int, @IntRange(from=0) int);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setManufactureDate(@IntRange(from=0xffffffff, to=53) int, @IntRange(from=0xffffffff) int);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setManufacturerPnpId(@NonNull String);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setModelYear(@IntRange(from=0xffffffff) int);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setName(@Nullable String);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setProductId(@NonNull String);
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @NonNull public android.hardware.display.DeviceProductInfo.Builder setVideoInputType(int);
  }
  @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final class DeviceProductInfo.EdidStructureMetadata implements android.os.Parcelable {
    method public int describeContents();
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @IntRange(from=0) public int getRevision();
    method @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") @IntRange(from=0) public int getVersion();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.display.DeviceProductInfo.EdidStructureMetadata> CREATOR;
  }
  public final class DisplayManager {
+4 −0
Original line number Diff line number Diff line
@@ -1803,6 +1803,10 @@ package android.hardware.display {
    method @RequiresPermission(android.Manifest.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS) public boolean isSaturationActivated();
  }

  @FlaggedApi("com.android.graphics.surfaceflinger.flags.parse_edid_version_and_input_type") public static final class DeviceProductInfo.EdidStructureMetadata implements android.os.Parcelable {
    ctor public DeviceProductInfo.EdidStructureMetadata(@IntRange(from=0) int, @IntRange(from=0) int);
  }

  public final class DisplayManager {
    method public boolean areUserDisabledHdrTypesAllowed();
    method @RequiresPermission(android.Manifest.permission.MODIFY_USER_PREFERRED_DISPLAY_MODE) public void clearGlobalUserPreferredDisplayMode();
+349 −27
Original line number Diff line number Diff line
@@ -16,10 +16,15 @@

package android.hardware.display;

import static com.android.graphics.surfaceflinger.flags.Flags.FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;

@@ -43,6 +48,24 @@ public final class DeviceProductInfo implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    public @interface ConnectionToSinkType { }

    /** @hide */
    @IntDef(prefix = {"VIDEO_INPUT_TYPE_"},
            value = {VIDEO_INPUT_TYPE_UNKNOWN, VIDEO_INPUT_TYPE_ANALOG, VIDEO_INPUT_TYPE_DIGITAL})
    @Retention(RetentionPolicy.SOURCE)
    public @interface VideoInputType {}

    /** The device input type is unknown. */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    public static final int VIDEO_INPUT_TYPE_UNKNOWN = -1;

    /** The device has an analog input. */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    public static final int VIDEO_INPUT_TYPE_ANALOG = 0;

    /** The device has a digital input. */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    public static final int VIDEO_INPUT_TYPE_DIGITAL = 1;

    /** The device connection to the display sink is unknown. */
    public static final int CONNECTION_TO_SINK_UNKNOWN =
            IDeviceProductInfoConstants.CONNECTION_TO_SINK_UNKNOWN;
@@ -65,28 +88,41 @@ public final class DeviceProductInfo implements Parcelable {
    private final Integer mModelYear;
    private final ManufactureDate mManufactureDate;
    private final @ConnectionToSinkType int mConnectionToSinkType;
    private final EdidStructureMetadata mEdidStructureMetadata;
    private final @VideoInputType int mVideoInputType;

    /** @hide */
    public DeviceProductInfo(
            String name,
            String manufacturerPnpId,
            String productId,
            Integer modelYear,
            ManufactureDate manufactureDate,
            int connectionToSinkType) {
    public DeviceProductInfo(String name, String manufacturerPnpId, String productId,
            Integer modelYear, ManufactureDate manufactureDate, int connectionToSinkType,
            EdidStructureMetadata edidStructureMetadata, @VideoInputType int videoInputType) {
        mName = name;
        mManufacturerPnpId = manufacturerPnpId;
        mProductId = productId;
        mModelYear = modelYear;
        mManufactureDate = manufactureDate;
        mConnectionToSinkType = connectionToSinkType;
        mEdidStructureMetadata = edidStructureMetadata;
        mVideoInputType = videoInputType;
    }

    public DeviceProductInfo(
            @Nullable String name,
            @NonNull String manufacturerPnpId,
            @NonNull String productId,
            @IntRange(from = 1990) int modelYear,
    private DeviceProductInfo(@Nullable String name, @NonNull String manufacturerPnpId,
            @NonNull String productId, @IntRange(from = 1990) int modelYear,
            @Nullable ManufactureDate manufactureDate,
            @ConnectionToSinkType int connectionToSinkType,
            @Nullable EdidStructureMetadata edidStructureMetadata,
            @VideoInputType int videoInputType) {
        mName = name;
        mManufacturerPnpId = Objects.requireNonNull(manufacturerPnpId);
        mProductId = Objects.requireNonNull(productId);
        mModelYear = modelYear;
        mManufactureDate = manufactureDate;
        mConnectionToSinkType = connectionToSinkType;
        mEdidStructureMetadata = edidStructureMetadata;
        mVideoInputType = videoInputType;
    }

    public DeviceProductInfo(@Nullable String name, @NonNull String manufacturerPnpId,
            @NonNull String productId, @IntRange(from = 1990) int modelYear,
            @ConnectionToSinkType int connectionToSinkType) {
        mName = name;
        mManufacturerPnpId = Objects.requireNonNull(manufacturerPnpId);
@@ -94,6 +130,8 @@ public final class DeviceProductInfo implements Parcelable {
        mModelYear = modelYear;
        mManufactureDate = null;
        mConnectionToSinkType = connectionToSinkType;
        mEdidStructureMetadata = null;
        mVideoInputType = VIDEO_INPUT_TYPE_UNKNOWN;
    }

    private DeviceProductInfo(Parcel in) {
@@ -103,6 +141,190 @@ public final class DeviceProductInfo implements Parcelable {
        mModelYear = (Integer) in.readValue(null);
        mManufactureDate = (ManufactureDate) in.readValue(null);
        mConnectionToSinkType = in.readInt();
        mEdidStructureMetadata = in.readTypedObject(EdidStructureMetadata.CREATOR);
        mVideoInputType = in.readInt();
    }

    /**
     * Builder for {@link DeviceProductInfo}.
     */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    public static final class Builder {
        private String mName;
        private String mManufacturerPnpId;
        private String mProductId;
        private int mModelYear = -1;
        private ManufactureDate mManufactureDate = new ManufactureDate(-1, -1);
        private @ConnectionToSinkType int mConnectionToSinkType = CONNECTION_TO_SINK_UNKNOWN;
        private EdidStructureMetadata mEdidStructureMetadata = null;
        private @VideoInputType int mVideoInputType = VIDEO_INPUT_TYPE_UNKNOWN;

        /**
         * Creates a new Builder.
         *
         * @param manufacturerPnpId The Manufacturer Plug and Play ID.
         * @param productId The product ID.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        public Builder(@NonNull String manufacturerPnpId, @NonNull String productId) {
            mManufacturerPnpId = Objects.requireNonNull(manufacturerPnpId);
            mProductId = Objects.requireNonNull(productId);
        }

        /**
         * Sets the display name.
         *
         * @param name The display name.
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setName(@Nullable String name) {
            mName = name;
            return this;
        }

        /**
         * Sets the Manufacturer Plug and Play ID.
         *
         * @param manufacturerPnpId The Manufacturer Plug and Play ID.
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setManufacturerPnpId(@NonNull String manufacturerPnpId) {
            mManufacturerPnpId = Objects.requireNonNull(manufacturerPnpId);
            return this;
        }

        /**
         * Sets the product ID.
         *
         * @param productId The product ID.
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setProductId(@NonNull String productId) {
            mProductId = Objects.requireNonNull(productId);
            return this;
        }

        /**
         * Sets the model year of the device.
         *
         * @param modelYear The model year, must be >= 1990, or -1 if not available.
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setModelYear(@IntRange(from = -1) int modelYear) {
            if (modelYear != -1 && modelYear < 1990) {
                throw new IllegalArgumentException(
                        "modelYear must be >= 1990, or -1 if not available.");
            }
            mModelYear = modelYear;
            return this;
        }

        /**
         * Sets the manufacturing week and year of the device.
         *
         * @param manufactureWeek Week of manufacturing, must be >= 1 and <=53, or -1 if not
         *         available.
         * @param manufactureYear Year of manufacturing, must be >= 1990, or -1 if not available.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        // Getters are already public and are split to getManufactureWeek and getManufactureYear
        @SuppressLint("MissingGetterMatchingBuilder")
        @NonNull
        public Builder setManufactureDate(@IntRange(from = -1, to = 53) int manufactureWeek,
                @IntRange(from = -1) int manufactureYear) {
            if (manufactureWeek < -1 || manufactureWeek > 53) {
                throw new IllegalArgumentException(
                        "manufactureWeek must be >= 1 and <= 53, or -1 if missing");
            }
            if (manufactureWeek == 0) {
                throw new IllegalArgumentException("manufactureWeek cannot be 0.");
            }
            if (manufactureYear != -1 && manufactureYear < 1990) {
                throw new IllegalArgumentException(
                        "manufactureYear must be >= 1990, or -1 if not available.");
            }

            mManufactureDate = new ManufactureDate(manufactureWeek, manufactureYear);
            return this;
        }

        /**
         * Sets how the current device is connected to the display sink.
         *
         * @param connectionToSinkType The connection type.
         * @see #CONNECTION_TO_SINK_UNKNOWN
         * @see #CONNECTION_TO_SINK_BUILT_IN
         * @see #CONNECTION_TO_SINK_DIRECT
         * @see #CONNECTION_TO_SINK_TRANSITIVE
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setConnectionToSinkType(@ConnectionToSinkType int connectionToSinkType) {
            mConnectionToSinkType = connectionToSinkType;
            return this;
        }

        /**
         * Sets the EDID structure metadata. If left unset, {@link EdidStructureMetadata} will be
         * null.
         *
         * @param edidStructureVersion The EDID version, must be >= 0.
         * @param edidStructureRevision The EDID revision, must be >= 0.
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setEdidStructureMetadata(@IntRange(from = 0) int edidStructureVersion,
                @IntRange(from = 0) int edidStructureRevision) {
            if (edidStructureVersion < 0) {
                throw new IllegalArgumentException("edidStructureVersion must be >= 0");
            }
            if (edidStructureRevision < 0) {
                throw new IllegalArgumentException("edidStructureRevision must be >= 0");
            }

            mEdidStructureMetadata =
                    new EdidStructureMetadata(edidStructureVersion, edidStructureRevision);
            return this;
        }

        /**
         * Sets the video input type of the device.
         *
         * @param videoInputType The video input type.
         * @see #VIDEO_INPUT_TYPE_UNKNOWN
         * @see #VIDEO_INPUT_TYPE_ANALOG
         * @see #VIDEO_INPUT_TYPE_DIGITAL
         * @return This builder.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public Builder setVideoInputType(@VideoInputType int videoInputType) {
            mVideoInputType = videoInputType;
            return this;
        }

        /**
         * Builds a new {@link DeviceProductInfo} instance.
         *
         * @return A new {@link DeviceProductInfo}.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @NonNull
        public DeviceProductInfo build() {
            return new DeviceProductInfo(mName, mManufacturerPnpId, mProductId, mModelYear,
                    mManufactureDate, mConnectionToSinkType, mEdidStructureMetadata,
                    mVideoInputType);
        }
    }

    /**
@@ -184,22 +406,35 @@ public final class DeviceProductInfo implements Parcelable {
        return mConnectionToSinkType;
    }

    /**
     * @return An {@link EdidStructureMetadata} containing the EDID major version and minor
     * revision (e.g., version 1, revision 4 for EDID 1.4), or null if unavailable.
     */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    @Nullable
    public EdidStructureMetadata getEdidStructureMetadata() {
        return mEdidStructureMetadata;
    }

    /**
     * @return The video input type of the device.
     * @see #VIDEO_INPUT_TYPE_UNKNOWN
     * @see #VIDEO_INPUT_TYPE_ANALOG
     * @see #VIDEO_INPUT_TYPE_DIGITAL
     */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    @VideoInputType
    public int getVideoInputType() {
        return mVideoInputType;
    }

    @Override
    public String toString() {
        return "DeviceProductInfo{"
                + "name="
                + mName
                + ", manufacturerPnpId="
                + mManufacturerPnpId
                + ", productId="
                + mProductId
                + ", modelYear="
                + mModelYear
                + ", manufactureDate="
                + mManufactureDate
                + ", connectionToSinkType="
                + mConnectionToSinkType
                + '}';
                + "name=" + mName + ", manufacturerPnpId=" + mManufacturerPnpId + ", productId="
                + mProductId + ", modelYear=" + mModelYear + ", manufactureDate=" + mManufactureDate
                + ", connectionToSinkType=" + mConnectionToSinkType + ", edidStructureMetadata="
                + mEdidStructureMetadata + ", videoInputType=" + mVideoInputType + '}';
    }

    @Override
@@ -212,13 +447,15 @@ public final class DeviceProductInfo implements Parcelable {
                && Objects.equals(mProductId, that.mProductId)
                && Objects.equals(mModelYear, that.mModelYear)
                && Objects.equals(mManufactureDate, that.mManufactureDate)
                && mConnectionToSinkType == that.mConnectionToSinkType;
                && mConnectionToSinkType == that.mConnectionToSinkType
                && Objects.equals(mEdidStructureMetadata, that.mEdidStructureMetadata)
                && mVideoInputType == that.mVideoInputType;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mName, mManufacturerPnpId, mProductId, mModelYear, mManufactureDate,
                mConnectionToSinkType);
                mConnectionToSinkType, mEdidStructureMetadata, mVideoInputType);
    }

    @NonNull public static final Creator<DeviceProductInfo> CREATOR =
@@ -247,6 +484,8 @@ public final class DeviceProductInfo implements Parcelable {
        dest.writeValue(mModelYear);
        dest.writeValue(mManufactureDate);
        dest.writeInt(mConnectionToSinkType);
        dest.writeTypedObject(mEdidStructureMetadata, flags);
        dest.writeInt(mVideoInputType);
    }

    /**
@@ -318,4 +557,87 @@ public final class DeviceProductInfo implements Parcelable {
            return Objects.hash(mWeek, mYear);
        }
    }

    /**
     * Encapsulates the EDID version, parsed from bytes 18 (version) and 19 (revision).
     */
    @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
    public static final class EdidStructureMetadata implements Parcelable {
        private final int mVersion;
        private final int mRevision;

        /** @hide */
        @TestApi
        public EdidStructureMetadata(
                @IntRange(from = 0) int version, @IntRange(from = 0) int revision) {
            mVersion = version;
            mRevision = revision;
        }

        private EdidStructureMetadata(Parcel in) {
            mVersion = in.readInt();
            mRevision = in.readInt();
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeInt(mVersion);
            dest.writeInt(mRevision);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @NonNull
        public static final Creator<EdidStructureMetadata> CREATOR =
                new Creator<EdidStructureMetadata>() {
                    @Override
                    public EdidStructureMetadata createFromParcel(Parcel in) {
                        return new EdidStructureMetadata(in);
                    }

                    @Override
                    public EdidStructureMetadata[] newArray(int size) {
                        return new EdidStructureMetadata[size];
                    }
                };

        /**
         * @return The EDID version. For example, if the EDID version is 1.4, this will return 1.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @IntRange(from = 0)
        public int getVersion() {
            return mVersion;
        }

        /**
         * @return The EDID revision. For example, if the EDID version is 1.4, this will return 4.
         */
        @FlaggedApi(FLAG_PARSE_EDID_VERSION_AND_INPUT_TYPE)
        @IntRange(from = 0)
        public int getRevision() {
            return mRevision;
        }

        @Override
        public String toString() {
            return "EdidStructureMetadata{version=" + mVersion + ", revision=" + mRevision + '}';
        }

        @Override
        public boolean equals(@Nullable Object o) {
            if (this == o) return true;
            if (!(o instanceof EdidStructureMetadata)) return false;
            EdidStructureMetadata metadata = (EdidStructureMetadata) o;
            return mVersion == metadata.mVersion && mRevision == metadata.mRevision;
        }

        @Override
        public int hashCode() {
            return Objects.hash(mVersion, mRevision);
        }
    }
}
+23 −3

File changed.

Preview size limit exceeded, changes collapsed.