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

Commit 89270a44 authored by Antonio Cansado's avatar Antonio Cansado Committed by Android (Google) Code Review
Browse files

Merge "Retuning tag information through NetworkStatsManager."

parents 58869d2c 46c75367
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6329,6 +6329,7 @@ package android.app.usage {
    method public long getRxPackets();
    method public long getStartTimeStamp();
    method public int getState();
    method public int getTag();
    method public long getTxBytes();
    method public long getTxPackets();
    method public int getUid();
@@ -6338,6 +6339,8 @@ 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 TAG_ALL = 0; // 0x0
    field public static final int TAG_ANY = -1; // 0xffffffff
    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
@@ -6346,9 +6349,12 @@ package android.app.usage {
  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 queryDetailsForUidTag(int, java.lang.String, long, long, int, 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 querySummary(int, java.lang.String, long, long, boolean) 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;
    method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class UsageEvents implements android.os.Parcelable {
+6 −0
Original line number Diff line number Diff line
@@ -6586,6 +6586,7 @@ package android.app.usage {
    method public long getRxPackets();
    method public long getStartTimeStamp();
    method public int getState();
    method public int getTag();
    method public long getTxBytes();
    method public long getTxPackets();
    method public int getUid();
@@ -6595,6 +6596,8 @@ 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 TAG_ALL = 0; // 0x0
    field public static final int TAG_ANY = -1; // 0xffffffff
    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
@@ -6603,9 +6606,12 @@ package android.app.usage {
  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 queryDetailsForUidTag(int, java.lang.String, long, long, int, 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 querySummary(int, java.lang.String, long, long, boolean) 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;
    method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class UsageEvents implements android.os.Parcelable {
+6 −0
Original line number Diff line number Diff line
@@ -6331,6 +6331,7 @@ package android.app.usage {
    method public long getRxPackets();
    method public long getStartTimeStamp();
    method public int getState();
    method public int getTag();
    method public long getTxBytes();
    method public long getTxPackets();
    method public int getUid();
@@ -6340,6 +6341,8 @@ 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 TAG_ALL = 0; // 0x0
    field public static final int TAG_ANY = -1; // 0xffffffff
    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
@@ -6348,9 +6351,12 @@ package android.app.usage {
  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 queryDetailsForUidTag(int, java.lang.String, long, long, int, 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 querySummary(int, java.lang.String, long, long, boolean) 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;
    method public android.app.usage.NetworkStats.Bucket querySummaryForUser(int, java.lang.String, long, long, boolean) throws android.os.RemoteException, java.lang.SecurityException;
  }
  public final class UsageEvents implements android.os.Parcelable {
+39 −5
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ public final class NetworkStats implements AutoCloseable {
     */
    private final long mEndTimeStamp;


    /**
     * Non-null array indicates the query enumerates over uids.
     */
@@ -165,7 +164,18 @@ public final class NetworkStats implements AutoCloseable {
         */
        public static final int ROAMING_ROAMING = 0x2;

        /**
         * Special TAG value matching any tag.
         */
        public static final int TAG_ANY = android.net.NetworkStats.TAG_ALL;

        /**
         * Special TAG value for total data across all tags
         */
        public static final int TAG_ALL = android.net.NetworkStats.TAG_NONE;

        private int mUid;
        private int mTag;
        private int mState;
        private int mRoaming;
        private long mBeginTimeStamp;
@@ -192,6 +202,14 @@ public final class NetworkStats implements AutoCloseable {
            return uid;
        }

        private static int convertTag(int tag) {
            switch (tag) {
                case android.net.NetworkStats.TAG_ALL: return TAG_ANY;
                case android.net.NetworkStats.TAG_NONE: return TAG_ALL;
            }
            return tag;
        }

        private static int convertRoaming(int roaming) {
            switch (roaming) {
                case android.net.NetworkStats.ROAMING_ALL : return ROAMING_ALL;
@@ -217,6 +235,14 @@ public final class NetworkStats implements AutoCloseable {
            return mUid;
        }

        /**
         * Tag of the bucket.<p />
         * @return Bucket tag.
         */
        public int getTag() {
            return mTag;
        }

        /**
         * Usage state. One of the following values:<p/>
         * <ul>
@@ -363,9 +389,9 @@ public final class NetworkStats implements AutoCloseable {
     * Collects summary results and sets summary enumeration mode.
     * @throws RemoteException
     */
    void startSummaryEnumeration() throws RemoteException {
        mSummary = mSession.getSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp, false);

    void startSummaryEnumeration(boolean includeTags) throws RemoteException {
        mSummary = mSession.getSummaryForAllUid(mTemplate, mStartTimeStamp, mEndTimeStamp,
                includeTags);
        mEnumerationIndex = 0;
    }

@@ -373,10 +399,17 @@ public final class NetworkStats implements AutoCloseable {
     * Collects history results for uid and resets history enumeration index.
     */
    void startHistoryEnumeration(int uid) {
        startHistoryEnumeration(uid, android.net.NetworkStats.TAG_NONE);
    }

    /**
     * Collects history results for uid and resets history enumeration index.
     */
    void startHistoryEnumeration(int uid, int tag) {
        mHistory = null;
        try {
            mHistory = mSession.getHistoryIntervalForUid(mTemplate, uid,
                    android.net.NetworkStats.SET_ALL, android.net.NetworkStats.TAG_NONE,
                    android.net.NetworkStats.SET_ALL, tag,
                    NetworkStatsHistory.FIELD_ALL, mStartTimeStamp, mEndTimeStamp);
            setSingleUid(uid);
        } catch (RemoteException e) {
@@ -434,6 +467,7 @@ public final class NetworkStats implements AutoCloseable {

    private void fillBucketFromSummaryEntry(Bucket bucketOut) {
        bucketOut.mUid = Bucket.convertUid(mRecycledSummaryEntry.uid);
        bucketOut.mTag = Bucket.convertTag(mRecycledSummaryEntry.tag);
        bucketOut.mState = Bucket.convertState(mRecycledSummaryEntry.set);
        bucketOut.mRoaming = Bucket.convertRoaming(mRecycledSummaryEntry.roaming);
        bucketOut.mBeginTimeStamp = mStartTimeStamp;
+64 −23
Original line number Diff line number Diff line
@@ -82,10 +82,11 @@ 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. 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}, uid
     * {@link NetworkStats.Bucket#UID_ALL}, and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
     * device. Result is a single Bucket aggregated over time, state, uid, tag and roaming. 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}, uid
     * {@link NetworkStats.Bucket#UID_ALL}, tag {@link NetworkStats.Bucket#TAG_ALL}
     * and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -113,12 +114,23 @@ public class NetworkStatsManager {
        return bucket;
    }

    /**
     * Query network usage statistics summaries aggregated across tags.
     *
     * #see querySummaryForUser(int, String, long, long, boolean)
     */
    public Bucket querySummaryForUser(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
        return querySummaryForUser(networkType, subscriberId, startTime, endTime,
            false /* includeTags */);
    }

    /**
     * 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}, uid
     * {@link NetworkStats.Bucket#UID_ALL}, and roaming {@link NetworkStats.Bucket#ROAMING_ALL}.
     * 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}
@@ -128,11 +140,13 @@ public class NetworkStatsManager {
     *            {@link java.lang.System#currentTimeMillis}.
     * @param endTime End of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @param includeTags whether to include network tags. If {@code true}, tags will be returned
     *            and history retention may be shorter.
     * @return Bucket object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public Bucket querySummaryForUser(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
            long endTime, boolean includeTags) throws SecurityException, RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
@@ -140,18 +154,28 @@ public class NetworkStatsManager {

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

        stats.close();
        return stats.getSummaryAggregate();
    }

    /**
     * Query network usage statistics summaries aggregated across tags.
     *
     * #see querySummary(int, String, long, long, boolean)
     */
    public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
        return querySummary(networkType, subscriberId, startTime, endTime, false /* includeTags */);
    }

    /**
     * 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, uid, or roaming. 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.
     * end timestamps. Not aggregated over state or uid or tag. This means buckets' start and end
     * timestamps are going to be the same as the 'startTime' and 'endTime' parameters. State,
     * uid and tag are going to vary.
     *
     * @param networkType As defined in {@link ConnectivityManager}, e.g.
     *            {@link ConnectivityManager#TYPE_MOBILE}, {@link ConnectivityManager#TYPE_WIFI}
@@ -161,11 +185,13 @@ public class NetworkStatsManager {
     *            {@link java.lang.System#currentTimeMillis}.
     * @param endTime End of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @param includeTags whether to include network tags. If {@code true}, tags will be returned
     *            and history retention may be shorter.
     * @return Statistics object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public NetworkStats querySummary(int networkType, String subscriberId, long startTime,
            long endTime) throws SecurityException, RemoteException {
            long endTime, boolean includeTags) throws SecurityException, RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
@@ -173,17 +199,28 @@ public class NetworkStatsManager {

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

        return result;
    }

    /**
     * Query network usage statistics details. Only usable for uids belonging to calling user.
     * 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. roaming
     * is going to be {@link NetworkStats.Bucket#ROAMING_ALL}.
     * Query network usage statistics details for a given uid.
     *
     * #see queryDetailsForUidTag(int, String, long, long, int, int)
     */
    public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
            long startTime, long endTime, int uid) throws SecurityException, RemoteException {
        return queryDetailsForUidTag(networkType, subscriberId, startTime, endTime, uid,
            NetworkStats.Bucket.TAG_ALL);
    }

    /**
     * Query network usage statistics details for a given uid and tag. Only usable for uids
     * belonging to calling user. 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}, uid the
     * same as the 'uid' parameter and tag the same as 'tag' parameter.
     * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't
     * interpolate across partial buckets. Since bucket length is in the order of hours, this
     * method cannot be used to measure data usage on a fine grained time scale.
@@ -197,11 +234,14 @@ public class NetworkStatsManager {
     * @param endTime End of period. Defined in terms of "Unix time", see
     *            {@link java.lang.System#currentTimeMillis}.
     * @param uid UID of app
     * @param tag TAG of interest. Use {@link NetworkStats.Bucket#TAG_ANY} for any tags, use
     *            {@link NetworkStats.Bucket#TAG_ALL} to aggregate over tags.
     * @return Statistics object or null if permissions are insufficient or error happened during
     *         statistics collection.
     */
    public NetworkStats queryDetailsForUid(int networkType, String subscriberId,
            long startTime, long endTime, int uid) throws SecurityException, RemoteException {
    public NetworkStats queryDetailsForUidTag(int networkType, String subscriberId,
            long startTime, long endTime, int uid, int tag) throws SecurityException,
            RemoteException {
        NetworkTemplate template = createTemplate(networkType, subscriberId);
        if (template == null) {
            return null;
@@ -209,7 +249,7 @@ public class NetworkStatsManager {

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

        return result;
    }
@@ -218,8 +258,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. 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.
     * roaming is going to be {@link NetworkStats.Bucket#ROAMING_ALL}.
     * parameters. State is going to be {@link NetworkStats.Bucket#STATE_ALL}, uid will vary,
     * tag {@link NetworkStats.Bucket#TAG_ALL} and roaming is going to be
     * {@link NetworkStats.Bucket#ROAMING_ALL}.
     * <p>Only includes buckets that atomically occur in the inclusive time range. Doesn't
     * interpolate across partial buckets. Since bucket length is in the order of hours, this
     * method cannot be used to measure data usage on a fine grained time scale.
Loading