carrier id APNs duplicates in restore
When doing reset to default in APN Settings, APNs defined with only
carrier id are kept in the database and an extra APN is added.
For every restore there is an additional APN added which means that
the DB increase every time a user choose "reset to default".
This happens due to carrier id only APNs are added with NULL value
for mcc, mnc and numeric, while their default value is an empty string.
- Changing to set default empty string for numeric, mcc and mnc will
solve this problem.
The database query when deleting preferred APNs is also wrong since
it only deletes preferred APNs with a numeric value, it does not
take into account that a carrier id APN can be default.
- Adding carrier id in the where clause will do the trick here.
Test: Add a carrier id APN, insert its sim and try to restore
Bug: 221220163
Change-Id: I529bf8b5d2877b0c27ec682041e10fcf6fb1bc2d
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 1899e25..23f0e87 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -2398,11 +2398,13 @@
// if not found a three digit mnc value is chosen
mncString = getBestStringMnc(mContext, mccString, Integer.parseInt(mnc));
}
-
- String numeric = (mccString == null | mncString == null) ? null : mccString + mncString;
+ // Make sure to set default values for numeric, mcc and mnc. This is the empty string.
+ // If default is not set here, a duplicate of each carrier id APN will be created next
+ // time the apn list is read. This happens at OTA or at restore.
+ String numeric = (mccString == null | mncString == null) ? "" : mccString + mncString;
map.put(NUMERIC, numeric);
- map.put(MCC, mccString);
- map.put(MNC, mncString);
+ map.put(MCC, mccString != null ? mccString : "");
+ map.put(MNC, mncString != null ? mncString : "");
map.put(NAME, parser.getAttributeValue(null, "carrier"));
// do not add NULL to the map so that default values can be inserted in db
@@ -5005,6 +5007,7 @@
TelephonyManager telephonyManager =
getContext().getSystemService(TelephonyManager.class).createForSubscriptionId(subId);
String simOperator = telephonyManager.getSimOperator();
+ int simCarrierId = telephonyManager.getSimSpecificCarrierId();
Cursor cursor = db.query(CARRIERS_TABLE, new String[] {MVNO_TYPE, MVNO_MATCH_DATA},
NUMERIC + "='" + simOperator + "'", null, null, null, DEFAULT_SORT_ORDER);
String where = null;
@@ -5032,6 +5035,12 @@
+ " AND (" + MVNO_TYPE + "='' OR " + MVNO_MATCH_DATA + "='')"
+ " AND " + IS_NOT_OWNED_BY_DPC;
}
+ // Add carrier id APNs
+ if (TelephonyManager.UNKNOWN_CARRIER_ID < simCarrierId) {
+ where = where.concat(" OR " + CARRIER_ID + " = '" + simCarrierId + "'" + " AND "
+ + IS_NOT_OWNED_BY_DPC);
+ }
+
}
return where;
}