BpfCoordinator: ignore stopping event monitoring if never started
Ignore stopping monitoring if the monitor has never started
for a given IpServer.
Also fix the related bug in
BpfCoordinator#testStartStopConntrackMonitoring.
Bug: 250552545
Test: atest BpfCoordinatorTest
Change-Id: I7ac71f0ed52bf52244aadaa3c90ca8df239873e4
diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
index 142a0b9..74ba209 100644
--- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
+++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
@@ -536,6 +536,13 @@
// TODO: Wrap conntrackMonitor stopping function into mBpfCoordinatorShim.
if (!isUsingBpf() || !mDeps.isAtLeastS()) return;
+ // Ignore stopping monitoring if the monitor has never started for a given IpServer.
+ if (!mMonitoringIpServers.contains(ipServer)) {
+ mLog.e("Ignore stopping monitoring because monitoring has never started for "
+ + ipServer.interfaceName());
+ return;
+ }
+
mMonitoringIpServers.remove(ipServer);
if (!mMonitoringIpServers.isEmpty()) return;
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
index 758b533..ac92b43 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
@@ -1413,7 +1413,7 @@
// [1] Don't stop monitoring if it has never started.
coordinator.stopMonitoring(mIpServer);
- verify(mConntrackMonitor, never()).start();
+ verify(mConntrackMonitor, never()).stop();
// [2] Start monitoring.
coordinator.startMonitoring(mIpServer);