Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cfc7dc5 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed that MMS incorrectly treated as metered data traffic.

The metered APN types cache was built before carrier config
is ready. Get rid of the cache because it doesn't buy us too much
in terms of performance as carrier config already has its own
cache. This will ensure we load the up to date configuration
when we bring up the data call.

Test: Manually sent mms on Vzw network.
bug: 31233558
Change-Id: Id0c243a7a92bd6ab3e7a46053e173bf727041015
parent 861fb73f
Loading
Loading
Loading
Loading
+38 −59
Original line number Diff line number Diff line
@@ -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,
@@ -415,18 +403,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) {
@@ -446,14 +426,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);
@@ -472,7 +451,7 @@ public class ApnSetting {
                return true;
            }
        }
        }

        if (DBG) Rlog.d(LOG_TAG, type + " is not metered. isRoaming: " + isRoaming);
        return false;
    }
+20 −2
Original line number Diff line number Diff line
@@ -258,7 +258,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,
@@ -275,6 +274,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
@@ -315,6 +323,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
@@ -395,7 +414,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,