• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.IntDef;
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.util.Objects;
28 
29 /**
30  * Class for the information of a UICC slot.
31  * @hide
32  */
33 @SystemApi
34 public class UiccSlotInfo implements Parcelable {
35     /**
36      * Card state.
37      * @hide
38      */
39     @Retention(RetentionPolicy.SOURCE)
40     @IntDef(prefix = { "CARD_STATE_INFO_" }, value = {
41             CARD_STATE_INFO_ABSENT,
42             CARD_STATE_INFO_PRESENT,
43             CARD_STATE_INFO_ERROR,
44             CARD_STATE_INFO_RESTRICTED
45     })
46     public @interface CardStateInfo {}
47 
48     /** Card state absent. */
49     public static final int CARD_STATE_INFO_ABSENT = 1;
50 
51     /** Card state present. */
52     public static final int CARD_STATE_INFO_PRESENT = 2;
53 
54     /** Card state error. */
55     public static final int CARD_STATE_INFO_ERROR = 3;
56 
57     /** Card state restricted. */
58     public static final int CARD_STATE_INFO_RESTRICTED = 4;
59 
60     private final boolean mIsActive;
61     private final boolean mIsEuicc;
62     private final String mCardId;
63     private final @CardStateInfo int mCardStateInfo;
64     private final int mLogicalSlotIdx;
65     private final boolean mIsExtendedApduSupported;
66     private final boolean mIsRemovable;
67 
68     public static final @android.annotation.NonNull Creator<UiccSlotInfo> CREATOR = new Creator<UiccSlotInfo>() {
69         @Override
70         public UiccSlotInfo createFromParcel(Parcel in) {
71             return new UiccSlotInfo(in);
72         }
73 
74         @Override
75         public UiccSlotInfo[] newArray(int size) {
76             return new UiccSlotInfo[size];
77         }
78     };
79 
UiccSlotInfo(Parcel in)80     private UiccSlotInfo(Parcel in) {
81         mIsActive = in.readByte() != 0;
82         mIsEuicc = in.readByte() != 0;
83         mCardId = in.readString();
84         mCardStateInfo = in.readInt();
85         mLogicalSlotIdx = in.readInt();
86         mIsExtendedApduSupported = in.readByte() != 0;
87         mIsRemovable = in.readByte() != 0;
88     }
89 
90     @Override
writeToParcel(Parcel dest, int flags)91     public void writeToParcel(Parcel dest, int flags) {
92         dest.writeByte((byte) (mIsActive ? 1 : 0));
93         dest.writeByte((byte) (mIsEuicc ? 1 : 0));
94         dest.writeString(mCardId);
95         dest.writeInt(mCardStateInfo);
96         dest.writeInt(mLogicalSlotIdx);
97         dest.writeByte((byte) (mIsExtendedApduSupported ? 1 : 0));
98         dest.writeByte((byte) (mIsRemovable ? 1 : 0));
99     }
100 
101     @Override
describeContents()102     public int describeContents() {
103         return 0;
104     }
105 
106     /**
107      * Construct a UiccSlotInfo.
108      * @deprecated apps should not be constructing UiccSlotInfo objects
109      */
110     @Deprecated
UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId, @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported)111     public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
112             @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported) {
113         this.mIsActive = isActive;
114         this.mIsEuicc = isEuicc;
115         this.mCardId = cardId;
116         this.mCardStateInfo = cardStateInfo;
117         this.mLogicalSlotIdx = logicalSlotIdx;
118         this.mIsExtendedApduSupported = isExtendedApduSupported;
119         this.mIsRemovable = false;
120     }
121 
122     /**
123      * @hide
124      */
UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId, @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported, boolean isRemovable)125     public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
126             @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported,
127             boolean isRemovable) {
128         this.mIsActive = isActive;
129         this.mIsEuicc = isEuicc;
130         this.mCardId = cardId;
131         this.mCardStateInfo = cardStateInfo;
132         this.mLogicalSlotIdx = logicalSlotIdx;
133         this.mIsExtendedApduSupported = isExtendedApduSupported;
134         this.mIsRemovable = isRemovable;
135     }
136 
getIsActive()137     public boolean getIsActive() {
138         return mIsActive;
139     }
140 
getIsEuicc()141     public boolean getIsEuicc() {
142         return mIsEuicc;
143     }
144 
145     /**
146      * Returns the ICCID of the card in the slot, or the EID of an active eUICC.
147      * <p>
148      * If the UICC slot is for an active eUICC, returns the EID.
149      * If the UICC slot is for an inactive eUICC, returns the ICCID of the enabled profile, or the
150      * root profile if all other profiles are disabled.
151      * If the UICC slot is not an eUICC, returns the ICCID.
152      */
getCardId()153     public String getCardId() {
154         return mCardId;
155     }
156 
157     @CardStateInfo
getCardStateInfo()158     public int getCardStateInfo() {
159         return mCardStateInfo;
160     }
161 
getLogicalSlotIdx()162     public int getLogicalSlotIdx() {
163         return mLogicalSlotIdx;
164     }
165 
166     /**
167      * @return {@code true} if this slot supports extended APDU from ATR, {@code false} otherwise.
168      */
getIsExtendedApduSupported()169     public boolean getIsExtendedApduSupported() {
170         return mIsExtendedApduSupported;
171     }
172 
173    /**
174      * Return whether the UICC slot is for a removable UICC.
175      * <p>
176      * UICCs are generally removable, but eUICCs may be removable or built in to the device.
177      * @return true if the slot is for removable UICCs
178      */
isRemovable()179     public boolean isRemovable() {
180         return mIsRemovable;
181     }
182 
183     @Override
equals(@ullable Object obj)184     public boolean equals(@Nullable Object obj) {
185         if (this == obj) {
186             return true;
187         }
188         if (obj == null || getClass() != obj.getClass()) {
189             return false;
190         }
191 
192         UiccSlotInfo that = (UiccSlotInfo) obj;
193         return (mIsActive == that.mIsActive)
194                 && (mIsEuicc == that.mIsEuicc)
195                 && (Objects.equals(mCardId, that.mCardId))
196                 && (mCardStateInfo == that.mCardStateInfo)
197                 && (mLogicalSlotIdx == that.mLogicalSlotIdx)
198                 && (mIsExtendedApduSupported == that.mIsExtendedApduSupported)
199                 && (mIsRemovable == that.mIsRemovable);
200     }
201 
202     @Override
hashCode()203     public int hashCode() {
204         int result = 1;
205         result = 31 * result + (mIsActive ? 1 : 0);
206         result = 31 * result + (mIsEuicc ? 1 : 0);
207         result = 31 * result + Objects.hashCode(mCardId);
208         result = 31 * result + mCardStateInfo;
209         result = 31 * result + mLogicalSlotIdx;
210         result = 31 * result + (mIsExtendedApduSupported ? 1 : 0);
211         result = 31 * result + (mIsRemovable ? 1 : 0);
212         return result;
213     }
214 
215     @NonNull
216     @Override
toString()217     public String toString() {
218         return "UiccSlotInfo (mIsActive="
219                 + mIsActive
220                 + ", mIsEuicc="
221                 + mIsEuicc
222                 + ", mCardId="
223                 + mCardId
224                 + ", cardState="
225                 + mCardStateInfo
226                 + ", phoneId="
227                 + mLogicalSlotIdx
228                 + ", mIsExtendedApduSupported="
229                 + mIsExtendedApduSupported
230                 + ", mIsRemovable="
231                 + mIsRemovable
232                 + ")";
233     }
234 }
235