Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62fbaad7 authored by Lucas Lin's avatar Lucas Lin Committed by Automerger Merge Worker
Browse files

Merge "Revert "Improve the code of handleSessionLost()"" am: f4d9a092 am:...

Merge "Revert "Improve the code of handleSessionLost()"" am: f4d9a092 am: ed511881 am: bf384901 am: 828fd83d am: 228e8960

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2112764



Change-Id: I51cdd7d177dc7b0214f1b32c395f6f5b2027cdf9
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 72df3f66 228e8960
Loading
Loading
Loading
Loading
+80 −33
Original line number Original line Diff line number Diff line
@@ -3159,13 +3159,8 @@ public class Vpn {
            cancelHandleNetworkLostTimeout();
            cancelHandleNetworkLostTimeout();


            synchronized (Vpn.this) {
            synchronized (Vpn.this) {
                String category = "";
                int errorClass = 0;
                int errorCode = 0;
                if (exception instanceof IkeProtocolException) {
                if (exception instanceof IkeProtocolException) {
                    final IkeProtocolException ikeException = (IkeProtocolException) exception;
                    final IkeProtocolException ikeException = (IkeProtocolException) exception;
                    category = VpnManager.CATEGORY_EVENT_IKE_ERROR;
                    errorCode = ikeException.getErrorType();


                    switch (ikeException.getErrorType()) {
                    switch (ikeException.getErrorType()) {
                        case IkeProtocolException.ERROR_TYPE_NO_PROPOSAL_CHOSEN: // Fallthrough
                        case IkeProtocolException.ERROR_TYPE_NO_PROPOSAL_CHOSEN: // Fallthrough
@@ -3175,38 +3170,92 @@ public class Vpn {
                        case IkeProtocolException.ERROR_TYPE_FAILED_CP_REQUIRED: // Fallthrough
                        case IkeProtocolException.ERROR_TYPE_FAILED_CP_REQUIRED: // Fallthrough
                        case IkeProtocolException.ERROR_TYPE_TS_UNACCEPTABLE:
                        case IkeProtocolException.ERROR_TYPE_TS_UNACCEPTABLE:
                            // All the above failures are configuration errors, and are terminal
                            // All the above failures are configuration errors, and are terminal
                            errorClass = VpnManager.ERROR_CLASS_NOT_RECOVERABLE;
                            // TODO(b/230548427): Remove SDK check once VPN related stuff are
                            break;
                            //  decoupled from ConnectivityServiceTest.
                            if (SdkLevel.isAtLeastT()) {
                                sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR,
                                        VpnManager.ERROR_CLASS_NOT_RECOVERABLE,
                                        ikeException.getErrorType(),
                                        getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                        mActiveNetwork,
                                        getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
                                                mUnderlyingNetworkCapabilities),
                                        getRedactedLinkPropertiesOfUnderlyingNetwork(
                                                mUnderlyingLinkProperties));
                            }
                            markFailedAndDisconnect(exception);
                            return;
                        // All other cases possibly recoverable.
                        // All other cases possibly recoverable.
                        default:
                        default:
                            // All the above failures are configuration errors, and are terminal
                            // All the above failures are configuration errors, and are terminal
                            errorClass = VpnManager.ERROR_CLASS_RECOVERABLE;
                            // TODO(b/230548427): Remove SDK check once VPN related stuff are
                            //  decoupled from ConnectivityServiceTest.
                            if (SdkLevel.isAtLeastT()) {
                                sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_IKE_ERROR,
                                        VpnManager.ERROR_CLASS_RECOVERABLE,
                                        ikeException.getErrorType(),
                                        getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                        mActiveNetwork,
                                        getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
                                                mUnderlyingNetworkCapabilities),
                                        getRedactedLinkPropertiesOfUnderlyingNetwork(
                                                mUnderlyingLinkProperties));
                            }
                    }
                    }
                } else if (exception instanceof IllegalArgumentException) {
                } else if (exception instanceof IllegalArgumentException) {
                    // Failed to build IKE/ChildSessionParams; fatal profile configuration error
                    // Failed to build IKE/ChildSessionParams; fatal profile configuration error
                    markFailedAndDisconnect(exception);
                    markFailedAndDisconnect(exception);
                    return;
                    return;
                } else if (exception instanceof IkeNetworkLostException) {
                } else if (exception instanceof IkeNetworkLostException) {
                    category = VpnManager.CATEGORY_EVENT_NETWORK_ERROR;
                    // TODO(b/230548427): Remove SDK check once VPN related stuff are
                    errorClass = VpnManager.ERROR_CLASS_RECOVERABLE;
                    //  decoupled from ConnectivityServiceTest.
                    errorCode = VpnManager.ERROR_CODE_NETWORK_LOST;
                    if (SdkLevel.isAtLeastT()) {
                        sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
                                VpnManager.ERROR_CLASS_RECOVERABLE,
                                VpnManager.ERROR_CODE_NETWORK_LOST,
                                getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                mActiveNetwork,
                                getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
                                        mUnderlyingNetworkCapabilities),
                                getRedactedLinkPropertiesOfUnderlyingNetwork(
                                        mUnderlyingLinkProperties));
                    }
                } else if (exception instanceof IkeNonProtocolException) {
                } else if (exception instanceof IkeNonProtocolException) {
                    category = VpnManager.CATEGORY_EVENT_NETWORK_ERROR;
                    errorClass = VpnManager.ERROR_CLASS_RECOVERABLE;
                    if (exception.getCause() instanceof UnknownHostException) {
                    if (exception.getCause() instanceof UnknownHostException) {
                        errorCode = VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST;
                        // TODO(b/230548427): Remove SDK check once VPN related stuff are
                    } else if (exception.getCause() instanceof IkeTimeoutException) {
                        //  decoupled from ConnectivityServiceTest.
                        errorCode = VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT;
                        if (SdkLevel.isAtLeastT()) {
                    } else if (exception.getCause() instanceof IOException) {
                            sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
                        errorCode = VpnManager.ERROR_CODE_NETWORK_IO;
                                    VpnManager.ERROR_CLASS_RECOVERABLE,
                                    VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST,
                                    getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                    mActiveNetwork,
                                    getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
                                            mUnderlyingNetworkCapabilities),
                                    getRedactedLinkPropertiesOfUnderlyingNetwork(
                                            mUnderlyingLinkProperties));
                        }
                        }
                } else if (exception != null) {
                    } else if (exception.getCause() instanceof IkeTimeoutException) {
                    Log.wtf(TAG, "onSessionLost: exception = " + exception);
                        // 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(
                                            mUnderlyingNetworkCapabilities),
                                    getRedactedLinkPropertiesOfUnderlyingNetwork(
                                            mUnderlyingLinkProperties));
                        }
                        }
                    } else if (exception.getCause() instanceof IOException) {
                        // TODO(b/230548427): Remove SDK check once VPN related stuff are
                        // TODO(b/230548427): Remove SDK check once VPN related stuff are
                        //  decoupled from ConnectivityServiceTest.
                        //  decoupled from ConnectivityServiceTest.
                        if (SdkLevel.isAtLeastT()) {
                        if (SdkLevel.isAtLeastT()) {
                    sendEventToVpnManagerApp(category, errorClass, errorCode,
                            sendEventToVpnManagerApp(VpnManager.CATEGORY_EVENT_NETWORK_ERROR,
                                    VpnManager.ERROR_CLASS_RECOVERABLE,
                                    VpnManager.ERROR_CODE_NETWORK_IO,
                                    getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                    getPackage(), mSessionKey, makeVpnProfileStateLocked(),
                                    mActiveNetwork,
                                    mActiveNetwork,
                                    getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
                                    getRedactedNetworkCapabilitiesOfUnderlyingNetwork(
@@ -3214,11 +3263,9 @@ public class Vpn {
                                    getRedactedLinkPropertiesOfUnderlyingNetwork(
                                    getRedactedLinkPropertiesOfUnderlyingNetwork(
                                            mUnderlyingLinkProperties));
                                            mUnderlyingLinkProperties));
                        }
                        }
                if (errorClass == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
                    }
                    markFailedAndDisconnect(exception);
                } else if (exception != null) {
                    return;
                    Log.wtf(TAG, "onSessionLost: exception = " + exception);
                } else if (errorClass == VpnManager.ERROR_CLASS_RECOVERABLE) {
                    // Retry a new IKE session.
                }
                }
            }
            }