Merge "Pivot network statistics to use DataInput/Output." am: 5b322f10be am: 84dee682ac
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1540224 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ic0502659732c1957b297095a5332e6dc0b514397
This commit is contained in:
@@ -45,8 +45,8 @@ import com.android.internal.util.IndentingPrintWriter;
|
|||||||
import libcore.util.EmptyArray;
|
import libcore.util.EmptyArray;
|
||||||
|
|
||||||
import java.io.CharArrayWriter;
|
import java.io.CharArrayWriter;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
@@ -162,7 +162,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
out.writeLong(totalBytes);
|
out.writeLong(totalBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkStatsHistory(DataInputStream in) throws IOException {
|
public NetworkStatsHistory(DataInput in) throws IOException {
|
||||||
final int version = in.readInt();
|
final int version = in.readInt();
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case VERSION_INIT: {
|
case VERSION_INIT: {
|
||||||
@@ -204,7 +204,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToStream(DataOutputStream out) throws IOException {
|
public void writeToStream(DataOutput out) throws IOException {
|
||||||
out.writeInt(VERSION_ADD_ACTIVE);
|
out.writeInt(VERSION_ADD_ACTIVE);
|
||||||
out.writeLong(bucketDuration);
|
out.writeLong(bucketDuration);
|
||||||
writeVarLongArray(out, bucketStart, bucketCount);
|
writeVarLongArray(out, bucketStart, bucketCount);
|
||||||
@@ -768,7 +768,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static class DataStreamUtils {
|
public static class DataStreamUtils {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static long[] readFullLongArray(DataInputStream in) throws IOException {
|
public static long[] readFullLongArray(DataInput in) throws IOException {
|
||||||
final int size = in.readInt();
|
final int size = in.readInt();
|
||||||
if (size < 0) throw new ProtocolException("negative array size");
|
if (size < 0) throw new ProtocolException("negative array size");
|
||||||
final long[] values = new long[size];
|
final long[] values = new long[size];
|
||||||
@@ -781,7 +781,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Read variable-length {@link Long} using protobuf-style approach.
|
* Read variable-length {@link Long} using protobuf-style approach.
|
||||||
*/
|
*/
|
||||||
public static long readVarLong(DataInputStream in) throws IOException {
|
public static long readVarLong(DataInput in) throws IOException {
|
||||||
int shift = 0;
|
int shift = 0;
|
||||||
long result = 0;
|
long result = 0;
|
||||||
while (shift < 64) {
|
while (shift < 64) {
|
||||||
@@ -797,7 +797,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Write variable-length {@link Long} using protobuf-style approach.
|
* Write variable-length {@link Long} using protobuf-style approach.
|
||||||
*/
|
*/
|
||||||
public static void writeVarLong(DataOutputStream out, long value) throws IOException {
|
public static void writeVarLong(DataOutput out, long value) throws IOException {
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((value & ~0x7FL) == 0) {
|
if ((value & ~0x7FL) == 0) {
|
||||||
out.writeByte((int) value);
|
out.writeByte((int) value);
|
||||||
@@ -809,7 +809,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long[] readVarLongArray(DataInputStream in) throws IOException {
|
public static long[] readVarLongArray(DataInput in) throws IOException {
|
||||||
final int size = in.readInt();
|
final int size = in.readInt();
|
||||||
if (size == -1) return null;
|
if (size == -1) return null;
|
||||||
if (size < 0) throw new ProtocolException("negative array size");
|
if (size < 0) throw new ProtocolException("negative array size");
|
||||||
@@ -820,7 +820,7 @@ public class NetworkStatsHistory implements Parcelable {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeVarLongArray(DataOutputStream out, long[] values, int size)
|
public static void writeVarLongArray(DataOutput out, long[] values, int size)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (values == null) {
|
if (values == null) {
|
||||||
out.writeInt(-1);
|
out.writeInt(-1);
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import android.net.NetworkIdentity;
|
|||||||
import android.service.NetworkIdentitySetProto;
|
import android.service.NetworkIdentitySetProto;
|
||||||
import android.util.proto.ProtoOutputStream;
|
import android.util.proto.ProtoOutputStream;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
|||||||
public NetworkIdentitySet() {
|
public NetworkIdentitySet() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkIdentitySet(DataInputStream in) throws IOException {
|
public NetworkIdentitySet(DataInput in) throws IOException {
|
||||||
final int version = in.readInt();
|
final int version = in.readInt();
|
||||||
final int size = in.readInt();
|
final int size = in.readInt();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@@ -89,7 +89,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToStream(DataOutputStream out) throws IOException {
|
public void writeToStream(DataOutput out) throws IOException {
|
||||||
out.writeInt(VERSION_ADD_DEFAULT_NETWORK);
|
out.writeInt(VERSION_ADD_DEFAULT_NETWORK);
|
||||||
out.writeInt(size());
|
out.writeInt(size());
|
||||||
for (NetworkIdentity ident : this) {
|
for (NetworkIdentity ident : this) {
|
||||||
@@ -143,7 +143,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeOptionalString(DataOutputStream out, String value) throws IOException {
|
private static void writeOptionalString(DataOutput out, String value) throws IOException {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
out.writeByte(1);
|
out.writeByte(1);
|
||||||
out.writeUTF(value);
|
out.writeUTF(value);
|
||||||
@@ -152,7 +152,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readOptionalString(DataInputStream in) throws IOException {
|
private static String readOptionalString(DataInput in) throws IOException {
|
||||||
if (in.readByte() != 0) {
|
if (in.readByte() != 0) {
|
||||||
return in.readUTF();
|
return in.readUTF();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,12 +63,15 @@ import com.google.android.collect.Lists;
|
|||||||
import com.google.android.collect.Maps;
|
import com.google.android.collect.Maps;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutput;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.ProtocolException;
|
import java.net.ProtocolException;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
@@ -82,7 +85,7 @@ import java.util.Objects;
|
|||||||
* Collection of {@link NetworkStatsHistory}, stored based on combined key of
|
* Collection of {@link NetworkStatsHistory}, stored based on combined key of
|
||||||
* {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself.
|
* {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself.
|
||||||
*/
|
*/
|
||||||
public class NetworkStatsCollection implements FileRotator.Reader {
|
public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.Writer {
|
||||||
/** File header magic number: "ANET" */
|
/** File header magic number: "ANET" */
|
||||||
private static final int FILE_MAGIC = 0x414E4554;
|
private static final int FILE_MAGIC = 0x414E4554;
|
||||||
|
|
||||||
@@ -431,10 +434,10 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(InputStream in) throws IOException {
|
public void read(InputStream in) throws IOException {
|
||||||
read(new DataInputStream(in));
|
read((DataInput) new DataInputStream(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(DataInputStream in) throws IOException {
|
private void read(DataInput in) throws IOException {
|
||||||
// verify file magic header intact
|
// verify file magic header intact
|
||||||
final int magic = in.readInt();
|
final int magic = in.readInt();
|
||||||
if (magic != FILE_MAGIC) {
|
if (magic != FILE_MAGIC) {
|
||||||
@@ -468,7 +471,13 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutputStream out) throws IOException {
|
@Override
|
||||||
|
public void write(OutputStream out) throws IOException {
|
||||||
|
write((DataOutput) new DataOutputStream(out));
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write(DataOutput out) throws IOException {
|
||||||
// cluster key lists grouped by ident
|
// cluster key lists grouped by ident
|
||||||
final HashMap<NetworkIdentitySet, ArrayList<Key>> keysByIdent = Maps.newHashMap();
|
final HashMap<NetworkIdentitySet, ArrayList<Key>> keysByIdent = Maps.newHashMap();
|
||||||
for (Key key : mStats.keySet()) {
|
for (Key key : mStats.keySet()) {
|
||||||
@@ -497,8 +506,6 @@ public class NetworkStatsCollection implements FileRotator.Reader {
|
|||||||
history.writeToStream(out);
|
history.writeToStream(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import com.google.android.collect.Sets;
|
|||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -375,7 +374,7 @@ public class NetworkStatsRecorder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
mCollection.write(new DataOutputStream(out));
|
mCollection.write(out);
|
||||||
mCollection.reset();
|
mCollection.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -412,7 +411,7 @@ public class NetworkStatsRecorder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
mTemp.write(new DataOutputStream(out));
|
mTemp.write(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user