Support protofied dumpsys for NetStats
Bug 34228873 Test: manual tests with "incident_report netstats" Change-Id: I359b364c64d9798fd4229018a905658d5d46ea5c
This commit is contained in:
@@ -24,8 +24,10 @@ import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.service.NetworkIdentityProto;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Slog;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -110,6 +112,23 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
return builder.append("}").toString();
|
||||
}
|
||||
|
||||
public void writeToProto(ProtoOutputStream proto, long tag) {
|
||||
final long start = proto.start(tag);
|
||||
|
||||
proto.write(NetworkIdentityProto.TYPE, mType);
|
||||
|
||||
// Not dumping mSubType, subtypes are no longer supported.
|
||||
|
||||
if (mSubscriberId != null) {
|
||||
proto.write(NetworkIdentityProto.SUBSCRIBER_ID, scrubSubscriberId(mSubscriberId));
|
||||
}
|
||||
proto.write(NetworkIdentityProto.NETWORK_ID, mNetworkId);
|
||||
proto.write(NetworkIdentityProto.ROAMING, mRoaming);
|
||||
proto.write(NetworkIdentityProto.METERED, mMetered);
|
||||
|
||||
proto.end(start);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ import static com.android.internal.util.ArrayUtils.total;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.service.NetworkStatsHistoryBucketProto;
|
||||
import android.service.NetworkStatsHistoryProto;
|
||||
import android.util.MathUtils;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
|
||||
@@ -628,6 +631,33 @@ public class NetworkStatsHistory implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToProto(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]);
|
||||
writeToProto(proto, NetworkStatsHistoryBucketProto.RX_BYTES, rxBytes, i);
|
||||
writeToProto(proto, NetworkStatsHistoryBucketProto.RX_PACKETS, rxPackets, i);
|
||||
writeToProto(proto, NetworkStatsHistoryBucketProto.TX_BYTES, txBytes, i);
|
||||
writeToProto(proto, NetworkStatsHistoryBucketProto.TX_PACKETS, txPackets, i);
|
||||
writeToProto(proto, NetworkStatsHistoryBucketProto.OPERATIONS, operations, i);
|
||||
|
||||
proto.end(startBucket);
|
||||
}
|
||||
|
||||
proto.end(start);
|
||||
}
|
||||
|
||||
private static void writeToProto(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();
|
||||
|
||||
Reference in New Issue
Block a user