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

Commit 51a49303 authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Gerrit Code Review
Browse files

Merge "Fixed that MMS incorrectly treated as metered data traffic."

parents 6ee00440 b08ea565
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,
@@ -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) {
@@ -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);
@@ -470,7 +449,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
@@ -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,
@@ -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
@@ -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
@@ -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,