Android 系统(165)---在apns-conf文件中配置一个read_only字段,使APN不可被编辑

在apns-conf文件中配置一个read_only字段,使APN不可被编辑

 

 

 如果有需要在apns-conf中配置一个新的read_only字段,并使其生效,比如使得APN不可被编辑。可以最如下的修改。

 

 一、使新添加的字段能成功的读取到telephony.db数据库中

 1、TelephonyProvider.java文件中的createCarriersTable方法中添加如下代码:
     EDITED + " INTEGER DEFAULT " + UNEDITED + "," +
 USER_VISIBLE + " BOOLEAN DEFAULT 1);";
修改为:
  EDITED + " INTEGER DEFAULT " + UNEDITED + "," +
       READ_ONLY + " BOOLEAN DEFAULT 0," +     //添加这一句
 USER_VISIBLE + " BOOLEAN DEFAULT 1);";

2、Telephony.java中添加如下一句:
   public static final String USER_VISIBLE = "user_visible";

 

@hide      //参照USER_VISIBLE ,不能忽略hide
public static final String READ_ONLY = "read_only";   //添加这句


3、在TelephonyProvider.java文件中的getRow()方法中添加如下代码
    addBoolAttribute(parser, "carrier_enabled", map, CARRIER_ENABLED);
    addBoolAttribute(parser, "modem_cognitive", map, MODEM_COGNITIVE);
  addBoolAttribute(parser, "user_visible", map, USER_VISIBLE);
++    addBoolAttribute(parser, "read_only", map, READ_ONLY);  //添加这一句

 

4、还请在TelephonyProvider.java文件中的onUpgrade方法中添加如下代码:

   if (oldVersion < (18 << 16 | 6)) {
     try {
  // Try to update the siminfo table. It might not be there.
  db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " +
  SubscriptionManager.SIM_PROVISIONING_STATUS + " INTEGER DEFAULT " +
  SubscriptionManager.SIM_PROVISIONED + ";");
  } catch (SQLiteException e) {
  if (DBG) {
 log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
 " The table will get created in onOpen.");
 }
 }
 oldVersion = 18 << 16 | 6;
 }
++if(oldVersion < (19 << 16 | 6)){
++ try {
++ db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
++ " ADD COLUMN read_only BOOLEAN DEFAULT 0;");
++ Log.d(TAG, "Update read_only column");
++ } catch (SQLException e) {
++ e.printStackTrace();
++ Log.e(TAG, "Add read_only column fail with table " + CARRIERS_TABLE + ".");
++ }
++ log("Add Read_only ");
++ oldVersion = 19 << 16 | 6;
++}

 

5、OTA升级时,upgrade 相应的DATABASE_VERSION。

 


二、从数据库中读取出对应字段,并判断
1、ApnSettings.java中添加如下静态常量
  private static final int SOURCE_TYPE_INDEX = 6;
++  private static final int READ_ONLY_INDEX = 7;

2、filllist()方法中修改查询条件
  Cursor cursor = getContentResolver().query(
  Telephony.Carriers.CONTENT_URI,
  new String[] { "_id", "name", "apn", "type", "mvno_type", "mvno_match_data",
  "sourcetype" }, where, null, order);
修改为:
Cursor cursor = getContentResolver().query(
Telephony.Carriers.CONTENT_URI,
new String[] { "_id", "name", "apn", "type", "mvno_type", "mvno_match_data",
"sourcetype", "read_only" }, where, null, order);

3、根据数据库中读取的值,修改APN能否被编辑的判断条件
414 /// M: for [Read Only APN]
415 pref.setApnEditable(mApnExt.isAllowEditPresetApn(type, apn, mccmnc, sourcetype));
修改为:
boolean isEdit = mApnExt.isAllowEditPresetApn(type, apn, mccmnc, sourcetype);   //true 表示允许编辑
boolean isReadOnly = cursor.getInt(READ_ONLY_INDEX) < 1;   //true表示允许编辑
pref.setApnEditable(isEdit && isReadOnly);

 

你可能感兴趣的:(android,data部分)