summaryrefslogtreecommitdiff
path: root/framework-t/src/android/net/NetworkStatsCollection.java
diff options
context:
space:
mode:
authorJunyu Lai <junyulai@google.com>2022-01-24 14:08:56 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2022-01-24 14:08:56 +0000
commit546ae74ab987af6db142c0cb1ab75789a617a290 (patch)
tree3aa71a4bea7a2837c515f2923c214b8ccaefff0f /framework-t/src/android/net/NetworkStatsCollection.java
parent84b61cfcdab36dc3a1634f1373aa2f078e676ae5 (diff)
parentc28dd15332ec595b318a1eea15798db2b9814602 (diff)
Merge changes I54c2258c,I47b2d3ac
* changes: [MS38] Remove android.os.HandlerExecutor dependencies [MS58] Expose Apis which will be used by data migration utility
Diffstat (limited to 'framework-t/src/android/net/NetworkStatsCollection.java')
-rw-r--r--framework-t/src/android/net/NetworkStatsCollection.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/framework-t/src/android/net/NetworkStatsCollection.java b/framework-t/src/android/net/NetworkStatsCollection.java
index f169fed6b9..58ca21fdfa 100644
--- a/framework-t/src/android/net/NetworkStatsCollection.java
+++ b/framework-t/src/android/net/NetworkStatsCollection.java
@@ -72,6 +72,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects;
+import java.util.Set;
/**
* Collection of {@link NetworkStatsHistory}, stored based on combined key of
@@ -702,7 +703,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
private ArrayList<Key> getSortedKeys() {
final ArrayList<Key> keys = new ArrayList<>();
keys.addAll(mStats.keySet());
- Collections.sort(keys);
+ Collections.sort(keys, (left, right) -> Key.compare(left, right));
return keys;
}
@@ -812,7 +813,7 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
* 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> {
+ public static class Key {
/** @hide */
public final NetworkIdentitySet ident;
/** @hide */
@@ -832,6 +833,11 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
* @param set Set of the record, see {@code NetworkStats#SET_*}.
* @param tag Tag of the record, see {@link TrafficStats#setThreadStatsTag(int)}.
*/
+ public Key(@NonNull Set<NetworkIdentity> ident, int uid, int set, int tag) {
+ this(new NetworkIdentitySet(Objects.requireNonNull(ident)), uid, set, tag);
+ }
+
+ /** @hide */
public Key(@NonNull NetworkIdentitySet ident, int uid, int set, int tag) {
this.ident = Objects.requireNonNull(ident);
this.uid = uid;
@@ -855,21 +861,22 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W
return false;
}
- @Override
- public int compareTo(@NonNull Key another) {
- Objects.requireNonNull(another);
+ /** @hide */
+ public static int compare(@NonNull Key left, @NonNull Key right) {
+ Objects.requireNonNull(left);
+ Objects.requireNonNull(right);
int res = 0;
- if (ident != null && another.ident != null) {
- res = ident.compareTo(another.ident);
+ if (left.ident != null && right.ident != null) {
+ res = NetworkIdentitySet.compare(left.ident, right.ident);
}
if (res == 0) {
- res = Integer.compare(uid, another.uid);
+ res = Integer.compare(left.uid, right.uid);
}
if (res == 0) {
- res = Integer.compare(set, another.set);
+ res = Integer.compare(left.set, right.set);
}
if (res == 0) {
- res = Integer.compare(tag, another.tag);
+ res = Integer.compare(left.tag, right.tag);
}
return res;
}