android4.x information initialization process of SIM card _android

Source: Internet
Author: User

The example of this paper describes the process of the initialization of SIM card information in android4.x. Share to everyone for your reference, specific as follows:

During the Phone object initialization process, part of the SIM card's data information is loaded, which is stored in iccrecords and Adnrecordcache. The initialization of the data information of the SIM card is mainly divided into the following steps

1.RIL and Uicccontroller to establish a monitoring relationship, the SIM card status changes, Uicccontroller first to deal with.

Phone application to initialize the phone object will establish a RIL and Uicccontroller listening relationship: Uicccontroller monitoring RIL, the relevant code is as follows

Scommandsinterface = new RIL (context, Networkmode, cdmasubscription);   Uicccontroller.make (context, scommandsinterface);
Uicccontroller constructs the process
private Uicccontroller (context C, Commandsinterface ci) {
 if (DBG) log ("Creating Uicccontroller ");
 Mcontext = C;
 MCi = CI;
 Mci.registerforiccstatuschanged (this, event_icc_status_changed, null);
 TODO remove this once modem correctly notifies the Unsols
 Mci.registerforon (this, event_icc_status_changed, null);
}

As you can see from the code, the Uicccontroller object is registered as a listener for the RIL object, when RIL detects that the UICC card state has changed or radio on Uicccontroller handles the corresponding data changes. Uicccontroller is the first processor that has changed the status of a SIM card.

Uicccontroller processing event_icc_status_changed

