Android手机通过fota升级后,apn数据库不会重新load的问题解决
问题描述
android手机通过fota升级,从A版本升级到B版本。在此过程中,修改了客户提供的apn参数,/system/etc/apns-conf.xml文件。但是手机通过fota升级后,发现手机apns数据库并没有重新load。必需要将fota升级后的手机恢复出厂设置才可以。
解决方案
为了避免恢复出厂设置的过程。可以修改apns数据库的版本号,通过
onUpgrade 来重新load数据库
public class TelephonyProvider extends ContentProvider
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (DBG) {
log("dbh.onUpgrade:+ db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
}
TelephonyManager telePhonyManager = TelephonyManager.from(mContext);
int numPhones = telePhonyManager.getPhoneCount();
/*SUN:jicong.wang remove for apns update start {@
for (int i = 0; i < numPhones; i++) {
if(i ==0){
db.execSQL("ALTER TABLE " + CARRIERS_TABLE + i +
" RENAME TO " + CARRIERS_TABLE + ";");
}else{
db.execSQL("DROP TABLE " + CARRIERS_TABLE + i + ";");
}
}SUN:jicong.wang remove for apns update end @}*/
if (oldVersion < (5 << 16 | 6)) {
// 5 << 16 is the Database version and 6 in the xml version.
// This change adds a new authtype column to the database.
// The auth type column can have 4 values: 0 (None), 1 (PAP), 2 (CHAP)
// 3 (PAP or CHAP). To avoid breaking compatibility, with already working
// APNs, the unset value (-1) will be used. If the value is -1.
// the authentication will default to 0 (if no user / password) is specified
// or to 3. Currently, there have been no reported problems with
// pre-configured APNs and hence it is set to -1 for them. Similarly,
// if the user, has added a new APN, we set the authentication type
// to -1.
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN authtype INTEGER DEFAULT -1;");
oldVersion = 5 << 16 | 6;
}
if (oldVersion < (6 << 16 | 6)) {
// Add protcol fields to the APN. The XML file does not change.
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN protocol TEXT DEFAULT IP;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN roaming_protocol TEXT DEFAULT IP;");
oldVersion = 6 << 16 | 6;
}
if (oldVersion < (7 << 16 | 6)) {
// Add carrier_enabled, bearer fields to the APN. The XML file does not change.
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN carrier_enabled BOOLEAN DEFAULT 1;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN bearer INTEGER DEFAULT 0;");
oldVersion = 7 << 16 | 6;
}
if (oldVersion < (8 << 16 | 6)) {
// Add mvno_type, mvno_match_data fields to the APN.
// The XML file does not change.
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN mvno_type TEXT DEFAULT '';");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN mvno_match_data TEXT DEFAULT '';");
oldVersion = 8 << 16 | 6;
}
if (oldVersion < (9 << 16 | 6)) {
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN sub_id INTEGER DEFAULT " +
SubscriptionManager.INVALID_SUBSCRIPTION_ID + ";");
oldVersion = 9 << 16 | 6;
}
if (oldVersion < (10 << 16 | 6)) {
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN profile_id INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN modem_cognitive BOOLEAN DEFAULT 0;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN max_conns INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN wait_time INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN max_conns_time INTEGER DEFAULT 0;");
oldVersion = 10 << 16 | 6;
}
if (oldVersion < (11 << 16 | 6)) {
db.execSQL("ALTER TABLE " + CARRIERS_TABLE +
" ADD COLUMN mtu INTEGER DEFAULT 0;");
oldVersion = 11 << 16 | 6;
}
if (oldVersion < (12 << 16 | 6)) {
try {
// Try to update the siminfo table. It might not be there.
db.execSQL("ALTER TABLE " + SIMINFO_TABLE +
" ADD COLUMN " + SubscriptionManager.MCC + " INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE " + SIMINFO_TABLE +
" ADD COLUMN " + SubscriptionManager.MNC + " INTEGER DEFAULT 0;");
} catch (SQLiteException e) {
if (DBG) {
log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
" The table will get created in onOpen.");
}
}
oldVersion = 12 << 16 | 6;
}
if (oldVersion < (13 << 16 | 6)) {
try {
// Try to update the siminfo table. It might not be there.
db.execSQL("ALTER TABLE " + SIMINFO_TABLE +
" ADD COLUMN " + SubscriptionManager.CARRIER_NAME + " TEXT DEFAULT '';");
} catch (SQLiteException e) {
if (DBG) {
log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " +
" The table will get created in onOpen.");
}
}
oldVersion = 13 << 16 | 6;
}
if (DBG) {
log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion);
}
db.delete(carriers_table, null, null);//modify
initdatabase(db);//modify
}