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

Commit 41ca7655 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed that unmetered-used-only flag not properly set" into qt-dev

am: 18354af0

Change-Id: Ib64b27944cbd4b8606748bdce00ef4a3b39fe698
parents e9a37108 18354af0
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());
    }
}