Track and persist in stats whether traffic is on the default network.
This change adds the defaultNetwork to the ident based on current system networking state, and persists that value to flash. Bug: 35142602 Test: runtest frameworks-net Test: downloaded files using default/non-default networks while watching dumpsys netstats Change-Id: Id8776d149b2977548a9eb455ad4926af55e25aba
This commit is contained in:
@@ -58,21 +58,24 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
final String mNetworkId;
|
||||
final boolean mRoaming;
|
||||
final boolean mMetered;
|
||||
final boolean mDefaultNetwork;
|
||||
|
||||
public NetworkIdentity(
|
||||
int type, int subType, String subscriberId, String networkId, boolean roaming,
|
||||
boolean metered) {
|
||||
boolean metered, boolean defaultNetwork) {
|
||||
mType = type;
|
||||
mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
|
||||
mSubscriberId = subscriberId;
|
||||
mNetworkId = networkId;
|
||||
mRoaming = roaming;
|
||||
mMetered = metered;
|
||||
mDefaultNetwork = defaultNetwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered);
|
||||
return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered,
|
||||
mDefaultNetwork);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +85,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
|
||||
&& Objects.equals(mSubscriberId, ident.mSubscriberId)
|
||||
&& Objects.equals(mNetworkId, ident.mNetworkId)
|
||||
&& mMetered == ident.mMetered;
|
||||
&& mMetered == ident.mMetered
|
||||
&& mDefaultNetwork == ident.mDefaultNetwork;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -109,6 +113,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
builder.append(", ROAMING");
|
||||
}
|
||||
builder.append(", metered=").append(mMetered);
|
||||
builder.append(", defaultNetwork=").append(mDefaultNetwork);
|
||||
return builder.append("}").toString();
|
||||
}
|
||||
|
||||
@@ -153,6 +158,10 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
return mMetered;
|
||||
}
|
||||
|
||||
public boolean getDefaultNetwork() {
|
||||
return mDefaultNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrub given IMSI on production builds.
|
||||
*/
|
||||
@@ -183,7 +192,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
* Build a {@link NetworkIdentity} from the given {@link NetworkState},
|
||||
* assuming that any mobile networks are using the current IMSI.
|
||||
*/
|
||||
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state) {
|
||||
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state,
|
||||
boolean defaultNetwork) {
|
||||
final int type = state.networkInfo.getType();
|
||||
final int subType = state.networkInfo.getSubtype();
|
||||
|
||||
@@ -216,7 +226,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
}
|
||||
}
|
||||
|
||||
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered);
|
||||
return new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered,
|
||||
defaultNetwork);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,6 +248,9 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
if (res == 0) {
|
||||
res = Boolean.compare(mMetered, another.mMetered);
|
||||
}
|
||||
if (res == 0) {
|
||||
res = Boolean.compare(mDefaultNetwork, another.mDefaultNetwork);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user