Search in sources :

Example 1 with NetworkState

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

the class ConnectivityService method getAllNetworkState.

@Override
public NetworkState[] getAllNetworkState() {
    enforceAccessPermission();
    final int uid = Binder.getCallingUid();
    final ArrayList<NetworkState> result = Lists.newArrayList();
    synchronized (mRulesLock) {
        for (NetworkStateTracker tracker : mNetTrackers) {
            if (tracker != null) {
                final NetworkInfo info = getFilteredNetworkInfo(tracker, uid);
                result.add(new NetworkState(info, tracker.getLinkProperties(), tracker.getLinkCapabilities()));
            }
        }
    }
    return result.toArray(new NetworkState[result.size()]);
}
Also used : NetworkInfo(android.net.NetworkInfo) NetworkState(android.net.NetworkState) NetworkStateTracker(android.net.NetworkStateTracker)

Example 2 with NetworkState

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

the class ConnectivityService method getActiveNetworkQuotaInfo.

@Override
public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
    enforceAccessPermission();
    final long token = Binder.clearCallingIdentity();
    try {
        final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
        if (state != null) {
            try {
                return mPolicyManager.getNetworkQuotaInfo(state);
            } catch (RemoteException e) {
            }
        }
        return null;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : NetworkState(android.net.NetworkState) RemoteException(android.os.RemoteException)

Example 3 with NetworkState

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

the class NetworkPolicyManagerServiceTest method testMeteredNetworkWithoutLimit.

public void testMeteredNetworkWithoutLimit() throws Exception {
    NetworkState[] state = null;
    NetworkStats stats = null;
    Future<Void> future;
    Future<String> tagFuture;
    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();
        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
        expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, currentTimeMillis())).andReturn(stats.getTotalBytes()).atLeastOnce();
        expectPolicyDataEnable(TYPE_WIFI, true);
        expectRemoveInterfaceQuota(TEST_IFACE);
        expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
        expectClearNotifications();
        expectAdvisePersistThreshold();
        future = expectMeteredIfacesChanged(TEST_IFACE);
        replay();
        setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, WARNING_DISABLED, LIMIT_DISABLED, true));
        future.get();
        verifyAndReset();
    }
}
Also used : NetworkPolicy(android.net.NetworkPolicy) NetworkStats(android.net.NetworkStats) NetworkState(android.net.NetworkState)

Example 4 with NetworkState

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

the class NetworkPolicyManagerServiceTest method testNetworkPolicyAppliedCycleLastMonth.

public void testNetworkPolicyAppliedCycleLastMonth() throws Exception {
    NetworkState[] state = null;
    NetworkStats stats = null;
    Future<Void> future;
    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() };
    expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
    expectCurrentTime();
    expectClearNotifications();
    expectAdvisePersistThreshold();
    future = expectMeteredIfacesChanged();
    replay();
    mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
    future.get();
    verifyAndReset();
    // now change cycle to be on 15th, and test in early march, to verify we
    // pick cycle day in previous month.
    expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
    expectCurrentTime();
    // pretend that 512 bytes total have happened
    stats = new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 256L, 2L, 256L, 2L);
    expect(mStatsService.getNetworkTotalBytes(sTemplateWifi, TIME_FEB_15, TIME_MAR_10)).andReturn(stats.getTotalBytes()).atLeastOnce();
    expectPolicyDataEnable(TYPE_WIFI, true);
    // TODO: consider making strongly ordered mock
    expectRemoveInterfaceQuota(TEST_IFACE);
    expectSetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);
    expectClearNotifications();
    expectAdvisePersistThreshold();
    future = expectMeteredIfacesChanged(TEST_IFACE);
    replay();
    setNetworkPolicies(new NetworkPolicy(sTemplateWifi, CYCLE_DAY, TIMEZONE_UTC, 1 * MB_IN_BYTES, 2 * MB_IN_BYTES, false));
    future.get();
    verifyAndReset();
}
Also used : NetworkPolicy(android.net.NetworkPolicy) NetworkStats(android.net.NetworkStats) Intent(android.content.Intent) NetworkState(android.net.NetworkState)

Example 5 with NetworkState

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

the class NetworkStatsServiceTest method buildMobile3gState.

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

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