Shishir Agrawal | a122e8d | 2014-07-29 21:15:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.telephony; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Response to the {@link TelephonyManager#iccOpenLogicalChannel} command. |
| 25 | */ |
| 26 | public class IccOpenLogicalChannelResponse implements Parcelable { |
Shishir Agrawal | ef489ef | 2014-08-25 08:53:29 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Indicates an invalid channel. |
| 29 | */ |
Shishir Agrawal | ed62dd4 | 2014-09-04 12:32:00 -0700 | [diff] [blame] | 30 | public static final int INVALID_CHANNEL = -1; |
Shishir Agrawal | a122e8d | 2014-07-29 21:15:42 -0700 | [diff] [blame] | 31 | |
Shishir Agrawal | ef489ef | 2014-08-25 08:53:29 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Possible status values returned by open channel command. |
| 34 | * |
| 35 | * STATUS_NO_ERROR: Open channel command returned successfully. |
| 36 | * STATUS_MISSING_RESOURCE: No logical channels available. |
| 37 | * STATUS_NO_SUCH_ELEMENT: AID not found on UICC. |
| 38 | * STATUS_UNKNOWN_ERROR: Unknown error in open channel command. |
| 39 | */ |
Shishir Agrawal | ed62dd4 | 2014-09-04 12:32:00 -0700 | [diff] [blame] | 40 | public static final int STATUS_NO_ERROR = 1; |
| 41 | public static final int STATUS_MISSING_RESOURCE = 2; |
| 42 | public static final int STATUS_NO_SUCH_ELEMENT = 3; |
| 43 | public static final int STATUS_UNKNOWN_ERROR = 4; |
Shishir Agrawal | a122e8d | 2014-07-29 21:15:42 -0700 | [diff] [blame] | 44 | |
| 45 | private final int mChannel; |
| 46 | private final int mStatus; |
| 47 | private final byte[] mSelectResponse; |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | * |
| 52 | * @hide |
| 53 | */ |
| 54 | public IccOpenLogicalChannelResponse(int channel, int status, byte[] selectResponse) { |
| 55 | mChannel = channel; |
| 56 | mStatus = status; |
| 57 | mSelectResponse = selectResponse; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Construct a IccOpenLogicalChannelResponse from a given parcel. |
| 62 | */ |
| 63 | private IccOpenLogicalChannelResponse(Parcel in) { |
| 64 | mChannel = in.readInt(); |
| 65 | mStatus = in.readInt(); |
| 66 | int arrayLength = in.readInt(); |
| 67 | if (arrayLength > 0) { |
| 68 | mSelectResponse = new byte[arrayLength]; |
| 69 | in.readByteArray(mSelectResponse); |
| 70 | } else { |
| 71 | mSelectResponse = null; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return the channel id. |
| 77 | */ |
| 78 | public int getChannel() { |
| 79 | return mChannel; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return the status of the command. |
| 84 | */ |
| 85 | public int getStatus() { |
| 86 | return mStatus; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @return the select response. |
| 91 | */ |
| 92 | public byte[] getSelectResponse() { |
| 93 | return mSelectResponse; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int describeContents() { |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void writeToParcel(Parcel out, int flags) { |
| 103 | out.writeInt(mChannel); |
| 104 | out.writeInt(mStatus); |
Shishir Agrawal | 1521e5a | 2014-07-31 19:01:12 -0700 | [diff] [blame] | 105 | if (mSelectResponse != null && mSelectResponse.length > 0) { |
Shishir Agrawal | a122e8d | 2014-07-29 21:15:42 -0700 | [diff] [blame] | 106 | out.writeInt(mSelectResponse.length); |
| 107 | out.writeByteArray(mSelectResponse); |
| 108 | } else { |
| 109 | out.writeInt(0); |
| 110 | } |
| 111 | } |
| 112 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 113 | public static final @android.annotation.NonNull Parcelable.Creator<IccOpenLogicalChannelResponse> CREATOR |
Shishir Agrawal | a122e8d | 2014-07-29 21:15:42 -0700 | [diff] [blame] | 114 | = new Parcelable.Creator<IccOpenLogicalChannelResponse>() { |
| 115 | |
| 116 | @Override |
| 117 | public IccOpenLogicalChannelResponse createFromParcel(Parcel in) { |
| 118 | return new IccOpenLogicalChannelResponse(in); |
| 119 | } |
| 120 | |
| 121 | public IccOpenLogicalChannelResponse[] newArray(int size) { |
| 122 | return new IccOpenLogicalChannelResponse[size]; |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return "Channel: " + mChannel + " Status: " + mStatus; |
| 129 | } |
| 130 | } |