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

Commit 96f9371a authored by Erik Kline's avatar Erik Kline Committed by android-build-merger
Browse files

Merge "Expand logging capabilities of Tethering subsystem"

am: 0373340b

Change-Id: I1381b8457781dcfafe52371a5dc7628282cb8efc
parents 13f0d101 0373340b
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -183,6 +183,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
        implements PendingIntent.OnFinished {
    private static final String TAG = ConnectivityService.class.getSimpleName();

    public static final String DIAG_ARG = "--diag";
    public static final String SHORT_ARG = "--short";

    private static final boolean DBG = true;
    private static final boolean VDBG = false;

@@ -1961,7 +1964,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            return;
        }

        if (argsContain(args, "--diag")) {
        if (argsContain(args, DIAG_ARG)) {
            dumpNetworkDiagnostics(pw);
            return;
        }
@@ -2053,7 +2056,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        pw.println();
        dumpAvoidBadWifiSettings(pw);

        if (argsContain(args, "--short") == false) {
        if (argsContain(args, SHORT_ARG) == false) {
            pw.println();
            synchronized (mValidationLogs) {
                pw.println("mValidationLogs (most recent first):");
+31 −22
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.hardware.usb.UsbManager.USB_CONNECTED;
import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS;
import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE;
import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED;
import static com.android.server.ConnectivityService.SHORT_ARG;

import android.app.Notification;
import android.app.NotificationManager;
@@ -47,6 +48,7 @@ import android.net.NetworkRequest;
import android.net.NetworkState;
import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.util.SharedLog;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Bundle;
@@ -62,7 +64,6 @@ import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.LocalLog;
import android.util.Log;
import android.util.SparseArray;

@@ -146,9 +147,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
        }
    }

    private final static int MAX_LOG_RECORDS = 500;

    private final LocalLog mLocalLog = new LocalLog(MAX_LOG_RECORDS);
    private final SharedLog mLog = new SharedLog(TAG);

    // used to synchronize public access to members
    private final Object mPublicSync;
@@ -181,7 +180,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
            INetworkStatsService statsService, INetworkPolicyManager policyManager,
            Looper looper, MockableSystemProperties systemProperties,
            TetheringDependencies deps) {
        mLocalLog.log("CONSTRUCTED");
        mLog.mark("constructed");
        mContext = context;
        mNMService = nmService;
        mStatsService = statsService;
@@ -197,9 +196,9 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
        mTetherMasterSM.start();

        mOffloadController = new OffloadController(mTetherMasterSM.getHandler(),
                deps.getOffloadHardwareInterface());
                deps.getOffloadHardwareInterface(), mLog);
        mUpstreamNetworkMonitor = new UpstreamNetworkMonitor(
                mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
                mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK, mLog);
        mForwardedDownstreams = new HashSet<>();
        mSimChange = new SimChangeListener(
                mContext, mTetherMasterSM.getHandler(), () -> reevaluateSimCardProvisioning());
@@ -1131,7 +1130,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
            addState(mSetDnsForwardersErrorState);

            mNotifyList = new ArrayList<>();
            mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList);
            mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog);
            setInitialState(mInitialState);
        }

@@ -1178,7 +1177,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
                try {
                    mNMService.setIpForwardingEnabled(true);
                } catch (Exception e) {
                    mLocalLog.log("ERROR " + e);
                    mLog.e(e);
                    transitionTo(mSetIpForwardingEnabledErrorState);
                    return false;
                }
@@ -1191,12 +1190,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
                        mNMService.stopTethering();
                        mNMService.startTethering(cfg.dhcpRanges);
                    } catch (Exception ee) {
                        mLocalLog.log("ERROR " + ee);
                        mLog.e(ee);
                        transitionTo(mStartTetheringErrorState);
                        return false;
                    }
                }
                mLocalLog.log("SET master tether settings: ON");
                mLog.log("SET master tether settings: ON");
                return true;
            }

@@ -1204,19 +1203,19 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
                try {
                    mNMService.stopTethering();
                } catch (Exception e) {
                    mLocalLog.log("ERROR " + e);
                    mLog.e(e);
                    transitionTo(mStopTetheringErrorState);
                    return false;
                }
                try {
                    mNMService.setIpForwardingEnabled(false);
                } catch (Exception e) {
                    mLocalLog.log("ERROR " + e);
                    mLog.e(e);
                    transitionTo(mSetIpForwardingDisabledErrorState);
                    return false;
                }
                transitionTo(mInitialState);
                mLocalLog.log("SET master tether settings: OFF");
                mLog.log("SET master tether settings: OFF");
                return true;
            }

