Merge changes Ibe22b300,I0b0f0bf1 into main

* changes:
  SyncSM08: handle IpServer requestEnableTethering callback in mainSM
  SyncSM07.1: Add a test that shows tethering restarts when disabling
This commit is contained in:
Mark Chien
2023-10-27 08:50:04 +00:00
committed by Gerrit Code Review
2 changed files with 22 additions and 4 deletions

View File

@@ -1687,6 +1687,8 @@ public class Tethering {
static final int EVENT_IFACE_UPDATE_LINKPROPERTIES = BASE_MAIN_SM + 7;
// Events from EntitlementManager to choose upstream again.
static final int EVENT_UPSTREAM_PERMISSION_CHANGED = BASE_MAIN_SM + 8;
// Internal request from IpServer to enable or disable downstream.
static final int EVENT_REQUEST_CHANGE_DOWNSTREAM = BASE_MAIN_SM + 9;
private final State mInitialState;
private final State mTetherModeAliveState;
@@ -2186,6 +2188,12 @@ public class Tethering {
}
break;
}
case EVENT_REQUEST_CHANGE_DOWNSTREAM: {
final int tetheringType = message.arg1;
final Boolean enabled = (Boolean) message.obj;
enableTetheringInternal(tetheringType, enabled, null);
break;
}
default:
retValue = false;
break;
@@ -2743,7 +2751,8 @@ public class Tethering {
@Override
public void requestEnableTethering(int tetheringType, boolean enabled) {
enableTetheringInternal(tetheringType, enabled, null);
mTetherMainSM.sendMessage(TetherMainSM.EVENT_REQUEST_CHANGE_DOWNSTREAM,
tetheringType, 0, enabled ? Boolean.TRUE : Boolean.FALSE);
}
};
}

View File

@@ -2880,24 +2880,33 @@ public class TetheringTest {
final Network wifiNetwork = new Network(200);
final Network[] allNetworks = { wifiNetwork };
doReturn(allNetworks).when(mCm).getAllNetworks();
InOrder inOrder = inOrder(mUsbManager, mNetd);
runUsbTethering(null);
inOrder.verify(mNetd).tetherInterfaceAdd(TEST_RNDIS_IFNAME);
final ArgumentCaptor<InterfaceConfigurationParcel> ifaceConfigCaptor =
ArgumentCaptor.forClass(InterfaceConfigurationParcel.class);
verify(mNetd).interfaceSetCfg(ifaceConfigCaptor.capture());
final String ipv4Address = ifaceConfigCaptor.getValue().ipv4Addr;
verify(mDhcpServer, timeout(DHCPSERVER_START_TIMEOUT_MS).times(1)).startWithCallbacks(
any(), any());
reset(mUsbManager);
// Cause a prefix conflict by assigning a /30 out of the downstream's /24 to the upstream.
updateV4Upstream(new LinkAddress(InetAddresses.parseNumericAddress(ipv4Address), 30),
wifiNetwork, TEST_WIFI_IFNAME, TRANSPORT_WIFI);
// verify turn off usb tethering
verify(mUsbManager).setCurrentFunctions(UsbManager.FUNCTION_NONE);
inOrder.verify(mUsbManager).setCurrentFunctions(UsbManager.FUNCTION_NONE);
sendUsbBroadcast(true, true, -1 /* function */);
mLooper.dispatchAll();
inOrder.verify(mNetd).tetherInterfaceRemove(TEST_RNDIS_IFNAME);
// verify restart usb tethering
verify(mUsbManager).setCurrentFunctions(UsbManager.FUNCTION_RNDIS);
inOrder.verify(mUsbManager).setCurrentFunctions(UsbManager.FUNCTION_RNDIS);
sendUsbBroadcast(true, true, TETHER_USB_RNDIS_FUNCTION);
mLooper.dispatchAll();
inOrder.verify(mNetd).tetherInterfaceAdd(TEST_RNDIS_IFNAME);
}
@Test