From ac136a020fb10b0bb28e48b7e63b71809e8624f6 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Fri, 22 Jan 2016 04:04:57 +0900 Subject: [PATCH] Debug logging for when getActiveNetworkInfo returns BLOCKED. Bug: 26488100 Change-Id: I991581732d35aed18392bed2f3d69ca8fb231f5e --- .../android/server/ConnectivityService.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 327fb8a7ef..75f5c15400 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -169,6 +169,7 @@ public class ConnectivityService extends IConnectivityManager.Stub private static final boolean VDBG = false; private static final boolean LOGD_RULES = false; + private static final boolean LOGD_BLOCKED_NETWORKINFO = true; // TODO: create better separation between radio types and network types @@ -955,6 +956,21 @@ public class ConnectivityService extends IConnectivityManager.Stub } } + private void maybeLogBlockedNetworkInfo(NetworkInfo ni, int uid) { + if (ni == null || !LOGD_BLOCKED_NETWORKINFO) return; + boolean removed = false; + boolean added = false; + synchronized (mBlockedAppUids) { + if (ni.getDetailedState() == DetailedState.BLOCKED && mBlockedAppUids.add(uid)) { + added = true; + } else if (ni.isConnected() && mBlockedAppUids.remove(uid)) { + removed = true; + } + } + if (added) log("Returning blocked NetworkInfo to uid=" + uid); + else if (removed) log("Returning unblocked NetworkInfo to uid=" + uid); + } + /** * Return a filtered {@link NetworkInfo}, potentially marked * {@link DetailedState#BLOCKED} based on @@ -965,10 +981,6 @@ public class ConnectivityService extends IConnectivityManager.Stub // network is blocked; clone and override state info = new NetworkInfo(info); info.setDetailedState(DetailedState.BLOCKED, null, null); - if (VDBG) { - log("returning Blocked NetworkInfo for ifname=" + - lp.getInterfaceName() + ", uid=" + uid); - } } if (info != null && mLockdownTracker != null) { info = mLockdownTracker.augmentNetworkInfo(info); @@ -989,7 +1001,9 @@ public class ConnectivityService extends IConnectivityManager.Stub enforceAccessPermission(); final int uid = Binder.getCallingUid(); NetworkState state = getUnfilteredActiveNetworkState(uid); - return getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid); + NetworkInfo ni = getFilteredNetworkInfo(state.networkInfo, state.linkProperties, uid); + maybeLogBlockedNetworkInfo(ni, uid); + return ni; } @Override @@ -3882,6 +3896,9 @@ public class ConnectivityService extends IConnectivityManager.Stub private final HashMap mNetworkAgentInfos = new HashMap(); + @GuardedBy("mBlockedAppUids") + private final HashSet mBlockedAppUids = new HashSet(); + // Note: if mDefaultRequest is changed, NetworkMonitor needs to be updated. private final NetworkRequest mDefaultRequest;