SIM card related operations in Android

Source: Internet
Author: User

Reprinted: http://topic.csdn.net/u/20110417/14/edcbbcd9-44f0-4175-a156-0231d12cba47.html

1. add, delete, and modify SIM card contacts
Uri is content: // ICC/ADN/
The specific usage is the same as that of other contentprovider operations. For the passed parameters, refer to \ base \ telephony \ Java \ com \ Android \ internal \ telephony \ iccprovider. java.

2. Questions about saving the contact to the USIM card
The essence of this problem is that the ef id of the common SIM card file is different from the ef id in the USIM card. The SIM card uses ef_adn = 0x6f3a, the efid of the stored contact in the usim card is ef_pbr = 0x4f30.

Modification method:
1. Check whether the USIM card is used in the updateadnrecordsinefbysearch function in \ base \ telephony \ Java \ com \ Android \ internal \ telephony \ iccphonebookinterfacemanager. java.
Add the following line
If (phone. getcontext (). checkcallingorselfpermission (
Android. manifest. Permission. write_contacts)
! = Packagemanager. permission_granted ){
Throw new securityexception (
"Requires Android. Permission. write_contacts permission ");
}
// Modified by Leon at 5/11/2010 change SIM card EF to USIM card EF if user use USIM card
Efid = updateefforicctype (efid );
// Modified end;

If (DBG) logd ("updateadnrecordsinefbysearch: efid =" + efid +
"(" + Oldtag + "," + oldphonenumber + ")" + "=>" +
"(" + Newtag + "," + newphonenumber + ")" + "pin2 =" + pin2 );

The implementation of updateefforicctype (efid) is:
Private int updateefforicctype (INT efid ){
// Check if we are trying to read ADN records
If (efid = iccconstants. ef_adn ){
If (phone. geticccard (). isapplicationonicc (icccardapplication. apptype. apptype_usim )){
Return iccconstants. ef_pbr;
}
}
Return efid;
}

In \ base \ telephony \ Java \ com \ Android \ internal \ telephony \ adnrecordcache. Java, the modified updateadnbysearch function is

Public void updateadnbysearch (INT efid, adnrecord oldadn, adnrecord newadn,
String pin2, message response ){

Int extensionef;
Extensionef = extensionefforef (efid );

If (extensionef <0 ){
Senderrorresponse (response, "EF is not known ADN-like EF:" + efid );
Return;
}

// Modified by Leon 5/11/2010
// If user use USIM card, the change the phonebook ef
Arraylist <adnrecord> oldadnlist = NULL;
If (efid = ef_pbr ){
Int usimef [] = musimphonebookmanager. getusimef ();
Int usimextensionef [] = musimphonebookmanager. getusimextensionef ();
Int size = usimef. length;
 
For (INT I = 0; I <size; I ++ ){
Oldadnlist = getrecordsifloaded (usimef [I]);
Efid = usimef [I];
Extensionef = usimextensionef [I];
Boolean bbreak = false;
If (oldadnlist! = NULL ){
For (iterator <adnrecord> it = oldadnlist. iterator (); it. hasnext ();){
If (oldadn. isequal (it. Next ())){
Bbreak = true;
Break;
}
}
}
If (bbreak)
Break;
}
} Else {
Oldadnlist = getrecordsifloaded (efid );
}
// Modified end

If (oldadnlist = NULL ){
Senderrorresponse (response, "ADN list not exist for EF:" + efid );
Return;
}

Int Index =-1;
Int COUNT = 1;
For (iterator <adnrecord> it = oldadnlist. iterator (); it. hasnext ();){
If (oldadn. isequal (it. Next ())){
Index = count;
Break;
}
Count ++;
}

If (Index =-1 ){
Senderrorresponse (response, "ADN record don't exist for" + oldadn );
Return;
}

Message pendingresponse = userwriteresponse. Get (efid );

If (pendingresponse! = NULL ){
Senderrorresponse (response, "have pending update for EF:" + efid );
Return;
}

Userwriteresponse. Put (efid, response );

New adnrecordloader (phone). updateef (newadn, efid, extensionef,
Index, pin2,
Obtainmessage (event_update_adn_done, efid, index, newadn ));
}

The getusimef and getusimextensionef functions are implemented as follows:
// Add by Leon at 5/11/2010

 
Public int [] getusimef (){
If (mpbrfile = NULL) return NULL;
Int numrecs = mpbrfile. mfileids. Size ();
Int [] result = new int [numrecs];
For (INT I = 0; I <numrecs; I ++ ){
Map <integer, integer> fileids;
Fileids = mpbrfile. mfileids. Get (I );
If (fileids = NULL | fileids. isempty ()){
Result [I] = 0;
} Else {
Result [I] = fileids. Get (usim_efadn_tag );
}
 
}
Return result;
}


 
Public int [] getusimextensionef (){
If (mpbrfile = NULL) return NULL;
Int numrecs = mpbrfile. mfileids. Size ();
Int [] result = new int [numrecs];
For (INT I = 0; I <numrecs; I ++ ){
Map <integer, integer> fileids;
Fileids = mpbrfile. mfileids. Get (I );
If (fileids = NULL | fileids. isempty ()){
Result [I] = 0;
} Else {
Result [I] = fileids. Get (usim_efext1_tag );
}
 
}
Return result;
}

 
Public void addusimadn (adnrecord ADN ){
Mphonebookrecords. Add (ADN );
}

// Add end

Here, an addusimadn function is called in the handlemessage function in this file. What it looks like is to write the USIM card while retaining a copy in the cache file.
Handlemessage (Message MSG ){
Asyncresult Ar;
Int efid;

Switch (msg. What)
Case event_update_adn_done:
AR = (asyncresult) msg. OBJ;
Efid = msg. arg1;
Int Index = msg. arg2;
Adnrecord ADN = (adnrecord) (AR. userobj );

If (AR. Exception = NULL ){
Adnlikefiles. Get (efid). Set (index-1, ADN );
// Add by Leon to update usimphonebookmanager, when export a contacts to USIM card.
If (efid! = Iccconstants. ef_adn ){
Musimphonebookmanager. addusimadn (ADN );
}
// Add end
}

These changes should store contacts in the USIM card.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.