From 055165000ee4889f272fffeb396583a6a10b9bf2 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Mon, 8 Mar 2021 15:58:34 +0800 Subject: [PATCH] Replace ConnectivityManager.isNetworkTypeMobile usage in NSS ConnectivityManager is a part of connectivity mainline. The hidden methods dependency in ConnectivityManager should be removed to make it a moudle. NSS use isNetworkTypeMobile to check if the NetworkState belongs to a cellular network or not. It should be replaced by the NetworkCapabilities inside the NetworkState. The result of isNetworkTypeMobile relies on the legacy network type. The legacy network type comes from the network type of its network info. The replacement should consider VPN active case because the network type will not be TYPE_MOBILE. Thus, replace it with Networkcapabilities.getDisplayTransport() to get a transport that can be used to classify a network when displaying its info to users, i.e. it will return TRANSPORT_VPN for a vpn network on cellular network. Bug: 172183305 Test: atest FrameworksNetTests Change-Id: I2132a7288a93e4430cbd9efabc33ae56ce8bdd9b --- .../java/com/android/server/net/NetworkStatsService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index e0f534602d..7b376847fd 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -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.EXTRA_UID; import static android.content.pm.PackageManager.PERMISSION_GRANTED; -import static android.net.ConnectivityManager.isNetworkTypeMobile; import static android.net.NetworkIdentity.SUBTYPE_COMBINED; import static android.net.NetworkStack.checkNetworkStackPermission; import static android.net.NetworkStats.DEFAULT_NETWORK_ALL; @@ -71,6 +70,7 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS; import static android.text.format.DateUtils.MINUTE_IN_MILLIS; import static android.text.format.DateUtils.SECOND_IN_MILLIS; +import static com.android.net.module.util.NetworkCapabilitiesUtils.getDisplayTransport; import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT; import static com.android.server.NetworkManagementSocketTagger.resetKernelUidStats; import static com.android.server.NetworkManagementSocketTagger.setKernelCounterSet; @@ -1291,7 +1291,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub { final boolean combineSubtypeEnabled = mSettings.getCombineSubtypeEnabled(); final ArraySet mobileIfaces = new ArraySet<>(); for (NetworkStateSnapshot snapshot : snapshots) { - final boolean isMobile = isNetworkTypeMobile(snapshot.legacyType); + final int displayTransport = + getDisplayTransport(snapshot.networkCapabilities.getTransportTypes()); + final boolean isMobile = (NetworkCapabilities.TRANSPORT_CELLULAR == displayTransport); final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, snapshot.network); final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED : getSubTypeForStateSnapshot(snapshot);