1. Introduction of problems
In the android source code, make and make sdks are successfully executed and finally burned to the Development Board! Unfortunately, you cannot access the Internet by inserting a SIM card. You must manually set the APN before you can access the Internet. However, some "cainiao-level" users cannot access the Internet, so we need our developers to provide convenience for them! How can I ensure that the APN is automatically set after the SIM card is inserted? At this time, you only need to gently correspond to the APN of the specified SIM card!
2. Problem Analysis
2-1. apn process analysis and related documents
First, configure the environment variables in ~ /Add to the bashrc File
Export ANDROID_SRC_HOME =/mnt/yqmiao/android_2.1
The relevant documents are described as follows:
Main. mk -- $ ANDROID_SRC_HOME/build/core/main. mk
-- The xml file related to the apn settings can be seen from the [core Makefile file] of this file.
The excerpt is as follows:
# Install an apns-conf.xml file if one's not already being installed.
Ifeq (, $ (filter %: system/etc/apns-conf.xml, $ (PRODUCT_COPY_FILES )))
PRODUCT_COPY_FILES + = \
Development/data/etc/apns-conf_sdk.xml: system/etc/apns-conf.xml
Ifeq ($ (filter eng tests, $ (TARGET_BUILD_VARIANT )),)
$ (Warning implicitly installing apns-conf_sdk.xml)
Endif
Endif
Apns-conf_sdk.xml -- $ ANDROID_SRC_HOME/development/data/etc/apns-conf_sdk.xml
-- Mainly used to generate the system/etc/apns-conf.xml file, the generation process is essentially the original copy
Apns. xml -- $ ANDROID_SRC_HOME/frameworks/base/core/res/xml/apns. xml
-- This file has no practical significance in the configuration of the apn, but it is very important in the logic of the android apn settings, especially the version value in it.
Apns-conf.xml -- $ ANDROID_SRC_HOME/out/target/product/generic/system/etc/apns-conf.xml
-- The content is finally packaged into system. img:
View results:
1) run the simulator
Root @ ubuntuorg: $ ANDROID_SRC_HOME/out/target/product/generic #.. /.. /.. /host/linux-x86/bin/emulator-system. img-data userdata. img-ramdisk. img
2) Enter terminate
Adb shell
Cat/system/etc/apns-conf.xml
Note: This file is from here !!
TelephonyProvider. java -- $ ANDROID_SRC_HOME/packages/providers/TelephonyProvider/src/com/android/providers/telephony/TelephonyProvider. java
-- This class is mainly used for APN settings. Because the source code does not meet the customization requirements, you must manually modify it!
However, the ultimate goal of the modification is to ensure that the database table content of the APN can be updated and maintained in a timely manner after the database version is updated!
The following describes how to modify this class!
First, ensure that Emulator or the Development Board is successfully run and view the data maintained by the APN. The operations are as follows:
# Adb shell
# Cd/data/com. android. providers. telephony/databases
# Sqlite3 telephony. db
Sqlite>. dump carriers
2-2. Specific modification implementation
***********
Add new apn settings
Eg:
<Apn carrier = "China Unicom"
Apn = "3 gnet"
Proxy = ""
Port = ""
User = ""
Password = ""
Server = ""
Mmsc = ""
Mcc = "460"
Mnc = "01"
Mmsproxy = ""
Mmsport = ""
Type = ""
/>
Some of these attributes cannot be removed even if they are null strings.
Modify the version value to ensure that it is greater than the original value:
<Apns version = "7">
...
</Apns>
* ************* Modify the apns. xml file ******************
Modify the version value to make sure it is greater than the original value and must be the same as the version value set in the previous step.
Eg:
<Apns version = "7">
...
</Apns>
You need to modify the version value for each next change to the APN.
* ************ Modify the TelephonyProvider. java file *******
Purpose of modification, as mentioned above!
Eg1:
@ Override
Public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion ){
If (oldVersion <newVersion)
{
Final int count = db. delete (CARRIERS_TABLE, null, null );
InitDatabase (db );
}
}
Eg2:
@ Override
Public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion ){
If (oldVersion <newVersion ){
Db. beginTransaction ();
Db.exe cSQL ("drop table if exists" + CARRIERS_TABLE + ";");
Db.exe cSQL ("create table if not exists" + CARRIERS_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," +
"Type TEXT," +
"Current INTEGER );");
Db. endTransaction ();
InitDatabase (db );
}
}
After testing, eg2 may be better!
2-3. Compile make
Root @ ubuntu-org:/mnt/yqmiao/android_2.1 # ../build/envsetup. sh
Root @ ubuntu-org:/mnt/yqmiao/android_2.1 # make
If no configuration is configured after make is complete, the configuration is as follows:
Eg:
1) In ~ /. Add the following to the bashrc file:
Export ANDROID_SRC_HOME =/mnt/yqmiao/android_2.1
Export PATH = $ PATH: $ ANDROID_SRC_HOME/out/host/linux-x86/bin
ExportANDROID_PRODUCT_OUT = $ ANDROID_SRC_HOME/out/target/product/generic
2) Save and exit:
Source ~ /. Bashrc
3) then run Emulator.
Emulator
3. Result Verification
1)
After the simulator is successfully started, go to the carriers table in the telephony. db database to view it!
2)
After inserting a SIM card into the Development Board, go to the APN settings page to view
4. Conclusion Analysis
1) The android source code does not support the automatic configuration of APN for localized [different countries and service providers.
2) Some forums mention how to configure the APN, but do not mention modifying the version value or modifying the java source.
Code, just simply add a new apn in the apns-conf_sdk.xml file, so it always fails and ends, the reason is TelephonyProvider. the java file cannot ensure that the new APN is added to telephony. in db, the essence is determined by the lifecycle of ContentProvider. onCreate is only executed at the first runtime and will not be executed in the future. Then, onUpdate is required to update the database table, in this case, you need to modify the database version.
3) readers are expected to make the changes smoothly !!
From Miao yunqi's blog