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;
}
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);
}
}
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);
}
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;
}
};
}
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;
}
Aggregations