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

Commit c2ae287e authored by Hugo Benichi's avatar Hugo Benichi
Browse files

ConnectivityService dump: add apps blocked logs

This patch adds NetworkInfo BLOCKED/UNBLOCKED status of apps to
ConnectivityService's dump logs.

The BLOCKED or UNBLOCKED status of an app is logged with the app uid
when the app calls getActiveNetworkInfo().

Examples:
mNetworkInfoBlockingLogs (most recent first):
  07-11 11:04:43.139 - BLOCKED 10060
  07-11 11:04:39.056 - UNBLOCKED 10061
  07-11 11:04:38.851 - BLOCKED 10061

Bug: 29981766
Change-Id: I6e2fde446702b92b0964ed894409b5d733d8f8a7
parent ee5b7477
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -449,6 +449,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
    private static final int MAX_NETWORK_REQUEST_LOGS = 20;
    private final LocalLog mNetworkRequestInfoLogs = new LocalLog(MAX_NETWORK_REQUEST_LOGS);

    // NetworkInfo blocked and unblocked String log entries
    // TODO: consider reducing memory usage. Each log line is ~40 2B chars, for a total of ~8kB.
    private static final int MAX_NETWORK_INFO_LOGS = 100;
    private final LocalLog mNetworkInfoBlockingLogs = new LocalLog(MAX_NETWORK_INFO_LOGS);

    // Array of <Network,ReadOnlyLocalLogs> tracking network validation and results
    private static final int MAX_VALIDATION_LOGS = 10;
    private static class ValidationLog {
@@ -1013,7 +1018,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
    }

    private void maybeLogBlockedNetworkInfo(NetworkInfo ni, int uid) {
        if (ni == null || !LOGD_BLOCKED_NETWORKINFO) return;
        if (ni == null || !LOGD_BLOCKED_NETWORKINFO) {
            return;
        }
        boolean removed = false;
        boolean added = false;
        synchronized (mBlockedAppUids) {
@@ -1023,8 +1030,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
                removed = true;
            }
        }
        if (added) log("Returning blocked NetworkInfo to uid=" + uid);
        else if (removed) log("Returning unblocked NetworkInfo to uid=" + uid);
        if (added) {
            log("Returning blocked NetworkInfo to uid=" + uid);
            mNetworkInfoBlockingLogs.log("BLOCKED " + uid);
        } else if (removed) {
            log("Returning unblocked NetworkInfo to uid=" + uid);
            mNetworkInfoBlockingLogs.log("UNBLOCKED " + uid);
        }
    }

    /**
@@ -2024,6 +2036,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
            pw.increaseIndent();
            mNetworkRequestInfoLogs.reverseDump(fd, pw, args);
            pw.decreaseIndent();

            pw.println();
            pw.println("mNetworkInfoBlockingLogs (most recent first):");
            pw.increaseIndent();
            mNetworkInfoBlockingLogs.reverseDump(fd, pw, args);
            pw.decreaseIndent();
        }
    }