Loading services/core/java/com/android/server/ConnectivityService.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -178,6 +178,9 @@ public class ConnectivityService extends IConnectivityManager.Stub implements PendingIntent.OnFinished { implements PendingIntent.OnFinished { private static final String TAG = ConnectivityService.class.getSimpleName(); 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 DBG = true; private static final boolean VDBG = false; private static final boolean VDBG = false; Loading Loading @@ -1860,7 +1863,7 @@ public class ConnectivityService extends IConnectivityManager.Stub final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (argsContain(args, "--diag")) { if (argsContain(args, DIAG_ARG)) { dumpNetworkDiagnostics(pw); dumpNetworkDiagnostics(pw); return; return; } } Loading Loading @@ -1925,7 +1928,7 @@ public class ConnectivityService extends IConnectivityManager.Stub pw.println(); pw.println(); dumpAvoidBadWifiSettings(pw); dumpAvoidBadWifiSettings(pw); if (argsContain(args, "--short") == false) { if (argsContain(args, SHORT_ARG) == false) { pw.println(); pw.println(); synchronized (mValidationLogs) { synchronized (mValidationLogs) { pw.println("mValidationLogs (most recent first):"); pw.println("mValidationLogs (most recent first):"); Loading services/core/java/com/android/server/connectivity/Tethering.java +31 −22 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.hardware.usb.UsbManager.USB_CONNECTED; import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS; 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.EXTRA_WIFI_AP_STATE; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; 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.Notification; import android.app.NotificationManager; import android.app.NotificationManager; Loading Loading @@ -47,6 +48,7 @@ import android.net.NetworkRequest; import android.net.NetworkState; import android.net.NetworkState; import android.net.NetworkUtils; import android.net.NetworkUtils; import android.net.RouteInfo; import android.net.RouteInfo; import android.net.util.SharedLog; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.Binder; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; Loading @@ -62,7 +64,6 @@ import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.LocalLog; import android.util.Log; import android.util.Log; import android.util.SparseArray; import android.util.SparseArray; Loading Loading @@ -149,9 +150,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } } private final static int MAX_LOG_RECORDS = 500; private final SharedLog mLog = new SharedLog(TAG); private final LocalLog mLocalLog = new LocalLog(MAX_LOG_RECORDS); // used to synchronize public access to members // used to synchronize public access to members private final Object mPublicSync; private final Object mPublicSync; Loading Loading @@ -184,7 +183,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering INetworkStatsService statsService, INetworkPolicyManager policyManager, INetworkStatsService statsService, INetworkPolicyManager policyManager, Looper looper, MockableSystemProperties systemProperties, Looper looper, MockableSystemProperties systemProperties, TetheringDependencies deps) { TetheringDependencies deps) { mLocalLog.log("CONSTRUCTED"); mLog.mark("constructed"); mContext = context; mContext = context; mNMService = nmService; mNMService = nmService; mStatsService = statsService; mStatsService = statsService; Loading @@ -200,9 +199,9 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mTetherMasterSM.start(); mTetherMasterSM.start(); mOffloadController = new OffloadController(mTetherMasterSM.getHandler(), mOffloadController = new OffloadController(mTetherMasterSM.getHandler(), deps.getOffloadHardwareInterface()); deps.getOffloadHardwareInterface(), mLog); mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK, mLog); mForwardedDownstreams = new HashSet<>(); mForwardedDownstreams = new HashSet<>(); mSimChange = new SimChangeListener( mSimChange = new SimChangeListener( mContext, mTetherMasterSM.getHandler(), () -> reevaluateSimCardProvisioning()); mContext, mTetherMasterSM.getHandler(), () -> reevaluateSimCardProvisioning()); Loading Loading @@ -1148,7 +1147,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering addState(mSetDnsForwardersErrorState); addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<>(); mNotifyList = new ArrayList<>(); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog); setInitialState(mInitialState); setInitialState(mInitialState); } } Loading Loading @@ -1195,7 +1194,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering try { try { mNMService.setIpForwardingEnabled(true); mNMService.setIpForwardingEnabled(true); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mSetIpForwardingEnabledErrorState); transitionTo(mSetIpForwardingEnabledErrorState); return false; return false; } } Loading @@ -1208,12 +1207,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mNMService.stopTethering(); mNMService.stopTethering(); mNMService.startTethering(cfg.dhcpRanges); mNMService.startTethering(cfg.dhcpRanges); } catch (Exception ee) { } catch (Exception ee) { mLocalLog.log("ERROR " + ee); mLog.e(ee); transitionTo(mStartTetheringErrorState); transitionTo(mStartTetheringErrorState); return false; return false; } } } } mLocalLog.log("SET master tether settings: ON"); mLog.log("SET master tether settings: ON"); return true; return true; } } Loading @@ -1221,19 +1220,19 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering try { try { mNMService.stopTethering(); mNMService.stopTethering(); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mStopTetheringErrorState); transitionTo(mStopTetheringErrorState); return false; return false; } } try { try { mNMService.setIpForwardingEnabled(false); mNMService.setIpForwardingEnabled(false); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mSetIpForwardingDisabledErrorState); transitionTo(mSetIpForwardingDisabledErrorState); return false; return false; } } transitionTo(mInitialState); transitionTo(mInitialState); mLocalLog.log("SET master tether settings: OFF"); mLog.log("SET master tether settings: OFF"); return true; return true; } } Loading Loading @@ -1359,13 +1358,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } try { try { mNMService.setDnsForwarders(network, dnsServers); mNMService.setDnsForwarders(network, dnsServers); mLocalLog.log(String.format( mLog.log(String.format( "SET DNS forwarders: network=%s dnsServers=[%s]", "SET DNS forwarders: network=%s dnsServers=%s", network, Arrays.toString(dnsServers))); network, Arrays.toString(dnsServers))); } catch (Exception e) { } catch (Exception e) { // TODO: Investigate how this can fail and what exactly // TODO: Investigate how this can fail and what exactly // happens if/when such failures occur. // happens if/when such failures occur. mLocalLog.log("ERROR setting DNS forwarders failed, " + e); mLog.e("setting DNS forwarders failed, " + e); transitionTo(mSetDnsForwardersErrorState); transitionTo(mSetDnsForwardersErrorState); } } } } Loading Loading @@ -1721,12 +1720,23 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering pw.println("Log:"); pw.println("Log:"); pw.increaseIndent(); 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(); 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 @Override public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, int state, int error) { int state, int error) { Loading @@ -1740,8 +1750,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } } mLocalLog.log(String.format("OBSERVED iface=%s state=%s error=%s", mLog.log(String.format("OBSERVED iface=%s state=%s error=%s", iface, state, error)); iface, state, error)); try { try { // Notify that we're tethering (or not) this interface. // Notify that we're tethering (or not) this interface. Loading Loading @@ -1779,8 +1788,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private void trackNewTetherableInterface(String iface, int interfaceType) { private void trackNewTetherableInterface(String iface, int interfaceType) { TetherState tetherState; TetherState tetherState; tetherState = new TetherState(new TetherInterfaceStateMachine(iface, mLooper, tetherState = new TetherState(new TetherInterfaceStateMachine(iface, mLooper, interfaceType, mNMService, mStatsService, this, interfaceType, mLog, mNMService, mStatsService, this, new IPv6TetheringInterfaceServices(iface, mNMService))); new IPv6TetheringInterfaceServices(iface, mNMService, mLog))); mTetherStates.put(iface, tetherState); mTetherStates.put(iface, tetherState); tetherState.stateMachine.start(); tetherState.stateMachine.start(); } } Loading services/core/java/com/android/server/connectivity/tethering/IPv6TetheringCoordinator.java +13 −13 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.net.NetworkCapabilities; import android.net.NetworkState; import android.net.NetworkState; import android.net.RouteInfo; import android.net.RouteInfo; import android.net.util.NetworkConstants; import android.net.util.NetworkConstants; import android.net.util.SharedLog; import android.util.Log; import android.util.Log; import java.net.Inet6Address; import java.net.Inet6Address; Loading Loading @@ -64,6 +65,7 @@ public class IPv6TetheringCoordinator { } } private final ArrayList<TetherInterfaceStateMachine> mNotifyList; private final ArrayList<TetherInterfaceStateMachine> mNotifyList; private final SharedLog mLog; // NOTE: mActiveDownstreams is a list and not a hash data structure because // 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 // 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 // be parceled out on a "first come, first served" basis and a /64 used by Loading @@ -74,8 +76,10 @@ public class IPv6TetheringCoordinator { private short mNextSubnetId; private short mNextSubnetId; private NetworkState mUpstreamNetworkState; private NetworkState mUpstreamNetworkState; public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList) { public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList, SharedLog log) { mNotifyList = notifyList; mNotifyList = notifyList; mLog = log.forSubComponent(TAG); mActiveDownstreams = new LinkedList<>(); mActiveDownstreams = new LinkedList<>(); mUniqueLocalPrefix = generateUniqueLocalPrefix(); mUniqueLocalPrefix = generateUniqueLocalPrefix(); mNextSubnetId = 0; mNextSubnetId = 0; Loading Loading @@ -115,7 +119,7 @@ public class IPv6TetheringCoordinator { if (VDBG) { if (VDBG) { Log.d(TAG, "updateUpstreamNetworkState: " + toDebugString(ns)); Log.d(TAG, "updateUpstreamNetworkState: " + toDebugString(ns)); } } if (!canTetherIPv6(ns)) { if (!canTetherIPv6(ns, mLog)) { stopIPv6TetheringOnAllInterfaces(); stopIPv6TetheringOnAllInterfaces(); setUpstreamNetworkState(null); setUpstreamNetworkState(null); return; return; Loading Loading @@ -150,9 +154,7 @@ public class IPv6TetheringCoordinator { null); null); } } if (DBG) { mLog.log("setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState)); Log.d(TAG, "setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState)); } } } private void updateIPv6TetheringInterfaces() { private void updateIPv6TetheringInterfaces() { Loading Loading @@ -206,7 +208,7 @@ public class IPv6TetheringCoordinator { return null; return null; } } private static boolean canTetherIPv6(NetworkState ns) { private static boolean canTetherIPv6(NetworkState ns, SharedLog sharedLog) { // Broadly speaking: // Broadly speaking: // // // [1] does the upstream have an IPv6 default route? // [1] does the upstream have an IPv6 default route? Loading Loading @@ -260,14 +262,12 @@ public class IPv6TetheringCoordinator { final boolean outcome = canTether && supportedConfiguration; final boolean outcome = canTether && supportedConfiguration; if (VDBG) { if (ns == null) { if (ns == null) { Log.d(TAG, "No available upstream."); sharedLog.log("No available upstream."); } else { } 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))); (outcome ? "available" : "not available"), toDebugString(ns))); } } } return outcome; return outcome; } } Loading services/core/java/com/android/server/connectivity/tethering/IPv6TetheringInterfaceServices.java +15 −12 Original line number Original line Diff line number Diff line Loading @@ -28,10 +28,10 @@ import android.net.RouteInfo; import android.net.ip.RouterAdvertisementDaemon; import android.net.ip.RouterAdvertisementDaemon; import android.net.ip.RouterAdvertisementDaemon.RaParams; import android.net.ip.RouterAdvertisementDaemon.RaParams; import android.net.util.NetdService; import android.net.util.NetdService; import android.net.util.SharedLog; import android.os.INetworkManagementService; import android.os.INetworkManagementService; import android.os.ServiceSpecificException; import android.os.ServiceSpecificException; import android.os.RemoteException; import android.os.RemoteException; import android.util.Log; import android.util.Slog; import android.util.Slog; import java.net.Inet6Address; import java.net.Inet6Address; Loading @@ -54,6 +54,7 @@ public class IPv6TetheringInterfaceServices { private final String mIfName; private final String mIfName; private final INetworkManagementService mNMService; private final INetworkManagementService mNMService; private final SharedLog mLog; private NetworkInterface mNetworkInterface; private NetworkInterface mNetworkInterface; private byte[] mHwAddr; private byte[] mHwAddr; Loading @@ -61,9 +62,11 @@ public class IPv6TetheringInterfaceServices { private RouterAdvertisementDaemon mRaDaemon; private RouterAdvertisementDaemon mRaDaemon; private RaParams mLastRaParams; private RaParams mLastRaParams; public IPv6TetheringInterfaceServices(String ifname, INetworkManagementService nms) { public IPv6TetheringInterfaceServices( String ifname, INetworkManagementService nms, SharedLog log) { mIfName = ifname; mIfName = ifname; mNMService = nms; mNMService = nms; mLog = log.forSubComponent(mIfName); } } public boolean start() { public boolean start() { Loading @@ -72,12 +75,12 @@ public class IPv6TetheringInterfaceServices { try { try { mNetworkInterface = NetworkInterface.getByName(mIfName); mNetworkInterface = NetworkInterface.getByName(mIfName); } catch (SocketException e) { } catch (SocketException e) { Log.e(TAG, "Error looking up NetworkInterfaces for " + mIfName, e); mLog.e("Error looking up NetworkInterfaces: " + e); stop(); stop(); return false; return false; } } if (mNetworkInterface == null) { if (mNetworkInterface == null) { Log.e(TAG, "Failed to find NetworkInterface for " + mIfName); mLog.e("Failed to find NetworkInterface"); stop(); stop(); return false; return false; } } Loading @@ -85,7 +88,7 @@ public class IPv6TetheringInterfaceServices { try { try { mHwAddr = mNetworkInterface.getHardwareAddress(); mHwAddr = mNetworkInterface.getHardwareAddress(); } catch (SocketException e) { } catch (SocketException e) { Log.e(TAG, "Failed to find hardware address for " + mIfName, e); mLog.e("Failed to find hardware address: " + e); stop(); stop(); return false; return false; } } Loading Loading @@ -161,11 +164,11 @@ public class IPv6TetheringInterfaceServices { try { try { final int removalFailures = mNMService.removeRoutesFromLocalNetwork(toBeRemoved); final int removalFailures = mNMService.removeRoutesFromLocalNetwork(toBeRemoved); if (removalFailures > 0) { 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)); removalFailures)); } } } catch (RemoteException e) { } 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); } } } } Loading Loading @@ -195,7 +198,7 @@ public class IPv6TetheringInterfaceServices { // error (EEXIST is silently ignored). // error (EEXIST is silently ignored). mNMService.addInterfaceToLocalNetwork(mIfName, toBeAdded); mNMService.addInterfaceToLocalNetwork(mIfName, toBeAdded); } catch (RemoteException e) { } 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); } } } } } } Loading @@ -206,7 +209,7 @@ public class IPv6TetheringInterfaceServices { final INetd netd = NetdService.getInstance(); final INetd netd = NetdService.getInstance(); if (netd == null) { if (netd == null) { if (newDnses != null) newDnses.clear(); 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; return; } } Loading @@ -217,7 +220,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.interfaceDelAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); netd.interfaceDelAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); } catch (ServiceSpecificException | RemoteException e) { } 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); } } } } } } Loading @@ -234,7 +237,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.interfaceAddAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); netd.interfaceAddAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); } catch (ServiceSpecificException | RemoteException e) { } 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); newDnses.remove(dns); } } } } Loading @@ -243,7 +246,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.tetherApplyDnsInterfaces(); netd.tetherApplyDnsInterfaces(); } catch (ServiceSpecificException | RemoteException e) { } 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(); if (newDnses != null) newDnses.clear(); } } } } Loading services/core/java/com/android/server/connectivity/tethering/OffloadController.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -18,8 +18,7 @@ package com.android.server.connectivity.tethering; import android.net.LinkProperties; import android.net.LinkProperties; import android.os.Handler; import android.os.Handler; import android.os.RemoteException; import android.net.util.SharedLog; import android.util.Log; /** /** * A class to encapsulate the business logic of programming the tethering * A class to encapsulate the business logic of programming the tethering Loading @@ -32,13 +31,15 @@ public class OffloadController { private final Handler mHandler; private final Handler mHandler; private final OffloadHardwareInterface mHwInterface; private final OffloadHardwareInterface mHwInterface; private final SharedLog mLog; private boolean mConfigInitialized; private boolean mConfigInitialized; private boolean mControlInitialized; private boolean mControlInitialized; private LinkProperties mUpstreamLinkProperties; private LinkProperties mUpstreamLinkProperties; public OffloadController(Handler h, OffloadHardwareInterface hwi) { public OffloadController(Handler h, OffloadHardwareInterface hwi, SharedLog log) { mHandler = h; mHandler = h; mHwInterface = hwi; mHwInterface = hwi; mLog = log.forSubComponent(TAG); } } public void start() { public void start() { Loading @@ -47,7 +48,7 @@ public class OffloadController { if (!mConfigInitialized) { if (!mConfigInitialized) { mConfigInitialized = mHwInterface.initOffloadConfig(); mConfigInitialized = mHwInterface.initOffloadConfig(); if (!mConfigInitialized) { if (!mConfigInitialized) { Log.d(TAG, "tethering offload config not supported"); mLog.i("tethering offload config not supported"); return; return; } } } } Loading Loading
services/core/java/com/android/server/ConnectivityService.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -178,6 +178,9 @@ public class ConnectivityService extends IConnectivityManager.Stub implements PendingIntent.OnFinished { implements PendingIntent.OnFinished { private static final String TAG = ConnectivityService.class.getSimpleName(); 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 DBG = true; private static final boolean VDBG = false; private static final boolean VDBG = false; Loading Loading @@ -1860,7 +1863,7 @@ public class ConnectivityService extends IConnectivityManager.Stub final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (argsContain(args, "--diag")) { if (argsContain(args, DIAG_ARG)) { dumpNetworkDiagnostics(pw); dumpNetworkDiagnostics(pw); return; return; } } Loading Loading @@ -1925,7 +1928,7 @@ public class ConnectivityService extends IConnectivityManager.Stub pw.println(); pw.println(); dumpAvoidBadWifiSettings(pw); dumpAvoidBadWifiSettings(pw); if (argsContain(args, "--short") == false) { if (argsContain(args, SHORT_ARG) == false) { pw.println(); pw.println(); synchronized (mValidationLogs) { synchronized (mValidationLogs) { pw.println("mValidationLogs (most recent first):"); pw.println("mValidationLogs (most recent first):"); Loading
services/core/java/com/android/server/connectivity/Tethering.java +31 −22 Original line number Original line Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static android.hardware.usb.UsbManager.USB_CONNECTED; import static android.hardware.usb.UsbManager.USB_FUNCTION_RNDIS; 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.EXTRA_WIFI_AP_STATE; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; 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.Notification; import android.app.NotificationManager; import android.app.NotificationManager; Loading Loading @@ -47,6 +48,7 @@ import android.net.NetworkRequest; import android.net.NetworkState; import android.net.NetworkState; import android.net.NetworkUtils; import android.net.NetworkUtils; import android.net.RouteInfo; import android.net.RouteInfo; import android.net.util.SharedLog; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager; import android.os.Binder; import android.os.Binder; import android.os.Bundle; import android.os.Bundle; Loading @@ -62,7 +64,6 @@ import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.LocalLog; import android.util.Log; import android.util.Log; import android.util.SparseArray; import android.util.SparseArray; Loading Loading @@ -149,9 +150,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } } private final static int MAX_LOG_RECORDS = 500; private final SharedLog mLog = new SharedLog(TAG); private final LocalLog mLocalLog = new LocalLog(MAX_LOG_RECORDS); // used to synchronize public access to members // used to synchronize public access to members private final Object mPublicSync; private final Object mPublicSync; Loading Loading @@ -184,7 +183,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering INetworkStatsService statsService, INetworkPolicyManager policyManager, INetworkStatsService statsService, INetworkPolicyManager policyManager, Looper looper, MockableSystemProperties systemProperties, Looper looper, MockableSystemProperties systemProperties, TetheringDependencies deps) { TetheringDependencies deps) { mLocalLog.log("CONSTRUCTED"); mLog.mark("constructed"); mContext = context; mContext = context; mNMService = nmService; mNMService = nmService; mStatsService = statsService; mStatsService = statsService; Loading @@ -200,9 +199,9 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mTetherMasterSM.start(); mTetherMasterSM.start(); mOffloadController = new OffloadController(mTetherMasterSM.getHandler(), mOffloadController = new OffloadController(mTetherMasterSM.getHandler(), deps.getOffloadHardwareInterface()); deps.getOffloadHardwareInterface(), mLog); mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mContext, mTetherMasterSM, TetherMasterSM.EVENT_UPSTREAM_CALLBACK, mLog); mForwardedDownstreams = new HashSet<>(); mForwardedDownstreams = new HashSet<>(); mSimChange = new SimChangeListener( mSimChange = new SimChangeListener( mContext, mTetherMasterSM.getHandler(), () -> reevaluateSimCardProvisioning()); mContext, mTetherMasterSM.getHandler(), () -> reevaluateSimCardProvisioning()); Loading Loading @@ -1148,7 +1147,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering addState(mSetDnsForwardersErrorState); addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<>(); mNotifyList = new ArrayList<>(); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog); setInitialState(mInitialState); setInitialState(mInitialState); } } Loading Loading @@ -1195,7 +1194,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering try { try { mNMService.setIpForwardingEnabled(true); mNMService.setIpForwardingEnabled(true); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mSetIpForwardingEnabledErrorState); transitionTo(mSetIpForwardingEnabledErrorState); return false; return false; } } Loading @@ -1208,12 +1207,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mNMService.stopTethering(); mNMService.stopTethering(); mNMService.startTethering(cfg.dhcpRanges); mNMService.startTethering(cfg.dhcpRanges); } catch (Exception ee) { } catch (Exception ee) { mLocalLog.log("ERROR " + ee); mLog.e(ee); transitionTo(mStartTetheringErrorState); transitionTo(mStartTetheringErrorState); return false; return false; } } } } mLocalLog.log("SET master tether settings: ON"); mLog.log("SET master tether settings: ON"); return true; return true; } } Loading @@ -1221,19 +1220,19 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering try { try { mNMService.stopTethering(); mNMService.stopTethering(); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mStopTetheringErrorState); transitionTo(mStopTetheringErrorState); return false; return false; } } try { try { mNMService.setIpForwardingEnabled(false); mNMService.setIpForwardingEnabled(false); } catch (Exception e) { } catch (Exception e) { mLocalLog.log("ERROR " + e); mLog.e(e); transitionTo(mSetIpForwardingDisabledErrorState); transitionTo(mSetIpForwardingDisabledErrorState); return false; return false; } } transitionTo(mInitialState); transitionTo(mInitialState); mLocalLog.log("SET master tether settings: OFF"); mLog.log("SET master tether settings: OFF"); return true; return true; } } Loading Loading @@ -1359,13 +1358,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } try { try { mNMService.setDnsForwarders(network, dnsServers); mNMService.setDnsForwarders(network, dnsServers); mLocalLog.log(String.format( mLog.log(String.format( "SET DNS forwarders: network=%s dnsServers=[%s]", "SET DNS forwarders: network=%s dnsServers=%s", network, Arrays.toString(dnsServers))); network, Arrays.toString(dnsServers))); } catch (Exception e) { } catch (Exception e) { // TODO: Investigate how this can fail and what exactly // TODO: Investigate how this can fail and what exactly // happens if/when such failures occur. // happens if/when such failures occur. mLocalLog.log("ERROR setting DNS forwarders failed, " + e); mLog.e("setting DNS forwarders failed, " + e); transitionTo(mSetDnsForwardersErrorState); transitionTo(mSetDnsForwardersErrorState); } } } } Loading Loading @@ -1721,12 +1720,23 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering pw.println("Log:"); pw.println("Log:"); pw.increaseIndent(); 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(); 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 @Override public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, int state, int error) { int state, int error) { Loading @@ -1740,8 +1750,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } } mLocalLog.log(String.format("OBSERVED iface=%s state=%s error=%s", mLog.log(String.format("OBSERVED iface=%s state=%s error=%s", iface, state, error)); iface, state, error)); try { try { // Notify that we're tethering (or not) this interface. // Notify that we're tethering (or not) this interface. Loading Loading @@ -1779,8 +1788,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private void trackNewTetherableInterface(String iface, int interfaceType) { private void trackNewTetherableInterface(String iface, int interfaceType) { TetherState tetherState; TetherState tetherState; tetherState = new TetherState(new TetherInterfaceStateMachine(iface, mLooper, tetherState = new TetherState(new TetherInterfaceStateMachine(iface, mLooper, interfaceType, mNMService, mStatsService, this, interfaceType, mLog, mNMService, mStatsService, this, new IPv6TetheringInterfaceServices(iface, mNMService))); new IPv6TetheringInterfaceServices(iface, mNMService, mLog))); mTetherStates.put(iface, tetherState); mTetherStates.put(iface, tetherState); tetherState.stateMachine.start(); tetherState.stateMachine.start(); } } Loading
services/core/java/com/android/server/connectivity/tethering/IPv6TetheringCoordinator.java +13 −13 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.net.NetworkCapabilities; import android.net.NetworkState; import android.net.NetworkState; import android.net.RouteInfo; import android.net.RouteInfo; import android.net.util.NetworkConstants; import android.net.util.NetworkConstants; import android.net.util.SharedLog; import android.util.Log; import android.util.Log; import java.net.Inet6Address; import java.net.Inet6Address; Loading Loading @@ -64,6 +65,7 @@ public class IPv6TetheringCoordinator { } } private final ArrayList<TetherInterfaceStateMachine> mNotifyList; private final ArrayList<TetherInterfaceStateMachine> mNotifyList; private final SharedLog mLog; // NOTE: mActiveDownstreams is a list and not a hash data structure because // 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 // 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 // be parceled out on a "first come, first served" basis and a /64 used by Loading @@ -74,8 +76,10 @@ public class IPv6TetheringCoordinator { private short mNextSubnetId; private short mNextSubnetId; private NetworkState mUpstreamNetworkState; private NetworkState mUpstreamNetworkState; public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList) { public IPv6TetheringCoordinator(ArrayList<TetherInterfaceStateMachine> notifyList, SharedLog log) { mNotifyList = notifyList; mNotifyList = notifyList; mLog = log.forSubComponent(TAG); mActiveDownstreams = new LinkedList<>(); mActiveDownstreams = new LinkedList<>(); mUniqueLocalPrefix = generateUniqueLocalPrefix(); mUniqueLocalPrefix = generateUniqueLocalPrefix(); mNextSubnetId = 0; mNextSubnetId = 0; Loading Loading @@ -115,7 +119,7 @@ public class IPv6TetheringCoordinator { if (VDBG) { if (VDBG) { Log.d(TAG, "updateUpstreamNetworkState: " + toDebugString(ns)); Log.d(TAG, "updateUpstreamNetworkState: " + toDebugString(ns)); } } if (!canTetherIPv6(ns)) { if (!canTetherIPv6(ns, mLog)) { stopIPv6TetheringOnAllInterfaces(); stopIPv6TetheringOnAllInterfaces(); setUpstreamNetworkState(null); setUpstreamNetworkState(null); return; return; Loading Loading @@ -150,9 +154,7 @@ public class IPv6TetheringCoordinator { null); null); } } if (DBG) { mLog.log("setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState)); Log.d(TAG, "setUpstreamNetworkState: " + toDebugString(mUpstreamNetworkState)); } } } private void updateIPv6TetheringInterfaces() { private void updateIPv6TetheringInterfaces() { Loading Loading @@ -206,7 +208,7 @@ public class IPv6TetheringCoordinator { return null; return null; } } private static boolean canTetherIPv6(NetworkState ns) { private static boolean canTetherIPv6(NetworkState ns, SharedLog sharedLog) { // Broadly speaking: // Broadly speaking: // // // [1] does the upstream have an IPv6 default route? // [1] does the upstream have an IPv6 default route? Loading Loading @@ -260,14 +262,12 @@ public class IPv6TetheringCoordinator { final boolean outcome = canTether && supportedConfiguration; final boolean outcome = canTether && supportedConfiguration; if (VDBG) { if (ns == null) { if (ns == null) { Log.d(TAG, "No available upstream."); sharedLog.log("No available upstream."); } else { } 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))); (outcome ? "available" : "not available"), toDebugString(ns))); } } } return outcome; return outcome; } } Loading
services/core/java/com/android/server/connectivity/tethering/IPv6TetheringInterfaceServices.java +15 −12 Original line number Original line Diff line number Diff line Loading @@ -28,10 +28,10 @@ import android.net.RouteInfo; import android.net.ip.RouterAdvertisementDaemon; import android.net.ip.RouterAdvertisementDaemon; import android.net.ip.RouterAdvertisementDaemon.RaParams; import android.net.ip.RouterAdvertisementDaemon.RaParams; import android.net.util.NetdService; import android.net.util.NetdService; import android.net.util.SharedLog; import android.os.INetworkManagementService; import android.os.INetworkManagementService; import android.os.ServiceSpecificException; import android.os.ServiceSpecificException; import android.os.RemoteException; import android.os.RemoteException; import android.util.Log; import android.util.Slog; import android.util.Slog; import java.net.Inet6Address; import java.net.Inet6Address; Loading @@ -54,6 +54,7 @@ public class IPv6TetheringInterfaceServices { private final String mIfName; private final String mIfName; private final INetworkManagementService mNMService; private final INetworkManagementService mNMService; private final SharedLog mLog; private NetworkInterface mNetworkInterface; private NetworkInterface mNetworkInterface; private byte[] mHwAddr; private byte[] mHwAddr; Loading @@ -61,9 +62,11 @@ public class IPv6TetheringInterfaceServices { private RouterAdvertisementDaemon mRaDaemon; private RouterAdvertisementDaemon mRaDaemon; private RaParams mLastRaParams; private RaParams mLastRaParams; public IPv6TetheringInterfaceServices(String ifname, INetworkManagementService nms) { public IPv6TetheringInterfaceServices( String ifname, INetworkManagementService nms, SharedLog log) { mIfName = ifname; mIfName = ifname; mNMService = nms; mNMService = nms; mLog = log.forSubComponent(mIfName); } } public boolean start() { public boolean start() { Loading @@ -72,12 +75,12 @@ public class IPv6TetheringInterfaceServices { try { try { mNetworkInterface = NetworkInterface.getByName(mIfName); mNetworkInterface = NetworkInterface.getByName(mIfName); } catch (SocketException e) { } catch (SocketException e) { Log.e(TAG, "Error looking up NetworkInterfaces for " + mIfName, e); mLog.e("Error looking up NetworkInterfaces: " + e); stop(); stop(); return false; return false; } } if (mNetworkInterface == null) { if (mNetworkInterface == null) { Log.e(TAG, "Failed to find NetworkInterface for " + mIfName); mLog.e("Failed to find NetworkInterface"); stop(); stop(); return false; return false; } } Loading @@ -85,7 +88,7 @@ public class IPv6TetheringInterfaceServices { try { try { mHwAddr = mNetworkInterface.getHardwareAddress(); mHwAddr = mNetworkInterface.getHardwareAddress(); } catch (SocketException e) { } catch (SocketException e) { Log.e(TAG, "Failed to find hardware address for " + mIfName, e); mLog.e("Failed to find hardware address: " + e); stop(); stop(); return false; return false; } } Loading Loading @@ -161,11 +164,11 @@ public class IPv6TetheringInterfaceServices { try { try { final int removalFailures = mNMService.removeRoutesFromLocalNetwork(toBeRemoved); final int removalFailures = mNMService.removeRoutesFromLocalNetwork(toBeRemoved); if (removalFailures > 0) { 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)); removalFailures)); } } } catch (RemoteException e) { } 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); } } } } Loading Loading @@ -195,7 +198,7 @@ public class IPv6TetheringInterfaceServices { // error (EEXIST is silently ignored). // error (EEXIST is silently ignored). mNMService.addInterfaceToLocalNetwork(mIfName, toBeAdded); mNMService.addInterfaceToLocalNetwork(mIfName, toBeAdded); } catch (RemoteException e) { } 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); } } } } } } Loading @@ -206,7 +209,7 @@ public class IPv6TetheringInterfaceServices { final INetd netd = NetdService.getInstance(); final INetd netd = NetdService.getInstance(); if (netd == null) { if (netd == null) { if (newDnses != null) newDnses.clear(); 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; return; } } Loading @@ -217,7 +220,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.interfaceDelAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); netd.interfaceDelAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); } catch (ServiceSpecificException | RemoteException e) { } 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); } } } } } } Loading @@ -234,7 +237,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.interfaceAddAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); netd.interfaceAddAddress(mIfName, dnsString, RFC7421_PREFIX_LENGTH); } catch (ServiceSpecificException | RemoteException e) { } 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); newDnses.remove(dns); } } } } Loading @@ -243,7 +246,7 @@ public class IPv6TetheringInterfaceServices { try { try { netd.tetherApplyDnsInterfaces(); netd.tetherApplyDnsInterfaces(); } catch (ServiceSpecificException | RemoteException e) { } 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(); if (newDnses != null) newDnses.clear(); } } } } Loading
services/core/java/com/android/server/connectivity/tethering/OffloadController.java +5 −4 Original line number Original line Diff line number Diff line Loading @@ -18,8 +18,7 @@ package com.android.server.connectivity.tethering; import android.net.LinkProperties; import android.net.LinkProperties; import android.os.Handler; import android.os.Handler; import android.os.RemoteException; import android.net.util.SharedLog; import android.util.Log; /** /** * A class to encapsulate the business logic of programming the tethering * A class to encapsulate the business logic of programming the tethering Loading @@ -32,13 +31,15 @@ public class OffloadController { private final Handler mHandler; private final Handler mHandler; private final OffloadHardwareInterface mHwInterface; private final OffloadHardwareInterface mHwInterface; private final SharedLog mLog; private boolean mConfigInitialized; private boolean mConfigInitialized; private boolean mControlInitialized; private boolean mControlInitialized; private LinkProperties mUpstreamLinkProperties; private LinkProperties mUpstreamLinkProperties; public OffloadController(Handler h, OffloadHardwareInterface hwi) { public OffloadController(Handler h, OffloadHardwareInterface hwi, SharedLog log) { mHandler = h; mHandler = h; mHwInterface = hwi; mHwInterface = hwi; mLog = log.forSubComponent(TAG); } } public void start() { public void start() { Loading @@ -47,7 +48,7 @@ public class OffloadController { if (!mConfigInitialized) { if (!mConfigInitialized) { mConfigInitialized = mHwInterface.initOffloadConfig(); mConfigInitialized = mHwInterface.initOffloadConfig(); if (!mConfigInitialized) { if (!mConfigInitialized) { Log.d(TAG, "tethering offload config not supported"); mLog.i("tethering offload config not supported"); return; return; } } } } Loading