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 17 package android.net.ipsec.ike; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.net.ipsec.ike.exceptions.IkeException; 22 import android.net.ipsec.ike.exceptions.IkeProtocolException; 23 24 /** 25 * Callback interface for receiving state changes of an {@link IkeSession}. 26 * 27 * <p>{@link IkeSessionCallback} MUST be unique to each {@link IkeSession}. It is registered when 28 * callers are requesting a new {@link IkeSession}. It is automatically unregistered when an {@link 29 * IkeSession} is closed. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public interface IkeSessionCallback { 35 /** 36 * Called when the {@link IkeSession} setup succeeds. 37 * 38 * <p>This method does not indicate the first Child Session has been setup. Caller MUST refer to 39 * the corresponding {@link ChildSessionCallback} for the Child Session setup result. 40 * 41 * @param sessionConfiguration the configuration information of {@link IkeSession} negotiated 42 * during IKE setup. 43 */ onOpened(@onNull IkeSessionConfiguration sessionConfiguration)44 void onOpened(@NonNull IkeSessionConfiguration sessionConfiguration); 45 46 /** 47 * Called when the {@link IkeSession} is closed. 48 * 49 * <p>When the closure is caused by a local, fatal error, {@link 50 * #onClosedExceptionally(IkeException)} will be fired instead of this method. 51 */ onClosed()52 void onClosed(); 53 54 /** 55 * Called if {@link IkeSession} setup failed or {@link IkeSession} is closed because of a fatal 56 * error. 57 * 58 * @param exception the detailed error information. 59 */ onClosedExceptionally(@onNull IkeException exception)60 void onClosedExceptionally(@NonNull IkeException exception); 61 62 /** 63 * Called if a recoverable error is encountered in an established {@link IkeSession}. 64 * 65 * <p>This method may be triggered by protocol errors such as an INVALID_IKE_SPI or 66 * INVALID_MESSAGE_ID. 67 * 68 * @param exception the detailed error information. 69 */ onError(@onNull IkeProtocolException exception)70 void onError(@NonNull IkeProtocolException exception); 71 } 72