Loading src/java/com/android/internal/telephony/dataconnection/ApnSetting.java +38 −59 Original line number Diff line number Diff line Loading @@ -112,18 +112,6 @@ public class ApnSetting { * */ public boolean permanentFailed = false; /** * Metered APN types which would be accounted for in data usage. This is a map of subId -> * set of metered apn strings for the carrier. */ private static HashMap<Integer, HashSet<String>> sMeteredApnTypes = new HashMap<>(); /** * Metered Roaming APN types which would be accounted for in data usage. This is a map of * subId -> set of metered roaming apn strings for the carrier. */ private static HashMap<Integer, HashSet<String>> sMeteredRoamingApnTypes = new HashMap<>(); public ApnSetting(int id, String numeric, String carrier, String apn, String proxy, String port, String mmsc, String mmsProxy, String mmsPort, Loading Loading @@ -413,18 +401,10 @@ public class ApnSetting { public static boolean isMeteredApnType(String type, Context context, int subId, boolean isRoaming) { HashMap<Integer, HashSet<String>> meteredApnTypesCache = (isRoaming) ? sMeteredApnTypes : sMeteredRoamingApnTypes; String carrierConfig = (isRoaming) ? CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS : CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS; synchronized (meteredApnTypesCache) { HashSet<String> meteredApnSet = meteredApnTypesCache.get(subId); // In case of cache miss, we need to look up the settings from carrier config. if (meteredApnSet == null) { // Retrieve the metered APN types from carrier config CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager == null) { Loading @@ -444,14 +424,13 @@ public class ApnSetting { return true; } meteredApnSet = new HashSet<String>(Arrays.asList(meteredApnTypes)); meteredApnTypesCache.put(subId, meteredApnSet); HashSet<String> meteredApnSet = new HashSet<>(Arrays.asList(meteredApnTypes)); if (DBG) { Rlog.d(LOG_TAG, "For subId = " + subId + ", metered APN types are " + Arrays.toString(meteredApnSet.toArray()) + " isRoaming: " + isRoaming); } } // If all types of APN are metered, then this APN setting must be metered. if (meteredApnSet.contains(PhoneConstants.APN_TYPE_ALL)) { if (DBG) Rlog.d(LOG_TAG, "All APN types are metered. isRoaming: " + isRoaming); Loading @@ -470,7 +449,7 @@ public class ApnSetting { return true; } } } if (DBG) Rlog.d(LOG_TAG, type + " is not metered. isRoaming: " + isRoaming); return false; } Loading tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnSettingTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -246,7 +246,6 @@ public class ApnSettingTest extends TelephonyTest { new String[]{PhoneConstants.APN_TYPE_IA, PhoneConstants.APN_TYPE_CBS}). isMetered(mContext, 1, isRoaming)); //reuse the cached result for subId 1 assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, Loading @@ -263,6 +262,15 @@ public class ApnSettingTest extends TelephonyTest { mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_HIPRI, mContext, 1, isRoaming)); // Carrier config settings changes. mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_DEFAULT}); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, mContext, 1, isRoaming)); } @Test Loading Loading @@ -303,6 +311,17 @@ public class ApnSettingTest extends TelephonyTest { assertFalse(createApnSetting( new String[]{PhoneConstants.APN_TYPE_IA, PhoneConstants.APN_TYPE_CBS}). isMetered(mContext, 1, isRoaming)); // Carrier config settings changes. mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_FOTA}); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, mContext, 1, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_FOTA, mContext, 1, isRoaming)); } @Test Loading Loading @@ -383,7 +402,6 @@ public class ApnSettingTest extends TelephonyTest { new String[]{PhoneConstants.APN_TYPE_IMS}). isMetered(mContext, 2, isRoaming)); //reuse the cached result for subId 2 assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_SUPL, mContext, 2, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_CBS, Loading Loading
src/java/com/android/internal/telephony/dataconnection/ApnSetting.java +38 −59 Original line number Diff line number Diff line Loading @@ -112,18 +112,6 @@ public class ApnSetting { * */ public boolean permanentFailed = false; /** * Metered APN types which would be accounted for in data usage. This is a map of subId -> * set of metered apn strings for the carrier. */ private static HashMap<Integer, HashSet<String>> sMeteredApnTypes = new HashMap<>(); /** * Metered Roaming APN types which would be accounted for in data usage. This is a map of * subId -> set of metered roaming apn strings for the carrier. */ private static HashMap<Integer, HashSet<String>> sMeteredRoamingApnTypes = new HashMap<>(); public ApnSetting(int id, String numeric, String carrier, String apn, String proxy, String port, String mmsc, String mmsProxy, String mmsPort, Loading Loading @@ -413,18 +401,10 @@ public class ApnSetting { public static boolean isMeteredApnType(String type, Context context, int subId, boolean isRoaming) { HashMap<Integer, HashSet<String>> meteredApnTypesCache = (isRoaming) ? sMeteredApnTypes : sMeteredRoamingApnTypes; String carrierConfig = (isRoaming) ? CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS : CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS; synchronized (meteredApnTypesCache) { HashSet<String> meteredApnSet = meteredApnTypesCache.get(subId); // In case of cache miss, we need to look up the settings from carrier config. if (meteredApnSet == null) { // Retrieve the metered APN types from carrier config CarrierConfigManager configManager = (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE); if (configManager == null) { Loading @@ -444,14 +424,13 @@ public class ApnSetting { return true; } meteredApnSet = new HashSet<String>(Arrays.asList(meteredApnTypes)); meteredApnTypesCache.put(subId, meteredApnSet); HashSet<String> meteredApnSet = new HashSet<>(Arrays.asList(meteredApnTypes)); if (DBG) { Rlog.d(LOG_TAG, "For subId = " + subId + ", metered APN types are " + Arrays.toString(meteredApnSet.toArray()) + " isRoaming: " + isRoaming); } } // If all types of APN are metered, then this APN setting must be metered. if (meteredApnSet.contains(PhoneConstants.APN_TYPE_ALL)) { if (DBG) Rlog.d(LOG_TAG, "All APN types are metered. isRoaming: " + isRoaming); Loading @@ -470,7 +449,7 @@ public class ApnSetting { return true; } } } if (DBG) Rlog.d(LOG_TAG, type + " is not metered. isRoaming: " + isRoaming); return false; } Loading
tests/telephonytests/src/com/android/internal/telephony/dataconnection/ApnSettingTest.java +20 −2 Original line number Diff line number Diff line Loading @@ -246,7 +246,6 @@ public class ApnSettingTest extends TelephonyTest { new String[]{PhoneConstants.APN_TYPE_IA, PhoneConstants.APN_TYPE_CBS}). isMetered(mContext, 1, isRoaming)); //reuse the cached result for subId 1 assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, Loading @@ -263,6 +262,15 @@ public class ApnSettingTest extends TelephonyTest { mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_HIPRI, mContext, 1, isRoaming)); // Carrier config settings changes. mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_DEFAULT}); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, mContext, 1, isRoaming)); } @Test Loading Loading @@ -303,6 +311,17 @@ public class ApnSettingTest extends TelephonyTest { assertFalse(createApnSetting( new String[]{PhoneConstants.APN_TYPE_IA, PhoneConstants.APN_TYPE_CBS}). isMetered(mContext, 1, isRoaming)); // Carrier config settings changes. mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS, new String[]{PhoneConstants.APN_TYPE_FOTA}); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_DEFAULT, mContext, 1, isRoaming)); assertFalse(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_MMS, mContext, 1, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_FOTA, mContext, 1, isRoaming)); } @Test Loading Loading @@ -383,7 +402,6 @@ public class ApnSettingTest extends TelephonyTest { new String[]{PhoneConstants.APN_TYPE_IMS}). isMetered(mContext, 2, isRoaming)); //reuse the cached result for subId 2 assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_SUPL, mContext, 2, isRoaming)); assertTrue(ApnSetting.isMeteredApnType(PhoneConstants.APN_TYPE_CBS, Loading