FileDocCategorySizeDatePackage
NetworkControllerBaseTest.javaAPI DocAndroid 5.1 API11467Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

NetworkControllerBaseTest

public class NetworkControllerBaseTest extends android.test.AndroidTestCase

Fields Summary
private static final String
TAG
protected static final int
DEFAULT_LEVEL
protected static final int
DEFAULT_SIGNAL_STRENGTH
protected static final int
DEFAULT_QS_SIGNAL_STRENGTH
protected static final int
DEFAULT_ICON
protected static final int
DEFAULT_QS_ICON
protected NetworkControllerImpl
mNetworkController
protected android.telephony.PhoneStateListener
mPhoneStateListener
protected com.android.systemui.statusbar.policy.NetworkControllerImpl.SignalCluster
mSignalCluster
protected com.android.systemui.statusbar.policy.NetworkController.NetworkSignalChangedCallback
mNetworkSignalChangedCallback
private android.telephony.SignalStrength
mSignalStrength
private android.telephony.ServiceState
mServiceState
protected android.net.ConnectivityManager
mMockCm
protected android.net.wifi.WifiManager
mMockWm
protected android.telephony.SubscriptionManager
mMockSm
protected android.telephony.TelephonyManager
mMockTm
protected com.android.systemui.statusbar.policy.NetworkControllerImpl.Config
mConfig
private android.net.NetworkCapabilities
mNetCapabilities
Constructors Summary
Methods Summary
public voidsetCdmaEri(int index, int mode)

        // TODO: Figure this out.
    
public voidsetCdmaLevel(int level)

        when(mSignalStrength.getCdmaLevel()).thenReturn(level);
        updateSignalStrength();
    
public voidsetCdmaRoaming(boolean isRoaming)

        when(mServiceState.getCdmaEriIconIndex()).thenReturn(isRoaming ?
                EriInfo.ROAMING_INDICATOR_ON : EriInfo.ROAMING_INDICATOR_OFF);
        when(mServiceState.getCdmaEriIconMode()).thenReturn(isRoaming ?
                EriInfo.ROAMING_ICON_MODE_NORMAL : -1);
        updateServiceState();
    
public voidsetConnectivity(int inetCondition, int networkType, boolean isConnected)

        Intent i = new Intent(ConnectivityManager.INET_CONDITION_ACTION);
        // TODO: Separate out into several NetworkCapabilities.
        if (isConnected) {
            mNetCapabilities.addTransportType(networkType);
        } else {
            mNetCapabilities.removeTransportType(networkType);
        }
        if (inetCondition != 0) {
            mNetCapabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
        } else {
            mNetCapabilities.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
        }

        mNetworkController.onReceive(mContext, i);
    
public voidsetDataRegState(int dataRegState)

        when(mServiceState.getDataRegState()).thenReturn(dataRegState);
        updateServiceState();
    
public voidsetGsmRoaming(boolean isRoaming)

        when(mServiceState.getRoaming()).thenReturn(isRoaming);
        updateServiceState();
    
public voidsetIsEmergencyOnly(boolean isEmergency)

        when(mServiceState.isEmergencyOnly()).thenReturn(isEmergency);
        updateServiceState();
    
public voidsetIsGsm(boolean gsm)

        when(mSignalStrength.isGsm()).thenReturn(gsm);
        updateSignalStrength();
    
public voidsetLevel(int level)

        when(mSignalStrength.getLevel()).thenReturn(level);
        updateSignalStrength();
    
protected voidsetUp()


    
         
        super.setUp();
        // Mockito stuff.
        System.setProperty("dexmaker.dexcache", mContext.getCacheDir().getPath());
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

        mMockWm = mock(WifiManager.class);
        mMockTm = mock(TelephonyManager.class);
        mMockSm = mock(SubscriptionManager.class);
        mMockCm = mock(ConnectivityManager.class);
        mNetCapabilities = new NetworkCapabilities();
        when(mMockCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true);
        when(mMockCm.getDefaultNetworkCapabilitiesForUser(0)).thenReturn(
                new NetworkCapabilities[] { mNetCapabilities });

        mSignalStrength = mock(SignalStrength.class);
        mServiceState = mock(ServiceState.class);

        mConfig = new Config();
        mConfig.hspaDataDistinguishable = true;
        mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm,
                mConfig, mock(AccessPointControllerImpl.class),
                mock(MobileDataControllerImpl.class));
        setupNetworkController();
    
public voidsetVoiceRegState(int voiceRegState)

        when(mServiceState.getVoiceRegState()).thenReturn(voiceRegState);
        updateServiceState();
    
public voidsetupDefaultSignal()

        setIsGsm(true);
        setVoiceRegState(ServiceState.STATE_IN_SERVICE);
        setGsmRoaming(false);
        setLevel(DEFAULT_LEVEL);
        updateDataConnectionState(TelephonyManager.DATA_CONNECTED,
                TelephonyManager.NETWORK_TYPE_UMTS);
        setConnectivity(100, ConnectivityManager.TYPE_MOBILE, true);
    
