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.ike3gpp; 18 19 import android.annotation.NonNull; 20 import android.annotation.SuppressLint; 21 import android.annotation.SystemApi; 22 23 import java.util.List; 24 import java.util.Objects; 25 26 /** 27 * Ike3gppExtension is used to provide 3GPP-specific extensions for an IKE Session. 28 * 29 * <p>Ike3gppExtension must be set in IkeSessionParams.Builder in order for it to be enabled during 30 * an IKE Session. 31 * 32 * @see 3GPP ETSI TS 24.302: Access to the 3GPP Evolved Packet Core (EPC) via non-3GPP access 33 * networks 34 * @hide 35 */ 36 @SystemApi 37 public final class Ike3gppExtension { 38 @NonNull private final Ike3gppParams mIke3gppParams; 39 @NonNull private final Ike3gppDataListener mIke3gppDataListener; 40 41 /** 42 * Constructs an Ike3gppExtension instance with the given Ike3gppDataListener and Ike3gppParams 43 * instances. 44 * 45 * @param ike3gppParams Ike3gppParams used to configure the 3GPP-support for an IKE Session. 46 * @param ike3gppDataListener Ike3gppDataListener used to notify the caller of 3GPP-specific 47 * data received during an IKE Session. 48 */ 49 // ExecutorRegistration: Not necessary to take an Executor for invoking the listener here, as 50 // this is not actually where the listener is registered. The caller's Executor provided in the 51 // IkeSession constructor will be used to invoke the Ike3gppDataListener. 52 @SuppressLint("ExecutorRegistration") Ike3gppExtension( @onNull Ike3gppParams ike3gppParams, @NonNull Ike3gppDataListener ike3gppDataListener)53 public Ike3gppExtension( 54 @NonNull Ike3gppParams ike3gppParams, 55 @NonNull Ike3gppDataListener ike3gppDataListener) { 56 Objects.requireNonNull(ike3gppParams, "ike3gppParams must not be null"); 57 Objects.requireNonNull(ike3gppDataListener, "ike3gppDataListener must not be null"); 58 59 mIke3gppParams = ike3gppParams; 60 mIke3gppDataListener = ike3gppDataListener; 61 } 62 63 /** Retrieves the configured Ike3gppDataListener. */ 64 @NonNull getIke3gppDataListener()65 public Ike3gppDataListener getIke3gppDataListener() { 66 return mIke3gppDataListener; 67 } 68 69 /** Retrieves the configured Ike3gppParams. */ 70 @NonNull getIke3gppParams()71 public Ike3gppParams getIke3gppParams() { 72 return mIke3gppParams; 73 } 74 75 @Override hashCode()76 public int hashCode() { 77 return Objects.hash(mIke3gppParams, mIke3gppDataListener); 78 } 79 80 @Override equals(Object o)81 public boolean equals(Object o) { 82 if (!(o instanceof Ike3gppExtension)) { 83 return false; 84 } 85 86 Ike3gppExtension other = (Ike3gppExtension) o; 87 88 return mIke3gppParams.equals(other.mIke3gppParams) 89 && mIke3gppDataListener.equals(other.mIke3gppDataListener); 90 } 91 92 /** 93 * Listener for receiving 3GPP-specific data. 94 * 95 * <p>MUST be unique to each IKE Session. 96 * 97 * <p>All Ike3gppDataListener calls will be invoked on the Executor provided in the IkeSession 98 * constructor. 99 */ 100 public interface Ike3gppDataListener { 101 /** 102 * Invoked when the IKE Session receives 3GPP-specific data. 103 * 104 * <p>This function will be invoked at most once for each IKE Message received by the IKEv2 105 * library. 106 * 107 * @param ike3gppDataList List<Ike3gppData> the 3GPP-data received 108 */ onIke3gppDataReceived(@onNull List<Ike3gppData> ike3gppDataList)109 void onIke3gppDataReceived(@NonNull List<Ike3gppData> ike3gppDataList); 110 } 111 } 112