Snap for 4557233 from 6e3be007786a8b0cc46b50f96438f2860f7f868b to pi-release

Change-Id: I5ef649756f733d771bd9aacc6c2d4ac78a5f53ba
This commit is contained in:
android-build-team Robot
2018-01-21 08:22:49 +00:00
10 changed files with 294 additions and 51 deletions

View File

@@ -18,6 +18,7 @@ package android.net;
import android.net.DataUsageRequest; import android.net.DataUsageRequest;
import android.net.INetworkStatsSession; import android.net.INetworkStatsSession;
import android.net.Network;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.NetworkStatsHistory; import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
@@ -53,7 +54,7 @@ interface INetworkStatsService {
void setUidForeground(int uid, boolean uidForeground); void setUidForeground(int uid, boolean uidForeground);
/** Force update of ifaces. */ /** Force update of ifaces. */
void forceUpdateIfaces(); void forceUpdateIfaces(in Network[] defaultNetworks);
/** Force update of statistics. */ /** Force update of statistics. */
void forceUpdate(); void forceUpdate();

View File

@@ -19,6 +19,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.SystemService; import android.annotation.SystemService;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.content.Context; import android.content.Context;
@@ -624,6 +625,133 @@ public final class IpSecManager {
return new UdpEncapsulationSocket(mService, 0); return new UdpEncapsulationSocket(mService, 0);
} }
/**
* This class represents an IpSecTunnelInterface
*
* <p>IpSecTunnelInterface objects track tunnel interfaces that serve as
* local endpoints for IPsec tunnels.
*
* <p>Creating an IpSecTunnelInterface creates a device to which IpSecTransforms may be
* applied to provide IPsec security to packets sent through the tunnel. While a tunnel
* cannot be used in standalone mode within Android, the higher layers may use the tunnel
* to create Network objects which are accessible to the Android system.
* @hide
*/
@SystemApi
public static final class IpSecTunnelInterface implements AutoCloseable {
private final IIpSecService mService;
private final InetAddress mRemoteAddress;
private final InetAddress mLocalAddress;
private final Network mUnderlyingNetwork;
private final CloseGuard mCloseGuard = CloseGuard.get();
private String mInterfaceName;
private int mResourceId = INVALID_RESOURCE_ID;
/** Get the underlying SPI held by this object. */
public String getInterfaceName() {
return mInterfaceName;
}
/**
* Add an address to the IpSecTunnelInterface
*
* <p>Add an address which may be used as the local inner address for
* tunneled traffic.
*
* @param address the local address for traffic inside the tunnel
* @throws IOException if the address could not be added
* @hide
*/
public void addAddress(LinkAddress address) throws IOException {
}
/**
* Remove an address from the IpSecTunnelInterface
*
* <p>Remove an address which was previously added to the IpSecTunnelInterface
*
* @param address to be removed
* @throws IOException if the address could not be removed
* @hide
*/
public void removeAddress(LinkAddress address) throws IOException {
}
private IpSecTunnelInterface(@NonNull IIpSecService service,
@NonNull InetAddress localAddress, @NonNull InetAddress remoteAddress,
@NonNull Network underlyingNetwork)
throws ResourceUnavailableException, IOException {
mService = service;
mLocalAddress = localAddress;
mRemoteAddress = remoteAddress;
mUnderlyingNetwork = underlyingNetwork;
// TODO: Call IpSecService
}
/**
* Delete an IpSecTunnelInterface
*
* <p>Calling close will deallocate the IpSecTunnelInterface and all of its system
* resources. Any packets bound for this interface either inbound or outbound will
* all be lost.
*/
@Override
public void close() {
// try {
// TODO: Call IpSecService
mResourceId = INVALID_RESOURCE_ID;
// } catch (RemoteException e) {
// throw e.rethrowFromSystemServer();
// }
mCloseGuard.close();
}
/** Check that the Interface was closed properly. */
@Override
protected void finalize() throws Throwable {
if (mCloseGuard != null) {
mCloseGuard.warnIfOpen();
}
close();
}
}
/**
* Create a new IpSecTunnelInterface as a local endpoint for tunneled IPsec traffic.
*
* @param localAddress The local addres of the tunnel
* @param remoteAddress The local addres of the tunnel
* @param underlyingNetwork the {@link Network} that will carry traffic for this tunnel.
* This network should almost certainly be a network such as WiFi with an L2 address.
* @return a new {@link IpSecManager#IpSecTunnelInterface} with the specified properties
* @throws IOException indicating that the socket could not be opened or bound
* @throws ResourceUnavailableException indicating that too many encapsulation sockets are open
* @hide
*/
@SystemApi
public IpSecTunnelInterface createIpSecTunnelInterface(@NonNull InetAddress localAddress,
@NonNull InetAddress remoteAddress, @NonNull Network underlyingNetwork)
throws ResourceUnavailableException, IOException {
return new IpSecTunnelInterface(mService, localAddress, remoteAddress, underlyingNetwork);
}
/**
* Apply a transform to the IpSecTunnelInterface
*
* @param tunnel The {@link IpSecManager#IpSecTunnelInterface} that will use the supplied
* transform.
* @param direction the direction, {@link DIRECTION_OUT} or {@link #DIRECTION_IN} in which
* the transform will be used.
* @param transform an {@link IpSecTransform} created in tunnel mode
* @throws IOException indicating that the transform could not be applied due to a lower
* layer failure.
* @hide
*/
@SystemApi
void applyTunnelModeTransform(IpSecTunnelInterface tunnel, int direction,
IpSecTransform transform) throws IOException {
// TODO: call IpSecService
}
/** /**
* Construct an instance of IpSecManager within an application context. * Construct an instance of IpSecManager within an application context.
* *

View File

@@ -299,21 +299,6 @@ public final class IpSecTransform implements AutoCloseable {
return this; return this;
} }
/**
* Set the {@link Network} which will carry tunneled traffic.
*
* <p>Restricts the transformed traffic to a particular {@link Network}. This is required
* for tunnel mode, otherwise tunneled traffic would be sent on the default network.
*
* @hide
*/
@SystemApi
public IpSecTransform.Builder setUnderlyingNetwork(@NonNull Network net) {
Preconditions.checkNotNull(net);
mConfig.setNetwork(net);
return this;
}
/** /**
* Add UDP encapsulation to an IPv4 transform. * Add UDP encapsulation to an IPv4 transform.
* *
@@ -415,6 +400,7 @@ public final class IpSecTransform implements AutoCloseable {
* @throws IOException indicating other errors * @throws IOException indicating other errors
* @hide * @hide
*/ */
@SystemApi
public IpSecTransform buildTunnelModeTransform( public IpSecTransform buildTunnelModeTransform(
@NonNull InetAddress sourceAddress, @NonNull InetAddress sourceAddress,
@NonNull IpSecManager.SecurityParameterIndex spi) @NonNull IpSecManager.SecurityParameterIndex spi)