@@ -1342,13 +1341,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
                }
                try {
                    mNMService.setDnsForwarders(network, dnsServers);
                    mLocalLog.log(String.format(
                            "SET DNS forwarders: network=%s dnsServers=[%s]",
                    mLog.log(String.format(
                            "SET DNS forwarders: network=%s dnsServers=%s",
                            network, Arrays.toString(dnsServers)));
                } catch (Exception e) {
                    // TODO: Investigate how this can fail and what exactly
                    // happens if/when such failures occur.
                    mLocalLog.log("ERROR setting DNS forwarders failed, " + e);
                    mLog.e("setting DNS forwarders failed, " + e);
                    transitionTo(mSetDnsForwardersErrorState);
                }
            }
@@ -1710,12 +1709,23 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering

        pw.println("Log:");
        pw.increaseIndent();
        mLocalLog.readOnlyLocalLog().dump(fd, pw, args);
        if (argsContain(args, SHORT_ARG)) {
            pw.println("<log removed for brevity>");
        } else {
            mLog.dump(fd, pw, args);
        }
        pw.decreaseIndent();

        pw.decreaseIndent();
    }

    private static boolean argsContain(String[] args, String target) {
        for (String arg : args) {
            if (arg.equals(target)) return true;
        }
        return false;
    }

    @Override
    public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who,
                                           int state, int error) {
@@ -1729,8 +1739,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
            }
        }

        mLocalLog.log(String.format("OBSERVED iface=%s state=%s error=%s",
                iface, state, error));
        mLog.log(String.format("OBSERVED iface=%s state=%s error=%s", iface, state, error));

        try {
            // Notify that we're tethering (or not) this interface.
@@ -1768,8 +1777,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
    private void trackNewTetherableInterface(String iface, int interfaceType) {
        TetherState tetherState;
        tetherState = new TetherState(new TetherInterfaceStateMachine(iface, mLooper,
                interfaceType, mNMService, mStatsService, this,
                new IPv6TetheringInterfaceServices(iface, mNMService)));
                interfaceType, mLog, mNMService, mStatsService, this,
                new IPv6TetheringInterfaceServices(iface, mNMService, mLog)));
        mTetherStates.put(iface, tetherState);
        tetherState.stateMachine.start();
    }
+13 −13
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.net.NetworkCapabilities;
import android.net.NetworkState;
import android.net.RouteInfo;
import android.net.util.NetworkConstants;
import android.net.util.SharedLog;
import android.util.Log;

import java.net.Inet6Address;
@@ -64,6 +65,7 @@ public class IPv6TetheringCoordinator {
    }

    private final ArrayList<TetherInterfaceStateMachine> mNotifyList;
    private final SharedLog mLog;
    // NOTE: mActiveDownstreams is a list and not a hash data structure because
    // we keep active downstreams in arrival order.  This is done so /64s can
    // be parceled out on a "first come, first served" basis and a /64 used by
