Merge "Disable tryCell when UpstreamMonitor stop" into sc-dev

This commit is contained in:
Mark Chien 2021-06-22 07:34:35 +00:00 committed by Android (Google) Code Review
commit 07584931b5
2 changed files with 25 additions and 7 deletions

View File

@ -191,7 +191,7 @@ public class UpstreamNetworkMonitor {
* check even tethering is not active yet.
*/
public void stop() {
releaseMobileNetworkRequest();
setTryCell(false);
releaseCallback(mListenAllCallback);
mListenAllCallback = null;

View File

@ -389,11 +389,6 @@ public class TetheringTest {
StateMachine mUpstreamNetworkMonitorSM;
ArrayList<IpServer> mIpv6CoordinatorNotifyList;
public void reset() {
mUpstreamNetworkMonitorSM = null;
mIpv6CoordinatorNotifyList = null;
}
@Override
public BpfCoordinator getBpfCoordinator(
BpfCoordinator.Dependencies deps) {
@ -673,7 +668,6 @@ public class TetheringTest {
}
private Tethering makeTethering() {
mTetheringDependencies.reset();
return new Tethering(mTetheringDependencies);
}
@ -1105,6 +1099,11 @@ public class TetheringTest {
verify(mUpstreamNetworkMonitor, times(1)).setCurrentUpstream(upstreamState.network);
}
private void verifyDisableTryCellWhenTetheringStop(InOrder inOrder) {
runStopUSBTethering();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
}
private void upstreamSelectionTestCommon(final boolean automatic, InOrder inOrder,
TestNetworkAgent mobile, TestNetworkAgent wifi) throws Exception {
// Enable automatic upstream selection.
@ -1128,6 +1127,7 @@ public class TetheringTest {
wifi.fakeConnect();
mCm.makeDefaultNetwork(wifi, BROADCAST_FIRST);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId);
}
@ -1150,6 +1150,7 @@ public class TetheringTest {
mCm.makeDefaultNetwork(wifi, BROADCAST_FIRST, doDispatchAll);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId);
mCm.makeDefaultNetwork(mobile, CALLBACKS_FIRST);
@ -1158,6 +1159,7 @@ public class TetheringTest {
mCm.makeDefaultNetwork(wifi, CALLBACKS_FIRST);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId);
mCm.makeDefaultNetwork(mobile, CALLBACKS_FIRST, doDispatchAll);
@ -1176,6 +1178,7 @@ public class TetheringTest {
mLooper.dispatchAll();
mobile.fakeDisconnect();
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(true);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(null);
mobile = new TestNetworkAgent(mCm, buildMobile464xlatUpstreamState());
@ -1193,6 +1196,7 @@ public class TetheringTest {
mCm.makeDefaultNetwork(null, CALLBACKS_FIRST, doDispatchAll);
mobile.fakeDisconnect();
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(true);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(null);
mobile = new TestNetworkAgent(mCm, buildMobileDualStackUpstreamState());
@ -1208,6 +1212,8 @@ public class TetheringTest {
mobile.fakeDisconnect();
mobile.sendLinkProperties();
mLooper.dispatchAll();
verifyDisableTryCellWhenTetheringStop(inOrder);
}
@Test
@ -1230,6 +1236,10 @@ public class TetheringTest {
mLooper.dispatchAll();
mCm.makeDefaultNetwork(wifi, CALLBACKS_FIRST, null);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId);
verifyDisableTryCellWhenTetheringStop(inOrder);
}
@Test
@ -1245,6 +1255,7 @@ public class TetheringTest {
// automatic mode would request dun again and choose it as upstream.
mCm.makeDefaultNetwork(mobile, CALLBACKS_FIRST);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(true);
ArgumentCaptor<NetworkCallback> captor = ArgumentCaptor.forClass(NetworkCallback.class);
inOrder.verify(mCm).requestNetwork(any(), eq(0), eq(TYPE_MOBILE_DUN), any(), any());
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(null);
@ -1256,11 +1267,14 @@ public class TetheringTest {
// Lose and regain upstream again.
dun.fakeDisconnect(CALLBACKS_FIRST, doDispatchAll);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(true);
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(null);
inOrder.verify(mCm, never()).unregisterNetworkCallback(any(NetworkCallback.class));
dun.fakeConnect(CALLBACKS_FIRST, doDispatchAll);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(dun.networkId);
verifyDisableTryCellWhenTetheringStop(inOrder);
}
@Test
@ -1276,6 +1290,7 @@ public class TetheringTest {
// list).
mCm.makeDefaultNetwork(mobile, CALLBACKS_FIRST);
mLooper.dispatchAll();
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mUpstreamNetworkMonitor, never()).setCurrentUpstream(any());
// BUG: when wifi disconnect, the dun request would not be filed again because wifi is
// no longer be default network which do not have CONNECTIVIY_ACTION broadcast.
@ -1297,8 +1312,11 @@ public class TetheringTest {
mLooper.dispatchAll();
// BUG: dun has higher priority than wifi but tethering don't file dun request because
// current upstream is wifi.
inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false);
inOrder.verify(mCm, never()).requestNetwork(any(), eq(0), eq(TYPE_MOBILE_DUN), any(),
any());
verifyDisableTryCellWhenTetheringStop(inOrder);
}
private void chooseDunUpstreamTestCommon(final boolean automatic, InOrder inOrder,