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