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

Commit d5b505aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set NetworkInfo's meter flag when capability changes." into nyc-mr1-dev

parents b7d1d41b a8201a7b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -409,6 +409,9 @@ public class DataConnection extends StateMachine {
                networkType, NETWORK_TYPE, TelephonyManager.getNetworkTypeName(networkType));
        mNetworkInfo.setRoaming(ss.getDataRoaming());
        mNetworkInfo.setIsAvailable(true);
        // The network should be by default metered until we find it has NET_CAPABILITY_NOT_METERED
        // capability.
        mNetworkInfo.setMetered(true);

        addState(mDefaultState);
            addState(mInactiveState, mDefaultState);
@@ -947,6 +950,10 @@ public class DataConnection extends StateMachine {
            if (!mApnSetting.isMetered(mPhone.getContext(), mPhone.getSubId(),
                    mPhone.getServiceState().getDataRoaming())) {
                result.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
                mNetworkInfo.setMetered(false);
            } else {
                result.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
                mNetworkInfo.setMetered(true);
            }

            result.maybeMarkCapabilitiesRestricted();
+51 −0
Original line number Diff line number Diff line
@@ -16,10 +16,13 @@

package com.android.internal.telephony.dataconnection;

import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.telephony.CarrierConfigManager;
import android.telephony.ServiceState;
import android.test.suitebuilder.annotation.SmallTest;

@@ -32,15 +35,20 @@ import com.android.internal.telephony.dataconnection.DataConnection.DisconnectPa
import com.android.internal.util.IState;
import com.android.internal.util.StateMachine;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -246,4 +254,47 @@ public class DataConnectionTest extends TelephonyTest {
        AsyncResult ar = new AsyncResult(null, response, null);
        assertEquals(RetryManager.NO_RETRY, getSuggestedRetryDelay(ar));
    }

    private NetworkInfo getNetworkInfo() throws Exception {
        Field f = DataConnection.class.getDeclaredField("mNetworkInfo");
        f.setAccessible(true);
        return (NetworkInfo) f.get(mDc);
    }

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

    @Test
    @SmallTest
    public void testMeteredCapability() throws Exception {

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

        testConnectEvent();

        assertTrue(getNetworkInfo().isMetered());
        assertFalse(getCopyNetworkCapabilities().
                hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
    }

    @Test
    @SmallTest
    public void testNonMeteredCapability() throws Exception {

        doReturn(1).when(mPhone).getSubId();
        mContextFixture.getCarrierConfigBundle().
                putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                        new String[] {"mms"});

        testConnectEvent();

        assertFalse(getNetworkInfo().isMetered());
        assertTrue(getCopyNetworkCapabilities().
                hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED));
    }
}
 No newline at end of file