Loading services/core/java/com/android/server/connectivity/Tethering.java +39 −38 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.IoThread; import com.android.server.connectivity.tethering.IControlsTethering; import com.android.server.connectivity.tethering.TetherInterfaceSM; import com.android.server.connectivity.tethering.TetherInterfaceStateMachine; import com.android.server.net.BaseNetworkObserver; import java.io.FileDescriptor; Loading Loading @@ -101,7 +101,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private final static boolean VDBG = false; private static final Class[] messageClasses = { Tethering.class, TetherMasterSM.class, TetherInterfaceSM.class Tethering.class, TetherMasterSM.class, TetherInterfaceStateMachine.class }; private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); Loading @@ -127,7 +127,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private final INetworkStatsService mStatsService; private final Looper mLooper; private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces private HashMap<String, TetherInterfaceStateMachine> mIfaces; // all tethered/tetherable ifaces private BroadcastReceiver mStateReceiver; Loading Loading @@ -172,7 +172,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mPublicSync = new Object(); mIfaces = new HashMap<String, TetherInterfaceSM>(); mIfaces = new HashMap<String, TetherInterfaceStateMachine>(); // make our own thread so we don't anr the system mLooper = IoThread.get().getLooper(); Loading Loading @@ -259,10 +259,10 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } if (found == false) return; TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (up) { if (sm == null) { sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync, sm = new TetherInterfaceStateMachine(iface, mLooper, usb, mPublicSync, mNMService, mStatsService, this); mIfaces.put(iface, sm); sm.start(); Loading @@ -273,7 +273,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering // we will handle disconnect in interfaceRemoved instead if (VDBG) Log.d(TAG, "ignore interface down for " + iface); } else if (sm != null) { sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); sm.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); mIfaces.remove(iface); } } Loading Loading @@ -333,12 +333,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering return; } TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null) { if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring"); return; } sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync, sm = new TetherInterfaceStateMachine(iface, mLooper, usb, mPublicSync, mNMService, mStatsService, this); mIfaces.put(iface, sm); sm.start(); Loading @@ -349,14 +349,14 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public void interfaceRemoved(String iface) { if (VDBG) Log.d(TAG, "interfaceRemoved " + iface); synchronized (mPublicSync) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm == null) { if (VDBG) { Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring"); } return; } sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); sm.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); mIfaces.remove(iface); } } Loading Loading @@ -576,7 +576,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public int tether(String iface) { if (DBG) Log.d(TAG, "Tethering " + iface); TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); } Loading @@ -588,13 +588,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; } sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED); sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); return ConnectivityManager.TETHER_ERROR_NO_ERROR; } public int untether(String iface) { if (DBG) Log.d(TAG, "Untethering " + iface); TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); } Loading @@ -606,7 +606,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; } sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); return ConnectivityManager.TETHER_ERROR_NO_ERROR; } Loading @@ -618,7 +618,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } public int getLastTetherError(String iface) { TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); if (sm == null) { Loading Loading @@ -647,7 +647,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> ifaces = mIfaces.keySet(); for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null) { if (sm.isErrored()) { erroredList.add(iface); Loading Loading @@ -917,7 +917,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isTethered()) { list.add(key); } Loading @@ -935,7 +935,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isAvailable()) { list.add(key); } Loading @@ -957,7 +957,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isErrored()) { list.add(key); } Loading Loading @@ -1097,7 +1097,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private State mStopTetheringErrorState; private State mSetDnsForwardersErrorState; private ArrayList<TetherInterfaceSM> mNotifyList; private ArrayList<TetherInterfaceStateMachine> mNotifyList; private int mMobileApnReserved = ConnectivityManager.TYPE_NONE; private NetworkCallback mMobileUpstreamCallback; Loading @@ -1124,7 +1124,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mSetDnsForwardersErrorState = new SetDnsForwardersErrorState(); addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<TetherInterfaceSM>(); mNotifyList = new ArrayList<>(); setInitialState(mInitialState); } Loading Loading @@ -1339,8 +1339,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering protected void notifyTetheredOfNewUpstreamIface(String ifaceName) { if (DBG) Log.d(TAG, "Notifying tethered with upstream=" + ifaceName); mCurrentUpstreamIface = ifaceName; for (TetherInterfaceSM sm : mNotifyList) { sm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, for (TetherInterfaceStateMachine sm : mNotifyList) { sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, ifaceName); } } Loading Loading @@ -1409,7 +1409,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> ifaces = mIfaces.keySet(); for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null && sm.isTethered()) { if (isUsb(iface)) { tethered.add(new Integer( Loading Loading @@ -1455,13 +1455,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); mNotifyList.add(who); transitionTo(mTetherModeAliveState); break; case CMD_TETHER_MODE_UNREQUESTED: who = (TetherInterfaceSM)message.obj; who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); int index = mNotifyList.indexOf(who); if (index != -1) { Loading Loading @@ -1503,14 +1503,14 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); mNotifyList.add(who); who.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, who.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, mCurrentUpstreamIface); break; case CMD_TETHER_MODE_UNREQUESTED: who = (TetherInterfaceSM)message.obj; who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); int index = mNotifyList.indexOf(who); if (index != -1) { Loading Loading @@ -1572,7 +1572,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; who.sendMessage(mErrorNotification); break; default: Loading @@ -1583,7 +1583,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering void notify(int msgType) { mErrorNotification = msgType; for (Object o : mNotifyList) { TetherInterfaceSM sm = (TetherInterfaceSM)o; TetherInterfaceStateMachine sm = (TetherInterfaceStateMachine)o; sm.sendMessage(msgType); } } Loading @@ -1593,7 +1593,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setIpForwardingEnabled"); notify(TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR); notify(TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR); } } Loading @@ -1601,7 +1601,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setIpForwardingDisabled"); notify(TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR); notify(TetherInterfaceStateMachine.CMD_IP_FORWARDING_DISABLE_ERROR); } } Loading @@ -1609,7 +1609,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in startTethering"); notify(TetherInterfaceSM.CMD_START_TETHERING_ERROR); notify(TetherInterfaceStateMachine.CMD_START_TETHERING_ERROR); try { mNMService.setIpForwardingEnabled(false); } catch (Exception e) {} Loading @@ -1620,7 +1620,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in stopTethering"); notify(TetherInterfaceSM.CMD_STOP_TETHERING_ERROR); notify(TetherInterfaceStateMachine.CMD_STOP_TETHERING_ERROR); try { mNMService.setIpForwardingEnabled(false); } catch (Exception e) {} Loading @@ -1631,7 +1631,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setDnsForwarders"); notify(TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR); notify(TetherInterfaceStateMachine.CMD_SET_DNS_FORWARDERS_ERROR); try { mNMService.stopTethering(); } catch (Exception e) {} Loading Loading @@ -1675,7 +1675,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } @Override public void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceSM who) { public void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceStateMachine who) { mTetherMasterSM.sendMessage((isReady) ? TetherMasterSM.CMD_TETHER_MODE_REQUESTED : TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, who); } Loading services/core/java/com/android/server/connectivity/tethering/IControlsTethering.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,5 +23,5 @@ package com.android.server.connectivity.tethering; */ public interface IControlsTethering { void sendTetherStateChangedBroadcast(); void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceSM who); void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceStateMachine who); } services/core/java/com/android/server/connectivity/tethering/TetherInterfaceSM.java→services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +6 −6 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ import java.net.InetAddress; * * Tracks the eligibility of a given network interface for tethering. */ public class TetherInterfaceSM extends StateMachine { public class TetherInterfaceStateMachine extends StateMachine { private static final String USB_NEAR_IFACE_ADDR = "192.168.42.129"; private static final int USB_PREFIX_LENGTH = 24; Loading @@ -48,7 +48,7 @@ public class TetherInterfaceSM extends StateMachine { private final static boolean DBG = false; private final static boolean VDBG = false; private static final Class[] messageClasses = { TetherInterfaceSM.class TetherInterfaceStateMachine.class }; private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); Loading Loading @@ -90,7 +90,7 @@ public class TetherInterfaceSM extends StateMachine { private int mLastError; private String mMyUpstreamIfaceName; // may change over time public TetherInterfaceSM(String ifaceName, Looper looper, boolean usb, Object mutex, public TetherInterfaceStateMachine(String ifaceName, Looper looper, boolean usb, Object mutex, INetworkManagementService nMService, INetworkStatsService statsService, IControlsTethering tetherController) { super(ifaceName, looper); Loading Loading @@ -224,7 +224,7 @@ public class TetherInterfaceSM extends StateMachine { switch (message.what) { case CMD_TETHER_REQUESTED: setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR); mTetherController.notifyInterfaceTetheringReadiness(true, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(true, TetherInterfaceStateMachine.this); transitionTo(mTetheredState); break; case CMD_INTERFACE_DOWN: Loading @@ -244,7 +244,7 @@ public class TetherInterfaceSM extends StateMachine { setAvailable(false); if (mUsb) { if (!configureUsbIface(true, mIfaceName)) { mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceStateMachine.this); setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); transitionTo(mInitialState); Loading Loading @@ -314,7 +314,7 @@ public class TetherInterfaceSM extends StateMachine { ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR); break; } mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceStateMachine.this); if (message.what == CMD_TETHER_UNREQUESTED) { if (mUsb) { if (!configureUsbIface(false, mIfaceName)) { Loading services/tests/servicestests/src/com/android/server/connectivity/tethering/TetherInterfaceSMTest.java→services/tests/servicestests/src/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java +20 −19 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class TetherInterfaceSMTest { public class TetherInterfaceStateMachineTest { private static final String IFACE_NAME = "testnet1"; private static final String UPSTREAM_IFACE = "upstream0"; private static final String UPSTREAM_IFACE2 = "upstream1"; Loading @@ -49,10 +49,10 @@ public class TetherInterfaceSMTest { private final TestLooper mLooper = new TestLooper(); private final Object mMutex = new Object(); private TetherInterfaceSM mTestedSm; private TetherInterfaceStateMachine mTestedSm; private void initStateMachine(boolean isUsb) { mTestedSm = new TetherInterfaceSM(IFACE_NAME, mLooper.getLooper(), isUsb, mMutex, mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), isUsb, mMutex, mNMService, mStatsService, mTetherHelper); mTestedSm.start(); // Starting the state machine always puts us in a consistent state and notifies Loading @@ -63,7 +63,7 @@ public class TetherInterfaceSMTest { private void initTetheredStateMachine(boolean isUsb, String upstreamIface) { initStateMachine(isUsb); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); if (upstreamIface != null) { dispatchTetherConnectionChanged(upstreamIface); } Loading @@ -77,7 +77,7 @@ public class TetherInterfaceSMTest { @Test public void startsOutAvailable() { mTestedSm = new TetherInterfaceSM(IFACE_NAME, mLooper.getLooper(), false, mMutex, mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), false, mMutex, mNMService, mStatsService, mTetherHelper); mTestedSm.start(); mLooper.dispatchAll(); Loading @@ -92,13 +92,13 @@ public class TetherInterfaceSMTest { public void shouldDoNothingUntilRequested() { initStateMachine(false); final int [] NOOP_COMMANDS = { TetherInterfaceSM.CMD_TETHER_UNREQUESTED, TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR, TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR, TetherInterfaceSM.CMD_START_TETHERING_ERROR, TetherInterfaceSM.CMD_STOP_TETHERING_ERROR, TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR, TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED, TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR, TetherInterfaceStateMachine.CMD_IP_FORWARDING_DISABLE_ERROR, TetherInterfaceStateMachine.CMD_START_TETHERING_ERROR, TetherInterfaceStateMachine.CMD_STOP_TETHERING_ERROR, TetherInterfaceStateMachine.CMD_SET_DNS_FORWARDERS_ERROR, TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED }; for (int command : NOOP_COMMANDS) { // None of these commands should trigger us to request action from Loading @@ -111,7 +111,7 @@ public class TetherInterfaceSMTest { @Test public void handlesImmediateInterfaceDown() { initStateMachine(false); dispatchCommand(TetherInterfaceSM.CMD_INTERFACE_DOWN); dispatchCommand(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); verify(mTetherHelper).sendTetherStateChangedBroadcast(); verifyNoMoreInteractions(mNMService, mStatsService, mTetherHelper); assertFalse("Should not be tetherable when the interface is down", mTestedSm.isAvailable()); Loading @@ -123,7 +123,7 @@ public class TetherInterfaceSMTest { @Test public void canBeTethered() throws RemoteException { initStateMachine(false); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm); inOrder.verify(mNMService).tetherInterface(IFACE_NAME); Loading @@ -139,7 +139,7 @@ public class TetherInterfaceSMTest { public void canUnrequestTethering() throws Exception { initTetheredStateMachine(false, null); dispatchCommand(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); inOrder.verify(mNMService).untetherInterface(IFACE_NAME); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(false, mTestedSm); Loading @@ -155,7 +155,7 @@ public class TetherInterfaceSMTest { initStateMachine(true); when(mNMService.getInterfaceConfig(IFACE_NAME)).thenReturn(mInterfaceConfiguration); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm); Loading Loading @@ -206,7 +206,7 @@ public class TetherInterfaceSMTest { public void canUnrequestTetheringWithUpstream() throws Exception { initTetheredStateMachine(false, UPSTREAM_IFACE); dispatchCommand(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); inOrder.verify(mStatsService).forceUpdate(); inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE); Loading @@ -224,7 +224,7 @@ public class TetherInterfaceSMTest { /** * Send a command to the state machine under test, and run the event loop to idle. * * @param command One of the TetherInterfaceSM.CMD_* constants. * @param command One of the TetherInterfaceStateMachine.CMD_* constants. */ private void dispatchCommand(int command) { mTestedSm.sendMessage(command); Loading @@ -238,7 +238,8 @@ public class TetherInterfaceSMTest { * @param upstreamIface String name of upstream interface (or null) */ private void dispatchTetherConnectionChanged(String upstreamIface) { mTestedSm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, upstreamIface); mTestedSm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, upstreamIface); mLooper.dispatchAll(); } } Loading
services/core/java/com/android/server/connectivity/Tethering.java +39 −38 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.server.IoThread; import com.android.server.connectivity.tethering.IControlsTethering; import com.android.server.connectivity.tethering.TetherInterfaceSM; import com.android.server.connectivity.tethering.TetherInterfaceStateMachine; import com.android.server.net.BaseNetworkObserver; import java.io.FileDescriptor; Loading Loading @@ -101,7 +101,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private final static boolean VDBG = false; private static final Class[] messageClasses = { Tethering.class, TetherMasterSM.class, TetherInterfaceSM.class Tethering.class, TetherMasterSM.class, TetherInterfaceStateMachine.class }; private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); Loading @@ -127,7 +127,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private final INetworkStatsService mStatsService; private final Looper mLooper; private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces private HashMap<String, TetherInterfaceStateMachine> mIfaces; // all tethered/tetherable ifaces private BroadcastReceiver mStateReceiver; Loading Loading @@ -172,7 +172,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mPublicSync = new Object(); mIfaces = new HashMap<String, TetherInterfaceSM>(); mIfaces = new HashMap<String, TetherInterfaceStateMachine>(); // make our own thread so we don't anr the system mLooper = IoThread.get().getLooper(); Loading Loading @@ -259,10 +259,10 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } if (found == false) return; TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (up) { if (sm == null) { sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync, sm = new TetherInterfaceStateMachine(iface, mLooper, usb, mPublicSync, mNMService, mStatsService, this); mIfaces.put(iface, sm); sm.start(); Loading @@ -273,7 +273,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering // we will handle disconnect in interfaceRemoved instead if (VDBG) Log.d(TAG, "ignore interface down for " + iface); } else if (sm != null) { sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); sm.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); mIfaces.remove(iface); } } Loading Loading @@ -333,12 +333,12 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering return; } TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null) { if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring"); return; } sm = new TetherInterfaceSM(iface, mLooper, usb, mPublicSync, sm = new TetherInterfaceStateMachine(iface, mLooper, usb, mPublicSync, mNMService, mStatsService, this); mIfaces.put(iface, sm); sm.start(); Loading @@ -349,14 +349,14 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public void interfaceRemoved(String iface) { if (VDBG) Log.d(TAG, "interfaceRemoved " + iface); synchronized (mPublicSync) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm == null) { if (VDBG) { Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring"); } return; } sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); sm.sendMessage(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); mIfaces.remove(iface); } } Loading Loading @@ -576,7 +576,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering public int tether(String iface) { if (DBG) Log.d(TAG, "Tethering " + iface); TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); } Loading @@ -588,13 +588,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; } sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED); sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); return ConnectivityManager.TETHER_ERROR_NO_ERROR; } public int untether(String iface) { if (DBG) Log.d(TAG, "Untethering " + iface); TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); } Loading @@ -606,7 +606,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring"); return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; } sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); return ConnectivityManager.TETHER_ERROR_NO_ERROR; } Loading @@ -618,7 +618,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } public int getLastTetherError(String iface) { TetherInterfaceSM sm = null; TetherInterfaceStateMachine sm = null; synchronized (mPublicSync) { sm = mIfaces.get(iface); if (sm == null) { Loading Loading @@ -647,7 +647,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> ifaces = mIfaces.keySet(); for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null) { if (sm.isErrored()) { erroredList.add(iface); Loading Loading @@ -917,7 +917,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isTethered()) { list.add(key); } Loading @@ -935,7 +935,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isAvailable()) { list.add(key); } Loading @@ -957,7 +957,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> keys = mIfaces.keySet(); for (String key : keys) { TetherInterfaceSM sm = mIfaces.get(key); TetherInterfaceStateMachine sm = mIfaces.get(key); if (sm.isErrored()) { list.add(key); } Loading Loading @@ -1097,7 +1097,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering private State mStopTetheringErrorState; private State mSetDnsForwardersErrorState; private ArrayList<TetherInterfaceSM> mNotifyList; private ArrayList<TetherInterfaceStateMachine> mNotifyList; private int mMobileApnReserved = ConnectivityManager.TYPE_NONE; private NetworkCallback mMobileUpstreamCallback; Loading @@ -1124,7 +1124,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering mSetDnsForwardersErrorState = new SetDnsForwardersErrorState(); addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<TetherInterfaceSM>(); mNotifyList = new ArrayList<>(); setInitialState(mInitialState); } Loading Loading @@ -1339,8 +1339,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering protected void notifyTetheredOfNewUpstreamIface(String ifaceName) { if (DBG) Log.d(TAG, "Notifying tethered with upstream=" + ifaceName); mCurrentUpstreamIface = ifaceName; for (TetherInterfaceSM sm : mNotifyList) { sm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, for (TetherInterfaceStateMachine sm : mNotifyList) { sm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, ifaceName); } } Loading Loading @@ -1409,7 +1409,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering synchronized (mPublicSync) { Set<String> ifaces = mIfaces.keySet(); for (String iface : ifaces) { TetherInterfaceSM sm = mIfaces.get(iface); TetherInterfaceStateMachine sm = mIfaces.get(iface); if (sm != null && sm.isTethered()) { if (isUsb(iface)) { tethered.add(new Integer( Loading Loading @@ -1455,13 +1455,13 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); mNotifyList.add(who); transitionTo(mTetherModeAliveState); break; case CMD_TETHER_MODE_UNREQUESTED: who = (TetherInterfaceSM)message.obj; who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); int index = mNotifyList.indexOf(who); if (index != -1) { Loading Loading @@ -1503,14 +1503,14 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); mNotifyList.add(who); who.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, who.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, mCurrentUpstreamIface); break; case CMD_TETHER_MODE_UNREQUESTED: who = (TetherInterfaceSM)message.obj; who = (TetherInterfaceStateMachine)message.obj; if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); int index = mNotifyList.indexOf(who); if (index != -1) { Loading Loading @@ -1572,7 +1572,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering boolean retValue = true; switch (message.what) { case CMD_TETHER_MODE_REQUESTED: TetherInterfaceSM who = (TetherInterfaceSM)message.obj; TetherInterfaceStateMachine who = (TetherInterfaceStateMachine)message.obj; who.sendMessage(mErrorNotification); break; default: Loading @@ -1583,7 +1583,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering void notify(int msgType) { mErrorNotification = msgType; for (Object o : mNotifyList) { TetherInterfaceSM sm = (TetherInterfaceSM)o; TetherInterfaceStateMachine sm = (TetherInterfaceStateMachine)o; sm.sendMessage(msgType); } } Loading @@ -1593,7 +1593,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setIpForwardingEnabled"); notify(TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR); notify(TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR); } } Loading @@ -1601,7 +1601,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setIpForwardingDisabled"); notify(TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR); notify(TetherInterfaceStateMachine.CMD_IP_FORWARDING_DISABLE_ERROR); } } Loading @@ -1609,7 +1609,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in startTethering"); notify(TetherInterfaceSM.CMD_START_TETHERING_ERROR); notify(TetherInterfaceStateMachine.CMD_START_TETHERING_ERROR); try { mNMService.setIpForwardingEnabled(false); } catch (Exception e) {} Loading @@ -1620,7 +1620,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in stopTethering"); notify(TetherInterfaceSM.CMD_STOP_TETHERING_ERROR); notify(TetherInterfaceStateMachine.CMD_STOP_TETHERING_ERROR); try { mNMService.setIpForwardingEnabled(false); } catch (Exception e) {} Loading @@ -1631,7 +1631,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering @Override public void enter() { Log.e(TAG, "Error in setDnsForwarders"); notify(TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR); notify(TetherInterfaceStateMachine.CMD_SET_DNS_FORWARDERS_ERROR); try { mNMService.stopTethering(); } catch (Exception e) {} Loading Loading @@ -1675,7 +1675,8 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } @Override public void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceSM who) { public void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceStateMachine who) { mTetherMasterSM.sendMessage((isReady) ? TetherMasterSM.CMD_TETHER_MODE_REQUESTED : TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, who); } Loading
services/core/java/com/android/server/connectivity/tethering/IControlsTethering.java +2 −2 Original line number Diff line number Diff line Loading @@ -23,5 +23,5 @@ package com.android.server.connectivity.tethering; */ public interface IControlsTethering { void sendTetherStateChangedBroadcast(); void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceSM who); void notifyInterfaceTetheringReadiness(boolean isReady, TetherInterfaceStateMachine who); }
services/core/java/com/android/server/connectivity/tethering/TetherInterfaceSM.java→services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +6 −6 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ import java.net.InetAddress; * * Tracks the eligibility of a given network interface for tethering. */ public class TetherInterfaceSM extends StateMachine { public class TetherInterfaceStateMachine extends StateMachine { private static final String USB_NEAR_IFACE_ADDR = "192.168.42.129"; private static final int USB_PREFIX_LENGTH = 24; Loading @@ -48,7 +48,7 @@ public class TetherInterfaceSM extends StateMachine { private final static boolean DBG = false; private final static boolean VDBG = false; private static final Class[] messageClasses = { TetherInterfaceSM.class TetherInterfaceStateMachine.class }; private static final SparseArray<String> sMagicDecoderRing = MessageUtils.findMessageNames(messageClasses); Loading Loading @@ -90,7 +90,7 @@ public class TetherInterfaceSM extends StateMachine { private int mLastError; private String mMyUpstreamIfaceName; // may change over time public TetherInterfaceSM(String ifaceName, Looper looper, boolean usb, Object mutex, public TetherInterfaceStateMachine(String ifaceName, Looper looper, boolean usb, Object mutex, INetworkManagementService nMService, INetworkStatsService statsService, IControlsTethering tetherController) { super(ifaceName, looper); Loading Loading @@ -224,7 +224,7 @@ public class TetherInterfaceSM extends StateMachine { switch (message.what) { case CMD_TETHER_REQUESTED: setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR); mTetherController.notifyInterfaceTetheringReadiness(true, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(true, TetherInterfaceStateMachine.this); transitionTo(mTetheredState); break; case CMD_INTERFACE_DOWN: Loading @@ -244,7 +244,7 @@ public class TetherInterfaceSM extends StateMachine { setAvailable(false); if (mUsb) { if (!configureUsbIface(true, mIfaceName)) { mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceStateMachine.this); setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); transitionTo(mInitialState); Loading Loading @@ -314,7 +314,7 @@ public class TetherInterfaceSM extends StateMachine { ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR); break; } mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this); mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceStateMachine.this); if (message.what == CMD_TETHER_UNREQUESTED) { if (mUsb) { if (!configureUsbIface(false, mIfaceName)) { Loading
services/tests/servicestests/src/com/android/server/connectivity/tethering/TetherInterfaceSMTest.java→services/tests/servicestests/src/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java +20 −19 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class TetherInterfaceSMTest { public class TetherInterfaceStateMachineTest { private static final String IFACE_NAME = "testnet1"; private static final String UPSTREAM_IFACE = "upstream0"; private static final String UPSTREAM_IFACE2 = "upstream1"; Loading @@ -49,10 +49,10 @@ public class TetherInterfaceSMTest { private final TestLooper mLooper = new TestLooper(); private final Object mMutex = new Object(); private TetherInterfaceSM mTestedSm; private TetherInterfaceStateMachine mTestedSm; private void initStateMachine(boolean isUsb) { mTestedSm = new TetherInterfaceSM(IFACE_NAME, mLooper.getLooper(), isUsb, mMutex, mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), isUsb, mMutex, mNMService, mStatsService, mTetherHelper); mTestedSm.start(); // Starting the state machine always puts us in a consistent state and notifies Loading @@ -63,7 +63,7 @@ public class TetherInterfaceSMTest { private void initTetheredStateMachine(boolean isUsb, String upstreamIface) { initStateMachine(isUsb); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); if (upstreamIface != null) { dispatchTetherConnectionChanged(upstreamIface); } Loading @@ -77,7 +77,7 @@ public class TetherInterfaceSMTest { @Test public void startsOutAvailable() { mTestedSm = new TetherInterfaceSM(IFACE_NAME, mLooper.getLooper(), false, mMutex, mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), false, mMutex, mNMService, mStatsService, mTetherHelper); mTestedSm.start(); mLooper.dispatchAll(); Loading @@ -92,13 +92,13 @@ public class TetherInterfaceSMTest { public void shouldDoNothingUntilRequested() { initStateMachine(false); final int [] NOOP_COMMANDS = { TetherInterfaceSM.CMD_TETHER_UNREQUESTED, TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR, TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR, TetherInterfaceSM.CMD_START_TETHERING_ERROR, TetherInterfaceSM.CMD_STOP_TETHERING_ERROR, TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR, TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED, TetherInterfaceStateMachine.CMD_IP_FORWARDING_ENABLE_ERROR, TetherInterfaceStateMachine.CMD_IP_FORWARDING_DISABLE_ERROR, TetherInterfaceStateMachine.CMD_START_TETHERING_ERROR, TetherInterfaceStateMachine.CMD_STOP_TETHERING_ERROR, TetherInterfaceStateMachine.CMD_SET_DNS_FORWARDERS_ERROR, TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED }; for (int command : NOOP_COMMANDS) { // None of these commands should trigger us to request action from Loading @@ -111,7 +111,7 @@ public class TetherInterfaceSMTest { @Test public void handlesImmediateInterfaceDown() { initStateMachine(false); dispatchCommand(TetherInterfaceSM.CMD_INTERFACE_DOWN); dispatchCommand(TetherInterfaceStateMachine.CMD_INTERFACE_DOWN); verify(mTetherHelper).sendTetherStateChangedBroadcast(); verifyNoMoreInteractions(mNMService, mStatsService, mTetherHelper); assertFalse("Should not be tetherable when the interface is down", mTestedSm.isAvailable()); Loading @@ -123,7 +123,7 @@ public class TetherInterfaceSMTest { @Test public void canBeTethered() throws RemoteException { initStateMachine(false); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm); inOrder.verify(mNMService).tetherInterface(IFACE_NAME); Loading @@ -139,7 +139,7 @@ public class TetherInterfaceSMTest { public void canUnrequestTethering() throws Exception { initTetheredStateMachine(false, null); dispatchCommand(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); inOrder.verify(mNMService).untetherInterface(IFACE_NAME); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(false, mTestedSm); Loading @@ -155,7 +155,7 @@ public class TetherInterfaceSMTest { initStateMachine(true); when(mNMService.getInterfaceConfig(IFACE_NAME)).thenReturn(mInterfaceConfiguration); dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_REQUESTED); InOrder inOrder = inOrder(mTetherHelper, mNMService); inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm); Loading Loading @@ -206,7 +206,7 @@ public class TetherInterfaceSMTest { public void canUnrequestTetheringWithUpstream() throws Exception { initTetheredStateMachine(false, UPSTREAM_IFACE); dispatchCommand(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); dispatchCommand(TetherInterfaceStateMachine.CMD_TETHER_UNREQUESTED); InOrder inOrder = inOrder(mNMService, mStatsService, mTetherHelper); inOrder.verify(mStatsService).forceUpdate(); inOrder.verify(mNMService).stopInterfaceForwarding(IFACE_NAME, UPSTREAM_IFACE); Loading @@ -224,7 +224,7 @@ public class TetherInterfaceSMTest { /** * Send a command to the state machine under test, and run the event loop to idle. * * @param command One of the TetherInterfaceSM.CMD_* constants. * @param command One of the TetherInterfaceStateMachine.CMD_* constants. */ private void dispatchCommand(int command) { mTestedSm.sendMessage(command); Loading @@ -238,7 +238,8 @@ public class TetherInterfaceSMTest { * @param upstreamIface String name of upstream interface (or null) */ private void dispatchTetherConnectionChanged(String upstreamIface) { mTestedSm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, upstreamIface); mTestedSm.sendMessage(TetherInterfaceStateMachine.CMD_TETHER_CONNECTION_CHANGED, upstreamIface); mLooper.dispatchAll(); } }