1 /*
2  * Copyright (C) 2018 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 package android.telephony;
17 
18 import android.annotation.SystemApi;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.util.Objects;
24 
25 import android.annotation.IntDef;
26 
27 /**
28  * Class for the information of a UICC slot.
29  * @hide
30  */
31 @SystemApi
32 public class UiccSlotInfo implements Parcelable {
33     /**
34      * Card state.
35      * @hide
36      */
37     @Retention(RetentionPolicy.SOURCE)
38     @IntDef(prefix = { "CARD_STATE_INFO_" }, value = {
39             CARD_STATE_INFO_ABSENT,
40             CARD_STATE_INFO_PRESENT,
41             CARD_STATE_INFO_ERROR,
42             CARD_STATE_INFO_RESTRICTED
43     })
44     public @interface CardStateInfo {}
45 
46     /** Card state absent. */
47     public static final int CARD_STATE_INFO_ABSENT = 1;
48 
49     /** Card state present. */
50     public static final int CARD_STATE_INFO_PRESENT = 2;
51 
52     /** Card state error. */
53     public static final int CARD_STATE_INFO_ERROR = 3;
54 
55     /** Card state restricted. */
56     public static final int CARD_STATE_INFO_RESTRICTED = 4;
57 
58     private final boolean mIsActive;
59     private final boolean mIsEuicc;
60     private final String mCardId;
61     private final @CardStateInfo int mCardStateInfo;
62     private final int mLogicalSlotIdx;
63     private final boolean mIsExtendedApduSupported;
64 
65     public static final Creator<UiccSlotInfo> CREATOR = new Creator<UiccSlotInfo>() {
66         @Override
67         public UiccSlotInfo createFromParcel(Parcel in) {
68             return new UiccSlotInfo(in);
69         }
70 
71         @Override
72         public UiccSlotInfo[] newArray(int size) {
73             return new UiccSlotInfo[size];
74         }
75     };
76 
UiccSlotInfo(Parcel in)77     private UiccSlotInfo(Parcel in) {
78         mIsActive = in.readByte() != 0;
79         mIsEuicc = in.readByte() != 0;
80         mCardId = in.readString();
81         mCardStateInfo = in.readInt();
82         mLogicalSlotIdx = in.readInt();
83         mIsExtendedApduSupported = in.readByte() != 0;
84     }
85 
86     @Override
writeToParcel(Parcel dest, int flags)87     public void writeToParcel(Parcel dest, int flags) {
88         dest.writeByte((byte) (mIsActive ? 1 : 0));
89         dest.writeByte((byte) (mIsEuicc ? 1 : 0));
90         dest.writeString(mCardId);
91         dest.writeInt(mCardStateInfo);
92         dest.writeInt(mLogicalSlotIdx);
93         dest.writeByte((byte) (mIsExtendedApduSupported ? 1 : 0));
94     }
95 
96     @Override
describeContents()97     public int describeContents() {
98         return 0;
99     }
100 
UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId, @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported)101     public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
102             @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported) {
103         this.mIsActive = isActive;
104         this.mIsEuicc = isEuicc;
105         this.mCardId = cardId;
106         this.mCardStateInfo = cardStateInfo;
107         this.mLogicalSlotIdx = logicalSlotIdx;
108         this.mIsExtendedApduSupported = isExtendedApduSupported;
109     }
110 
getIsActive()111     public boolean getIsActive() {
112         return mIsActive;
113     }
114 
getIsEuicc()115     public boolean getIsEuicc() {
116         return mIsEuicc;
117     }
118 
getCardId()119     public String getCardId() {
120         return mCardId;
121     }
122 
123     @CardStateInfo
getCardStateInfo()124     public int getCardStateInfo() {
125         return mCardStateInfo;
126     }
127 
getLogicalSlotIdx()128     public int getLogicalSlotIdx() {
129         return mLogicalSlotIdx;
130     }
131 
132     /**
133      * @return {@code true} if this slot supports extended APDU from ATR, {@code false} otherwise.
134      */
getIsExtendedApduSupported()135     public boolean getIsExtendedApduSupported() {
136         return mIsExtendedApduSupported;
137     }
138 
139     @Override
equals(Object obj)140     public boolean equals(Object obj) {
141         if (this == obj) {
142             return true;
143         }
144         if (obj == null || getClass() != obj.getClass()) {
145             return false;
146         }
147 
148         UiccSlotInfo that = (UiccSlotInfo) obj;
149         return (mIsActive == that.mIsActive)
150                 && (mIsEuicc == that.mIsEuicc)
151                 && (Objects.equals(mCardId, that.mCardId))
152                 && (mCardStateInfo == that.mCardStateInfo)
153                 && (mLogicalSlotIdx == that.mLogicalSlotIdx)
154                 && (mIsExtendedApduSupported == that.mIsExtendedApduSupported);
155     }
156 
157     @Override
hashCode()158     public int hashCode() {
159         int result = 1;
160         result = 31 * result + (mIsActive ? 1 : 0);
161         result = 31 * result + (mIsEuicc ? 1 : 0);
162         result = 31 * result + Objects.hashCode(mCardId);
163         result = 31 * result + mCardStateInfo;
164         result = 31 * result + mLogicalSlotIdx;
165         result = 31 * result + (mIsExtendedApduSupported ? 1 : 0);
166         return result;
167     }
168 
169     @Override
toString()170     public String toString() {
171         return "UiccSlotInfo (mIsActive="
172                 + mIsActive
173                 + ", mIsEuicc="
174                 + mIsEuicc
175                 + ", mCardId="
176                 + mCardId
177                 + ", cardState="
178                 + mCardStateInfo
179                 + ", phoneId="
180                 + mLogicalSlotIdx
181                 + ", mIsExtendedApduSupported="
182                 + mIsExtendedApduSupported
183                 + ")";
184     }
185 }
186