Merge changes I54c2258c,I47b2d3ac am: 546ae74ab9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1936446 Change-Id: Id51ceff565e5d5467f3a236b5d43e5395d65bdac
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;
|
||||
@@ -24,6 +25,7 @@ import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.SystemApi;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.service.NetworkIdentityProto;
|
||||
@@ -46,8 +48,8 @@ import java.util.Objects;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
// @SystemApi(client = MODULE_LIBRARIES)
|
||||
public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
@SystemApi(client = MODULE_LIBRARIES)
|
||||
public class NetworkIdentity {
|
||||
private static final String TAG = "NetworkIdentity";
|
||||
|
||||
/** @hide */
|
||||
@@ -299,30 +301,30 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
return oemManaged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull NetworkIdentity another) {
|
||||
Objects.requireNonNull(another);
|
||||
int res = Integer.compare(mType, another.mType);
|
||||
/** @hide */
|
||||
public static int compare(@NonNull NetworkIdentity left, @NonNull NetworkIdentity right) {
|
||||
Objects.requireNonNull(right);
|
||||
int res = Integer.compare(left.mType, right.mType);
|
||||
if (res == 0) {
|
||||
res = Integer.compare(mRatType, another.mRatType);
|
||||
res = Integer.compare(left.mRatType, right.mRatType);
|
||||
}
|
||||
if (res == 0 && mSubscriberId != null && another.mSubscriberId != null) {
|
||||
res = mSubscriberId.compareTo(another.mSubscriberId);
|
||||
if (res == 0 && left.mSubscriberId != null && right.mSubscriberId != null) {
|
||||
res = left.mSubscriberId.compareTo(right.mSubscriberId);
|
||||
}
|
||||
if (res == 0 && mWifiNetworkKey != null && another.mWifiNetworkKey != null) {
|
||||
res = mWifiNetworkKey.compareTo(another.mWifiNetworkKey);
|
||||
if (res == 0 && left.mWifiNetworkKey != null && right.mWifiNetworkKey != null) {
|
||||
res = left.mWifiNetworkKey.compareTo(right.mWifiNetworkKey);
|
||||
}
|
||||
if (res == 0) {
|
||||
res = Boolean.compare(mRoaming, another.mRoaming);
|
||||
res = Boolean.compare(left.mRoaming, right.mRoaming);
|
||||
}
|
||||
if (res == 0) {
|
||||
res = Boolean.compare(mMetered, another.mMetered);
|
||||
res = Boolean.compare(left.mMetered, right.mMetered);
|
||||
}
|
||||
if (res == 0) {
|
||||
res = Boolean.compare(mDefaultNetwork, another.mDefaultNetwork);
|
||||
res = Boolean.compare(left.mDefaultNetwork, right.mDefaultNetwork);
|
||||
}
|
||||
if (res == 0) {
|
||||
res = Integer.compare(mOemManaged, another.mOemManaged);
|
||||
res = Integer.compare(left.mOemManaged, right.mOemManaged);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -362,7 +364,14 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
|
||||
/**
|
||||
* Add an {@link NetworkStateSnapshot} into the {@link NetworkIdentity} instance.
|
||||
* This is to read roaming, metered, wifikey... from the snapshot for convenience.
|
||||
* This is a useful shorthand that will read from the snapshot and set the
|
||||
* following fields, if they are set in the snapshot :
|
||||
* - type
|
||||
* - subscriberId
|
||||
* - roaming
|
||||
* - metered
|
||||
* - oemManaged
|
||||
* - wifiNetworkKey
|
||||
*
|
||||
* @param snapshot The target {@link NetworkStateSnapshot} object.
|
||||
* @return The builder object.
|
||||
@@ -415,6 +424,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
/**
|
||||
* Set the Radio Access Technology(RAT) type of the network.
|
||||
*
|
||||
* No RAT type is specified by default. Call clearRatType to reset.
|
||||
*
|
||||
* @param ratType the Radio Access Technology(RAT) type if applicable. See
|
||||
* {@code TelephonyManager.NETWORK_TYPE_*}.
|
||||
*
|
||||
@@ -470,6 +481,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
/**
|
||||
* Set whether this network is roaming.
|
||||
*
|
||||
* This field is false by default. Call with false to reset.
|
||||
*
|
||||
* @param roaming the roaming status of the network.
|
||||
* @return this builder.
|
||||
*/
|
||||
@@ -482,6 +495,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
/**
|
||||
* Set whether this network is metered.
|
||||
*
|
||||
* This field is false by default. Call with false to reset.
|
||||
*
|
||||
* @param metered the meteredness of the network.
|
||||
* @return this builder.
|
||||
*/
|
||||
@@ -494,6 +509,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
/**
|
||||
* Set whether this network is the default network.
|
||||
*
|
||||
* This field is false by default. Call with false to reset.
|
||||
*
|
||||
* @param defaultNetwork the default network status of the network.
|
||||
* @return this builder.
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Identity of a {@code iface}, defined by the set of {@link NetworkIdentity}
|
||||
@@ -34,9 +35,7 @@ import java.util.Objects;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
// @SystemApi(client = MODULE_LIBRARIES)
|
||||
public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
||||
Comparable<NetworkIdentitySet> {
|
||||
public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
|
||||
private static final int VERSION_INIT = 1;
|
||||
private static final int VERSION_ADD_ROAMING = 2;
|
||||
private static final int VERSION_ADD_NETWORK_ID = 3;
|
||||
@@ -51,6 +50,11 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
||||
super();
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public NetworkIdentitySet(@NonNull Set<NetworkIdentity> ident) {
|
||||
super(ident);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public NetworkIdentitySet(DataInput in) throws IOException {
|
||||
final int version = in.readInt();
|
||||
@@ -189,15 +193,15 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull NetworkIdentitySet another) {
|
||||
Objects.requireNonNull(another);
|
||||
if (isEmpty()) return -1;
|
||||
if (another.isEmpty()) return 1;
|
||||
public static int compare(@NonNull NetworkIdentitySet left, @NonNull NetworkIdentitySet right) {
|
||||
Objects.requireNonNull(left);
|
||||
Objects.requireNonNull(right);
|
||||
if (left.isEmpty()) return -1;
|
||||
if (right.isEmpty()) return 1;
|
||||
|
||||
final NetworkIdentity ident = iterator().next();
|
||||
final NetworkIdentity anotherIdent = another.iterator().next();
|
||||
return ident.compareTo(anotherIdent);
|
||||
final NetworkIdentity leftIdent = left.iterator().next();
|
||||
final NetworkIdentity rightIdent = right.iterator().next();
|
||||
return NetworkIdentity.compare(leftIdent, rightIdent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
||||
import static android.net.NetworkStats.IFACE_ALL;
|
||||
import static android.net.NetworkStats.SET_DEFAULT;
|
||||
import static android.net.NetworkStats.TAG_NONE;
|
||||
@@ -31,6 +32,7 @@ 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.SystemApi;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
@@ -67,7 +69,7 @@ import java.util.Random;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
// @SystemApi(client = MODULE_LIBRARIES)
|
||||
@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;
|
||||
|
||||
@@ -106,7 +106,6 @@ import android.os.Binder;
|
||||
import android.os.DropBoxManager;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerExecutor;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
@@ -450,7 +449,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
handlerThread.start();
|
||||
mHandler = new NetworkStatsHandler(handlerThread.getLooper());
|
||||
mNetworkStatsSubscriptionsMonitor = deps.makeSubscriptionsMonitor(mContext,
|
||||
new HandlerExecutor(mHandler), this);
|
||||
(command) -> mHandler.post(command) , this);
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mContentObserver = mDeps.makeContentObserver(mHandler, mSettings,
|
||||
mNetworkStatsSubscriptionsMonitor);
|
||||
@@ -557,7 +556,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
// watch for tethering changes
|
||||
final TetheringManager tetheringManager = mContext.getSystemService(TetheringManager.class);
|
||||
tetheringManager.registerTetheringEventCallback(
|
||||
new HandlerExecutor(mHandler), mTetherListener);
|
||||
(command) -> mHandler.post(command), mTetherListener);
|
||||
|
||||
// listen for periodic polling events
|
||||
final IntentFilter pollFilter = new IntentFilter(ACTION_NETWORK_STATS_POLL);
|
||||
|
||||
Reference in New Issue
Block a user