Search in sources :

Example 6 with NetworkStats

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

the class BandwidthTest method fetchDataFromProc.

/**
     * Fetch network data from /proc/uid_stat/uid
     *
     * @return populated {@link NetworkStats}
     */
public NetworkStats fetchDataFromProc(int uid) {
    String root_filepath = "/proc/uid_stat/" + uid + "/";
    File rcv_stat = new File(root_filepath + "tcp_rcv");
    int rx = BandwidthTestUtil.parseIntValueFromFile(rcv_stat);
    File snd_stat = new File(root_filepath + "tcp_snd");
    int tx = BandwidthTestUtil.parseIntValueFromFile(snd_stat);
    NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
    stats.addValues(NetworkStats.IFACE_ALL, uid, NetworkStats.SET_DEFAULT, NetworkStats.TAG_NONE, rx, 0, tx, 0, 0);
    return stats;
}
Also used : NetworkStats(android.net.NetworkStats) File(java.io.File)

Example 7 with NetworkStats

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

the class NetworkStatsFactoryBenchmark method timeReadNetworkStatsDetailNative.

public void timeReadNetworkStatsDetailNative(int reps) {
    for (int i = 0; i < reps; i++) {
        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 0);
        NetworkStatsFactory.nativeReadNetworkStatsDetail(stats, mStats.getAbsolutePath(), NetworkStats.UID_ALL);
    }
}
Also used : NetworkStats(android.net.NetworkStats)

Example 8 with NetworkStats

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

the class NetworkStatsFactoryTest method testNetworkStatsDetail.

public void testNetworkStatsDetail() throws Exception {
    stageFile(R.raw.xt_qtaguid_typical, new File(mTestProc, "net/xt_qtaguid/stats"));
    final NetworkStats stats = mFactory.readNetworkStatsDetail();
    assertEquals(70, stats.size());
    assertStatsEntry(stats, "wlan0", 0, SET_DEFAULT, 0x0, 18621L, 2898L);
    assertStatsEntry(stats, "wlan0", 10011, SET_DEFAULT, 0x0, 35777L, 5718L);
    assertStatsEntry(stats, "wlan0", 10021, SET_DEFAULT, 0x7fffff01, 562386L, 49228L);
    assertStatsEntry(stats, "rmnet1", 10021, SET_DEFAULT, 0x30100000, 219110L, 227423L);
    assertStatsEntry(stats, "rmnet2", 10001, SET_DEFAULT, 0x0, 1125899906842624L, 984L);
}
Also used : NetworkStats(android.net.NetworkStats) File(java.io.File)

Example 9 with NetworkStats

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

the class NetworkStatsService method openSession.

@Override
public INetworkStatsSession openSession() {
    mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
    assertBandwidthControlEnabled();
    return new INetworkStatsSession.Stub() {

        private NetworkStatsCollection mUidComplete;

        private NetworkStatsCollection mUidTagComplete;

        private NetworkStatsCollection getUidComplete() {
            if (mUidComplete == null) {
                synchronized (mStatsLock) {
                    mUidComplete = mUidRecorder.getOrLoadCompleteLocked();
                }
            }
            return mUidComplete;
        }

        private NetworkStatsCollection getUidTagComplete() {
            if (mUidTagComplete == null) {
                synchronized (mStatsLock) {
                    mUidTagComplete = mUidTagRecorder.getOrLoadCompleteLocked();
                }
            }
            return mUidTagComplete;
        }

        @Override
        public NetworkStats getSummaryForNetwork(NetworkTemplate template, long start, long end) {
            return internalGetSummaryForNetwork(template, start, end);
        }

        @Override
        public NetworkStatsHistory getHistoryForNetwork(NetworkTemplate template, int fields) {
            return internalGetHistoryForNetwork(template, fields);
        }

        @Override
        public NetworkStats getSummaryForAllUid(NetworkTemplate template, long start, long end, boolean includeTags) {
            final NetworkStats stats = getUidComplete().getSummary(template, start, end);
            if (includeTags) {
                final NetworkStats tagStats = getUidTagComplete().getSummary(template, start, end);
                stats.combineAllValues(tagStats);
            }
            return stats;
        }

        @Override
        public NetworkStatsHistory getHistoryForUid(NetworkTemplate template, int uid, int set, int tag, int fields) {
            if (tag == TAG_NONE) {
                return getUidComplete().getHistory(template, uid, set, tag, fields);
            } else {
                return getUidTagComplete().getHistory(template, uid, set, tag, fields);
            }
        }

        @Override
        public void close() {
            mUidComplete = null;
            mUidTagComplete = null;
        }
    };
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkStats(android.net.NetworkStats)

Example 10 with NetworkStats

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

the class NetworkStatsService method getNetworkStatsUidDetail.

/**
     * Return snapshot of current UID statistics, including any
     * {@link TrafficStats#UID_TETHERING} and {@link #mUidOperations} values.
     */
private NetworkStats getNetworkStatsUidDetail() throws RemoteException {
    final NetworkStats uidSnapshot = mNetworkManager.getNetworkStatsUidDetail(UID_ALL);
    // fold tethering stats and operations into uid snapshot
    final NetworkStats tetherSnapshot = getNetworkStatsTethering();
    uidSnapshot.combineAllValues(tetherSnapshot);
    uidSnapshot.combineAllValues(mUidOperations);
    return uidSnapshot;
}
Also used : NetworkStats(android.net.NetworkStats)

Aggregations

NetworkStats (android.net.NetworkStats)271 File (java.io.File)49 DataUsageRequest (android.net.DataUsageRequest)32 Intent (android.content.Intent)29 NetworkIdentity (android.net.NetworkIdentity)28 NetworkStatsHistory (android.net.NetworkStatsHistory)21 Bundle (android.os.Bundle)18 StrictMode (android.os.StrictMode)18 ProcFileReader (com.android.internal.util.ProcFileReader)18 FileInputStream (java.io.FileInputStream)18 ProtocolException (java.net.ProtocolException)18 PendingIntent (android.app.PendingIntent)17 IOException (java.io.IOException)17 NetworkPolicy (android.net.NetworkPolicy)15 NetworkState (android.net.NetworkState)15 Test (org.junit.Test)14 Suppress (android.test.suitebuilder.annotation.Suppress)13 VpnInfo (com.android.internal.net.VpnInfo)10 RemoteException (android.os.RemoteException)8 NetworkTemplate (android.net.NetworkTemplate)6