@@ -74,8 +76,10 @@ public class IPv6TetheringCoordinator {
    private short mNextSubnetId;
    private NetworkState mUpstreamNetworkState;

    public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList) {
    public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList,
                                    SharedLog log) {
        mNotifyList = notifyList;
        mLog = log.forSubComponent(TAG);
        mActiveDownstreams = new LinkedList<>();
        mUniqueLocalPrefix = generateUniqueLocalPrefix();
        mNextSubnetId = 0;
@@ -115,7 +119,7 @@ public class IPv6TetheringCoordinator {
        if (VDBG) {
            Log.d(TAG, "updateUpstreamNetworkState: " + toDebugString(ns));
        }
        if (!canTetherIPv6(ns)) {
        if (!canTetherIPv6(ns, mLog)) {
            stopIPv6TetheringOnAllInterfaces();
            setUpstreamNetworkState(null);
            return;
@@ -150,9 +154,7 @@ public class IPv6TetheringCoordinator {
                    null);
        }

        if (DBG) {
            Log.d(TAG, "setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState));
        }
        mLog.log("setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState));
    }

    private void updateIPv6TetheringInterfaces() {
@@ -206,7 +208,7 @@ public class IPv6TetheringCoordinator {
        return null;
    }

    private static boolean canTetherIPv6(NetworkState ns) {
    private static boolean canTetherIPv6(NetworkState ns, SharedLog sharedLog) {
        // Broadly speaking:
        //
        //     [1] does the upstream have an IPv6 default route?
@@ -260,14 +262,12 @@ public class IPv6TetheringCoordinator {

        final boolean outcome = canTether && supportedConfiguration;

        if (VDBG) {
        if (ns == null) {
                Log.d(TAG, "No available upstream.");
            sharedLog.log("No available upstream.");
        } else {
                Log.d(TAG, String.format("IPv6 tethering is %s for upstream: %s",
            sharedLog.log(String.format("IPv6 tethering is %s for upstream: %s",
                    (outcome ? "available" : "not available"), toDebugString(ns)));
        }
        }

        return outcome;
    }
+15 −12
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@ import android.net.RouteInfo;
import android.net.ip.RouterAdvertisementDaemon;
import android.net.ip.RouterAdvertisementDaemon.RaParams;
import android.net.util.NetdService;
import android.net.util.SharedLog;
import android.os.INetworkManagementService;
import android.os.ServiceSpecificException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Slog;

import java.net.Inet6Address;
@@ -54,6 +54,7 @@ public class IPv6TetheringInterfaceServices {

    private final String mIfName;
    private final INetworkManagementService mNMService;
    private final SharedLog mLog;

    private NetworkInterface mNetworkInterface;
    private byte[] mHwAddr;
@@ -61,9 +62,11 @@ public class IPv6TetheringInterfaceServices {
    private RouterAdvertisementDaemon mRaDaemon;
    private RaParams mLastRaParams;

    public IPv6TetheringInterfaceServices(String ifname, INetworkManagementService nms) {
    public IPv6TetheringInterfaceServices(
            String ifname, INetworkManagementService nms, SharedLog log) {
        mIfName = ifname;
        mNMService = nms;
        mLog = log.forSubComponent(mIfName);
    }

    public boolean start() {
@@ -72,12 +75,12 @@ public class IPv6TetheringInterfaceServices {
        try {
            mNetworkInterface = NetworkInterface.getByName(mIfName);
        } catch (SocketException e) {
            Log.e(TAG, "Error looking up NetworkInterfaces for " + mIfName, e);
            mLog.e("Error looking up NetworkInterfaces: " + e);
            stop();
            return false;
        }
        if (mNetworkInterface == null) {
            Log.e(TAG, "Failed to find NetworkInterface for " + mIfName);
            mLog.e("Failed to find NetworkInterface");
            stop();
            return false;
        }
@@ -85,7 +88,7 @@ public class IPv6TetheringInterfaceServices {
        try {
            mHwAddr = mNetworkInterface.getHardwareAddress();
        } catch (SocketException e) {
            Log.e(TAG, "Failed to find hardware address for " + mIfName, e);
            mLog.e("Failed to find hardware address: " + e);
            stop();
            return false;
        }
@@ -161,11 +164,11 @@ public class IPv6TetheringInterfaceServices {
            try {
                final int removalFailures = mNMService.removeRoutesFromLocalNetwork(toBeRemoved);
                if (removalFailures > 0) {
                    Log.e(TAG, String.format("Failed to remove %d IPv6 routes from local table.",
                    mLog.e(String.format("Failed to remove %d IPv6 routes from local table.",
                            removalFailures));
                }
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to remove IPv6 routes from local table: ", e);
                mLog.e("Failed to remove IPv6 routes from local table: " + e);
            }
        }

@@ -195,7 +198,7 @@ public class IPv6TetheringInterfaceServices {
                    // error (EEXIST is silently ignored).
                    mNMService.addInterfaceToLocalNetwork(mIfName, toBeAdded);
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to add IPv6 routes to local table: ", e);
                    mLog.e("Failed to add IPv6 routes to local table: " + e);
                }
            }
        }
@@ -206,7 +209,7 @@ public class IPv6TetheringInterfaceServices {
        final INetd netd = NetdService.getInstance();
        if (netd == null) {
            if (newDnses != null) newDnses.clear();
            Log.e(TAG, "No netd service instance available; not setting local IPv6 addresses");
            mLog.e("No netd service instance available; not setting local IPv6 addresses");
            return;
        }

@@ -217,7 +220,7 @@ public class IPv6TetheringInterfaceServices {
                try {
                    netd.interfaceDelAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH);
                } catch (ServiceSpecificException | RemoteException e) {
                    Log.e(TAG, "Failed to remove local dns IP: " + dnsString, e);
                    mLog.e("Failed to remove local dns IP " + dnsString + ": " + e);
                }
            }
        }
@@ -234,7 +237,7 @@ public class IPv6TetheringInterfaceServices {
                try {
                    netd.interfaceAddAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH);
                } catch (ServiceSpecificException | RemoteException e) {
                    Log.e(TAG, "Failed to add local dns IP: " + dnsString, e);
                    mLog.e("Failed to add local dns IP " + dnsString + ": " + e);
                    newDnses.remove(dns);
                }
            }
@@ -243,7 +246,7 @@ public class IPv6TetheringInterfaceServices {
        try {
            netd.tetherApplyDnsInterfaces();
        } catch (ServiceSpecificException | RemoteException e) {
            Log.e(TAG, "Failed to update local DNS caching server");
            mLog.e("Failed to update local DNS caching server");
            if (newDnses != null) newDnses.clear();
        }
    }
+5 −4
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ package com.android.server.connectivity.tethering;

import android.net.LinkProperties;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Log;
import android.net.util.SharedLog;

/**
 * A class to encapsulate the business logic of programming the tethering
@@ -32,13 +31,15 @@ public class OffloadController {

    private final Handler mHandler;
    private final OffloadHardwareInterface mHwInterface;
    private final SharedLog mLog;
    private boolean mConfigInitialized;
    private boolean mControlInitialized;
    private LinkProperties mUpstreamLinkProperties;

    public OffloadController(Handler h, OffloadHardwareInterface hwi) {
    public OffloadController(Handler h, OffloadHardwareInterface hwi, SharedLog log) {
        mHandler = h;
        mHwInterface = hwi;
        mLog = log.forSubComponent(TAG);
    }

    public void start() {
@@ -47,7 +48,7 @@ public class OffloadController {
        if (!mConfigInitialized) {
            mConfigInitialized = mHwInterface.initOffloadConfig();
            if (!mConfigInitialized) {
                Log.d(TAG, "tethering offload config not supported");
                mLog.i("tethering offload config not supported");
                return;
            }
        }
Loading