Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79e7fde0 authored by Christopher Wiley's avatar Christopher Wiley
Browse files

Remove transient StartingState from TetherInterfaceSM

This state immediately switched into the TetheredState.
We can safely remove it at only the expense of a misleading state
broadcast.

Bug: 28798823
Test: runtest frameworks-services -c
    com.android.server.connectivity.tethering.TetherInterfaceSMTest

Change-Id: I295d830dbdb11717d6e05161d97787ffe871beb3
parent 1b3830a2
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -90,9 +90,8 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
 * @hide
 *
 * Timeout
 *
 * TODO - look for parent classes and code sharing
 * This class holds much of the business logic to allow Android devices
 * to act as IP gateways via USB, BT, and WiFi interfaces.
 */
public class Tethering extends BaseNetworkObserver implements IControlsTethering {

+2 −51
Original line number Diff line number Diff line
@@ -80,7 +80,6 @@ public class TetherInterfaceSM extends StateMachine {
    public static final int CMD_TETHER_CONNECTION_CHANGED   = BASE_IFACE + 12;

    private final State mInitialState;
    private final State mStartingState;
    private final State mTetheredState;
    private final State mUnavailableState;

@@ -111,8 +110,6 @@ public class TetherInterfaceSM extends StateMachine {

        mInitialState = new InitialState();
        addState(mInitialState);
        mStartingState = new StartingState();
        addState(mStartingState);
        mTetheredState = new TetheredState();
        addState(mTetheredState);
        mUnavailableState = new UnavailableState();
@@ -127,7 +124,6 @@ public class TetherInterfaceSM extends StateMachine {
        res += mIfaceName + " - ";
        IState current = getCurrentState();
        if (current == mInitialState) res += "InitialState";
        if (current == mStartingState) res += "StartingState";
        if (current == mTetheredState) res += "TetheredState";
        if (current == mUnavailableState) res += "UnavailableState";
        if (isAvailable()) res += " - Available";
@@ -235,7 +231,7 @@ public class TetherInterfaceSM extends StateMachine {
                case CMD_TETHER_REQUESTED:
                    setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
                    mTetherController.notifyInterfaceTetheringReadiness(true, TetherInterfaceSM.this);
                    transitionTo(mStartingState);
                    transitionTo(mTetheredState);
                    break;
                case CMD_INTERFACE_DOWN:
                    transitionTo(mUnavailableState);
@@ -248,7 +244,7 @@ public class TetherInterfaceSM extends StateMachine {
        }
    }

    class StartingState extends State {
    class TetheredState extends State {
        @Override
        public void enter() {
            setAvailable(false);
@@ -261,51 +257,7 @@ public class TetherInterfaceSM extends StateMachine {
                    return;
                }
            }
            mTetherController.sendTetherStateChangedBroadcast();

            // Skipping StartingState
            transitionTo(mTetheredState);
        }
        @Override
        public boolean processMessage(Message message) {
            maybeLogMessage(this, message.what);
            boolean retValue = true;
            switch (message.what) {
                // maybe a parent class?
                case CMD_TETHER_UNREQUESTED:
                    mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this);
                    if (mUsb) {
                        if (!configureUsbIface(false, mIfaceName)) {
                            setLastErrorAndTransitionToInitialState(
                                ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
                            break;
                        }
                    }
                    transitionTo(mInitialState);
                    break;
                case CMD_CELL_DUN_ERROR:
                case CMD_IP_FORWARDING_ENABLE_ERROR:
                case CMD_IP_FORWARDING_DISABLE_ERROR:
                case CMD_START_TETHERING_ERROR:
                case CMD_STOP_TETHERING_ERROR:
                case CMD_SET_DNS_FORWARDERS_ERROR:
                    setLastErrorAndTransitionToInitialState(
                            ConnectivityManager.TETHER_ERROR_MASTER_ERROR);
                    break;
                case CMD_INTERFACE_DOWN:
                    mTetherController.notifyInterfaceTetheringReadiness(false, TetherInterfaceSM.this);
                    transitionTo(mUnavailableState);
                    break;
                default:
                    retValue = false;
            }
            return retValue;
        }
    }

    class TetheredState extends State {
        @Override
        public void enter() {
            try {
                mNMService.tetherInterface(mIfaceName);
            } catch (Exception e) {
@@ -321,7 +273,6 @@ public class TetherInterfaceSM extends StateMachine {
                return;
            }
            if (DBG) Log.d(TAG, "Tethered " + mIfaceName);
            setAvailable(false);
            setTethered(true);
            mTetherController.sendTetherStateChangedBroadcast();
        }
+0 −8
Original line number Diff line number Diff line
@@ -129,10 +129,6 @@ public class TetherInterfaceSMTest {
        dispatchCommand(TetherInterfaceSM.CMD_TETHER_REQUESTED);
        InOrder inOrder = inOrder(mTetherHelper, mNMService);
        inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm);
        // TODO: This broadcast should be removed.  When we send this, we are neither
        //       available nor tethered, which is misleading, since we're transitioning
        //       from one to the other.
        inOrder.verify(mTetherHelper).sendTetherStateChangedBroadcast();
        inOrder.verify(mNMService).tetherInterface(IFACE_NAME);
        inOrder.verify(mTetherHelper).sendTetherStateChangedBroadcast();

@@ -168,10 +164,6 @@ public class TetherInterfaceSMTest {
        inOrder.verify(mTetherHelper).notifyInterfaceTetheringReadiness(true, mTestedSm);
        inOrder.verify(mNMService).getInterfaceConfig(IFACE_NAME);
        inOrder.verify(mNMService).setInterfaceConfig(IFACE_NAME, mInterfaceConfiguration);
        // TODO: This broadcast should be removed.  When we send this, we are neither
        //       available nor tethered, which is misleading, since we're transitioning
        //       from one to the other.
        inOrder.verify(mTetherHelper).sendTetherStateChangedBroadcast();
        inOrder.verify(mNMService).tetherInterface(IFACE_NAME);
        inOrder.verify(mTetherHelper).sendTetherStateChangedBroadcast();