Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d840b665 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Collect historical network stats."

parents dfb25e20 75279904
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ LOCAL_SRC_FILES += \
	core/java/android/net/IThrottleManager.aidl \
	core/java/android/net/INetworkPolicyListener.aidl \
	core/java/android/net/INetworkPolicyManager.aidl \
	core/java/android/net/INetworkStatsService.aidl \
	core/java/android/nfc/ILlcpConnectionlessSocket.aidl \
	core/java/android/nfc/ILlcpServiceSocket.aidl \
	core/java/android/nfc/ILlcpSocket.aidl \
@@ -124,7 +125,6 @@ LOCAL_SRC_FILES += \
	core/java/android/os/IHardwareService.aidl \
	core/java/android/os/IMessenger.aidl \
	core/java/android/os/INetworkManagementService.aidl \
	core/java/android/os/INetStatService.aidl \
	core/java/android/os/IPermissionController.aidl \
	core/java/android/os/IPowerManager.aidl \
    core/java/android/os/IRemoteCallback.aidl \
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framew
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/nfc)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libstagefright_intermediates)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
+2 −0
Original line number Diff line number Diff line
@@ -1544,6 +1544,8 @@ public abstract class Context {
     */
    public static final String NETWORKMANAGEMENT_SERVICE = "network_management";

    /** {@hide} */
    public static final String NETWORK_STATS_SERVICE = "netstats";
    /** {@hide} */
    public static final String NETWORK_POLICY_SERVICE = "netpolicy";

+10 −18
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -14,22 +14,14 @@
 * limitations under the License.
 */

package android.os;
package android.net;

import android.net.NetworkStatsHistory;

/** {@hide} */
interface INetworkStatsService {

    NetworkStatsHistory[] getNetworkStatsSummary(int networkType);
    NetworkStatsHistory getNetworkStatsUid(int uid);

/**
 * Retrieves packet and byte counts for the phone data interface,
 * and for all interfaces.
 * Used for the data activity icon and the phone status in Settings.
 *
 * {@hide}
 */
interface INetStatService {
    long getMobileTxPackets();
    long getMobileRxPackets();
    long getMobileTxBytes();
    long getMobileRxBytes();
    long getTotalTxPackets();
    long getTotalRxPackets();
    long getTotalTxBytes();
    long getTotalRxBytes();
}
+37 −11
Original line number Diff line number Diff line
@@ -22,19 +22,22 @@ import android.os.SystemClock;

import java.io.CharArrayWriter;
import java.io.PrintWriter;
import java.util.HashSet;

/**
 * Collection of network statistics. Can contain summary details across all
 * interfaces, or details with per-UID granularity. Designed to parcel quickly
 * across process boundaries.
 * Collection of active network statistics. Can contain summary details across
 * all interfaces, or details with per-UID granularity. Internally stores data
 * as a large table, closely matching {@code /proc/} data format. This structure
 * optimizes for rapid in-memory comparison, but consider using
 * {@link NetworkStatsHistory} when persisting.
 *
 * @hide
 */
public class NetworkStats implements Parcelable {
    /** {@link #iface} value when entry is summarized over all interfaces. */
    /** {@link #iface} value when interface details unavailable. */
    public static final String IFACE_ALL = null;
    /** {@link #uid} value when entry is summarized over all UIDs. */
    public static final int UID_ALL = 0;
    /** {@link #uid} value when UID details unavailable. */
    public static final int UID_ALL = -1;

    // NOTE: data should only be accounted for once in this structure; if data
    // is broken out, the summarized version should not be included.
@@ -49,7 +52,7 @@ public class NetworkStats implements Parcelable {
    public final long[] rx;
    public final long[] tx;

    // TODO: add fg/bg stats and tag granularity
    // TODO: add fg/bg stats once reported by kernel

    private NetworkStats(long elapsedRealtime, String[] iface, int[] uid, long[] rx, long[] tx) {
        this.elapsedRealtime = elapsedRealtime;
@@ -119,16 +122,36 @@ public class NetworkStats implements Parcelable {
        return -1;
    }

    /**
     * Return list of unique interfaces known by this data structure.
     */
    public String[] getKnownIfaces() {
        final HashSet<String> ifaces = new HashSet<String>();
        for (String iface : this.iface) {
            if (iface != IFACE_ALL) {
                ifaces.add(iface);
            }
        }
        return ifaces.toArray(new String[ifaces.size()]);
    }

    /**
     * Subtract the given {@link NetworkStats}, effectively leaving the delta
     * between two snapshots in time. Assumes that statistics rows collect over
     * time, and that none of them have disappeared.
     *
     * @param enforceMonotonic Validate that incoming value is strictly
     *            monotonic compared to this object.
     */
    public NetworkStats subtract(NetworkStats value) {
        // result will have our rows, but no meaningful timestamp
        final int length = length();
        final NetworkStats.Builder result = new NetworkStats.Builder(-1, length);
    public NetworkStats subtract(NetworkStats value, boolean enforceMonotonic) {
        final long deltaRealtime = this.elapsedRealtime - value.elapsedRealtime;
        if (enforceMonotonic && deltaRealtime < 0) {
            throw new IllegalArgumentException("found non-monotonic realtime");
        }

        // result will have our rows, and elapsed time between snapshots
        final int length = length();
        final NetworkStats.Builder result = new NetworkStats.Builder(deltaRealtime, length);
        for (int i = 0; i < length; i++) {
            final String iface = this.iface[i];
            final int uid = this.uid[i];
@@ -142,6 +165,9 @@ public class NetworkStats implements Parcelable {
                // existing row, subtract remote value
                final long rx = this.rx[i] - value.rx[j];
                final long tx = this.tx[i] - value.tx[j];
                if (enforceMonotonic && (rx < 0 || tx < 0)) {
                    throw new IllegalArgumentException("found non-monotonic values");
                }
                result.addEntry(iface, uid, rx, tx);
            }
        }
Loading