1 /* 2 * Copyright (C) 2006 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 17 package com.android.internal.telephony.uicc; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.telephony.SubscriptionInfo; 22 23 import com.android.internal.telephony.util.TelephonyUtils; 24 import com.android.telephony.Rlog; 25 26 /** 27 * See also RIL_CardStatus in include/telephony/ril.h 28 * 29 * {@hide} 30 */ 31 public class IccCardStatus { 32 public static final int CARD_MAX_APPS = 8; 33 34 public enum CardState { 35 @UnsupportedAppUsage 36 CARDSTATE_ABSENT, 37 @UnsupportedAppUsage 38 CARDSTATE_PRESENT, 39 @UnsupportedAppUsage 40 CARDSTATE_ERROR, 41 CARDSTATE_RESTRICTED; 42 43 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) isCardPresent()44 public boolean isCardPresent() { 45 return this == CARDSTATE_PRESENT || 46 this == CARDSTATE_RESTRICTED; 47 } 48 } 49 50 public enum PinState { 51 PINSTATE_UNKNOWN, 52 PINSTATE_ENABLED_NOT_VERIFIED, 53 PINSTATE_ENABLED_VERIFIED, 54 @UnsupportedAppUsage 55 PINSTATE_DISABLED, 56 @UnsupportedAppUsage 57 PINSTATE_ENABLED_BLOCKED, 58 @UnsupportedAppUsage 59 PINSTATE_ENABLED_PERM_BLOCKED; 60 isPermBlocked()61 boolean isPermBlocked() { 62 return this == PINSTATE_ENABLED_PERM_BLOCKED; 63 } 64 isPinRequired()65 boolean isPinRequired() { 66 return this == PINSTATE_ENABLED_NOT_VERIFIED; 67 } 68 isPukRequired()69 boolean isPukRequired() { 70 return this == PINSTATE_ENABLED_BLOCKED; 71 } 72 } 73 74 @UnsupportedAppUsage 75 public CardState mCardState; 76 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 77 public PinState mUniversalPinState; 78 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 79 public int mGsmUmtsSubscriptionAppIndex; 80 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 81 public int mCdmaSubscriptionAppIndex; 82 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 83 public int mImsSubscriptionAppIndex; 84 public String atr; 85 public String iccid; 86 public String eid; 87 88 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 89 public IccCardApplicationStatus[] mApplications; 90 91 public IccSlotPortMapping mSlotPortMapping; 92 setCardState(int state)93 public void setCardState(int state) { 94 switch(state) { 95 case 0: 96 mCardState = CardState.CARDSTATE_ABSENT; 97 break; 98 case 1: 99 mCardState = CardState.CARDSTATE_PRESENT; 100 break; 101 case 2: 102 mCardState = CardState.CARDSTATE_ERROR; 103 break; 104 case 3: 105 mCardState = CardState.CARDSTATE_RESTRICTED; 106 break; 107 default: 108 throw new RuntimeException("Unrecognized RIL_CardState: " + state); 109 } 110 } 111 setUniversalPinState(int state)112 public void setUniversalPinState(int state) { 113 switch(state) { 114 case 0: 115 mUniversalPinState = PinState.PINSTATE_UNKNOWN; 116 break; 117 case 1: 118 mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED; 119 break; 120 case 2: 121 mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED; 122 break; 123 case 3: 124 mUniversalPinState = PinState.PINSTATE_DISABLED; 125 break; 126 case 4: 127 mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED; 128 break; 129 case 5: 130 mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED; 131 break; 132 default: 133 throw new RuntimeException("Unrecognized RIL_PinState: " + state); 134 } 135 } 136 137 @Override toString()138 public String toString() { 139 IccCardApplicationStatus app; 140 141 StringBuilder sb = new StringBuilder(); 142 sb.append("IccCardState {").append(mCardState).append(",") 143 .append(mUniversalPinState); 144 if (mApplications != null) { 145 sb.append(",num_apps=").append(mApplications.length); 146 } else { 147 sb.append(",mApplications=null"); 148 } 149 150 sb.append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex); 151 if (mApplications != null 152 && mGsmUmtsSubscriptionAppIndex >= 0 153 && mGsmUmtsSubscriptionAppIndex < mApplications.length) { 154 app = mApplications[mGsmUmtsSubscriptionAppIndex]; 155 sb.append(app == null ? "null" : app); 156 } 157 158 sb.append(",cdma_id=").append(mCdmaSubscriptionAppIndex); 159 if (mApplications != null 160 && mCdmaSubscriptionAppIndex >= 0 161 && mCdmaSubscriptionAppIndex < mApplications.length) { 162 app = mApplications[mCdmaSubscriptionAppIndex]; 163 sb.append(app == null ? "null" : app); 164 } 165 166 sb.append(",ims_id=").append(mImsSubscriptionAppIndex); 167 if (mApplications != null 168 && mImsSubscriptionAppIndex >= 0 169 && mImsSubscriptionAppIndex < mApplications.length) { 170 app = mApplications[mImsSubscriptionAppIndex]; 171 sb.append(app == null ? "null" : app); 172 } 173 174 sb.append(",atr=").append(atr); 175 sb.append(",iccid=").append(SubscriptionInfo.givePrintableIccid(iccid)); 176 sb.append(",eid=").append(Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, eid)); 177 sb.append(",SlotPortMapping=").append(mSlotPortMapping); 178 179 sb.append("}"); 180 return sb.toString(); 181 } 182 183 } 184