/* * 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.net; import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; import static android.net.NetworkStats.DEFAULT_NETWORK_NO; import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.METERED_NO; import static android.net.NetworkStats.ROAMING_NO; import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.TAG_NONE; import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkStatsHistory.DataStreamUtils.readFullLongArray; import static android.net.NetworkStatsHistory.DataStreamUtils.readVarLongArray; import static android.net.NetworkStatsHistory.DataStreamUtils.writeVarLongArray; import static android.net.NetworkStatsHistory.Entry.UNKNOWN; import static android.net.NetworkStatsHistory.ParcelUtils.readLongArray; import static android.net.NetworkStatsHistory.ParcelUtils.writeLongArray; import static android.text.format.DateUtils.SECOND_IN_MILLIS; import static com.android.net.module.util.NetworkStatsUtils.multiplySafeByRational; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.service.NetworkStatsHistoryBucketProto; import android.service.NetworkStatsHistoryProto; import android.util.IndentingPrintWriter; import android.util.proto.ProtoOutputStream; import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.NetworkStatsUtils; import libcore.util.EmptyArray; import java.io.CharArrayWriter; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.io.PrintWriter; import java.net.ProtocolException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.TreeMap; /** * Collection of historical network statistics, recorded into equally-sized * "buckets" in time. Internally it stores data in {@code long} series for more * efficient persistence. *
* Each bucket is defined by a {@link #bucketStart} timestamp, and lasts for
* {@link #bucketDuration}. Internally assumes that {@link #bucketStart} is
* sorted at all times.
*
* @hide
*/
@SystemApi(client = MODULE_LIBRARIES)
public final class NetworkStatsHistory implements Parcelable {
private static final int VERSION_INIT = 1;
private static final int VERSION_ADD_PACKETS = 2;
private static final int VERSION_ADD_ACTIVE = 3;
/** @hide */
public static final int FIELD_ACTIVE_TIME = 0x01;
/** @hide */
public static final int FIELD_RX_BYTES = 0x02;
/** @hide */
public static final int FIELD_RX_PACKETS = 0x04;
/** @hide */
public static final int FIELD_TX_BYTES = 0x08;
/** @hide */
public static final int FIELD_TX_PACKETS = 0x10;
/** @hide */
public static final int FIELD_OPERATIONS = 0x20;
/** @hide */
public static final int FIELD_ALL = 0xFFFFFFFF;
private long bucketDuration;
private int bucketCount;
private long[] bucketStart;
private long[] activeTime;
private long[] rxBytes;
private long[] rxPackets;
private long[] txBytes;
private long[] txPackets;
private long[] operations;
private long totalBytes;
/** @hide */
public NetworkStatsHistory(long bucketDuration, long[] bucketStart, long[] activeTime,
long[] rxBytes, long[] rxPackets, long[] txBytes, long[] txPackets,
long[] operations, int bucketCount, long totalBytes) {
this.bucketDuration = bucketDuration;
this.bucketStart = bucketStart;
this.activeTime = activeTime;
this.rxBytes = rxBytes;
this.rxPackets = rxPackets;
this.txBytes = txBytes;
this.txPackets = txPackets;
this.operations = operations;
this.bucketCount = bucketCount;
this.totalBytes = totalBytes;
}
/**
* An instance to represent a single record in a {@link NetworkStatsHistory} object.
*/
public static final class Entry {
/** @hide */
public static final long UNKNOWN = -1;
/** @hide */
// TODO: Migrate all callers to get duration from the history object and remove this field.
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long bucketDuration;
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long bucketStart;
/** @hide */
public long activeTime;
/** @hide */
@UnsupportedAppUsage
public long rxBytes;
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long rxPackets;
/** @hide */
@UnsupportedAppUsage
public long txBytes;
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long txPackets;
/** @hide */
public long operations;
/** @hide */
Entry() {}
/**
* Construct a {@link Entry} instance to represent a single record in a
* {@link NetworkStatsHistory} object.
*
* @param bucketStart Start of period for this {@link Entry}, in milliseconds since the
* Unix epoch, see {@link java.lang.System#currentTimeMillis}.
* @param activeTime Active time for this {@link Entry}, in milliseconds.
* @param rxBytes Number of bytes received for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param rxPackets Number of packets received for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param txBytes Number of bytes transmitted for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param txPackets Number of bytes transmitted for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param operations count of network operations performed for this {@link Entry}. This can
* be used to derive bytes-per-operation.
*/
public Entry(long bucketStart, long activeTime, long rxBytes,
long rxPackets, long txBytes, long txPackets, long operations) {
this.bucketStart = bucketStart;
this.activeTime = activeTime;
this.rxBytes = rxBytes;
this.rxPackets = rxPackets;
this.txBytes = txBytes;
this.txPackets = txPackets;
this.operations = operations;
}
/**
* Get start timestamp of the bucket's time interval, in milliseconds since the Unix epoch.
*/
public long getBucketStart() {
return bucketStart;
}
/**
* Get active time of the bucket's time interval, in milliseconds.
*/
public long getActiveTime() {
return activeTime;
}
/** Get number of bytes received for this {@link Entry}. */
public long getRxBytes() {
return rxBytes;
}
/** Get number of packets received for this {@link Entry}. */
public long getRxPackets() {
return rxPackets;
}
/** Get number of bytes transmitted for this {@link Entry}. */
public long getTxBytes() {
return txBytes;
}
/** Get number of packets transmitted for this {@link Entry}. */
public long getTxPackets() {
return txPackets;
}
/** Get count of network operations performed for this {@link Entry}. */
public long getOperations() {
return operations;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o.getClass() != getClass()) return false;
Entry entry = (Entry) o;
return bucketStart == entry.bucketStart
&& activeTime == entry.activeTime && rxBytes == entry.rxBytes
&& rxPackets == entry.rxPackets && txBytes == entry.txBytes
&& txPackets == entry.txPackets && operations == entry.operations;
}
@Override
public int hashCode() {
return (int) (bucketStart * 2
+ activeTime * 3
+ rxBytes * 5
+ rxPackets * 7
+ txBytes * 11
+ txPackets * 13
+ operations * 17);
}
@Override
public String toString() {
return "Entry{"
+ "bucketStart=" + bucketStart
+ ", activeTime=" + activeTime
+ ", rxBytes=" + rxBytes
+ ", rxPackets=" + rxPackets
+ ", txBytes=" + txBytes
+ ", txPackets=" + txPackets
+ ", operations=" + operations
+ "}";
}
/**
* Add the given {@link Entry} with this instance and return a new {@link Entry}
* instance as the result.
*
* @hide
*/
@NonNull
public Entry plus(@NonNull Entry another, long bucketDuration) {
if (this.bucketStart != another.bucketStart) {
throw new IllegalArgumentException("bucketStart " + this.bucketStart
+ " is not equal to " + another.bucketStart);
}
return new Entry(this.bucketStart,
// Active time should not go over bucket duration.
Math.min(this.activeTime + another.activeTime, bucketDuration),
this.rxBytes + another.rxBytes,
this.rxPackets + another.rxPackets,
this.txBytes + another.txBytes,
this.txPackets + another.txPackets,
this.operations + another.operations);
}
}
/** @hide */
@UnsupportedAppUsage
public NetworkStatsHistory(long bucketDuration) {
this(bucketDuration, 10, FIELD_ALL);
}
/** @hide */
public NetworkStatsHistory(long bucketDuration, int initialSize) {
this(bucketDuration, initialSize, FIELD_ALL);
}
/** @hide */
public NetworkStatsHistory(long bucketDuration, int initialSize, int fields) {
this.bucketDuration = bucketDuration;
bucketStart = new long[initialSize];
if ((fields & FIELD_ACTIVE_TIME) != 0) activeTime = new long[initialSize];
if ((fields & FIELD_RX_BYTES) != 0) rxBytes = new long[initialSize];
if ((fields & FIELD_RX_PACKETS) != 0) rxPackets = new long[initialSize];
if ((fields & FIELD_TX_BYTES) != 0) txBytes = new long[initialSize];
if ((fields & FIELD_TX_PACKETS) != 0) txPackets = new long[initialSize];
if ((fields & FIELD_OPERATIONS) != 0) operations = new long[initialSize];
bucketCount = 0;
totalBytes = 0;
}
/** @hide */
public NetworkStatsHistory(NetworkStatsHistory existing, long bucketDuration) {
this(bucketDuration, existing.estimateResizeBuckets(bucketDuration));
recordEntireHistory(existing);
}
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public NetworkStatsHistory(Parcel in) {
bucketDuration = in.readLong();
bucketStart = readLongArray(in);
activeTime = readLongArray(in);
rxBytes = readLongArray(in);
rxPackets = readLongArray(in);
txBytes = readLongArray(in);
txPackets = readLongArray(in);
operations = readLongArray(in);
bucketCount = bucketStart.length;
totalBytes = in.readLong();
}
@Override
public void writeToParcel(@NonNull Parcel out, int flags) {
out.writeLong(bucketDuration);
writeLongArray(out, bucketStart, bucketCount);
writeLongArray(out, activeTime, bucketCount);
writeLongArray(out, rxBytes, bucketCount);
writeLongArray(out, rxPackets, bucketCount);
writeLongArray(out, txBytes, bucketCount);
writeLongArray(out, txPackets, bucketCount);
writeLongArray(out, operations, bucketCount);
out.writeLong(totalBytes);
}
/** @hide */
public NetworkStatsHistory(DataInput in) throws IOException {
final int version = in.readInt();
switch (version) {
case VERSION_INIT: {
bucketDuration = in.readLong();
bucketStart = readFullLongArray(in);
rxBytes = readFullLongArray(in);
rxPackets = new long[bucketStart.length];
txBytes = readFullLongArray(in);
txPackets = new long[bucketStart.length];
operations = new long[bucketStart.length];
bucketCount = bucketStart.length;
totalBytes = CollectionUtils.total(rxBytes) + CollectionUtils.total(txBytes);
break;
}
case VERSION_ADD_PACKETS:
case VERSION_ADD_ACTIVE: {
bucketDuration = in.readLong();
bucketStart = readVarLongArray(in);
activeTime = (version >= VERSION_ADD_ACTIVE) ? readVarLongArray(in)
: new long[bucketStart.length];
rxBytes = readVarLongArray(in);
rxPackets = readVarLongArray(in);
txBytes = readVarLongArray(in);
txPackets = readVarLongArray(in);
operations = readVarLongArray(in);
bucketCount = bucketStart.length;
totalBytes = CollectionUtils.total(rxBytes) + CollectionUtils.total(txBytes);
break;
}
default: {
throw new ProtocolException("unexpected version: " + version);
}
}
if (bucketStart.length != bucketCount || rxBytes.length != bucketCount
|| rxPackets.length != bucketCount || txBytes.length != bucketCount
|| txPackets.length != bucketCount || operations.length != bucketCount) {
throw new ProtocolException("Mismatched history lengths");
}
}
/** @hide */
public void writeToStream(DataOutput out) throws IOException {
out.writeInt(VERSION_ADD_ACTIVE);
out.writeLong(bucketDuration);
writeVarLongArray(out, bucketStart, bucketCount);
writeVarLongArray(out, activeTime, bucketCount);
writeVarLongArray(out, rxBytes, bucketCount);
writeVarLongArray(out, rxPackets, bucketCount);
writeVarLongArray(out, txBytes, bucketCount);
writeVarLongArray(out, txPackets, bucketCount);
writeVarLongArray(out, operations, bucketCount);
}
@Override
public int describeContents() {
return 0;
}
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int size() {
return bucketCount;
}
/** @hide */
public long getBucketDuration() {
return bucketDuration;
}
/** @hide */
@UnsupportedAppUsage
public long getStart() {
if (bucketCount > 0) {
return bucketStart[0];
} else {
return Long.MAX_VALUE;
}
}
/** @hide */
@UnsupportedAppUsage
public long getEnd() {
if (bucketCount > 0) {
return bucketStart[bucketCount - 1] + bucketDuration;
} else {
return Long.MIN_VALUE;
}
}
/**
* Return total bytes represented by this history.
* @hide
*/
public long getTotalBytes() {
return totalBytes;
}
/**
* Return index of bucket that contains or is immediately before the
* requested time.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int getIndexBefore(long time) {
int index = Arrays.binarySearch(bucketStart, 0, bucketCount, time);
if (index < 0) {
index = (~index) - 1;
} else {
index -= 1;
}
return NetworkStatsUtils.constrain(index, 0, bucketCount - 1);
}
/**
* Return index of bucket that contains or is immediately after the
* requested time.
* @hide
*/
public int getIndexAfter(long time) {
int index = Arrays.binarySearch(bucketStart, 0, bucketCount, time);
if (index < 0) {
index = ~index;
} else {
index += 1;
}
return NetworkStatsUtils.constrain(index, 0, bucketCount - 1);
}
/**
* Return specific stats entry.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public Entry getValues(int i, Entry recycle) {
final Entry entry = recycle != null ? recycle : new Entry();
entry.bucketStart = bucketStart[i];
entry.bucketDuration = bucketDuration;
entry.activeTime = getLong(activeTime, i, UNKNOWN);
entry.rxBytes = getLong(rxBytes, i, UNKNOWN);
entry.rxPackets = getLong(rxPackets, i, UNKNOWN);
entry.txBytes = getLong(txBytes, i, UNKNOWN);
entry.txPackets = getLong(txPackets, i, UNKNOWN);
entry.operations = getLong(operations, i, UNKNOWN);
return entry;
}
/**
* Get List of {@link Entry} of the {@link NetworkStatsHistory} instance.
*
* @return
*/
@NonNull
public List If the active bucket is not completed yet, it returns the proportional value of it
* based on its duration and the {@code end} param.
*
* @param start - start of the range, timestamp in milliseconds since the epoch.
* @param end - end of the range, timestamp in milliseconds since the epoch.
* @param recycle - entry instance for performance, could be null.
* @hide
*/
@UnsupportedAppUsage
public Entry getValues(long start, long end, Entry recycle) {
return getValues(start, end, Long.MAX_VALUE, recycle);
}
/**
* Return interpolated data usage across the requested range. Interpolates
* across buckets, so values may be rounded slightly.
*
* @param start - start of the range, timestamp in milliseconds since the epoch.
* @param end - end of the range, timestamp in milliseconds since the epoch.
* @param now - current timestamp in milliseconds since the epoch (wall clock).
* @param recycle - entry instance for performance, could be null.
* @hide
*/
@UnsupportedAppUsage
public Entry getValues(long start, long end, long now, Entry recycle) {
final Entry entry = recycle != null ? recycle : new Entry();
entry.bucketDuration = end - start;
entry.bucketStart = start;
entry.activeTime = activeTime != null ? 0 : UNKNOWN;
entry.rxBytes = rxBytes != null ? 0 : UNKNOWN;
entry.rxPackets = rxPackets != null ? 0 : UNKNOWN;
entry.txBytes = txBytes != null ? 0 : UNKNOWN;
entry.txPackets = txPackets != null ? 0 : UNKNOWN;
entry.operations = operations != null ? 0 : UNKNOWN;
// Return fast if there is no entry.
if (bucketCount == 0) return entry;
final int startIndex = getIndexAfter(end);
for (int i = startIndex; i >= 0; i--) {
final long curStart = bucketStart[i];
long curEnd = curStart + bucketDuration;
// bucket is older than request; we're finished
if (curEnd <= start) break;
// bucket is newer than request; keep looking
if (curStart >= end) continue;
// the active bucket is shorter then a normal completed bucket
if (curEnd > now) curEnd = now;
// usually this is simply bucketDuration
final long bucketSpan = curEnd - curStart;
// prevent division by zero
if (bucketSpan <= 0) continue;
final long overlapEnd = curEnd < end ? curEnd : end;
final long overlapStart = curStart > start ? curStart : start;
final long overlap = overlapEnd - overlapStart;
if (overlap <= 0) continue;
// integer math each time is faster than floating point
if (activeTime != null) {
entry.activeTime += multiplySafeByRational(activeTime[i], overlap, bucketSpan);
}
if (rxBytes != null) {
entry.rxBytes += multiplySafeByRational(rxBytes[i], overlap, bucketSpan);
}
if (rxPackets != null) {
entry.rxPackets += multiplySafeByRational(rxPackets[i], overlap, bucketSpan);
}
if (txBytes != null) {
entry.txBytes += multiplySafeByRational(txBytes[i], overlap, bucketSpan);
}
if (txPackets != null) {
entry.txPackets += multiplySafeByRational(txPackets[i], overlap, bucketSpan);
}
if (operations != null) {
entry.operations += multiplySafeByRational(operations[i], overlap, bucketSpan);
}
}
return entry;
}
/**
* @deprecated only for temporary testing
* @hide
*/
@Deprecated
public void generateRandom(long start, long end, long bytes) {
final Random r = new Random();
final float fractionRx = r.nextFloat();
final long rxBytes = (long) (bytes * fractionRx);
final long txBytes = (long) (bytes * (1 - fractionRx));
final long rxPackets = rxBytes / 1024;
final long txPackets = txBytes / 1024;
final long operations = rxBytes / 2048;
generateRandom(start, end, rxBytes, rxPackets, txBytes, txPackets, operations, r);
}
/**
* @deprecated only for temporary testing
* @hide
*/
@Deprecated
public void generateRandom(long start, long end, long rxBytes, long rxPackets, long txBytes,
long txPackets, long operations, Random r) {
ensureBuckets(start, end);
final NetworkStats.Entry entry = new NetworkStats.Entry(
IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, METERED_NO, ROAMING_NO,
DEFAULT_NETWORK_NO, 0L, 0L, 0L, 0L, 0L);
while (rxBytes > 1024 || rxPackets > 128 || txBytes > 1024 || txPackets > 128
|| operations > 32) {
final long curStart = randomLong(r, start, end);
final long curEnd = curStart + randomLong(r, 0, (end - curStart) / 2);
entry.rxBytes = randomLong(r, 0, rxBytes);
entry.rxPackets = randomLong(r, 0, rxPackets);
entry.txBytes = randomLong(r, 0, txBytes);
entry.txPackets = randomLong(r, 0, txPackets);
entry.operations = randomLong(r, 0, operations);
rxBytes -= entry.rxBytes;
rxPackets -= entry.rxPackets;
txBytes -= entry.txBytes;
txPackets -= entry.txPackets;
operations -= entry.operations;
recordData(curStart, curEnd, entry);
}
}
/** @hide */
public static long randomLong(Random r, long start, long end) {
return (long) (start + (r.nextFloat() * (end - start)));
}
/**
* Quickly determine if this history intersects with given window.
* @hide
*/
public boolean intersects(long start, long end) {
final long dataStart = getStart();
final long dataEnd = getEnd();
if (start >= dataStart && start <= dataEnd) return true;
if (end >= dataStart && end <= dataEnd) return true;
if (dataStart >= start && dataStart <= end) return true;
if (dataEnd >= start && dataEnd <= end) return true;
return false;
}
/** @hide */
public void dump(IndentingPrintWriter pw, boolean fullHistory) {
pw.print("NetworkStatsHistory: bucketDuration=");
pw.println(bucketDuration / SECOND_IN_MILLIS);
pw.increaseIndent();
final int start = fullHistory ? 0 : Math.max(0, bucketCount - 32);
if (start > 0) {
pw.print("(omitting "); pw.print(start); pw.println(" buckets)");
}
for (int i = start; i < bucketCount; i++) {
pw.print("st="); pw.print(bucketStart[i] / SECOND_IN_MILLIS);
if (rxBytes != null) { pw.print(" rb="); pw.print(rxBytes[i]); }
if (rxPackets != null) { pw.print(" rp="); pw.print(rxPackets[i]); }
if (txBytes != null) { pw.print(" tb="); pw.print(txBytes[i]); }
if (txPackets != null) { pw.print(" tp="); pw.print(txPackets[i]); }
if (operations != null) { pw.print(" op="); pw.print(operations[i]); }
pw.println();
}
pw.decreaseIndent();
}
/** @hide */
public void dumpCheckin(PrintWriter pw) {
pw.print("d,");
pw.print(bucketDuration / SECOND_IN_MILLIS);
pw.println();
for (int i = 0; i < bucketCount; i++) {
pw.print("b,");
pw.print(bucketStart[i] / SECOND_IN_MILLIS); pw.print(',');
if (rxBytes != null) { pw.print(rxBytes[i]); } else { pw.print("*"); } pw.print(',');
if (rxPackets != null) { pw.print(rxPackets[i]); } else { pw.print("*"); } pw.print(',');
if (txBytes != null) { pw.print(txBytes[i]); } else { pw.print("*"); } pw.print(',');
if (txPackets != null) { pw.print(txPackets[i]); } else { pw.print("*"); } pw.print(',');
if (operations != null) { pw.print(operations[i]); } else { pw.print("*"); }
pw.println();
}
}
/** @hide */
public void dumpDebug(ProtoOutputStream proto, long tag) {
final long start = proto.start(tag);
proto.write(NetworkStatsHistoryProto.BUCKET_DURATION_MS, bucketDuration);
for (int i = 0; i < bucketCount; i++) {
final long startBucket = proto.start(NetworkStatsHistoryProto.BUCKETS);
proto.write(NetworkStatsHistoryBucketProto.BUCKET_START_MS,
bucketStart[i]);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
dumpDebug(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);
proto.end(startBucket);
}
proto.end(start);
}
private static void dumpDebug(ProtoOutputStream proto, long tag, long[] array, int index) {
if (array != null) {
proto.write(tag, array[index]);
}
}
@Override
public String toString() {
final CharArrayWriter writer = new CharArrayWriter();
dump(new IndentingPrintWriter(writer, " "), false);
return writer.toString();
}
/**
* Same as "equals", but not actually called equals as this would affect public API behavior.
* @hide
*/
@Nullable
public boolean isSameAs(NetworkStatsHistory other) {
return bucketCount == other.bucketCount
&& Arrays.equals(bucketStart, other.bucketStart)
// Don't check activeTime since it can change on import due to the importer using
// recordHistory. It's also not exposed by the APIs or present in dumpsys or
// toString().
&& Arrays.equals(rxBytes, other.rxBytes)
&& Arrays.equals(rxPackets, other.rxPackets)
&& Arrays.equals(txBytes, other.txBytes)
&& Arrays.equals(txPackets, other.txPackets)
&& Arrays.equals(operations, other.operations)
&& totalBytes == other.totalBytes;
}
@UnsupportedAppUsage
public static final @android.annotation.NonNull Creator