Clear mInterface before calling resetIkeState()
Clear mInterface before calling resetIkeState() in
resetIkeState() will trigger interfaceRemoved() to be called.
If mInterface is set, interfaceRemoved() will clear
Ikev2VpnRunner which makes VPN disconnect.
This issue can be reproduced when device establishes VPN
connection with mobile data first then connects to wifi.
In this case, onLost() for mobile data will not be called
because there is a new network(wifi) can satisfy the request,
so only onAvailable() for wifi will be called.
Which means onSessionLost() will not be called and only
onDefaultNetworkChanged() will be called, which makes that
mInterface is not cleared before interfaceRemoved() is called.
Test: Check if VPN is still there when establishing VPN with
mobile data first, then connect to wifi and disconnect
(cherry picked from commit 520cc2fde363dd038911b98b8b46259faf58a659)
(cherry picked from commit 65d44b93bb99eae441ebf5bf1afb4efd00074758)
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 1acbde9..aa3c999 100644
@@ -2606,6 +2606,9 @@
return; // VPN has been shut down.
+ // Clear mInterface to prevent Ikev2VpnRunner being cleared when
+ // interfaceRemoved() is called.
+ mInterface = null;
// Without MOBIKE, we have no way to seamlessly migrate. Close on old
// (non-default) network, and start the new one.