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

Commit eae13185 authored by Nathalie Le Clair's avatar Nathalie Le Clair
Browse files

Replace public constructors by builders

Following the Android API Council code style guidelines for builders.

One constructor hasn´t been released yet, so it can be removed entirely
instead of deprecated.

Test: atest com.android.server.hdmi
Bug: 265117347
Change-Id: I285638d94f4ac6661665b9952ad52606adb5d64f
parent e67df620
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -4573,8 +4573,7 @@ package android.hardware.hdmi {
  }
  public final class HdmiPortInfo implements android.os.Parcelable {
    ctor public HdmiPortInfo(int, int, int, boolean, boolean, boolean);
    ctor public HdmiPortInfo(int, int, int, boolean, boolean, boolean, boolean);
    ctor @Deprecated public HdmiPortInfo(int, int, int, boolean, boolean, boolean);
    method public int describeContents();
    method public int getAddress();
    method public int getId();
@@ -4589,6 +4588,15 @@ package android.hardware.hdmi {
    field public static final int PORT_OUTPUT = 1; // 0x1
  }
  public static final class HdmiPortInfo.Builder {
    ctor public HdmiPortInfo.Builder(int, int, int);
    method @NonNull public android.hardware.hdmi.HdmiPortInfo build();
    method @NonNull public android.hardware.hdmi.HdmiPortInfo.Builder setArcSupported(boolean);
    method @NonNull public android.hardware.hdmi.HdmiPortInfo.Builder setCecSupported(boolean);
    method @NonNull public android.hardware.hdmi.HdmiPortInfo.Builder setEarcSupported(boolean);
    method @NonNull public android.hardware.hdmi.HdmiPortInfo.Builder setMhlSupported(boolean);
  }
  public abstract class HdmiRecordListener {
    ctor public HdmiRecordListener();
    method public void onClearTimerRecordingResult(int, int);
+143 −34
Original line number Diff line number Diff line
@@ -15,14 +15,20 @@
 */
package android.hardware.hdmi;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.IntRange;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A class to encapsulate HDMI port information. Contains the capability of the ports such as
 * Encapsulates HDMI port information. Contains the capability of the ports such as
 * HDMI-CEC, MHL, ARC(Audio Return Channel), eARC and physical address assigned to each port.
 *
 * @hide
@@ -35,6 +41,18 @@ public final class HdmiPortInfo implements Parcelable {
    /** HDMI port type: Output */
    public static final int PORT_OUTPUT = 1;

    /**
     * @hide
     *
     * @see HdmiPortInfo#getType()
     */
    @IntDef(prefix = { "PORT_" }, value = {
            PORT_INPUT,
            PORT_OUTPUT
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PortType {}

    private final int mId;
    private final int mType;
    private final int mAddress;
@@ -46,43 +64,48 @@ public final class HdmiPortInfo implements Parcelable {
    /**
     * Constructor.
     *
     * @param id identifier assigned to each port. 1 for HDMI port 1
     * @param id identifier assigned to each port. 1 for HDMI OUT port 1
     * @param type HDMI port input/output type
     * @param address physical address of the port
     * @param cec {@code true} if HDMI-CEC is supported on the port
     * @param mhl {@code true} if MHL is supported on the port
     * @param arc {@code true} if audio return channel is supported on the port
     */
    public HdmiPortInfo(int id, int type, int address, boolean cec, boolean mhl, boolean arc) {
        this(id, type, address, cec, mhl, arc, false);
    }

    /**
     * Constructor.
     *
     * @param id identifier assigned to each port. 1 for HDMI port 1
     * @param type HDMI port input/output type
     * @param address physical address of the port
     * @param cec {@code true} if HDMI-CEC is supported on the port
     * @param mhl {@code true} if MHL is supported on the port
     * @param arc {@code true} if audio return channel is supported on the port
     * @param earc {@code true} if eARC is supported on the port
     * @deprecated use {@link Builder()} instead
     */
    public HdmiPortInfo(int id, int type, int address,
            boolean cec, boolean mhl, boolean arc, boolean earc) {
    @Deprecated
    public HdmiPortInfo(int id, @PortType int type,
            @IntRange(from = 0) int address, boolean cec, boolean mhl, boolean arc) {
        mId = id;
        mType = type;
        mAddress = address;
        mCecSupported = cec;
        mArcSupported = arc;
        mEarcSupported = earc;
        mEarcSupported = false;
        mMhlSupported = mhl;
    }

    /**
     * Returns the port id.
     * Converts an instance to a builder
     *
     * @return port id
     * @hide
     */
    public Builder toBuilder() {
        return new Builder(this);
    }

    private HdmiPortInfo(Builder builder) {
        this.mId = builder.mId;
        this.mType = builder.mType;
        this.mAddress = builder.mAddress;
        this.mCecSupported = builder.mCecSupported;
        this.mArcSupported = builder.mArcSupported;
        this.mEarcSupported = builder.mEarcSupported;
        this.mMhlSupported = builder.mMhlSupported;
    }

    /**
     * Returns the port id.
     */
    public int getId() {
        return mId;
@@ -90,26 +113,22 @@ public final class HdmiPortInfo implements Parcelable {

    /**
     * Returns the port type.
     *
     * @return port type
     */
    @PortType
    public int getType() {
        return mType;
    }

    /**
     * Returns the port address.
     *
     * @return port address
     */
    @IntRange(from = 0)
    public int getAddress() {
        return mAddress;
    }

    /**
     * Returns {@code true} if the port supports HDMI-CEC signaling.
     *
     * @return {@code true} if the port supports HDMI-CEC signaling.
     */
    public boolean isCecSupported() {
        return mCecSupported;
@@ -117,8 +136,6 @@ public final class HdmiPortInfo implements Parcelable {

    /**
     * Returns {@code true} if the port supports MHL signaling.
     *
     * @return {@code true} if the port supports MHL signaling.
     */
    public boolean isMhlSupported() {
        return mMhlSupported;
@@ -126,8 +143,6 @@ public final class HdmiPortInfo implements Parcelable {

    /**
     * Returns {@code true} if the port supports audio return channel.
     *
     * @return {@code true} if the port supports audio return channel
     */
    public boolean isArcSupported() {
        return mArcSupported;
@@ -135,8 +150,6 @@ public final class HdmiPortInfo implements Parcelable {

    /**
     * Returns {@code true} if the port supports eARC.
     *
     * @return {@code true} if the port supports eARC.
     */
    public boolean isEarcSupported() {
        return mEarcSupported;
@@ -166,7 +179,12 @@ public final class HdmiPortInfo implements Parcelable {
                    boolean arc = (source.readInt() == 1);
                    boolean mhl = (source.readInt() == 1);
                    boolean earc = (source.readInt() == 1);
                    return new HdmiPortInfo(id, type, address, cec, mhl, arc, earc);
                    return new Builder(id, type, address)
                            .setCecSupported(cec)
                            .setArcSupported(arc)
                            .setEarcSupported(earc)
                            .setMhlSupported(mhl)
                            .build();
                }

                @Override
@@ -225,4 +243,95 @@ public final class HdmiPortInfo implements Parcelable {
        return java.util.Objects.hash(
                mId, mType, mAddress, mCecSupported, mArcSupported, mMhlSupported, mEarcSupported);
    }

    /**
     * Builder for {@link HdmiPortInfo} instances.
     */
    public static final class Builder {
        // Required parameters
        private int mId;
        private int mType;
        private int mAddress;

        // Optional parameters that are set to false by default.
        private boolean mCecSupported;
        private boolean mArcSupported;
        private boolean mEarcSupported;
        private boolean mMhlSupported;

        /**
         * Constructor
         *
         * @param id      identifier assigned to each port. 1 for HDMI OUT port 1
         * @param type    HDMI port input/output type
         * @param address physical address of the port
         * @throws IllegalArgumentException if the parameters are invalid
         */
        public Builder(int id, @PortType int type, @IntRange(from = 0) int address) {
            if (type != PORT_INPUT && type != PORT_OUTPUT) {
                throw new IllegalArgumentException(
                        "type should be " + PORT_INPUT + " or " + PORT_OUTPUT + ".");
            }
            if (address < 0) {
                throw new IllegalArgumentException("address should be positive.");
            }
            mId = id;
            mType = type;
            mAddress = address;
        }

        private Builder(@NonNull HdmiPortInfo hdmiPortInfo) {
            mId = hdmiPortInfo.mId;
            mType = hdmiPortInfo.mType;
            mAddress = hdmiPortInfo.mAddress;
            mCecSupported = hdmiPortInfo.mCecSupported;
            mArcSupported = hdmiPortInfo.mArcSupported;
            mEarcSupported = hdmiPortInfo.mEarcSupported;
            mMhlSupported = hdmiPortInfo.mMhlSupported;
        }

        /**
         * Create a new {@link HdmiPortInfo} object.
         */
        @NonNull
        public HdmiPortInfo build() {
            return new HdmiPortInfo(this);
        }

        /**
         * Sets the value for whether the port supports HDMI-CEC signaling.
         */
        @NonNull
        public Builder setCecSupported(boolean supported) {
            mCecSupported = supported;
            return this;
        }

        /**
         * Sets the value for whether the port supports audio return channel.
         */
        @NonNull
        public Builder setArcSupported(boolean supported) {
            mArcSupported = supported;
            return this;
        }

        /**
         * Sets the value for whether the port supports eARC.
         */
        @NonNull
        public Builder setEarcSupported(boolean supported) {
            mEarcSupported = supported;
            return this;
        }

        /**
         * Sets the value for whether the port supports MHL signaling.
         */
        @NonNull
        public Builder setMhlSupported(boolean supported) {
            mMhlSupported = supported;
            return this;
        }
    }
}
+45 −21
Original line number Diff line number Diff line
@@ -41,34 +41,58 @@ public class HdmiPortInfoTest {

        new EqualsTester()
                .addEqualityGroup(
                        new HdmiPortInfo(portId, portType, address, isCec, isMhl, isArcSupported,
                                isEarcSupported),
                        new HdmiPortInfo(portId, portType, address, isCec, isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported),
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(
                                portId + 1, portType, address, isCec, isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId + 1, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(
                                portId, portType + 1, address, isCec, isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType + 1, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(
                                portId, portType, address + 1, isCec, isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address + 1)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(portId, portType, address, !isCec, isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(!isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(portId, portType, address, isCec, !isMhl, isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(!isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(portId, portType, address, isCec, isMhl, !isArcSupported,
                                isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(!isArcSupported)
                                .setEarcSupported(isEarcSupported))
                .addEqualityGroup(
                        new HdmiPortInfo(portId, portType, address, isCec, isMhl, isArcSupported,
                                !isEarcSupported))
                        new HdmiPortInfo.Builder(portId, portType, address)
                                .setCecSupported(isCec)
                                .setMhlSupported(isMhl)
                                .setArcSupported(isArcSupported)
                                .setEarcSupported(!isEarcSupported))
                .testEquals();
    }
}
+23 −19
Original line number Diff line number Diff line
@@ -1096,15 +1096,15 @@ final class HdmiCecController {
                HdmiPortInfo[] hdmiPortInfo = new HdmiPortInfo[hdmiPortInfos.length];
                int i = 0;
                for (android.hardware.tv.hdmi.connection.HdmiPortInfo portInfo : hdmiPortInfos) {
                    hdmiPortInfo[i] =
                            new HdmiPortInfo(
                    hdmiPortInfo[i] = new HdmiPortInfo.Builder(
                                    portInfo.portId,
                                    portInfo.type,
                                    portInfo.physicalAddress,
                                    portInfo.cecSupported,
                                    false,
                                    portInfo.arcSupported,
                                    false);
                                    portInfo.physicalAddress)
                                    .setCecSupported(portInfo.cecSupported)
                                    .setMhlSupported(false)
                                    .setArcSupported(portInfo.arcSupported)
                                    .setEarcSupported(false)
                                    .build();
                    i++;
                }
                return hdmiPortInfo;
@@ -1260,13 +1260,15 @@ final class HdmiCecController {
                HdmiPortInfo[] hdmiPortInfo = new HdmiPortInfo[hdmiPortInfos.size()];
                int i = 0;
                for (android.hardware.tv.cec.V1_0.HdmiPortInfo portInfo : hdmiPortInfos) {
                    hdmiPortInfo[i] = new HdmiPortInfo(portInfo.portId,
                    hdmiPortInfo[i] = new HdmiPortInfo.Builder(
                            portInfo.portId,
                            portInfo.type,
                            portInfo.physicalAddress,
                            portInfo.cecSupported,
                            false,
                            portInfo.arcSupported,
                            false);
                            portInfo.physicalAddress)
                            .setCecSupported(portInfo.cecSupported)
                            .setMhlSupported(false)
                            .setArcSupported(portInfo.arcSupported)
                            .setEarcSupported(false)
                            .build();
                    i++;
                }
                return hdmiPortInfo;
@@ -1442,13 +1444,15 @@ final class HdmiCecController {
                HdmiPortInfo[] hdmiPortInfo = new HdmiPortInfo[hdmiPortInfos.size()];
                int i = 0;
                for (android.hardware.tv.cec.V1_0.HdmiPortInfo portInfo : hdmiPortInfos) {
                    hdmiPortInfo[i] = new HdmiPortInfo(portInfo.portId,
                    hdmiPortInfo[i] = new HdmiPortInfo.Builder(
                            portInfo.portId,
                            portInfo.type,
                            portInfo.physicalAddress,
                            portInfo.cecSupported,
                            false,
                            portInfo.arcSupported,
                            false);
                            portInfo.physicalAddress)
                            .setCecSupported(portInfo.cecSupported)
                            .setMhlSupported(false)
                            .setArcSupported(portInfo.arcSupported)
                            .setEarcSupported(false)
                            .build();
                    i++;
                }
                return hdmiPortInfo;
+6 −3
Original line number Diff line number Diff line
@@ -469,9 +469,12 @@ public class HdmiCecNetwork {
        ArrayList<HdmiPortInfo> result = new ArrayList<>(cecPortInfo.length);
        for (HdmiPortInfo info : cecPortInfo) {
            if (mhlSupportedPorts.contains(info.getId())) {
                result.add(new HdmiPortInfo(info.getId(), info.getType(), info.getAddress(),
                        info.isCecSupported(), true, info.isArcSupported(),
                        info.isEarcSupported()));
                result.add(new HdmiPortInfo.Builder(info.getId(), info.getType(), info.getAddress())
                        .setCecSupported(info.isCecSupported())
                        .setMhlSupported(true)
                        .setArcSupported(info.isArcSupported())
                        .setEarcSupported(info.isEarcSupported())
                        .build());
            } else {
                result.add(info);
            }
Loading