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

Commit 941b8579 authored by Jeff Davidson's avatar Jeff Davidson Committed by android-build-merger
Browse files

Merge "NetworkStats.Bucket API polish." into nyc-dev am: 1c0c14fe

am: cb4ad154

* commit 'cb4ad154':
  NetworkStats.Bucket API polish.
parents 5ede839e cb4ad154
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6377,8 +6377,8 @@ package android.app.usage {
    method public long getTxPackets();
    method public int getUid();
    field public static final int ROAMING_ALL = -1; // 0xffffffff
    field public static final int ROAMING_DEFAULT = 1; // 0x1
    field public static final int ROAMING_ROAMING = 2; // 0x2
    field public static final int ROAMING_NO = 1; // 0x1
    field public static final int ROAMING_YES = 2; // 0x2
    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
+2 −2
Original line number Diff line number Diff line
@@ -6643,8 +6643,8 @@ package android.app.usage {
    method public long getTxPackets();
    method public int getUid();
    field public static final int ROAMING_ALL = -1; // 0xffffffff
    field public static final int ROAMING_DEFAULT = 1; // 0x1
    field public static final int ROAMING_ROAMING = 2; // 0x2
    field public static final int ROAMING_NO = 1; // 0x1
    field public static final int ROAMING_YES = 2; // 0x2
    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
+2 −2
Original line number Diff line number Diff line
@@ -6381,8 +6381,8 @@ package android.app.usage {
    method public long getTxPackets();
    method public int getUid();
    field public static final int ROAMING_ALL = -1; // 0xffffffff
    field public static final int ROAMING_DEFAULT = 1; // 0x1
    field public static final int ROAMING_ROAMING = 2; // 0x2
    field public static final int ROAMING_NO = 1; // 0x1
    field public static final int ROAMING_YES = 2; // 0x2
    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
+36 −13
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.app.usage;

import android.annotation.IntDef;
import android.content.Context;
import android.net.INetworkStatsService;
import android.net.INetworkStatsSession;
@@ -29,6 +30,9 @@ import android.util.Log;

import dalvik.system.CloseGuard;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Class providing enumeration over buckets of network usage statistics. {@link NetworkStats} objects
 * are returned as results to various queries in {@link NetworkStatsManager}.
@@ -119,6 +123,11 @@ public final class NetworkStats implements AutoCloseable {
     * aggregated (e.g. time or state) some values may be equal across all buckets.
     */
    public static class Bucket {
        /** @hide */
        @IntDef({STATE_ALL, STATE_DEFAULT, STATE_FOREGROUND})
        @Retention(RetentionPolicy.SOURCE)
        public @interface State {}

        /**
         * Combined usage across all states.
         */
@@ -149,20 +158,34 @@ public final class NetworkStats implements AutoCloseable {
         */
        public static final int UID_TETHERING = TrafficStats.UID_TETHERING;

        /** @hide */
        @IntDef({ROAMING_ALL, ROAMING_NO, ROAMING_YES})
        @Retention(RetentionPolicy.SOURCE)
        public @interface Roaming {}

        /**
         * Combined usage across all roaming states.
         * Combined usage across all roaming states. Covers both roaming and non-roaming usage.
         */
        public static final int ROAMING_ALL = -1;

        /**
         * Usage not accounted for in any other roaming state.
         * Usage that occurs on a home, non-roaming network.
         *
         * <p>Any cellular usage in this bucket was incurred while the device was connected to a
         * tower owned or operated by the user's wireless carrier, or a tower that the user's
         * wireless carrier has indicated should be treated as a home network regardless.
         *
         * <p>This is also the default value for network types that do not support roaming.
         */
        public static final int ROAMING_DEFAULT = 0x1;
        public static final int ROAMING_NO = 0x1;

        /**
         * Roaming usage.
         * Usage that occurs on a roaming network.
         *
         * <p>Any cellular usage in this bucket as incurred while the device was roaming on another
         * carrier's network, for which additional charges may apply.
         */
        public static final int ROAMING_ROAMING = 0x2;
        public static final int ROAMING_YES = 0x2;

        /**
         * Special TAG value matching any tag.
@@ -185,7 +208,7 @@ public final class NetworkStats implements AutoCloseable {
        private long mTxBytes;
        private long mTxPackets;

        private static int convertState(int networkStatsSet) {
        private static @State int convertState(int networkStatsSet) {
            switch (networkStatsSet) {
                case android.net.NetworkStats.SET_ALL : return STATE_ALL;
                case android.net.NetworkStats.SET_DEFAULT : return STATE_DEFAULT;
@@ -210,11 +233,11 @@ public final class NetworkStats implements AutoCloseable {
            return tag;
        }

        private static int convertRoaming(int roaming) {
        private static @Roaming int convertRoaming(int roaming) {
            switch (roaming) {
                case android.net.NetworkStats.ROAMING_ALL : return ROAMING_ALL;
                case android.net.NetworkStats.ROAMING_DEFAULT : return ROAMING_DEFAULT;
                case android.net.NetworkStats.ROAMING_ROAMING : return ROAMING_ROAMING;
                case android.net.NetworkStats.ROAMING_NO: return ROAMING_NO;
                case android.net.NetworkStats.ROAMING_YES: return ROAMING_YES;
            }
            return 0;
        }
@@ -252,7 +275,7 @@ public final class NetworkStats implements AutoCloseable {
         * </ul>
         * @return Usage state.
         */
        public int getState() {
        public @State int getState() {
            return mState;
        }

@@ -260,11 +283,11 @@ public final class NetworkStats implements AutoCloseable {
         * Roaming state. One of the following values:<p/>
         * <ul>
         * <li>{@link #ROAMING_ALL}</li>
         * <li>{@link #ROAMING_DEFAULT}</li>
         * <li>{@link #ROAMING_ROAMING}</li>
         * <li>{@link #ROAMING_NO}</li>
         * <li>{@link #ROAMING_YES}</li>
         * </ul>
         */
        public int getRoaming() {
        public @Roaming int getRoaming() {
            return mRoaming;
        }

+10 −10
Original line number Diff line number Diff line
@@ -71,9 +71,9 @@ public class NetworkStats implements Parcelable {
    /** {@link #set} value for all roaming values. */
    public static final int ROAMING_ALL = -1;
    /** {@link #set} value where native, non-roaming data is accounted. */
    public static final int ROAMING_DEFAULT = 0;
    public static final int ROAMING_NO = 0;
    /** {@link #set} value where roaming data is accounted. */
    public static final int ROAMING_ROAMING = 1;
    public static final int ROAMING_YES = 1;

    // TODO: move fields to "mVariable" notation

@@ -123,7 +123,7 @@ public class NetworkStats implements Parcelable {

        public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets,
                long txBytes, long txPackets, long operations) {
            this(iface, uid, set, tag, ROAMING_DEFAULT, rxBytes, rxPackets, txBytes, txPackets,
            this(iface, uid, set, tag, ROAMING_NO, rxBytes, rxPackets, txBytes, txPackets,
                    operations);
        }

@@ -836,10 +836,10 @@ public class NetworkStats implements Parcelable {
        switch (roaming) {
            case ROAMING_ALL:
                return "ALL";
            case ROAMING_DEFAULT:
                return "DEFAULT";
            case ROAMING_ROAMING:
                return "ROAMING";
            case ROAMING_NO:
                return "NO";
            case ROAMING_YES:
                return "YES";
            default:
                return "UNKNOWN";
        }
@@ -1019,18 +1019,18 @@ public class NetworkStats implements Parcelable {
        // Caveat: if the vpn software uses tag, the total tagged traffic may be greater than
        // the TAG_NONE traffic.
        //
        // Relies on the fact that the underlying traffic only has state ROAMING_DEFAULT, which
        // Relies on the fact that the underlying traffic only has state ROAMING_NO, which
        // should be the case as it comes directly from the /proc file. We only blend in the
        // roaming data after applying these adjustments, by checking the NetworkIdentity of the
        // underlying iface.
        int idxVpnBackground = findIndex(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE,
                ROAMING_DEFAULT);
                ROAMING_NO);
        if (idxVpnBackground != -1) {
            tunSubtract(idxVpnBackground, this, moved);
        }

        int idxVpnForeground = findIndex(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE,
                ROAMING_DEFAULT);
                ROAMING_NO);
        if (idxVpnForeground != -1) {
            tunSubtract(idxVpnForeground, this, moved);
        }
Loading