Skip to content

Commit fe37aca

Browse files
Alex YakavenkaAndroid (Google) Code Review
authored andcommitted
Telephony: Dynamically instantiate IccCard
Change-Id: I8c4d800158fb1eb12de66d437cb0d76695ff98d3
1 parent df1423e commit fe37aca

21 files changed

+635
-274
lines changed

telephony/java/com/android/internal/telephony/DataConnectionTracker.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import com.android.internal.R;
4848
import com.android.internal.telephony.DataConnection.FailCause;
49+
import com.android.internal.telephony.uicc.UiccController;
4950
import com.android.internal.util.AsyncChannel;
5051
import com.android.internal.util.Protocol;
5152

@@ -57,6 +58,7 @@
5758
import java.util.Set;
5859
import java.util.concurrent.ConcurrentHashMap;
5960
import java.util.concurrent.atomic.AtomicInteger;
61+
import java.util.concurrent.atomic.AtomicReference;
6062

6163
/**
6264
* {@hide}
@@ -138,6 +140,7 @@ public enum Activity {
138140
public static final int EVENT_CLEAN_UP_ALL_CONNECTIONS = BASE + 30;
139141
public static final int CMD_SET_DEPENDENCY_MET = BASE + 31;
140142
public static final int CMD_SET_POLICY_DATA_ENABLE = BASE + 32;
143+
protected static final int EVENT_ICC_CHANGED = BASE + 33;
141144

142145
/***** Constants *****/
143146

