Always disconnect agents immediately.
Currently, various codepaths in ConnectivityService disconnect
networks using NetworkAgentInfo#disconnect. This posts a message
to the NetworkAgent to disconnect and also posts a message to
ConnectivityService to call disconnectAndDestroyNetwork, which
performs all cleanup in ConnectivityService. These two messages
race and the order is non-deterministic.
Instead, always disconnect using disconnectAndDestroyNetwork,
and have disconnectAndDestroyNetwork post the message to the
agent to disconnect.
This fixes a bug where if wifi uses unregisterAfterReplacement
twice in quick succession, when the third agent connects it
doesn't work because the interface is still being used by the
second network.
Also remove the import of IllegalArgumentException to keep the
linter happy (java.lang.* never needs to be imported).
Bug: 286649301
Test: covered by existing tests
(cherry picked from https://android-review.googlesource.com/q/commit:4bc9fa6b8cefca88f1065e95df06532979c202ee)
Merged-In: Ie01f5589d6839ac6db25f0ba98fc929fbb5b0a96
Change-Id: Ie01f5589d6839ac6db25f0ba98fc929fbb5b0a96
3 files changed