Android APN加载流程 【转】

一、关于APN

1、Android的APN(Access Point Name)数据预置在/system/etc/apns-conf.xml中:

2、源码:apns-conf.xml来自apns-full-conf.xml,编译系统的时候Copy到/system/etc/目录下:

  1. PRODUCT_COPY_FILES +=

  2. device/sample/etc/apns-full-conf.xml:system/etc/apns-conf.xml


二、APN加载过程

1、系统检查到SIM卡正常后从/system/etc/apns-conf.xml解析数据,存放到数据库:telephony.db

  1. /data/data/com.android.providers.telephony/databases/telephony.db

  2.  
  3. sqlite> select * from carriers where numeric='46001';

  4. 1113|China Unicom 3G|46001|460|01|3gnet|||||80||||-1|default,supl|1|IP|IP|1|0||

  5. 1114|中国联通 3g 彩信 (China Unicom)|46001|460|01|3gwap||||||10.0.0.172|80|http://mmsc.myuni.com.cn|-1|mms|1|IP|IP|1|0||

  6. 1115|China Unicom MMS|46001|460|01|uniwap||||||10.0.0.172|80|

telephony.db数据库的建立对应TelephonyProvider.java文件:

 

 
  1. packages\providers\telephonyprovider\src\com\android\providers\telephony\TelephonyProvider.java

  2. public class TelephonyProvider extends ContentProvider{

  3. private static final String DATABASE_NAME = "telephony.db";

  4. private static class DatabaseHelper extends SQLiteOpenHelper {

  5. public DatabaseHelper(Context context) {

  6. super(context, DATABASE_NAME, null, getVersion(context));

  7. mContext = context;

  8. }

  9.  
  10. @Override

  11. public void onCreate(SQLiteDatabase db) {

  12. // Set up the database schema

  13. db.execSQL("CREATE TABLE " + CARRIERS_TABLE +

  14. "(_id INTEGER PRIMARY KEY," +

  15. "name TEXT," +

  16. "numeric TEXT," +

  17. "mcc TEXT," +

  18. "mnc TEXT," +

  19. "apn TEXT," +

  20. "user TEXT," +

  21. "server TEXT," +

  22. "password TEXT," +

  23. "proxy TEXT," +

  24. "port TEXT," +

  25. "mmsproxy TEXT," +

  26. "mmsport TEXT," +

  27. "mmsc TEXT," +

  28. "authtype INTEGER," +

  29. "type TEXT," +

  30. "current INTEGER," +

  31. "protocol TEXT," +

  32. "roaming_protocol TEXT," +

  33. "carrier_enabled BOOLEAN," +

  34. "bearer INTEGER," +

  35. "mvno_type TEXT," +

  36. "mvno_match_data TEXT);");

  37.  
  38. initDatabase(db);

  39. }

  40.  
  41. private void initDatabase(SQLiteDatabase db) {

  42. // Read internal APNS data

  43. // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".

  44. File confFile = new File(Environment.getRootDirectory(), PARTNER_APNS_PATH);

  45. loadApns(db, confparser);

  46. }

  47. }

  48. }


2、检索APN,根据MCC、MNC的值组合(46001)来查询telephony.db数据库:

http://www.gpsspg.com/bs/mnc.htm

 

  1. frameworks\opt\telephony\src\java\com\android\internal\telephony\dataconnection\DcTracker.java

  2. /**

  3. * Based on the sim operator numeric, create a list for all possible

  4. * Data Connections and setup the preferredApn.

  5. */

  6. private void createAllApnList() {

  7. mAllApnSettings = new ArrayList<ApnSetting>();

  8. IccRecords r = mIccRecords.get();

  9. // getOperatorNumeric()返回MCC+MNC的组合值

  10. String operator = (r != null) ? r.getOperatorNumeric() : "";

  11. if (operator != null) {

  12. String selection = "numeric = '" + operator + "'";

  13. // query only enabled apn.

  14. // carrier_enabled : 1 means enabled apn, 0 disabled apn.

  15. selection += " and carrier_enabled = 1";

  16. if (DBG) log("createAllApnList: selection=" + selection);

  17.  
  18. Cursor cursor = mPhone.getContext().getContentResolver().query(

  19. Telephony.Carriers.CONTENT_URI, null, selection, null, null);

  20.  
  21. if (cursor != null) {

  22. Rlog.e(LOG_TAG, "cursor != null");

  23. Rlog.e(LOG_TAG, "cursor.getCount(): " + cursor.getCount());

  24. if (cursor.getCount() > 0) {

  25. mAllApnSettings = createApnList(cursor);

  26. }

  27. cursor.close();

  28. }

  29. }

  30. }

这样,在Setting界面就可以看到设备的APN信息;若APN缺少,4G、3G等移动网络异常!

转自: https://blog.csdn.net/u013686019/article/details/51283594

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值