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.NonNull;
20 import android.net.Uri;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * A request for DSM-CC from broadcast signal.
26  */
27 public final class DsmccRequest extends BroadcastInfoRequest implements Parcelable {
28     private static final @TvInputManager.BroadcastInfoType int REQUEST_TYPE =
29             TvInputManager.BROADCAST_INFO_TYPE_DSMCC;
30 
31     public static final @NonNull Parcelable.Creator<DsmccRequest> CREATOR =
32             new Parcelable.Creator<DsmccRequest>() {
33                 @Override
34                 public DsmccRequest createFromParcel(Parcel source) {
35                     source.readInt();
36                     return createFromParcelBody(source);
37                 }
38 
39                 @Override
40                 public DsmccRequest[] newArray(int size) {
41                     return new DsmccRequest[size];
42                 }
43             };
44 
45     private final Uri mUri;
46 
createFromParcelBody(Parcel in)47     static DsmccRequest createFromParcelBody(Parcel in) {
48         return new DsmccRequest(in);
49     }
50 
DsmccRequest(int requestId, @RequestOption int option, @NonNull Uri uri)51     public DsmccRequest(int requestId, @RequestOption int option, @NonNull Uri uri) {
52         super(REQUEST_TYPE, requestId, option);
53         mUri = uri;
54     }
55 
DsmccRequest(Parcel source)56     DsmccRequest(Parcel source) {
57         super(REQUEST_TYPE, source);
58         String uriString = source.readString();
59         mUri = uriString == null ? null : Uri.parse(uriString);
60     }
61 
62     /**
63      * Gets the URI for DSM-CC object.
64      */
65     @NonNull
getUri()66     public Uri getUri() {
67         return mUri;
68     }
69 
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
75     @Override
writeToParcel(@onNull Parcel dest, int flags)76     public void writeToParcel(@NonNull Parcel dest, int flags) {
77         super.writeToParcel(dest, flags);
78         String uriString = mUri == null ? null : mUri.toString();
79         dest.writeString(uriString);
80     }
81 }
82