Search in sources :

Example 1 with NetworkStatsHistory

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

the class NetworkStatsCollection method dump.

public void dump(IndentingPrintWriter pw) {
    final ArrayList<Key> keys = Lists.newArrayList();
    keys.addAll(mStats.keySet());
    Collections.sort(keys);
    for (Key key : keys) {
        pw.print("ident=");
        pw.print(key.ident.toString());
        pw.print(" uid=");
        pw.print(key.uid);
        pw.print(" set=");
        pw.print(NetworkStats.setToString(key.set));
        pw.print(" tag=");
        pw.println(NetworkStats.tagToString(key.tag));
        final NetworkStatsHistory history = mStats.get(key);
        pw.increaseIndent();
        history.dump(pw, true);
        pw.decreaseIndent();
    }
}
Also used : NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 2 with NetworkStatsHistory

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

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();
}
Also used : ArrayList(java.util.ArrayList) NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 3 with NetworkStatsHistory

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

the class NetworkStatsCollection method readLegacyNetwork.

@Deprecated
public void readLegacyNetwork(File file) throws IOException {
    final AtomicFile inputFile = new AtomicFile(file);
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
        // verify file magic header intact
        final int magic = in.readInt();
        if (magic != FILE_MAGIC) {
            throw new ProtocolException("unexpected magic: " + magic);
        }
        final int version = in.readInt();
        switch(version) {
            case VERSION_NETWORK_INIT:
                {
                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
                    final int size = in.readInt();
                    for (int i = 0; i < size; i++) {
                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
                        final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
                        recordHistory(key, history);
                    }
                    break;
                }
            default:
                {
                    throw new ProtocolException("unexpected version: " + version);
                }
        }
    } catch (FileNotFoundException e) {
    // missing stats is okay, probably first boot
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : ProtocolException(java.net.ProtocolException) AtomicFile(android.util.AtomicFile) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) NetworkStatsHistory(android.net.NetworkStatsHistory) DataInputStream(java.io.DataInputStream)

Example 4 with NetworkStatsHistory

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

the class NetworkStatsCollection method read.

public void read(DataInputStream in) throws IOException {
    // verify file magic header intact
    final int magic = in.readInt();
    if (magic != FILE_MAGIC) {
        throw new ProtocolException("unexpected magic: " + magic);
    }
    final int version = in.readInt();
    switch(version) {
        case VERSION_UNIFIED_INIT:
            {
                // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
                final int identSize = in.readInt();
                for (int i = 0; i < identSize; i++) {
                    final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                    final int size = in.readInt();
                    for (int j = 0; j < size; j++) {
                        final int uid = in.readInt();
                        final int set = in.readInt();
                        final int tag = in.readInt();
                        final Key key = new Key(ident, uid, set, tag);
                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
                        recordHistory(key, history);
                    }
                }
                break;
            }
        default:
            {
                throw new ProtocolException("unexpected version: " + version);
            }
    }
}
Also used : ProtocolException(java.net.ProtocolException) NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 5 with NetworkStatsHistory

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

the class NetworkStatsCollection method findOrCreateHistory.

private NetworkStatsHistory findOrCreateHistory(NetworkIdentitySet ident, int uid, int set, int tag) {
    final Key key = new Key(ident, uid, set, tag);
    final NetworkStatsHistory existing = mStats.get(key);
    // update when no existing, or when bucket duration changed
    NetworkStatsHistory updated = null;
    if (existing == null) {
        updated = new NetworkStatsHistory(mBucketDuration, 10);
    } else if (existing.getBucketDuration() != mBucketDuration) {
        updated = new NetworkStatsHistory(existing, mBucketDuration);
    }
    if (updated != null) {
        mStats.put(key, updated);
        return updated;
    } else {
        return existing;
    }
}
Also used : NetworkStatsHistory(android.net.NetworkStatsHistory)

Aggregations

NetworkStatsHistory (android.net.NetworkStatsHistory)109 NetworkStats (android.net.NetworkStats)21 ProtocolException (java.net.ProtocolException)18 AtomicFile (android.util.AtomicFile)12 BufferedInputStream (java.io.BufferedInputStream)12 DataInputStream (java.io.DataInputStream)12 FileNotFoundException (java.io.FileNotFoundException)12 RemoteException (android.os.RemoteException)10 ArrayList (java.util.ArrayList)6 INetworkStatsSession (android.net.INetworkStatsSession)5 NetworkPolicy (android.net.NetworkPolicy)5 Time (android.text.format.Time)5 ArrayMap (android.util.ArrayMap)5 IntArray (android.util.IntArray)5 Date (java.util.Date)5 Suppress (android.test.suitebuilder.annotation.Suppress)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1