Merge "Remove the usage of hidden API and simplify the design" into sc-dev

This commit is contained in:
Lucas Lin
2021-03-19 14:14:41 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 33 deletions

View File

@@ -290,25 +290,6 @@ public class UnderlyingNetworkTracker {
maybeNotifyCallback();
}
private void handleNetworkSuspended(@NonNull Network network, boolean isSuspended) {
mVcnContext.ensureRunningOnLooperThread();
if (!isSameNetwork(mRecordInProgress, network)) {
Slog.wtf(TAG, "Invalid update to isSuspended");
return;
}
final NetworkCapabilities newCaps =
new NetworkCapabilities(mRecordInProgress.getNetworkCapabilities());
if (isSuspended) {
newCaps.removeCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
} else {
newCaps.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
}
handleCapabilitiesChanged(network, newCaps);
}
private void handlePropertiesChanged(
@NonNull Network network, @NonNull LinkProperties linkProperties) {
mVcnContext.ensureRunningOnLooperThread();
@@ -366,19 +347,10 @@ public class UnderlyingNetworkTracker {
@Override
public void onCapabilitiesChanged(
@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
if (networkCapabilities.equals(mRecordInProgress.getNetworkCapabilities())) return;
handleCapabilitiesChanged(network, networkCapabilities);
}
@Override
public void onNetworkSuspended(@NonNull Network network) {
handleNetworkSuspended(network, true /* isSuspended */);
}
@Override
public void onNetworkResumed(@NonNull Network network) {
handleNetworkSuspended(network, false /* isSuspended */);
}
@Override
public void onLinkPropertiesChanged(
@NonNull Network network, @NonNull LinkProperties linkProperties) {

View File

@@ -328,7 +328,7 @@ public class UnderlyingNetworkTrackerTest {
public void testRecordTrackerCallbackNotifiedForNetworkSuspended() {
RouteSelectionCallback cb = verifyRegistrationOnAvailableAndGetCallback();
cb.onNetworkSuspended(mNetwork);
cb.onCapabilitiesChanged(mNetwork, SUSPENDED_NETWORK_CAPABILITIES);
UnderlyingNetworkRecord expectedRecord =
new UnderlyingNetworkRecord(
@@ -336,7 +336,11 @@ public class UnderlyingNetworkTrackerTest {
SUSPENDED_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES,
false /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
// onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't
// change.
cb.onCapabilitiesChanged(mNetwork, SUSPENDED_NETWORK_CAPABILITIES);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
}
@Test
@@ -344,7 +348,7 @@ public class UnderlyingNetworkTrackerTest {
RouteSelectionCallback cb =
verifyRegistrationOnAvailableAndGetCallback(SUSPENDED_NETWORK_CAPABILITIES);
cb.onNetworkResumed(mNetwork);
cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES);
UnderlyingNetworkRecord expectedRecord =
new UnderlyingNetworkRecord(
@@ -352,7 +356,11 @@ public class UnderlyingNetworkTrackerTest {
INITIAL_NETWORK_CAPABILITIES,
INITIAL_LINK_PROPERTIES,
false /* isBlocked */);
verify(mNetworkTrackerCb).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
// onSelectedUnderlyingNetworkChanged() won't be fired twice if network capabilities doesn't
// change.
cb.onCapabilitiesChanged(mNetwork, INITIAL_NETWORK_CAPABILITIES);
verify(mNetworkTrackerCb, times(1)).onSelectedUnderlyingNetworkChanged(eq(expectedRecord));
}
@Test