3535
3636import com .android .internal .telephony .PhoneBase ;
3737import com .android .internal .telephony .CommandsInterface .RadioState ;
38+ import com .android .internal .telephony .gsm .GSMPhone ;
3839import com .android .internal .telephony .gsm .SIMFileHandler ;
3940import com .android .internal .telephony .gsm .SIMRecords ;
4041import com .android .internal .telephony .cat .CatService ;
4142import com .android .internal .telephony .cdma .CDMALTEPhone ;
43+ import com .android .internal .telephony .cdma .CDMAPhone ;
4244import com .android .internal .telephony .cdma .CdmaLteUiccFileHandler ;
4345import com .android .internal .telephony .cdma .CdmaLteUiccRecords ;
4446import 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 ();
0 commit comments