@@ -250,6 +253,8 @@ public enum Activity {
250253

251254
// member variables
252255
protected PhoneBase mPhone;
256+
protected UiccController mUiccController;
257+
protected AtomicReference<IccRecords> mIccRecords = new AtomicReference<IccRecords>();
253258
protected Activity mActivity = Activity.NONE;
254259
protected State mState = State.IDLE;
255260
protected Handler mDataConnectionTracker = null;
@@ -500,6 +505,8 @@ protected void onActionIntentDataStallAlarm(Intent intent) {
500505
protected DataConnectionTracker(PhoneBase phone) {
501506
super();
502507
mPhone = phone;
508+
mUiccController = UiccController.getInstance();
509+
mUiccController.registerForIccChanged(this, EVENT_ICC_CHANGED, null);
503510

504511
IntentFilter filter = new IntentFilter();
505512
filter.addAction(getActionIntentReconnectAlarm());
@@ -541,6 +548,7 @@ public void dispose() {
541548
mIsDisposed = true;
542549
mPhone.getContext().unregisterReceiver(this.mIntentReceiver);
543550
mDataRoamingSettingObserver.unregister(mPhone.getContext());
551+
mUiccController.unregisterForIccChanged(this);
544552
}
545553

546554
protected void broadcastMessenger() {
@@ -663,6 +671,7 @@ private void handleDataOnRoamingChange() {
663671
protected abstract void onCleanUpConnection(boolean tearDown, int apnId, String reason);
664672
protected abstract void onCleanUpAllConnections(String cause);
665673
protected abstract boolean isDataPossible(String apnType);
674+
protected abstract void onUpdateIcc();
666675

667676
protected void onDataStallAlarm(int tag) {
668677
loge("onDataStallAlarm: not impleted tag=" + tag);
@@ -773,6 +782,10 @@ public void handleMessage(Message msg) {
773782
onSetPolicyDataEnabled(enabled);
774783
break;
775784
}
785+
case EVENT_ICC_CHANGED:
786+
onUpdateIcc();
787+
break;
788+
776789
default:
777790
Log.e("DATA", "Unidentified event msg=" + msg);
778791
break;

telephony/java/com/android/internal/telephony/IccCard.java

Lines changed: 55 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535

3636
import com.android.internal.telephony.PhoneBase;
3737
import com.android.internal.telephony.CommandsInterface.RadioState;
38+
import com.android.internal.telephony.gsm.GSMPhone;
3839
import com.android.internal.telephony.gsm.SIMFileHandler;
3940
import com.android.internal.telephony.gsm.SIMRecords;
4041
import com.android.internal.telephony.cat.CatService;
4142
import com.android.internal.telephony.cdma.CDMALTEPhone;
43+
import com.android.internal.telephony.cdma.CDMAPhone;
4244
import com.android.internal.telephony.cdma.CdmaLteUiccFileHandler;
4345
import com.android.internal.telephony.cdma.CdmaLteUiccRecords;
4446
import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
@@ -114,8 +116,6 @@ public class IccCard {
114116
protected static final int EVENT_ICC_LOCKED = 1;
115117
private static final int EVENT_GET_ICC_STATUS_DONE = 2;
116118
protected static final int EVENT_RADIO_OFF_OR_NOT_AVAILABLE = 3;
117-
private static final int EVENT_PINPUK_DONE = 4;
118-
private static final int EVENT_REPOLL_STATUS_DONE = 5;
119119
protected static final int EVENT_ICC_READY = 6;
120120
private static final int EVENT_QUERY_FACILITY_LOCK_DONE = 7;
121121
private static final int EVENT_CHANGE_FACILITY_LOCK_DONE = 8;
@@ -178,34 +178,19 @@ public State getState() {
178178
return State.UNKNOWN;
179179
}
180180

181-
public IccCard(PhoneBase phone, String logTag, Boolean is3gpp, Boolean dbg) {
181+
public IccCard(PhoneBase phone, IccCardStatus ics, String logTag, boolean dbg) {
182182
mLogTag = logTag;
183183
mDbg = dbg;
184-
if (mDbg) log("[IccCard] Creating card type " + (is3gpp ? "3gpp" : "3gpp2"));
185-
mPhone = phone;
186-
this.is3gpp = is3gpp;
184+
if (mDbg) log("Creating");
185+
update(phone, ics);
187186
mCdmaSSM = CdmaSubscriptionSourceManager.getInstance(mPhone.getContext(),
188187
mPhone.mCM, mHandler, EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED, null);
189-
if (phone.mCM.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE
190-
&& phone instanceof CDMALTEPhone) {
191-
mIccFileHandler = new CdmaLteUiccFileHandler(this, "", mPhone.mCM);
192-
mIccRecords = new CdmaLteUiccRecords(this, mPhone.mContext, mPhone.mCM);
193-
} else {
194-
// Correct aid will be set later (when GET_SIM_STATUS returns)
195-
mIccFileHandler = is3gpp ? new SIMFileHandler(this, "", mPhone.mCM) :
196-
new RuimFileHandler(this, "", mPhone.mCM);
197-
mIccRecords = is3gpp ? new SIMRecords(this, mPhone.mContext, mPhone.mCM) :
198-
new RuimRecords(this, mPhone.mContext, mPhone.mCM);
199-
}
200-
mCatService = CatService.getInstance(mPhone.mCM, mIccRecords,
201-
mPhone.mContext, mIccFileHandler, this);
202188
mPhone.mCM.registerForOffOrNotAvailable(mHandler, EVENT_RADIO_OFF_OR_NOT_AVAILABLE, null);
203189
mPhone.mCM.registerForOn(mHandler, EVENT_RADIO_ON, null);
204-
mPhone.mCM.registerForIccStatusChanged(mHandler, EVENT_ICC_STATUS_CHANGED, null);
205190
}
206191

207192
public void dispose() {
208-
if (mDbg) log("[IccCard] Disposing card type " + (is3gpp ? "3gpp" : "3gpp2"));
193+
if (mDbg) log("Disposing card type " + (is3gpp ? "3gpp" : "3gpp2"));
209194
mPhone.mCM.unregisterForIccStatusChanged(mHandler);
210195
mPhone.mCM.unregisterForOffOrNotAvailable(mHandler);
211196
mPhone.mCM.unregisterForOn(mHandler);
@@ -215,6 +200,40 @@ public void dispose() {
215200
mIccFileHandler.dispose();
216201
}
217202

203+
public void update(PhoneBase phone, IccCardStatus ics) {
204+
if (phone != mPhone) {
205+
PhoneBase oldPhone = mPhone;
206+
mPhone = phone;
207+
log("Update");
208+
if (phone instanceof GSMPhone) {
209+
is3gpp = true;
210+
} else if (phone instanceof CDMALTEPhone){
211+
is3gpp = true;
212+
} else if (phone instanceof CDMAPhone){
213+
is3gpp = false;
214+
} else {
215+
throw new RuntimeException("Update: Unhandled phone type. Critical error!" +
216+
phone.getPhoneName());
217+
}
218+
219+
220+
if (phone.mCM.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE
221+
&& phone instanceof CDMALTEPhone) {
222+
mIccFileHandler = new CdmaLteUiccFileHandler(this, "", mPhone.mCM);
223+
mIccRecords = new CdmaLteUiccRecords(this, mPhone.mContext, mPhone.mCM);
224+
} else {
225+
// Correct aid will be set later (when GET_SIM_STATUS returns)
226+
mIccFileHandler = is3gpp ? new SIMFileHandler(this, "", mPhone.mCM) :
227+
new RuimFileHandler(this, "", mPhone.mCM);
228+
mIccRecords = is3gpp ? new SIMRecords(this, mPhone.mContext, mPhone.mCM) :
229+
new RuimRecords(this, mPhone.mContext, mPhone.mCM);
230+
}
231+
mCatService = CatService.getInstance(mPhone.mCM, mIccRecords, mPhone.mContext,
232+
mIccFileHandler, this);
233+
}
234+
mHandler.sendMessage(mHandler.obtainMessage(EVENT_GET_ICC_STATUS_DONE, ics));
235+
}
236+
218237
protected void finalize() {
219238
if (mDbg) log("[IccCard] Finalized card type " + (is3gpp ? "3gpp" : "3gpp2"));
220239
}
@@ -344,27 +363,23 @@ public void unregisterForRuimReady(Handler h) {
344363
*/
345364

346365
public void supplyPin (String pin, Message onComplete) {
347-
mPhone.mCM.supplyIccPin(pin, mHandler.obtainMessage(EVENT_PINPUK_DONE, onComplete));
366+
mPhone.mCM.supplyIccPin(pin, onComplete);
348367
}
349368

350369
public void supplyPuk (String puk, String newPin, Message onComplete) {
351-
mPhone.mCM.supplyIccPuk(puk, newPin,
352-
mHandler.obtainMessage(EVENT_PINPUK_DONE, onComplete));
370+
mPhone.mCM.supplyIccPuk(puk, newPin, onComplete);
353371
}
354372

355373
public void supplyPin2 (String pin2, Message onComplete) {
356-
mPhone.mCM.supplyIccPin2(pin2,
357-
mHandler.obtainMessage(EVENT_PINPUK_DONE, onComplete));
374+
mPhone.mCM.supplyIccPin2(pin2, onComplete);
358375
}
359376

360377
public void supplyPuk2 (String puk2, String newPin2, Message onComplete) {
361-
mPhone.mCM.supplyIccPuk2(puk2, newPin2,
362-
mHandler.obtainMessage(EVENT_PINPUK_DONE, onComplete));
378+
mPhone.mCM.supplyIccPuk2(puk2, newPin2, onComplete);
363379
}
364380

365381
public void supplyNetworkDepersonalization (String pin, Message onComplete) {
366-
mPhone.mCM.supplyNetworkDepersonalization(pin,
367-
mHandler.obtainMessage(EVENT_PINPUK_DONE, onComplete));
382+
mPhone.mCM.supplyNetworkDepersonalization(pin, onComplete);
368383
}
369384

370385
/**
@@ -494,21 +509,15 @@ public void changeIccFdnPassword(String oldPassword, String newPassword,
494509
*
495510
*/
496511
public String getServiceProviderName () {
497-
return mPhone.mIccRecords.getServiceProviderName();
512+
return mIccRecords.getServiceProviderName();
498513
}
499514

500515
protected void updateStateProperty() {
501516
mPhone.setSystemProperty(TelephonyProperties.PROPERTY_SIM_STATE, getState().toString());
502517
}
503518

504-
private void getIccCardStatusDone(AsyncResult ar) {
505-
if (ar.exception != null) {
506-
Log.e(mLogTag,"Error getting ICC status. "
507-
+ "RIL_REQUEST_GET_ICC_STATUS should "
508-
+ "never return an error", ar.exception);
509-
return;
510-
}
511-
handleIccCardStatus((IccCardStatus) ar.result);
519+
private void getIccCardStatusDone(IccCardStatus ics) {
520+
handleIccCardStatus(ics);
512521
}
513522

514523
private void handleIccCardStatus(IccCardStatus newCardStatus) {
@@ -584,6 +593,7 @@ private void handleIccCardStatus(IccCardStatus newCardStatus) {
584593
if (oldState != State.READY && newState == State.READY &&
585594
(is3gpp || isSubscriptionFromIccCard)) {
586595
mIccFileHandler.setAid(getAid());
596+
broadcastIccStateChangedIntent(INTENT_VALUE_ICC_READY, null);
587597
mIccRecords.onReady();
588598
}
589599
}
@@ -704,7 +714,6 @@ public void handleMessage(Message msg){
704714
if (!is3gpp) {
705715
handleCdmaSubscriptionSource();
706716
}
707-
mPhone.mCM.getIccCardStatus(obtainMessage(EVENT_GET_ICC_STATUS_DONE));
708717
break;
709718
case EVENT_CDMA_SUBSCRIPTION_SOURCE_CHANGED:
710719
handleCdmaSubscriptionSource();
@@ -725,30 +734,9 @@ public void handleMessage(Message msg){
725734
obtainMessage(EVENT_QUERY_FACILITY_LOCK_DONE));
726735
break;
727736
case EVENT_GET_ICC_STATUS_DONE:
728-
ar = (AsyncResult)msg.obj;
729-
730-
getIccCardStatusDone(ar);
731-
break;
732-
case EVENT_PINPUK_DONE:
733-
// a PIN/PUK/PIN2/PUK2/Network Personalization
734-
// request has completed. ar.userObj is the response Message
735-
// Repoll before returning
736-
ar = (AsyncResult)msg.obj;
737-
// TODO should abstract these exceptions
738-
AsyncResult.forMessage(((Message)ar.userObj)).exception
739-
= ar.exception;
740-
mPhone.mCM.getIccCardStatus(
741-
obtainMessage(EVENT_REPOLL_STATUS_DONE, ar.userObj));
742-
break;
743-
case EVENT_REPOLL_STATUS_DONE:
744-
// Finished repolling status after PIN operation
745-
// ar.userObj is the response messaeg
746-
// ar.userObj.obj is already an AsyncResult with an
747-
// appropriate exception filled in if applicable
737+
IccCardStatus cs = (IccCardStatus)msg.obj;
748738

749-
ar = (AsyncResult)msg.obj;
750-
getIccCardStatusDone(ar);
751-
((Message)ar.userObj).sendToTarget();
739+
getIccCardStatusDone(cs);
752740
break;
753741
case EVENT_QUERY_FACILITY_LOCK_DONE:
754742
ar = (AsyncResult)msg.obj;
@@ -797,10 +785,6 @@ public void handleMessage(Message msg){
797785
= ar.exception;
798786
((Message)ar.userObj).sendToTarget();
799787
break;
800-
case EVENT_ICC_STATUS_CHANGED:
801-
Log.d(mLogTag, "Received Event EVENT_ICC_STATUS_CHANGED");
802-
mPhone.mCM.getIccCardStatus(obtainMessage(EVENT_GET_ICC_STATUS_DONE));
803-
break;
804788
case EVENT_CARD_REMOVED:
805789
onIccSwap(false);
806790
break;
@@ -967,6 +951,10 @@ private void log(String msg) {
967951
Log.d(mLogTag, "[IccCard] " + msg);
968952
}
969953

954+
private void loge(String msg) {
955+
Log.e(mLogTag, "[IccCard] " + msg);
956+
}
957+
970958
protected int getCurrentApplicationIndex() {
971959
if (is3gpp) {
972960
return mIccCardStatus.getGsmUmtsSubscriptionAppIndex();

telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ private void notifyPending(AsyncResult ar) {
103103

104104
public IccPhoneBookInterfaceManager(PhoneBase phone) {
105105
this.phone = phone;
106+
IccRecords r = phone.mIccRecords.get();
107+
if (r != null) {
108+
adnCache = r.getAdnCache();
109+
}
106110
}
107111

108112
public void dispose() {
109113
}
110114

115+
public void updateIccRecords(IccRecords iccRecords) {
116+
if (iccRecords != null) {
117+
adnCache = iccRecords.getAdnCache();
118+
} else {
119+
adnCache = null;
120+
}
121+
}
122+
111123
protected void publish() {
112124
//NOTE service "simphonebook" added by IccSmsInterfaceManagerProxy
113125
ServiceManager.addService("simphonebook", this);

telephony/java/com/android/internal/telephony/IccRecords.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
import com.android.internal.telephony.gsm.UsimServiceTable;
2727
import com.android.internal.telephony.ims.IsimRecords;
2828

29+
import java.util.concurrent.atomic.AtomicBoolean;
30+
2931
/**
3032
* {@hide}
3133
*/
3234
public abstract class IccRecords extends Handler implements IccConstants {
3335

3436
protected static final boolean DBG = true;
3537
// ***** Instance Variables
36-
protected boolean mDestroyed = false; // set to true once this object needs to be disposed of
38+
protected AtomicBoolean mDestroyed = new AtomicBoolean(false);
3739
protected Context mContext;
3840
protected CommandsInterface mCi;
3941
protected IccFileHandler mFh;
@@ -79,9 +81,9 @@ public abstract class IccRecords extends Handler implements IccConstants {
7981

8082
// ***** Event Constants
8183
protected static final int EVENT_SET_MSISDN_DONE = 30;
82-
public static final int EVENT_MWI = 0;
83-
public static final int EVENT_CFI = 1;
84-
public static final int EVENT_SPN = 2;
84+
public static final int EVENT_MWI = 0; // Message Waiting indication
85+
public static final int EVENT_CFI = 1; // Call Forwarding indication
86+
public static final int EVENT_SPN = 2; // Service Provider Name
8587

8688
public static final int EVENT_GET_ICC_RECORD_DONE = 100;
8789

@@ -113,7 +115,7 @@ public IccRecords(IccCard card, Context c, CommandsInterface ci) {
113115
* Call when the IccRecords object is no longer going to be used.
114116
*/
115117
public void dispose() {
116-
mDestroyed = true;
118+
mDestroyed.set(true);
117119
mParentCard = null;
118120
mFh = null;
119121
mCi = null;
@@ -128,12 +130,8 @@ public AdnRecordCache getAdnCache() {
128130
return adnCache;
129131
}
130132

131-
public IccCard getIccCard() {
132-
return mParentCard;
133-
}
134-
135133
public void registerForRecordsLoaded(Handler h, int what, Object obj) {
136-
if (mDestroyed) {
134+
if (mDestroyed.get()) {
137135
return;
138136
}
139137

0 commit comments

Comments
 (0)