• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package android.net.ipsec.ike.exceptions;
18 
19 import android.annotation.NonNull;
20 import android.net.Network;
21 import android.net.ipsec.ike.IkeSessionCallback;
22 
23 import java.util.Objects;
24 
25 /**
26  * IkeNetworkLostException is returned to the caller via {@link
27  * IkeSessionCallback#onError(IkeException)} if the underlying Network for the {@link
28  * android.net.ipsec.ike.IkeSession} was lost with no alternatives.
29  *
30  * <p>This Exception corresponds to {@link
31  * android.net.ConnectivityManager.NetworkCallback#onLost(android.net.Network)} being invoked for
32  * the specified underlying Network.
33  *
34  * <p>When the caller receives this Exception, they must either:
35  *
36  * <ul>
37  *   <li>set a new underlying Network for the corresponding IkeSession (MOBIKE must be enabled and
38  *       the IKE Session must have started with a caller-configured Network), or
39  *   <li>wait for a new underlying Network to become available (MOBIKE must be enabled and the IKE
40  *       Session must be tracking the System default Network), or
41  *       <ul>
42  *         <li>Note: if the maximum retransmission time is encountered while waiting, the IKE
43  *             Session will close. If this occurs, the caller will be notified via {@link
44  *             IkeSessionCallback#onClosedWithException(IkeException)}.
45  *       </ul>
46  *   <li>close the corresponding IkeSession.
47  * </ul>
48  */
49 public final class IkeNetworkLostException extends IkeNonProtocolException {
50     private final Network mNetwork;
51 
52     /** Constructs an IkeNetworkLostException to indicate the specified Network was lost. */
IkeNetworkLostException(@onNull Network network)53     public IkeNetworkLostException(@NonNull Network network) {
54         super();
55         Objects.requireNonNull(network, "network is null");
56 
57         mNetwork = network;
58     }
59 
60     /** Returns the IkeSession's underlying Network that was lost. */
61     @NonNull
getNetwork()62     public Network getNetwork() {
63         return mNetwork;
64     }
65 }
66