Add getters to NetworkStateSnapshot
Address API council feedback, add getters to NetworkStateSnapshot instead of exposing the bare fields directly. Bug: 183972826 Test: FrameworksNetTests Change-Id: Id1707753b42ae88d2b95e4bd00a792609434e4f5
This commit is contained in:
@@ -198,13 +198,13 @@ package android.net {
|
|||||||
public final class NetworkStateSnapshot implements android.os.Parcelable {
|
public final class NetworkStateSnapshot implements android.os.Parcelable {
|
||||||
ctor public NetworkStateSnapshot(@NonNull android.net.Network, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, @Nullable String, int);
|
ctor public NetworkStateSnapshot(@NonNull android.net.Network, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, @Nullable String, int);
|
||||||
method public int describeContents();
|
method public int describeContents();
|
||||||
|
method public int getLegacyType();
|
||||||
|
method @NonNull public android.net.LinkProperties getLinkProperties();
|
||||||
|
method @NonNull public android.net.Network getNetwork();
|
||||||
|
method @NonNull public android.net.NetworkCapabilities getNetworkCapabilities();
|
||||||
|
method @Nullable public String getSubscriberId();
|
||||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.NetworkStateSnapshot> CREATOR;
|
field @NonNull public static final android.os.Parcelable.Creator<android.net.NetworkStateSnapshot> CREATOR;
|
||||||
field public final int legacyType;
|
|
||||||
field @NonNull public final android.net.LinkProperties linkProperties;
|
|
||||||
field @NonNull public final android.net.Network network;
|
|
||||||
field @NonNull public final android.net.NetworkCapabilities networkCapabilities;
|
|
||||||
field @Nullable public final String subscriberId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NetworkWatchlistManager {
|
public class NetworkWatchlistManager {
|
||||||
|
|||||||
@@ -186,19 +186,19 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
|||||||
*/
|
*/
|
||||||
public static NetworkIdentity buildNetworkIdentity(Context context,
|
public static NetworkIdentity buildNetworkIdentity(Context context,
|
||||||
NetworkStateSnapshot snapshot, boolean defaultNetwork, @NetworkType int subType) {
|
NetworkStateSnapshot snapshot, boolean defaultNetwork, @NetworkType int subType) {
|
||||||
final int legacyType = snapshot.legacyType;
|
final int legacyType = snapshot.getLegacyType();
|
||||||
|
|
||||||
final String subscriberId = snapshot.subscriberId;
|
final String subscriberId = snapshot.getSubscriberId();
|
||||||
String networkId = null;
|
String networkId = null;
|
||||||
boolean roaming = !snapshot.networkCapabilities.hasCapability(
|
boolean roaming = !snapshot.getNetworkCapabilities().hasCapability(
|
||||||
NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
|
NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING);
|
||||||
boolean metered = !snapshot.networkCapabilities.hasCapability(
|
boolean metered = !snapshot.getNetworkCapabilities().hasCapability(
|
||||||
NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
|
|
||||||
final int oemManaged = getOemBitfield(snapshot.networkCapabilities);
|
final int oemManaged = getOemBitfield(snapshot.getNetworkCapabilities());
|
||||||
|
|
||||||
if (legacyType == TYPE_WIFI) {
|
if (legacyType == TYPE_WIFI) {
|
||||||
networkId = snapshot.networkCapabilities.getSsid();
|
networkId = snapshot.getNetworkCapabilities().getSsid();
|
||||||
if (networkId == null) {
|
if (networkId == null) {
|
||||||
final WifiManager wifi = context.getSystemService(WifiManager.class);
|
final WifiManager wifi = context.getSystemService(WifiManager.class);
|
||||||
final WifiInfo info = wifi.getConnectionInfo();
|
final WifiInfo info = wifi.getConnectionInfo();
|
||||||
|
|||||||
@@ -37,47 +37,76 @@ import java.util.Objects;
|
|||||||
public final class NetworkStateSnapshot implements Parcelable {
|
public final class NetworkStateSnapshot implements Parcelable {
|
||||||
/** The network associated with this snapshot. */
|
/** The network associated with this snapshot. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public final Network network;
|
private final Network mNetwork;
|
||||||
|
|
||||||
/** The {@link NetworkCapabilities} of the network associated with this snapshot. */
|
/** The {@link NetworkCapabilities} of the network associated with this snapshot. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public final NetworkCapabilities networkCapabilities;
|
private final NetworkCapabilities mNetworkCapabilities;
|
||||||
|
|
||||||
/** The {@link LinkProperties} of the network associated with this snapshot. */
|
/** The {@link LinkProperties} of the network associated with this snapshot. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public final LinkProperties linkProperties;
|
private final LinkProperties mLinkProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Subscriber Id of the network associated with this snapshot. See
|
* The Subscriber Id of the network associated with this snapshot. See
|
||||||
* {@link android.telephony.TelephonyManager#getSubscriberId()}.
|
* {@link android.telephony.TelephonyManager#getSubscriberId()}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public final String subscriberId;
|
private final String mSubscriberId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The legacy type of the network associated with this snapshot. See
|
* The legacy type of the network associated with this snapshot. See
|
||||||
* {@code ConnectivityManager#TYPE_*}.
|
* {@code ConnectivityManager#TYPE_*}.
|
||||||
*/
|
*/
|
||||||
public final int legacyType;
|
private final int mLegacyType;
|
||||||
|
|
||||||
public NetworkStateSnapshot(@NonNull Network network,
|
public NetworkStateSnapshot(@NonNull Network network,
|
||||||
@NonNull NetworkCapabilities networkCapabilities,
|
@NonNull NetworkCapabilities networkCapabilities,
|
||||||
@NonNull LinkProperties linkProperties,
|
@NonNull LinkProperties linkProperties,
|
||||||
@Nullable String subscriberId, int legacyType) {
|
@Nullable String subscriberId, int legacyType) {
|
||||||
this.network = Objects.requireNonNull(network);
|
mNetwork = Objects.requireNonNull(network);
|
||||||
this.networkCapabilities = Objects.requireNonNull(networkCapabilities);
|
mNetworkCapabilities = Objects.requireNonNull(networkCapabilities);
|
||||||
this.linkProperties = Objects.requireNonNull(linkProperties);
|
mLinkProperties = Objects.requireNonNull(linkProperties);
|
||||||
this.subscriberId = subscriberId;
|
mSubscriberId = subscriberId;
|
||||||
this.legacyType = legacyType;
|
mLegacyType = legacyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public NetworkStateSnapshot(@NonNull Parcel in) {
|
public NetworkStateSnapshot(@NonNull Parcel in) {
|
||||||
network = in.readParcelable(null);
|
mNetwork = in.readParcelable(null);
|
||||||
networkCapabilities = in.readParcelable(null);
|
mNetworkCapabilities = in.readParcelable(null);
|
||||||
linkProperties = in.readParcelable(null);
|
mLinkProperties = in.readParcelable(null);
|
||||||
subscriberId = in.readString();
|
mSubscriberId = in.readString();
|
||||||
legacyType = in.readInt();
|
mLegacyType = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the network associated with this snapshot */
|
||||||
|
@NonNull
|
||||||
|
public Network getNetwork() {
|
||||||
|
return mNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get {@link NetworkCapabilities} of the network associated with this snapshot. */
|
||||||
|
@NonNull
|
||||||
|
public NetworkCapabilities getNetworkCapabilities() {
|
||||||
|
return mNetworkCapabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the {@link LinkProperties} of the network associated with this snapshot. */
|
||||||
|
@NonNull
|
||||||
|
public LinkProperties getLinkProperties() {
|
||||||
|
return mLinkProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the Subscriber Id of the network associated with this snapshot. */
|
||||||
|
@Nullable
|
||||||
|
public String getSubscriberId() {
|
||||||
|
return mSubscriberId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the legacy type of the network associated with this snapshot. */
|
||||||
|
public int getLegacyType() {
|
||||||
|
return mLegacyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,11 +116,11 @@ public final class NetworkStateSnapshot implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(@NonNull Parcel out, int flags) {
|
public void writeToParcel(@NonNull Parcel out, int flags) {
|
||||||
out.writeParcelable(network, flags);
|
out.writeParcelable(mNetwork, flags);
|
||||||
out.writeParcelable(networkCapabilities, flags);
|
out.writeParcelable(mNetworkCapabilities, flags);
|
||||||
out.writeParcelable(linkProperties, flags);
|
out.writeParcelable(mLinkProperties, flags);
|
||||||
out.writeString(subscriberId);
|
out.writeString(mSubscriberId);
|
||||||
out.writeInt(legacyType);
|
out.writeInt(mLegacyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -115,26 +144,27 @@ public final class NetworkStateSnapshot implements Parcelable {
|
|||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof NetworkStateSnapshot)) return false;
|
if (!(o instanceof NetworkStateSnapshot)) return false;
|
||||||
NetworkStateSnapshot that = (NetworkStateSnapshot) o;
|
NetworkStateSnapshot that = (NetworkStateSnapshot) o;
|
||||||
return legacyType == that.legacyType
|
return mLegacyType == that.mLegacyType
|
||||||
&& Objects.equals(network, that.network)
|
&& Objects.equals(mNetwork, that.mNetwork)
|
||||||
&& Objects.equals(networkCapabilities, that.networkCapabilities)
|
&& Objects.equals(mNetworkCapabilities, that.mNetworkCapabilities)
|
||||||
&& Objects.equals(linkProperties, that.linkProperties)
|
&& Objects.equals(mLinkProperties, that.mLinkProperties)
|
||||||
&& Objects.equals(subscriberId, that.subscriberId);
|
&& Objects.equals(mSubscriberId, that.mSubscriberId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(network, networkCapabilities, linkProperties, subscriberId, legacyType);
|
return Objects.hash(mNetwork,
|
||||||
|
mNetworkCapabilities, mLinkProperties, mSubscriberId, mLegacyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "NetworkStateSnapshot{"
|
return "NetworkStateSnapshot{"
|
||||||
+ "network=" + network
|
+ "network=" + mNetwork
|
||||||
+ ", networkCapabilities=" + networkCapabilities
|
+ ", networkCapabilities=" + mNetworkCapabilities
|
||||||
+ ", linkProperties=" + linkProperties
|
+ ", linkProperties=" + mLinkProperties
|
||||||
+ ", subscriberId='" + NetworkIdentityUtils.scrubSubscriberId(subscriberId) + '\''
|
+ ", subscriberId='" + NetworkIdentityUtils.scrubSubscriberId(mSubscriberId) + '\''
|
||||||
+ ", legacyType=" + legacyType
|
+ ", legacyType=" + mLegacyType
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2150,11 +2150,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) {
|
for (NetworkStateSnapshot snapshot : getAllNetworkStateSnapshot()) {
|
||||||
// NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the
|
// NetworkStateSnapshot doesn't contain NetworkInfo, so need to fetch it from the
|
||||||
// NetworkAgentInfo.
|
// NetworkAgentInfo.
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.network);
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(snapshot.getNetwork());
|
||||||
if (nai != null && nai.networkInfo.isConnected()) {
|
if (nai != null && nai.networkInfo.isConnected()) {
|
||||||
result.add(new NetworkState(new NetworkInfo(nai.networkInfo),
|
result.add(new NetworkState(new NetworkInfo(nai.networkInfo),
|
||||||
snapshot.linkProperties, snapshot.networkCapabilities, snapshot.network,
|
snapshot.getLinkProperties(), snapshot.getNetworkCapabilities(),
|
||||||
snapshot.subscriberId));
|
snapshot.getNetwork(), snapshot.getSubscriberId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toArray(new NetworkState[result.size()]);
|
return result.toArray(new NetworkState[result.size()]);
|
||||||
|
|||||||
@@ -1942,7 +1942,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
* Collect all ifaces from a {@link NetworkStateSnapshot} into the given set.
|
* Collect all ifaces from a {@link NetworkStateSnapshot} into the given set.
|
||||||
*/
|
*/
|
||||||
private static void collectIfaces(ArraySet<String> ifaces, NetworkStateSnapshot snapshot) {
|
private static void collectIfaces(ArraySet<String> ifaces, NetworkStateSnapshot snapshot) {
|
||||||
ifaces.addAll(snapshot.linkProperties.getAllInterfaceNames());
|
ifaces.addAll(snapshot.getLinkProperties().getAllInterfaceNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2023,7 +2023,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
mNetIdToSubId.clear();
|
mNetIdToSubId.clear();
|
||||||
final ArrayMap<NetworkStateSnapshot, NetworkIdentity> identified = new ArrayMap<>();
|
final ArrayMap<NetworkStateSnapshot, NetworkIdentity> identified = new ArrayMap<>();
|
||||||
for (final NetworkStateSnapshot snapshot : snapshots) {
|
for (final NetworkStateSnapshot snapshot : snapshots) {
|
||||||
mNetIdToSubId.put(snapshot.network.getNetId(), parseSubId(snapshot));
|
mNetIdToSubId.put(snapshot.getNetwork().getNetId(), parseSubId(snapshot));
|
||||||
|
|
||||||
// Policies matched by NPMS only match by subscriber ID or by ssid. Thus subtype
|
// Policies matched by NPMS only match by subscriber ID or by ssid. Thus subtype
|
||||||
// in the object created here is never used and its value doesn't matter, so use
|
// in the object created here is never used and its value doesn't matter, so use
|
||||||
@@ -2111,7 +2111,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
// One final pass to catch any metered ifaces that don't have explicitly
|
// One final pass to catch any metered ifaces that don't have explicitly
|
||||||
// defined policies; typically Wi-Fi networks.
|
// defined policies; typically Wi-Fi networks.
|
||||||
for (final NetworkStateSnapshot snapshot : snapshots) {
|
for (final NetworkStateSnapshot snapshot : snapshots) {
|
||||||
if (!snapshot.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_METERED)) {
|
if (!snapshot.getNetworkCapabilities().hasCapability(NET_CAPABILITY_NOT_METERED)) {
|
||||||
matchingIfaces.clear();
|
matchingIfaces.clear();
|
||||||
collectIfaces(matchingIfaces, snapshot);
|
collectIfaces(matchingIfaces, snapshot);
|
||||||
for (int j = matchingIfaces.size() - 1; j >= 0; j--) {
|
for (int j = matchingIfaces.size() - 1; j >= 0; j--) {
|
||||||
@@ -2147,14 +2147,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
mSubscriptionOpportunisticQuota.clear();
|
mSubscriptionOpportunisticQuota.clear();
|
||||||
for (final NetworkStateSnapshot snapshot : snapshots) {
|
for (final NetworkStateSnapshot snapshot : snapshots) {
|
||||||
if (!quotaEnabled) continue;
|
if (!quotaEnabled) continue;
|
||||||
if (snapshot.network == null) continue;
|
if (snapshot.getNetwork() == null) continue;
|
||||||
final int subId = getSubIdLocked(snapshot.network);
|
final int subId = getSubIdLocked(snapshot.getNetwork());
|
||||||
final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId);
|
final SubscriptionPlan plan = getPrimarySubscriptionPlanLocked(subId);
|
||||||
if (plan == null) continue;
|
if (plan == null) continue;
|
||||||
|
|
||||||
final long quotaBytes;
|
final long quotaBytes;
|
||||||
final long limitBytes = plan.getDataLimitBytes();
|
final long limitBytes = plan.getDataLimitBytes();
|
||||||
if (!snapshot.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_ROAMING)) {
|
if (!snapshot.getNetworkCapabilities().hasCapability(NET_CAPABILITY_NOT_ROAMING)) {
|
||||||
// Clamp to 0 when roaming
|
// Clamp to 0 when roaming
|
||||||
quotaBytes = 0;
|
quotaBytes = 0;
|
||||||
} else if (limitBytes == SubscriptionPlan.BYTES_UNKNOWN) {
|
} else if (limitBytes == SubscriptionPlan.BYTES_UNKNOWN) {
|
||||||
@@ -2172,7 +2172,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.truncatedTo(ChronoUnit.DAYS)
|
.truncatedTo(ChronoUnit.DAYS)
|
||||||
.toInstant().toEpochMilli();
|
.toInstant().toEpochMilli();
|
||||||
final long totalBytes = getTotalBytes(
|
final long totalBytes = getTotalBytes(
|
||||||
NetworkTemplate.buildTemplateMobileAll(snapshot.subscriberId),
|
NetworkTemplate.buildTemplateMobileAll(snapshot.getSubscriberId()),
|
||||||
start, startOfDay);
|
start, startOfDay);
|
||||||
final long remainingBytes = limitBytes - totalBytes;
|
final long remainingBytes = limitBytes - totalBytes;
|
||||||
// Number of remaining days including current day
|
// Number of remaining days including current day
|
||||||
@@ -5807,8 +5807,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
private int parseSubId(@NonNull NetworkStateSnapshot snapshot) {
|
private int parseSubId(@NonNull NetworkStateSnapshot snapshot) {
|
||||||
int subId = INVALID_SUBSCRIPTION_ID;
|
int subId = INVALID_SUBSCRIPTION_ID;
|
||||||
if (snapshot.networkCapabilities.hasTransport(TRANSPORT_CELLULAR)) {
|
if (snapshot.getNetworkCapabilities().hasTransport(TRANSPORT_CELLULAR)) {
|
||||||
NetworkSpecifier spec = snapshot.networkCapabilities.getNetworkSpecifier();
|
NetworkSpecifier spec = snapshot.getNetworkCapabilities().getNetworkSpecifier();
|
||||||
if (spec instanceof TelephonyNetworkSpecifier) {
|
if (spec instanceof TelephonyNetworkSpecifier) {
|
||||||
subId = ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
subId = ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import static android.content.Intent.ACTION_UID_REMOVED;
|
|||||||
import static android.content.Intent.ACTION_USER_REMOVED;
|
import static android.content.Intent.ACTION_USER_REMOVED;
|
||||||
import static android.content.Intent.EXTRA_UID;
|
import static android.content.Intent.EXTRA_UID;
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
|
||||||
import static android.net.NetworkIdentity.SUBTYPE_COMBINED;
|
import static android.net.NetworkIdentity.SUBTYPE_COMBINED;
|
||||||
import static android.net.NetworkStack.checkNetworkStackPermission;
|
import static android.net.NetworkStack.checkNetworkStackPermission;
|
||||||
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
|
||||||
@@ -97,12 +96,12 @@ import android.net.INetworkStatsSession;
|
|||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkCapabilities;
|
import android.net.NetworkCapabilities;
|
||||||
import android.net.NetworkIdentity;
|
import android.net.NetworkIdentity;
|
||||||
|
import android.net.NetworkSpecifier;
|
||||||
import android.net.NetworkStack;
|
import android.net.NetworkStack;
|
||||||
import android.net.NetworkStateSnapshot;
|
import android.net.NetworkStateSnapshot;
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.NetworkStats.NonMonotonicObserver;
|
import android.net.NetworkStats.NonMonotonicObserver;
|
||||||
import android.net.NetworkStatsHistory;
|
import android.net.NetworkStatsHistory;
|
||||||
import android.net.NetworkSpecifier;
|
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.net.TelephonyNetworkSpecifier;
|
import android.net.TelephonyNetworkSpecifier;
|
||||||
import android.net.TrafficStats;
|
import android.net.TrafficStats;
|
||||||
@@ -1296,9 +1295,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final ArraySet<String> mobileIfaces = new ArraySet<>();
|
final ArraySet<String> mobileIfaces = new ArraySet<>();
|
||||||
for (NetworkStateSnapshot snapshot : snapshots) {
|
for (NetworkStateSnapshot snapshot : snapshots) {
|
||||||
final int displayTransport =
|
final int displayTransport =
|
||||||
getDisplayTransport(snapshot.networkCapabilities.getTransportTypes());
|
getDisplayTransport(snapshot.getNetworkCapabilities().getTransportTypes());
|
||||||
final boolean isMobile = (NetworkCapabilities.TRANSPORT_CELLULAR == displayTransport);
|
final boolean isMobile = (NetworkCapabilities.TRANSPORT_CELLULAR == displayTransport);
|
||||||
final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, snapshot.network);
|
final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, snapshot.getNetwork());
|
||||||
final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED
|
final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED
|
||||||
: getSubTypeForStateSnapshot(snapshot);
|
: getSubTypeForStateSnapshot(snapshot);
|
||||||
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, snapshot,
|
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, snapshot,
|
||||||
@@ -1306,7 +1305,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
// Traffic occurring on the base interface is always counted for
|
// Traffic occurring on the base interface is always counted for
|
||||||
// both total usage and UID details.
|
// both total usage and UID details.
|
||||||
final String baseIface = snapshot.linkProperties.getInterfaceName();
|
final String baseIface = snapshot.getLinkProperties().getInterfaceName();
|
||||||
if (baseIface != null) {
|
if (baseIface != null) {
|
||||||
findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident);
|
findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident);
|
||||||
findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident);
|
findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident);
|
||||||
@@ -1316,7 +1315,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// If IMS is metered, then the IMS network usage has already included VT usage.
|
// If IMS is metered, then the IMS network usage has already included VT usage.
|
||||||
// VT is considered always metered in framework's layer. If VT is not metered
|
// VT is considered always metered in framework's layer. If VT is not metered
|
||||||
// per carrier's policy, modem will report 0 usage for VT calls.
|
// per carrier's policy, modem will report 0 usage for VT calls.
|
||||||
if (snapshot.networkCapabilities.hasCapability(
|
if (snapshot.getNetworkCapabilities().hasCapability(
|
||||||
NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.getMetered()) {
|
NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.getMetered()) {
|
||||||
|
|
||||||
// Copy the identify from IMS one but mark it as metered.
|
// Copy the identify from IMS one but mark it as metered.
|
||||||
@@ -1364,7 +1363,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
// accounting is explicitly bypassed for traffic from the clat uid.
|
// accounting is explicitly bypassed for traffic from the clat uid.
|
||||||
//
|
//
|
||||||
// TODO: This code might be combined to above code.
|
// TODO: This code might be combined to above code.
|
||||||
for (String iface : snapshot.linkProperties.getAllInterfaceNames()) {
|
for (String iface : snapshot.getLinkProperties().getAllInterfaceNames()) {
|
||||||
// baseIface has been handled, so ignore it.
|
// baseIface has been handled, so ignore it.
|
||||||
if (TextUtils.equals(baseIface, iface)) continue;
|
if (TextUtils.equals(baseIface, iface)) continue;
|
||||||
if (iface != null) {
|
if (iface != null) {
|
||||||
@@ -1383,11 +1382,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int getSubIdForMobile(@NonNull NetworkStateSnapshot state) {
|
private static int getSubIdForMobile(@NonNull NetworkStateSnapshot state) {
|
||||||
if (!state.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
if (!state.getNetworkCapabilities().hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||||
throw new IllegalArgumentException("Mobile state need capability TRANSPORT_CELLULAR");
|
throw new IllegalArgumentException("Mobile state need capability TRANSPORT_CELLULAR");
|
||||||
}
|
}
|
||||||
|
|
||||||
final NetworkSpecifier spec = state.networkCapabilities.getNetworkSpecifier();
|
final NetworkSpecifier spec = state.getNetworkCapabilities().getNetworkSpecifier();
|
||||||
if (spec instanceof TelephonyNetworkSpecifier) {
|
if (spec instanceof TelephonyNetworkSpecifier) {
|
||||||
return ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
return ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
||||||
} else {
|
} else {
|
||||||
@@ -1402,11 +1401,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
* transport types do not actually fill this value.
|
* transport types do not actually fill this value.
|
||||||
*/
|
*/
|
||||||
private int getSubTypeForStateSnapshot(@NonNull NetworkStateSnapshot state) {
|
private int getSubTypeForStateSnapshot(@NonNull NetworkStateSnapshot state) {
|
||||||
if (!state.networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
if (!state.getNetworkCapabilities().hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mNetworkStatsSubscriptionsMonitor.getRatTypeForSubscriberId(state.subscriberId);
|
return mNetworkStatsSubscriptionsMonitor.getRatTypeForSubscriberId(state.getSubscriberId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <K> NetworkIdentitySet findOrCreateNetworkIdentitySet(
|
private static <K> NetworkIdentitySet findOrCreateNetworkIdentitySet(
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ import android.net.NetworkStateSnapshot;
|
|||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.NetworkStatsHistory;
|
import android.net.NetworkStatsHistory;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.net.UnderlyingNetworkInfo;
|
|
||||||
import android.net.TelephonyNetworkSpecifier;
|
import android.net.TelephonyNetworkSpecifier;
|
||||||
|
import android.net.UnderlyingNetworkInfo;
|
||||||
import android.net.netstats.provider.INetworkStatsProviderCallback;
|
import android.net.netstats.provider.INetworkStatsProviderCallback;
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -873,7 +873,7 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
final LinkProperties stackedProp = new LinkProperties();
|
final LinkProperties stackedProp = new LinkProperties();
|
||||||
stackedProp.setInterfaceName(stackedIface);
|
stackedProp.setInterfaceName(stackedIface);
|
||||||
final NetworkStateSnapshot wifiState = buildWifiState();
|
final NetworkStateSnapshot wifiState = buildWifiState();
|
||||||
wifiState.linkProperties.addStackedLink(stackedProp);
|
wifiState.getLinkProperties().addStackedLink(stackedProp);
|
||||||
NetworkStateSnapshot[] states = new NetworkStateSnapshot[] {wifiState};
|
NetworkStateSnapshot[] states = new NetworkStateSnapshot[] {wifiState};
|
||||||
|
|
||||||
expectNetworkStatsSummary(buildEmptyStats());
|
expectNetworkStatsSummary(buildEmptyStats());
|
||||||
@@ -1564,10 +1564,10 @@ public class NetworkStatsServiceTest extends NetworkStatsBaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getActiveIface(NetworkStateSnapshot... states) throws Exception {
|
private String getActiveIface(NetworkStateSnapshot... states) throws Exception {
|
||||||
if (states == null || states.length == 0 || states[0].linkProperties == null) {
|
if (states == null || states.length == 0 || states[0].getLinkProperties() == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return states[0].linkProperties.getInterfaceName();
|
return states[0].getLinkProperties().getInterfaceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user