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; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.net.Network; 22 23 import java.net.InetAddress; 24 import java.util.Objects; 25 26 /** 27 * IkeSessionConnectionInfo represents the connection information of a {@link IkeSession}. 28 * 29 * <p>Connection information includes IP addresses of both the IKE client and server and the network 30 * being used. 31 * 32 * @hide 33 */ 34 @SystemApi 35 public final class IkeSessionConnectionInfo { 36 private final InetAddress mLocalAddress; 37 private final InetAddress mRemoteAddress; 38 private final Network mNetwork; 39 40 /** 41 * Construct an instance of {@link IkeSessionConnectionInfo}. 42 * 43 * @hide 44 */ IkeSessionConnectionInfo( InetAddress localAddress, InetAddress remoteAddress, Network network)45 public IkeSessionConnectionInfo( 46 InetAddress localAddress, InetAddress remoteAddress, Network network) { 47 Objects.requireNonNull(localAddress, "localAddress not provided"); 48 Objects.requireNonNull(remoteAddress, "remoteAddress not provided"); 49 Objects.requireNonNull(network, "network not provided"); 50 51 mLocalAddress = localAddress; 52 mRemoteAddress = remoteAddress; 53 mNetwork = network; 54 } 55 56 /** 57 * Returns the local IP address for the underlying {@link Network} being used. 58 * 59 * @return the local IP address. 60 */ 61 @NonNull getLocalAddress()62 public InetAddress getLocalAddress() { 63 return mLocalAddress; 64 } 65 66 /** 67 * Returns the remote IP address for the underlying {@link Network} being used. 68 * 69 * @return the remote IP address. 70 */ 71 @NonNull getRemoteAddress()72 public InetAddress getRemoteAddress() { 73 return mRemoteAddress; 74 } 75 76 /** 77 * Returns the underlying {@link Network} being used. 78 * 79 * @return the underlying {@link Network} that carries all IKE traffic. 80 */ 81 @NonNull getNetwork()82 public Network getNetwork() { 83 return mNetwork; 84 } 85 } 86