Search in sources :

Example 16 with NetworkState

use of android.net.NetworkState in project platform_frameworks_base by android.

the class NetworkStatsServiceTest method buildMobile4gState.

private static NetworkState buildMobile4gState(String iface) {
    final NetworkInfo info = new NetworkInfo(TYPE_WIMAX, 0, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(iface);
    final NetworkCapabilities capabilities = new NetworkCapabilities();
    return new NetworkState(info, prop, capabilities, null, null, null);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 17 with NetworkState

use of android.net.NetworkState in project platform_frameworks_base by android.

the class NetworkStatsServiceTest method buildWifiState.

private static NetworkState buildWifiState(boolean isMetered) {
    final NetworkInfo info = new NetworkInfo(TYPE_WIFI, 0, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    final NetworkCapabilities capabilities = new NetworkCapabilities();
    if (!isMetered) {
        capabilities.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
    }
    return new NetworkState(info, prop, capabilities, null, null, TEST_SSID);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 18 with NetworkState

use of android.net.NetworkState in project platform_frameworks_base by android.

the class NetworkStatsServiceTest method buildMobile3gState.

private static NetworkState buildMobile3gState(String subscriberId, boolean isRoaming) {
    final NetworkInfo info = new NetworkInfo(TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UMTS, null, null);
    info.setDetailedState(DetailedState.CONNECTED, null, null);
    info.setRoaming(isRoaming);
    final LinkProperties prop = new LinkProperties();
    prop.setInterfaceName(TEST_IFACE);
    final NetworkCapabilities capabilities = new NetworkCapabilities();
    return new NetworkState(info, prop, capabilities, null, subscriberId, null);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 19 with NetworkState

use of android.net.NetworkState in project platform_frameworks_base by android.

the class NetworkPolicyManagerServiceTest method testNetworkPolicyAppliedCycleLastMonth.

@Test
public void testNetworkPolicyAppliedCycleLastMonth() throws Exception {
    NetworkState[] state = null;
    NetworkStats stats = null;
    final long TIME_FEB_15 = 1171497600000L;
    final long TIME_MAR_10 = 1173484800000L;
    final int CYCLE_DAY = 15;
    setCurrentTimeMillis(TIME_MAR_10);
    // first, pretend that wifi network comes online. no policy active,
    // which means we shouldn't push limit to interface.
    state = new NetworkState[] { buildWifi() };
    when(mConnManager.getAllNetworkState()).thenReturn(state);
    expectCurrentTime();
    mPolicyListener.expect().onMeteredIfacesChanged(any());
    mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
    mPolicyListener.waitAndVerify().onMeteredIfacesChanged(any());
    // now change cycle to be on 15th, and test in early march, to verify we
    // pick cycle day in previous month.
    when(mConnManager.getAllNetworkState()).thenReturn(state);
    expectCurrentTime();
    // pretend that 512 bytes total have happened
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 256L, 2L, 256L, 2L);
    when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, TIME_MAR_10)).thenReturn(stats.getTotalBytes());
    mPolicyListener.expect().onMeteredIfacesChanged(any());
    setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
    mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[] { TEST_IFACE }));
    // TODO: consider making strongly ordered mock
    verifyPolicyDataEnable(TYPE_WIFI, true);
    verifyRemoveInterfaceQuota(TEST_IFACE);
    verifySetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);
}
Also used : NetworkPolicy(android.net.NetworkPolicy) NetworkStats(android.net.NetworkStats) Intent(android.content.Intent) NetworkState(android.net.NetworkState) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 20 with NetworkState

use of android.net.NetworkState in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method getActiveNetworkInfo.

/**
     * Return NetworkInfo for the active (i.e., connected) network interface.
     * It is assumed that at most one network is active at a time. If more
     * than one is active, it is indeterminate which will be returned.
     * @return the info for the active network, or {@code null} if none is
     * active
     */
@Override
public NetworkInfo getActiveNetworkInfo() {
    enforceAccessPermission();
    final int uid = Binder.getCallingUid();
    final NetworkState state = getUnfilteredActiveNetworkState(uid);
    filterNetworkStateForUid(state, uid, false);
    maybeLogBlockedNetworkInfo(state.networkInfo, uid);
    return state.networkInfo;
}
Also used : NetworkState(android.net.NetworkState)

Aggregations

NetworkState (android.net.NetworkState)101 LinkProperties (android.net.LinkProperties)36 NetworkInfo (android.net.NetworkInfo)26 NetworkPolicy (android.net.NetworkPolicy)21 RemoteException (android.os.RemoteException)18 NetworkStats (android.net.NetworkStats)15 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 NetworkIdentity (android.net.NetworkIdentity)11 Intent (android.content.Intent)10 ArraySet (android.util.ArraySet)10 Suppress (android.test.suitebuilder.annotation.Suppress)9 NetworkCapabilities (android.net.NetworkCapabilities)8 Network (android.net.Network)5 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)5 Pair (android.util.Pair)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)2 NetworkStateTracker (android.net.NetworkStateTracker)1 HashMap (java.util.HashMap)1