Search in sources :

Example 96 with NetworkStatsHistory

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

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 97 with NetworkStatsHistory

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

the class NetworkStatsServiceTest method assertNetworkTotal.

private void assertNetworkTotal(NetworkTemplate template, long start, long end, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations) throws Exception {
    // verify history API
    final NetworkStatsHistory history = mSession.getHistoryForNetwork(template, FIELD_ALL);
    assertValues(history, start, end, rxBytes, rxPackets, txBytes, txPackets, operations);
    // verify summary API
    final NetworkStats stats = mSession.getSummaryForNetwork(template, start, end);
    assertValues(stats, IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, ROAMING_NO, rxBytes, rxPackets, txBytes, txPackets, operations);
}
Also used : NetworkStats(android.net.NetworkStats) NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 98 with NetworkStatsHistory

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

the class NetworkStatsServiceTest method assertUidTotal.

private void assertUidTotal(NetworkTemplate template, int uid, int set, int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets, int operations) throws Exception {
    // verify history API
    final NetworkStatsHistory history = mSession.getHistoryForUid(template, uid, set, TAG_NONE, FIELD_ALL);
    assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, rxBytes, rxPackets, txBytes, txPackets, operations);
    // verify summary API
    final NetworkStats stats = mSession.getSummaryForAllUid(template, Long.MIN_VALUE, Long.MAX_VALUE, false);
    assertValues(stats, IFACE_ALL, uid, set, TAG_NONE, roaming, rxBytes, rxPackets, txBytes, txPackets, operations);
}
Also used : NetworkStats(android.net.NetworkStats) NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 99 with NetworkStatsHistory

use of android.net.NetworkStatsHistory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChartNetworkSeriesView method generatePath.

/**
     * Erase any existing {@link Path} and generate series outline based on
     * currently bound {@link NetworkStatsHistory} data.
     */
private void generatePath() {
    if (LOGD)
        Log.d(TAG, "generatePath()");
    mMax = 0;
    mPathStroke.reset();
    mPathFill.reset();
    mPathEstimate.reset();
    mPathValid = true;
    // bail when not enough stats to render
    if (mStats == null || mStats.size() < 2) {
        return;
    }
    final int width = getWidth();
    final int height = getHeight();
    boolean started = false;
    float lastX = 0;
    float lastY = height;
    long lastTime = mHoriz.convertToValue(lastX);
    // move into starting position
    mPathStroke.moveTo(lastX, lastY);
    mPathFill.moveTo(lastX, lastY);
    // TODO: count fractional data from first bucket crossing start;
    // currently it only accepts first full bucket.
    long totalData = 0;
    NetworkStatsHistory.Entry entry = null;
    final int start = mStats.getIndexBefore(mStart);
    final int end = mStats.getIndexAfter(mEnd);
    for (int i = start; i <= end; i++) {
        entry = mStats.getValues(i, entry);
        final long startTime = entry.bucketStart;
        final long endTime = startTime + entry.bucketDuration;
        final float startX = mHoriz.convertToPoint(startTime);
        final float endX = mHoriz.convertToPoint(endTime);
        // skip until we find first stats on screen
        if (endX < 0)
            continue;
        // increment by current bucket total
        totalData += entry.rxBytes + entry.txBytes;
        final float startY = lastY;
        final float endY = mVert.convertToPoint(totalData);
        if (lastTime != startTime) {
            // gap in buckets; line to start of current bucket
            mPathStroke.lineTo(startX, startY);
            mPathFill.lineTo(startX, startY);
        }
        // always draw to end of current bucket
        mPathStroke.lineTo(endX, endY);
        mPathFill.lineTo(endX, endY);
        lastX = endX;
        lastY = endY;
        lastTime = endTime;
    }
    // when data falls short, extend to requested end time
    if (lastTime < mEndTime) {
        lastX = mHoriz.convertToPoint(mEndTime);
        mPathStroke.lineTo(lastX, lastY);
        mPathFill.lineTo(lastX, lastY);
    }
    if (LOGD) {
        final RectF bounds = new RectF();
        mPathFill.computeBounds(bounds, true);
        Log.d(TAG, "onLayout() rendered with bounds=" + bounds.toString() + " and totalData=" + totalData);
    }
    // drop to bottom of graph from current location
    mPathFill.lineTo(lastX, height);
    mPathFill.lineTo(0, height);
    mMax = totalData;
    if (ESTIMATE_ENABLED) {
        // build estimated data
        mPathEstimate.moveTo(lastX, lastY);
        final long now = System.currentTimeMillis();
        final long bucketDuration = mStats.getBucketDuration();
        // long window is average over two weeks
        entry = mStats.getValues(lastTime - WEEK_IN_MILLIS * 2, lastTime, now, entry);
        final long longWindow = (entry.rxBytes + entry.txBytes) * bucketDuration / entry.bucketDuration;
        long futureTime = 0;
        while (lastX < width) {
            futureTime += bucketDuration;
            // short window is day average last week
            final long lastWeekTime = lastTime - WEEK_IN_MILLIS + (futureTime % WEEK_IN_MILLIS);
            entry = mStats.getValues(lastWeekTime - DAY_IN_MILLIS, lastWeekTime, now, entry);
            final long shortWindow = (entry.rxBytes + entry.txBytes) * bucketDuration / entry.bucketDuration;
            totalData += (longWindow * 7 + shortWindow * 3) / 10;
            lastX = mHoriz.convertToPoint(lastTime + futureTime);
            lastY = mVert.convertToPoint(totalData);
            mPathEstimate.lineTo(lastX, lastY);
        }
        mMaxEstimate = totalData;
    }
    invalidate();
}
Also used : RectF(android.graphics.RectF) NetworkStatsHistory(android.net.NetworkStatsHistory) Paint(android.graphics.Paint)

Example 100 with NetworkStatsHistory

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

the class NetworkStats method startUserUidEnumeration.

/**
     * Starts uid enumeration for current user.
     * @throws RemoteException
     */
void startUserUidEnumeration() throws RemoteException {
    // TODO: getRelevantUids should be sensitive to time interval. When that's done,
    //       the filtering logic below can be removed.
    int[] uids = mSession.getRelevantUids();
    // Filtering of uids with empty history.
    IntArray filteredUids = new IntArray(uids.length);
    for (int uid : uids) {
        try {
            NetworkStatsHistory history = mSession.getHistoryIntervalForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp);
            if (history != null && history.size() > 0) {
                filteredUids.add(uid);
            }
        } catch (RemoteException e) {
            Log.w(TAG, "Error while getting history of uid " + uid, e);
        }
    }
    mUids = filteredUids.toArray();
    mUidOrUidIndex = -1;
    stepHistory();
}
Also used : IntArray(android.util.IntArray) NetworkStatsHistory(android.net.NetworkStatsHistory) RemoteException(android.os.RemoteException)

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