Search in sources :

Example 76 with NetworkStatsHistory

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

the class NetworkStatsCollection method recordCollection.

/**
     * Record all {@link NetworkStatsHistory} contained in the given collection
     * into this collection.
     */
public void recordCollection(NetworkStatsCollection another) {
    for (int i = 0; i < another.mStats.size(); i++) {
        final Key key = another.mStats.keyAt(i);
        final NetworkStatsHistory value = another.mStats.valueAt(i);
        recordHistory(key, value);
    }
}
Also used : NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 77 with NetworkStatsHistory

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

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)

Example 78 with NetworkStatsHistory

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

the class NetworkStatsServiceTest method testStatsBucketResize.

// TODO: simulate reboot to test bucket resize
@Suppress
public void testStatsBucketResize() throws Exception {
    NetworkStatsHistory history = null;
    assertStatsFilesExist(false);
    // pretend that wifi network comes online; service should ask about full
    // network state, and poll any existing interfaces before updating.
    expectCurrentTime();
    expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
    expectNetworkState(buildWifiState());
    expectNetworkStatsSummary(buildEmptyStats());
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectNetworkStatsPoll();
    expectBandwidthControlCheck();
    replay();
    mService.forceUpdateIfaces();
    verifyAndReset();
    // modify some number on wifi, and trigger poll event
    incrementCurrentTime(2 * HOUR_IN_MILLIS);
    expectCurrentTime();
    expectSettings(0L, HOUR_IN_MILLIS, WEEK_IN_MILLIS);
    expectNetworkStatsSummary(new NetworkStats(getElapsedRealtime(), 1).addIfaceValues(TEST_IFACE, 512L, 4L, 512L, 4L));
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectNetworkStatsPoll();
    replay();
    forcePollAndWaitForIdle();
    // verify service recorded history
    history = mSession.getHistoryForNetwork(sTemplateWifi, FIELD_ALL);
    assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
    assertEquals(HOUR_IN_MILLIS, history.getBucketDuration());
    assertEquals(2, history.size());
    verifyAndReset();
    // now change bucket duration setting and trigger another poll with
    // exact same values, which should resize existing buckets.
    expectCurrentTime();
    expectSettings(0L, 30 * MINUTE_IN_MILLIS, WEEK_IN_MILLIS);
    expectNetworkStatsSummary(buildEmptyStats());
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectNetworkStatsPoll();
    replay();
    forcePollAndWaitForIdle();
    // verify identical stats, but spread across 4 buckets now
    history = mSession.getHistoryForNetwork(sTemplateWifi, FIELD_ALL);
    assertValues(history, Long.MIN_VALUE, Long.MAX_VALUE, 512L, 4L, 512L, 4L, 0);
    assertEquals(30 * MINUTE_IN_MILLIS, history.getBucketDuration());
    assertEquals(4, history.size());
    verifyAndReset();
}
Also used : NetworkStats(android.net.NetworkStats) NetworkStatsHistory(android.net.NetworkStatsHistory) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 79 with NetworkStatsHistory

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

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)

Example 80 with NetworkStatsHistory

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

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)

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