Merge "Rename UnderlyingNetworkTracker to UnderlyingNetworkController"

This commit is contained in:
Yan Yan
2021-11-24 18:39:29 +00:00
committed by Gerrit Code Review
10 changed files with 105 additions and 101 deletions

View File

@@ -141,7 +141,7 @@ import java.util.concurrent.TimeUnit;
* | or its properties * | or its properties
* v | * v |
* +-----------------------------------------------------------------------+ * +-----------------------------------------------------------------------+
* | UnderlyingNetworkTracker | * | UnderlyingNetworkController |
* | | * | |
* | Manages lifecycle of underlying physical networks, filing requests to | * | Manages lifecycle of underlying physical networks, filing requests to |
* | bring them up, and releasing them as they become no longer necessary | * | bring them up, and releasing them as they become no longer necessary |

View File

@@ -87,9 +87,10 @@ import com.android.internal.util.State;
import com.android.internal.util.StateMachine; import com.android.internal.util.StateMachine;
import com.android.internal.util.WakeupMessage; import com.android.internal.util.WakeupMessage;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot; import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkRecord;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkTrackerCallback;
import com.android.server.vcn.Vcn.VcnGatewayStatusCallback; import com.android.server.vcn.Vcn.VcnGatewayStatusCallback;
import com.android.server.vcn.routeselection.UnderlyingNetworkController;
import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkControllerCallback;
import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkRecord;
import com.android.server.vcn.util.LogUtils; import com.android.server.vcn.util.LogUtils;
import com.android.server.vcn.util.MtuUtils; import com.android.server.vcn.util.MtuUtils;
import com.android.server.vcn.util.OneWayBoolean; import com.android.server.vcn.util.OneWayBoolean;
@@ -201,7 +202,7 @@ public class VcnGatewayConnection extends StateMachine {
private interface EventInfo {} private interface EventInfo {}
/** /**
* Sent when there are changes to the underlying network (per the UnderlyingNetworkTracker). * Sent when there are changes to the underlying network (per the UnderlyingNetworkController).
* *
* <p>May indicate an entirely new underlying network, OR a change in network properties. * <p>May indicate an entirely new underlying network, OR a change in network properties.
* *
@@ -522,11 +523,14 @@ public class VcnGatewayConnection extends StateMachine {
@NonNull private final VcnContext mVcnContext; @NonNull private final VcnContext mVcnContext;
@NonNull private final ParcelUuid mSubscriptionGroup; @NonNull private final ParcelUuid mSubscriptionGroup;
@NonNull private final UnderlyingNetworkTracker mUnderlyingNetworkTracker; @NonNull private final UnderlyingNetworkController mUnderlyingNetworkController;
@NonNull private final VcnGatewayConnectionConfig mConnectionConfig; @NonNull private final VcnGatewayConnectionConfig mConnectionConfig;
@NonNull private final VcnGatewayStatusCallback mGatewayStatusCallback; @NonNull private final VcnGatewayStatusCallback mGatewayStatusCallback;
@NonNull private final Dependencies mDeps; @NonNull private final Dependencies mDeps;
@NonNull private final VcnUnderlyingNetworkTrackerCallback mUnderlyingNetworkTrackerCallback;
@NonNull
private final VcnUnderlyingNetworkControllerCallback mUnderlyingNetworkControllerCallback;
private final boolean mIsMobileDataEnabled; private final boolean mIsMobileDataEnabled;
@NonNull private final IpSecManager mIpSecManager; @NonNull private final IpSecManager mIpSecManager;
@@ -674,17 +678,17 @@ public class VcnGatewayConnection extends StateMachine {
mLastSnapshot = Objects.requireNonNull(snapshot, "Missing snapshot"); mLastSnapshot = Objects.requireNonNull(snapshot, "Missing snapshot");
mUnderlyingNetworkTrackerCallback = new VcnUnderlyingNetworkTrackerCallback(); mUnderlyingNetworkControllerCallback = new VcnUnderlyingNetworkControllerCallback();
mWakeLock = mWakeLock =
mDeps.newWakeLock(mVcnContext.getContext(), PowerManager.PARTIAL_WAKE_LOCK, TAG); mDeps.newWakeLock(mVcnContext.getContext(), PowerManager.PARTIAL_WAKE_LOCK, TAG);
mUnderlyingNetworkTracker = mUnderlyingNetworkController =
mDeps.newUnderlyingNetworkTracker( mDeps.newUnderlyingNetworkController(
mVcnContext, mVcnContext,
subscriptionGroup, subscriptionGroup,
mLastSnapshot, mLastSnapshot,
mUnderlyingNetworkTrackerCallback); mUnderlyingNetworkControllerCallback);
mIpSecManager = mVcnContext.getContext().getSystemService(IpSecManager.class); mIpSecManager = mVcnContext.getContext().getSystemService(IpSecManager.class);
addState(mDisconnectedState); addState(mDisconnectedState);
@@ -748,7 +752,7 @@ public class VcnGatewayConnection extends StateMachine {
cancelRetryTimeoutAlarm(); cancelRetryTimeoutAlarm();
cancelSafeModeAlarm(); cancelSafeModeAlarm();
mUnderlyingNetworkTracker.teardown(); mUnderlyingNetworkController.teardown();
mGatewayStatusCallback.onQuit(); mGatewayStatusCallback.onQuit();
} }
@@ -764,12 +768,13 @@ public class VcnGatewayConnection extends StateMachine {
mVcnContext.ensureRunningOnLooperThread(); mVcnContext.ensureRunningOnLooperThread();
mLastSnapshot = snapshot; mLastSnapshot = snapshot;
mUnderlyingNetworkTracker.updateSubscriptionSnapshot(mLastSnapshot); mUnderlyingNetworkController.updateSubscriptionSnapshot(mLastSnapshot);
sendMessageAndAcquireWakeLock(EVENT_SUBSCRIPTIONS_CHANGED, TOKEN_ALL); sendMessageAndAcquireWakeLock(EVENT_SUBSCRIPTIONS_CHANGED, TOKEN_ALL);
} }
private class VcnUnderlyingNetworkTrackerCallback implements UnderlyingNetworkTrackerCallback { private class VcnUnderlyingNetworkControllerCallback
implements UnderlyingNetworkControllerCallback {
@Override @Override
public void onSelectedUnderlyingNetworkChanged( public void onSelectedUnderlyingNetworkChanged(
@Nullable UnderlyingNetworkRecord underlying) { @Nullable UnderlyingNetworkRecord underlying) {
@@ -2264,7 +2269,7 @@ public class VcnGatewayConnection extends StateMachine {
+ (mNetworkAgent == null ? null : mNetworkAgent.getNetwork())); + (mNetworkAgent == null ? null : mNetworkAgent.getNetwork()));
pw.println(); pw.println();
mUnderlyingNetworkTracker.dump(pw); mUnderlyingNetworkController.dump(pw);
pw.println(); pw.println();
pw.decreaseIndent(); pw.decreaseIndent();
@@ -2276,8 +2281,8 @@ public class VcnGatewayConnection extends StateMachine {
} }
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
UnderlyingNetworkTrackerCallback getUnderlyingNetworkTrackerCallback() { UnderlyingNetworkControllerCallback getUnderlyingNetworkControllerCallback() {
return mUnderlyingNetworkTrackerCallback; return mUnderlyingNetworkControllerCallback;
} }
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
@@ -2356,17 +2361,14 @@ public class VcnGatewayConnection extends StateMachine {
/** External dependencies used by VcnGatewayConnection, for injection in tests */ /** External dependencies used by VcnGatewayConnection, for injection in tests */
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
public static class Dependencies { public static class Dependencies {
/** Builds a new UnderlyingNetworkTracker. */ /** Builds a new UnderlyingNetworkController. */
public UnderlyingNetworkTracker newUnderlyingNetworkTracker( public UnderlyingNetworkController newUnderlyingNetworkController(
VcnContext vcnContext, VcnContext vcnContext,
ParcelUuid subscriptionGroup, ParcelUuid subscriptionGroup,
TelephonySubscriptionSnapshot snapshot, TelephonySubscriptionSnapshot snapshot,
UnderlyingNetworkTrackerCallback callback) { UnderlyingNetworkControllerCallback callback) {
return new UnderlyingNetworkTracker( return new UnderlyingNetworkController(
vcnContext, vcnContext, subscriptionGroup, snapshot, callback);
subscriptionGroup,
snapshot,
callback);
} }
/** Builds a new IkeSession. */ /** Builds a new IkeSession. */

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server.vcn; package com.android.server.vcn.routeselection;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI; import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
@@ -48,6 +48,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility; import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot; import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import com.android.server.vcn.VcnContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -61,14 +62,14 @@ import java.util.TreeSet;
/** /**
* Tracks a set of Networks underpinning a VcnGatewayConnection. * Tracks a set of Networks underpinning a VcnGatewayConnection.
* *
* <p>A single UnderlyingNetworkTracker is built to serve a SINGLE VCN Gateway Connection, and MUST * <p>A single UnderlyingNetworkController is built to serve a SINGLE VCN Gateway Connection, and
* be torn down with the VcnGatewayConnection in order to ensure underlying networks are allowed to * MUST be torn down with the VcnGatewayConnection in order to ensure underlying networks are
* be reaped. * allowed to be reaped.
* *
* @hide * @hide
*/ */
public class UnderlyingNetworkTracker { public class UnderlyingNetworkController {
@NonNull private static final String TAG = UnderlyingNetworkTracker.class.getSimpleName(); @NonNull private static final String TAG = UnderlyingNetworkController.class.getSimpleName();
/** /**
* Minimum signal strength for a WiFi network to be eligible for switching to * Minimum signal strength for a WiFi network to be eligible for switching to
@@ -122,7 +123,7 @@ public class UnderlyingNetworkTracker {
@NonNull private final VcnContext mVcnContext; @NonNull private final VcnContext mVcnContext;
@NonNull private final ParcelUuid mSubscriptionGroup; @NonNull private final ParcelUuid mSubscriptionGroup;
@NonNull private final UnderlyingNetworkTrackerCallback mCb; @NonNull private final UnderlyingNetworkControllerCallback mCb;
@NonNull private final Dependencies mDeps; @NonNull private final Dependencies mDeps;
@NonNull private final Handler mHandler; @NonNull private final Handler mHandler;
@NonNull private final ConnectivityManager mConnectivityManager; @NonNull private final ConnectivityManager mConnectivityManager;
@@ -142,11 +143,11 @@ public class UnderlyingNetworkTracker {
@Nullable private UnderlyingNetworkRecord mCurrentRecord; @Nullable private UnderlyingNetworkRecord mCurrentRecord;
@Nullable private UnderlyingNetworkRecord.Builder mRecordInProgress; @Nullable private UnderlyingNetworkRecord.Builder mRecordInProgress;
public UnderlyingNetworkTracker( public UnderlyingNetworkController(
@NonNull VcnContext vcnContext, @NonNull VcnContext vcnContext,
@NonNull ParcelUuid subscriptionGroup, @NonNull ParcelUuid subscriptionGroup,
@NonNull TelephonySubscriptionSnapshot snapshot, @NonNull TelephonySubscriptionSnapshot snapshot,
@NonNull UnderlyingNetworkTrackerCallback cb) { @NonNull UnderlyingNetworkControllerCallback cb) {
this( this(
vcnContext, vcnContext,
subscriptionGroup, subscriptionGroup,
@@ -155,11 +156,11 @@ public class UnderlyingNetworkTracker {
new Dependencies()); new Dependencies());
} }
private UnderlyingNetworkTracker( private UnderlyingNetworkController(
@NonNull VcnContext vcnContext, @NonNull VcnContext vcnContext,
@NonNull ParcelUuid subscriptionGroup, @NonNull ParcelUuid subscriptionGroup,
@NonNull TelephonySubscriptionSnapshot snapshot, @NonNull TelephonySubscriptionSnapshot snapshot,
@NonNull UnderlyingNetworkTrackerCallback cb, @NonNull UnderlyingNetworkControllerCallback cb,
@NonNull Dependencies deps) { @NonNull Dependencies deps) {
mVcnContext = Objects.requireNonNull(vcnContext, "Missing vcnContext"); mVcnContext = Objects.requireNonNull(vcnContext, "Missing vcnContext");
mSubscriptionGroup = Objects.requireNonNull(subscriptionGroup, "Missing subscriptionGroup"); mSubscriptionGroup = Objects.requireNonNull(subscriptionGroup, "Missing subscriptionGroup");
@@ -271,8 +272,8 @@ public class UnderlyingNetworkTracker {
* subscription group, while the VCN networks are excluded by virtue of not having subIds set on * subscription group, while the VCN networks are excluded by virtue of not having subIds set on
* the VCN-exposed networks. * the VCN-exposed networks.
* *
* <p>If the VCN that this UnderlyingNetworkTracker belongs to is in test-mode, this will return * <p>If the VCN that this UnderlyingNetworkController belongs to is in test-mode, this will
* a NetworkRequest that only matches Test Networks. * return a NetworkRequest that only matches Test Networks.
*/ */
private NetworkRequest getRouteSelectionRequest() { private NetworkRequest getRouteSelectionRequest() {
if (mVcnContext.isInTestMode()) { if (mVcnContext.isInTestMode()) {
@@ -373,9 +374,9 @@ public class UnderlyingNetworkTracker {
} }
/** /**
* Update this UnderlyingNetworkTracker's TelephonySubscriptionSnapshot. * Update this UnderlyingNetworkController's TelephonySubscriptionSnapshot.
* *
* <p>Updating the TelephonySubscriptionSnapshot will cause this UnderlyingNetworkTracker to * <p>Updating the TelephonySubscriptionSnapshot will cause this UnderlyingNetworkController to
* reevaluate its NetworkBringupCallbacks. This may result in NetworkRequests being registered * reevaluate its NetworkBringupCallbacks. This may result in NetworkRequests being registered
* or unregistered if the subIds mapped to the this Tracker's SubscriptionGroup change. * or unregistered if the subIds mapped to the this Tracker's SubscriptionGroup change.
*/ */
@@ -410,7 +411,7 @@ public class UnderlyingNetworkTracker {
private void reevaluateNetworks() { private void reevaluateNetworks() {
if (mIsQuitting || mRouteSelectionCallback == null) { if (mIsQuitting || mRouteSelectionCallback == null) {
return; // UnderlyingNetworkTracker has quit. return; // UnderlyingNetworkController has quit.
} }
TreeSet<UnderlyingNetworkRecord> sorted = TreeSet<UnderlyingNetworkRecord> sorted =
@@ -572,7 +573,7 @@ public class UnderlyingNetworkTracker {
public final boolean isBlocked; public final boolean isBlocked;
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
UnderlyingNetworkRecord( public UnderlyingNetworkRecord(
@NonNull Network network, @NonNull Network network,
@NonNull NetworkCapabilities networkCapabilities, @NonNull NetworkCapabilities networkCapabilities,
@NonNull LinkProperties linkProperties, @NonNull LinkProperties linkProperties,
@@ -780,7 +781,7 @@ public class UnderlyingNetworkTracker {
/** Dumps the state of this record for logging and debugging purposes. */ /** Dumps the state of this record for logging and debugging purposes. */
public void dump(IndentingPrintWriter pw) { public void dump(IndentingPrintWriter pw) {
pw.println("UnderlyingNetworkTracker:"); pw.println("UnderlyingNetworkController:");
pw.increaseIndent(); pw.increaseIndent();
pw.println("Carrier WiFi Entry Threshold: " + getWifiEntryRssiThreshold(mCarrierConfig)); pw.println("Carrier WiFi Entry Threshold: " + getWifiEntryRssiThreshold(mCarrierConfig));
@@ -811,7 +812,7 @@ public class UnderlyingNetworkTracker {
} }
/** Callbacks for being notified of the changes in, or to the selected underlying network. */ /** Callbacks for being notified of the changes in, or to the selected underlying network. */
public interface UnderlyingNetworkTrackerCallback { public interface UnderlyingNetworkControllerCallback {
/** /**
* Fired when a new underlying network is selected, or properties have changed. * Fired when a new underlying network is selected, or properties have changed.
* *

View File

@@ -119,7 +119,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
@Test @Test
public void testNullNetworkDoesNotTriggerDisconnect() throws Exception { public void testNullNetworkDoesNotTriggerDisconnect() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(null); .onSelectedUnderlyingNetworkChanged(null);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -131,7 +131,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
@Test @Test
public void testNewNetworkTriggersMigration() throws Exception { public void testNewNetworkTriggersMigration() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -143,7 +143,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
@Test @Test
public void testSameNetworkDoesNotTriggerMigration() throws Exception { public void testSameNetworkDoesNotTriggerMigration() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -203,7 +203,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
triggerChildOpened(); triggerChildOpened();
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
getChildSessionCallback() getChildSessionCallback()
.onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform()); .onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());

View File

@@ -64,7 +64,7 @@ public class VcnGatewayConnectionConnectingStateTest extends VcnGatewayConnectio
@Test @Test
public void testNullNetworkTriggersDisconnect() throws Exception { public void testNullNetworkTriggersDisconnect() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(null); .onSelectedUnderlyingNetworkChanged(null);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -76,7 +76,7 @@ public class VcnGatewayConnectionConnectingStateTest extends VcnGatewayConnectio
@Test @Test
public void testNewNetworkTriggersReconnect() throws Exception { public void testNewNetworkTriggersReconnect() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -89,7 +89,7 @@ public class VcnGatewayConnectionConnectingStateTest extends VcnGatewayConnectio
@Test @Test
public void testSameNetworkDoesNotTriggerReconnect() throws Exception { public void testSameNetworkDoesNotTriggerReconnect() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();

View File

@@ -78,7 +78,7 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
@Test @Test
public void testNetworkChangesTriggerStateTransitions() throws Exception { public void testNetworkChangesTriggerStateTransitions() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -89,7 +89,7 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
@Test @Test
public void testNullNetworkDoesNotTriggerStateTransition() throws Exception { public void testNullNetworkDoesNotTriggerStateTransition() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(null); .onSelectedUnderlyingNetworkChanged(null);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();

View File

@@ -58,7 +58,7 @@ public class VcnGatewayConnectionRetryTimeoutStateTest extends VcnGatewayConnect
@Test @Test
public void testNewNetworkTriggerRetry() throws Exception { public void testNewNetworkTriggerRetry() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -72,7 +72,7 @@ public class VcnGatewayConnectionRetryTimeoutStateTest extends VcnGatewayConnect
@Test @Test
public void testSameNetworkDoesNotTriggerRetry() throws Exception { public void testSameNetworkDoesNotTriggerRetry() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -86,7 +86,7 @@ public class VcnGatewayConnectionRetryTimeoutStateTest extends VcnGatewayConnect
@Test @Test
public void testNullNetworkTriggersDisconnect() throws Exception { public void testNullNetworkTriggersDisconnect() throws Exception {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(null); .onSelectedUnderlyingNetworkChanged(null);
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();

View File

@@ -59,7 +59,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot; import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkRecord; import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkRecord;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -238,14 +238,14 @@ public class VcnGatewayConnectionTest extends VcnGatewayConnectionTestBase {
} }
@Test @Test
public void testSubscriptionSnapshotUpdateNotifiesUnderlyingNetworkTracker() { public void testSubscriptionSnapshotUpdateNotifiesUnderlyingNetworkController() {
verifyWakeLockSetUp(); verifyWakeLockSetUp();
final TelephonySubscriptionSnapshot updatedSnapshot = final TelephonySubscriptionSnapshot updatedSnapshot =
mock(TelephonySubscriptionSnapshot.class); mock(TelephonySubscriptionSnapshot.class);
mGatewayConnection.updateSubscriptionSnapshot(updatedSnapshot); mGatewayConnection.updateSubscriptionSnapshot(updatedSnapshot);
verify(mUnderlyingNetworkTracker).updateSubscriptionSnapshot(eq(updatedSnapshot)); verify(mUnderlyingNetworkController).updateSubscriptionSnapshot(eq(updatedSnapshot));
verifyWakeLockAcquired(); verifyWakeLockAcquired();
mTestLooper.dispatchAll(); mTestLooper.dispatchAll();
@@ -256,13 +256,13 @@ public class VcnGatewayConnectionTest extends VcnGatewayConnectionTestBase {
@Test @Test
public void testNonNullUnderlyingNetworkRecordUpdateCancelsAlarm() { public void testNonNullUnderlyingNetworkRecordUpdateCancelsAlarm() {
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(null); .onSelectedUnderlyingNetworkChanged(null);
verifyDisconnectRequestAlarmAndGetCallback(false /* expectCanceled */); verifyDisconnectRequestAlarmAndGetCallback(false /* expectCanceled */);
mGatewayConnection mGatewayConnection
.getUnderlyingNetworkTrackerCallback() .getUnderlyingNetworkControllerCallback()
.onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1); .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_1);
verify(mDisconnectRequestAlarm).cancel(); verify(mDisconnectRequestAlarm).cancel();

View File

@@ -16,10 +16,10 @@
package com.android.server.vcn; package com.android.server.vcn;
import static com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkRecord;
import static com.android.server.vcn.VcnGatewayConnection.VcnIkeSession; import static com.android.server.vcn.VcnGatewayConnection.VcnIkeSession;
import static com.android.server.vcn.VcnGatewayConnection.VcnNetworkAgent; import static com.android.server.vcn.VcnGatewayConnection.VcnNetworkAgent;
import static com.android.server.vcn.VcnTestUtils.setupIpSecManager; import static com.android.server.vcn.VcnTestUtils.setupIpSecManager;
import static com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkRecord;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@@ -62,6 +62,7 @@ import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscription
import com.android.server.vcn.Vcn.VcnGatewayStatusCallback; import com.android.server.vcn.Vcn.VcnGatewayStatusCallback;
import com.android.server.vcn.VcnGatewayConnection.VcnChildSessionCallback; import com.android.server.vcn.VcnGatewayConnection.VcnChildSessionCallback;
import com.android.server.vcn.VcnGatewayConnection.VcnWakeLock; import com.android.server.vcn.VcnGatewayConnection.VcnWakeLock;
import com.android.server.vcn.routeselection.UnderlyingNetworkController;
import org.junit.Before; import org.junit.Before;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -137,7 +138,7 @@ public class VcnGatewayConnectionTestBase {
@NonNull protected final VcnGatewayConnectionConfig mConfig; @NonNull protected final VcnGatewayConnectionConfig mConfig;
@NonNull protected final VcnGatewayStatusCallback mGatewayStatusCallback; @NonNull protected final VcnGatewayStatusCallback mGatewayStatusCallback;
@NonNull protected final VcnGatewayConnection.Dependencies mDeps; @NonNull protected final VcnGatewayConnection.Dependencies mDeps;
@NonNull protected final UnderlyingNetworkTracker mUnderlyingNetworkTracker; @NonNull protected final UnderlyingNetworkController mUnderlyingNetworkController;
@NonNull protected final VcnWakeLock mWakeLock; @NonNull protected final VcnWakeLock mWakeLock;
@NonNull protected final WakeupMessage mTeardownTimeoutAlarm; @NonNull protected final WakeupMessage mTeardownTimeoutAlarm;
@NonNull protected final WakeupMessage mDisconnectRequestAlarm; @NonNull protected final WakeupMessage mDisconnectRequestAlarm;
@@ -158,7 +159,7 @@ public class VcnGatewayConnectionTestBase {
mConfig = VcnGatewayConnectionConfigTest.buildTestConfig(); mConfig = VcnGatewayConnectionConfigTest.buildTestConfig();
mGatewayStatusCallback = mock(VcnGatewayStatusCallback.class); mGatewayStatusCallback = mock(VcnGatewayStatusCallback.class);
mDeps = mock(VcnGatewayConnection.Dependencies.class); mDeps = mock(VcnGatewayConnection.Dependencies.class);
mUnderlyingNetworkTracker = mock(UnderlyingNetworkTracker.class); mUnderlyingNetworkController = mock(UnderlyingNetworkController.class);
mWakeLock = mock(VcnWakeLock.class); mWakeLock = mock(VcnWakeLock.class);
mTeardownTimeoutAlarm = mock(WakeupMessage.class); mTeardownTimeoutAlarm = mock(WakeupMessage.class);
mDisconnectRequestAlarm = mock(WakeupMessage.class); mDisconnectRequestAlarm = mock(WakeupMessage.class);
@@ -176,9 +177,9 @@ public class VcnGatewayConnectionTestBase {
doReturn(mTestLooper.getLooper()).when(mVcnContext).getLooper(); doReturn(mTestLooper.getLooper()).when(mVcnContext).getLooper();
doReturn(mVcnNetworkProvider).when(mVcnContext).getVcnNetworkProvider(); doReturn(mVcnNetworkProvider).when(mVcnContext).getVcnNetworkProvider();
doReturn(mUnderlyingNetworkTracker) doReturn(mUnderlyingNetworkController)
.when(mDeps) .when(mDeps)
.newUnderlyingNetworkTracker(any(), any(), any(), any()); .newUnderlyingNetworkController(any(), any(), any(), any());
doReturn(mWakeLock) doReturn(mWakeLock)
.when(mDeps) .when(mDeps)
.newWakeLock(eq(mContext), eq(PowerManager.PARTIAL_WAKE_LOCK), any()); .newWakeLock(eq(mContext), eq(PowerManager.PARTIAL_WAKE_LOCK), any());

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.server.vcn; package com.android.server.vcn.routeselection;
import static com.android.server.vcn.VcnTestUtils.setupSystemService; import static com.android.server.vcn.VcnTestUtils.setupSystemService;
@@ -48,10 +48,12 @@ import android.telephony.TelephonyManager;
import android.util.ArraySet; import android.util.ArraySet;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot; import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import com.android.server.vcn.UnderlyingNetworkTracker.NetworkBringupCallback; import com.android.server.vcn.VcnContext;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkListener; import com.android.server.vcn.VcnNetworkProvider;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkRecord; import com.android.server.vcn.routeselection.UnderlyingNetworkController.NetworkBringupCallback;
import com.android.server.vcn.UnderlyingNetworkTracker.UnderlyingNetworkTrackerCallback; import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkControllerCallback;
import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkListener;
import com.android.server.vcn.routeselection.UnderlyingNetworkController.UnderlyingNetworkRecord;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -64,7 +66,7 @@ import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class UnderlyingNetworkTrackerTest { public class UnderlyingNetworkControllerTest {
private static final ParcelUuid SUB_GROUP = new ParcelUuid(new UUID(0, 0)); private static final ParcelUuid SUB_GROUP = new ParcelUuid(new UUID(0, 0));
private static final int INITIAL_SUB_ID_1 = 1; private static final int INITIAL_SUB_ID_1 = 1;
private static final int INITIAL_SUB_ID_2 = 2; private static final int INITIAL_SUB_ID_2 = 2;
@@ -102,14 +104,14 @@ public class UnderlyingNetworkTrackerTest {
@Mock private TelephonyManager mTelephonyManager; @Mock private TelephonyManager mTelephonyManager;
@Mock private CarrierConfigManager mCarrierConfigManager; @Mock private CarrierConfigManager mCarrierConfigManager;
@Mock private TelephonySubscriptionSnapshot mSubscriptionSnapshot; @Mock private TelephonySubscriptionSnapshot mSubscriptionSnapshot;
@Mock private UnderlyingNetworkTrackerCallback mNetworkTrackerCb; @Mock private UnderlyingNetworkControllerCallback mNetworkControllerCb;
@Mock private Network mNetwork; @Mock private Network mNetwork;
@Captor private ArgumentCaptor<UnderlyingNetworkListener> mUnderlyingNetworkListenerCaptor; @Captor private ArgumentCaptor<UnderlyingNetworkListener> mUnderlyingNetworkListenerCaptor;
private TestLooper mTestLooper; private TestLooper mTestLooper;
private VcnContext mVcnContext; private VcnContext mVcnContext;
private UnderlyingNetworkTracker mUnderlyingNetworkTracker; private UnderlyingNetworkController mUnderlyingNetworkController;
@Before @Before
public void setUp() { public void setUp() {
@@ -140,12 +142,9 @@ public class UnderlyingNetworkTrackerTest {
when(mSubscriptionSnapshot.getAllSubIdsInGroup(eq(SUB_GROUP))).thenReturn(INITIAL_SUB_IDS); when(mSubscriptionSnapshot.getAllSubIdsInGroup(eq(SUB_GROUP))).thenReturn(INITIAL_SUB_IDS);
mUnderlyingNetworkTracker = mUnderlyingNetworkController =
new UnderlyingNetworkTracker( new UnderlyingNetworkController(
mVcnContext, mVcnContext, SUB_GROUP, mSubscriptionSnapshot, mNetworkControllerCb);
SUB_GROUP,
mSubscriptionSnapshot,
mNetworkTrackerCb);
} }
private void resetVcnContext() { private void resetVcnContext() {
@@ -181,11 +180,8 @@ public class UnderlyingNetworkTrackerTest {
mVcnNetworkProvider, mVcnNetworkProvider,
true /* isInTestMode */); true /* isInTestMode */);
new UnderlyingNetworkTracker( new UnderlyingNetworkController(
vcnContext, vcnContext, SUB_GROUP, mSubscriptionSnapshot, mNetworkControllerCb);
SUB_GROUP,
mSubscriptionSnapshot,
mNetworkTrackerCb);
verify(cm) verify(cm)
.registerNetworkCallback( .registerNetworkCallback(
@@ -233,7 +229,7 @@ public class UnderlyingNetworkTrackerTest {
mock(TelephonySubscriptionSnapshot.class); mock(TelephonySubscriptionSnapshot.class);
when(subscriptionUpdate.getAllSubIdsInGroup(eq(SUB_GROUP))).thenReturn(UPDATED_SUB_IDS); when(subscriptionUpdate.getAllSubIdsInGroup(eq(SUB_GROUP))).thenReturn(UPDATED_SUB_IDS);
mUnderlyingNetworkTracker.updateSubscriptionSnapshot(subscriptionUpdate); mUnderlyingNetworkController.updateSubscriptionSnapshot(subscriptionUpdate);
// verify that initially-filed bringup requests are unregistered (cell + wifi) // verify that initially-filed bringup requests are unregistered (cell + wifi)
verify(mConnectivityManager, times(INITIAL_SUB_IDS.size() + 3)) verify(mConnectivityManager, times(INITIAL_SUB_IDS.size() + 3))
@@ -255,7 +251,7 @@ public class UnderlyingNetworkTrackerTest {
return getExpectedRequestBase() return getExpectedRequestBase()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setSubscriptionIds(netCapsSubIds) .setSubscriptionIds(netCapsSubIds)
.setSignalStrength(UnderlyingNetworkTracker.WIFI_ENTRY_RSSI_THRESHOLD_DEFAULT) .setSignalStrength(UnderlyingNetworkController.WIFI_ENTRY_RSSI_THRESHOLD_DEFAULT)
.build(); .build();
} }
@@ -264,7 +260,7 @@ public class UnderlyingNetworkTrackerTest {
return getExpectedRequestBase() return getExpectedRequestBase()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setSubscriptionIds(netCapsSubIds) .setSubscriptionIds(netCapsSubIds)
.setSignalStrength(UnderlyingNetworkTracker.WIFI_EXIT_RSSI_THRESHOLD_DEFAULT) .setSignalStrength(UnderlyingNetworkController.WIFI_EXIT_RSSI_THRESHOLD_DEFAULT)
.build(); .build();
} }
@@ -304,7 +300,7 @@ public class UnderlyingNetworkTrackerTest {
@Test @Test
public void testTeardown() { public void testTeardown() {
mUnderlyingNetworkTracker.teardown(); mUnderlyingNetworkController.teardown();
// Expect 5 NetworkBringupCallbacks to be unregistered: 1 for WiFi, 2 for Cellular (1x for // Expect 5 NetworkBringupCallbacks to be unregistered: 1 for WiFi, 2 for Cellular (1x for
// each subId), and 1 for each of the Wifi signal strength thresholds // each subId), and 1 for each of the Wifi signal strength thresholds
@@ -368,7 +364,7 @@ public class UnderlyingNetworkTrackerTest {
networkCapabilities, networkCapabilities,
INITIAL_LINK_PROPERTIES, INITIAL_LINK_PROPERTIES,
false /* isBlocked */); false /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
return cb; return cb;
} }
@@ -384,7 +380,7 @@ public class UnderlyingNetworkTrackerTest {
UPDATED_NETWORK_CAPABILITIES, UPDATED_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES, INITIAL_LINK_PROPERTIES,
false /* isBlocked */); false /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
} }
@Test @Test
@@ -399,7 +395,7 @@ public class UnderlyingNetworkTrackerTest {
INITIAL_NETWORK_CAPABILITIES, INITIAL_NETWORK_CAPABILITIES,
UPDATED_LINK_PROPERTIES, UPDATED_LINK_PROPERTIES,
false /* isBlocked */); false /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
} }
@Test @Test
@@ -414,11 +410,13 @@ public class UnderlyingNetworkTrackerTest {
SUSPENDED_NETWORK_CAPABILITIES, SUSPENDED_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES, INITIAL_LINK_PROPERTIES,
false /* isBlocked */); false /* isBlocked */);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb, times(1))
.onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
// onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't // onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't
// change. // change.
cb.onCapabilitiesChanged(mNetwork, SUSPENDED_NETWORK_CAPABILITIES); cb.onCapabilitiesChanged(mNetwork, SUSPENDED_NETWORK_CAPABILITIES);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb, times(1))
.onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
} }
@Test @Test
@@ -434,11 +432,13 @@ public class UnderlyingNetworkTrackerTest {
INITIAL_NETWORK_CAPABILITIES, INITIAL_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES, INITIAL_LINK_PROPERTIES,
false /* isBlocked */); false /* isBlocked */);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb, times(1))
.onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
// onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't // onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't
// change. // change.
cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES); cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb, times(1))
.onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
} }
@Test @Test
@@ -453,7 +453,7 @@ public class UnderlyingNetworkTrackerTest {
INITIAL_NETWORK_CAPABILITIES, INITIAL_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES, INITIAL_LINK_PROPERTIES,
true /* isBlocked */); true /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord)); verify(mNetworkControllerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
} }
@Test @Test
@@ -462,7 +462,7 @@ public class UnderlyingNetworkTrackerTest {
cb.onLost(mNetwork); cb.onLost(mNetwork);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(null); verify(mNetworkControllerCb).onSelectedUnderlyingNetworkChanged(null);
} }
@Test @Test
@@ -471,20 +471,20 @@ public class UnderlyingNetworkTrackerTest {
cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES); cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES);
// Verify no more calls to the UnderlyingNetworkTrackerCallback when the // Verify no more calls to the UnderlyingNetworkControllerCallback when the
// UnderlyingNetworkRecord does not actually change // UnderlyingNetworkRecord does not actually change
verifyNoMoreInteractions(mNetworkTrackerCb); verifyNoMoreInteractions(mNetworkControllerCb);
} }
@Test @Test
public void testRecordTrackerCallbackNotifiedAfterTeardown() { public void testRecordTrackerCallbackNotifiedAfterTeardown() {
UnderlyingNetworkListener cb = verifyRegistrationOnAvailableAndGetCallback(); UnderlyingNetworkListener cb = verifyRegistrationOnAvailableAndGetCallback();
mUnderlyingNetworkTracker.teardown(); mUnderlyingNetworkController.teardown();
cb.onCapabilitiesChanged(mNetwork, UPDATED_NETWORK_CAPABILITIES); cb.onCapabilitiesChanged(mNetwork, UPDATED_NETWORK_CAPABILITIES);
// Verify that the only call was during onAvailable() // Verify that the only call was during onAvailable()
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(any()); verify(mNetworkControllerCb, times(1)).onSelectedUnderlyingNetworkChanged(any());
} }
// TODO (b/187991063): Add tests for network prioritization // TODO (b/187991063): Add tests for network prioritization