public void Handlemessage (message msg) {
  synchronized (mlock) {
  switch (msg.what) {case
   Event_icc_status_ CHANGED:
   if (DBG) log ("Received event_icc_status_changed, calling Geticccardstatus");
   Mci.geticccardstatus (Obtainmessage (Event_get_icc_status_done));
   break;
   Case Event_get_icc_status_done:
   if (DBG) log ("Received event_get_icc_status_done");
   AsyncResult ar = (asyncresult) msg.obj;
   Ongeticccardstatusdone (AR);
   break;
   Default:
   rlog.e (Log_tag, "Unknown Event" + Msg.what);}}

From the code can be seen, RIL reported the change in the status of the SIM card, did two things, one is to obtain the specific status of the SIM card, the second is to deal with this state.

Uicccontroller Process specific SIM card status

Private synchronized void Ongeticccardstatusdone (asyncresult ar) {
  if (ar.exception!= null) {
  RLOG.E (Log_tag, " Error getting ICC status. "
   +" Ril_request_get_icc_status should "
   +" never return a Error ", ar.exception);
  return;
  }
  Icccardstatus status = (Icccardstatus) ar.result;
  if (Muicccard = = null) {
  //create new card
  Muicccard = new Uicccard (Mcontext, mCi, status);
  } else {
  / Update already existing card
  muicccard.update (Mcontext, mCi, status);
  }
  if (DBG) log ("notifying Iccchangedregistrants");
  Miccchangedregistrants.notifyregistrants ();
}

As you can see from the code, two things have been done,
One is to create or update Uicccard
The second is to notify the listener listening to the Uicccontroller.

2. Create or update uicccard,uicccard Create or update the uicccardapplication corresponding to the SIM card type.

A Uicccard object represents a SIM card that uicccard to create uicccardapplication,uicccardapplication to read the information in a specific SIM card based on the SIM information obtained.

Update Uicccard

public void Update (context C, Commandsinterface CI, icccardstatus ICS) {synchronized (Mlock) {if (mdestroyed) { Loge ("Updated after destroyed!
   Fix me! ");
  Return
  } cardstate oldstate = Mcardstate;
  Mcardstate = ics.mcardstate;
  Muniversalpinstate = ics.muniversalpinstate;
  Mgsmumtssubscriptionappindex = Ics.mgsmumtssubscriptionappindex;
  Mcdmasubscriptionappindex = Ics.mcdmasubscriptionappindex;
  Mimssubscriptionappindex = Ics.mimssubscriptionappindex;
  Mcontext = C;
  MCi = CI;
  Update applications if (DBG) log (ics.mApplications.length + "applications"); for (int i = 0; i < muiccapplications.length i++) {if (muiccapplications[i] = null) {//create newly added Ap Plications if (i < ics.mApplications.length) {Muiccapplications[i] = new Uicccardapplication (This, ics.map
   Plications[i], Mcontext, mCi);
   } else if (i >= ics.mApplications.length) {//delete removed applications muiccapplications[i].dispose (); MuiccaPplications[i] = null;
   else {//update the rest muiccapplications[i].update (Ics.mapplications[i], mcontext, mCi); } if (Muiccapplications.length > 0 && muiccapplications[0]!= null) {//Initialize or reinitialize Ca
  TService Mcatservice = catservice.getinstance (MCi, Mcontext, this);
   } else {if (Mcatservice!= null) {mcatservice.dispose ();
  } mcatservice = null;
  } sanitizeapplicationindexes ();
  Radiostate radiostate = Mci.getradiostate ();
  if (DBG) log ("update:radiostate=" + radiostate + "mlastradiostate=" + mlastradiostate); No notifications while radio are off or we just powering up if (radiostate = = radiostate.radio_on && Mlastradi Ostate = = radiostate.radio_on) {if (oldstate!= cardstate.cardstate_absent && mcardstate = = Cardstate.card
   State_absent) {if (DBG) log ("update:notify card removed");
   Mabsentregistrants.notifyregistrants (); Mhandler.sendmessage (Mhandler.obtainMessage (event_card_removed, null)); else if (oldstate = = cardstate.cardstate_absent && mcardstate!= cardstate.cardstate_absent) {if (DBG) L
   OG ("update:notify card added");
   Mhandler.sendmessage (Mhandler.obtainmessage (event_card_added, null));
  } mlastradiostate = Radiostate;

 }
}

Icccardstatus, records the information of the SIM card read by Ril, Uicccard create uicccardapplication based on the application information recorded in Icccardstatus.

Uicccard also created a catservice to read STK information.

Create or update uicccardapplication

Uicccardapplication, records the status of the card, the type, and the record information of the card.

Create Uicccardapplication uicccardapplication (Uicccard Uicccard, icccardapplicationstatus As, context C, Comma
  Ndsinterface ci) {if (DBG) log ("Creating Uiccapp:" + as);
  Muicccard = Uicccard;
  Mappstate = as.app_state;
  Mapptype = As.app_type;
  Mpersosubstate = as.perso_substate;
  MAid = As.aid;
  Mapplabel = As.app_label;
  mpin1replaced = (as.pin1_replaced!= 0);
  Mpin1state = as.pin1;
  Mpin2state = as.pin2;
  Mcontext = C;
  MCi = CI;
  MICCFH = Createiccfilehandler (As.app_type);
  Miccrecords = Createiccrecords (As.app_type, Mcontext, mCi); Read the EF file information on the SIM card if (mappstate = = Appstate.appstate_ready) {QUERYFDN ();//FDN information querypin1state ();//Pin Stat e}//update uicccardapplication void Update (Icccardapplicationstatus As, context C, Commandsinterface ci) {Synchron Ized (Mlock) {if (mdestroyed) {loge (application after updated
   Fix me! ");
  Return } if (DBG) log (mapptype + "Update").
  New "+ as);
  Mcontext = C; MCi = CI;
  Apptype oldapptype = Mapptype;
  Appstate oldappstate = mappstate;
  Persosubstate oldpersosubstate = mpersosubstate;
  Mapptype = As.app_type;
  Mappstate = as.app_state;
  Mpersosubstate = as.perso_substate;
  MAid = As.aid;
  Mapplabel = As.app_label;
  mpin1replaced = (as.pin1_replaced!= 0);
  Mpin1state = as.pin1;
  Mpin2state = as.pin2;
   if (Mapptype!= oldapptype) {if (MICCFH!= null) {Miccfh.dispose ();}
   if (miccrecords!= null) {Miccrecords.dispose ();}
   MICCFH = Createiccfilehandler (As.app_type);
  Miccrecords = Createiccrecords (As.app_type, C, CI); } if (mpersosubstate!= oldpersosubstate && mpersosubstate = = persosubstate.persosubstate_sim_network) {n
  otifynetworklockedregistrantsifneeded (NULL); } if (Mappstate!= oldappstate) {if (DBG) log (Oldapptype + "changed state:" + oldappstate + "->" + mappstate)
   ;
   If the app state turns to Appstate_ready, then query FDN status,//as it might have in failed earlier.if (mappstate = = Appstate.appstate_ready) {QUERYFDN ();//FDN information querypin1state ();
   } notifypinlockedregistrantsifneeded (NULL);
  notifyreadyregistrantsifneeded (NULL);

 }
  }
}

In the process of updating and creating uicccardapplication, there are several important variables

Iccrecords
Records the EF file information on the SIM card, implements the class to have the Simrecords,ruimrecords,isimuiccrecords, corresponds to the different type of SIM card.

Iccfilehandler
According to the type of SIM card, to read the information on the SIM card, the implementation class has Simfilehandler,ruimfilehandler,usimfilehandler,csimfilehandler,isimfilehandler, Corresponds to a different SIM card.

Creating Iccrecords Objects

As described earlier, Iccrecords records the EF file information of the SIM card, and the process of reading the SIM card's EF file information is implemented by Iccfilehandler, taking Simrecords as an example.

Public Simrecords (Uicccardapplication app, context C, Commandsinterface ci) {
  super (app, C, CI);
  1. The cache
  Madncache = new Adnrecordcache (mFh) of the telephone book;
  Mvmconfig = new Voicemailconstants ();
  Mspnoverride = new Spnoverride ();
  mrecordsrequested = false; No load request is made till SIM ready
  //Recordstoload are set to 0 because no requests are made yet
  Mrecordsto Load = 0;
  Mci.setonsmsonsim (this, event_sms_on_sim, null);
  Mci.registerforiccrefresh (this, event_sim_refresh, null);
  Start from setting empty state
  resetrecords ();
  2. Read all important record information of the SIM card
  mparentapp.registerforready (this, event_app_ready, null);
  if (DBG) log ("Simrecords X ctor this=" + this);
}

This process consists of two important steps

Create Adnrecordcache to hold the phone-book data and, depending on the EF ID, read the SIM card and the USIM card's phone data separately. Adnrecordcache holds a usimphonebookmanager, which is used to read the USIM card phone data. GSM SIM card and WCDMA Usim card are the corresponding simrecords.
Read all important record information for the SIM card and implement it in the Fetchsimrecords method.

protected void Fetchsimrecords () {mrecordsrequested = true;
  if (DBG) log ("Fetchsimrecords" + mrecordstoload);
  Mci.getimsiforapp (Mparentapp.getaid (), Obtainmessage (Event_get_imsi_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_iccid, Obtainmessage (Event_get_iccid_done));
  mrecordstoload++; Fixme should examine EF[MSISDN] ' s capability configuration//To determine which-the Voice/data/fax line new ADN
  Recordloader (mFh). LOADFROMEF (Ef_msisdn, Ef_ext1, 1, Obtainmessage (Event_get_msisdn_done));
  mrecordstoload++;
  Record number are subscriber profile mfh.loadeflinearfixed (Ef_mbi, 1, Obtainmessage (Event_get_mbi_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_ad, Obtainmessage (Event_get_ad_done));
  mrecordstoload++;
  Record number are subscriber profile mfh.loadeflinearfixed (Ef_mwis, 1, Obtainmessage (Event_get_mwis_done));
  mrecordstoload++; Also Load cphs-style voice mail indicator, which stores//the same info as Ef[mwis]. If both exIST, both are updated//But the Ef[mwis] data is preferred//Please note this must to loaded after Ef[mwis] Mfh.lo
  Adeftransparent (Ef_voice_mail_indicator_cphs, Obtainmessage (Event_get_voice_mail_indicator_cphs_done));
  mrecordstoload++;
  Same goes for call Forward Status Indicator:fetch both//Ef[cfis] and Cphs-ef, with Ef[cfis] preferred.
  Mfh.loadeflinearfixed (Ef_cfis, 1, Obtainmessage (Event_get_cfis_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_cff_cphs, Obtainmessage (Event_get_cff_done));
  mrecordstoload++;
  GETSPNFSM (true, null);
  Mfh.loadeftransparent (Ef_spdi, Obtainmessage (Event_get_spdi_done));
  mrecordstoload++;
  Mfh.loadeflinearfixed (EF_PNN, 1, Obtainmessage (Event_get_pnn_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_sst, Obtainmessage (Event_get_sst_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_info_cphs, Obtainmessage (Event_get_info_cphs_done));
  mrecordstoload++; Mfh.loadeftransparent (Ef_csp_cphs,obtainmessage (evenT_get_csp_cphs_done));
  mrecordstoload++;
  Mfh.loadeftransparent (Ef_gid1, Obtainmessage (Event_get_gid1_done));
  mrecordstoload++; XXX should seek instead of examining them all if (false) {//xxx Mfh.loadeflinearfixedall (ef_sms, Obtainmessage (EV
  Ent_get_all_sms_done));
  mrecordstoload++; } if (crash_ril) {String SMS = "0107912160130310f20404d0110041007030208054832b0120" + "ffffffffffffffffffffffffff Fffffffffffffffffffffffffffffffffffffffffff "+" Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff "+" Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff "+"
  Fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff "+" FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ";
  byte[] ba = iccutils.hexstringtobytes (SMS);
  Mfh.updateeflinearfixed (ef_sms, 1, BA, NULL, Obtainmessage (Event_mark_sms_read_done, 1));

 } if (DBG) log ("Fetchsimrecords" + Mrecordstoload + "requested:" + mrecordsrequested);}

In general, the process of creating simrecords is to read and save important information about the SIM card. The information in the phone book is kept in the Madncache and the other information is kept in the simrecords, but after the phone object is initialized, the Madncache is empty, that is, in the process of iccrecords initialization, Adnrecordcache did not take the initiative to request the SIM card contact's data.

All the iccrecords are sent to the modem by the Iccfilehandler command to read the data. The interaction diagram between them is as follows

3. Notify the Uicccontroller Listener, and uicccardapplication information can be updated. Based on the analysis of the source code, we can see that phonebase, Servicestatetracker,icccardproxy,dctrackerbase, these classes are uicccontroller listeners. They will deal with uicccontroller changes. We can understand that these classes are entities that have changed the status of the SIM card after the second batch processes the state of the SIM card. The first to handle SIM card state change is Uicccontroller.

I hope this article will help you with the Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.