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.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * A response for command from broadcast signal. 26 */ 27 public final class CommandResponse extends BroadcastInfoResponse implements Parcelable { 28 public static final String RESPONSE_TYPE_XML = "xml"; 29 public static final String RESPONSE_TYPE_JSON = "json"; 30 private static final @TvInputManager.BroadcastInfoType int RESPONSE_TYPE = 31 TvInputManager.BROADCAST_INFO_TYPE_COMMAND; 32 33 public static final @NonNull Parcelable.Creator<CommandResponse> CREATOR = 34 new Parcelable.Creator<CommandResponse>() { 35 @Override 36 public CommandResponse createFromParcel(Parcel source) { 37 source.readInt(); 38 return createFromParcelBody(source); 39 } 40 41 @Override 42 public CommandResponse[] newArray(int size) { 43 return new CommandResponse[size]; 44 } 45 }; 46 47 private final String mResponse; 48 private final String mResponseType; 49 createFromParcelBody(Parcel in)50 static CommandResponse createFromParcelBody(Parcel in) { 51 return new CommandResponse(in); 52 } 53 CommandResponse(int requestId, int sequence, @ResponseResult int responseResult, @Nullable String response, @NonNull String responseType)54 public CommandResponse(int requestId, int sequence, @ResponseResult int responseResult, 55 @Nullable String response, @NonNull String responseType) { 56 super(RESPONSE_TYPE, requestId, sequence, responseResult); 57 mResponse = response; 58 mResponseType = responseType; 59 } 60 CommandResponse(Parcel source)61 CommandResponse(Parcel source) { 62 super(RESPONSE_TYPE, source); 63 mResponse = source.readString(); 64 mResponseType = source.readString(); 65 } 66 67 /** 68 * Gets the response of the command. 69 * It could be serialized from some formats, such as JSON, XML, etc. 70 */ 71 @Nullable getResponse()72 public String getResponse() { 73 return mResponse; 74 } 75 76 /** 77 * Gets the type of the command response. 78 * It could be either JSON or XML. 79 */ 80 @NonNull getResponseType()81 public String getResponseType() { 82 return mResponseType; 83 } 84 85 @Override describeContents()86 public int describeContents() { 87 return 0; 88 } 89 90 @Override writeToParcel(@onNull Parcel dest, int flags)91 public void writeToParcel(@NonNull Parcel dest, int flags) { 92 super.writeToParcel(dest, flags); 93 dest.writeString(mResponse); 94 dest.writeString(mResponseType); 95 } 96 } 97