APN, this thing is not so good for people just contact, for 3G transplant Internet is necessary, here to record.
Writing is not easy, reproduced please specify the source: http://blog.csdn.net/jscese/article/details/41248939
Concept:
APN (access point Name), which is a parameter that the mobile device must configure to use data traffic on the Internet, represents the way to connect to the help desk to turn on the data traffic feature.
Generally have access to WAP or connect Internet, the domestic operator 2g,3g identified as follows:
Mobile Company: 2G:GSM, 3G:TD-SCDMA
Unicom Company: 2g:gsm, 3G:WCDMA
Telecom companies: 2G:CDMA, 3g:cdma2000
What is the APN for a specific carrier's few G networks specific to reference /device/sample/etc/apns-full-conf.xml
This XML file has Google's pre-built APN for many countries
use:Apns-full-conf.xml
It says Apns-full-conf.xml This configuration file, which is basically the module:
<APN carrier= "3G connected to the Internet (China Unicom)" mcc= "460" mnc= "" apn= "3gnet" type= "DEFAULT,SUPL" />
The other options are network parameters, where the APN is our most important access point. You can also add your own APN Properties module.
When porting 3G, you need to use this XML config file, add a product_copy_files to Android Device.mk:
Product_copy_files + = device/sample/etc/apns-full-conf.xml:system/etc/apns-conf.xml
Telephony.db
Where this file is loaded, refer to/packages/providers/telephonyprovider/src/com/android/providers/telephony/telephonyprovider.java:
private static final String database_name = "TELEPHONY.DB"; Database db file private static final String Partner_apns_path = "Etc/apns-conf.xml"; The copy mentioned above is in the system system/etc directory ... private static class Databasehelper extends Sqliteopenhelper {//context to ACCE SS Resources with private Context mcontext; /** * Databasehelper helper class for loading APNs to a database. * * @param context of the user. */Public Databasehelper (context context) {Super (context, database_name, NULL, getversion (context)); Mcontext = context; }... @Override public void OnCreate (sqlitedatabase db) { //Set up the Database schema db.execsql ("CREATE TABLE" + Carriers_table + //Build table "(_id INTEGER PRIMARY KEY," + " Name TEXT, "+ "Numeric TEXT," + "MCC TEXT," + "MNC TEXT," + "APN TEXT," + "User TEXT," + "Server TEXT, "+ "Password TEXT," + "proxy TEXT," + "Port TEXT," + "Mmsproxy TEXT," + "Mmsport TEXT," + "MMSc TEXT," + "AuthType INTEGER," + & nbsp; "type TEXT," + "Current INTEGER," + "Protocol TEXT," + "Roaming_protocol TEXT," + "carrier_enabled BOOLEAN," + "bearer INTEGER);"); initdatabase (db); private void Initdatabase (Sqlitedatabase db) {...//environment.getrootdirectory () is A fancy the saying aNdroid_root or "/system". File Conffile = new file (Environment.getrootdirectory (), Partner_apns_path); Here is the load parse load into db filereader confreader = null; try {confreader = new FileReader (conffile); Confparser = Xml.newpullparser (); Confparser.setinput (Confreader); Xmlutils.begindocument (Confparser, "APNs"); Sanity check. Force internal version and confidential versions to agree int confversion = Integer.parseint (confparser.get AttributeValue (NULL, "version")); if (publicversion! = confversion) {throw new IllegalStateException ("Internal APNS file version doesn ' t Match "+ Conffile.getabsolutepath ()); } Loadapns (db, Confparser); } ... }}
Because the content provider is lazy-loaded, the DB is created only when the SIM on the load is detected:
You can use Sqlite3 to view:
Createallapnlist
Data traffic in Android by/frameworks/opt/telephony/src/java/com/android/internal/telephony/dataconnectiontracker.java
and its subclass Gsmdataconnectiontracker.java (GSM mode) or Cdmadataconnectiontracker.java (CDMA mode), (the former is mobile, Unicom, the latter is dedicated to telecommunications)
To control where the start Data flow switch is onsetuserdataenabled (Boolean enabled).
Here in GSM mode, the SIM is called when it is load:
private void onrecordsloaded () { if (DBG) log ("Onrecordsloaded:createallapnlist"); Createallapnlist (); if (!muserdataenabled) Return;//jscese Add Judgement if (MPhone.mCM.getRadioState (). IsOn ()) { if (DBG) Log ("onrecordsloaded:notifying data Availability"); Notifyoffapnsofavailability (phone.reason_sim_loaded); } Setupdataonreadyapns (phone.reason_sim_loaded); }
Call into Createallapnlist
/** * Based on the SIM operator numeric, create a list for all possible * Data Connections and setup the Prefe RREDAPN. */private void Createallapnlist () {Mallapns = new arraylist<apnsetting> (); Iccrecords r = Miccrecords.get (); String operator = (r! = null)? R.getoperatornumeric (): ""; if (operator! = null) {String selection = "Numeric = '" + operator + "'"; Query only enabled APN. Carrier_enabled:1 means enabled APN, 0 disabled APN. Selection + = "and carrier_enabled = 1"; if (DBG) log ("createallapnlist:selection=" + selection); cursor cursor = Mphone.getcontext (). Getcontentresolver (). Query (//Use the operator of the current SIM card to inquire all the APN of the system, call down Createapnlist Telephony.Carriers.CONTENT_URI, NULL, selection, NULL, or NULL); if (cursor! = NULL) {if (Cursor.getcount () > 0) {Mallapns = createapnlist (cursor); //can follow up to see the query telephony.carriers and return an APN list} cursor.close (); }} if (Mallapns.isempty ()) {if (DBG) log ("Createallapnlist:no APN found for carrier:" + Opera TOR); MPREFERREDAPN = null; Todo:what is the right behaviour? Notifynodata (GsmDataConnection.FailCause.MISSING_UNKNOWN_APN); } else {mpreferredapn = GETPREFERREDAPN (); if (MPREFERREDAPN! = null &&!mpreferredapn.numeric.equals (operator)) {MPREFERREDAPN = null; SETPREFERREDAPN (-1); } if (DBG) log ("createallapnlist:mpreferredapn=" + mpreferredapn); } if (DBG) log ("Createallapnlist:x mallapns=" + Mallapns); }
Onsetuserdataenabled (True):
Represents open data traffic and eventually calls to
Private Boolean Trysetupdata (Apncontext apncontext) {... if (apncontext.getstate () = = DctConstants.State.IDLE) { arraylist<apnsetting> Waitingapns = Buildwaitingapns (Apncontext.getapntype ());//Use the user-set preferred APN to build a Alternate APN list for data connections, which is the Waitingapns list (there is only one list when there is a preferred APN). If the user does not have the preferred APN set, add all types of APN to the Waitingapns list (such as default type) if (Waitingapns.isempty ()) { if (DBG) log ("Trysetupdata:no APN found"); Notifynodata (GsmDataConnection.FailCause.MISSING_UNKNOWN_APN, Apncontext); Notifyoffapnsofavailability (Apncontext.getreason ()); return false; } else {Apncontext.setwaitingapns (Waitingapns); if (DBG) {log ("Trysetupdata:create from Mallapns:" + apnlisttostring (Mallapns)); }}} if (DBG) {log ("Setup Watingapns:" + APNlisttostring (Apncontext.getwaitingapns ())); }//Apncontext.setreason (Apncontext.getreason ()); Boolean retvalue = SetupData (Apncontext); When an APN is available in the Waitingapns list, try to establish a connection notifyoffapnsofavailability (Apncontext.getreason ()); Return RetValue, ...}
Several other functions for APN operations are in this file, the function of which is as follows:
Onapnchanged: When the APN is changed by the user, it is called to this function to reestablish the data connection
SETPREFERREDAPN: When the user does not have the preferred APN set, the APN with the current data connection success is set to preferred APN. can go to see Ondatasetupcomplete when the operation.
GETPREFERREDAPN: The user gets the user-set preferred APN, which in the above mentioned Createallapnlist will go to get once, see if there is.
For this preferredapn will be persisted in the form of XML:
[Email protected]:/data/data/com.android.providers.telephony/shared_prefs # cat preferred-apn.xmlml <<? XML version= ' 1.0 ' encoding= ' utf-8 ' standalone= ' yes '? ><map><long name= "apn_id" value= "1124"/></map >
This is the APN map that represents the success of opening data traffic, and you can go to the telephony.db and check it out as above:
Sqlite> SELECT * from carriers where _id= ' 1124 '; 1124| 3G Internet connection (China Unicom) |46001|460|01|3gnet| | | | | | | | | -1|default,supl|1| ip| Ip|1|0
This is just an analysis of the origin of the APN and the use of the framework layer, and ultimately through the Ril.java Setupdatacall through a rild socket to send the request to hardware ril.cpp:
public void Setupdatacall (string radiotechnology, String profile, String APN,/* apn*/ string User, String Password, string authtype, String protocol, Message result) { rilrequest rr = Rilrequest.obtain (ril_ Request_setup_data_call, result); Rr.mp.writeInt (7); Rr.mp.writeString (radiotechnology); Rr.mp.writeString (profile); Rr.mp.writeString (APN); rr.mp.writeString (user); rr.mp.writeString (password); Rr.mp.writeString (authtype); rr.mp.writeString (protocol); if (RILJ_LOGD) Riljlog (rr.serialstring () + ">" + requesttostring (rr.mrequest) + "+ radiotechnology +" " + profile + "+ APN +" "+ user +" "+ Password +" "+ AuthType +" "+ protocol); Send (RR); It's a socket inside. }
Then how to get to this socket event processing and give Reference-ril to send this APN Access gateway can refer to my previous blog:
Android--ril mechanism Source Analysis
The reference-ril of the android--4.2-3g transplant. PPPD Dial-up internet access (iii)
APN of the android--4.2-3g Transplant Route (v)