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

Commit 80c372ce authored by Junyu Lai's avatar Junyu Lai Committed by Automerger Merge Worker
Browse files

Merge changes from topic "ms57-migrationapi" am: 159be51d am: c207cac6 am:...

Merge changes from topic "ms57-migrationapi" am: 159be51d am: c207cac6 am: b32de775 am: 6ca5d475

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1951477

Change-Id: I4d3e51cc7c2c9ab4ae85a5e03839219b73df2525
parents 219437f1 6ca5d475
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -125,6 +125,19 @@ public class NetworkStatsManager {
    private final Context mContext;
    private final INetworkStatsService mService;

    /**
     * Type constants for reading different types of Data Usage.
     * @hide
     */
    // @SystemApi(client = MODULE_LIBRARIES)
    public static final String PREFIX_DEV = "dev";
    /** @hide */
    public static final String PREFIX_XT = "xt";
    /** @hide */
    public static final String PREFIX_UID = "uid";
    /** @hide */
    public static final String PREFIX_UID_TAG = "uid_tag";

    /** @hide */
    public static final int FLAG_POLL_ON_OPEN = 1 << 0;
    /** @hide */
+62 −34
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@
package android.net;

import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.service.NetworkIdentityProto;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation;
import android.telephony.TelephonyManager;
import android.util.proto.ProtoOutputStream;

import com.android.net.module.util.NetworkCapabilitiesUtils;
@@ -37,9 +40,13 @@ import java.util.Objects;
 *
 * @hide
 */
// @SystemApi(client = MODULE_LIBRARIES)
public class NetworkIdentity implements Comparable<NetworkIdentity> {
    private static final String TAG = "NetworkIdentity";

    /** @hide */
    // TODO: Remove this after migrating all callers to use
    //  {@link NetworkTemplate#NETWORK_TYPE_ALL} instead.
    public static final int SUBTYPE_COMBINED = -1;

    /**
@@ -59,21 +66,22 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
    public static final int OEM_PRIVATE = 0x2;

    final int mType;
    final int mSubType;
    final int mRatType;
    final String mSubscriberId;
    final String mNetworkId;
    final String mWifiNetworkKey;
    final boolean mRoaming;
    final boolean mMetered;
    final boolean mDefaultNetwork;
    final int mOemManaged;

    /** @hide */
    public NetworkIdentity(
            int type, int subType, String subscriberId, String networkId, boolean roaming,
            boolean metered, boolean defaultNetwork, int oemManaged) {
            int type, int ratType, @Nullable String subscriberId, @Nullable String wifiNetworkKey,
            boolean roaming, boolean metered, boolean defaultNetwork, int oemManaged) {
        mType = type;
        mSubType = subType;
        mRatType = ratType;
        mSubscriberId = subscriberId;
        mNetworkId = networkId;
        mWifiNetworkKey = wifiNetworkKey;
        mRoaming = roaming;
        mMetered = metered;
        mDefaultNetwork = defaultNetwork;
@@ -82,7 +90,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {

    @Override
    public int hashCode() {
        return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered,
        return Objects.hash(mType, mRatType, mSubscriberId, mWifiNetworkKey, mRoaming, mMetered,
                mDefaultNetwork, mOemManaged);
    }

@@ -90,9 +98,9 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof NetworkIdentity) {
            final NetworkIdentity ident = (NetworkIdentity) obj;
            return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
            return mType == ident.mType && mRatType == ident.mRatType && mRoaming == ident.mRoaming
                    && Objects.equals(mSubscriberId, ident.mSubscriberId)
                    && Objects.equals(mNetworkId, ident.mNetworkId)
                    && Objects.equals(mWifiNetworkKey, ident.mWifiNetworkKey)
                    && mMetered == ident.mMetered
                    && mDefaultNetwork == ident.mDefaultNetwork
                    && mOemManaged == ident.mOemManaged;
@@ -104,18 +112,18 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
    public String toString() {
        final StringBuilder builder = new StringBuilder("{");
        builder.append("type=").append(mType);
        builder.append(", subType=");
        if (mSubType == SUBTYPE_COMBINED) {
        builder.append(", ratType=");
        if (mRatType == NETWORK_TYPE_ALL) {
            builder.append("COMBINED");
        } else {
            builder.append(mSubType);
            builder.append(mRatType);
        }
        if (mSubscriberId != null) {
            builder.append(", subscriberId=")
                    .append(NetworkIdentityUtils.scrubSubscriberId(mSubscriberId));
        }
        if (mNetworkId != null) {
            builder.append(", networkId=").append(mNetworkId);
        if (mWifiNetworkKey != null) {
            builder.append(", wifiNetworkKey=").append(mWifiNetworkKey);
        }
        if (mRoaming) {
            builder.append(", ROAMING");
@@ -153,12 +161,13 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        }
    }

    /** @hide */
    public void dumpDebug(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);

        proto.write(NetworkIdentityProto.TYPE, mType);

        // Not dumping mSubType, subtypes are no longer supported.
        // TODO: dump mRatType as well.

        proto.write(NetworkIdentityProto.ROAMING, mRoaming);
        proto.write(NetworkIdentityProto.METERED, mMetered);
@@ -168,50 +177,68 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
        proto.end(start);
    }

    /** @hide */
    public int getType() {
        return mType;
    }

    public int getSubType() {
        return mSubType;
    /** @hide */
    public int getRatType() {
        return mRatType;
    }

    /** @hide */
    public String getSubscriberId() {
        return mSubscriberId;
    }

    public String getNetworkId() {
        return mNetworkId;
    /** @hide */
    public String getWifiNetworkKey() {
        return mWifiNetworkKey;
    }

    /** @hide */
    public boolean getRoaming() {
        return mRoaming;
    }

    /** @hide */
    public boolean getMetered() {
        return mMetered;
    }

    /** @hide */
    public boolean getDefaultNetwork() {
        return mDefaultNetwork;
    }

    /** @hide */
    public int getOemManaged() {
        return mOemManaged;
    }

    /**
     * Build a {@link NetworkIdentity} from the given {@link NetworkStateSnapshot} and
     * {@code subType}, assuming that any mobile networks are using the current IMSI.
     * The subType if applicable, should be set as one of the TelephonyManager.NETWORK_TYPE_*
     * constants, or {@link android.telephony.TelephonyManager#NETWORK_TYPE_UNKNOWN} if not.
     * Assemble a {@link NetworkIdentity} from the passed arguments.
     *
     * This methods builds an identity based on the capabilities of the network in the
     * snapshot and other passed arguments. The identity is used as a key to record data usage.
     *
     * @param snapshot the snapshot of network state. See {@link NetworkStateSnapshot}.
     * @param defaultNetwork whether the network is a default network.
     * @param ratType the Radio Access Technology(RAT) type of the network. Or
     *                {@link TelephonyManager#NETWORK_TYPE_UNKNOWN} if not applicable.
     *                See {@code TelephonyManager.NETWORK_TYPE_*}.
     * @hide
     */
    // TODO: Remove this after all callers are migrated to use new Api.
    @NonNull
    public static NetworkIdentity buildNetworkIdentity(Context context,
            NetworkStateSnapshot snapshot, boolean defaultNetwork, @NetworkType int subType) {
            @NonNull NetworkStateSnapshot snapshot,
            boolean defaultNetwork, @Annotation.NetworkType int ratType) {
        final int legacyType = snapshot.getLegacyType();

        final String subscriberId = snapshot.getSubscriberId();
        String networkId = null;
        String wifiNetworkKey = null;
        boolean roaming = !snapshot.getNetworkCapabilities().hasCapability(
                NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
        boolean metered = !(snapshot.getNetworkCapabilities().hasCapability(
@@ -226,19 +253,19 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
                    .getTransportInfo();
            if (transportInfo instanceof WifiInfo) {
                final WifiInfo info = (WifiInfo) transportInfo;
                networkId = info != null ? info.getCurrentNetworkKey() : null;
                wifiNetworkKey = info != null ? info.getCurrentNetworkKey() : null;
            }
        }

        return new NetworkIdentity(legacyType, subType, subscriberId, networkId, roaming, metered,
                defaultNetwork, oemManaged);
        return new NetworkIdentity(legacyType, ratType, subscriberId, wifiNetworkKey, roaming,
                metered, defaultNetwork, oemManaged);
    }

    /**
     * Builds a bitfield of {@code NetworkIdentity.OEM_*} based on {@link NetworkCapabilities}.
     * @hide
     */
    public static int getOemBitfield(NetworkCapabilities nc) {
    public static int getOemBitfield(@NonNull NetworkCapabilities nc) {
        int oemManaged = OEM_NONE;

        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID)) {
@@ -252,16 +279,17 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
    }

    @Override
    public int compareTo(NetworkIdentity another) {
    public int compareTo(@NonNull NetworkIdentity another) {
        Objects.requireNonNull(another);
        int res = Integer.compare(mType, another.mType);
        if (res == 0) {
            res = Integer.compare(mSubType, another.mSubType);
            res = Integer.compare(mRatType, another.mRatType);
        }
        if (res == 0 && mSubscriberId != null && another.mSubscriberId != null) {
            res = mSubscriberId.compareTo(another.mSubscriberId);
        }
        if (res == 0 && mNetworkId != null && another.mNetworkId != null) {
            res = mNetworkId.compareTo(another.mNetworkId);
        if (res == 0 && mWifiNetworkKey != null && another.mWifiNetworkKey != null) {
            res = mWifiNetworkKey.compareTo(another.mWifiNetworkKey);
        }
        if (res == 0) {
            res = Boolean.compare(mRoaming, another.mRoaming);
+29 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.net;

import static android.net.ConnectivityManager.TYPE_MOBILE;

import android.annotation.NonNull;
import android.service.NetworkIdentitySetProto;
import android.util.proto.ProtoOutputStream;

@@ -25,6 +26,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;

/**
 * Identity of a {@code iface}, defined by the set of {@link NetworkIdentity}
@@ -32,6 +34,7 @@ import java.util.HashSet;
 *
 * @hide
 */
// @SystemApi(client = MODULE_LIBRARIES)
public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
        Comparable<NetworkIdentitySet> {
    private static final int VERSION_INIT = 1;
@@ -41,9 +44,14 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
    private static final int VERSION_ADD_DEFAULT_NETWORK = 5;
    private static final int VERSION_ADD_OEM_MANAGED_NETWORK = 6;

    /**
     * Construct a {@link NetworkIdentitySet} object.
     */
    public NetworkIdentitySet() {
        super();
    }

    /** @hide */
    public NetworkIdentitySet(DataInput in) throws IOException {
        final int version = in.readInt();
        final int size = in.readInt();
@@ -52,7 +60,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
                final int ignored = in.readInt();
            }
            final int type = in.readInt();
            final int subType = in.readInt();
            final int ratType = in.readInt();
            final String subscriberId = readOptionalString(in);
            final String networkId;
            if (version >= VERSION_ADD_NETWORK_ID) {
@@ -91,22 +99,23 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
                oemNetCapabilities = NetworkIdentity.OEM_NONE;
            }

            add(new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered,
            add(new NetworkIdentity(type, ratType, subscriberId, networkId, roaming, metered,
                    defaultNetwork, oemNetCapabilities));
        }
    }

    /**
     * Method to serialize this object into a {@code DataOutput}.
     * @hide
     */
    public void writeToStream(DataOutput out) throws IOException {
        out.writeInt(VERSION_ADD_OEM_MANAGED_NETWORK);
        out.writeInt(size());
        for (NetworkIdentity ident : this) {
            out.writeInt(ident.getType());
            out.writeInt(ident.getSubType());
            out.writeInt(ident.getRatType());
            writeOptionalString(out, ident.getSubscriberId());
            writeOptionalString(out, ident.getNetworkId());
            writeOptionalString(out, ident.getWifiNetworkKey());
            out.writeBoolean(ident.getRoaming());
            out.writeBoolean(ident.getMetered());
            out.writeBoolean(ident.getDefaultNetwork());
@@ -114,7 +123,10 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
        }
    }

    /** @return whether any {@link NetworkIdentity} in this set is considered metered. */
    /**
     * @return whether any {@link NetworkIdentity} in this set is considered metered.
     * @hide
     */
    public boolean isAnyMemberMetered() {
        if (isEmpty()) {
            return false;
@@ -127,7 +139,10 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
        return false;
    }

    /** @return whether any {@link NetworkIdentity} in this set is considered roaming. */
    /**
     * @return whether any {@link NetworkIdentity} in this set is considered roaming.
     * @hide
     */
    public boolean isAnyMemberRoaming() {
        if (isEmpty()) {
            return false;
@@ -140,8 +155,11 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
        return false;
    }

    /** @return whether any {@link NetworkIdentity} in this set is considered on the default
            network. */
    /**
     * @return whether any {@link NetworkIdentity} in this set is considered on the default
     *         network.
     * @hide
     */
    public boolean areAllMembersOnDefaultNetwork() {
        if (isEmpty()) {
            return true;
@@ -172,7 +190,8 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
    }

    @Override
    public int compareTo(NetworkIdentitySet another) {
    public int compareTo(@NonNull NetworkIdentitySet another) {
        Objects.requireNonNull(another);
        if (isEmpty()) return -1;
        if (another.isEmpty()) return 1;

@@ -183,6 +202,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements

    /**
     * Method to dump this object into proto debug file.
     * @hide
     */
    public void dumpDebug(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);
+64 −7
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import static android.text.format.DateUtils.WEEK_IN_MILLIS;

import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Binder;
import android.service.NetworkStatsCollectionKeyProto;
import android.service.NetworkStatsCollectionProto;
@@ -77,6 +79,7 @@ import java.util.Objects;
 *
 * @hide
 */
// @SystemApi(client = MODULE_LIBRARIES)
public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.Writer {
    private static final String TAG = NetworkStatsCollection.class.getSimpleName();
    /** File header magic number: "ANET" */
@@ -100,15 +103,23 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
    private long mTotalBytes;
    private boolean mDirty;

    /**
     * Construct a {@link NetworkStatsCollection} object.
     *
     * @param bucketDuration duration of the buckets in this object, in milliseconds.
     * @hide
     */
    public NetworkStatsCollection(long bucketDuration) {
        mBucketDuration = bucketDuration;
        reset();
    }

    /** @hide */
    public void clear() {
        reset();
    }

    /** @hide */
    public void reset() {
        mStats.clear();
        mStartMillis = Long.MAX_VALUE;
@@ -117,6 +128,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        mDirty = false;
    }

    /** @hide */
    public long getStartMillis() {
        return mStartMillis;
    }
@@ -124,6 +136,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
    /**
     * Return first atomic bucket in this collection, which is more conservative
     * than {@link #mStartMillis}.
     * @hide
     */
    public long getFirstAtomicBucketMillis() {
        if (mStartMillis == Long.MAX_VALUE) {
@@ -133,26 +146,32 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    public long getEndMillis() {
        return mEndMillis;
    }

    /** @hide */
    public long getTotalBytes() {
        return mTotalBytes;
    }

    /** @hide */
    public boolean isDirty() {
        return mDirty;
    }

    /** @hide */
    public void clearDirty() {
        mDirty = false;
    }

    /** @hide */
    public boolean isEmpty() {
        return mStartMillis == Long.MAX_VALUE && mEndMillis == Long.MIN_VALUE;
    }

    /** @hide */
    @VisibleForTesting
    public long roundUp(long time) {
        if (time == Long.MIN_VALUE || time == Long.MAX_VALUE
@@ -168,6 +187,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    @VisibleForTesting
    public long roundDown(long time) {
        if (time == Long.MIN_VALUE || time == Long.MAX_VALUE
@@ -182,10 +202,12 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    public int[] getRelevantUids(@NetworkStatsAccess.Level int accessLevel) {
        return getRelevantUids(accessLevel, Binder.getCallingUid());
    }

    /** @hide */
    public int[] getRelevantUids(@NetworkStatsAccess.Level int accessLevel,
                final int callerUid) {
        final ArrayList<Integer> uids = new ArrayList<>();
@@ -206,6 +228,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
    /**
     * Combine all {@link NetworkStatsHistory} in this collection which match
     * the requested parameters.
     * @hide
     */
    public NetworkStatsHistory getHistory(NetworkTemplate template, SubscriptionPlan augmentPlan,
            int uid, int set, int tag, int fields, long start, long end,
@@ -331,6 +354,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
     * @param end - end of the range, timestamp in milliseconds since the epoch.
     * @param accessLevel - caller access level.
     * @param callerUid - caller UID.
     * @hide
     */
    public NetworkStats getSummary(NetworkTemplate template, long start, long end,
            @NetworkStatsAccess.Level int accessLevel, int callerUid) {
@@ -377,6 +401,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W

    /**
     * Record given {@link android.net.NetworkStats.Entry} into this collection.
     * @hide
     */
    public void recordData(NetworkIdentitySet ident, int uid, int set, int tag, long start,
            long end, NetworkStats.Entry entry) {
@@ -387,8 +412,12 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W

    /**
     * Record given {@link NetworkStatsHistory} into this collection.
     *
     * @hide
     */
    private void recordHistory(Key key, NetworkStatsHistory history) {
    public void recordHistory(@NonNull Key key, @NonNull NetworkStatsHistory history) {
        Objects.requireNonNull(key);
        Objects.requireNonNull(history);
        if (history.size() == 0) return;
        noteRecordedHistory(history.getStart(), history.getEnd(), history.getTotalBytes());

@@ -403,8 +432,11 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
    /**
     * Record all {@link NetworkStatsHistory} contained in the given collection
     * into this collection.
     *
     * @hide
     */
    public void recordCollection(NetworkStatsCollection another) {
    public void recordCollection(@NonNull NetworkStatsCollection another) {
        Objects.requireNonNull(another);
        for (int i = 0; i < another.mStats.size(); i++) {
            final Key key = another.mStats.keyAt(i);
            final NetworkStatsHistory value = another.mStats.valueAt(i);
@@ -433,6 +465,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    @Override
    public void read(InputStream in) throws IOException {
        read((DataInput) new DataInputStream(in));
@@ -472,6 +505,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    @Override
    public void write(OutputStream out) throws IOException {
        write((DataOutput) new DataOutputStream(out));
@@ -514,6 +548,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
     * See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
     *
     * @deprecated
     * @hide
     */
    @Deprecated
    public void readLegacyNetwork(File file) throws IOException {
@@ -559,6 +594,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
     * See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
     *
     * @deprecated
     * @hide
     */
    @Deprecated
    public void readLegacyUid(File file, boolean onlyTags) throws IOException {
@@ -629,6 +665,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
     * Remove any {@link NetworkStatsHistory} attributed to the requested UID,
     * moving any {@link NetworkStats#TAG_NONE} series to
     * {@link TrafficStats#UID_REMOVED}.
     * @hide
     */
    public void removeUids(int[] uids) {
        final ArrayList<Key> knownKeys = new ArrayList<>();
@@ -669,6 +706,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        return keys;
    }

    /** @hide */
    public void dump(IndentingPrintWriter pw) {
        for (Key key : getSortedKeys()) {
            pw.print("ident="); pw.print(key.ident.toString());
@@ -683,6 +721,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }
    }

    /** @hide */
    public void dumpDebug(ProtoOutputStream proto, long tag) {
        final long start = proto.start(tag);

@@ -706,6 +745,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        proto.end(start);
    }

    /** @hide */
    public void dumpCheckin(PrintWriter pw, long start, long end) {
        dumpCheckin(pw, start, end, NetworkTemplate.buildTemplateMobileWildcard(), "cell");
        dumpCheckin(pw, start, end, NetworkTemplate.buildTemplateWifiWildcard(), "wifi");
@@ -768,16 +808,32 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        return false;
    }

    private static class Key implements Comparable<Key> {
    /**
     * the identifier that associate with the {@link NetworkStatsHistory} object to identify
     * a certain record in the {@link NetworkStatsCollection} object.
     */
    public static class Key implements Comparable<Key> {
        /** @hide */
        public final NetworkIdentitySet ident;
        /** @hide */
        public final int uid;
        /** @hide */
        public final int set;
        /** @hide */
        public final int tag;

        private final int mHashCode;

        Key(NetworkIdentitySet ident, int uid, int set, int tag) {
            this.ident = ident;
        /**
         * Construct a {@link Key} object.
         *
         * @param ident a Set of {@link NetworkIdentity} that associated with the record.
         * @param uid Uid of the record.
         * @param set Set of the record, see {@code NetworkStats#SET_*}.
         * @param tag Tag of the record, see {@link TrafficStats#setThreadStatsTag(int)}.
         */
        public Key(@NonNull NetworkIdentitySet ident, int uid, int set, int tag) {
            this.ident = Objects.requireNonNull(ident);
            this.uid = uid;
            this.set = set;
            this.tag = tag;
@@ -790,7 +846,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }

        @Override
        public boolean equals(Object obj) {
        public boolean equals(@Nullable Object obj) {
            if (obj instanceof Key) {
                final Key key = (Key) obj;
                return uid == key.uid && set == key.set && tag == key.tag
@@ -800,7 +856,8 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
        }

        @Override
        public int compareTo(Key another) {
        public int compareTo(@NonNull Key another) {
            Objects.requireNonNull(another);
            int res = 0;
            if (ident != null && another.ident != null) {
                res = ident.compareTo(another.ident);
+49 −5

File changed.

Preview size limit exceeded, changes collapsed.

Loading