Merge "Change throw to Log.wtf" into main

This commit is contained in:
Remi NGUYEN VAN 2023-12-28 01:40:10 +00:00 • committed by Gerrit Code Review
commit ab2fd4cac9
2 changed files with 14 additions and 4 deletions

View file

@ -171,7 +171,8 @@ public class RoutingCoordinatorService extends IRoutingCoordinator.Stub {
}
final ForwardingPair fwp = new ForwardingPair(fromIface, toIface);
if (mForwardedInterfaces.contains(fwp)) {
throw new IllegalStateException("Forward already exists between ifaces "
// TODO: remove if no reports are observed from the below log
Log.wtf(TAG, "Forward already exists between ifaces "
+ fromIface + " → " + toIface);
}
mForwardedInterfaces.add(fwp);

View file

@ -18,14 +18,17 @@ package com.android.server.connectivity
import android.net.INetd
import android.os.Build
import android.util.Log
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
import com.android.testutils.DevSdkIgnoreRunner
import com.android.testutils.tryTest
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.mock
import kotlin.test.assertFailsWith
@RunWith(DevSdkIgnoreRunner::class)
@IgnoreUpTo(Build.VERSION_CODES.TIRAMISU)
@ -46,9 +49,15 @@ class RoutingCoordinatorServiceTest {
inOrder.verify(mNetd).tetherAddForward("from2", "to1")
inOrder.verify(mNetd).ipfwdAddInterfaceForward("from2", "to1")
assertFailsWith<IllegalStateException> {
// Can't add the same pair again
val hasFailed = AtomicBoolean(false)
val prevHandler = Log.setWtfHandler { tag, what, system ->
hasFailed.set(true)
}
tryTest {
mService.addInterfaceForward("from2", "to1")
assertTrue(hasFailed.get())
} cleanup {
Log.setWtfHandler(prevHandler)
}
mService.removeInterfaceForward("from1", "to1")