[FUI06] Stop using NetworkInfo in NetworkState from external callers
This is achieved by:
1. Use legacy network type inside NetworkState to replace the
needs of referencing NetworkInfo.getType().
2. Let getAllNetworkState only return networks with isConnected()
equals true. This allows callers such as NPMS or NSS does not
have to reference to NetworkInfo.isConnected().
Test: atest FrameworksNetTests NetworkPolicyManagerServiceTest
Bug: 174123988
Change-Id: I1c4eb08d18ca973eb8f41d06258872eabc0006b8
This commit is contained in:
@@ -31,7 +31,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Network definition that includes strong identity. Analogous to combining
|
* Network definition that includes strong identity. Analogous to combining
|
||||||
* {@link NetworkInfo} and an IMSI.
|
* {@link NetworkCapabilities} and an IMSI.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -159,7 +159,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
|||||||
*/
|
*/
|
||||||
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state,
|
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state,
|
||||||
boolean defaultNetwork, @NetworkType int subType) {
|
boolean defaultNetwork, @NetworkType int subType) {
|
||||||
final int type = state.networkInfo.getType();
|
final int legacyType = state.legacyNetworkType;
|
||||||
|
|
||||||
String subscriberId = null;
|
String subscriberId = null;
|
||||||
String networkId = null;
|
String networkId = null;
|
||||||
@@ -170,7 +170,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
|||||||
|
|
||||||
subscriberId = state.subscriberId;
|
subscriberId = state.subscriberId;
|
||||||
|
|
||||||
if (type == TYPE_WIFI) {
|
if (legacyType == TYPE_WIFI) {
|
||||||
if (state.networkCapabilities.getSsid() != null) {
|
if (state.networkCapabilities.getSsid() != null) {
|
||||||
networkId = state.networkCapabilities.getSsid();
|
networkId = state.networkCapabilities.getSsid();
|
||||||
if (networkId == null) {
|
if (networkId == null) {
|
||||||
@@ -183,7 +183,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered,
|
return new NetworkIdentity(legacyType, subType, subscriberId, networkId, roaming, metered,
|
||||||
defaultNetwork);
|
defaultNetwork);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ import android.net.LinkProperties;
|
|||||||
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.NetworkInfo;
|
|
||||||
import android.net.NetworkStack;
|
import android.net.NetworkStack;
|
||||||
import android.net.NetworkState;
|
import android.net.NetworkState;
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
@@ -1264,7 +1263,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect all current {@link NetworkState} to derive mapping from {@code iface} to {@link
|
* Inspect all current {@link NetworkState} to derive mapping from {@code iface} to {@link
|
||||||
* NetworkStatsHistory}. When multiple {@link NetworkInfo} are active on a single {@code iface},
|
* NetworkStatsHistory}. When multiple networks are active on a single {@code iface},
|
||||||
* they are combined under a single {@link NetworkIdentitySet}.
|
* they are combined under a single {@link NetworkIdentitySet}.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mStatsLock")
|
@GuardedBy("mStatsLock")
|
||||||
@@ -1294,8 +1293,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
final boolean combineSubtypeEnabled = mSettings.getCombineSubtypeEnabled();
|
final boolean combineSubtypeEnabled = mSettings.getCombineSubtypeEnabled();
|
||||||
final ArraySet<String> mobileIfaces = new ArraySet<>();
|
final ArraySet<String> mobileIfaces = new ArraySet<>();
|
||||||
for (NetworkState state : states) {
|
for (NetworkState state : states) {
|
||||||
if (state.networkInfo.isConnected()) {
|
final boolean isMobile = isNetworkTypeMobile(state.legacyNetworkType);
|
||||||
final boolean isMobile = isNetworkTypeMobile(state.networkInfo.getType());
|
|
||||||
final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, state.network);
|
final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, state.network);
|
||||||
final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED
|
final int subType = combineSubtypeEnabled ? SUBTYPE_COMBINED
|
||||||
: getSubTypeForState(state);
|
: getSubTypeForState(state);
|
||||||
@@ -1374,7 +1372,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mMobileIfaces = mobileIfaces.toArray(new String[mobileIfaces.size()]);
|
mMobileIfaces = mobileIfaces.toArray(new String[mobileIfaces.size()]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user