Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6855a1f authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android (Google) Code Review
Browse files

Merge "Debug logging for when getActiveNetworkInfo returns BLOCKED." into mnc-dr1.5-dev

parents 746ea1ef c1a6ce70
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -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<Messenger, NetworkAgentInfo> mNetworkAgentInfos =
            new HashMap<Messenger, NetworkAgentInfo>();

    @GuardedBy("mBlockedAppUids")
    private final HashSet<Integer> mBlockedAppUids = new HashSet();

    // Note: if mDefaultRequest is changed, NetworkMonitor needs to be updated.
    private final NetworkRequest mDefaultRequest;