diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt index 53d485d5e8..7b97ceca2e 100644 --- a/framework/api/system-current.txt +++ b/framework/api/system-current.txt @@ -236,7 +236,6 @@ package android.net { public abstract class NetworkAgent { ctor public NetworkAgent(@NonNull android.content.Context, @NonNull android.os.Looper, @NonNull String, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, int, @NonNull android.net.NetworkAgentConfig, @Nullable android.net.NetworkProvider); ctor public NetworkAgent(@NonNull android.content.Context, @NonNull android.os.Looper, @NonNull String, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, @NonNull android.net.NetworkScore, @NonNull android.net.NetworkAgentConfig, @Nullable android.net.NetworkProvider); - method public void destroyAndAwaitReplacement(@IntRange(from=0, to=0x1388) int); method @Nullable public android.net.Network getNetwork(); method public void markConnected(); method public void onAddKeepalivePacketFilter(int, @NonNull android.net.KeepalivePacketData); @@ -271,6 +270,7 @@ package android.net { method public void setTeardownDelayMillis(@IntRange(from=0, to=0x1388) int); method public final void setUnderlyingNetworks(@Nullable java.util.List); method public void unregister(); + method public void unregisterAfterReplacement(@IntRange(from=0, to=0x1388) int); field public static final int VALIDATION_STATUS_NOT_VALID = 2; // 0x2 field public static final int VALIDATION_STATUS_VALID = 1; // 0x1 } diff --git a/framework/src/android/net/INetworkAgentRegistry.aidl b/framework/src/android/net/INetworkAgentRegistry.aidl index 2b22a5cfde..b375b7b649 100644 --- a/framework/src/android/net/INetworkAgentRegistry.aidl +++ b/framework/src/android/net/INetworkAgentRegistry.aidl @@ -47,5 +47,5 @@ oneway interface INetworkAgentRegistry { void sendAddDscpPolicy(in DscpPolicy policy); void sendRemoveDscpPolicy(int policyId); void sendRemoveAllDscpPolicies(); - void sendDestroyAndAwaitReplacement(int timeoutMillis); + void sendUnregisterAfterReplacement(int timeoutMillis); } diff --git a/framework/src/android/net/NetworkAgent.java b/framework/src/android/net/NetworkAgent.java index fdc9081836..07b6227c20 100644 --- a/framework/src/android/net/NetworkAgent.java +++ b/framework/src/android/net/NetworkAgent.java @@ -440,7 +440,7 @@ public abstract class NetworkAgent { * arg1 = timeout in milliseconds * @hide */ - public static final int EVENT_DESTROY_AND_AWAIT_REPLACEMENT = BASE + 29; + public static final int EVENT_UNREGISTER_AFTER_REPLACEMENT = BASE + 29; private static NetworkInfo getLegacyNetworkInfo(final NetworkAgentConfig config) { final NetworkInfo ni = new NetworkInfo(config.legacyType, config.legacySubType, @@ -984,9 +984,9 @@ public abstract class NetworkAgent { * @param timeoutMillis the timeout after which this network will be unregistered even if * {@link #unregister} was not called. */ - public void destroyAndAwaitReplacement( + public void unregisterAfterReplacement( @IntRange(from = 0, to = MAX_TEARDOWN_DELAY_MS) int timeoutMillis) { - queueOrSendMessage(reg -> reg.sendDestroyAndAwaitReplacement(timeoutMillis)); + queueOrSendMessage(reg -> reg.sendUnregisterAfterReplacement(timeoutMillis)); } /** diff --git a/service/ServiceConnectivityResources/res/values/config.xml b/service/ServiceConnectivityResources/res/values/config.xml index 1af00c7bb1..81782f98f6 100644 --- a/service/ServiceConnectivityResources/res/values/config.xml +++ b/service/ServiceConnectivityResources/res/values/config.xml @@ -176,7 +176,7 @@ NetworkMonitor will continue to attempt validation, and if it fails after this time has passed, the network will be marked unvalidated. - Only supported up to S. On T+, the Wi-Fi code should use destroyAndAwaitReplacement in order + Only supported up to S. On T+, the Wi-Fi code should use unregisterAfterReplacement in order to ensure that apps see the network disconnect and reconnect. --> -1 diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index e58160a5e4..ab5f5d381a 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -3648,7 +3648,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } break; } - case NetworkAgent.EVENT_DESTROY_AND_AWAIT_REPLACEMENT: { + case NetworkAgent.EVENT_UNREGISTER_AFTER_REPLACEMENT: { // If nai is not yet created, or is already destroyed, ignore. if (!shouldDestroyNativeNetwork(nai)) break; @@ -4213,7 +4213,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } private boolean shouldIgnoreValidationFailureAfterRoam(NetworkAgentInfo nai) { - // T+ devices should use destroyAndAwaitReplacement. + // T+ devices should use unregisterAfterReplacement. if (SdkLevel.isAtLeastT()) return false; final long blockTimeOut = Long.valueOf(mResources.get().getInteger( R.integer.config_validationFailureAfterRoamIgnoreTimeMillis)); diff --git a/service/src/com/android/server/connectivity/NetworkAgentInfo.java b/service/src/com/android/server/connectivity/NetworkAgentInfo.java index b73e2ccb4e..1fc5a8fff0 100644 --- a/service/src/com/android/server/connectivity/NetworkAgentInfo.java +++ b/service/src/com/android/server/connectivity/NetworkAgentInfo.java @@ -736,8 +736,8 @@ public class NetworkAgentInfo implements Comparable, NetworkRa } @Override - public void sendDestroyAndAwaitReplacement(final int timeoutMillis) { - mHandler.obtainMessage(NetworkAgent.EVENT_DESTROY_AND_AWAIT_REPLACEMENT, + public void sendUnregisterAfterReplacement(final int timeoutMillis) { + mHandler.obtainMessage(NetworkAgent.EVENT_UNREGISTER_AFTER_REPLACEMENT, new Pair<>(NetworkAgentInfo.this, timeoutMillis)).sendToTarget(); } } diff --git a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt index 53b00dbfb9..f007b83b9e 100644 --- a/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt +++ b/tests/cts/net/src/android/net/cts/NetworkAgentTest.kt @@ -1152,7 +1152,7 @@ class NetworkAgentTest { } @Test - fun testDestroyAndAwaitReplacement() { + fun testUnregisterAfterReplacement() { // Keeps an eye on all test networks. val matchAllCallback = TestableNetworkCallback(timeoutMs = DEFAULT_TIMEOUT_MS) registerNetworkCallback(makeTestNetworkRequest(), matchAllCallback) @@ -1180,15 +1180,15 @@ class NetworkAgentTest { // Mark the first network as awaiting replacement. This should destroy the underlying // native network and send onNetworkDestroyed, but will not send any NetworkCallbacks, // because for callback and scoring purposes network1 is still connected. - agent1.destroyAndAwaitReplacement(5_000 /* timeoutMillis */) + agent1.unregisterAfterReplacement(5_000 /* timeoutMillis */) agent1.expectCallback() assertThrows(IOException::class.java) { network1.bindSocket(DatagramSocket()) } assertNotNull(mCM.getLinkProperties(network1)) - // Calling destroyAndAwaitReplacement more than once has no effect. + // Calling unregisterAfterReplacement more than once has no effect. // If it did, this test would fail because the 1ms timeout means that the network would be // torn down before the replacement arrives. - agent1.destroyAndAwaitReplacement(1 /* timeoutMillis */) + agent1.unregisterAfterReplacement(1 /* timeoutMillis */) // Connect a third network. Because network1 is awaiting replacement, network3 is preferred // as soon as it validates (until then, it is outscored by network1). @@ -1216,14 +1216,14 @@ class NetworkAgentTest { matchAllCallback.expectCallback(network3) testCallback.expectAvailableCallbacks(network4, validated = true) mCM.unregisterNetworkCallback(agent4callback) - agent3.destroyAndAwaitReplacement(5_000) + agent3.unregisterAfterReplacement(5_000) agent3.expectCallback() matchAllCallback.expectCallback(network3, 1000L) agent3.expectCallback() // Now mark network4 awaiting replacement with a low timeout, and check that if no // replacement arrives, it is torn down. - agent4.destroyAndAwaitReplacement(100 /* timeoutMillis */) + agent4.unregisterAfterReplacement(100 /* timeoutMillis */) matchAllCallback.expectCallback(network4, 1000L /* timeoutMs */) testCallback.expectCallback(network4, 1000L /* timeoutMs */) agent4.expectCallback() @@ -1234,7 +1234,7 @@ class NetworkAgentTest { val (agent5, network5) = connectNetwork() matchAllCallback.expectAvailableThenValidatedCallbacks(network5) testCallback.expectAvailableThenValidatedCallbacks(network5) - agent5.destroyAndAwaitReplacement(5_000 /* timeoutMillis */) + agent5.unregisterAfterReplacement(5_000 /* timeoutMillis */) agent5.unregister() matchAllCallback.expectCallback(network5, 1000L /* timeoutMs */) testCallback.expectCallback(network5, 1000L /* timeoutMs */) @@ -1257,7 +1257,7 @@ class NetworkAgentTest { it.hasCapability(NET_CAPABILITY_VALIDATED) } - wifiAgent.destroyAndAwaitReplacement(5_000 /* timeoutMillis */) + wifiAgent.unregisterAfterReplacement(5_000 /* timeoutMillis */) wifiAgent.expectCallback() // Once the network is awaiting replacement, changing LinkProperties, NetworkCapabilities or