Android contact-read the email address of the USIM card

Source: Internet
Author: User

This article mainly describes the email address analysis instance on the USIM card, along with an example of a contact number. I have previously written an article about reading short messages and contact information on the SIM/USIM card, the Code call process is biased towards the specific parsing process. This article can be combined with the following links.

1. Android
-- SIM/USIM card Guide Contact

2. Android
Information (MMS) story (7)-SIM card text message 3. Concepts about SIM/USIM

Here we start usimphonebookmanager. java internal class pbrfile. java, the byte data read from the card is parsed here, the Code is not too much, the process is still clear, pbrfile. in Java constructor, parsetag is called, and parseef is called in parsetag. Let's take a look at the code and analyze it together. The following is the specific code,

[Java]
View plaincopy
  1. Private class pbrfile {
  2. Hashmap <integer, Map <integer, integer> mfileids;
  3. Pbrfile (arraylist <byte []> records ){
  4. Mfileids = new hashmap <integer, Map <integer, integer> ();
  5. Simtlv rectlv;
  6. Int recnum = 0;
  7. For (byte [] record: records ){
  8. Rectlv = new simtlv (record, 0, record. Length );
  9. Parsetag (rectlv, recnum );
  10. Recnum ++;
  11. }
  12. }
  13. Void parsetag (simtlv TLV, int recnum ){
  14. Simtlv tl.pdf;
  15. Int tag;
  16. Byte [] data;
  17. Map <integer, integer> val = new hashmap <integer, integer> ();
  18. Do {
  19. Tag = TLV. gettag ();
  20. Switch (TAG ){
  21. Case usim_type1_tag: // A8
  22. Case usim_type3_tag: // AA
  23. Case usim_type2_tag: // A9
  24. Data = TLV. getdata ();
  25. Tl.pdf = new simtlv (data, 0, Data. Length );
  26. Parseef (tl1_, Val, tag );
  27. Break;
  28. }
  29. } While (TLV. nextobject ());
  30. Mfileids. Put (recnum, Val );
  31. }
  32. Void parseef (simtlv TLV, Map <integer, integer> Val, int parenttag ){
  33. Int tag;
  34. Byte [] data;
  35. Int tagnumberwithinparenttag = 0;
  36. Do {
  37. Tag = TLV. gettag ();
  38. If (parenttag = usim_type2_tag & tag = usim_efemail_tag ){
  39. Memailpresentiniap = true;
  40. Memailtagnumberiniap = tagnumberwithinparenttag;
  41. }
  42. Switch (TAG ){
  43. Case usim_efemail_tag:
  44. Case usim_efadn_tag:
  45. Case usim_efext1_tag:
  46. Case usim_efanr_tag:
  47. Case usim_efpbc_tag:
  48. Case usim_efgrp_tag:
  49. Case usim_efaas_tag:
  50. Case usim_efgsd_tag:
  51. Case usim_efuid_tag:
  52. Case usim_efccp1_tag:
  53. Case usim_efiap_tag:
  54. Case usim_efsne_tag:
  55. Data = TLV. getdata ();
  56. Int efid = (data [0] & 0xff) <8) | (data [1] & 0xff );
  57. Val. Put (TAG, efid );
  58. Break;
  59. }
  60. Tagnumberwithinparenttag ++;
  61. } While (TLV. nextobject ());
  62. }

First, we can see that a new simtlv (simtlv name source, TLV: Tag Length Value in 3GPP 31.102) object is used to wrap the passed byte array, continue to look at the switch statement in the parsetag function. What does A8, A9, and AA mean? What is the relationship with reading arrays? Read, it is clear that these three tags are the basis for data parsing. The rules are as follows,
1: EF files in the USIM card file system are divided into three types: type1 files Whose tag is A8, type2 files Whose tag is A9, and type3 files Whose tag is aa.
2: efemail (email) only exists in type1 and type2: When efemail exists in type1, the record content maps to efadn, the main file of the phone book, that is, the N records in efadn correspond to the N records in the efemail file one by one. When efemail exists in type2 mode, the records in efadn and efemail are associated through the efiap file. Efiap is a type1 file, which corresponds to records in efadn one by one. efiap and type2 files must exist simultaneously in the file system. PS: there may be more than one efemail in the file system, and there may be multiple combinations of methods.
Next, several tags will appear in parseef. Here we will focus on usim_efemail_tag (CA), usim_efadn_tag (C0), and usim_efiap_tag (C1). Ca will identify the email id, c0 identifies the phone number ID. The role of C1 can be understood as an index, and then the CA is retrieved based on this index. The rules are similar. Let's look at some examples. Take the standard at Command (3GPP 27.007) as an Example

Read email:
1. Use the AT command at + crsm = 178,20272 (ef_pbr: 4f30) to record the subscript, to read the records of the efpbr file and obtain the file ID and short File id sfi of each file. Below are two real data records of the two USIM cards.
A8 ID
1e length (hexadecimal)
C0034f3a01c1034f3102c4034f5a0ac5034f4156c6034f5417c9034f6108
A9 ID
05 Length
Ca034f7109
Bytes
This section will not be marked again, as shown above. A8
28
Bytes
A9
05
Ca034f710c
Aa14
C2034f4a0dc7034f4b0ec8034f4c0fcb034f4f10

From the actual records, we can see that there is an identity Ca (email) under the identity A9, And the efemail File ID is 4f71. The C0 (efadn file) is available under the identifier A8, The efadn File ID is 4f3a, and the short File ID is 04. ID of the C1 (efiap file) file is 4f31. During reading, if the email is a type1 file, efemail maps to efadn one-to-one and writes the corresponding subscript. If the email is a type2 file:
1) Use the AT command to read the record subscript corresponding to the efemail file:
At + crsm = 178, efiap File ID, corresponding to record subscript in efadn file
Find the field value email_record_index of the order in the returned record.
2) use the AT command to read the record of the subject under email_record_index in the email file:
At + crsm = 178, efemail File ID, email_record_index

The following example is provided for the second type.
[Java]
View plaincopy

  1. ==>> [Send at cmd] [5] At + crsm = 178, (4f31) 20273,2, 3f007f105f3a,
  2. <= [Recv at cmd] [5] + crsm: 144,0, 01,
  3. ==>> [Send at cmd] [5] At + crsm = 178, (4f71) 20337,1, 3f007f105f3a,
  4. <= [Recv at cmd] [5] + crsm: 144,0, large,

The story is not over yet. We can see efadn in the above string. This guy instructs the phone number. Maybe we still need to look for the phone number here. The contact's number record is like this.[Java]
View plaincopy

  1. ==>> [Send at cmd] [5] At + crsm = 178,20282, 2000, 28, 3f007f105f3a, time = SAT Jan 1 08:06:39
  2. <= [Recv at cmd] [5] + crsm: 144,0, 804e09ffffffffffffffffffffffff048033333333ffffffffffffffff

80, 81 encoding format, followed by the ascending contact name 4e09: 3, Number: 3333333 (I believe you already know what 80, 81 represents ).
The content is almost the same, and the main things should be written out. The Guide card gives the individual the feeling that if they want to read the contact information on the full reading card (all the numbers and mailboxes) there are still a lot of things to consider. The process itself is not complicated, but the process is relatively complex. If you want to export the card for a short period of time, just export the main information (for example, ignore the additional number, find only one email address), which can be much faster. Some mobile phones do. However, this method is not technically appropriate, the trade-off between time and quality depends on the specific requirements of the project.
Finally, there are no examples of the type1 type emails. If you want to share it, you are also welcome to make a brick for the wrong part of the article.

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.