protected voidsetupNetworkController()

        // For now just pretend to be the data sim, so we can test that too.
        final int subId = SubscriptionManager.getDefaultDataSubId();
        SubscriptionInfo subscription = mock(SubscriptionInfo.class);
        List<SubscriptionInfo> subs = new ArrayList<SubscriptionInfo>();
        when(subscription.getSubscriptionId()).thenReturn(subId);
        subs.add(subscription);
        mNetworkController.setCurrentSubscriptions(subs);
        mPhoneStateListener =
                mNetworkController.mMobileSignalControllers.get(subId).mPhoneStateListener;
        mSignalCluster = mock(SignalCluster.class);
        mNetworkSignalChangedCallback = mock(NetworkSignalChangedCallback.class);
        mNetworkController.addSignalCluster(mSignalCluster);
        mNetworkController.addNetworkSignalChangedCallback(mNetworkSignalChangedCallback);
    
protected voidtearDown()

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        mNetworkController.dump(null, pw, null);
        pw.flush();
        Log.d(TAG, sw.toString());
        super.tearDown();
    
public voidupdateCallState(int state)

        // Inputs not currently used in NetworkControllerImpl.
        mPhoneStateListener.onCallStateChanged(state, "0123456789");
    
public voidupdateDataActivity(int dataActivity)

        mPhoneStateListener.onDataActivity(dataActivity);
    
public voidupdateDataConnectionState(int dataState, int dataNetType)

        mPhoneStateListener.onDataConnectionStateChanged(dataState, dataNetType);
    
private voidupdateServiceState()

        Log.d(TAG, "Sending Service State: " + mServiceState);
        mPhoneStateListener.onServiceStateChanged(mServiceState);
    
private voidupdateSignalStrength()

        Log.d(TAG, "Sending Signal Strength: " + mSignalStrength);
        mPhoneStateListener.onSignalStrengthsChanged(mSignalStrength);
    
protected voidverifyHasNoSims(boolean hasNoSimsVisible)

        ArgumentCaptor<Boolean> hasNoSimsArg = ArgumentCaptor.forClass(Boolean.class);

        Mockito.verify(mSignalCluster, Mockito.atLeastOnce()).setNoSims(hasNoSimsArg.capture());
        assertEquals("No sims in status bar", hasNoSimsVisible, (boolean) hasNoSimsArg.getValue());

        Mockito.verify(mNetworkSignalChangedCallback, Mockito.atLeastOnce())
                .onNoSimVisibleChanged(hasNoSimsArg.capture());
        assertEquals("No sims in quick settings", hasNoSimsVisible,
                (boolean) hasNoSimsArg.getValue());
    
protected voidverifyLastMobileDataIndicators(boolean visible, int icon, int typeIcon)

        ArgumentCaptor<Integer> iconArg = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Boolean> visibleArg = ArgumentCaptor.forClass(Boolean.class);

        // TODO: Verify all fields.
        Mockito.verify(mSignalCluster, Mockito.atLeastOnce()).setMobileDataIndicators(
                visibleArg.capture(), iconArg.capture(), typeIconArg.capture(),
                ArgumentCaptor.forClass(String.class).capture(),
                ArgumentCaptor.forClass(String.class).capture(),
                ArgumentCaptor.forClass(Boolean.class).capture(),
                ArgumentCaptor.forClass(Integer.class).capture());

        assertEquals("Signal icon in status bar", icon, (int) iconArg.getValue());
        assertEquals("Data icon in status bar", typeIcon, (int) typeIconArg.getValue());
        assertEquals("Visibility in status bar", visible, (boolean) visibleArg.getValue());
    
protected voidverifyLastQsMobileDataIndicators(boolean visible, int icon, int typeIcon, boolean dataIn, boolean dataOut)

        ArgumentCaptor<Integer> iconArg = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Integer> typeIconArg = ArgumentCaptor.forClass(Integer.class);
        ArgumentCaptor<Boolean> visibleArg = ArgumentCaptor.forClass(Boolean.class);
        ArgumentCaptor<Boolean> dataInArg = ArgumentCaptor.forClass(Boolean.class);
        ArgumentCaptor<Boolean> dataOutArg = ArgumentCaptor.forClass(Boolean.class);

        Mockito.verify(mNetworkSignalChangedCallback, Mockito.atLeastOnce())
                .onMobileDataSignalChanged(visibleArg.capture(), iconArg.capture(),
                        ArgumentCaptor.forClass(String.class).capture(),
                        typeIconArg.capture(),
                        dataInArg.capture(),
                        dataOutArg.capture(),
                        ArgumentCaptor.forClass(String.class).capture(),
                        ArgumentCaptor.forClass(String.class).capture(),
                        ArgumentCaptor.forClass(Boolean.class).capture());
        assertEquals("Visibility in, quick settings", visible, (boolean) visibleArg.getValue());
        assertEquals("Signal icon in, quick settings", icon, (int) iconArg.getValue());
        assertEquals("Data icon in, quick settings", typeIcon, (int) typeIconArg.getValue());
        assertEquals("Data direction in, in quick settings", dataIn,
                (boolean) dataInArg.getValue());
        assertEquals("Data direction out, in quick settings", dataOut,
                (boolean) dataOutArg.getValue());