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 com.android.networkstack.tethering; 17 18 import static android.net.INetd.IPSEC_INTERFACE_PREFIX; 19 20 import android.net.LinkProperties; 21 import android.net.Network; 22 import android.net.NetworkCapabilities; 23 24 import androidx.annotation.NonNull; 25 26 /** 27 * Snapshot of tethering upstream network state. 28 */ 29 public class UpstreamNetworkState { 30 /** {@link LinkProperties}. */ 31 public final LinkProperties linkProperties; 32 /** {@link NetworkCapabilities}. */ 33 public final NetworkCapabilities networkCapabilities; 34 /** {@link Network}. */ 35 public final Network network; 36 37 /** Constructs a new UpstreamNetworkState. */ UpstreamNetworkState(LinkProperties linkProperties, NetworkCapabilities networkCapabilities, Network network)38 public UpstreamNetworkState(LinkProperties linkProperties, 39 NetworkCapabilities networkCapabilities, Network network) { 40 this.linkProperties = linkProperties; 41 this.networkCapabilities = networkCapabilities; 42 this.network = network; 43 } 44 45 @NonNull 46 @Override toString()47 public String toString() { 48 return String.format("UpstreamNetworkState{%s, %s, %s}", 49 network == null ? "null" : network, 50 networkCapabilities == null ? "null" : networkCapabilities, 51 linkProperties == null ? "null" : linkProperties); 52 } 53 54 /** Check whether the interface is VCN. */ isVcnInterface(@onNull String iface)55 public static boolean isVcnInterface(@NonNull String iface) { 56 return iface.startsWith(IPSEC_INTERFACE_PREFIX); 57 } 58 } 59