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

Commit 6d2f3b3c authored by shubang's avatar shubang
Browse files

API review: Builder for TableResponse

Fix: 269604423
Test: atest testTableResponseWithByteArray
Test: atest testTableResponseWithSharedMemory
Change-Id: Ifac6212f7b406af3f5fede92f58bdf69fa640b86
parent b295b957
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -26754,9 +26754,7 @@ package android.media.tv {
  }
  public final class TableResponse extends android.media.tv.BroadcastInfoResponse implements android.os.Parcelable {
    ctor public TableResponse(int, int, int, @Nullable android.net.Uri, int, int);
    ctor public TableResponse(int, int, int, @NonNull byte[], int, int);
    ctor public TableResponse(int, int, int, @NonNull android.os.SharedMemory, int, int);
    ctor @Deprecated public TableResponse(int, int, int, @Nullable android.net.Uri, int, int);
    method public int getSize();
    method @Nullable public byte[] getTableByteArray();
    method @Nullable public android.os.SharedMemory getTableSharedMemory();
@@ -26765,6 +26763,14 @@ package android.media.tv {
    field @NonNull public static final android.os.Parcelable.Creator<android.media.tv.TableResponse> CREATOR;
  }
  public static final class TableResponse.Builder {
    ctor public TableResponse.Builder(int, int, int, int, int);
    method @NonNull public android.media.tv.TableResponse build();
    method @NonNull public android.media.tv.TableResponse.Builder setTableByteArray(@NonNull byte[]);
    method @NonNull public android.media.tv.TableResponse.Builder setTableSharedMemory(@NonNull android.os.SharedMemory);
    method @NonNull public android.media.tv.TableResponse.Builder setTableUri(@NonNull android.net.Uri);
  }
  public final class TimelineRequest extends android.media.tv.BroadcastInfoRequest implements android.os.Parcelable {
    ctor public TimelineRequest(int, int, int);
    ctor public TimelineRequest(int, int, int, @NonNull String);
+119 −28
Original line number Diff line number Diff line
@@ -64,7 +64,10 @@ public final class TableResponse extends BroadcastInfoResponse implements Parcel
     * @param tableUri The URI of the table in the database.
     * @param version The version number of requested table.
     * @param size The Size number of table in bytes.
     *
     * @deprecated use {@link Builder} instead.
     */
    @Deprecated
    public TableResponse(int requestId, int sequence, @ResponseResult int responseResult,
            @Nullable Uri tableUri, int version, int size) {
        super(RESPONSE_TYPE, requestId, sequence, responseResult);
@@ -76,51 +79,139 @@ public final class TableResponse extends BroadcastInfoResponse implements Parcel
    }

    /**
     * Constructs a TableResponse with a table URI.
     * Constructs a TableResponse.
     *
     * @param requestId The ID is used to associate the response with the request.
     * @param sequence The sequence number which indicates the order of related responses.
     * @param responseResult The result for the response. It's one of {@link #RESPONSE_RESULT_OK},
     *                       {@link #RESPONSE_RESULT_CANCEL}, {@link #RESPONSE_RESULT_ERROR}.
     * @param tableByteArray The byte array which stores the table in bytes. The structure and
     *                       syntax of the table depends on the table name in
     * @param tableSharedMemory The shared memory which stores the table. The table size can be
     *                          large so using a shared memory optimizes the data
     *                          communication between the table data source and the receiver. The
     *                          structure syntax of the table depends on the table name in
     *                          {@link TableRequest#getTableName()} and the corresponding standard.
     * @param version The version number of requested table.
     * @param size The Size number of table in bytes.
     * @param tableUri The URI of the table in the database.
     * @param tableByteArray The byte array which stores the table in bytes. The structure and
     *                       syntax of the table depends on the table name in
     * @param tableSharedMemory The shared memory which stores the table. The table size can be
     *                          large so using a shared memory optimizes the data
     *                          communication between the table data source and the receiver. The
     *                          structure syntax of the table depends on the table name in
     *                          {@link TableRequest#getTableName()} and the corresponding standard.
     */
    public TableResponse(int requestId, int sequence, @ResponseResult int responseResult,
            @NonNull byte[] tableByteArray, int version, int size) {
    private TableResponse(int requestId, int sequence, @ResponseResult int responseResult,
            int version, int size, Uri tableUri, byte[] tableByteArray,
            SharedMemory tableSharedMemory) {
        super(RESPONSE_TYPE, requestId, sequence, responseResult);
        mVersion = version;
        mSize = size;
        mTableUri = null;
        mTableUri = tableUri;
        mTableByteArray = tableByteArray;
        mTableSharedMemory = null;
        mTableSharedMemory = tableSharedMemory;
    }

    /**
     * Constructs a TableResponse with a table URI.
     * Builder for {@link TableResponse}.
     */
    public static final class Builder {
        private final int mRequestId;
        private final int mSequence;
        @ResponseResult
        private final int mResponseResult;
        private final int mVersion;
        private final int mSize;
        private Uri mTableUri;
        private byte[] mTableByteArray;
        private SharedMemory mTableSharedMemory;

        /**
         * Constructs a Builder object of {@link TableResponse}.
         *
         * @param requestId The ID is used to associate the response with the request.
         * @param sequence The sequence number which indicates the order of related responses.
     * @param responseResult The result for the response. It's one of {@link #RESPONSE_RESULT_OK},
     *                       {@link #RESPONSE_RESULT_CANCEL}, {@link #RESPONSE_RESULT_ERROR}.
     * @param tableSharedMemory The shared memory which stores the table. The table size can be
     *                          large so using a shared memory optimizes the data
     *                          communication between the table data source and the receiver. The
     *                          structure syntax of the table depends on the table name in
     *                          {@link TableRequest#getTableName()} and the corresponding standard.
         * @param responseResult The result for the response. It's one of
         *                       {@link #RESPONSE_RESULT_OK}, {@link #RESPONSE_RESULT_CANCEL},
         *                       {@link #RESPONSE_RESULT_ERROR}.
         * @param version The version number of requested table.
         * @param size The Size number of table in bytes.
         */
    public TableResponse(int requestId, int sequence, @ResponseResult int responseResult,
            @NonNull SharedMemory tableSharedMemory, int version, int size) {
        super(RESPONSE_TYPE, requestId, sequence, responseResult);
        public Builder(int requestId, int sequence, @ResponseResult int responseResult, int version,
                int size) {
            mRequestId = requestId;
            mSequence = sequence;
            mResponseResult = responseResult;
            mVersion = version;
            mSize = size;
        }

        /**
         * Sets table URI.
         *
         * <p>For a single builder instance, at most one of table URI, table byte array, and table
         * shared memory can be set. If more than one are set, only the last call takes precedence
         * and others are reset to {@code null}.
         *
         * @param uri The URI of the table.
         */
        @NonNull
        public Builder setTableUri(@NonNull Uri uri) {
            mTableUri = uri;
            mTableByteArray = null;
            mTableSharedMemory = null;
            return this;
        }

        /**
         * Sets table byte array.
         *
         * <p>For a single builder instance, at most one of table URI, table byte array, and table
         * shared memory can be set. If more than one are set, only the last call takes precedence
         * and others are reset to {@code null}.
         *
         * @param bytes The byte array which stores the table in bytes. The structure and
         *              syntax of the table depends on the table name in
         *              {@link TableRequest#getTableName()} and the corresponding standard.
         */
        @NonNull
        public Builder setTableByteArray(@NonNull byte[] bytes) {
            mTableByteArray = bytes;
            mTableUri = null;
            mTableSharedMemory = null;
            return this;
        }


        /**
         * Sets table shared memory.
         *
         * <p>For a single builder instance, at most one of table URI, table byte array, and table
         * shared memory can be set. If more than one are set, only the last call takes precedence
         * and others are reset to {@code null}.
         *
         * @param sharedMemory The shared memory which stores the table. The table size can be
         *                     large so using a shared memory optimizes the data
         *                     communication between the table data source and the receiver. The
         *                     structure syntax of the table depends on the table name in
         *                     {@link TableRequest#getTableName()} and the corresponding standard.
         */
        @NonNull
        public Builder setTableSharedMemory(@NonNull SharedMemory sharedMemory) {
            mTableSharedMemory = sharedMemory;
            mTableUri = null;
            mTableByteArray = null;
        mTableSharedMemory = tableSharedMemory;
            return this;
        }

        /**
         * Builds a {@link TableResponse} object.
         */
        @NonNull
        public TableResponse build() {
            return new TableResponse(mRequestId, mSequence, mResponseResult, mVersion, mSize,
                    mTableUri, mTableByteArray, mTableSharedMemory);
        }
    }

    TableResponse(Parcel source) {