Rename TetherInterfaceSM to TetherInterfaceStateMachine
( cherry-pick of c5baad0250 )
Change-Id: I324690b20f37cef6d58872e21b126a87d16f7ec8
This commit is contained in:
committed by
Christopher Wiley
parent
9ad83ab607
commit
7040b4ebdf
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
@@ -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) {
|
||||
@@ -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) {
|
||||
@@ -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:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {}
|
||||
@@ -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) {}
|
||||
@@ -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) {}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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:
|
||||
@@ -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);
|
||||
@@ -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)) {
|
||||
@@ -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";
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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
|
||||
@@ -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());
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user