Merge "TetheringTest: test upstream changes capabilities" am: 79adbb234e

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2419000

Change-Id: I7c7cd0da78384b74939af018cabc82baa65865ac
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Nucca Chen 2023-02-14 02:02:35 +00:00 • committed by Automerger Merge Worker
commit 7a647a0f29

View file

@ -29,6 +29,7 @@ import static android.net.ConnectivityManager.TYPE_MOBILE_DUN;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
@ -2688,7 +2689,7 @@ public class TetheringTest {
inOrder.verify(mNotificationUpdater)
.onUpstreamCapabilitiesChanged(upstreamState.networkCapabilities);
// Set the upstream with the same network ID but different object.
// Set the upstream with the same network ID but different object and the same capability.
final UpstreamNetworkState upstreamState2 = buildMobileIPv4UpstreamState();
initTetheringUpstream(upstreamState2);
stateMachine.chooseUpstreamType(true);
@ -2697,6 +2698,17 @@ public class TetheringTest {
inOrder.verify(mNotificationUpdater)
.onUpstreamCapabilitiesChanged(upstreamState2.networkCapabilities);
// Set the upstream with the same network ID but different object and different capability.
final UpstreamNetworkState upstreamState3 = buildMobileIPv4UpstreamState();
assertFalse(upstreamState3.networkCapabilities.hasCapability(NET_CAPABILITY_VALIDATED));
upstreamState3.networkCapabilities.addCapability(NET_CAPABILITY_VALIDATED);
initTetheringUpstream(upstreamState3);
stateMachine.chooseUpstreamType(true);
// Bug: duplicated upstream change event.
mTetheringEventCallback.expectUpstreamChanged(upstreamState3.network);
inOrder.verify(mNotificationUpdater)
.onUpstreamCapabilitiesChanged(upstreamState3.networkCapabilities);
// Lose upstream.
initTetheringUpstream(null);
stateMachine.chooseUpstreamType(true);
@ -2720,6 +2732,15 @@ public class TetheringTest {
inOrder.verify(mNotificationUpdater)
.onUpstreamCapabilitiesChanged(upstreamState.networkCapabilities);
// Verify that onUpstreamCapabilitiesChanged is called if current upstream network
// capabilities changed.
// Expect that capability is changed with new capability VALIDATED.
assertFalse(upstreamState.networkCapabilities.hasCapability(NET_CAPABILITY_VALIDATED));
upstreamState.networkCapabilities.addCapability(NET_CAPABILITY_VALIDATED);
stateMachine.handleUpstreamNetworkMonitorCallback(EVENT_ON_CAPABILITIES, upstreamState);
inOrder.verify(mNotificationUpdater)
.onUpstreamCapabilitiesChanged(upstreamState.networkCapabilities);
// Verify that onUpstreamCapabilitiesChanged won't be called if not current upstream network
// capabilities changed.
final UpstreamNetworkState upstreamState2 = new UpstreamNetworkState(