summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/NetworkIdentity.java24
-rw-r--r--core/java/android/net/NetworkStats.java16
-rw-r--r--core/java/android/net/NetworkStatsHistory.java48
-rw-r--r--core/java/android/net/NetworkTemplate.java28
4 files changed, 103 insertions, 13 deletions
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
index 36dd2fdfbcf1..d36707e4cb35 100644
--- a/core/java/android/net/NetworkIdentity.java
+++ b/core/java/android/net/NetworkIdentity.java
@@ -34,7 +34,7 @@ import java.util.Objects;
*
* @hide
*/
-public class NetworkIdentity {
+public class NetworkIdentity implements Comparable<NetworkIdentity> {
/**
* When enabled, combine all {@link #mSubType} together under
* {@link #SUBTYPE_COMBINED}.
@@ -76,7 +76,7 @@ public class NetworkIdentity {
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder("[");
+ final StringBuilder builder = new StringBuilder("{");
builder.append("type=").append(getNetworkTypeName(mType));
builder.append(", subType=");
if (COMBINE_SUBTYPE_ENABLED) {
@@ -95,7 +95,7 @@ public class NetworkIdentity {
if (mRoaming) {
builder.append(", ROAMING");
}
- return builder.append("]").toString();
+ return builder.append("}").toString();
}
public int getType() {
@@ -170,4 +170,22 @@ public class NetworkIdentity {
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming);
}
+
+ @Override
+ public int compareTo(NetworkIdentity another) {
+ int res = Integer.compare(mType, another.mType);
+ if (res == 0) {
+ res = Integer.compare(mSubType, another.mSubType);
+ }
+ 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) {
+ res = Boolean.compare(mRoaming, another.mRoaming);
+ }
+ return res;
+ }
}
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index ea5dfd184f29..2afe578b6b6f 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -733,6 +733,22 @@ public class NetworkStats implements Parcelable {
}
/**
+ * Return text description of {@link #set} value.
+ */
+ public static String setToCheckinString(int set) {
+ switch (set) {
+ case SET_ALL:
+ return "all";
+ case SET_DEFAULT:
+ return "def";
+ case SET_FOREGROUND:
+ return "fg";
+ default:
+ return "unk";
+ }
+ }
+
+ /**
* Return text description of {@link #tag} value.
*/
public static String tagToString(int tag) {
diff --git a/core/java/android/net/NetworkStatsHistory.java b/core/java/android/net/NetworkStatsHistory.java
index 62d8738ba6dd..4a4accbba502 100644
--- a/core/java/android/net/NetworkStatsHistory.java
+++ b/core/java/android/net/NetworkStatsHistory.java
@@ -26,6 +26,7 @@ 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.internal.util.ArrayUtils.total;
import android.os.Parcel;
@@ -38,6 +39,7 @@ import java.io.CharArrayWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.io.PrintWriter;
import java.net.ProtocolException;
import java.util.Arrays;
import java.util.Random;
@@ -573,8 +575,22 @@ public class NetworkStatsHistory implements Parcelable {
return (long) (start + (r.nextFloat() * (end - start)));
}
+ /**
+ * Quickly determine if this history intersects with given window.
+ */
+ 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;
+ }
+
public void dump(IndentingPrintWriter pw, boolean fullHistory) {
- pw.print("NetworkStatsHistory: bucketDuration="); pw.println(bucketDuration);
+ pw.print("NetworkStatsHistory: bucketDuration=");
+ pw.println(bucketDuration / SECOND_IN_MILLIS);
pw.increaseIndent();
final int start = fullHistory ? 0 : Math.max(0, bucketCount - 32);
@@ -583,19 +599,35 @@ public class NetworkStatsHistory implements Parcelable {
}
for (int i = start; i < bucketCount; i++) {
- pw.print("bucketStart="); pw.print(bucketStart[i]);
- if (activeTime != null) { pw.print(" activeTime="); pw.print(activeTime[i]); }
- if (rxBytes != null) { pw.print(" rxBytes="); pw.print(rxBytes[i]); }
- if (rxPackets != null) { pw.print(" rxPackets="); pw.print(rxPackets[i]); }
- if (txBytes != null) { pw.print(" txBytes="); pw.print(txBytes[i]); }
- if (txPackets != null) { pw.print(" txPackets="); pw.print(txPackets[i]); }
- if (operations != null) { pw.print(" operations="); pw.print(operations[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();
}
+ 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();
+ }
+ }
+
@Override
public String toString() {
final CharArrayWriter writer = new CharArrayWriter();
diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java
index 27197cc8a306..b839e0ac69a2 100644
--- a/core/java/android/net/NetworkTemplate.java
+++ b/core/java/android/net/NetworkTemplate.java
@@ -16,6 +16,7 @@
package android.net;
+import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
@@ -34,10 +35,10 @@ import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
-import java.util.Objects;
-
import com.android.internal.annotations.VisibleForTesting;
+import java.util.Objects;
+
/**
* Template definition used to generically match {@link NetworkIdentity},
* usually when collecting statistics.
@@ -53,6 +54,7 @@ public class NetworkTemplate implements Parcelable {
public static final int MATCH_ETHERNET = 5;
public static final int MATCH_MOBILE_WILDCARD = 6;
public static final int MATCH_WIFI_WILDCARD = 7;
+ public static final int MATCH_BLUETOOTH = 8;
/**
* Set of {@link NetworkInfo#getType()} that reflect data usage.
@@ -134,6 +136,14 @@ public class NetworkTemplate implements Parcelable {
return new NetworkTemplate(MATCH_ETHERNET, null, null);
}
+ /**
+ * Template to combine all {@link ConnectivityManager#TYPE_BLUETOOTH} style
+ * networks together.
+ */
+ public static NetworkTemplate buildTemplateBluetooth() {
+ return new NetworkTemplate(MATCH_BLUETOOTH, null, null);
+ }
+
private final int mMatchRule;
private final String mSubscriberId;
private final String mNetworkId;
@@ -222,6 +232,8 @@ public class NetworkTemplate implements Parcelable {
return matchesMobileWildcard(ident);
case MATCH_WIFI_WILDCARD:
return matchesWifiWildcard(ident);
+ case MATCH_BLUETOOTH:
+ return matchesBluetooth(ident);
default:
throw new IllegalArgumentException("unknown network template");
}
@@ -316,6 +328,16 @@ public class NetworkTemplate implements Parcelable {
}
}
+ /**
+ * Check if matches Bluetooth network template.
+ */
+ private boolean matchesBluetooth(NetworkIdentity ident) {
+ if (ident.mType == TYPE_BLUETOOTH) {
+ return true;
+ }
+ return false;
+ }
+
private static String getMatchRuleName(int matchRule) {
switch (matchRule) {
case MATCH_MOBILE_3G_LOWER:
@@ -332,6 +354,8 @@ public class NetworkTemplate implements Parcelable {
return "MOBILE_WILDCARD";
case MATCH_WIFI_WILDCARD:
return "WIFI_WILDCARD";
+ case MATCH_BLUETOOTH:
+ return "BLUETOOTH";
default:
return "UNKNOWN";
}