blob: b438920362ff3b067fbdcb9bae4046bd844366df [file] [log] [blame]
Jordan Liu11374f42018-12-18 15:42:38 -08001/*
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 */
16package android.telephony;
17
Jordan Liu28911512019-02-27 14:44:20 -080018import android.annotation.NonNull;
19import android.annotation.Nullable;
Jordan Liu11374f42018-12-18 15:42:38 -080020import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Objects;
24
25/**
26 * The UiccCardInfo represents information about a currently inserted UICC or embedded eUICC.
Jordan Liu11374f42018-12-18 15:42:38 -080027 */
Jordan Liud6c684f2019-01-18 10:29:56 -080028public final class UiccCardInfo implements Parcelable {
Jordan Liu11374f42018-12-18 15:42:38 -080029
30 private final boolean mIsEuicc;
31 private final int mCardId;
32 private final String mEid;
33 private final String mIccId;
34 private final int mSlotIndex;
Jordan Liu0fe68452019-01-18 16:43:53 -080035 private final boolean mIsRemovable;
Jordan Liu11374f42018-12-18 15:42:38 -080036
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070037 public static final @android.annotation.NonNull Creator<UiccCardInfo> CREATOR = new Creator<UiccCardInfo>() {
Jordan Liu11374f42018-12-18 15:42:38 -080038 @Override
39 public UiccCardInfo createFromParcel(Parcel in) {
40 return new UiccCardInfo(in);
41 }
42
43 @Override
44 public UiccCardInfo[] newArray(int size) {
45 return new UiccCardInfo[size];
46 }
47 };
48
49 private UiccCardInfo(Parcel in) {
50 mIsEuicc = in.readByte() != 0;
51 mCardId = in.readInt();
52 mEid = in.readString();
53 mIccId = in.readString();
54 mSlotIndex = in.readInt();
Jordan Liu0fe68452019-01-18 16:43:53 -080055 mIsRemovable = in.readByte() != 0;
Jordan Liu11374f42018-12-18 15:42:38 -080056 }
57
58 @Override
59 public void writeToParcel(Parcel dest, int flags) {
60 dest.writeByte((byte) (mIsEuicc ? 1 : 0));
61 dest.writeInt(mCardId);
62 dest.writeString(mEid);
63 dest.writeString(mIccId);
64 dest.writeInt(mSlotIndex);
Jordan Liu0fe68452019-01-18 16:43:53 -080065 dest.writeByte((byte) (mIsRemovable ? 1 : 0));
Jordan Liu11374f42018-12-18 15:42:38 -080066 }
67
68 @Override
69 public int describeContents() {
70 return 0;
71 }
72
Jordan Liu0fe68452019-01-18 16:43:53 -080073 /**
74 * @hide
75 */
76 public UiccCardInfo(boolean isEuicc, int cardId, String eid, String iccId, int slotIndex,
77 boolean isRemovable) {
Jordan Liu11374f42018-12-18 15:42:38 -080078 this.mIsEuicc = isEuicc;
79 this.mCardId = cardId;
80 this.mEid = eid;
81 this.mIccId = iccId;
82 this.mSlotIndex = slotIndex;
Jordan Liu0fe68452019-01-18 16:43:53 -080083 this.mIsRemovable = isRemovable;
Jordan Liu11374f42018-12-18 15:42:38 -080084 }
85
86 /**
Jordan Liu0fe68452019-01-18 16:43:53 -080087 * Return whether the UICC is an eUICC.
Jordan Liu11374f42018-12-18 15:42:38 -080088 * @return true if the UICC is an eUICC.
89 */
90 public boolean isEuicc() {
91 return mIsEuicc;
92 }
93
94 /**
95 * Get the card ID of the UICC. See {@link TelephonyManager#getCardIdForDefaultEuicc()} for more
96 * details on card ID.
97 */
98 public int getCardId() {
99 return mCardId;
100 }
101
102 /**
103 * Get the embedded ID (EID) of the eUICC. If the UiccCardInfo is not an eUICC
Jordan Liu5867df32019-04-22 15:16:10 -0700104 * (see {@link #isEuicc()}), or the EID is not available, returns null.
Jordan Liud6c684f2019-01-18 10:29:56 -0800105 * <p>
106 * Note that this field may be omitted if the caller does not have the correct permissions
107 * (see {@link TelephonyManager#getUiccCardsInfo()}).
Jordan Liu11374f42018-12-18 15:42:38 -0800108 */
Jordan Liu28911512019-02-27 14:44:20 -0800109 @Nullable
Jordan Liu11374f42018-12-18 15:42:38 -0800110 public String getEid() {
111 if (!mIsEuicc) {
112 return null;
113 }
114 return mEid;
115 }
116
117 /**
Jordan Liu5867df32019-04-22 15:16:10 -0700118 * Get the ICCID of the UICC. If the ICCID is not availble, returns null.
Jordan Liud6c684f2019-01-18 10:29:56 -0800119 * <p>
120 * Note that this field may be omitted if the caller does not have the correct permissions
121 * (see {@link TelephonyManager#getUiccCardsInfo()}).
Jordan Liu11374f42018-12-18 15:42:38 -0800122 */
Jordan Liu28911512019-02-27 14:44:20 -0800123 @Nullable
Jordan Liu11374f42018-12-18 15:42:38 -0800124 public String getIccId() {
125 return mIccId;
126 }
127
128 /**
129 * Gets the slot index for the slot that the UICC is currently inserted in.
130 */
131 public int getSlotIndex() {
132 return mSlotIndex;
133 }
134
Jordan Liud6c684f2019-01-18 10:29:56 -0800135 /**
Jordan Liu28911512019-02-27 14:44:20 -0800136 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
137 * generally private and require carrier privileges to view.
Jordan Liud6c684f2019-01-18 10:29:56 -0800138 *
139 * @hide
140 */
Jordan Liu28911512019-02-27 14:44:20 -0800141 @NonNull
Jordan Liud6c684f2019-01-18 10:29:56 -0800142 public UiccCardInfo getUnprivileged() {
Jordan Liu0fe68452019-01-18 16:43:53 -0800143 return new UiccCardInfo(mIsEuicc, mCardId, null, null, mSlotIndex, mIsRemovable);
144 }
145
146 /**
147 * Return whether the UICC or eUICC is removable.
148 * <p>
149 * UICCs are generally removable, but eUICCs may be removable or built in to the device.
150 * @return true if the UICC or eUICC is removable
151 */
152 public boolean isRemovable() {
153 return mIsRemovable;
Jordan Liud6c684f2019-01-18 10:29:56 -0800154 }
155
Jordan Liu11374f42018-12-18 15:42:38 -0800156 @Override
157 public boolean equals(Object obj) {
158 if (this == obj) {
159 return true;
160 }
161 if (obj == null || getClass() != obj.getClass()) {
162 return false;
163 }
164
165 UiccCardInfo that = (UiccCardInfo) obj;
166 return ((mIsEuicc == that.mIsEuicc)
167 && (mCardId == that.mCardId)
168 && (Objects.equals(mEid, that.mEid))
169 && (Objects.equals(mIccId, that.mIccId))
Jordan Liu0fe68452019-01-18 16:43:53 -0800170 && (mSlotIndex == that.mSlotIndex)
171 && (mIsRemovable == that.mIsRemovable));
Jordan Liu11374f42018-12-18 15:42:38 -0800172 }
173
174 @Override
175 public int hashCode() {
Jordan Liu0fe68452019-01-18 16:43:53 -0800176 return Objects.hash(mIsEuicc, mCardId, mEid, mIccId, mSlotIndex, mIsRemovable);
Jordan Liu11374f42018-12-18 15:42:38 -0800177 }
178
179 @Override
180 public String toString() {
181 return "UiccCardInfo (mIsEuicc="
182 + mIsEuicc
183 + ", mCardId="
184 + mCardId
185 + ", mEid="
186 + mEid
187 + ", mIccId="
188 + mIccId
189 + ", mSlotIndex="
190 + mSlotIndex
Jordan Liu0fe68452019-01-18 16:43:53 -0800191 + ", mIsRemovable="
192 + mIsRemovable
Jordan Liu11374f42018-12-18 15:42:38 -0800193 + ")";
194 }
195}