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

Commit 39b8c69a authored by Zoltan Szatmary-Ban's avatar Zoltan Szatmary-Ban Committed by Android (Google) Code Review
Browse files

Merge "Rename NetworkUsageStats -> NetworkStats" into mnc-dev

parents 5bcbf857 381483b3
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -6058,22 +6058,14 @@ package android.app.usage {
    field public static final android.os.Parcelable.Creator<android.app.usage.ConfigurationStats> CREATOR;
  }
  public class NetworkStatsManager {
    method public android.app.usage.NetworkUsageStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class NetworkUsageStats implements java.lang.AutoCloseable {
  public final class NetworkStats implements java.lang.AutoCloseable {
    method public void close();
    method public boolean getNextBucket(android.app.usage.NetworkUsageStats.Bucket);
    method public boolean getNextBucket(android.app.usage.NetworkStats.Bucket);
    method public boolean hasNextBucket();
  }
  public static class NetworkUsageStats.Bucket {
    ctor public NetworkUsageStats.Bucket();
  public static class NetworkStats.Bucket {
    ctor public NetworkStats.Bucket();
    method public long getEndTimeStamp();
    method public long getRxBytes();
    method public long getRxPackets();
@@ -6085,10 +6077,19 @@ package android.app.usage {
    field public static final int STATE_ALL = -1; // 0xffffffff
    field public static final int STATE_DEFAULT = 1; // 0x1
    field public static final int STATE_FOREGROUND = 2; // 0x2
    field public static final int UID_ALL = -1; // 0xffffffff
    field public static final int UID_REMOVED = -4; // 0xfffffffc
    field public static final int UID_TETHERING = -5; // 0xfffffffb
  }
  public class NetworkStatsManager {
    method public android.app.usage.NetworkStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class UsageEvents implements android.os.Parcelable {
    method public int describeContents();
    method public boolean getNextEvent(android.app.usage.UsageEvents.Event);
+13 −12
Original line number Diff line number Diff line
@@ -6249,22 +6249,14 @@ package android.app.usage {
    field public static final android.os.Parcelable.Creator<android.app.usage.ConfigurationStats> CREATOR;
  }
  public class NetworkStatsManager {
    method public android.app.usage.NetworkUsageStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkUsageStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class NetworkUsageStats implements java.lang.AutoCloseable {
  public final class NetworkStats implements java.lang.AutoCloseable {
    method public void close();
    method public boolean getNextBucket(android.app.usage.NetworkUsageStats.Bucket);
    method public boolean getNextBucket(android.app.usage.NetworkStats.Bucket);
    method public boolean hasNextBucket();
  }
  public static class NetworkUsageStats.Bucket {
    ctor public NetworkUsageStats.Bucket();
  public static class NetworkStats.Bucket {
    ctor public NetworkStats.Bucket();
    method public long getEndTimeStamp();
    method public long getRxBytes();
    method public long getRxPackets();
@@ -6276,10 +6268,19 @@ package android.app.usage {
    field public static final int STATE_ALL = -1; // 0xffffffff
    field public static final int STATE_DEFAULT = 1; // 0x1
    field public static final int STATE_FOREGROUND = 2; // 0x2
    field public static final int UID_ALL = -1; // 0xffffffff
    field public static final int UID_REMOVED = -4; // 0xfffffffc
    field public static final int UID_TETHERING = -5; // 0xfffffffb
  }
  public class NetworkStatsManager {
    method public android.app.usage.NetworkStats queryDetails(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats queryDetailsForUid(int, java.lang.String, long, long, int) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats querySummary(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats.Bucket querySummaryForDevice(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
    method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class UsageEvents implements android.os.Parcelable {
    method public int describeContents();
    method public boolean getNextEvent(android.app.usage.UsageEvents.Event);
+20 −15
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.app.usage;
import android.content.Context;
import android.net.INetworkStatsService;
import android.net.INetworkStatsSession;
import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate;
import android.net.TrafficStats;
@@ -33,7 +32,7 @@ import dalvik.system.CloseGuard;
 * Class providing enumeration over buckets of network usage statistics. NetworkUsageStats objects
 * are returned as results to various queries in {@link NetworkStatsManager}.
 */
public final class NetworkUsageStats implements AutoCloseable {
public final class NetworkStats implements AutoCloseable {
    private final static String TAG = "NetworkUsageStats";

    private final CloseGuard mCloseGuard = CloseGuard.get();
@@ -70,7 +69,7 @@ public final class NetworkUsageStats implements AutoCloseable {
    /**
     * Results of a summary query.
     */
    private NetworkStats mSummary = null;
    private android.net.NetworkStats mSummary = null;

    /**
     * Results of detail queries.
@@ -85,11 +84,11 @@ public final class NetworkUsageStats implements AutoCloseable {
    /**
     * Recycling entry objects to prevent heap fragmentation.
     */
    private NetworkStats.Entry mRecycledSummaryEntry = null;
    private android.net.NetworkStats.Entry mRecycledSummaryEntry = null;
    private NetworkStatsHistory.Entry mRecycledHistoryEntry = null;

    /** @hide */
    NetworkUsageStats(Context context, NetworkTemplate template, long startTimestamp,
    NetworkStats(Context context, NetworkTemplate template, long startTimestamp,
            long endTimestamp) throws RemoteException, SecurityException {
        final INetworkStatsService statsService = INetworkStatsService.Stub.asInterface(
                ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
@@ -135,15 +134,20 @@ public final class NetworkUsageStats implements AutoCloseable {
         */
        public static final int STATE_FOREGROUND = 0x2;

        /**
         * Special UID value for aggregate/unspecified.
         */
        public static final int UID_ALL = android.net.NetworkStats.UID_ALL;

        /**
         * Special UID value for removed apps.
         */
        public static final int UID_REMOVED = -4;
        public static final int UID_REMOVED = TrafficStats.UID_REMOVED;

        /**
         * Special UID value for data usage by tethering.
         */
        public static final int UID_TETHERING = -5;
        public static final int UID_TETHERING = TrafficStats.UID_TETHERING;

        private int mUid;
        private int mState;
@@ -156,9 +160,9 @@ public final class NetworkUsageStats implements AutoCloseable {

        private static int convertState(int networkStatsSet) {
            switch (networkStatsSet) {
                case NetworkStats.SET_ALL : return STATE_ALL;
                case NetworkStats.SET_DEFAULT : return STATE_DEFAULT;
                case NetworkStats.SET_FOREGROUND : return STATE_FOREGROUND;
                case android.net.NetworkStats.SET_ALL : return STATE_ALL;
                case android.net.NetworkStats.SET_DEFAULT : return STATE_DEFAULT;
                case android.net.NetworkStats.SET_FOREGROUND : return STATE_FOREGROUND;
            }
            return 0;
        }
@@ -337,8 +341,8 @@ public final class NetworkUsageStats implements AutoCloseable {
    void startHistoryEnumeration(int uid) {
        mHistory = null;
        try {
            mHistory = mSession.getHistoryForUid(mTemplate, uid, NetworkStats.SET_ALL,
                    NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
            mHistory = mSession.getHistoryForUid(mTemplate, uid, android.net.NetworkStats.SET_ALL,
                    android.net.NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
            setSingleUid(uid);
        } catch (RemoteException e) {
            Log.w(TAG, e);
@@ -364,8 +368,9 @@ public final class NetworkUsageStats implements AutoCloseable {
            stepUid();
            mHistory = null;
            try {
                mHistory = mSession.getHistoryForUid(mTemplate, getUid(), NetworkStats.SET_ALL,
                        NetworkStats.TAG_NONE, NetworkStatsHistory.FIELD_ALL);
                mHistory = mSession.getHistoryForUid(mTemplate, getUid(),
                        android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE,
                        NetworkStatsHistory.FIELD_ALL);
            } catch (RemoteException e) {
                Log.w(TAG, e);
                // Leaving mHistory null
@@ -405,7 +410,7 @@ public final class NetworkUsageStats implements AutoCloseable {
        }
        Bucket bucket = new Bucket();
        if (mRecycledSummaryEntry == null) {
            mRecycledSummaryEntry = new NetworkStats.Entry();
            mRecycledSummaryEntry = new android.net.NetworkStats.Entry();
        }
        mSummary.getTotal(mRecycledSummaryEntry);
        fillBucketFromSummaryEntry(bucket);
+36 −20
Original line number Diff line number Diff line
@@ -16,18 +16,17 @@

package android.app.usage;

import android.app.usage.NetworkUsageStats.Bucket;
import android.app.usage.NetworkStats.Bucket;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkIdentity;
import android.net.NetworkTemplate;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;

/**
 * Provides access to network usage history and statistics. Usage data is collected in
 * discrete bins of time called 'Buckets'. See {@link NetworkUsageStats.Bucket} for details.
 * discrete bins of time called 'Buckets'. See {@link NetworkStats.Bucket} for details.
 * <p />
 * Queries can define a time interval in the form of start and end timestamps (Long.MIN_VALUE and
 * Long.MAX_VALUE can be used to simulate open ended intervals). All queries (except
@@ -37,15 +36,20 @@ import android.util.Log;
 * <h3>
 * Summary queries
 * </h3>
 * {@link #querySummaryForDevice} <p />
 * {@link #querySummaryForUser} <p />
 * {@link #querySummary} <p />
 * These queries aggregate network usage across the whole interval. Therefore there will be only one
 * bucket for a particular key and state combination. In case of the user-wide and device-wide
 * summaries a single bucket containing the totalised network usage is returned.
 * <h3>
 * History queries
 * </h3>
 * {@link #queryDetailsForUid} <p />
 * {@link #queryDetails} <p />
 * These queries do not aggregate over time but do aggregate over state. Therefore there can be
 * multiple buckets for a particular key but all Bucket's state is going to be
 * {@link NetworkUsageStats.Bucket#STATE_ALL}.
 * {@link NetworkStats.Bucket#STATE_ALL}.
 * <p />
 * <b>NOTE:</b> This API requires the permission
 * {@link android.Manifest.permission#PACKAGE_USAGE_STATS}, which is a system-level permission and
@@ -68,7 +72,10 @@ public class NetworkStatsManager {
    }
    /**
     * Query network usage statistics summaries. Result is summarised data usage for the whole
     * device. Result is a single Bucket aggregated over time, state and uid.
     * device. Result is a single Bucket aggregated over time, state and uid. This means the
     * bucket's start and end timestamp are going to be the same as the 'startTime' and 'endTime'
     * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
     * {@link NetworkStats.Bucket#UID_ALL}.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -89,7 +96,7 @@ public class NetworkStatsManager {
        }

        Bucket bucket = null;
        NetworkUsageStats stats = new NetworkUsageStats(mContext, template, startTime, endTime);
        NetworkStats stats = new NetworkStats(mContext, template, startTime, endTime);
        bucket = stats.getDeviceSummaryForNetwork(startTime, endTime);

        stats.close();
@@ -99,6 +106,9 @@ public class NetworkStatsManager {
    /**
     * Query network usage statistics summaries. Result is summarised data usage for all uids
     * belonging to calling user. Result is a single Bucket aggregated over time, state and uid.
     * This means the bucket's start and end timestamp are going to be the same as the 'startTime' 
     * and 'endTime' parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid
     * {@link NetworkStats.Bucket#UID_ALL}.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -118,8 +128,8 @@ public class NetworkStatsManager {
            return null;
        }

        NetworkUsageStats stats;
        stats = new NetworkUsageStats(mContext, template, startTime, endTime);
        NetworkStats stats;
        stats = new NetworkStats(mContext, template, startTime, endTime);
        stats.startSummaryEnumeration(startTime, endTime);

        stats.close();
@@ -129,7 +139,9 @@ public class NetworkStatsManager {
    /**
     * Query network usage statistics summaries. Result filtered to include only uids belonging to
     * calling user. Result is aggregated over time, hence all buckets will have the same start and
     * end timestamps. Not aggregated over state or uid.
     * end timestamps. Not aggregated over state or uid. This means buckets' start and end
     * timestamps are going to be the same as the 'startTime' and 'endTime' parameters, state and 
     * uid are going to vary.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -142,15 +154,15 @@ public class NetworkStatsManager {
     * @return Statistics object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public NetworkUsageStats querySummary(int networkType, String subscriberId, long startTime,
    public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
        }

        NetworkUsageStats result;
        result = new NetworkUsageStats(mContext, template, startTime, endTime);
        NetworkStats result;
        result = new NetworkStats(mContext, template, startTime, endTime);
        result.startSummaryEnumeration(startTime, endTime);

        return result;
@@ -158,7 +170,9 @@ public class NetworkStatsManager {

    /**
     * Query network usage statistics details. Only usable for uids belonging to calling user.
     * Result is aggregated over state but not aggregated over time.
     * Result is aggregated over state but not aggregated over time. This means buckets' start and
     * end timestamps are going to be between 'startTime' and 'endTime' parameters, state is going
     * to be {@link NetworkStats.Bucket#STATE_ALL} and uid the same as the 'uid' parameter.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -172,15 +186,15 @@ public class NetworkStatsManager {
     * @return Statistics object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public NetworkUsageStats queryDetailsForUid(int networkType, String subscriberId,
    public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
            long startTime, long endTime, int uid) throws SecurityException, RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
        }

        NetworkUsageStats result;
        result = new NetworkUsageStats(mContext, template, startTime, endTime);
        NetworkStats result;
        result = new NetworkStats(mContext, template, startTime, endTime);
        result.startHistoryEnumeration(uid);

        return result;
@@ -188,7 +202,9 @@ public class NetworkStatsManager {

    /**
     * Query network usage statistics details. Result filtered to include only uids belonging to
     * calling user. Result is aggregated over state but not aggregated over time or uid.
     * calling user. Result is aggregated over state but not aggregated over time or uid. This means
     * buckets' start and end timestamps are going to be between 'startTime' and 'endTime'
     * parameters, state is going to be {@link NetworkStats.Bucket#STATE_ALL} and uid will vary.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -201,14 +217,14 @@ public class NetworkStatsManager {
     * @return Statistics object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public NetworkUsageStats queryDetails(int networkType, String subscriberId, long startTime,
    public NetworkStats queryDetails(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
        }
        NetworkUsageStats result;
        result = new NetworkUsageStats(mContext, template, startTime, endTime);
        NetworkStats result;
        result = new NetworkStats(mContext, template, startTime, endTime);
        result.startUserUidEnumeration();
        return result;
    }