Android-SIM/USIM card Guide Contact

Source: Internet
Author: User

From: http://blog.csdn.net/baimy1985/article/details/7820024

 

 

There is a previous article about the information on the card (Android information (MMS) (7)-SIM card text message). There is also a very important information on the SIM card, that is, the contacts on the card. I don't know if you have noticed that Android phones, especially those with carrier IDs, are slow to boot. This is irrelevant to the contacts and information on the boot guide card, the operator requires that the card be redirected when the device is started. However, in public speaking, the slow boot may be related to the card, but it cannot be totally attributed to the card. (Android phones also load a lot of things when the device is started ), of course, there must be another reason if your mobile phone is too slow to boot without a card.

Of course, the android source code does not guide the card when it is started. If we need to view the contacts on the card, we need to manually import them, and apply contactslistactivity from the contact. in the menu of the Java class, find import and export, and select the import SIM card contact to enter simcontactsselectactivity. java class, in which the query () method is executed, and the corresponding provider and Uri are iccprovider. java and Uri. parse (content: // ICC/ADN), enter iccprovider. the code after Java is a part of attention in this article, starting from the query () method

 

[Java]View plaincopy

  1. Public cursor query (uri url, string [] projection, string selection,
  2. String [] selectionargs, string sort ){
  3. Arraylist <arraylist> results;
  4. Switch (url_matcher.match (URL )){
  5. Case ADN:
  6. Results = loadfromef (iccconstants. ef_adn );
  7. Break;

 

We are concerned about this loadfromef () method. The value of iccconstants. ef_and is 6f3a, which tells us to first find the content at this position on the card.

 

[Java]View plaincopy

  1. Private arraylist <arraylist> loadfromef (INT eftype ){
  2. Arraylist <arraylist> Results = new arraylist <arraylist> ();
  3. List <adnrecord> adnrecords = NULL;
  4. Try {
  5. Iiccphonebook iccipb = iiccphonebook. stub. asinterface (// binder comes servicemanager. getservice ("simphonebook "));
  6. If (iccipb! = NULL ){
  7. Adnrecords = iccipb. getadnrecordsinef (eftype); // proxy Mode
  8. }
  9. }... Omitting the secondary code .... }

 

Next, the code goes to the getadnrecordsinef (intefid) method of the iccphonebookinterfacemanager. Java class, which involves the proxy mode. iccphonebookinterfacemanagerproxy. Java performs a conversion in the middle. In the getadnrecordsinef (intefid) method, call updateefforicctype (efid) to determine whether it is a SIM card or a USIM card, and then determine whether the efid below uses iccconstants. ef_and or iccconstants. ef_pbr: the true query is requestloadalladnlike (). Pay attention to the event_load_done mark and use it to receive query results.

[Java]View plaincopy

  1. Requestloadalladnlike (INT efid, int extensionef, message response ){
  2. Arraylist <message> waiters;
  3. Arraylist <adnrecord> result;
  4. If (efid = ef_pbr) {// USIM card, here let's look at this method
  5. Result = musimphonebookmanager. loadeffilesfromusim ();
  6. } Else {// SIM card
  7. Result = getrecordsifloaded (efid );
  8. }.

 

Let's take a look at the loadeffilesfromusim () method and read it cyclically until all files are read and then returned. There are two types in it: one is the contact of the phone number and the other is the contact of the email address, mailbox is more troublesome than phone number.

[Java]View plaincopy

  1. Public arraylist <adnrecord> loadeffilesfromusim (){
  2. Synchronized (mlock ){
  3. //... Omitting the secondary code ....
  4. Numrecs = mpbrfile. mfileids. Size ();
  5. For (INT I = 0; I <numrecs; I ++ ){
  6. Readadnfileandwait (I );
  7. Reademailfileandwait (I );
  8. } // All EF files are loaded, post the response.
  9. }

 

Readadnfileandwait (I) and reademailfileandwait (I) call the mphone. geticcfilehandler (). loadeflinearfixedall () method at the end, but the specific parameters are different. Check the loadeflinearfixedall () code.

[Java]View plaincopy

  1. Public void loadeflinearfixedall (INT fileid, message onloaded ){
  2. Message response = obtainmessage (event_get_record_size_done,
  3. New loadlinearfixedcontext (fileid, onloaded ));
  4. Phone. mcm. iccio (command_get_response, fileid, getefpath (fileid ),
  5. 0, 0, get_response_ef_size_bytes, null, null, response );
  6. }

The iccio () method shows that the Code ran to RIL. java. The information code on the reading card also came here.

[Java]View plaincopy

  1. Public void iccio (INT command, int fileid, string path, int P1, int P2, int P3,
  2. String data, string pin2, message result ){
  3. Rilrequest RR = rilrequest. Obtain (ril_request_sim_io, result); // follow this tag flag
  4. Rr. MP. writeint (command );
  5. Rr. MP. writeint (fileid );
  6. Rr. MP. writestring (PATH );
  7. Rr. MP. writeint (P1 );
  8. Rr. MP. writeint (P2 );
  9. Rr. MP. writeint (P3 );
  10. Rr. MP. writestring (data );
  11. Rr. MP. writestring (pin2 );
  12. Send (RR );
  13. }
  14. According to the tag above, you can find this branch in the Reference-ril.c.
  15. Case ril_request_sim_io:
  16. Requestsim_io (data, datalen, t );
  17. Break;

Read the requestsim_io () method to see how the android Source Code reads contacts from the SIM card. The source code uses the at + crsm command. For the AT command, see the 3GPP 27.007 document. When the read is complete, you will receive the event_pbr_load_done message. In the createpbrfile () method, you can parse the string to obtain the contact information.

 

[Java]View plaincopy

  1. Public void handlemessage (Message MSG ){
  2. ... Omitting code ....
  3. Switch (msg. What ){
  4. Case event_pbr_load_done:
  5. If (AR. Exception = NULL ){
  6. Createpbrfile (arraylist <byte []>) Ar. Result );
  7. }... Omitting code ....
  8. Break;

 

At this point, most of the processes for importing card contacts are completed, and some other operations for writing to the contact database are relatively simple, so the overall process is clear, but there are many cycles, remote debugging is not very convenient. Generally, a SIM card can store 250 contacts, and a USIM card can store more contacts, but the number is not fixed, the email address of the read/write contact is troublesome. Because of the bucket restrictions, you need to find the corresponding index multiple times to find what we want. For specific examples of reading and writing card contacts, add them separately. The last figure shows the truth.

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.