1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.tv; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * A request for Table from broadcast signal. 29 */ 30 public final class TableRequest extends BroadcastInfoRequest implements Parcelable { 31 private static final @TvInputManager.BroadcastInfoType int REQUEST_TYPE = 32 TvInputManager.BROADCAST_INFO_TYPE_TABLE; 33 34 /** @hide */ 35 @Retention(RetentionPolicy.SOURCE) 36 @IntDef({TABLE_NAME_PAT, TABLE_NAME_PMT, TABLE_NAME_CAT, TABLE_NAME_NIT, TABLE_NAME_BAT, 37 TABLE_NAME_SDT, TABLE_NAME_EIT, TABLE_NAME_TDT, TABLE_NAME_TOT, TABLE_NAME_SIT}) 38 public @interface TableName {} 39 40 /** Program Association Table */ 41 public static final int TABLE_NAME_PAT = 0; 42 /** Program Mapping Table */ 43 public static final int TABLE_NAME_PMT = 1; 44 /** 45 * Conditional Access Table 46 */ 47 public static final int TABLE_NAME_CAT = 2; 48 /** 49 * Network Information Table 50 */ 51 public static final int TABLE_NAME_NIT = 3; 52 /** 53 * Bouquet Association Table 54 */ 55 public static final int TABLE_NAME_BAT = 4; 56 /** 57 * Service Description Table 58 */ 59 public static final int TABLE_NAME_SDT = 5; 60 /** 61 * Event Information Table 62 */ 63 public static final int TABLE_NAME_EIT = 6; 64 /** 65 * Time and Date Table 66 */ 67 public static final int TABLE_NAME_TDT = 7; 68 /** 69 * Time Offset Table 70 */ 71 public static final int TABLE_NAME_TOT = 8; 72 /** 73 * Selection Information Table 74 */ 75 public static final int TABLE_NAME_SIT = 9; 76 77 78 public static final @NonNull Parcelable.Creator<TableRequest> CREATOR = 79 new Parcelable.Creator<TableRequest>() { 80 @Override 81 public TableRequest createFromParcel(Parcel source) { 82 source.readInt(); 83 return createFromParcelBody(source); 84 } 85 86 @Override 87 public TableRequest[] newArray(int size) { 88 return new TableRequest[size]; 89 } 90 }; 91 92 private final int mTableId; 93 private final @TableName int mTableName; 94 private final int mVersion; 95 createFromParcelBody(Parcel in)96 static TableRequest createFromParcelBody(Parcel in) { 97 return new TableRequest(in); 98 } 99 TableRequest(int requestId, @RequestOption int option, int tableId, @TableName int tableName, int version)100 public TableRequest(int requestId, @RequestOption int option, int tableId, 101 @TableName int tableName, int version) { 102 super(REQUEST_TYPE, requestId, option); 103 mTableId = tableId; 104 mTableName = tableName; 105 mVersion = version; 106 } 107 TableRequest(Parcel source)108 TableRequest(Parcel source) { 109 super(REQUEST_TYPE, source); 110 mTableId = source.readInt(); 111 mTableName = source.readInt(); 112 mVersion = source.readInt(); 113 } 114 115 /** 116 * Gets the ID of requested table. 117 */ getTableId()118 public int getTableId() { 119 return mTableId; 120 } 121 122 /** 123 * Gets the name of requested table. 124 */ getTableName()125 public @TableName int getTableName() { 126 return mTableName; 127 } 128 129 /** 130 * Gets the version number of requested table. If it is null, value will be -1. 131 * <p>The consistency of version numbers between request and response depends on 132 * {@link BroadcastInfoRequest.RequestOption}. If the request has RequestOption value 133 * REQUEST_OPTION_AUTO_UPDATE, then the response may be set to the latest version which may be 134 * different from the version of the request. Otherwise, response with a different version from 135 * its request will be considered invalid. 136 */ getVersion()137 public int getVersion() { 138 return mVersion; 139 } 140 141 @Override describeContents()142 public int describeContents() { 143 return 0; 144 } 145 146 @Override writeToParcel(@onNull Parcel dest, int flags)147 public void writeToParcel(@NonNull Parcel dest, int flags) { 148 super.writeToParcel(dest, flags); 149 dest.writeInt(mTableId); 150 dest.writeInt(mTableName); 151 dest.writeInt(mVersion); 152 } 153 } 154