use of android.net.NetworkStatsHistory in project android_frameworks_base by AOSPA.
the class NetworkStatsCollection method recordHistory.
/**
* Record given {@link NetworkStatsHistory} into this collection.
*/
private void recordHistory(Key key, NetworkStatsHistory history) {
if (history.size() == 0)
return;
noteRecordedHistory(history.getStart(), history.getEnd(), history.getTotalBytes());
NetworkStatsHistory target = mStats.get(key);
if (target == null) {
target = new NetworkStatsHistory(history.getBucketDuration());
mStats.put(key, target);
}
target.recordEntireHistory(history);
}
use of android.net.NetworkStatsHistory in project android_frameworks_base by AOSPA.
the class NetworkStatsCollection method write.
public void write(DataOutputStream out) throws IOException {
// cluster key lists grouped by ident
final HashMap<NetworkIdentitySet, ArrayList<Key>> keysByIdent = Maps.newHashMap();
for (Key key : mStats.keySet()) {
ArrayList<Key> keys = keysByIdent.get(key.ident);
if (keys == null) {
keys = Lists.newArrayList();
keysByIdent.put(key.ident, keys);
}
keys.add(key);
}
out.writeInt(FILE_MAGIC);
out.writeInt(VERSION_UNIFIED_INIT);
out.writeInt(keysByIdent.size());
for (NetworkIdentitySet ident : keysByIdent.keySet()) {
final ArrayList<Key> keys = keysByIdent.get(ident);
ident.writeToStream(out);
out.writeInt(keys.size());
for (Key key : keys) {
final NetworkStatsHistory history = mStats.get(key);
out.writeInt(key.uid);
out.writeInt(key.set);
out.writeInt(key.tag);
history.writeToStream(out);
}
}
out.flush();
}
use of android.net.NetworkStatsHistory in project android_frameworks_base by AOSPA.
the class NetworkStatsCollection method removeUids.
/**
* Remove any {@link NetworkStatsHistory} attributed to the requested UID,
* moving any {@link NetworkStats#TAG_NONE} series to
* {@link TrafficStats#UID_REMOVED}.
*/
public void removeUids(int[] uids) {
final ArrayList<Key> knownKeys = Lists.newArrayList();
knownKeys.addAll(mStats.keySet());
// migrate all UID stats into special "removed" bucket
for (Key key : knownKeys) {
if (ArrayUtils.contains(uids, key.uid)) {
// only migrate combined TAG_NONE history
if (key.tag == TAG_NONE) {
final NetworkStatsHistory uidHistory = mStats.get(key);
final NetworkStatsHistory removedHistory = findOrCreateHistory(key.ident, UID_REMOVED, SET_DEFAULT, TAG_NONE);
removedHistory.recordEntireHistory(uidHistory);
}
mStats.remove(key);
mDirty = true;
}
}
}
use of android.net.NetworkStatsHistory in project android_frameworks_base by crdroidandroid.
the class ChartDataLoader method loadInBackground.
private ChartData loadInBackground(NetworkTemplate template, AppItem app, int fields) throws RemoteException {
final ChartData data = new ChartData();
data.network = mSession.getHistoryForNetwork(template, fields);
if (app != null) {
// load stats for current uid and template
final int size = app.uids.size();
for (int i = 0; i < size; i++) {
final int uid = app.uids.keyAt(i);
data.detailDefault = collectHistoryForUid(template, uid, SET_DEFAULT, data.detailDefault);
data.detailForeground = collectHistoryForUid(template, uid, SET_FOREGROUND, data.detailForeground);
}
if (size > 0) {
data.detail = new NetworkStatsHistory(data.detailForeground.getBucketDuration());
data.detail.recordEntireHistory(data.detailDefault);
data.detail.recordEntireHistory(data.detailForeground);
} else {
data.detailDefault = new NetworkStatsHistory(HOUR_IN_MILLIS);
data.detailForeground = new NetworkStatsHistory(HOUR_IN_MILLIS);
data.detail = new NetworkStatsHistory(HOUR_IN_MILLIS);
}
}
return data;
}
use of android.net.NetworkStatsHistory in project android_frameworks_base by crdroidandroid.
the class NetworkStatsCollection method recordData.
/**
* Record given {@link android.net.NetworkStats.Entry} into this collection.
*/
public void recordData(NetworkIdentitySet ident, int uid, int set, int tag, long start, long end, NetworkStats.Entry entry) {
final NetworkStatsHistory history = findOrCreateHistory(ident, uid, set, tag);
history.recordData(start, end, entry);
noteRecordedHistory(history.getStart(), history.getEnd(), entry.rxBytes + entry.txBytes);
}
Aggregations