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.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * A request for command from broadcast signal.
25  */
26 public final class CommandRequest extends BroadcastInfoRequest implements Parcelable {
27     public static final String ARGUMENT_TYPE_XML = "xml";
28     public static final String ARGUMENT_TYPE_JSON = "json";
29     private static final @TvInputManager.BroadcastInfoType int REQUEST_TYPE =
30             TvInputManager.BROADCAST_INFO_TYPE_COMMAND;
31 
32     public static final @NonNull Parcelable.Creator<CommandRequest> CREATOR =
33             new Parcelable.Creator<CommandRequest>() {
34                 @Override
35                 public CommandRequest createFromParcel(Parcel source) {
36                     source.readInt();
37                     return createFromParcelBody(source);
38                 }
39 
40                 @Override
41                 public CommandRequest[] newArray(int size) {
42                     return new CommandRequest[size];
43                 }
44             };
45 
46     private final String mNamespace;
47     private final String mName;
48     private final String mArguments;
49     private final String mArgumentType;
50 
createFromParcelBody(Parcel in)51     static CommandRequest createFromParcelBody(Parcel in) {
52         return new CommandRequest(in);
53     }
54 
CommandRequest(int requestId, @RequestOption int option, @NonNull String namespace, @NonNull String name, @NonNull String arguments, @NonNull String argumentType)55     public CommandRequest(int requestId, @RequestOption int option, @NonNull String namespace,
56             @NonNull String name, @NonNull String arguments, @NonNull String argumentType) {
57         super(REQUEST_TYPE, requestId, option);
58         mNamespace = namespace;
59         mName = name;
60         mArguments = arguments;
61         mArgumentType = argumentType;
62     }
63 
CommandRequest(Parcel source)64     CommandRequest(Parcel source) {
65         super(REQUEST_TYPE, source);
66         mNamespace = source.readString();
67         mName = source.readString();
68         mArguments = source.readString();
69         mArgumentType = source.readString();
70     }
71 
72     /**
73      * Gets the namespace of the command.
74      */
75     @NonNull
getNamespace()76     public String getNamespace() {
77         return mNamespace;
78     }
79 
80     /**
81      * Gets the name of the command.
82      */
83     @NonNull
getName()84     public String getName() {
85         return mName;
86     }
87 
88     /**
89      * Gets the arguments of the command.
90      * It could be serialized from some formats, such as JSON, XML, etc.
91      */
92     @NonNull
getArguments()93     public String getArguments() {
94         return mArguments;
95     }
96 
97     /**
98      * Gets the argument type of the command.
99      * It could be either JSON or XML.
100      */
101     @NonNull
getArgumentType()102     public String getArgumentType() {
103         return mArgumentType;
104     }
105 
106     @Override
describeContents()107     public int describeContents() {
108         return 0;
109     }
110 
111     @Override
writeToParcel(@onNull Parcel dest, int flags)112     public void writeToParcel(@NonNull Parcel dest, int flags) {
113         super.writeToParcel(dest, flags);
114         dest.writeString(mNamespace);
115         dest.writeString(mName);
116         dest.writeString(mArguments);
117         dest.writeString(mArgumentType);
118     }
119 }
120