Pass all default networks to NetworkStatsService
This will allow NetworkStatsService to treat traffic on these networks differently from traffic where the app selects a network that is not the default. Bug: 35142602 Test: runtest frameworks-net Change-Id: I5ea9d200d9fb153490c6108bb9390bf152f297da
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,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 +232,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();
|
||||||
|
|
||||||
@@ -779,13 +790,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 +1007,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 +1024,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,6 +1051,10 @@ 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) {
|
||||||
@@ -1511,7 +1526,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: {
|
||||||
|
|||||||
Reference in New Issue
Block a user