Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 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 | |
Jordan Liu | 2891151 | 2019-02-27 14:44:20 -0800 | [diff] [blame] | 18 | import android.annotation.NonNull; |
| 19 | import android.annotation.Nullable; |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
| 26 | * The UiccCardInfo represents information about a currently inserted UICC or embedded eUICC. |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 27 | */ |
Jordan Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 28 | public final class UiccCardInfo implements Parcelable { |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 29 | |
| 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 Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 35 | private final boolean mIsRemovable; |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 36 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 37 | public static final @android.annotation.NonNull Creator<UiccCardInfo> CREATOR = new Creator<UiccCardInfo>() { |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 38 | @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 Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 55 | mIsRemovable = in.readByte() != 0; |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 56 | } |
| 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 Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 65 | dest.writeByte((byte) (mIsRemovable ? 1 : 0)); |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int describeContents() { |
| 70 | return 0; |
| 71 | } |
| 72 | |
Jordan Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 73 | /** |
| 74 | * @hide |
| 75 | */ |
| 76 | public UiccCardInfo(boolean isEuicc, int cardId, String eid, String iccId, int slotIndex, |
| 77 | boolean isRemovable) { |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 78 | this.mIsEuicc = isEuicc; |
| 79 | this.mCardId = cardId; |
| 80 | this.mEid = eid; |
| 81 | this.mIccId = iccId; |
| 82 | this.mSlotIndex = slotIndex; |
Jordan Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 83 | this.mIsRemovable = isRemovable; |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
Jordan Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 87 | * Return whether the UICC is an eUICC. |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 88 | * @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 Liu | 5867df3 | 2019-04-22 15:16:10 -0700 | [diff] [blame] | 104 | * (see {@link #isEuicc()}), or the EID is not available, returns null. |
Jordan Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 105 | * <p> |
| 106 | * Note that this field may be omitted if the caller does not have the correct permissions |
| 107 | * (see {@link TelephonyManager#getUiccCardsInfo()}). |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 108 | */ |
Jordan Liu | 2891151 | 2019-02-27 14:44:20 -0800 | [diff] [blame] | 109 | @Nullable |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 110 | public String getEid() { |
| 111 | if (!mIsEuicc) { |
| 112 | return null; |
| 113 | } |
| 114 | return mEid; |
| 115 | } |
| 116 | |
| 117 | /** |
Jordan Liu | 5867df3 | 2019-04-22 15:16:10 -0700 | [diff] [blame] | 118 | * Get the ICCID of the UICC. If the ICCID is not availble, returns null. |
Jordan Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 119 | * <p> |
| 120 | * Note that this field may be omitted if the caller does not have the correct permissions |
| 121 | * (see {@link TelephonyManager#getUiccCardsInfo()}). |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 122 | */ |
Jordan Liu | 2891151 | 2019-02-27 14:44:20 -0800 | [diff] [blame] | 123 | @Nullable |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 124 | 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 Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 135 | /** |
Jordan Liu | 2891151 | 2019-02-27 14:44:20 -0800 | [diff] [blame] | 136 | * 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 Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 138 | * |
| 139 | * @hide |
| 140 | */ |
Jordan Liu | 2891151 | 2019-02-27 14:44:20 -0800 | [diff] [blame] | 141 | @NonNull |
Jordan Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 142 | public UiccCardInfo getUnprivileged() { |
Jordan Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 143 | 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 Liu | d6c684f | 2019-01-18 10:29:56 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 156 | @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 Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 170 | && (mSlotIndex == that.mSlotIndex) |
| 171 | && (mIsRemovable == that.mIsRemovable)); |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public int hashCode() { |
Jordan Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 176 | return Objects.hash(mIsEuicc, mCardId, mEid, mIccId, mSlotIndex, mIsRemovable); |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 177 | } |
| 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 Liu | 0fe6845 | 2019-01-18 16:43:53 -0800 | [diff] [blame] | 191 | + ", mIsRemovable=" |
| 192 | + mIsRemovable |
Jordan Liu | 11374f4 | 2018-12-18 15:42:38 -0800 | [diff] [blame] | 193 | + ")"; |
| 194 | } |
| 195 | } |