diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index 32773635a4..da3b584fb9 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -2734,84 +2734,73 @@ public class Tethering { } } - private IpServer.Callback makeControlCallback() { - return new IpServer.Callback() { - @Override - public void updateInterfaceState(IpServer who, int state, int lastError) { - notifyInterfaceStateChange(who, state, lastError); + private class ControlCallback extends IpServer.Callback { + @Override + public void updateInterfaceState(IpServer who, int state, int lastError) { + final String iface = who.interfaceName(); + final TetherState tetherState = mTetherStates.get(iface); + if (tetherState != null && tetherState.ipServer.equals(who)) { + tetherState.lastState = state; + tetherState.lastError = lastError; + } else { + if (DBG) Log.d(TAG, "got notification from stale iface " + iface); } - @Override - public void updateLinkProperties(IpServer who, LinkProperties newLp) { - notifyLinkPropertiesChanged(who, newLp); - } + mLog.log(String.format("OBSERVED iface=%s state=%s error=%s", iface, state, lastError)); - @Override - public void dhcpLeasesChanged() { - maybeDhcpLeasesChanged(); + // If TetherMainSM is in ErrorState, TetherMainSM stays there. + // Thus we give a chance for TetherMainSM to recover to InitialState + // by sending CMD_CLEAR_ERROR + if (lastError == TETHER_ERROR_INTERNAL_ERROR) { + mTetherMainSM.sendMessage(TetherMainSM.CMD_CLEAR_ERROR, who); } - - @Override - public void requestEnableTethering(int tetheringType, boolean enabled) { - mTetherMainSM.sendMessage(TetherMainSM.EVENT_REQUEST_CHANGE_DOWNSTREAM, - tetheringType, 0, enabled ? Boolean.TRUE : Boolean.FALSE); + int which; + switch (state) { + case IpServer.STATE_UNAVAILABLE: + case IpServer.STATE_AVAILABLE: + which = TetherMainSM.EVENT_IFACE_SERVING_STATE_INACTIVE; + break; + case IpServer.STATE_TETHERED: + case IpServer.STATE_LOCAL_ONLY: + which = TetherMainSM.EVENT_IFACE_SERVING_STATE_ACTIVE; + break; + default: + Log.wtf(TAG, "Unknown interface state: " + state); + return; } - }; - } - - // TODO: Move into TetherMainSM. - private void notifyInterfaceStateChange(IpServer who, int state, int error) { - final String iface = who.interfaceName(); - final TetherState tetherState = mTetherStates.get(iface); - if (tetherState != null && tetherState.ipServer.equals(who)) { - tetherState.lastState = state; - tetherState.lastError = error; - } else { - if (DBG) Log.d(TAG, "got notification from stale iface " + iface); + mTetherMainSM.sendMessage(which, state, 0, who); + sendTetherStateChangedBroadcast(); } - mLog.log(String.format("OBSERVED iface=%s state=%s error=%s", iface, state, error)); - - // If TetherMainSM is in ErrorState, TetherMainSM stays there. - // Thus we give a chance for TetherMainSM to recover to InitialState - // by sending CMD_CLEAR_ERROR - if (error == TETHER_ERROR_INTERNAL_ERROR) { - mTetherMainSM.sendMessage(TetherMainSM.CMD_CLEAR_ERROR, who); - } - int which; - switch (state) { - case IpServer.STATE_UNAVAILABLE: - case IpServer.STATE_AVAILABLE: - which = TetherMainSM.EVENT_IFACE_SERVING_STATE_INACTIVE; - break; - case IpServer.STATE_TETHERED: - case IpServer.STATE_LOCAL_ONLY: - which = TetherMainSM.EVENT_IFACE_SERVING_STATE_ACTIVE; - break; - default: - Log.wtf(TAG, "Unknown interface state: " + state); + @Override + public void updateLinkProperties(IpServer who, LinkProperties newLp) { + final String iface = who.interfaceName(); + final int state; + final TetherState tetherState = mTetherStates.get(iface); + if (tetherState != null && tetherState.ipServer.equals(who)) { + state = tetherState.lastState; + } else { + mLog.log("got notification from stale iface " + iface); return; - } - mTetherMainSM.sendMessage(which, state, 0, who); - sendTetherStateChangedBroadcast(); - } + } - private void notifyLinkPropertiesChanged(IpServer who, LinkProperties newLp) { - final String iface = who.interfaceName(); - final int state; - final TetherState tetherState = mTetherStates.get(iface); - if (tetherState != null && tetherState.ipServer.equals(who)) { - state = tetherState.lastState; - } else { - mLog.log("got notification from stale iface " + iface); - return; + mLog.log(String.format( + "OBSERVED LinkProperties update iface=%s state=%s lp=%s", + iface, IpServer.getStateString(state), newLp)); + final int which = TetherMainSM.EVENT_IFACE_UPDATE_LINKPROPERTIES; + mTetherMainSM.sendMessage(which, state, 0, newLp); } - mLog.log(String.format( - "OBSERVED LinkProperties update iface=%s state=%s lp=%s", - iface, IpServer.getStateString(state), newLp)); - final int which = TetherMainSM.EVENT_IFACE_UPDATE_LINKPROPERTIES; - mTetherMainSM.sendMessage(which, state, 0, newLp); + @Override + public void dhcpLeasesChanged() { + maybeDhcpLeasesChanged(); + } + + @Override + public void requestEnableTethering(int tetheringType, boolean enabled) { + mTetherMainSM.sendMessage(TetherMainSM.EVENT_REQUEST_CHANGE_DOWNSTREAM, + tetheringType, 0, enabled ? Boolean.TRUE : Boolean.FALSE); + } } private boolean hasSystemFeature(final String feature) { @@ -2853,7 +2842,7 @@ public class Tethering { mLog.i("adding IpServer for: " + iface); final TetherState tetherState = new TetherState( new IpServer(iface, mHandler, interfaceType, mLog, mNetd, mBpfCoordinator, - mRoutingCoordinator, makeControlCallback(), mConfig, + mRoutingCoordinator, new ControlCallback(), mConfig, mPrivateAddressCoordinator, mTetheringMetrics, mDeps.getIpServerDependencies()), isNcm); mTetherStates.put(iface, tetherState);