APN of the android--4.2-3g Transplant Route (v)

Source: Internet
Author: User

APN, this thing is not so well understood by people who are just touching. For 3G transplant Internet is indispensable, here is a 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 the AP, a parameter that a mobile device must configure to use data traffic to surf the Internet, representing how the data traffic function is connected to the service desk.

Generally have access to WAP or connect Internet, the domestic operator 2G,3G logo such as the following:

Mobile Company: 2G:GSM, 3G:TD-SCDMA
Unicom Company: 2g:gsm, 3G:WCDMA
Telecom companies: 2G:CDMA, 3g:cdma2000

Details of what APN is detailed for a few G networks of a carrier /device/sample/etc/apns-full-conf.xml

This XML file has a Google-provisioned APN that is frequently used by many countries



use:Apns-full-conf.xml

It says Apns-full-conf.xml This configuration file, which is basically this module:

  <APN carrier= "3G connected to the Internet (China Unicom)"      mcc= "460"      mnc= ""      apn= "3gnet"      type=  "DEFAULT,SUPL" />

The other options are network parameters, in which the APN is our most important access point. You can also add your own APN attribute module.


This XML configuration file is required for porting 3G. 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, you can 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 under the System System/etc folder ... private static class Databasehelper extends Sqliteopenhelper {//context to ACC        ESS 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 sayingAndroid_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 uses lazy loading mechanisms, it is only created when the SIM card is detected on load:


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, in which 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 APN for the system.            Call down Createapnlist Telephony.Carriers.CONTENT_URI, NULL, selection, NULL, or NULL); if (cursor! = NULL) {if (Cursor.getcount () > 0) {Mallapns = createapnlist (cursor);  //Be able to 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. Finally called 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 An alternative APN list for data connections, the Waitingapns list (only one if there is a preferred APN).

If the user does not have the preferred APN set, the all type-matching APN is added to the Waitingapns list (such as the 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 (A Pncontext.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 functions of the distinction are for example the following:

Onapnchanged: When the APN is changed by the user, it is called to this function, and once again the data connection is established


SETPREFERREDAPN: When the user does not have the preferred APN set, the APN with the current data connection success is set to preferred APN.

Be able to see the ondatasetupcomplete when the operation.


GETPREFERREDAPN: The user gets the user-set preferred APN, which is obtained once in the createallapnlist mentioned above. See if it exists.

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 saved after the successful opening of data traffic. To look inside the telephony.db like above to check it out:

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




Here is just an analysis of the origin of the APN and the use of the framework layer, and finally 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 Code 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)

Related 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.