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

Commit aeb1618b authored by Jack Yu's avatar Jack Yu
Browse files

Fixed that unmetered-used-only flag not properly set

The unmetered-used-only flag was not set properly so all
capabilities including metered ones were advertised to
connectivity services. Thus clients wanted internet
access were accidentally allowed to use it even when
data is turned off by the user.

Bug: 132369991
Test: Manually tested MMS on ATT with data disabled
Merged-In: Ib84f9116a8518e1257a187d63a5642144f19225e
Change-Id: Ib84f9116a8518e1257a187d63a5642144f19225e
(cherry picked from commit e148aade)
parent 0dfb1f53
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -1131,14 +1131,28 @@ public class DataConnection extends StateMachine {
     * @return True if this data connection should only be used for unmetered purposes.
     */
    private boolean isUnmeteredUseOnly() {
        // The data connection can only be unmetered used only if all requests' reasons are
        // unmetered.
        // If this data connection is on IWLAN, then it's unmetered and can be used by everyone.
        // Should not be for unmetered used only.
        if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) {
            return false;
        }

        // If data is enabled, this data connection can't be for unmetered used only because
        // everyone should be able to use it.
        if (mPhone.getDataEnabledSettings().isDataEnabled()) {
            return false;
        }

        // If the device is roaming and data roaming it turned on, then this data connection can't
        // be for unmetered use only.
        if (mDct.getDataRoamingEnabled() && mPhone.getServiceState().getDataRoaming()) {
            return false;
        }

        // The data connection can only be unmetered used only if all attached APN contexts
        // attached to this data connection are unmetered.
        for (ApnContext apnContext : mApnContexts.keySet()) {
            DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
            boolean isDataAllowed = mDct.isDataAllowed(apnContext, DcTracker.REQUEST_TYPE_NORMAL,
                    dataConnectionReasons);
            if (!isDataAllowed || !dataConnectionReasons.contains(
                    DataConnectionReasons.DataAllowedReasonType.UNMETERED_APN)) {
            if (ApnSettingUtils.isMeteredApnType(apnContext.getApnTypeBitmask(), mPhone)) {
                return false;
            }
        }
+30 −0
Original line number Diff line number Diff line
@@ -343,6 +343,12 @@ public class DataConnectionTest extends TelephonyTest {
        return (long) method.invoke(mDc, response);
    }

    private boolean isUnmeteredUseOnly() throws Exception {
        Method method = DataConnection.class.getDeclaredMethod("isUnmeteredUseOnly");
        method.setAccessible(true);
        return (boolean) method.invoke(mDc);
    }

    private SetupResult setLinkProperties(DataCallResponse response,
                                                         LinkProperties linkProperties)
            throws Exception {
@@ -902,4 +908,28 @@ public class DataConnectionTest extends TelephonyTest {
    public void testStartNattKeepaliveFailCondensed() throws Exception {
        checkStartNattKeepaliveFail(true);
    }

    @Test
    @SmallTest
    public void testIsUnmeteredUseOnly() throws Exception {
        Field field = DataConnection.class.getDeclaredField("mTransportType");
        field.setAccessible(true);
        field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);

        assertFalse(isUnmeteredUseOnly());

        field = DataConnection.class.getDeclaredField("mTransportType");
        field.setAccessible(true);
        field.setInt(mDc, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);

        doReturn(false).when(mDataEnabledSettings).isDataEnabled();
        doReturn(false).when(mServiceState).getDataRoaming();
        doReturn(ApnSetting.TYPE_MMS).when(mApnContext).getApnTypeBitmask();

        mContextFixture.getCarrierConfigBundle().putStringArray(
                CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[] { "default" });

        assertTrue(isUnmeteredUseOnly());
    }
}