Loading services/core/java/com/android/server/connectivity/Tethering.java +31 −3 Original line number Diff line number Diff line Loading @@ -219,6 +219,10 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); } private WifiManager getWifiManager() { return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); } private void updateConfiguration() { mConfig = new TetheringConfiguration(mContext); } Loading Loading @@ -411,8 +415,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private int setWifiTethering(final boolean enable) { synchronized (mPublicSync) { mWifiTetherRequested = enable; final WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); final WifiManager wifiManager = getWifiManager(); if ((enable && wifiManager.startSoftAp(null /* use existing wifi config */)) || (!enable && wifiManager.stopSoftAp())) { return ConnectivityManager.TETHER_ERROR_NO_ERROR; Loading Loading @@ -1334,12 +1337,37 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } else { mForwardedDownstreams.remove(who); } // If this is a Wi-Fi interface, notify WifiManager of the active serving state. if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) { final WifiManager mgr = getWifiManager(); final String iface = who.interfaceName(); switch (mode) { case IControlsTethering.STATE_TETHERED: mgr.updateInterfaceIpState(iface, WifiManager.IFACE_IP_MODE_TETHERED); break; case IControlsTethering.STATE_LOCAL_ONLY: mgr.updateInterfaceIpState(iface, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); break; default: Log.wtf(TAG, "Unknown active serving mode: " + mode); break; } } } private void handleInterfaceServingStateInactive(TetherInterfaceStateMachine who) { mNotifyList.remove(who); mIPv6TetheringCoordinator.removeActiveDownstream(who); mForwardedDownstreams.remove(who); // If this is a Wi-Fi interface, tell WifiManager of any errors. if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) { if (who.lastError() != ConnectivityManager.TETHER_ERROR_NO_ERROR) { getWifiManager().updateInterfaceIpState( who.interfaceName(), WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR); } } } class InitialState extends State { Loading Loading @@ -1661,7 +1689,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, int state, int error) { synchronized (mPublicSync) { TetherState tetherState = mTetherStates.get(iface); final TetherState tetherState = mTetherStates.get(iface); if (tetherState != null && tetherState.stateMachine.equals(who)) { tetherState.lastState = state; tetherState.lastError = error; Loading services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +5 −3 Original line number Diff line number Diff line Loading @@ -117,9 +117,11 @@ public class TetherInterfaceStateMachine extends StateMachine { setInitialState(mInitialState); } public int interfaceType() { return mInterfaceType; } public String interfaceName() { return mIfaceName; } public int interfaceType() { return mInterfaceType; } public int lastError() { return mLastError; } // configured when we start tethering and unconfig'd on error or conclusion private boolean configureIfaceIp(boolean enabled) { Loading tests/net/java/com/android/server/connectivity/TetheringTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,9 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); verify(mWifiManager).updateInterfaceIpState( mTestIfname, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); verifyNoMoreInteractions(mWifiManager); verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY); // UpstreamNetworkMonitor will be started, and will register two callbacks: // a "listen all" and a "track default". Loading @@ -261,6 +264,7 @@ public class TetheringTest { verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine // has been reaped yields an unknown interface error. assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, Loading Loading @@ -292,6 +296,9 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); verify(mWifiManager).updateInterfaceIpState( mTestIfname, WifiManager.IFACE_IP_MODE_TETHERED); verifyNoMoreInteractions(mWifiManager); verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_TETHER); // UpstreamNetworkMonitor will be started, and will register two callbacks: // a "listen all" and a "track default". Loading Loading @@ -338,6 +345,7 @@ public class TetheringTest { verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine // has been reaped yields an unknown interface error. assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, Loading Loading
services/core/java/com/android/server/connectivity/Tethering.java +31 −3 Original line number Diff line number Diff line Loading @@ -219,6 +219,10 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering return (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); } private WifiManager getWifiManager() { return (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); } private void updateConfiguration() { mConfig = new TetheringConfiguration(mContext); } Loading Loading @@ -411,8 +415,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private int setWifiTethering(final boolean enable) { synchronized (mPublicSync) { mWifiTetherRequested = enable; final WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); final WifiManager wifiManager = getWifiManager(); if ((enable && wifiManager.startSoftAp(null /* use existing wifi config */)) || (!enable && wifiManager.stopSoftAp())) { return ConnectivityManager.TETHER_ERROR_NO_ERROR; Loading Loading @@ -1334,12 +1337,37 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } else { mForwardedDownstreams.remove(who); } // If this is a Wi-Fi interface, notify WifiManager of the active serving state. if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) { final WifiManager mgr = getWifiManager(); final String iface = who.interfaceName(); switch (mode) { case IControlsTethering.STATE_TETHERED: mgr.updateInterfaceIpState(iface, WifiManager.IFACE_IP_MODE_TETHERED); break; case IControlsTethering.STATE_LOCAL_ONLY: mgr.updateInterfaceIpState(iface, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); break; default: Log.wtf(TAG, "Unknown active serving mode: " + mode); break; } } } private void handleInterfaceServingStateInactive(TetherInterfaceStateMachine who) { mNotifyList.remove(who); mIPv6TetheringCoordinator.removeActiveDownstream(who); mForwardedDownstreams.remove(who); // If this is a Wi-Fi interface, tell WifiManager of any errors. if (who.interfaceType() == ConnectivityManager.TETHERING_WIFI) { if (who.lastError() != ConnectivityManager.TETHER_ERROR_NO_ERROR) { getWifiManager().updateInterfaceIpState( who.interfaceName(), WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR); } } } class InitialState extends State { Loading Loading @@ -1661,7 +1689,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public void notifyInterfaceStateChange(String iface, TetherInterfaceStateMachine who, int state, int error) { synchronized (mPublicSync) { TetherState tetherState = mTetherStates.get(iface); final TetherState tetherState = mTetherStates.get(iface); if (tetherState != null && tetherState.stateMachine.equals(who)) { tetherState.lastState = state; tetherState.lastError = error; Loading
services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +5 −3 Original line number Diff line number Diff line Loading @@ -117,9 +117,11 @@ public class TetherInterfaceStateMachine extends StateMachine { setInitialState(mInitialState); } public int interfaceType() { return mInterfaceType; } public String interfaceName() { return mIfaceName; } public int interfaceType() { return mInterfaceType; } public int lastError() { return mLastError; } // configured when we start tethering and unconfig'd on error or conclusion private boolean configureIfaceIp(boolean enabled) { Loading
tests/net/java/com/android/server/connectivity/TetheringTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,9 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); verify(mWifiManager).updateInterfaceIpState( mTestIfname, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); verifyNoMoreInteractions(mWifiManager); verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY); // UpstreamNetworkMonitor will be started, and will register two callbacks: // a "listen all" and a "track default". Loading @@ -261,6 +264,7 @@ public class TetheringTest { verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine // has been reaped yields an unknown interface error. assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, Loading Loading @@ -292,6 +296,9 @@ public class TetheringTest { verify(mNMService, times(1)).setIpForwardingEnabled(true); verify(mNMService, times(1)).startTethering(any(String[].class)); verifyNoMoreInteractions(mNMService); verify(mWifiManager).updateInterfaceIpState( mTestIfname, WifiManager.IFACE_IP_MODE_TETHERED); verifyNoMoreInteractions(mWifiManager); verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_TETHER); // UpstreamNetworkMonitor will be started, and will register two callbacks: // a "listen all" and a "track default". Loading Loading @@ -338,6 +345,7 @@ public class TetheringTest { verify(mNMService, times(1)).stopTethering(); verify(mNMService, times(1)).setIpForwardingEnabled(false); verifyNoMoreInteractions(mNMService); verifyNoMoreInteractions(mWifiManager); // Asking for the last error after the per-interface state machine // has been reaped yields an unknown interface error. assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, Loading