Skip to content
Snippets Groups Projects
Commit f1c04ca9 authored by Mark Chien's avatar Mark Chien Committed by Gerrit Code Review
Browse files

Merge "SyncSM11.1 make some functions inline" into main

parents 005fb887 2ca4b1d1
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
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);
}
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;
@Override
public void dhcpLeasesChanged() {
maybeDhcpLeasesChanged();
}
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 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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment