From 2d36831a38b829910b20c46bdf059c686d3c075e Mon Sep 17 00:00:00 2001 From: Mark Chien Date: Mon, 24 May 2021 03:00:20 +0000 Subject: [PATCH] Disable tryCell when UpstreamMonitor stop tryCell configuration would not be force disabled UpstreamMonitor stop. If tethering stop with using mobile upstream and swap with SIM fron no dun to dun supported, dun request would be filed even tethering is not active. Bug: 173068192 Test: atest TetheringTests Original-Change: https://android-review.googlesource.com/1715791 Merged-In: I5505655f52da9fdca2fd43a58e043a9ab727741d Change-Id: I5505655f52da9fdca2fd43a58e043a9ab727741d --- .../tethering/UpstreamNetworkMonitor.java | 2 +- .../networkstack/tethering/TetheringTest.java | 30 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Tethering/src/com/android/networkstack/tethering/UpstreamNetworkMonitor.java b/Tethering/src/com/android/networkstack/tethering/UpstreamNetworkMonitor.java index 485eec8400..69471a1516 100644 --- a/Tethering/src/com/android/networkstack/tethering/UpstreamNetworkMonitor.java +++ b/Tethering/src/com/android/networkstack/tethering/UpstreamNetworkMonitor.java @@ -191,7 +191,7 @@ public class UpstreamNetworkMonitor { * check even tethering is not active yet. */ public void stop() { - releaseMobileNetworkRequest(); + setTryCell(false); releaseCallback(mListenAllCallback); mListenAllCallback = null; diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java index c636384807..83f13228d4 100644 --- a/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java +++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/TetheringTest.java @@ -402,11 +402,6 @@ public class TetheringTest { StateMachine mUpstreamNetworkMonitorSM; ArrayList mIpv6CoordinatorNotifyList; - public void reset() { - mUpstreamNetworkMonitorSM = null; - mIpv6CoordinatorNotifyList = null; - } - @Override public BpfCoordinator getBpfCoordinator( BpfCoordinator.Dependencies deps) { @@ -689,7 +684,6 @@ public class TetheringTest { } private Tethering makeTethering() { - mTetheringDependencies.reset(); return new Tethering(mTetheringDependencies); } @@ -1095,6 +1089,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. @@ -1118,6 +1117,7 @@ public class TetheringTest { wifi.fakeConnect(); mCm.makeDefaultNetwork(wifi, BROADCAST_FIRST); mLooper.dispatchAll(); + inOrder.verify(mUpstreamNetworkMonitor).setTryCell(false); inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(wifi.networkId); } @@ -1140,6 +1140,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); @@ -1148,6 +1149,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); @@ -1166,6 +1168,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()); @@ -1183,6 +1186,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()); @@ -1198,6 +1202,8 @@ public class TetheringTest { mobile.fakeDisconnect(); mobile.sendLinkProperties(); mLooper.dispatchAll(); + + verifyDisableTryCellWhenTetheringStop(inOrder); } @Test @@ -1220,6 +1226,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 @@ -1235,6 +1245,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 captor = ArgumentCaptor.forClass(NetworkCallback.class); inOrder.verify(mCm).requestNetwork(any(), eq(0), eq(TYPE_MOBILE_DUN), any(), any()); inOrder.verify(mUpstreamNetworkMonitor).setCurrentUpstream(null); @@ -1246,11 +1257,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 @@ -1266,6 +1280,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. @@ -1287,8 +1302,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,