1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.net.ipsec.ike.exceptions;
17 
18 import android.annotation.NonNull;
19 import android.net.ipsec.ike.ChildSessionCallback;
20 import android.net.ipsec.ike.IkeSessionCallback;
21 
22 import com.android.internal.net.ipsec.ike.utils.IkeMetrics;
23 
24 /**
25  * IkeInternalException encapsulates all local implementation or resource related exceptions.
26  *
27  * <p>Causes may include exceptions such as {@link android.net.IpSecManager.SpiUnavailableException}
28  * when the requested SPI resources failed to be allocated.
29  */
30 public final class IkeInternalException extends IkeNonProtocolException {
31     /**
32      * Constructs a new exception with the specified cause.
33      *
34      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
35      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
36      *
37      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
38      *     method).
39      */
IkeInternalException(@onNull Throwable cause)40     public IkeInternalException(@NonNull Throwable cause) {
41         super(cause);
42     }
43 
44     /**
45      * Constructs a new exception with a descriptive message.
46      *
47      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
48      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
49      *
50      * @param message the descriptive message (which is saved for later retrieval by the {@link
51      *     #getMessage()} method).
52      * @hide
53      */
IkeInternalException(@onNull String message)54     public IkeInternalException(@NonNull String message) {
55         super(message);
56     }
57 
58     /**
59      * Constructs a new exception with the specified cause.
60      *
61      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
62      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
63      *
64      * @param message the descriptive message (which is saved for later retrieval by the {@link
65      *     #getMessage()} method).
66      * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
67      *     method).
68      */
IkeInternalException(@onNull String message, @NonNull Throwable cause)69     public IkeInternalException(@NonNull String message, @NonNull Throwable cause) {
70         super(message, cause);
71     }
72 
73     /**
74      * Returns the error code for metrics
75      *
76      * @hide
77      */
78     @Override
getMetricsErrorCode()79     public int getMetricsErrorCode() {
80         return IkeMetrics.IKE_ERROR_INTERNAL;
81     }
82 }
83