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

Commit fc6e6d13 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expand logging capabilities of Tethering subsystem" into oc-dev

parents 807a8c6e 292b65a6
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -175,6 +175,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;

@@ -1852,7 +1855,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

        if (argsContain(args, "--diag")) {
        if (argsContain(args, DIAG_ARG)) {
            dumpNetworkDiagnostics(pw);
            return;
        }
@@ -1938,7 +1941,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            pw.decreaseIndent();
        }

        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;

@@ -147,9 +148,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;
@@ -180,7 +179,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
    public Tethering(Context context, INetworkManagementService nmService,
            INetworkStatsService statsService, INetworkPolicyManager policyManager,
            Looper looper, MockableSystemProperties systemProperties) {
        mLocalLog.log("CONSTRUCTED");
        mLog.mark("constructed");
        mContext = context;
        mNMService = nmService;
        mStatsService = statsService;
@@ -195,9 +194,9 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper);
        mTetherMasterSM.start();

        mOffloadController = new OffloadController(mTetherMasterSM.getHandler());
        mOffloadController = new OffloadController(mTetherMasterSM.getHandler(), mLog);
        mUpstreamNetworkMonitor = new UpstreamNetworkMonitor(
                mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK);
                mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK, mLog);
        mForwardedDownstreams = new HashSet<>();

        mStateReceiver = new StateReceiver();
@@ -1094,7 +1093,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering
            addState(mSetDnsForwardersErrorState);

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

@@ -1141,7 +1140,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;
                }
@@ -1154,12 +1153,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;
            }

@@ -1167,19 +1166,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;
            }

@@ -1305,13 +1304,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);
                }
            }
@@ -1788,12 +1787,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) {
@@ -1807,8 +1817,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.
@@ -1846,8 +1855,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 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.server.connectivity.tethering;

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

/**
 * A wrapper around hardware offload interface.
@@ -29,16 +29,18 @@ public class OffloadController {
    private static final String TAG = OffloadController.class.getSimpleName();

    private final Handler mHandler;
    private final SharedLog mLog;
    private LinkProperties mUpstreamLinkProperties;

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

    public void start() {
        // TODO: initOffload() and configure callbacks to be handled on our
        // preferred Handler.
        Log.d(TAG, "tethering offload not supported");
        mLog.i("tethering offload not supported");
    }

    public void stop() {
Loading