• 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.SystemApi;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.lang.annotation.Retention;
24 import java.lang.annotation.RetentionPolicy;
25 import java.util.Objects;
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     private final boolean mIsRemovable;
65 
66     public static final @android.annotation.NonNull Creator<UiccSlotInfo> CREATOR = new Creator<UiccSlotInfo>() {
67         @Override
68         public UiccSlotInfo createFromParcel(Parcel in) {
69             return new UiccSlotInfo(in);
70         }
71 
72         @Override
73         public UiccSlotInfo[] newArray(int size) {
74             return new UiccSlotInfo[size];
75         }
76     };
77 
UiccSlotInfo(Parcel in)78     private UiccSlotInfo(Parcel in) {
79         mIsActive = in.readByte() != 0;
80         mIsEuicc = in.readByte() != 0;
81         mCardId = in.readString();
82         mCardStateInfo = in.readInt();
83         mLogicalSlotIdx = in.readInt();
84         mIsExtendedApduSupported = in.readByte() != 0;
85         mIsRemovable = in.readByte() != 0;
86     }
87 
88     @Override
writeToParcel(Parcel dest, int flags)89     public void writeToParcel(Parcel dest, int flags) {
90         dest.writeByte((byte) (mIsActive ? 1 : 0));
91         dest.writeByte((byte) (mIsEuicc ? 1 : 0));
92         dest.writeString(mCardId);
93         dest.writeInt(mCardStateInfo);
94         dest.writeInt(mLogicalSlotIdx);
95         dest.writeByte((byte) (mIsExtendedApduSupported ? 1 : 0));
96         dest.writeByte((byte) (mIsRemovable ? 1 : 0));
97     }
98 
99     @Override
describeContents()100     public int describeContents() {
101         return 0;
102     }
103 
104     /**
105      * Construct a UiccSlotInfo.
106      * @deprecated apps should not be constructing UiccSlotInfo objects
107      */
108     @Deprecated
UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId, @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported)109     public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
110             @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported) {
111         this.mIsActive = isActive;
112         this.mIsEuicc = isEuicc;
113         this.mCardId = cardId;
114         this.mCardStateInfo = cardStateInfo;
115         this.mLogicalSlotIdx = logicalSlotIdx;
116         this.mIsExtendedApduSupported = isExtendedApduSupported;
117         this.mIsRemovable = false;
118     }
119 
120     /**
121      * @hide
122      */
UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId, @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported, boolean isRemovable)123     public UiccSlotInfo(boolean isActive, boolean isEuicc, String cardId,
124             @CardStateInfo int cardStateInfo, int logicalSlotIdx, boolean isExtendedApduSupported,
125             boolean isRemovable) {
126         this.mIsActive = isActive;
127         this.mIsEuicc = isEuicc;
128         this.mCardId = cardId;
129         this.mCardStateInfo = cardStateInfo;
130         this.mLogicalSlotIdx = logicalSlotIdx;
131         this.mIsExtendedApduSupported = isExtendedApduSupported;
132         this.mIsRemovable = isRemovable;
133     }
134 
getIsActive()135     public boolean getIsActive() {
136         return mIsActive;
137     }
138 
getIsEuicc()139     public boolean getIsEuicc() {
140         return mIsEuicc;
141     }
142 
getCardId()143     public String getCardId() {
144         return mCardId;
145     }
146 
147     @CardStateInfo
getCardStateInfo()148     public int getCardStateInfo() {
149         return mCardStateInfo;
150     }
151 
getLogicalSlotIdx()152     public int getLogicalSlotIdx() {
153         return mLogicalSlotIdx;
154     }
155 
156     /**
157      * @return {@code true} if this slot supports extended APDU from ATR, {@code false} otherwise.
158      */
getIsExtendedApduSupported()159     public boolean getIsExtendedApduSupported() {
160         return mIsExtendedApduSupported;
161     }
162 
163    /**
164      * Return whether the UICC slot is for a removable UICC.
165      * <p>
166      * UICCs are generally removable, but eUICCs may be removable or built in to the device.
167      * @return true if the slot is for removable UICCs
168      */
isRemovable()169     public boolean isRemovable() {
170         return mIsRemovable;
171     }
172 
173     @Override
equals(Object obj)174     public boolean equals(Object obj) {
175         if (this == obj) {
176             return true;
177         }
178         if (obj == null || getClass() != obj.getClass()) {
179             return false;
180         }
181 
182         UiccSlotInfo that = (UiccSlotInfo) obj;
183         return (mIsActive == that.mIsActive)
184                 && (mIsEuicc == that.mIsEuicc)
185                 && (Objects.equals(mCardId, that.mCardId))
186                 && (mCardStateInfo == that.mCardStateInfo)
187                 && (mLogicalSlotIdx == that.mLogicalSlotIdx)
188                 && (mIsExtendedApduSupported == that.mIsExtendedApduSupported)
189                 && (mIsRemovable == that.mIsRemovable);
190     }
191 
192     @Override
hashCode()193     public int hashCode() {
194         int result = 1;
195         result = 31 * result + (mIsActive ? 1 : 0);
196         result = 31 * result + (mIsEuicc ? 1 : 0);
197         result = 31 * result + Objects.hashCode(mCardId);
198         result = 31 * result + mCardStateInfo;
199         result = 31 * result + mLogicalSlotIdx;
200         result = 31 * result + (mIsExtendedApduSupported ? 1 : 0);
201         result = 31 * result + (mIsRemovable ? 1 : 0);
202         return result;
203     }
204 
205     @Override
toString()206     public String toString() {
207         return "UiccSlotInfo (mIsActive="
208                 + mIsActive
209                 + ", mIsEuicc="
210                 + mIsEuicc
211                 + ", mCardId="
212                 + mCardId
213                 + ", cardState="
214                 + mCardStateInfo
215                 + ", phoneId="
216                 + mLogicalSlotIdx
217                 + ", mIsExtendedApduSupported="
218                 + mIsExtendedApduSupported
219                 + ", mIsRemovable="
220                 + mIsRemovable
221                 + ")";
222     }
223 }
224