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 Stream Event from broadcast signal.
26  */
27 public final class StreamEventRequest extends BroadcastInfoRequest implements Parcelable {
28     private static final @TvInputManager.BroadcastInfoType int REQUEST_TYPE =
29             TvInputManager.BROADCAST_INFO_STREAM_EVENT;
30 
31     public static final @NonNull Parcelable.Creator<StreamEventRequest> CREATOR =
32             new Parcelable.Creator<StreamEventRequest>() {
33                 @Override
34                 public StreamEventRequest createFromParcel(Parcel source) {
35                     source.readInt();
36                     return createFromParcelBody(source);
37                 }
38 
39                 @Override
40                 public StreamEventRequest[] newArray(int size) {
41                     return new StreamEventRequest[size];
42                 }
43             };
44 
45     private final Uri mTargetUri;
46     private final String mEventName;
47 
createFromParcelBody(Parcel in)48     static StreamEventRequest createFromParcelBody(Parcel in) {
49         return new StreamEventRequest(in);
50     }
51 
StreamEventRequest(int requestId, @RequestOption int option, @NonNull Uri targetUri, @NonNull String eventName)52     public StreamEventRequest(int requestId, @RequestOption int option, @NonNull Uri targetUri,
53             @NonNull String eventName) {
54         super(REQUEST_TYPE, requestId, option);
55         this.mTargetUri = targetUri;
56         this.mEventName = eventName;
57     }
58 
StreamEventRequest(Parcel source)59     StreamEventRequest(Parcel source) {
60         super(REQUEST_TYPE, source);
61         String uriString = source.readString();
62         mTargetUri = uriString == null ? null : Uri.parse(uriString);
63         mEventName = source.readString();
64     }
65 
66     /**
67      * Gets the URI for the DSM-CC Object or the event description file describing the event.
68      */
69     @NonNull
getTargetUri()70     public Uri getTargetUri() {
71         return mTargetUri;
72     }
73 
74     /**
75      * Gets the name of the event.
76      */
77     @NonNull
getEventName()78     public String getEventName() {
79         return mEventName;
80     }
81 
82     @Override
describeContents()83     public int describeContents() {
84         return 0;
85     }
86 
87     @Override
writeToParcel(@onNull Parcel dest, int flags)88     public void writeToParcel(@NonNull Parcel dest, int flags) {
89         super.writeToParcel(dest, flags);
90         String uriString = mTargetUri == null ? null : mTargetUri.toString();
91         dest.writeString(uriString);
92         dest.writeString(mEventName);
93     }
94 }
95