Search in sources :

Example 66 with NetworkState

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

the class NetworkPolicyManagerServiceTest method buildWifi.

private static NetworkState buildWifi() {
    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);
    return new NetworkState(info, prop, null, null, null, TEST_SSID);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) LinkProperties(android.net.LinkProperties)

Example 67 with NetworkState

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

the class NetworkPolicyManagerServiceTest method testMeteredNetworkWithoutLimit.

@Test
public void testMeteredNetworkWithoutLimit() 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);
    // bring up wifi network with metered policy
    state = new NetworkState[] { buildWifi() };
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 0L, 0L, 0L, 0L);
    {
        expectCurrentTime();
        when(mConnManager.getAllNetworkState()).thenReturn(state);
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).thenReturn(stats.getTotalBytes());
        mPolicyListener.expect().onMeteredIfacesChanged(any());
        setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, true));
        mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[] { TEST_IFACE }));
        verifyPolicyDataEnable(TYPE_WIFI, true);
        verifyRemoveInterfaceQuota(TEST_IFACE);
        verifySetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
    }
}
Also used : NetworkPolicy(android.net.NetworkPolicy) NetworkStats(android.net.NetworkStats) NetworkState(android.net.NetworkState) Test(org.junit.Test)

Example 68 with NetworkState

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

the class NetworkPolicyManagerServiceTest method testOverWarningLimitNotification.

@Test
public void testOverWarningLimitNotification() throws Exception {
    NetworkState[] state = null;
    NetworkStats stats = null;
    Future<String> tagFuture = null;
    final long TIME_FEB_15 = 1171497600000L;
    final long TIME_MAR_10 = 1173484800000L;
    final int CYCLE_DAY = 15;
    setCurrentTimeMillis(TIME_MAR_10);
    // assign wifi policy
    state = new NetworkState[] {};
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 0L, 0L, 0L, 0L);
    {
        expectCurrentTime();
        when(mConnManager.getAllNetworkState()).thenReturn(state);
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).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(any());
        verifyPolicyDataEnable(TYPE_WIFI, true);
    }
    // bring up wifi network
    incrementCurrentTime(MINUTE_IN_MILLIS);
    state = new NetworkState[] { buildWifi() };
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 0L, 0L, 0L, 0L);
    {
        expectCurrentTime();
        when(mConnManager.getAllNetworkState()).thenReturn(state);
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).thenReturn(stats.getTotalBytes());
        mPolicyListener.expect().onMeteredIfacesChanged(any());
        mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
        mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[] { TEST_IFACE }));
        verifyPolicyDataEnable(TYPE_WIFI, true);
        verifyRemoveInterfaceQuota(TEST_IFACE);
        verifySetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);
    }
    // go over warning, which should kick notification
    incrementCurrentTime(MINUTE_IN_MILLIS);
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 1536 * KB_IN_BYTES, 15L, 0L, 0L);
    {
        expectCurrentTime();
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).thenReturn(stats.getTotalBytes());
        tagFuture = expectEnqueueNotification();
        mNetworkObserver.limitReached(null, TEST_IFACE);
        assertNotificationType(TYPE_WARNING, tagFuture.get());
        verifyPolicyDataEnable(TYPE_WIFI, true);
    }
    // go over limit, which should kick notification and dialog
    incrementCurrentTime(MINUTE_IN_MILLIS);
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 5 * MB_IN_BYTES, 512L, 0L, 0L);
    {
        expectCurrentTime();
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).thenReturn(stats.getTotalBytes());
        tagFuture = expectEnqueueNotification();
        mNetworkObserver.limitReached(null, TEST_IFACE);
        assertNotificationType(TYPE_LIMIT, tagFuture.get());
        verifyPolicyDataEnable(TYPE_WIFI, false);
    }
    // now snooze policy, which should remove quota
    incrementCurrentTime(MINUTE_IN_MILLIS);
    {
        expectCurrentTime();
        when(mConnManager.getAllNetworkState()).thenReturn(state);
        when(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).thenReturn(stats.getTotalBytes());
        tagFuture = expectEnqueueNotification();
        mPolicyListener.expect().onMeteredIfacesChanged(any());
        mService.snoozeLimit(sTemplateWifi);
        mPolicyListener.waitAndVerify().onMeteredIfacesChanged(eq(new String[] { TEST_IFACE }));
        assertNotificationType(TYPE_LIMIT_SNOOZED, tagFuture.get());
        // snoozed interface still has high quota so background data is
        // still restricted.
        verifyRemoveInterfaceQuota(TEST_IFACE);
        verifySetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
        verifyPolicyDataEnable(TYPE_WIFI, true);
    }
}
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 69 with NetworkState

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

the class ConnectivityService method getActiveNetworkInfoUnfiltered.

// Public because it's used by mLockdownTracker.
public NetworkInfo getActiveNetworkInfoUnfiltered() {
    enforceAccessPermission();
    final int uid = Binder.getCallingUid();
    NetworkState state = getUnfilteredActiveNetworkState(uid);
    return state.networkInfo;
}
Also used : NetworkState(android.net.NetworkState)

Example 70 with NetworkState

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

the class ConnectivityService method getNetworkInfoForUid.

@Override
public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked) {
    enforceAccessPermission();
    final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
    if (nai != null) {
        final NetworkState state = nai.getNetworkState();
        filterNetworkStateForUid(state, uid, ignoreBlocked);
        return state.networkInfo;
    } else {
        return null;
    }
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) 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