Merge "Remove ConnectivityManager and its usages from NetworkStatsService."

This commit is contained in:
Varun Anand
2019-03-01 01:14:34 +00:00
committed by Android (Google) Code Review
2 changed files with 28 additions and 26 deletions

View File

@@ -19,11 +19,13 @@ 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.Network;
import android.net.NetworkState;
import android.net.NetworkStats; import android.net.NetworkStats;
import android.net.NetworkStatsHistory; import android.net.NetworkStatsHistory;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.os.IBinder; import android.os.IBinder;
import android.os.Messenger; import android.os.Messenger;
import com.android.internal.net.VpnInfo;
/** {@hide} */ /** {@hide} */
interface INetworkStatsService { interface INetworkStatsService {
@@ -62,7 +64,11 @@ interface INetworkStatsService {
void incrementOperationCount(int uid, int tag, int operationCount); void incrementOperationCount(int uid, int tag, int operationCount);
/** Force update of ifaces. */ /** Force update of ifaces. */
void forceUpdateIfaces(in Network[] defaultNetworks); void forceUpdateIfaces(
in Network[] defaultNetworks,
in VpnInfo[] vpnArray,
in NetworkState[] networkStates,
in String activeIface);
/** Force update of statistics. */ /** Force update of statistics. */
@UnsupportedAppUsage @UnsupportedAppUsage
void forceUpdate(); void forceUpdate();

View File

@@ -82,7 +82,6 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.DataUsageRequest; import android.net.DataUsageRequest;
import android.net.IConnectivityManager;
import android.net.INetworkManagementEventObserver; import android.net.INetworkManagementEventObserver;
import android.net.INetworkStatsService; import android.net.INetworkStatsService;
import android.net.INetworkStatsSession; import android.net.INetworkStatsSession;
@@ -196,8 +195,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private final boolean mUseBpfTrafficStats; private final boolean mUseBpfTrafficStats;
private IConnectivityManager mConnManager;
@VisibleForTesting @VisibleForTesting
public static final String ACTION_NETWORK_STATS_POLL = public static final String ACTION_NETWORK_STATS_POLL =
"com.android.server.action.NETWORK_STATS_POLL"; "com.android.server.action.NETWORK_STATS_POLL";
@@ -259,6 +256,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private final ArrayMap<String, NetworkIdentitySet> mActiveUidIfaces = new ArrayMap<>(); private final ArrayMap<String, NetworkIdentitySet> mActiveUidIfaces = new ArrayMap<>();
/** Current default active iface. */ /** Current default active iface. */
@GuardedBy("mStatsLock")
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. */
@@ -269,6 +267,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
@GuardedBy("mStatsLock") @GuardedBy("mStatsLock")
private Network[] mDefaultNetworks = new Network[0]; private Network[] mDefaultNetworks = new Network[0];
/** Set containing info about active VPNs and their underlying networks. */
@GuardedBy("mStatsLock")
private VpnInfo[] mVpnInfos = new VpnInfo[0];
private final DropBoxNonMonotonicObserver mNonMonotonicObserver = private final DropBoxNonMonotonicObserver mNonMonotonicObserver =
new DropBoxNonMonotonicObserver(); new DropBoxNonMonotonicObserver();
@@ -382,10 +384,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mHandlerCallback = callback; mHandlerCallback = callback;
} }
public void bindConnectivityManager(IConnectivityManager connManager) {
mConnManager = checkNotNull(connManager, "missing IConnectivityManager");
}
public void systemReady() { public void systemReady() {
mSystemReady = true; mSystemReady = true;
@@ -864,13 +862,17 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
@Override @Override
public void forceUpdateIfaces(Network[] defaultNetworks) { public void forceUpdateIfaces(
Network[] defaultNetworks,
VpnInfo[] vpnArray,
NetworkState[] networkStates,
String activeIface) {
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(defaultNetworks); updateIfaces(defaultNetworks, vpnArray, networkStates, activeIface);
} finally { } finally {
Binder.restoreCallingIdentity(token); Binder.restoreCallingIdentity(token);
} }
@@ -1134,11 +1136,17 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
} }
}; };
private void updateIfaces(Network[] defaultNetworks) { private void updateIfaces(
Network[] defaultNetworks,
VpnInfo[] vpnArray,
NetworkState[] networkStates,
String activeIface) {
synchronized (mStatsLock) { synchronized (mStatsLock) {
mWakeLock.acquire(); mWakeLock.acquire();
try { try {
updateIfacesLocked(defaultNetworks); mVpnInfos = vpnArray;
mActiveIface = activeIface;
updateIfacesLocked(defaultNetworks, networkStates);
} finally { } finally {
mWakeLock.release(); mWakeLock.release();
} }
@@ -1152,7 +1160,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
* {@link NetworkIdentitySet}. * {@link NetworkIdentitySet}.
*/ */
@GuardedBy("mStatsLock") @GuardedBy("mStatsLock")
private void updateIfacesLocked(Network[] defaultNetworks) { private void updateIfacesLocked(Network[] defaultNetworks, NetworkState[] states) {
if (!mSystemReady) return; if (!mSystemReady) return;
if (LOGV) Slog.v(TAG, "updateIfacesLocked()"); if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
@@ -1164,18 +1172,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// will be persisted during next alarm poll event. // will be persisted during next alarm poll event.
performPollLocked(FLAG_PERSIST_NETWORK); performPollLocked(FLAG_PERSIST_NETWORK);
final NetworkState[] states;
final LinkProperties activeLink;
try {
states = mConnManager.getAllNetworkState();
activeLink = mConnManager.getActiveLinkProperties();
} catch (RemoteException e) {
// ignored; service lives in system_server
return;
}
mActiveIface = activeLink != null ? activeLink.getInterfaceName() : null;
// Rebuild active interfaces based on connected networks // Rebuild active interfaces based on connected networks
mActiveIfaces.clear(); mActiveIfaces.clear();
mActiveUidIfaces.clear(); mActiveUidIfaces.clear();
@@ -1287,7 +1283,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceEnd(TRACE_TAG_NETWORK);
// For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps. // For per-UID stats, pass the VPN info so VPN traffic is reattributed to responsible apps.
VpnInfo[] vpnArray = mConnManager.getAllVpnInfo(); VpnInfo[] vpnArray = mVpnInfos;
Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid"); Trace.traceBegin(TRACE_TAG_NETWORK, "recordUid");
mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime); mUidRecorder.recordSnapshotLocked(uidSnapshot, mActiveUidIfaces, vpnArray, currentTime);
Trace.traceEnd(TRACE_TAG_NETWORK); Trace.traceEnd(TRACE_TAG_NETWORK);