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

Commit ef9c8be5 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by The Android Automerger
Browse files

Debug logging for when getActiveNetworkInfo returns BLOCKED.

Bug: 26488100
Change-Id: I991581732d35aed18392bed2f3d69ca8fb231f5e
parent 4276d402
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;