View File

@@ -58,21 +58,24 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
final String mNetworkId; final String mNetworkId;
final boolean mRoaming; final boolean mRoaming;
final boolean mMetered; final boolean mMetered;
final boolean mDefaultNetwork;
public NetworkIdentity( public NetworkIdentity(
int type, int subType, String subscriberId, String networkId, boolean roaming, int type, int subType, String subscriberId, String networkId, boolean roaming,
boolean metered) { boolean metered, boolean defaultNetwork) {
mType = type; mType = type;
mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType; mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
mSubscriberId = subscriberId; mSubscriberId = subscriberId;
mNetworkId = networkId; mNetworkId = networkId;
mRoaming = roaming; mRoaming = roaming;
mMetered = metered; mMetered = metered;
mDefaultNetwork = defaultNetwork;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered); return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming, mMetered,
mDefaultNetwork);
} }
@Override @Override
@@ -82,7 +85,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
&& Objects.equals(mSubscriberId, ident.mSubscriberId) && Objects.equals(mSubscriberId, ident.mSubscriberId)
&& Objects.equals(mNetworkId, ident.mNetworkId) && Objects.equals(mNetworkId, ident.mNetworkId)
&& mMetered == ident.mMetered; && mMetered == ident.mMetered
&& mDefaultNetwork == ident.mDefaultNetwork;
} }
return false; return false;
} }
@@ -109,6 +113,7 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
builder.append(", ROAMING"); builder.append(", ROAMING");
} }
builder.append(", metered=").append(mMetered); builder.append(", metered=").append(mMetered);
builder.append(", defaultNetwork=").append(mDefaultNetwork);
return builder.append("}").toString(); return builder.append("}").toString();
} }
@@ -153,6 +158,10 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
return mMetered; return mMetered;
} }
public boolean getDefaultNetwork() {
return mDefaultNetwork;
}
/** /**
* Scrub given IMSI on production builds. * 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}, * Build a {@link NetworkIdentity} from the given {@link NetworkState},
* assuming that any mobile networks are using the current IMSI. * 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 type = state.networkInfo.getType();
final int subType = state.networkInfo.getSubtype(); 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 @Override
@@ -237,6 +248,9 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
if (res == 0) { if (res == 0) {
res = Boolean.compare(mMetered, another.mMetered); res = Boolean.compare(mMetered, another.mMetered);
} }
if (res == 0) {
res = Boolean.compare(mDefaultNetwork, another.mDefaultNetwork);
}
return res; return res;
} }
} }

View File

@@ -82,6 +82,13 @@ public class NetworkStats implements Parcelable {
/** {@link #roaming} value where roaming data is accounted. */ /** {@link #roaming} value where roaming data is accounted. */
public static final int ROAMING_YES = 1; public static final int ROAMING_YES = 1;
/** {@link #onDefaultNetwork} value to account for all default network states. */
public static final int DEFAULT_NETWORK_ALL = -1;
/** {@link #onDefaultNetwork} value to account for usage while not the default network. */
public static final int DEFAULT_NETWORK_NO = 0;
/** {@link #onDefaultNetwork} value to account for usage while the default network. */
public static final int DEFAULT_NETWORK_YES = 1;
/** Denotes a request for stats at the interface level. */ /** Denotes a request for stats at the interface level. */
public static final int STATS_PER_IFACE = 0; public static final int STATS_PER_IFACE = 0;
/** Denotes a request for stats at the interface and UID level. */ /** Denotes a request for stats at the interface and UID level. */
@@ -102,6 +109,7 @@ public class NetworkStats implements Parcelable {
private int[] tag; private int[] tag;
private int[] metered; private int[] metered;
private int[] roaming; private int[] roaming;
private int[] defaultNetwork;
private long[] rxBytes; private long[] rxBytes;
private long[] rxPackets; private long[] rxPackets;
private long[] txBytes; private long[] txBytes;
@@ -125,6 +133,12 @@ public class NetworkStats implements Parcelable {
* getSummary(). * getSummary().
*/ */
public int roaming; public int roaming;
/**
* Note that this is only populated w/ the default value when read from /proc or written
* to disk. We merge in the correct value when reporting this value to clients of
* getSummary().
*/
public int defaultNetwork;
public long rxBytes; public long rxBytes;
public long rxPackets; public long rxPackets;
public long txBytes; public long txBytes;
@@ -142,18 +156,27 @@ public class NetworkStats implements Parcelable {
public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets, public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets,
long txBytes, long txPackets, long operations) { long txBytes, long txPackets, long operations) {
this(iface, uid, set, tag, METERED_NO, ROAMING_NO, rxBytes, rxPackets, txBytes, this(iface, uid, set, tag, METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO,
txPackets, operations); rxBytes, rxPackets, txBytes, txPackets, operations);
}
// TODO: fix the the telephony code to pass DEFAULT_NETWORK_YES and remove this constructor.
public Entry(String iface, int uid, int set, int tag, int metered, int roaming,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
this(iface, uid, set, tag, metered, roaming, DEFAULT_NETWORK_YES, rxBytes, rxPackets,
txBytes, txPackets, operations);
} }
public Entry(String iface, int uid, int set, int tag, int metered, int roaming, public Entry(String iface, int uid, int set, int tag, int metered, int roaming,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) { int defaultNetwork, long rxBytes, long rxPackets, long txBytes, long txPackets,
long operations) {
this.iface = iface; this.iface = iface;
this.uid = uid; this.uid = uid;
this.set = set; this.set = set;
this.tag = tag; this.tag = tag;
this.metered = metered; this.metered = metered;
this.roaming = roaming; this.roaming = roaming;
this.defaultNetwork = defaultNetwork;
this.rxBytes = rxBytes; this.rxBytes = rxBytes;
this.rxPackets = rxPackets; this.rxPackets = rxPackets;
this.txBytes = txBytes; this.txBytes = txBytes;
@@ -187,6 +210,7 @@ public class NetworkStats implements Parcelable {
builder.append(" tag=").append(tagToString(tag)); builder.append(" tag=").append(tagToString(tag));
builder.append(" metered=").append(meteredToString(metered)); builder.append(" metered=").append(meteredToString(metered));
builder.append(" roaming=").append(roamingToString(roaming)); builder.append(" roaming=").append(roamingToString(roaming));
builder.append(" defaultNetwork=").append(defaultNetworkToString(defaultNetwork));
builder.append(" rxBytes=").append(rxBytes); builder.append(" rxBytes=").append(rxBytes);
builder.append(" rxPackets=").append(rxPackets); builder.append(" rxPackets=").append(rxPackets);
builder.append(" txBytes=").append(txBytes); builder.append(" txBytes=").append(txBytes);
@@ -200,7 +224,8 @@ public class NetworkStats implements Parcelable {
if (o instanceof Entry) { if (o instanceof Entry) {
final Entry e = (Entry) o; final Entry e = (Entry) o;
return uid == e.uid && set == e.set && tag == e.tag && metered == e.metered return uid == e.uid && set == e.set && tag == e.tag && metered == e.metered
&& roaming == e.roaming && rxBytes == e.rxBytes && rxPackets == e.rxPackets && roaming == e.roaming && defaultNetwork == e.defaultNetwork
&& rxBytes == e.rxBytes && rxPackets == e.rxPackets
&& txBytes == e.txBytes && txPackets == e.txPackets && txBytes == e.txBytes && txPackets == e.txPackets
&& operations == e.operations && iface.equals(e.iface); && operations == e.operations && iface.equals(e.iface);
} }
@@ -209,7 +234,7 @@ public class NetworkStats implements Parcelable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(uid, set, tag, metered, roaming, iface); return Objects.hash(uid, set, tag, metered, roaming, defaultNetwork, iface);
} }
} }
@@ -224,6 +249,7 @@ public class NetworkStats implements Parcelable {
this.tag = new int[initialSize]; this.tag = new int[initialSize];
this.metered = new int[initialSize]; this.metered = new int[initialSize];
this.roaming = new int[initialSize]; this.roaming = new int[initialSize];
this.defaultNetwork = new int[initialSize];
this.rxBytes = new long[initialSize]; this.rxBytes = new long[initialSize];
this.rxPackets = new long[initialSize]; this.rxPackets = new long[initialSize];
this.txBytes = new long[initialSize]; this.txBytes = new long[initialSize];
@@ -238,6 +264,7 @@ public class NetworkStats implements Parcelable {
this.tag = EmptyArray.INT; this.tag = EmptyArray.INT;
this.metered = EmptyArray.INT; this.metered = EmptyArray.INT;
this.roaming = EmptyArray.INT; this.roaming = EmptyArray.INT;
this.defaultNetwork = EmptyArray.INT;
this.rxBytes = EmptyArray.LONG; this.rxBytes = EmptyArray.LONG;
this.rxPackets = EmptyArray.LONG; this.rxPackets = EmptyArray.LONG;
this.txBytes = EmptyArray.LONG; this.txBytes = EmptyArray.LONG;
@@ -256,6 +283,7 @@ public class NetworkStats implements Parcelable {
tag = parcel.createIntArray(); tag = parcel.createIntArray();
metered = parcel.createIntArray(); metered = parcel.createIntArray();
roaming = parcel.createIntArray(); roaming = parcel.createIntArray();
defaultNetwork = parcel.createIntArray();
rxBytes = parcel.createLongArray(); rxBytes = parcel.createLongArray();
rxPackets = parcel.createLongArray(); rxPackets = parcel.createLongArray();
txBytes = parcel.createLongArray(); txBytes = parcel.createLongArray();
@@ -274,6 +302,7 @@ public class NetworkStats implements Parcelable {
dest.writeIntArray(tag); dest.writeIntArray(tag);
dest.writeIntArray(metered); dest.writeIntArray(metered);
dest.writeIntArray(roaming); dest.writeIntArray(roaming);
dest.writeIntArray(defaultNetwork);
dest.writeLongArray(rxBytes); dest.writeLongArray(rxBytes);
dest.writeLongArray(rxPackets); dest.writeLongArray(rxPackets);
dest.writeLongArray(txBytes); dest.writeLongArray(txBytes);
@@ -308,10 +337,11 @@ public class NetworkStats implements Parcelable {
@VisibleForTesting @VisibleForTesting
public NetworkStats addValues(String iface, int uid, int set, int tag, int metered, int roaming, public NetworkStats addValues(String iface, int uid, int set, int tag, int metered, int roaming,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) { int defaultNetwork, long rxBytes, long rxPackets, long txBytes, long txPackets,
long operations) {
return addValues(new Entry( return addValues(new Entry(
iface, uid, set, tag, metered, roaming, rxBytes, rxPackets, txBytes, txPackets, iface, uid, set, tag, metered, roaming, defaultNetwork, rxBytes, rxPackets,
operations)); txBytes, txPackets, operations));
} }
/** /**
@@ -327,6 +357,7 @@ public class NetworkStats implements Parcelable {
tag = Arrays.copyOf(tag, newLength); tag = Arrays.copyOf(tag, newLength);
metered = Arrays.copyOf(metered, newLength); metered = Arrays.copyOf(metered, newLength);
roaming = Arrays.copyOf(roaming, newLength); roaming = Arrays.copyOf(roaming, newLength);
defaultNetwork = Arrays.copyOf(defaultNetwork, newLength);
rxBytes = Arrays.copyOf(rxBytes, newLength); rxBytes = Arrays.copyOf(rxBytes, newLength);
rxPackets = Arrays.copyOf(rxPackets, newLength); rxPackets = Arrays.copyOf(rxPackets, newLength);
txBytes = Arrays.copyOf(txBytes, newLength); txBytes = Arrays.copyOf(txBytes, newLength);
@@ -341,6 +372,7 @@ public class NetworkStats implements Parcelable {
tag[size] = entry.tag; tag[size] = entry.tag;
metered[size] = entry.metered; metered[size] = entry.metered;
roaming[size] = entry.roaming; roaming[size] = entry.roaming;
defaultNetwork[size] = entry.defaultNetwork;
rxBytes[size] = entry.rxBytes; rxBytes[size] = entry.rxBytes;
rxPackets[size] = entry.rxPackets; rxPackets[size] = entry.rxPackets;
txBytes[size] = entry.txBytes; txBytes[size] = entry.txBytes;
@@ -362,6 +394,7 @@ public class NetworkStats implements Parcelable {
entry.tag = tag[i]; entry.tag = tag[i];
entry.metered = metered[i]; entry.metered = metered[i];
entry.roaming = roaming[i]; entry.roaming = roaming[i];
entry.defaultNetwork = defaultNetwork[i];
entry.rxBytes = rxBytes[i]; entry.rxBytes = rxBytes[i];
entry.rxPackets = rxPackets[i]; entry.rxPackets = rxPackets[i];
entry.txBytes = txBytes[i]; entry.txBytes = txBytes[i];
@@ -416,7 +449,7 @@ public class NetworkStats implements Parcelable {
*/ */
public NetworkStats combineValues(Entry entry) { public NetworkStats combineValues(Entry entry) {
final int i = findIndex(entry.iface, entry.uid, entry.set, entry.tag, entry.metered, final int i = findIndex(entry.iface, entry.uid, entry.set, entry.tag, entry.metered,
entry.roaming); entry.roaming, entry.defaultNetwork);
if (i == -1) { if (i == -1) {
// only create new entry when positive contribution // only create new entry when positive contribution
addValues(entry); addValues(entry);
@@ -444,10 +477,12 @@ public class NetworkStats implements Parcelable {
/** /**
* Find first stats index that matches the requested parameters. * Find first stats index that matches the requested parameters.
*/ */
public int findIndex(String iface, int uid, int set, int tag, int metered, int roaming) { public int findIndex(String iface, int uid, int set, int tag, int metered, int roaming,
int defaultNetwork) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i] if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
&& metered == this.metered[i] && roaming == this.roaming[i] && metered == this.metered[i] && roaming == this.roaming[i]
&& defaultNetwork == this.defaultNetwork[i]
&& Objects.equals(iface, this.iface[i])) { && Objects.equals(iface, this.iface[i])) {
return i; return i;
} }
@@ -461,7 +496,7 @@ public class NetworkStats implements Parcelable {
*/ */
@VisibleForTesting @VisibleForTesting
public int findIndexHinted(String iface, int uid, int set, int tag, int metered, int roaming, public int findIndexHinted(String iface, int uid, int set, int tag, int metered, int roaming,
int hintIndex) { int defaultNetwork, int hintIndex) {
for (int offset = 0; offset < size; offset++) { for (int offset = 0; offset < size; offset++) {
final int halfOffset = offset / 2; final int halfOffset = offset / 2;
@@ -475,6 +510,7 @@ public class NetworkStats implements Parcelable {
if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i] if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
&& metered == this.metered[i] && roaming == this.roaming[i] && metered == this.metered[i] && roaming == this.roaming[i]
&& defaultNetwork == this.defaultNetwork[i]
&& Objects.equals(iface, this.iface[i])) { && Objects.equals(iface, this.iface[i])) {
return i; return i;
} }
@@ -489,7 +525,8 @@ public class NetworkStats implements Parcelable {
*/ */
public void spliceOperationsFrom(NetworkStats stats) { public void spliceOperationsFrom(NetworkStats stats) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final int j = stats.findIndex(iface[i], uid[i], set[i], tag[i], metered[i], roaming[i]); final int j = stats.findIndex(iface[i], uid[i], set[i], tag[i], metered[i], roaming[i],
defaultNetwork[i]);
if (j == -1) { if (j == -1) {
operations[i] = 0; operations[i] = 0;
} else { } else {
@@ -581,6 +618,7 @@ public class NetworkStats implements Parcelable {
entry.tag = TAG_NONE; entry.tag = TAG_NONE;
entry.metered = METERED_ALL; entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL; entry.roaming = ROAMING_ALL;
entry.defaultNetwork = DEFAULT_NETWORK_ALL;
entry.rxBytes = 0; entry.rxBytes = 0;
entry.rxPackets = 0; entry.rxPackets = 0;
entry.txBytes = 0; entry.txBytes = 0;
@@ -677,6 +715,7 @@ public class NetworkStats implements Parcelable {
entry.tag = left.tag[i]; entry.tag = left.tag[i];
entry.metered = left.metered[i]; entry.metered = left.metered[i];
entry.roaming = left.roaming[i]; entry.roaming = left.roaming[i];
entry.defaultNetwork = left.defaultNetwork[i];
entry.rxBytes = left.rxBytes[i]; entry.rxBytes = left.rxBytes[i];
entry.rxPackets = left.rxPackets[i]; entry.rxPackets = left.rxPackets[i];
entry.txBytes = left.txBytes[i]; entry.txBytes = left.txBytes[i];
@@ -685,7 +724,7 @@ public class NetworkStats implements Parcelable {
// find remote row that matches, and subtract // find remote row that matches, and subtract
final int j = right.findIndexHinted(entry.iface, entry.uid, entry.set, entry.tag, final int j = right.findIndexHinted(entry.iface, entry.uid, entry.set, entry.tag,
entry.metered, entry.roaming, i); entry.metered, entry.roaming, entry.defaultNetwork, i);
if (j != -1) { if (j != -1) {
// Found matching row, subtract remote value. // Found matching row, subtract remote value.
entry.rxBytes -= right.rxBytes[j]; entry.rxBytes -= right.rxBytes[j];
@@ -725,6 +764,7 @@ public class NetworkStats implements Parcelable {
entry.tag = TAG_NONE; entry.tag = TAG_NONE;
entry.metered = METERED_ALL; entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL; entry.roaming = ROAMING_ALL;
entry.defaultNetwork = DEFAULT_NETWORK_ALL;
entry.operations = 0L; entry.operations = 0L;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@@ -755,6 +795,7 @@ public class NetworkStats implements Parcelable {
entry.tag = TAG_NONE; entry.tag = TAG_NONE;
entry.metered = METERED_ALL; entry.metered = METERED_ALL;
entry.roaming = ROAMING_ALL; entry.roaming = ROAMING_ALL;
entry.defaultNetwork = DEFAULT_NETWORK_ALL;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// skip specific tags, since already counted in TAG_NONE // skip specific tags, since already counted in TAG_NONE
@@ -802,6 +843,7 @@ public class NetworkStats implements Parcelable {
pw.print(" tag="); pw.print(tagToString(tag[i])); pw.print(" tag="); pw.print(tagToString(tag[i]));
pw.print(" metered="); pw.print(meteredToString(metered[i])); pw.print(" metered="); pw.print(meteredToString(metered[i]));
pw.print(" roaming="); pw.print(roamingToString(roaming[i])); pw.print(" roaming="); pw.print(roamingToString(roaming[i]));
pw.print(" defaultNetwork="); pw.print(defaultNetworkToString(defaultNetwork[i]));
pw.print(" rxBytes="); pw.print(rxBytes[i]); pw.print(" rxBytes="); pw.print(rxBytes[i]);
pw.print(" rxPackets="); pw.print(rxPackets[i]); pw.print(" rxPackets="); pw.print(rxPackets[i]);
pw.print(" txBytes="); pw.print(txBytes[i]); pw.print(" txBytes="); pw.print(txBytes[i]);
@@ -900,6 +942,22 @@ public class NetworkStats implements Parcelable {
} }
} }
/**
* Return text description of {@link #defaultNetwork} value.
*/
public static String defaultNetworkToString(int defaultNetwork) {
switch (defaultNetwork) {
case DEFAULT_NETWORK_ALL:
return "ALL";
case DEFAULT_NETWORK_NO:
return "NO";
case DEFAULT_NETWORK_YES:
return "YES";
default:
return "UNKNOWN";
}
}
@Override @Override
public String toString() { public String toString() {
final CharArrayWriter writer = new CharArrayWriter(); final CharArrayWriter writer = new CharArrayWriter();
@@ -1055,6 +1113,7 @@ public class NetworkStats implements Parcelable {
tmpEntry.set = set[i]; tmpEntry.set = set[i];
tmpEntry.metered = metered[i]; tmpEntry.metered = metered[i];
tmpEntry.roaming = roaming[i]; tmpEntry.roaming = roaming[i];
tmpEntry.defaultNetwork = defaultNetwork[i];
combineValues(tmpEntry); combineValues(tmpEntry);
if (tag[i] == TAG_NONE) { if (tag[i] == TAG_NONE) {
moved.add(tmpEntry); moved.add(tmpEntry);
@@ -1075,6 +1134,7 @@ public class NetworkStats implements Parcelable {
moved.iface = underlyingIface; moved.iface = underlyingIface;
moved.metered = METERED_ALL; moved.metered = METERED_ALL;
moved.roaming = ROAMING_ALL; moved.roaming = ROAMING_ALL;
moved.defaultNetwork = DEFAULT_NETWORK_ALL;
combineValues(moved); combineValues(moved);
// Caveat: if the vpn software uses tag, the total tagged traffic may be greater than // Caveat: if the vpn software uses tag, the total tagged traffic may be greater than
@@ -1085,13 +1145,13 @@ public class NetworkStats implements Parcelable {
// roaming data after applying these adjustments, by checking the NetworkIdentity of the // roaming data after applying these adjustments, by checking the NetworkIdentity of the
// underlying iface. // underlying iface.
int idxVpnBackground = findIndex(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE, int idxVpnBackground = findIndex(underlyingIface, tunUid, SET_DEFAULT, TAG_NONE,
METERED_NO, ROAMING_NO); METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO);
if (idxVpnBackground != -1) { if (idxVpnBackground != -1) {
tunSubtract(idxVpnBackground, this, moved); tunSubtract(idxVpnBackground, this, moved);
} }
int idxVpnForeground = findIndex(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE, int idxVpnForeground = findIndex(underlyingIface, tunUid, SET_FOREGROUND, TAG_NONE,
METERED_NO, ROAMING_NO); METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO);
if (idxVpnForeground != -1) { if (idxVpnForeground != -1) {
tunSubtract(idxVpnForeground, this, moved); tunSubtract(idxVpnForeground, this, moved);
} }

View File

@@ -219,7 +219,7 @@ public class NetworkStatsFactory {
} }
NetworkStats.Entry adjust = NetworkStats.Entry adjust =
new NetworkStats.Entry(baseIface, 0, 0, 0, 0L, 0L, 0L, 0L, 0L); new NetworkStats.Entry(baseIface, 0, 0, 0, 0, 0, 0, 0L, 0L, 0L, 0L, 0L);
// Subtract any 464lat traffic seen for the root UID on the current base interface. // Subtract any 464lat traffic seen for the root UID on the current base interface.
adjust.rxBytes -= (entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA); adjust.rxBytes -= (entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA);
adjust.txBytes -= (entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA); adjust.txBytes -= (entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA);

View File

@@ -45,6 +45,7 @@ static struct {
jfieldID tag; jfieldID tag;
jfieldID metered; jfieldID metered;
jfieldID roaming; jfieldID roaming;
jfieldID defaultNetwork;
jfieldID rxBytes; jfieldID rxBytes;
jfieldID rxPackets; jfieldID rxPackets;
jfieldID txBytes; jfieldID txBytes;
@@ -246,6 +247,9 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
ScopedIntArrayRW roaming(env, get_int_array(env, stats, ScopedIntArrayRW roaming(env, get_int_array(env, stats,
gNetworkStatsClassInfo.roaming, size, grow)); gNetworkStatsClassInfo.roaming, size, grow));
if (roaming.get() == NULL) return -1; if (roaming.get() == NULL) return -1;
ScopedIntArrayRW defaultNetwork(env, get_int_array(env, stats,
gNetworkStatsClassInfo.defaultNetwork, size, grow));
if (defaultNetwork.get() == NULL) return -1;
ScopedLongArrayRW rxBytes(env, get_long_array(env, stats, ScopedLongArrayRW rxBytes(env, get_long_array(env, stats,
gNetworkStatsClassInfo.rxBytes, size, grow)); gNetworkStatsClassInfo.rxBytes, size, grow));
if (rxBytes.get() == NULL) return -1; if (rxBytes.get() == NULL) return -1;
@@ -269,7 +273,7 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
uid[i] = lines[i].uid; uid[i] = lines[i].uid;
set[i] = lines[i].set; set[i] = lines[i].set;
tag[i] = lines[i].tag; tag[i] = lines[i].tag;
// Metered and Roaming are populated in Java-land by inspecting the iface properties. // Metered, roaming and defaultNetwork are populated in Java-land.
rxBytes[i] = lines[i].rxBytes; rxBytes[i] = lines[i].rxBytes;
rxPackets[i] = lines[i].rxPackets; rxPackets[i] = lines[i].rxPackets;
txBytes[i] = lines[i].txBytes; txBytes[i] = lines[i].txBytes;
@@ -285,6 +289,8 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
env->SetObjectField(stats, gNetworkStatsClassInfo.tag, tag.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.tag, tag.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.metered, metered.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.metered, metered.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.roaming, roaming.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.roaming, roaming.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.defaultNetwork,
defaultNetwork.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.rxBytes, rxBytes.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.rxBytes, rxBytes.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.rxPackets, rxPackets.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.rxPackets, rxPackets.getJavaArray());
env->SetObjectField(stats, gNetworkStatsClassInfo.txBytes, txBytes.getJavaArray()); env->SetObjectField(stats, gNetworkStatsClassInfo.txBytes, txBytes.getJavaArray());
@@ -318,6 +324,7 @@ int register_com_android_internal_net_NetworkStatsFactory(JNIEnv* env) {
gNetworkStatsClassInfo.tag = GetFieldIDOrDie(env, clazz, "tag", "[I"); gNetworkStatsClassInfo.tag = GetFieldIDOrDie(env, clazz, "tag", "[I");
gNetworkStatsClassInfo.metered = GetFieldIDOrDie(env, clazz, "metered", "[I"); gNetworkStatsClassInfo.metered = GetFieldIDOrDie(env, clazz, "metered", "[I");
gNetworkStatsClassInfo.roaming = GetFieldIDOrDie(env, clazz, "roaming", "[I"); gNetworkStatsClassInfo.roaming = GetFieldIDOrDie(env, clazz, "roaming", "[I");
gNetworkStatsClassInfo.defaultNetwork = GetFieldIDOrDie(env, clazz, "defaultNetwork", "[I");
gNetworkStatsClassInfo.rxBytes = GetFieldIDOrDie(env, clazz, "rxBytes", "[J"); gNetworkStatsClassInfo.rxBytes = GetFieldIDOrDie(env, clazz, "rxBytes", "[J");
gNetworkStatsClassInfo.rxPackets = GetFieldIDOrDie(env, clazz, "rxPackets", "[J"); gNetworkStatsClassInfo.rxPackets = GetFieldIDOrDie(env, clazz, "rxPackets", "[J");
gNetworkStatsClassInfo.txBytes = GetFieldIDOrDie(env, clazz, "txBytes", "[J"); gNetworkStatsClassInfo.txBytes = GetFieldIDOrDie(env, clazz, "txBytes", "[J");

View File

@@ -39,6 +39,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
private static final int VERSION_ADD_ROAMING = 2; private static final int VERSION_ADD_ROAMING = 2;
private static final int VERSION_ADD_NETWORK_ID = 3; private static final int VERSION_ADD_NETWORK_ID = 3;
private static final int VERSION_ADD_METERED = 4; private static final int VERSION_ADD_METERED = 4;
private static final int VERSION_ADD_DEFAULT_NETWORK = 5;
public NetworkIdentitySet() { public NetworkIdentitySet() {
} }
@@ -76,12 +77,20 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
metered = (type == TYPE_MOBILE); metered = (type == TYPE_MOBILE);
} }
add(new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered)); final boolean defaultNetwork;
if (version >= VERSION_ADD_DEFAULT_NETWORK) {
defaultNetwork = in.readBoolean();
} else {
defaultNetwork = true;
}
add(new NetworkIdentity(type, subType, subscriberId, networkId, roaming, metered,
defaultNetwork));
} }
} }
public void writeToStream(DataOutputStream out) throws IOException { public void writeToStream(DataOutputStream out) throws IOException {
out.writeInt(VERSION_ADD_METERED); out.writeInt(VERSION_ADD_DEFAULT_NETWORK);
out.writeInt(size()); out.writeInt(size());
for (NetworkIdentity ident : this) { for (NetworkIdentity ident : this) {
out.writeInt(ident.getType()); out.writeInt(ident.getType());
@@ -90,6 +99,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
writeOptionalString(out, ident.getNetworkId()); writeOptionalString(out, ident.getNetworkId());
out.writeBoolean(ident.getRoaming()); out.writeBoolean(ident.getRoaming());
out.writeBoolean(ident.getMetered()); out.writeBoolean(ident.getMetered());
out.writeBoolean(ident.getDefaultNetwork());
} }
} }
@@ -119,6 +129,20 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> implements
return false; return false;
} }
/** @return whether any {@link NetworkIdentity} in this set is considered on the default
network. */
public boolean areAllMembersOnDefaultNetwork() {
if (isEmpty()) {
return true;
}
for (NetworkIdentity ident : this) {
if (!ident.getDefaultNetwork()) {
return false;
}
}
return true;
}
private static void writeOptionalString(DataOutputStream out, String value) throws IOException { private static void writeOptionalString(DataOutputStream out, String value) throws IOException {
if (value != null) { if (value != null) {
out.writeByte(1); out.writeByte(1);

View File

@@ -17,6 +17,8 @@
package com.android.server.net; package com.android.server.net;
import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.IFACE_ALL;
import static android.net.NetworkStats.DEFAULT_NETWORK_NO;
import static android.net.NetworkStats.DEFAULT_NETWORK_YES;
import static android.net.NetworkStats.METERED_NO; import static android.net.NetworkStats.METERED_NO;
import static android.net.NetworkStats.METERED_YES; import static android.net.NetworkStats.METERED_YES;
import static android.net.NetworkStats.ROAMING_NO; import static android.net.NetworkStats.ROAMING_NO;
@@ -364,6 +366,8 @@ public class NetworkStatsCollection implements FileRotator.Reader {
entry.uid = key.uid; entry.uid = key.uid;
entry.set = key.set; entry.set = key.set;
entry.tag = key.tag; entry.tag = key.tag;
entry.defaultNetwork = key.ident.areAllMembersOnDefaultNetwork() ?
DEFAULT_NETWORK_YES : DEFAULT_NETWORK_NO;
entry.metered = key.ident.isAnyMemberMetered() ? METERED_YES : METERED_NO; entry.metered = key.ident.isAnyMemberMetered() ? METERED_YES : METERED_NO;
entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO; entry.roaming = key.ident.isAnyMemberRoaming() ? ROAMING_YES : ROAMING_NO;
entry.rxBytes = historyEntry.rxBytes; entry.rxBytes = historyEntry.rxBytes;

View File

@@ -25,6 +25,7 @@ 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.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED; import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
import static android.net.ConnectivityManager.isNetworkTypeMobile; import static android.net.ConnectivityManager.isNetworkTypeMobile;
import static android.net.NetworkStats.DEFAULT_NETWORK_ALL;
import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.IFACE_ALL;
import static android.net.NetworkStats.METERED_ALL; import static android.net.NetworkStats.METERED_ALL;
import static android.net.NetworkStats.ROAMING_ALL; import static android.net.NetworkStats.ROAMING_ALL;
@@ -83,6 +84,7 @@ import android.net.INetworkManagementEventObserver;
import android.net.INetworkStatsService; import android.net.INetworkStatsService;
import android.net.INetworkStatsSession; import android.net.INetworkStatsSession;
import android.net.LinkProperties; import android.net.LinkProperties;
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.NetworkInfo;
@@ -231,14 +233,24 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private final Object mStatsLock = new Object(); private final Object mStatsLock = new Object();
/** Set of currently active ifaces. */ /** Set of currently active ifaces. */
@GuardedBy("mStatsLock")
private final ArrayMap<String, NetworkIdentitySet> mActiveIfaces = new ArrayMap<>(); private final ArrayMap<String, NetworkIdentitySet> mActiveIfaces = new ArrayMap<>();
/** Set of currently active ifaces for UID stats. */ /** Set of currently active ifaces for UID stats. */
@GuardedBy("mStatsLock")
private final ArrayMap<String, NetworkIdentitySet> mActiveUidIfaces = new ArrayMap<>(); private final ArrayMap<String, NetworkIdentitySet> mActiveUidIfaces = new ArrayMap<>();
/** Current default active iface. */ /** Current default active iface. */
private String mActiveIface; private String mActiveIface;
/** Set of any ifaces associated with mobile networks since boot. */ /** Set of any ifaces associated with mobile networks since boot. */
@GuardedBy("mStatsLock")
private String[] mMobileIfaces = new String[0]; private String[] mMobileIfaces = new String[0];
/** Set of all ifaces currently used by traffic that does not explicitly specify a Network. */
@GuardedBy("mStatsLock")
private Network[] mDefaultNetworks = new Network[0];
private final DropBoxNonMonotonicObserver mNonMonotonicObserver = private final DropBoxNonMonotonicObserver mNonMonotonicObserver =
new DropBoxNonMonotonicObserver(); new DropBoxNonMonotonicObserver();
@@ -666,9 +678,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null); final NetworkStatsHistory.Entry entry = history.getValues(start, end, now, null);
final NetworkStats stats = new NetworkStats(end - start, 1); final NetworkStats stats = new NetworkStats(end - start, 1);
stats.addValues(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE, METERED_ALL, stats.addValues(new NetworkStats.Entry(IFACE_ALL, UID_ALL, SET_ALL, TAG_NONE,
ROAMING_ALL, entry.rxBytes, entry.rxPackets, entry.txBytes, entry.txPackets, METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, entry.rxBytes, entry.rxPackets,
entry.operations)); entry.txBytes, entry.txPackets, entry.operations));
return stats; return stats;
} }
@@ -779,13 +791,13 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
@Override @Override
public void forceUpdateIfaces() { public void forceUpdateIfaces(Network[] defaultNetworks) {
mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG); mContext.enforceCallingOrSelfPermission(READ_NETWORK_USAGE_HISTORY, TAG);
assertBandwidthControlEnabled(); assertBandwidthControlEnabled();
final long token = Binder.clearCallingIdentity(); final long token = Binder.clearCallingIdentity();
try { try {
updateIfaces(); updateIfaces(defaultNetworks);
} finally { } finally {
Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token);
} }
@@ -996,11 +1008,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
}; };
private void updateIfaces() { private void updateIfaces(Network[] defaultNetworks) {
synchronized (mStatsLock) { synchronized (mStatsLock) {
mWakeLock.acquire(); mWakeLock.acquire();
try { try {
updateIfacesLocked(); updateIfacesLocked(defaultNetworks);
} finally { } finally {
mWakeLock.release(); mWakeLock.release();
} }
@@ -1013,7 +1025,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
* are active on a single {@code iface}, they are combined under a single * are active on a single {@code iface}, they are combined under a single
* {@link NetworkIdentitySet}. * {@link NetworkIdentitySet}.
*/ */
private void updateIfacesLocked() { private void updateIfacesLocked(Network[] defaultNetworks) {
if (!mSystemReady) return; if (!mSystemReady) return;
if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
@@ -1040,12 +1052,18 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// Rebuild active interfaces based on connected networks // Rebuild active interfaces based on connected networks
mActiveIfaces.clear(); mActiveIfaces.clear();
mActiveUidIfaces.clear(); mActiveUidIfaces.clear();
if (defaultNetworks != null) {
// Caller is ConnectivityService. Update the list of default networks.
mDefaultNetworks = defaultNetworks;
}
final ArraySet<String> mobileIfaces = new ArraySet<>(); final ArraySet<String> mobileIfaces = new ArraySet<>();
for (NetworkState state : states) { for (NetworkState state : states) {
if (state.networkInfo.isConnected()) { if (state.networkInfo.isConnected()) {
final boolean isMobile = isNetworkTypeMobile(state.networkInfo.getType()); final boolean isMobile = isNetworkTypeMobile(state.networkInfo.getType());
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state); final boolean isDefault = ArrayUtils.contains(mDefaultNetworks, state.network);
final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state,
isDefault);
// 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.
@@ -1065,7 +1083,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// Copy the identify from IMS one but mark it as metered. // Copy the identify from IMS one but mark it as metered.
NetworkIdentity vtIdent = new NetworkIdentity(ident.getType(), NetworkIdentity vtIdent = new NetworkIdentity(ident.getType(),
ident.getSubType(), ident.getSubscriberId(), ident.getNetworkId(), ident.getSubType(), ident.getSubscriberId(), ident.getNetworkId(),
ident.getRoaming(), true); ident.getRoaming(), true /* metered */,
true /* onDefaultNetwork */);
findOrCreateNetworkIdentitySet(mActiveIfaces, VT_INTERFACE).add(vtIdent); findOrCreateNetworkIdentitySet(mActiveIfaces, VT_INTERFACE).add(vtIdent);
findOrCreateNetworkIdentitySet(mActiveUidIfaces, VT_INTERFACE).add(vtIdent); findOrCreateNetworkIdentitySet(mActiveUidIfaces, VT_INTERFACE).add(vtIdent);
} }
@@ -1511,7 +1530,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
return true; return true;
} }
case MSG_UPDATE_IFACES: { case MSG_UPDATE_IFACES: {
mService.updateIfaces(); mService.updateIfaces(null);
return true; return true;
} }
case MSG_REGISTER_GLOBAL_ALERT: { case MSG_REGISTER_GLOBAL_ALERT: {