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

Commit 0abbcda3 authored by Pierre Imai's avatar Pierre Imai Committed by android-build-merger
Browse files

Merge "Add initial connectivity metrics handling." into nyc-dev

am: f262a7e3

* commit 'f262a7e3':
  Add initial connectivity metrics handling.
parents 5a26eabe f262a7e3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.UidRange;
import android.net.Uri;
import android.net.metrics.ConnectivityServiceChangeEvent;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -4511,6 +4512,7 @@ public class ConnectivityService extends IConnectivityManager.Stub

    private void makeDefault(NetworkAgentInfo newNetwork) {
        if (DBG) log("Switching to new default network: " + newNetwork);
        ConnectivityServiceChangeEvent.logEvent(newNetwork.network.netId);
        setupDataActivityTracking(newNetwork);
        try {
            mNetd.setDefaultNetId(newNetwork.network.netId);
@@ -5141,5 +5143,4 @@ public class ConnectivityService extends IConnectivityManager.Stub
            NetworkAgentInfo nai, NetworkRequest defaultRequest) {
        return new NetworkMonitor(context, handler, nai, defaultRequest);
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class MetricsLoggerService extends SystemService {
    private long mLastSentEventTimeMillis = System.currentTimeMillis();

    private final void enforceConnectivityInternalPermission() {
        getContext().enforceCallingPermission(
        getContext().enforceCallingOrSelfPermission(
                android.Manifest.permission.CONNECTIVITY_INTERNAL,
                "MetricsLoggerService");
    }
+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import android.net.NetworkRequest;
import android.net.ProxyInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.net.metrics.CaptivePortalCheckResultEvent;
import android.net.metrics.CaptivePortalStateChangeEvent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Handler;
@@ -297,9 +299,13 @@ public class NetworkMonitor extends StateMachine {
                    transitionTo(mLingeringState);
                    return HANDLED;
                case CMD_NETWORK_CONNECTED:
                    CaptivePortalStateChangeEvent.logEvent(
                            CaptivePortalStateChangeEvent.NETWORK_MONITOR_CONNECTED);
                    transitionTo(mEvaluatingState);
                    return HANDLED;
                case CMD_NETWORK_DISCONNECTED:
                    CaptivePortalStateChangeEvent.logEvent(
                            CaptivePortalStateChangeEvent.NETWORK_MONITOR_DISCONNECTED);
                    if (mLaunchCaptivePortalAppBroadcastReceiver != null) {
                        mContext.unregisterReceiver(mLaunchCaptivePortalAppBroadcastReceiver);
                        mLaunchCaptivePortalAppBroadcastReceiver = null;
@@ -349,6 +355,8 @@ public class NetworkMonitor extends StateMachine {
    private class ValidatedState extends State {
        @Override
        public void enter() {
            CaptivePortalStateChangeEvent.logEvent(
                   CaptivePortalStateChangeEvent.NETWORK_MONITOR_VALIDATED);
            mConnectivityServiceHandler.sendMessage(obtainMessage(EVENT_NETWORK_TESTED,
                    NETWORK_TEST_RESULT_VALID, 0, mNetworkAgentInfo));
        }
@@ -457,6 +465,8 @@ public class NetworkMonitor extends StateMachine {
                    // will be unresponsive. isCaptivePortal() could be executed on another Thread
                    // if this is found to cause problems.
                    int httpResponseCode = isCaptivePortal();
                    CaptivePortalCheckResultEvent.logEvent(mNetworkAgentInfo.network.netId,
                            httpResponseCode);
                    if (httpResponseCode == 204) {
                        transitionTo(mValidatedState);
                    } else if (httpResponseCode >= 200 && httpResponseCode <= 399) {
+9 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.net.DhcpResults;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.net.metrics.IpConnectivityEvent;
import android.net.metrics.DhcpClientEvent;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Message;
@@ -355,11 +357,15 @@ public class DhcpClient extends StateMachine {
                    if (!stopped) {
                        Log.e(TAG, "Read error", e);
                    }
                    DhcpClientEvent.logEvent(IpConnectivityEvent.IPCE_DHCP_RECV_ERROR,
                            mIfaceName, e.getMessage());
                } catch (DhcpPacket.ParseException e) {
                    Log.e(TAG, "Can't parse packet: " + e.getMessage());
                    if (PACKET_DBG) {
                        Log.d(TAG, HexDump.dumpHexString(mPacket, 0, length));
                    }
                    DhcpClientEvent.logEvent(IpConnectivityEvent.IPCE_DHCP_PARSE_ERROR, mIfaceName,
                            e.getMessage());
                }
            }
            if (DBG) Log.d(TAG, "Receive thread stopped");
@@ -456,7 +462,9 @@ public class DhcpClient extends StateMachine {

    abstract class LoggingState extends State {
        public void enter() {
            if (STATE_DBG) Log.d(TAG, "Entering state " + getName());
            String msg = "Entering state " + getName();
            if (STATE_DBG) Log.d(TAG, msg);
            DhcpClientEvent.logEvent(IpConnectivityEvent.IPCE_DHCP_STATE_CHANGE, mIfaceName, msg);
        }

        private String messageName(int what) {
+15 −4
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.net.LinkProperties;
import android.net.LinkProperties.ProvisioningChange;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.metrics.IpReachabilityMonitorMessageEvent;
import android.net.metrics.IpReachabilityMonitorProbeEvent;
import android.net.netlink.NetlinkConstants;
import android.net.netlink.NetlinkErrorMessage;
import android.net.netlink.NetlinkMessage;
@@ -162,7 +164,7 @@ public class IpReachabilityMonitor {
    private boolean mRunning;

    /**
     * Make the kernel to perform neighbor reachability detection (IPv4 ARP or IPv6 ND)
     * Make the kernel perform neighbor reachability detection (IPv4 ARP or IPv6 ND)
     * for the given IP address on the specified interface index.
     *
     * @return true, if the request was successfully passed to the kernel; false otherwise.
@@ -203,7 +205,8 @@ public class IpReachabilityMonitor {
        } catch (ErrnoException | InterruptedIOException | SocketException e) {
            Log.d(TAG, "Error " + msgSnippet, e);
        }

        IpReachabilityMonitorProbeEvent.logEvent("ifindex-" + ifIndex, ip.getHostAddress(),
                returnValue);
        return returnValue;
    }

@@ -400,8 +403,7 @@ public class IpReachabilityMonitor {
        return (numUnicastProbes * retransTimeMs) + gracePeriodMs;
    }


    // TODO: simply the number of objects by making this extend Thread.
    // TODO: simplify the number of objects by making this extend Thread.
    private final class NetlinkSocketObserver implements Runnable {
        private NetlinkSocket mSocket;

@@ -519,6 +521,8 @@ public class IpReachabilityMonitor {

            final short msgType = neighMsg.getHeader().nlmsg_type;
            final short nudState = ndMsg.ndm_state;
            IpReachabilityMonitorMessageEvent.logEvent(maybeGetInterfaceName(mInterfaceIndex),
                    destination.getHostAddress(), msgType, nudState);
            final String eventMsg = "NeighborEvent{"
                    + "elapsedMs=" + whenMs + ", "
                    + destination.getHostAddress() + ", "
@@ -549,4 +553,11 @@ public class IpReachabilityMonitor {
            }
        }
    }

    private String maybeGetInterfaceName(int index) {
        if (index == mInterfaceIndex) {
            return mInterfaceName;
        }
        return "ifindex-" + index;
    }
}
Loading