Android-4.2-3g migration path APN (5)

Source: Internet
Author: User

Android-4.2-3g migration path APN (5)

APN, this is not so easy to understand for people who are new to us. It is essential for 3G Internet transplantation. Record it here.

 

 

Concept:

The Access Point Name (APN) is the Access Point. A parameter that must be configured for a mobile device to Access the Internet using data traffic. This parameter indicates how to connect to the service center to enable the data traffic function.

Generally, there is access to WAP or connect to the Internet. The domestic carrier is 2G and the 3g id is as follows:

Mobile Company: 2G: GSM, 3G: TD-SCDMA
Unicom: 2G: GSM, 3G: WCDMA
China Telecom: 2G: CDMA, 3G: CDMA

For more information about the gnetwork APN of a carrier, see/Device/sample/etc/apns-full-conf.xml

This xml file contains many common APN preset by google.

 

 

Usage:Apns-full-conf.xml

The above said the apns-full-conf.xml configuration file, which is basically such a module:

 

  

Other options are network parameters, and the apn is our most important access point. You can also add the apn attribute module on your own.

 

 

You need to use this xml configuration file when porting 3G. Add PRODUCT_COPY_FILES in device. mk of android:

PRODUCT_COPY_FILES +=      device/sample/etc/apns-full-conf.xml:system/etc/apns-conf.xml

 

 

Telephony. db

For details about the file to be 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; // copy to the system/etc directory mentioned above... private static class DatabaseHelper extends SQLiteOpenHelper {// Context to access resources with private Context mContext;/*** DatabaseHelper helper class for loading apns into 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.exe cSQL (create table + CARRIERS_TABLE + // CREATE a TABLE (_ id integer primary key, + name TEXT, + numeric TEXT, + mcc TEXT, + mnc TEXT, + apn TEXT, + user TEXT, + server TEXT, + password TEXT, + proxy TEXT, + p Ort TEXT, + mmsproxy TEXT, + mmsport TEXT, + mmsc TEXT, + authtype INTEGER, + 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 way of saying ANDROID_ROOT or/system. file confFile = new File (Environment. getRootDire Ctory (), PARTNER_APNS_PATH); // load the parsing load to the 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. getAttributeValue (null, version); if (public Version! = Confversion) {throw new IllegalStateException (Internal APNS file version doesn' t match + confFile. getAbsolutePath ();} loadApns (db, confparser );}...}}


Because Content Provider uses the lazy loading mechanism, this db is created only when the SIM card is detected on the load:


You can use sqlite3 to view:

 

 

CreateAllApnList

 

In android, data traffic is measured by/frameworks/opt/telephony/src/java/com/android/internal/telephony/DataConnectionTracker. java

And its subclass GsmDataConnectionTracker. java (GSM mode) or CDMA dataconnectiontracker. java (CDMA mode). (The former is mobile, Unicom, and the latter is dedicated to telecom)

The Enable data traffic switch is onSetUserDataEnabled (boolean enabled ).

Here, in GSM mode, it is called when the SIM is loaded:

 

    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 createAllApnList

 

/*** Based on the sim operator numeric, create a list for all possible * Data Connections and setup the preferredApn. */private void createAllApnList () {mAllApns = new ArrayList (); 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 (// call createApnList Telephony. carriers. CONTENT_URI, null, selection, null, nu Ll); if (cursor! = Null) {if (cursor. getCount ()> 0) {mAllApns = createApnList (cursor); // you can follow up to query Telephony. carriers and returns an Apn list} cursor. close () ;}} if (mAllApns. isEmpty () {if (DBG) log (createAllApnList: No APN found for carrier: + operator); 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 ):

Indicates opening the data traffic and finally calling

 

Private boolean trySetupData (ApnContext apnContext ){... if (apnContext. getState () = DctConstants. state. IDLE) {ArrayList waitingApns = buildWaitingApns (apnContext. getApnType (); // use the preferred APN set by the user to construct an optional APN list for data connections, that is, the waitingApns list (if there is preferred APN, there is only one list ). // If the user has not set preferred APN, add all types of matching 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 there is an available apn in the waitingApns list, try to establish a connection to notifyOffApnsOfAvailability (apnContext. getReason (); return retValue ;...}

Several other functions for the apn operation are in this file. Their Respective functions are as follows:

 

OnApnChanged: When the APN is changed by the user, this function is called to re-establish a data connection.

 

SetPreferredApn: if you have not set preferred APN, set the APN that is successfully connected to the current data to preferred APN. You can view the onDataSetupComplete operation.

GetPreferredApn: the user obtains the preferred APN set by the user. This is obtained once in the createAllApnList mentioned above to see if it exists.

This preferredApn will be saved in xml format:

 

shell@android:/data/data/com.android.providers.telephony/shared_prefs # cat preferred-apn.xmlml                                                                            <
 

This indicates the apn map saved after data traffic is successfully opened. You can check it in telephony. db as shown above:

 

 

Sqlite> select * from carriers where _ id = '000000'; 1124 | China Unicom) | 46001 | 460 | 01 | 3gnet |-1 | default, supl | 1 | IP | 1 | 0

 

 

 


Here we only analyze the origin of apn and its usage at the framework layer, and finally send a request to RIL. cpp of hardware through a rild socket through setupDataCall of ril. java:

 

Public void setupDataCall (String radioTechnology, String profile, String apn,/* The above-passed 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); // socket in it}

 

Then, how can I get this socket event and send it to reference-ril to send this apn access network? refer to my previous blog:

Android-RIL mechanism source code analysis

Android -- reference-ril. pppd on the path of 4.2-3G transplantation (III)

 

 

 

 

 

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.