Loading services/core/java/com/android/server/connectivity/Tethering.java +8 −6 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ public class Tethering extends BaseNetworkObserver { private final VersionedBroadcastListener mCarrierConfigChange; // TODO: Delete SimChangeListener; it's obsolete. private final SimChangeListener mSimChange; private final TetheringDependencies mDeps; private volatile TetheringConfiguration mConfig; private String mCurrentUpstreamIface; Loading @@ -202,12 +203,13 @@ public class Tethering extends BaseNetworkObserver { mPolicyManager = policyManager; mLooper = looper; mSystemProperties = systemProperties; mDeps = deps; mPublicSync = new Object(); mTetherStates = new ArrayMap<>(); mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper); mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps); mTetherMasterSM.start(); final Handler smHandler = mTetherMasterSM.getHandler(); Loading @@ -215,8 +217,8 @@ public class Tethering extends BaseNetworkObserver { deps.getOffloadHardwareInterface(smHandler, mLog), mContext.getContentResolver(), mNMService, mLog); mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mContext, mTetherMasterSM, mLog, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mUpstreamNetworkMonitor = deps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mForwardedDownstreams = new HashSet<>(); IntentFilter filter = new IntentFilter(); Loading Loading @@ -1241,7 +1243,7 @@ public class Tethering extends BaseNetworkObserver { private static final int UPSTREAM_SETTLE_TIME_MS = 10000; TetherMasterSM(String name, Looper looper) { TetherMasterSM(String name, Looper looper, TetheringDependencies deps) { super(name, looper); mInitialState = new InitialState(); Loading @@ -1261,7 +1263,7 @@ public class Tethering extends BaseNetworkObserver { addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<>(); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog); mIPv6TetheringCoordinator = deps.getIPv6TetheringCoordinator(mNotifyList, mLog); mOffload = new OffloadWrapper(); setInitialState(mInitialState); Loading Loading @@ -1997,7 +1999,7 @@ public class Tethering extends BaseNetworkObserver { final TetherState tetherState = new TetherState( new TetherInterfaceStateMachine( iface, mLooper, interfaceType, mLog, mNMService, mStatsService, makeControlCallback(iface))); makeControlCallback(iface), mDeps)); mTetherStates.put(iface, tetherState); tetherState.stateMachine.start(); } Loading services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +8 −7 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public class TetherInterfaceStateMachine extends StateMachine { private final int mInterfaceType; private final LinkProperties mLinkProperties; private final TetheringDependencies mDeps; private int mLastError; private int mServingMode; private String mMyUpstreamIfaceName; // may change over time Loading @@ -134,18 +136,19 @@ public class TetherInterfaceStateMachine extends StateMachine { public TetherInterfaceStateMachine( String ifaceName, Looper looper, int interfaceType, SharedLog log, INetworkManagementService nMService, INetworkStatsService statsService, IControlsTethering tetherController) { IControlsTethering tetherController, TetheringDependencies deps) { super(ifaceName, looper); mLog = log.forSubComponent(ifaceName); mNMService = nMService; // TODO: This should be passed in for testability. mNetd = NetdService.getInstance(); mNetd = deps.getNetdService(); mStatsService = statsService; mTetherController = tetherController; mInterfaceCtrl = new InterfaceController(ifaceName, nMService, mNetd, mLog); mIfaceName = ifaceName; mInterfaceType = interfaceType; mLinkProperties = new LinkProperties(); mDeps = deps; resetLinkProperties(); mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; mServingMode = IControlsTethering.STATE_AVAILABLE; Loading Loading @@ -246,16 +249,14 @@ public class TetherInterfaceStateMachine extends StateMachine { } private boolean startIPv6() { // TODO: Refactor for better testability. This is one of the things // that prohibits unittesting IPv6 tethering setup. mInterfaceParams = InterfaceParams.getByName(mIfaceName); mInterfaceParams = mDeps.getInterfaceParams(mIfaceName); if (mInterfaceParams == null) { mLog.e("Failed to find InterfaceParams"); stopIPv6(); return false; } mRaDaemon = new RouterAdvertisementDaemon(mInterfaceParams); mRaDaemon = mDeps.getRouterAdvertisementDaemon(mInterfaceParams); if (!mRaDaemon.start()) { stopIPv6(); return false; Loading services/core/java/com/android/server/connectivity/tethering/TetheringDependencies.java +31 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,18 @@ package com.android.server.connectivity.tethering; import android.content.Context; import android.net.INetd; import android.net.ip.RouterAdvertisementDaemon; import android.net.util.InterfaceParams; import android.net.util.NetdService; import android.os.Handler; import android.net.util.SharedLog; import com.android.internal.util.StateMachine; import java.util.ArrayList; /** * Capture tethering dependencies, for injection. Loading @@ -29,4 +38,26 @@ public class TetheringDependencies { public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) { return new OffloadHardwareInterface(h, log); } public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx, StateMachine target, SharedLog log, int what) { return new UpstreamNetworkMonitor(ctx, target, log, what); } public IPv6TetheringCoordinator getIPv6TetheringCoordinator( ArrayList<TetherInterfaceStateMachine> notifyList, SharedLog log) { return new IPv6TetheringCoordinator(notifyList, log); } public RouterAdvertisementDaemon getRouterAdvertisementDaemon(InterfaceParams ifParams) { return new RouterAdvertisementDaemon(ifParams); } public InterfaceParams getInterfaceParams(String ifName) { return InterfaceParams.getByName(ifName); } public INetd getNetdService() { return NetdService.getInstance(); } } tests/net/java/com/android/server/connectivity/TetheringTest.java +234 −71 File changed.Preview size limit exceeded, changes collapsed. Show changes tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import static org.mockito.Mockito.when; import static android.net.ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; import static android.net.ConnectivityManager.TETHERING_BLUETOOTH; import static android.net.ConnectivityManager.TETHERING_USB; import static android.net.ConnectivityManager.TETHERING_WIFI; Loading @@ -39,7 +38,6 @@ import static com.android.server.connectivity.tethering.IControlsTethering.STATE import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE; import android.net.ConnectivityManager; import android.net.INetworkStatsService; import android.net.InterfaceConfiguration; import android.net.LinkAddress; Loading Loading @@ -75,6 +73,7 @@ public class TetherInterfaceStateMachineTest { @Mock private IControlsTethering mTetherHelper; @Mock private InterfaceConfiguration mInterfaceConfiguration; @Mock private SharedLog mSharedLog; @Mock private TetheringDependencies mTetheringDependencies; private final TestLooper mLooper = new TestLooper(); private final ArgumentCaptor<LinkProperties> mLinkPropertiesCaptor = Loading @@ -84,7 +83,7 @@ public class TetherInterfaceStateMachineTest { private void initStateMachine(int interfaceType) throws Exception { mTestedSm = new TetherInterfaceStateMachine( IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog, mNMService, mStatsService, mTetherHelper); mNMService, mStatsService, mTetherHelper, mTetheringDependencies); mTestedSm.start(); // Starting the state machine always puts us in a consistent state and notifies // the rest of the world that we've changed from an unknown to available state. Loading @@ -111,7 +110,8 @@ public class TetherInterfaceStateMachineTest { @Test public void startsOutAvailable() { mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper); TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper, mTetheringDependencies); mTestedSm.start(); mLooper.dispatchAll(); verify(mTetherHelper).updateInterfaceState( Loading Loading @@ -346,7 +346,7 @@ public class TetherInterfaceStateMachineTest { * Send a command to the state machine under test, and run the event loop to idle. * * @param command One of the TetherInterfaceStateMachine.CMD_* constants. * @param obj An additional argument to pass. * @param arg1 An additional argument to pass. */ private void dispatchCommand(int command, int arg1) { mTestedSm.sendMessage(command, arg1); Loading Loading
services/core/java/com/android/server/connectivity/Tethering.java +8 −6 Original line number Diff line number Diff line Loading @@ -181,6 +181,7 @@ public class Tethering extends BaseNetworkObserver { private final VersionedBroadcastListener mCarrierConfigChange; // TODO: Delete SimChangeListener; it's obsolete. private final SimChangeListener mSimChange; private final TetheringDependencies mDeps; private volatile TetheringConfiguration mConfig; private String mCurrentUpstreamIface; Loading @@ -202,12 +203,13 @@ public class Tethering extends BaseNetworkObserver { mPolicyManager = policyManager; mLooper = looper; mSystemProperties = systemProperties; mDeps = deps; mPublicSync = new Object(); mTetherStates = new ArrayMap<>(); mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper); mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper, deps); mTetherMasterSM.start(); final Handler smHandler = mTetherMasterSM.getHandler(); Loading @@ -215,8 +217,8 @@ public class Tethering extends BaseNetworkObserver { deps.getOffloadHardwareInterface(smHandler, mLog), mContext.getContentResolver(), mNMService, mLog); mUpstreamNetworkMonitor = new UpstreamNetworkMonitor( mContext, mTetherMasterSM, mLog, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mUpstreamNetworkMonitor = deps.getUpstreamNetworkMonitor(mContext, mTetherMasterSM, mLog, TetherMasterSM.EVENT_UPSTREAM_CALLBACK); mForwardedDownstreams = new HashSet<>(); IntentFilter filter = new IntentFilter(); Loading Loading @@ -1241,7 +1243,7 @@ public class Tethering extends BaseNetworkObserver { private static final int UPSTREAM_SETTLE_TIME_MS = 10000; TetherMasterSM(String name, Looper looper) { TetherMasterSM(String name, Looper looper, TetheringDependencies deps) { super(name, looper); mInitialState = new InitialState(); Loading @@ -1261,7 +1263,7 @@ public class Tethering extends BaseNetworkObserver { addState(mSetDnsForwardersErrorState); mNotifyList = new ArrayList<>(); mIPv6TetheringCoordinator = new IPv6TetheringCoordinator(mNotifyList, mLog); mIPv6TetheringCoordinator = deps.getIPv6TetheringCoordinator(mNotifyList, mLog); mOffload = new OffloadWrapper(); setInitialState(mInitialState); Loading Loading @@ -1997,7 +1999,7 @@ public class Tethering extends BaseNetworkObserver { final TetherState tetherState = new TetherState( new TetherInterfaceStateMachine( iface, mLooper, interfaceType, mLog, mNMService, mStatsService, makeControlCallback(iface))); makeControlCallback(iface), mDeps)); mTetherStates.put(iface, tetherState); tetherState.stateMachine.start(); } Loading
services/core/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachine.java +8 −7 Original line number Diff line number Diff line Loading @@ -117,6 +117,8 @@ public class TetherInterfaceStateMachine extends StateMachine { private final int mInterfaceType; private final LinkProperties mLinkProperties; private final TetheringDependencies mDeps; private int mLastError; private int mServingMode; private String mMyUpstreamIfaceName; // may change over time Loading @@ -134,18 +136,19 @@ public class TetherInterfaceStateMachine extends StateMachine { public TetherInterfaceStateMachine( String ifaceName, Looper looper, int interfaceType, SharedLog log, INetworkManagementService nMService, INetworkStatsService statsService, IControlsTethering tetherController) { IControlsTethering tetherController, TetheringDependencies deps) { super(ifaceName, looper); mLog = log.forSubComponent(ifaceName); mNMService = nMService; // TODO: This should be passed in for testability. mNetd = NetdService.getInstance(); mNetd = deps.getNetdService(); mStatsService = statsService; mTetherController = tetherController; mInterfaceCtrl = new InterfaceController(ifaceName, nMService, mNetd, mLog); mIfaceName = ifaceName; mInterfaceType = interfaceType; mLinkProperties = new LinkProperties(); mDeps = deps; resetLinkProperties(); mLastError = ConnectivityManager.TETHER_ERROR_NO_ERROR; mServingMode = IControlsTethering.STATE_AVAILABLE; Loading Loading @@ -246,16 +249,14 @@ public class TetherInterfaceStateMachine extends StateMachine { } private boolean startIPv6() { // TODO: Refactor for better testability. This is one of the things // that prohibits unittesting IPv6 tethering setup. mInterfaceParams = InterfaceParams.getByName(mIfaceName); mInterfaceParams = mDeps.getInterfaceParams(mIfaceName); if (mInterfaceParams == null) { mLog.e("Failed to find InterfaceParams"); stopIPv6(); return false; } mRaDaemon = new RouterAdvertisementDaemon(mInterfaceParams); mRaDaemon = mDeps.getRouterAdvertisementDaemon(mInterfaceParams); if (!mRaDaemon.start()) { stopIPv6(); return false; Loading
services/core/java/com/android/server/connectivity/tethering/TetheringDependencies.java +31 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,18 @@ package com.android.server.connectivity.tethering; import android.content.Context; import android.net.INetd; import android.net.ip.RouterAdvertisementDaemon; import android.net.util.InterfaceParams; import android.net.util.NetdService; import android.os.Handler; import android.net.util.SharedLog; import com.android.internal.util.StateMachine; import java.util.ArrayList; /** * Capture tethering dependencies, for injection. Loading @@ -29,4 +38,26 @@ public class TetheringDependencies { public OffloadHardwareInterface getOffloadHardwareInterface(Handler h, SharedLog log) { return new OffloadHardwareInterface(h, log); } public UpstreamNetworkMonitor getUpstreamNetworkMonitor(Context ctx, StateMachine target, SharedLog log, int what) { return new UpstreamNetworkMonitor(ctx, target, log, what); } public IPv6TetheringCoordinator getIPv6TetheringCoordinator( ArrayList<TetherInterfaceStateMachine> notifyList, SharedLog log) { return new IPv6TetheringCoordinator(notifyList, log); } public RouterAdvertisementDaemon getRouterAdvertisementDaemon(InterfaceParams ifParams) { return new RouterAdvertisementDaemon(ifParams); } public InterfaceParams getInterfaceParams(String ifName) { return InterfaceParams.getByName(ifName); } public INetd getNetdService() { return NetdService.getInstance(); } }
tests/net/java/com/android/server/connectivity/TetheringTest.java +234 −71 File changed.Preview size limit exceeded, changes collapsed. Show changes
tests/net/java/com/android/server/connectivity/tethering/TetherInterfaceStateMachineTest.java +5 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import static org.mockito.Mockito.when; import static android.net.ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_NO_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR; import static android.net.ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; import static android.net.ConnectivityManager.TETHERING_BLUETOOTH; import static android.net.ConnectivityManager.TETHERING_USB; import static android.net.ConnectivityManager.TETHERING_WIFI; Loading @@ -39,7 +38,6 @@ import static com.android.server.connectivity.tethering.IControlsTethering.STATE import static com.android.server.connectivity.tethering.IControlsTethering.STATE_TETHERED; import static com.android.server.connectivity.tethering.IControlsTethering.STATE_UNAVAILABLE; import android.net.ConnectivityManager; import android.net.INetworkStatsService; import android.net.InterfaceConfiguration; import android.net.LinkAddress; Loading Loading @@ -75,6 +73,7 @@ public class TetherInterfaceStateMachineTest { @Mock private IControlsTethering mTetherHelper; @Mock private InterfaceConfiguration mInterfaceConfiguration; @Mock private SharedLog mSharedLog; @Mock private TetheringDependencies mTetheringDependencies; private final TestLooper mLooper = new TestLooper(); private final ArgumentCaptor<LinkProperties> mLinkPropertiesCaptor = Loading @@ -84,7 +83,7 @@ public class TetherInterfaceStateMachineTest { private void initStateMachine(int interfaceType) throws Exception { mTestedSm = new TetherInterfaceStateMachine( IFACE_NAME, mLooper.getLooper(), interfaceType, mSharedLog, mNMService, mStatsService, mTetherHelper); mNMService, mStatsService, mTetherHelper, mTetheringDependencies); mTestedSm.start(); // Starting the state machine always puts us in a consistent state and notifies // the rest of the world that we've changed from an unknown to available state. Loading @@ -111,7 +110,8 @@ public class TetherInterfaceStateMachineTest { @Test public void startsOutAvailable() { mTestedSm = new TetherInterfaceStateMachine(IFACE_NAME, mLooper.getLooper(), TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper); TETHERING_BLUETOOTH, mSharedLog, mNMService, mStatsService, mTetherHelper, mTetheringDependencies); mTestedSm.start(); mLooper.dispatchAll(); verify(mTetherHelper).updateInterfaceState( Loading Loading @@ -346,7 +346,7 @@ public class TetherInterfaceStateMachineTest { * Send a command to the state machine under test, and run the event loop to idle. * * @param command One of the TetherInterfaceStateMachine.CMD_* constants. * @param obj An additional argument to pass. * @param arg1 An additional argument to pass. */ private void dispatchCommand(int command, int arg1) { mTestedSm.sendMessage(command, arg1); Loading