diff options
| author | 2022-04-22 03:26:37 +0800 | |
|---|---|---|
| committer | 2022-04-29 01:58:56 +0000 | |
| commit | 64eaff5dba207a05ff9b1f9826de98ee05533b30 (patch) | |
| tree | 93e311a224a49524411188dc3413c4afa26eb96a | |
| parent | 4e1f12986abbc1467bf337935650f70afbd569d2 (diff) | |
Send VPN manager event when there is a network error
Bug: 191413541
Test: atest FrameworksNetTests:VpnTest
Change-Id: I767e23750ccf12c0c787a3ec23d4a520dc5bb570
| -rw-r--r-- | services/core/java/com/android/server/connectivity/Vpn.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index aeea7215c63d..64ec12f7c131 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -86,7 +86,10 @@ import android.net.ipsec.ike.IkeSession; import android.net.ipsec.ike.IkeSessionCallback; import android.net.ipsec.ike.IkeSessionParams; import android.net.ipsec.ike.IkeTunnelConnectionParams; +import android.net.ipsec.ike.exceptions.IkeNetworkLostException; +import android.net.ipsec.ike.exceptions.IkeNonProtocolException; import android.net.ipsec.ike.exceptions.IkeProtocolException; +import android.net.ipsec.ike.exceptions.IkeTimeoutException; import android.os.Binder; import android.os.Build.VERSION_CODES; import android.os.Bundle; @@ -2937,6 +2940,66 @@ public class Vpn { // Failed to build IKE/ChildSessionParams; fatal profile configuration error markFailedAndDisconnect(exception); return; + } else if (exception instanceof IkeNetworkLostException) { + // TODO(b/230548427): Remove SDK check once VPN related stuff are + // decoupled from ConnectivityServiceTest. + if (SdkLevel.isAtLeastT()) { + sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, + VpnManager.ERROR_CLASS_RECOVERABLE, + VpnManager.ERROR_CODE_NETWORK_LOST, + getPackage(), mSessionKey, makeVpnProfileStateLocked(), + mActiveNetwork, + getRedactedNetworkCapabilitiesOfUnderlyingNetwork( + this.mNetworkCapabilities), + getRedactedLinkPropertiesOfUnderlyingNetwork( + this.mLinkProperties)); + } + } else if (exception instanceof IkeNonProtocolException) { + if (exception.getCause() instanceof UnknownHostException) { + // TODO(b/230548427): Remove SDK check once VPN related stuff are + // decoupled from ConnectivityServiceTest. + if (SdkLevel.isAtLeastT()) { + sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, + VpnManager.ERROR_CLASS_RECOVERABLE, + VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST, + getPackage(), mSessionKey, makeVpnProfileStateLocked(), + mActiveNetwork, + getRedactedNetworkCapabilitiesOfUnderlyingNetwork( + this.mNetworkCapabilities), + getRedactedLinkPropertiesOfUnderlyingNetwork( + this.mLinkProperties)); + } + } else if (exception.getCause() instanceof IkeTimeoutException) { + // TODO(b/230548427): Remove SDK check once VPN related stuff are + // decoupled from ConnectivityServiceTest. + if (SdkLevel.isAtLeastT()) { + sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, + VpnManager.ERROR_CLASS_RECOVERABLE, + VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT, + getPackage(), mSessionKey, makeVpnProfileStateLocked(), + mActiveNetwork, + getRedactedNetworkCapabilitiesOfUnderlyingNetwork( + this.mNetworkCapabilities), + getRedactedLinkPropertiesOfUnderlyingNetwork( + this.mLinkProperties)); + } + } else if (exception.getCause() instanceof IOException) { + // TODO(b/230548427): Remove SDK check once VPN related stuff are + // decoupled from ConnectivityServiceTest. + if (SdkLevel.isAtLeastT()) { + sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR, + VpnManager.ERROR_CLASS_RECOVERABLE, + VpnManager.ERROR_CODE_NETWORK_IO, + getPackage(), mSessionKey, makeVpnProfileStateLocked(), + mActiveNetwork, + getRedactedNetworkCapabilitiesOfUnderlyingNetwork( + this.mNetworkCapabilities), + getRedactedLinkPropertiesOfUnderlyingNetwork( + this.mLinkProperties)); + } + } + } else if (exception != null) { + Log.wtf(TAG, "onSessionLost: exception = " + exception); } } |