Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1 | /* |
Wink Saville | 6e80997 | 2010-09-21 09:15:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 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; |
| 18 | |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
paulhu | 7610bc7 | 2018-12-12 17:52:57 +0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Artur Satayev | 2695800 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 23 | import android.compat.annotation.UnsupportedAppUsage; |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 24 | import android.net.util.LinkPropertiesUtils; |
| 25 | import android.net.util.LinkPropertiesUtils.CompareResult; |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 26 | import android.os.Build; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 27 | import android.os.Parcel; |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 28 | import android.os.Parcelable; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 29 | import android.text.TextUtils; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 30 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 31 | import java.net.Inet4Address; |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 32 | import java.net.Inet6Address; |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 33 | import java.net.InetAddress; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 34 | import java.net.UnknownHostException; |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.Collection; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 37 | import java.util.Collections; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 38 | import java.util.Hashtable; |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 39 | import java.util.List; |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 40 | import java.util.Objects; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 41 | import java.util.StringJoiner; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 44 | * Describes the properties of a network link. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 45 | * |
| 46 | * A link represents a connection to a network. |
| 47 | * It may have multiple addresses and multiple gateways, |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 48 | * multiple dns servers but only one http proxy and one |
| 49 | * network interface. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 50 | * |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 51 | * Note that this is just a holder of data. Modifying it |
| 52 | * does not affect live networks. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 53 | * |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 54 | */ |
Robert Greenwalt | e595b97 | 2014-06-12 16:24:38 -0700 | [diff] [blame] | 55 | public final class LinkProperties implements Parcelable { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 56 | // The interface described by the network link. |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 57 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 58 | private String mIfaceName; |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 59 | private final ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>(); |
| 60 | private final ArrayList<InetAddress> mDnses = new ArrayList<>(); |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 61 | // PCSCF addresses are addresses of SIP proxies that only exist for the IMS core service. |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 62 | private final ArrayList<InetAddress> mPcscfs = new ArrayList<InetAddress>(); |
| 63 | private final ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>(); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 64 | private boolean mUsePrivateDns; |
| 65 | private String mPrivateDnsServerName; |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 66 | private String mDomains; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 67 | private ArrayList<RouteInfo> mRoutes = new ArrayList<>(); |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 68 | private Inet4Address mDhcpServerAddress; |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 69 | private ProxyInfo mHttpProxy; |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 70 | private int mMtu; |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 71 | // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max" |
| 72 | private String mTcpBufferSizes; |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 73 | private IpPrefix mNat64Prefix; |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 74 | private boolean mWakeOnLanSupported; |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 75 | private Uri mCaptivePortalApiUrl; |
| 76 | private CaptivePortalData mCaptivePortalData; |
| 77 | |
| 78 | /** |
| 79 | * Indicates whether parceling should preserve fields that are set based on permissions of |
| 80 | * the process receiving the {@link LinkProperties}. |
| 81 | */ |
| 82 | private final transient boolean mParcelSensitiveFields; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 83 | |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 84 | private static final int MIN_MTU = 68; |
Benedict Wong | feb69c1 | 2019-11-01 16:45:08 -0700 | [diff] [blame] | 85 | /* package-visibility - Used in other files (such as Ikev2VpnProfile) as minimum iface MTU. */ |
| 86 | static final int MIN_MTU_V6 = 1280; |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 87 | private static final int MAX_MTU = 10000; |
| 88 | |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 89 | private static final int INET6_ADDR_LENGTH = 16; |
| 90 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 91 | // Stores the properties of links that are "stacked" above this link. |
| 92 | // Indexed by interface name to allow modification and to prevent duplicates being added. |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 93 | private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 94 | |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 95 | /** |
| 96 | * @hide |
| 97 | */ |
Artur Satayev | fc46be7 | 2019-11-04 17:50:59 +0000 | [diff] [blame] | 98 | @UnsupportedAppUsage(implicitMember = |
| 99 | "values()[Landroid/net/LinkProperties$ProvisioningChange;") |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 100 | public enum ProvisioningChange { |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 101 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 102 | STILL_NOT_PROVISIONED, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 103 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 104 | LOST_PROVISIONING, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 105 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 106 | GAINED_PROVISIONING, |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 107 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 108 | STILL_PROVISIONED, |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Compare the provisioning states of two LinkProperties instances. |
| 113 | * |
| 114 | * @hide |
| 115 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 116 | @UnsupportedAppUsage |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 117 | public static ProvisioningChange compareProvisioning( |
| 118 | LinkProperties before, LinkProperties after) { |
| 119 | if (before.isProvisioned() && after.isProvisioned()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 120 | // On dual-stack networks, DHCPv4 renewals can occasionally fail. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 121 | // When this happens, IPv6-reachable services continue to function |
| 122 | // normally but IPv4-only services (naturally) fail. |
| 123 | // |
| 124 | // When an application using an IPv4-only service reports a bad |
| 125 | // network condition to the framework, attempts to re-validate |
| 126 | // the network succeed (since we support IPv6-only networks) and |
| 127 | // nothing is changed. |
| 128 | // |
| 129 | // For users, this is confusing and unexpected behaviour, and is |
| 130 | // not necessarily easy to diagnose. Therefore, we treat changing |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 131 | // from a dual-stack network to an IPv6-only network equivalent to |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 132 | // a total loss of provisioning. |
| 133 | // |
| 134 | // For one such example of this, see b/18867306. |
| 135 | // |
Erik Kline | 1ad4e22 | 2015-08-14 12:16:55 +0900 | [diff] [blame] | 136 | // Additionally, losing IPv6 provisioning can result in TCP |
| 137 | // connections getting stuck until timeouts fire and other |
| 138 | // baffling failures. Therefore, loss of either IPv4 or IPv6 on a |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 139 | // previously dual-stack network is deemed a lost of provisioning. |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 140 | if ((before.isIpv4Provisioned() && !after.isIpv4Provisioned()) |
| 141 | || (before.isIpv6Provisioned() && !after.isIpv6Provisioned())) { |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 142 | return ProvisioningChange.LOST_PROVISIONING; |
| 143 | } |
| 144 | return ProvisioningChange.STILL_PROVISIONED; |
| 145 | } else if (before.isProvisioned() && !after.isProvisioned()) { |
| 146 | return ProvisioningChange.LOST_PROVISIONING; |
| 147 | } else if (!before.isProvisioned() && after.isProvisioned()) { |
| 148 | return ProvisioningChange.GAINED_PROVISIONING; |
| 149 | } else { // !before.isProvisioned() && !after.isProvisioned() |
| 150 | return ProvisioningChange.STILL_NOT_PROVISIONED; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 155 | * Constructs a new {@code LinkProperties} with default values. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 156 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 157 | public LinkProperties() { |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 158 | mParcelSensitiveFields = false; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Sreeram Ramachandran | cc91c7b | 2014-06-03 18:41:43 -0700 | [diff] [blame] | 161 | /** |
| 162 | * @hide |
| 163 | */ |
Remi NGUYEN VAN | 299a7cc | 2019-01-23 21:35:52 +0900 | [diff] [blame] | 164 | @SystemApi |
| 165 | @TestApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 166 | public LinkProperties(@Nullable LinkProperties source) { |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 167 | this(source, false /* parcelSensitiveFields */); |
| 168 | } |
| 169 | |
Automerger Merge Worker | 0acf910 | 2020-03-17 16:02:25 +0000 | [diff] [blame] | 170 | /** |
| 171 | * Create a copy of a {@link LinkProperties} that may preserve fields that were set |
| 172 | * based on the permissions of the process that originally received it. |
| 173 | * |
| 174 | * <p>By default {@link LinkProperties} does not preserve such fields during parceling, as |
| 175 | * they should not be shared outside of the process that receives them without appropriate |
| 176 | * checks. |
| 177 | * @param parcelSensitiveFields Whether the sensitive fields should be kept when parceling |
| 178 | * @hide |
| 179 | */ |
| 180 | @SystemApi |
| 181 | @TestApi |
| 182 | public LinkProperties(@Nullable LinkProperties source, boolean parcelSensitiveFields) { |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 183 | mParcelSensitiveFields = parcelSensitiveFields; |
| 184 | if (source == null) return; |
| 185 | mIfaceName = source.mIfaceName; |
| 186 | mLinkAddresses.addAll(source.mLinkAddresses); |
| 187 | mDnses.addAll(source.mDnses); |
| 188 | mValidatedPrivateDnses.addAll(source.mValidatedPrivateDnses); |
| 189 | mUsePrivateDns = source.mUsePrivateDns; |
| 190 | mPrivateDnsServerName = source.mPrivateDnsServerName; |
| 191 | mPcscfs.addAll(source.mPcscfs); |
| 192 | mDomains = source.mDomains; |
| 193 | mRoutes.addAll(source.mRoutes); |
| 194 | mHttpProxy = (source.mHttpProxy == null) ? null : new ProxyInfo(source.mHttpProxy); |
| 195 | for (LinkProperties l: source.mStackedLinks.values()) { |
| 196 | addStackedLink(l); |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 197 | } |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 198 | setMtu(source.mMtu); |
| 199 | setDhcpServerAddress(source.getDhcpServerAddress()); |
| 200 | mTcpBufferSizes = source.mTcpBufferSizes; |
| 201 | mNat64Prefix = source.mNat64Prefix; |
| 202 | mWakeOnLanSupported = source.mWakeOnLanSupported; |
| 203 | mCaptivePortalApiUrl = source.mCaptivePortalApiUrl; |
| 204 | mCaptivePortalData = source.mCaptivePortalData; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 207 | /** |
| 208 | * Sets the interface name for this link. All {@link RouteInfo} already set for this |
| 209 | * will have their interface changed to match this new value. |
| 210 | * |
| 211 | * @param iface The name of the network interface used for this link. |
| 212 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 213 | public void setInterfaceName(@Nullable String iface) { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 214 | mIfaceName = iface; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 215 | ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size()); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 216 | for (RouteInfo route : mRoutes) { |
| 217 | newRoutes.add(routeWithInterface(route)); |
| 218 | } |
| 219 | mRoutes = newRoutes; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 222 | /** |
| 223 | * Gets the interface name for this link. May be {@code null} if not set. |
| 224 | * |
| 225 | * @return The interface name set for this link or {@code null}. |
| 226 | */ |
Jeff Sharkey | 9da2f1e | 2014-08-14 12:55:00 -0700 | [diff] [blame] | 227 | public @Nullable String getInterfaceName() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 228 | return mIfaceName; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 229 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 230 | |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 231 | /** |
| 232 | * @hide |
| 233 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 234 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 235 | public @NonNull List<String> getAllInterfaceNames() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 236 | List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1); |
| 237 | if (mIfaceName != null) interfaceNames.add(mIfaceName); |
Lorenzo Colitti | 4aa9bcf | 2013-03-20 19:22:58 +0900 | [diff] [blame] | 238 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 239 | interfaceNames.addAll(stacked.getAllInterfaceNames()); |
| 240 | } |
| 241 | return interfaceNames; |
| 242 | } |
| 243 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 244 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 245 | * Returns all the addresses on this link. We often think of a link having a single address, |
| 246 | * however, particularly with Ipv6 several addresses are typical. Note that the |
| 247 | * {@code LinkProperties} actually contains {@link LinkAddress} objects which also include |
| 248 | * prefix lengths for each address. This is a simplified utility alternative to |
| 249 | * {@link LinkProperties#getLinkAddresses}. |
| 250 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 251 | * @return An unmodifiable {@link List} of {@link InetAddress} for this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 252 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 253 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 254 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 255 | public @NonNull List<InetAddress> getAddresses() { |
| 256 | final List<InetAddress> addresses = new ArrayList<>(); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 257 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 258 | addresses.add(linkAddress.getAddress()); |
| 259 | } |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 260 | return Collections.unmodifiableList(addresses); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 263 | /** |
| 264 | * Returns all the addresses on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 265 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 266 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 267 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 268 | public @NonNull List<InetAddress> getAllAddresses() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 269 | List<InetAddress> addresses = new ArrayList<>(); |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 270 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 271 | addresses.add(linkAddress.getAddress()); |
| 272 | } |
| 273 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 274 | addresses.addAll(stacked.getAllAddresses()); |
| 275 | } |
| 276 | return addresses; |
| 277 | } |
| 278 | |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 279 | private int findLinkAddressIndex(LinkAddress address) { |
| 280 | for (int i = 0; i < mLinkAddresses.size(); i++) { |
| 281 | if (mLinkAddresses.get(i).isSameAddressAs(address)) { |
| 282 | return i; |
| 283 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 284 | } |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 285 | return -1; |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 289 | * Adds a {@link LinkAddress} to this {@code LinkProperties} if a {@link LinkAddress} of the |
| 290 | * same address/prefix does not already exist. If it does exist it is replaced. |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 291 | * @param address The {@code LinkAddress} to add. |
| 292 | * @return true if {@code address} was added or updated, false otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 293 | * @hide |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 294 | */ |
Remi NGUYEN VAN | 5c5f1ba | 2019-01-29 12:08:43 +0900 | [diff] [blame] | 295 | @SystemApi |
| 296 | @TestApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 297 | public boolean addLinkAddress(@NonNull LinkAddress address) { |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 298 | if (address == null) { |
| 299 | return false; |
| 300 | } |
| 301 | int i = findLinkAddressIndex(address); |
| 302 | if (i < 0) { |
| 303 | // Address was not present. Add it. |
| 304 | mLinkAddresses.add(address); |
| 305 | return true; |
| 306 | } else if (mLinkAddresses.get(i).equals(address)) { |
| 307 | // Address was present and has same properties. Do nothing. |
| 308 | return false; |
| 309 | } else { |
| 310 | // Address was present and has different properties. Update it. |
| 311 | mLinkAddresses.set(i, address); |
| 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 317 | * Removes a {@link LinkAddress} from this {@code LinkProperties}. Specifically, matches |
| 318 | * and {@link LinkAddress} with the same address and prefix. |
| 319 | * |
| 320 | * @param toRemove A {@link LinkAddress} specifying the address to remove. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 321 | * @return true if the address was removed, false if it did not exist. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 322 | * @hide |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 323 | */ |
Remi NGUYEN VAN | 5c5f1ba | 2019-01-29 12:08:43 +0900 | [diff] [blame] | 324 | @SystemApi |
| 325 | @TestApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 326 | public boolean removeLinkAddress(@NonNull LinkAddress toRemove) { |
Lorenzo Colitti | 6448394 | 2013-11-15 18:43:52 +0900 | [diff] [blame] | 327 | int i = findLinkAddressIndex(toRemove); |
| 328 | if (i >= 0) { |
| 329 | mLinkAddresses.remove(i); |
| 330 | return true; |
| 331 | } |
| 332 | return false; |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 335 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 336 | * Returns all the {@link LinkAddress} on this link. Typically a link will have |
| 337 | * one IPv4 address and one or more IPv6 addresses. |
| 338 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 339 | * @return An unmodifiable {@link List} of {@link LinkAddress} for this link. |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 340 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 341 | public @NonNull List<LinkAddress> getLinkAddresses() { |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 342 | return Collections.unmodifiableList(mLinkAddresses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 345 | /** |
| 346 | * Returns all the addresses on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 347 | * @hide |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 348 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 349 | @SystemApi |
| 350 | public @NonNull List<LinkAddress> getAllLinkAddresses() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 351 | List<LinkAddress> addresses = new ArrayList<>(mLinkAddresses); |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 352 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 353 | addresses.addAll(stacked.getAllLinkAddresses()); |
| 354 | } |
| 355 | return addresses; |
| 356 | } |
| 357 | |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 358 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 359 | * Replaces the {@link LinkAddress} in this {@code LinkProperties} with |
| 360 | * the given {@link Collection} of {@link LinkAddress}. |
| 361 | * |
| 362 | * @param addresses The {@link Collection} of {@link LinkAddress} to set in this |
| 363 | * object. |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 364 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 365 | public void setLinkAddresses(@NonNull Collection<LinkAddress> addresses) { |
Lorenzo Colitti | 22f407b | 2013-08-23 20:54:49 +0900 | [diff] [blame] | 366 | mLinkAddresses.clear(); |
| 367 | for (LinkAddress address: addresses) { |
| 368 | addLinkAddress(address); |
| 369 | } |
| 370 | } |
| 371 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 372 | /** |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 373 | * Adds the given {@link InetAddress} to the list of DNS servers, if not present. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 374 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 375 | * @param dnsServer The {@link InetAddress} to add to the list of DNS servers. |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 376 | * @return true if the DNS server was added, false if it was already present. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 377 | * @hide |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 378 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 379 | @TestApi |
| 380 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 381 | public boolean addDnsServer(@NonNull InetAddress dnsServer) { |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 382 | if (dnsServer != null && !mDnses.contains(dnsServer)) { |
| 383 | mDnses.add(dnsServer); |
| 384 | return true; |
| 385 | } |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | /** |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 390 | * Removes the given {@link InetAddress} from the list of DNS servers. |
| 391 | * |
| 392 | * @param dnsServer The {@link InetAddress} to remove from the list of DNS servers. |
| 393 | * @return true if the DNS server was removed, false if it did not exist. |
| 394 | * @hide |
| 395 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 396 | @TestApi |
| 397 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 398 | public boolean removeDnsServer(@NonNull InetAddress dnsServer) { |
paulhu | 3d67f53 | 2019-03-22 16:35:06 +0800 | [diff] [blame] | 399 | return mDnses.remove(dnsServer); |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 403 | * Replaces the DNS servers in this {@code LinkProperties} with |
| 404 | * the given {@link Collection} of {@link InetAddress} objects. |
| 405 | * |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 406 | * @param dnsServers The {@link Collection} of DNS servers to set in this object. |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 407 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 408 | public void setDnsServers(@NonNull Collection<InetAddress> dnsServers) { |
Lorenzo Colitti | 309a75d | 2014-06-24 00:34:39 +0900 | [diff] [blame] | 409 | mDnses.clear(); |
| 410 | for (InetAddress dnsServer: dnsServers) { |
| 411 | addDnsServer(dnsServer); |
| 412 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 413 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 414 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 415 | /** |
Sreeram Ramachandran | cc91c7b | 2014-06-03 18:41:43 -0700 | [diff] [blame] | 416 | * Returns all the {@link InetAddress} for DNS servers on this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 417 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 418 | * @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 419 | * this link. |
| 420 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 421 | public @NonNull List<InetAddress> getDnsServers() { |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 422 | return Collections.unmodifiableList(mDnses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 425 | /** |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 426 | * Set whether private DNS is currently in use on this network. |
| 427 | * |
| 428 | * @param usePrivateDns The private DNS state. |
| 429 | * @hide |
| 430 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 431 | @TestApi |
| 432 | @SystemApi |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 433 | public void setUsePrivateDns(boolean usePrivateDns) { |
| 434 | mUsePrivateDns = usePrivateDns; |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Returns whether private DNS is currently in use on this network. When |
| 439 | * private DNS is in use, applications must not send unencrypted DNS |
| 440 | * queries as doing so could reveal private user information. Furthermore, |
| 441 | * if private DNS is in use and {@link #getPrivateDnsServerName} is not |
| 442 | * {@code null}, DNS queries must be sent to the specified DNS server. |
| 443 | * |
| 444 | * @return {@code true} if private DNS is in use, {@code false} otherwise. |
| 445 | */ |
| 446 | public boolean isPrivateDnsActive() { |
| 447 | return mUsePrivateDns; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Set the name of the private DNS server to which private DNS queries |
| 452 | * should be sent when in strict mode. This value should be {@code null} |
| 453 | * when private DNS is off or in opportunistic mode. |
| 454 | * |
| 455 | * @param privateDnsServerName The private DNS server name. |
| 456 | * @hide |
| 457 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 458 | @TestApi |
| 459 | @SystemApi |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 460 | public void setPrivateDnsServerName(@Nullable String privateDnsServerName) { |
| 461 | mPrivateDnsServerName = privateDnsServerName; |
| 462 | } |
| 463 | |
| 464 | /** |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 465 | * Set DHCP server address. |
| 466 | * |
| 467 | * @param serverAddress the server address to set. |
| 468 | */ |
| 469 | public void setDhcpServerAddress(@Nullable Inet4Address serverAddress) { |
| 470 | mDhcpServerAddress = serverAddress; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * Get DHCP server address |
| 475 | * |
| 476 | * @return The current DHCP server address. |
| 477 | */ |
| 478 | public @Nullable Inet4Address getDhcpServerAddress() { |
| 479 | return mDhcpServerAddress; |
| 480 | } |
| 481 | |
| 482 | /** |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 483 | * Returns the private DNS server name that is in use. If not {@code null}, |
| 484 | * private DNS is in strict mode. In this mode, applications should ensure |
| 485 | * that all DNS queries are encrypted and sent to this hostname and that |
| 486 | * queries are only sent if the hostname's certificate is valid. If |
| 487 | * {@code null} and {@link #isPrivateDnsActive} is {@code true}, private |
| 488 | * DNS is in opportunistic mode, and applications should ensure that DNS |
| 489 | * queries are encrypted and sent to a DNS server returned by |
| 490 | * {@link #getDnsServers}. System DNS will handle each of these cases |
| 491 | * correctly, but applications implementing their own DNS lookups must make |
| 492 | * sure to follow these requirements. |
| 493 | * |
| 494 | * @return The private DNS server name. |
| 495 | */ |
| 496 | public @Nullable String getPrivateDnsServerName() { |
| 497 | return mPrivateDnsServerName; |
| 498 | } |
| 499 | |
| 500 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 501 | * Adds the given {@link InetAddress} to the list of validated private DNS servers, |
| 502 | * if not present. This is distinct from the server name in that these are actually |
| 503 | * resolved addresses. |
| 504 | * |
| 505 | * @param dnsServer The {@link InetAddress} to add to the list of validated private DNS servers. |
| 506 | * @return true if the DNS server was added, false if it was already present. |
| 507 | * @hide |
| 508 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 509 | public boolean addValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) { |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 510 | if (dnsServer != null && !mValidatedPrivateDnses.contains(dnsServer)) { |
| 511 | mValidatedPrivateDnses.add(dnsServer); |
| 512 | return true; |
| 513 | } |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Removes the given {@link InetAddress} from the list of validated private DNS servers. |
| 519 | * |
| 520 | * @param dnsServer The {@link InetAddress} to remove from the list of validated private DNS |
| 521 | * servers. |
| 522 | * @return true if the DNS server was removed, false if it did not exist. |
| 523 | * @hide |
| 524 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 525 | public boolean removeValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) { |
| 526 | return mValidatedPrivateDnses.remove(dnsServer); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | /** |
| 530 | * Replaces the validated private DNS servers in this {@code LinkProperties} with |
| 531 | * the given {@link Collection} of {@link InetAddress} objects. |
| 532 | * |
| 533 | * @param dnsServers The {@link Collection} of validated private DNS servers to set in this |
| 534 | * object. |
| 535 | * @hide |
| 536 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 537 | @TestApi |
| 538 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 539 | public void setValidatedPrivateDnsServers(@NonNull Collection<InetAddress> dnsServers) { |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 540 | mValidatedPrivateDnses.clear(); |
| 541 | for (InetAddress dnsServer: dnsServers) { |
| 542 | addValidatedPrivateDnsServer(dnsServer); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Returns all the {@link InetAddress} for validated private DNS servers on this link. |
| 548 | * These are resolved from the private DNS server name. |
| 549 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 550 | * @return An unmodifiable {@link List} of {@link InetAddress} for validated private |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 551 | * DNS servers on this link. |
| 552 | * @hide |
| 553 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 554 | @TestApi |
| 555 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 556 | public @NonNull List<InetAddress> getValidatedPrivateDnsServers() { |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 557 | return Collections.unmodifiableList(mValidatedPrivateDnses); |
| 558 | } |
| 559 | |
| 560 | /** |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 561 | * Adds the given {@link InetAddress} to the list of PCSCF servers, if not present. |
| 562 | * |
| 563 | * @param pcscfServer The {@link InetAddress} to add to the list of PCSCF servers. |
| 564 | * @return true if the PCSCF server was added, false otherwise. |
| 565 | * @hide |
| 566 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 567 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 568 | public boolean addPcscfServer(@NonNull InetAddress pcscfServer) { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 569 | if (pcscfServer != null && !mPcscfs.contains(pcscfServer)) { |
| 570 | mPcscfs.add(pcscfServer); |
| 571 | return true; |
| 572 | } |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Removes the given {@link InetAddress} from the list of PCSCF servers. |
| 578 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 579 | * @param pcscfServer The {@link InetAddress} to remove from the list of PCSCF servers. |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 580 | * @return true if the PCSCF server was removed, false otherwise. |
| 581 | * @hide |
| 582 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 583 | public boolean removePcscfServer(@NonNull InetAddress pcscfServer) { |
| 584 | return mPcscfs.remove(pcscfServer); |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Replaces the PCSCF servers in this {@code LinkProperties} with |
| 589 | * the given {@link Collection} of {@link InetAddress} objects. |
| 590 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 591 | * @param pcscfServers The {@link Collection} of PCSCF servers to set in this object. |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 592 | * @hide |
| 593 | */ |
Remi NGUYEN VAN | 299a7cc | 2019-01-23 21:35:52 +0900 | [diff] [blame] | 594 | @SystemApi |
| 595 | @TestApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 596 | public void setPcscfServers(@NonNull Collection<InetAddress> pcscfServers) { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 597 | mPcscfs.clear(); |
| 598 | for (InetAddress pcscfServer: pcscfServers) { |
| 599 | addPcscfServer(pcscfServer); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Returns all the {@link InetAddress} for PCSCF servers on this link. |
| 605 | * |
| 606 | * @return An unmodifiable {@link List} of {@link InetAddress} for PCSCF servers on |
| 607 | * this link. |
| 608 | * @hide |
| 609 | */ |
Remi NGUYEN VAN | 299a7cc | 2019-01-23 21:35:52 +0900 | [diff] [blame] | 610 | @SystemApi |
| 611 | @TestApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 612 | public @NonNull List<InetAddress> getPcscfServers() { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 613 | return Collections.unmodifiableList(mPcscfs); |
| 614 | } |
| 615 | |
| 616 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 617 | * Sets the DNS domain search path used on this link. |
| 618 | * |
| 619 | * @param domains A {@link String} listing in priority order the comma separated |
| 620 | * domains to search when resolving host names on this link. |
| 621 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 622 | public void setDomains(@Nullable String domains) { |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 623 | mDomains = domains; |
| 624 | } |
| 625 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 626 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 627 | * Get the DNS domains search path set for this link. May be {@code null} if not set. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 628 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 629 | * @return A {@link String} containing the comma separated domains to search when resolving host |
| 630 | * names on this link or {@code null}. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 631 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 632 | public @Nullable String getDomains() { |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 633 | return mDomains; |
| 634 | } |
| 635 | |
| 636 | /** |
| 637 | * Sets the Maximum Transmission Unit size to use on this link. This should not be used |
| 638 | * unless the system default (1500) is incorrect. Values less than 68 or greater than |
| 639 | * 10000 will be ignored. |
| 640 | * |
| 641 | * @param mtu The MTU to use for this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 642 | */ |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 643 | public void setMtu(int mtu) { |
| 644 | mMtu = mtu; |
| 645 | } |
| 646 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 647 | /** |
| 648 | * Gets any non-default MTU size set for this link. Note that if the default is being used |
| 649 | * this will return 0. |
| 650 | * |
| 651 | * @return The mtu value set for this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 652 | */ |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 653 | public int getMtu() { |
| 654 | return mMtu; |
| 655 | } |
| 656 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 657 | /** |
| 658 | * Sets the tcp buffers sizes to be used when this link is the system default. |
| 659 | * Should be of the form "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max". |
| 660 | * |
| 661 | * @param tcpBufferSizes The tcp buffers sizes to use. |
| 662 | * |
| 663 | * @hide |
| 664 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 665 | @TestApi |
| 666 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 667 | public void setTcpBufferSizes(@Nullable String tcpBufferSizes) { |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 668 | mTcpBufferSizes = tcpBufferSizes; |
| 669 | } |
| 670 | |
| 671 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 672 | * Gets the tcp buffer sizes. May be {@code null} if not set. |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 673 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 674 | * @return the tcp buffer sizes to use when this link is the system default or {@code null}. |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 675 | * |
| 676 | * @hide |
| 677 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 678 | @TestApi |
| 679 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 680 | public @Nullable String getTcpBufferSizes() { |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 681 | return mTcpBufferSizes; |
| 682 | } |
| 683 | |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 684 | private RouteInfo routeWithInterface(RouteInfo route) { |
| 685 | return new RouteInfo( |
| 686 | route.getDestination(), |
| 687 | route.getGateway(), |
Lorenzo Colitti | 4b0f8e6 | 2014-09-19 01:49:05 +0900 | [diff] [blame] | 688 | mIfaceName, |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 689 | route.getType(), |
| 690 | route.getMtu()); |
| 691 | } |
| 692 | |
Treehugger Robot | 5dfba4b | 2020-03-24 06:53:37 +0000 | [diff] [blame] | 693 | private int findRouteIndexByRouteKey(RouteInfo route) { |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 694 | for (int i = 0; i < mRoutes.size(); i++) { |
Treehugger Robot | 5dfba4b | 2020-03-24 06:53:37 +0000 | [diff] [blame] | 695 | if (mRoutes.get(i).getRouteKey().equals(route.getRouteKey())) { |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 696 | return i; |
| 697 | } |
| 698 | } |
| 699 | return -1; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 700 | } |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 701 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 702 | /** |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 703 | * Adds a {@link RouteInfo} to this {@code LinkProperties}, if a {@link RouteInfo} |
Treehugger Robot | 5dfba4b | 2020-03-24 06:53:37 +0000 | [diff] [blame] | 704 | * with the same {@link RouteInfo.RouteKey} with different properties |
| 705 | * (e.g., different MTU), it will be updated. If the {@link RouteInfo} had an |
| 706 | * interface name set and that differs from the interface set for this |
| 707 | * {@code LinkProperties} an {@link IllegalArgumentException} will be thrown. |
| 708 | * The proper course is to add either un-named or properly named {@link RouteInfo}. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 709 | * |
| 710 | * @param route A {@link RouteInfo} to add to this object. |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 711 | * @return {@code true} was added or updated, false otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 712 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 713 | public boolean addRoute(@NonNull RouteInfo route) { |
| 714 | String routeIface = route.getInterface(); |
| 715 | if (routeIface != null && !routeIface.equals(mIfaceName)) { |
| 716 | throw new IllegalArgumentException( |
| 717 | "Route added with non-matching interface: " + routeIface |
| 718 | + " vs. " + mIfaceName); |
| 719 | } |
| 720 | route = routeWithInterface(route); |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 721 | |
Treehugger Robot | 5dfba4b | 2020-03-24 06:53:37 +0000 | [diff] [blame] | 722 | int i = findRouteIndexByRouteKey(route); |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 723 | if (i == -1) { |
| 724 | // Route was not present. Add it. |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 725 | mRoutes.add(route); |
| 726 | return true; |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 727 | } else if (mRoutes.get(i).equals(route)) { |
| 728 | // Route was present and has same properties. Do nothing. |
| 729 | return false; |
| 730 | } else { |
| 731 | // Route was present and has different properties. Update it. |
| 732 | mRoutes.set(i, route); |
| 733 | return true; |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 734 | } |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
| 738 | * Removes a {@link RouteInfo} from this {@code LinkProperties}, if present. The route must |
| 739 | * specify an interface and the interface must match the interface of this |
| 740 | * {@code LinkProperties}, or it will not be removed. |
| 741 | * |
Lorenzo Colitti | d86407b | 2020-03-18 07:52:25 +0000 | [diff] [blame] | 742 | * @param route A {@link RouteInfo} specifying the route to remove. |
Lorenzo Colitti | c17a1b9 | 2014-06-12 23:10:17 +0900 | [diff] [blame] | 743 | * @return {@code true} if the route was removed, {@code false} if it was not present. |
| 744 | * |
| 745 | * @hide |
| 746 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 747 | @TestApi |
| 748 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 749 | public boolean removeRoute(@NonNull RouteInfo route) { |
| 750 | return Objects.equals(mIfaceName, route.getInterface()) && mRoutes.remove(route); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 751 | } |
| 752 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 753 | /** |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 754 | * Returns all the {@link RouteInfo} set on this link. |
| 755 | * |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 756 | * @return An unmodifiable {@link List} of {@link RouteInfo} for this link. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 757 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 758 | public @NonNull List<RouteInfo> getRoutes() { |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 759 | return Collections.unmodifiableList(mRoutes); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 762 | /** |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 763 | * Make sure this LinkProperties instance contains routes that cover the local subnet |
| 764 | * of its link addresses. Add any route that is missing. |
| 765 | * @hide |
| 766 | */ |
| 767 | public void ensureDirectlyConnectedRoutes() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 768 | for (LinkAddress addr : mLinkAddresses) { |
Rubin Xu | 1bb5c08 | 2017-09-05 18:40:49 +0100 | [diff] [blame] | 769 | addRoute(new RouteInfo(addr, null, mIfaceName)); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | /** |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 774 | * Returns all the routes on this link and all the links stacked above it. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 775 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 776 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 777 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 778 | public @NonNull List<RouteInfo> getAllRoutes() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 779 | List<RouteInfo> routes = new ArrayList<>(mRoutes); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 780 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 781 | routes.addAll(stacked.getAllRoutes()); |
| 782 | } |
Robert Greenwalt | 6629bcd | 2013-03-15 11:28:50 -0700 | [diff] [blame] | 783 | return routes; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 786 | /** |
| 787 | * Sets the recommended {@link ProxyInfo} to use on this link, or {@code null} for none. |
| 788 | * Note that Http Proxies are only a hint - the system recommends their use, but it does |
| 789 | * not enforce it and applications may ignore them. |
| 790 | * |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 791 | * @param proxy A {@link ProxyInfo} defining the HTTP Proxy to use on this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 792 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 793 | public void setHttpProxy(@Nullable ProxyInfo proxy) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 794 | mHttpProxy = proxy; |
| 795 | } |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 796 | |
| 797 | /** |
| 798 | * Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link. |
| 799 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 800 | * @return The {@link ProxyInfo} set on this link or {@code null}. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 801 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 802 | public @Nullable ProxyInfo getHttpProxy() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 803 | return mHttpProxy; |
| 804 | } |
| 805 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 806 | /** |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 807 | * Returns the NAT64 prefix in use on this link, if any. |
| 808 | * |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 809 | * @return the NAT64 prefix or {@code null}. |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 810 | */ |
| 811 | public @Nullable IpPrefix getNat64Prefix() { |
| 812 | return mNat64Prefix; |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Sets the NAT64 prefix in use on this link. |
| 817 | * |
| 818 | * Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 819 | * 128-bit IPv6 address) are supported or {@code null} for no prefix. |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 820 | * |
| 821 | * @param prefix the NAT64 prefix. |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 822 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 823 | public void setNat64Prefix(@Nullable IpPrefix prefix) { |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 824 | if (prefix != null && prefix.getPrefixLength() != 96) { |
| 825 | throw new IllegalArgumentException("Only 96-bit prefixes are supported: " + prefix); |
| 826 | } |
| 827 | mNat64Prefix = prefix; // IpPrefix objects are immutable. |
| 828 | } |
| 829 | |
| 830 | /** |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 831 | * Adds a stacked link. |
| 832 | * |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 833 | * If there is already a stacked link with the same interface name as link, |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 834 | * that link is replaced with link. Otherwise, link is added to the list |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 835 | * of stacked links. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 836 | * |
| 837 | * @param link The link to add. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 838 | * @return true if the link was stacked, false otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 839 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 840 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 841 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 842 | public boolean addStackedLink(@NonNull LinkProperties link) { |
| 843 | if (link.getInterfaceName() != null) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 844 | mStackedLinks.put(link.getInterfaceName(), link); |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 845 | return true; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 846 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 847 | return false; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /** |
| 851 | * Removes a stacked link. |
| 852 | * |
Lorenzo Colitti | f3cab63 | 2014-10-20 11:08:03 +0900 | [diff] [blame] | 853 | * If there is a stacked link with the given interface name, it is |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 854 | * removed. Otherwise, nothing changes. |
| 855 | * |
Lorenzo Colitti | f3cab63 | 2014-10-20 11:08:03 +0900 | [diff] [blame] | 856 | * @param iface The interface name of the link to remove. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 857 | * @return true if the link was removed, false otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 858 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 859 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 860 | public boolean removeStackedLink(@NonNull String iface) { |
| 861 | LinkProperties removed = mStackedLinks.remove(iface); |
| 862 | return removed != null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | /** |
| 866 | * Returns all the links stacked on top of this link. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 867 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 868 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 869 | @UnsupportedAppUsage |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 870 | public @NonNull List<LinkProperties> getStackedLinks() { |
| 871 | if (mStackedLinks.isEmpty()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 872 | return Collections.emptyList(); |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 873 | } |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 874 | final List<LinkProperties> stacked = new ArrayList<>(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 875 | for (LinkProperties link : mStackedLinks.values()) { |
Jeff Sharkey | eb2c2c7 | 2014-08-11 15:22:51 -0700 | [diff] [blame] | 876 | stacked.add(new LinkProperties(link)); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 877 | } |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 878 | return Collections.unmodifiableList(stacked); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 879 | } |
| 880 | |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 881 | /** |
| 882 | * Clears this object to its initial state. |
| 883 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 884 | public void clear() { |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 885 | if (mParcelSensitiveFields) { |
| 886 | throw new UnsupportedOperationException( |
| 887 | "Cannot clear LinkProperties when parcelSensitiveFields is set"); |
| 888 | } |
| 889 | |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 890 | mIfaceName = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 891 | mLinkAddresses.clear(); |
| 892 | mDnses.clear(); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 893 | mUsePrivateDns = false; |
| 894 | mPrivateDnsServerName = null; |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 895 | mPcscfs.clear(); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 896 | mDomains = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 897 | mRoutes.clear(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 898 | mHttpProxy = null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 899 | mStackedLinks.clear(); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 900 | mMtu = 0; |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 901 | mDhcpServerAddress = null; |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 902 | mTcpBufferSizes = null; |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 903 | mNat64Prefix = null; |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 904 | mWakeOnLanSupported = false; |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 905 | mCaptivePortalApiUrl = null; |
| 906 | mCaptivePortalData = null; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /** |
| 910 | * Implement the Parcelable interface |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 911 | */ |
| 912 | public int describeContents() { |
| 913 | return 0; |
| 914 | } |
| 915 | |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 916 | @Override |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 917 | public String toString() { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 918 | // Space as a separator, so no need for spaces at start/end of the individual fragments. |
| 919 | final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 920 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 921 | if (mIfaceName != null) { |
| 922 | resultJoiner.add("InterfaceName:"); |
| 923 | resultJoiner.add(mIfaceName); |
| 924 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 925 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 926 | resultJoiner.add("LinkAddresses: ["); |
| 927 | if (!mLinkAddresses.isEmpty()) { |
| 928 | resultJoiner.add(TextUtils.join(",", mLinkAddresses)); |
| 929 | } |
| 930 | resultJoiner.add("]"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 931 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 932 | resultJoiner.add("DnsAddresses: ["); |
| 933 | if (!mDnses.isEmpty()) { |
| 934 | resultJoiner.add(TextUtils.join(",", mDnses)); |
| 935 | } |
| 936 | resultJoiner.add("]"); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 937 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 938 | if (mUsePrivateDns) { |
| 939 | resultJoiner.add("UsePrivateDns: true"); |
| 940 | } |
| 941 | |
Chalard Jean | faaf2fe | 2018-06-07 13:28:09 +0900 | [diff] [blame] | 942 | if (mPrivateDnsServerName != null) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 943 | resultJoiner.add("PrivateDnsServerName:"); |
| 944 | resultJoiner.add(mPrivateDnsServerName); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 945 | } |
| 946 | |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 947 | if (!mPcscfs.isEmpty()) { |
| 948 | resultJoiner.add("PcscfAddresses: ["); |
| 949 | resultJoiner.add(TextUtils.join(",", mPcscfs)); |
| 950 | resultJoiner.add("]"); |
| 951 | } |
| 952 | |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 953 | if (!mValidatedPrivateDnses.isEmpty()) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 954 | final StringJoiner validatedPrivateDnsesJoiner = |
| 955 | new StringJoiner(",", "ValidatedPrivateDnsAddresses: [", "]"); |
| 956 | for (final InetAddress addr : mValidatedPrivateDnses) { |
| 957 | validatedPrivateDnsesJoiner.add(addr.getHostAddress()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 958 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 959 | resultJoiner.add(validatedPrivateDnsesJoiner.toString()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 960 | } |
| 961 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 962 | resultJoiner.add("Domains:"); |
| 963 | resultJoiner.add(mDomains); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 964 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 965 | resultJoiner.add("MTU:"); |
| 966 | resultJoiner.add(Integer.toString(mMtu)); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 967 | |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 968 | if (mWakeOnLanSupported) { |
| 969 | resultJoiner.add("WakeOnLanSupported: true"); |
| 970 | } |
| 971 | |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 972 | if (mDhcpServerAddress != null) { |
| 973 | resultJoiner.add("ServerAddress:"); |
| 974 | resultJoiner.add(mDhcpServerAddress.toString()); |
| 975 | } |
| 976 | |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 977 | if (mCaptivePortalApiUrl != null) { |
| 978 | resultJoiner.add("CaptivePortalApiUrl: " + mCaptivePortalApiUrl); |
| 979 | } |
| 980 | |
| 981 | if (mCaptivePortalData != null) { |
| 982 | resultJoiner.add("CaptivePortalData: " + mCaptivePortalData); |
| 983 | } |
| 984 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 985 | if (mTcpBufferSizes != null) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 986 | resultJoiner.add("TcpBufferSizes:"); |
| 987 | resultJoiner.add(mTcpBufferSizes); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 990 | resultJoiner.add("Routes: ["); |
| 991 | if (!mRoutes.isEmpty()) { |
| 992 | resultJoiner.add(TextUtils.join(",", mRoutes)); |
| 993 | } |
| 994 | resultJoiner.add("]"); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 995 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 996 | if (mHttpProxy != null) { |
| 997 | resultJoiner.add("HttpProxy:"); |
| 998 | resultJoiner.add(mHttpProxy.toString()); |
| 999 | } |
| 1000 | |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1001 | if (mNat64Prefix != null) { |
| 1002 | resultJoiner.add("Nat64Prefix:"); |
| 1003 | resultJoiner.add(mNat64Prefix.toString()); |
| 1004 | } |
| 1005 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1006 | final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values(); |
| 1007 | if (!stackedLinksValues.isEmpty()) { |
| 1008 | final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]"); |
| 1009 | for (final LinkProperties lp : stackedLinksValues) { |
| 1010 | stackedLinksJoiner.add("[ " + lp + " ]"); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1011 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1012 | resultJoiner.add(stackedLinksJoiner.toString()); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1013 | } |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1014 | |
| 1015 | return resultJoiner.toString(); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | /** |
| 1019 | * Returns true if this link has an IPv4 address. |
| 1020 | * |
| 1021 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 1022 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1023 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1024 | @TestApi |
| 1025 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1026 | public boolean hasIpv4Address() { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1027 | for (LinkAddress address : mLinkAddresses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 1028 | if (address.getAddress() instanceof Inet4Address) { |
| 1029 | return true; |
| 1030 | } |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1031 | } |
| 1032 | return false; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1035 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1036 | * For backward compatibility. |
| 1037 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1038 | * just yet. |
| 1039 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
| 1040 | * @hide |
| 1041 | */ |
| 1042 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1043 | public boolean hasIPv4Address() { |
| 1044 | return hasIpv4Address(); |
| 1045 | } |
| 1046 | |
| 1047 | /** |
Lorenzo Colitti | 87cfc70 | 2015-07-27 16:35:33 +0900 | [diff] [blame] | 1048 | * Returns true if this link or any of its stacked interfaces has an IPv4 address. |
| 1049 | * |
| 1050 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
| 1051 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1052 | private boolean hasIpv4AddressOnInterface(String iface) { |
Lorenzo Colitti | 89b6392 | 2015-07-30 23:41:43 +0900 | [diff] [blame] | 1053 | // mIfaceName can be null. |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1054 | return (Objects.equals(iface, mIfaceName) && hasIpv4Address()) |
| 1055 | || (iface != null && mStackedLinks.containsKey(iface) |
| 1056 | && mStackedLinks.get(iface).hasIpv4Address()); |
Lorenzo Colitti | 87cfc70 | 2015-07-27 16:35:33 +0900 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1060 | * Returns true if this link has a global preferred IPv6 address. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 1061 | * |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1062 | * @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise. |
Robert Greenwalt | df2b878 | 2014-06-06 10:30:11 -0700 | [diff] [blame] | 1063 | * @hide |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 1064 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1065 | @TestApi |
| 1066 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1067 | public boolean hasGlobalIpv6Address() { |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 1068 | for (LinkAddress address : mLinkAddresses) { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1069 | if (address.getAddress() instanceof Inet6Address && address.isGlobalPreferred()) { |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame] | 1070 | return true; |
| 1071 | } |
| 1072 | } |
| 1073 | return false; |
| 1074 | } |
| 1075 | |
| 1076 | /** |
Lorenzo Colitti | 5ccee0c | 2020-04-02 04:50:41 +0000 | [diff] [blame] | 1077 | * Returns true if this link has an IPv4 unreachable default route. |
| 1078 | * |
| 1079 | * @return {@code true} if there is an IPv4 unreachable default route, {@code false} otherwise. |
| 1080 | * @hide |
| 1081 | */ |
| 1082 | public boolean hasIpv4UnreachableDefaultRoute() { |
| 1083 | for (RouteInfo r : mRoutes) { |
| 1084 | if (r.isIPv4UnreachableDefault()) { |
| 1085 | return true; |
| 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1092 | * For backward compatibility. |
| 1093 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1094 | * just yet. |
| 1095 | * @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise. |
| 1096 | * @hide |
| 1097 | */ |
| 1098 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1099 | public boolean hasGlobalIPv6Address() { |
| 1100 | return hasGlobalIpv6Address(); |
| 1101 | } |
| 1102 | |
| 1103 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1104 | * Returns true if this link has an IPv4 default route. |
| 1105 | * |
| 1106 | * @return {@code true} if there is an IPv4 default route, {@code false} otherwise. |
| 1107 | * @hide |
| 1108 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 1109 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1110 | public boolean hasIpv4DefaultRoute() { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1111 | for (RouteInfo r : mRoutes) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 1112 | if (r.isIPv4Default()) { |
| 1113 | return true; |
| 1114 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1115 | } |
| 1116 | return false; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
Lorenzo Colitti | 5ccee0c | 2020-04-02 04:50:41 +0000 | [diff] [blame] | 1120 | * Returns true if this link has an IPv6 unreachable default route. |
| 1121 | * |
| 1122 | * @return {@code true} if there is an IPv6 unreachable default route, {@code false} otherwise. |
| 1123 | * @hide |
| 1124 | */ |
| 1125 | public boolean hasIpv6UnreachableDefaultRoute() { |
| 1126 | for (RouteInfo r : mRoutes) { |
| 1127 | if (r.isIPv6UnreachableDefault()) { |
| 1128 | return true; |
| 1129 | } |
| 1130 | } |
| 1131 | return false; |
| 1132 | } |
| 1133 | |
| 1134 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1135 | * For backward compatibility. |
| 1136 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1137 | * just yet. |
| 1138 | * @return {@code true} if there is an IPv4 default route, {@code false} otherwise. |
| 1139 | * @hide |
| 1140 | */ |
| 1141 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1142 | public boolean hasIPv4DefaultRoute() { |
| 1143 | return hasIpv4DefaultRoute(); |
| 1144 | } |
| 1145 | |
| 1146 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1147 | * Returns true if this link has an IPv6 default route. |
| 1148 | * |
| 1149 | * @return {@code true} if there is an IPv6 default route, {@code false} otherwise. |
| 1150 | * @hide |
| 1151 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1152 | @TestApi |
| 1153 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1154 | public boolean hasIpv6DefaultRoute() { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1155 | for (RouteInfo r : mRoutes) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 1156 | if (r.isIPv6Default()) { |
| 1157 | return true; |
| 1158 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1159 | } |
| 1160 | return false; |
| 1161 | } |
| 1162 | |
| 1163 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1164 | * For backward compatibility. |
| 1165 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1166 | * just yet. |
| 1167 | * @return {@code true} if there is an IPv6 default route, {@code false} otherwise. |
| 1168 | * @hide |
| 1169 | */ |
| 1170 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1171 | public boolean hasIPv6DefaultRoute() { |
| 1172 | return hasIpv6DefaultRoute(); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1176 | * Returns true if this link has an IPv4 DNS server. |
| 1177 | * |
| 1178 | * @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise. |
| 1179 | * @hide |
| 1180 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 1181 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1182 | public boolean hasIpv4DnsServer() { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1183 | for (InetAddress ia : mDnses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 1184 | if (ia instanceof Inet4Address) { |
| 1185 | return true; |
| 1186 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1187 | } |
| 1188 | return false; |
| 1189 | } |
| 1190 | |
| 1191 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1192 | * For backward compatibility. |
| 1193 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1194 | * just yet. |
| 1195 | * @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise. |
| 1196 | * @hide |
| 1197 | */ |
| 1198 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1199 | public boolean hasIPv4DnsServer() { |
| 1200 | return hasIpv4DnsServer(); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1204 | * Returns true if this link has an IPv6 DNS server. |
| 1205 | * |
| 1206 | * @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise. |
| 1207 | * @hide |
| 1208 | */ |
Aaron Huang | 8b322ed | 2019-10-02 20:07:38 +0800 | [diff] [blame] | 1209 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1210 | public boolean hasIpv6DnsServer() { |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1211 | for (InetAddress ia : mDnses) { |
Hugo Benichi | bd87a39 | 2017-10-10 16:29:06 +0900 | [diff] [blame] | 1212 | if (ia instanceof Inet6Address) { |
| 1213 | return true; |
| 1214 | } |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1215 | } |
| 1216 | return false; |
| 1217 | } |
| 1218 | |
| 1219 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1220 | * For backward compatibility. |
| 1221 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1222 | * just yet. |
| 1223 | * @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise. |
| 1224 | * @hide |
| 1225 | */ |
| 1226 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1227 | public boolean hasIPv6DnsServer() { |
| 1228 | return hasIpv6DnsServer(); |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1232 | * Returns true if this link has an IPv4 PCSCF server. |
| 1233 | * |
| 1234 | * @return {@code true} if there is an IPv4 PCSCF server, {@code false} otherwise. |
| 1235 | * @hide |
| 1236 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1237 | public boolean hasIpv4PcscfServer() { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1238 | for (InetAddress ia : mPcscfs) { |
| 1239 | if (ia instanceof Inet4Address) { |
| 1240 | return true; |
| 1241 | } |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Returns true if this link has an IPv6 PCSCF server. |
| 1248 | * |
| 1249 | * @return {@code true} if there is an IPv6 PCSCF server, {@code false} otherwise. |
| 1250 | * @hide |
| 1251 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1252 | public boolean hasIpv6PcscfServer() { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1253 | for (InetAddress ia : mPcscfs) { |
| 1254 | if (ia instanceof Inet6Address) { |
| 1255 | return true; |
| 1256 | } |
| 1257 | } |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | /** |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1262 | * Returns true if this link is provisioned for global IPv4 connectivity. |
| 1263 | * This requires an IP address, default route, and DNS server. |
| 1264 | * |
| 1265 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 1266 | * @hide |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1267 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1268 | @TestApi |
| 1269 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1270 | public boolean isIpv4Provisioned() { |
| 1271 | return (hasIpv4Address() |
| 1272 | && hasIpv4DefaultRoute() |
| 1273 | && hasIpv4DnsServer()); |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /** |
| 1277 | * Returns true if this link is provisioned for global IPv6 connectivity. |
| 1278 | * This requires an IP address, default route, and DNS server. |
| 1279 | * |
| 1280 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
Erik Kline | cd7ed16 | 2015-05-21 16:15:02 +0900 | [diff] [blame] | 1281 | * @hide |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1282 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1283 | @TestApi |
| 1284 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1285 | public boolean isIpv6Provisioned() { |
| 1286 | return (hasGlobalIpv6Address() |
| 1287 | && hasIpv6DefaultRoute() |
| 1288 | && hasIpv6DnsServer()); |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1292 | * For backward compatibility. |
| 1293 | * This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely |
| 1294 | * just yet. |
| 1295 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
| 1296 | * @hide |
| 1297 | */ |
| 1298 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
| 1299 | public boolean isIPv6Provisioned() { |
| 1300 | return isIpv6Provisioned(); |
| 1301 | } |
| 1302 | |
| 1303 | |
| 1304 | /** |
Erik Kline | d3b9fd3 | 2014-10-24 21:50:20 +0900 | [diff] [blame] | 1305 | * Returns true if this link is provisioned for global connectivity, |
| 1306 | * for at least one Internet Protocol family. |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1307 | * |
| 1308 | * @return {@code true} if the link is provisioned, {@code false} otherwise. |
| 1309 | * @hide |
| 1310 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1311 | @TestApi |
| 1312 | @SystemApi |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1313 | public boolean isProvisioned() { |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1314 | return (isIpv4Provisioned() || isIpv6Provisioned()); |
Lorenzo Colitti | 76ea6c6 | 2014-06-23 22:33:43 +0900 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /** |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1318 | * Evaluate whether the {@link InetAddress} is considered reachable. |
| 1319 | * |
| 1320 | * @return {@code true} if the given {@link InetAddress} is considered reachable, |
| 1321 | * {@code false} otherwise. |
| 1322 | * @hide |
| 1323 | */ |
Remi NGUYEN VAN | 94a0557 | 2019-01-20 12:38:10 +0900 | [diff] [blame] | 1324 | @TestApi |
| 1325 | @SystemApi |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1326 | public boolean isReachable(@NonNull InetAddress ip) { |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1327 | final List<RouteInfo> allRoutes = getAllRoutes(); |
| 1328 | // If we don't have a route to this IP address, it's not reachable. |
| 1329 | final RouteInfo bestRoute = RouteInfo.selectBestRoute(allRoutes, ip); |
| 1330 | if (bestRoute == null) { |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | // TODO: better source address evaluation for destination addresses. |
| 1335 | |
| 1336 | if (ip instanceof Inet4Address) { |
| 1337 | // For IPv4, it suffices for now to simply have any address. |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1338 | return hasIpv4AddressOnInterface(bestRoute.getInterface()); |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1339 | } else if (ip instanceof Inet6Address) { |
| 1340 | if (ip.isLinkLocalAddress()) { |
| 1341 | // For now, just make sure link-local destinations have |
| 1342 | // scopedIds set, since transmits will generally fail otherwise. |
| 1343 | // TODO: verify it matches the ifindex of one of the interfaces. |
| 1344 | return (((Inet6Address)ip).getScopeId() != 0); |
| 1345 | } else { |
| 1346 | // For non-link-local destinations check that either the best route |
| 1347 | // is directly connected or that some global preferred address exists. |
| 1348 | // TODO: reconsider all cases (disconnected ULA networks, ...). |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1349 | return (!bestRoute.hasGateway() || hasGlobalIpv6Address()); |
Erik Kline | b36a313 | 2015-06-26 19:21:34 +0900 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | return false; |
| 1354 | } |
| 1355 | |
| 1356 | /** |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1357 | * Compares this {@code LinkProperties} interface name against the target |
| 1358 | * |
| 1359 | * @param target LinkProperties to compare. |
| 1360 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1361 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1362 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1363 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1364 | public boolean isIdenticalInterfaceName(@NonNull LinkProperties target) { |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 1365 | return LinkPropertiesUtils.isIdenticalInterfaceName(target, this); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | /** |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 1369 | * Compares this {@code LinkProperties} DHCP server address against the target |
| 1370 | * |
| 1371 | * @param target LinkProperties to compare. |
| 1372 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1373 | * @hide |
| 1374 | */ |
| 1375 | public boolean isIdenticalDhcpServerAddress(@NonNull LinkProperties target) { |
| 1376 | return Objects.equals(mDhcpServerAddress, target.mDhcpServerAddress); |
| 1377 | } |
| 1378 | |
| 1379 | /** |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1380 | * Compares this {@code LinkProperties} interface addresses against the target |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1381 | * |
| 1382 | * @param target LinkProperties to compare. |
| 1383 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1384 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1385 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1386 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1387 | public boolean isIdenticalAddresses(@NonNull LinkProperties target) { |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 1388 | return LinkPropertiesUtils.isIdenticalAddresses(target, this); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | /** |
| 1392 | * Compares this {@code LinkProperties} DNS addresses against the target |
| 1393 | * |
| 1394 | * @param target LinkProperties to compare. |
| 1395 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1396 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1397 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1398 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1399 | public boolean isIdenticalDnses(@NonNull LinkProperties target) { |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 1400 | return LinkPropertiesUtils.isIdenticalDnses(target, this); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | /** |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1404 | * Compares this {@code LinkProperties} private DNS settings against the |
| 1405 | * target. |
| 1406 | * |
| 1407 | * @param target LinkProperties to compare. |
| 1408 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1409 | * @hide |
| 1410 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1411 | public boolean isIdenticalPrivateDns(@NonNull LinkProperties target) { |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1412 | return (isPrivateDnsActive() == target.isPrivateDnsActive() |
| 1413 | && TextUtils.equals(getPrivateDnsServerName(), |
| 1414 | target.getPrivateDnsServerName())); |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1418 | * Compares this {@code LinkProperties} validated private DNS addresses against |
| 1419 | * the target |
| 1420 | * |
| 1421 | * @param target LinkProperties to compare. |
| 1422 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1423 | * @hide |
| 1424 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1425 | public boolean isIdenticalValidatedPrivateDnses(@NonNull LinkProperties target) { |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1426 | Collection<InetAddress> targetDnses = target.getValidatedPrivateDnsServers(); |
| 1427 | return (mValidatedPrivateDnses.size() == targetDnses.size()) |
| 1428 | ? mValidatedPrivateDnses.containsAll(targetDnses) : false; |
| 1429 | } |
| 1430 | |
| 1431 | /** |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1432 | * Compares this {@code LinkProperties} PCSCF addresses against the target |
| 1433 | * |
| 1434 | * @param target LinkProperties to compare. |
| 1435 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1436 | * @hide |
| 1437 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1438 | public boolean isIdenticalPcscfs(@NonNull LinkProperties target) { |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1439 | Collection<InetAddress> targetPcscfs = target.getPcscfServers(); |
| 1440 | return (mPcscfs.size() == targetPcscfs.size()) ? |
| 1441 | mPcscfs.containsAll(targetPcscfs) : false; |
| 1442 | } |
| 1443 | |
| 1444 | /** |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1445 | * Compares this {@code LinkProperties} Routes against the target |
| 1446 | * |
| 1447 | * @param target LinkProperties to compare. |
| 1448 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1449 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1450 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1451 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1452 | public boolean isIdenticalRoutes(@NonNull LinkProperties target) { |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 1453 | return LinkPropertiesUtils.isIdenticalRoutes(target, this); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Compares this {@code LinkProperties} HttpProxy against the target |
| 1458 | * |
| 1459 | * @param target LinkProperties to compare. |
| 1460 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1461 | * @hide |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1462 | */ |
Mathew Inwood | 55418ea | 2018-12-20 15:30:45 +0000 | [diff] [blame] | 1463 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1464 | public boolean isIdenticalHttpProxy(@NonNull LinkProperties target) { |
Aaron Huang | 94df39a | 2019-12-17 00:33:18 +0800 | [diff] [blame] | 1465 | return LinkPropertiesUtils.isIdenticalHttpProxy(target, this); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1466 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1467 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1468 | /** |
| 1469 | * Compares this {@code LinkProperties} stacked links against the target |
| 1470 | * |
| 1471 | * @param target LinkProperties to compare. |
| 1472 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1473 | * @hide |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1474 | */ |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 1475 | @UnsupportedAppUsage |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1476 | public boolean isIdenticalStackedLinks(@NonNull LinkProperties target) { |
Lorenzo Colitti | 213f98b | 2013-04-01 10:47:43 +0900 | [diff] [blame] | 1477 | if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1478 | return false; |
| 1479 | } |
| 1480 | for (LinkProperties stacked : mStackedLinks.values()) { |
| 1481 | // Hashtable values can never be null. |
| 1482 | String iface = stacked.getInterfaceName(); |
| 1483 | if (!stacked.equals(target.mStackedLinks.get(iface))) { |
| 1484 | return false; |
| 1485 | } |
| 1486 | } |
| 1487 | return true; |
| 1488 | } |
| 1489 | |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1490 | /** |
| 1491 | * Compares this {@code LinkProperties} MTU against the target |
| 1492 | * |
Ying Wang | d57de6a | 2013-09-06 22:53:16 -0700 | [diff] [blame] | 1493 | * @param target LinkProperties to compare. |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1494 | * @return {@code true} if both are identical, {@code false} otherwise. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1495 | * @hide |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1496 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1497 | public boolean isIdenticalMtu(@NonNull LinkProperties target) { |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1498 | return getMtu() == target.getMtu(); |
| 1499 | } |
| 1500 | |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1501 | /** |
| 1502 | * Compares this {@code LinkProperties} Tcp buffer sizes against the target. |
| 1503 | * |
| 1504 | * @param target LinkProperties to compare. |
| 1505 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1506 | * @hide |
| 1507 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1508 | public boolean isIdenticalTcpBufferSizes(@NonNull LinkProperties target) { |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1509 | return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes); |
| 1510 | } |
| 1511 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1512 | /** |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1513 | * Compares this {@code LinkProperties} NAT64 prefix against the target. |
| 1514 | * |
| 1515 | * @param target LinkProperties to compare. |
| 1516 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1517 | * @hide |
| 1518 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1519 | public boolean isIdenticalNat64Prefix(@NonNull LinkProperties target) { |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1520 | return Objects.equals(mNat64Prefix, target.mNat64Prefix); |
| 1521 | } |
| 1522 | |
| 1523 | /** |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1524 | * Compares this {@code LinkProperties} WakeOnLan supported against the target. |
| 1525 | * |
| 1526 | * @param target LinkProperties to compare. |
| 1527 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1528 | * @hide |
| 1529 | */ |
| 1530 | public boolean isIdenticalWakeOnLan(LinkProperties target) { |
| 1531 | return isWakeOnLanSupported() == target.isWakeOnLanSupported(); |
| 1532 | } |
| 1533 | |
| 1534 | /** |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1535 | * Compares this {@code LinkProperties}'s CaptivePortalApiUrl against the target. |
| 1536 | * |
| 1537 | * @param target LinkProperties to compare. |
| 1538 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1539 | * @hide |
| 1540 | */ |
| 1541 | public boolean isIdenticalCaptivePortalApiUrl(LinkProperties target) { |
| 1542 | return Objects.equals(mCaptivePortalApiUrl, target.mCaptivePortalApiUrl); |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * Compares this {@code LinkProperties}'s CaptivePortalData against the target. |
| 1547 | * |
| 1548 | * @param target LinkProperties to compare. |
| 1549 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 1550 | * @hide |
| 1551 | */ |
| 1552 | public boolean isIdenticalCaptivePortalData(LinkProperties target) { |
| 1553 | return Objects.equals(mCaptivePortalData, target.mCaptivePortalData); |
| 1554 | } |
| 1555 | |
| 1556 | /** |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1557 | * Set whether the network interface supports WakeOnLAN |
| 1558 | * |
| 1559 | * @param supported WakeOnLAN supported value |
| 1560 | * |
| 1561 | * @hide |
| 1562 | */ |
| 1563 | public void setWakeOnLanSupported(boolean supported) { |
| 1564 | mWakeOnLanSupported = supported; |
| 1565 | } |
| 1566 | |
| 1567 | /** |
| 1568 | * Returns whether the network interface supports WakeOnLAN |
| 1569 | * |
| 1570 | * @return {@code true} if interface supports WakeOnLAN, {@code false} otherwise. |
| 1571 | */ |
| 1572 | public boolean isWakeOnLanSupported() { |
| 1573 | return mWakeOnLanSupported; |
| 1574 | } |
| 1575 | |
| 1576 | /** |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1577 | * Set the URL of the captive portal API endpoint to get more information about the network. |
| 1578 | * @hide |
| 1579 | */ |
| 1580 | @SystemApi |
| 1581 | @TestApi |
| 1582 | public void setCaptivePortalApiUrl(@Nullable Uri url) { |
| 1583 | mCaptivePortalApiUrl = url; |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Get the URL of the captive portal API endpoint to get more information about the network. |
| 1588 | * |
| 1589 | * <p>This is null unless the application has |
| 1590 | * {@link android.Manifest.permission.NETWORK_SETTINGS} or |
| 1591 | * {@link NetworkStack#PERMISSION_MAINLINE_NETWORK_STACK} permissions, and the network provided |
| 1592 | * the URL. |
| 1593 | * @hide |
| 1594 | */ |
| 1595 | @SystemApi |
| 1596 | @TestApi |
| 1597 | @Nullable |
| 1598 | public Uri getCaptivePortalApiUrl() { |
| 1599 | return mCaptivePortalApiUrl; |
| 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * Set the CaptivePortalData obtained from the captive portal API (RFC7710bis). |
| 1604 | * @hide |
| 1605 | */ |
| 1606 | @SystemApi |
| 1607 | @TestApi |
| 1608 | public void setCaptivePortalData(@Nullable CaptivePortalData data) { |
| 1609 | mCaptivePortalData = data; |
| 1610 | } |
| 1611 | |
| 1612 | /** |
| 1613 | * Get the CaptivePortalData obtained from the captive portal API (RFC7710bis). |
| 1614 | * |
| 1615 | * <p>This is null unless the application has |
| 1616 | * {@link android.Manifest.permission.NETWORK_SETTINGS} or |
| 1617 | * {@link NetworkStack#PERMISSION_MAINLINE_NETWORK_STACK} permissions. |
| 1618 | * @hide |
| 1619 | */ |
| 1620 | @SystemApi |
| 1621 | @TestApi |
| 1622 | @Nullable |
| 1623 | public CaptivePortalData getCaptivePortalData() { |
| 1624 | return mCaptivePortalData; |
| 1625 | } |
| 1626 | |
| 1627 | /** |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1628 | * Compares this {@code LinkProperties} instance against the target |
| 1629 | * LinkProperties in {@code obj}. Two LinkPropertieses are equal if |
| 1630 | * all their fields are equal in values. |
| 1631 | * |
| 1632 | * For collection fields, such as mDnses, containsAll() is used to check |
| 1633 | * if two collections contains the same elements, independent of order. |
| 1634 | * There are two thoughts regarding containsAll() |
| 1635 | * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal. |
| 1636 | * 2. Worst case performance is O(n^2). |
| 1637 | * |
| 1638 | * @param obj the object to be tested for equality. |
| 1639 | * @return {@code true} if both objects are equal, {@code false} otherwise. |
| 1640 | */ |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1641 | @Override |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1642 | public boolean equals(Object obj) { |
| 1643 | if (this == obj) return true; |
| 1644 | |
| 1645 | if (!(obj instanceof LinkProperties)) return false; |
| 1646 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1647 | LinkProperties target = (LinkProperties) obj; |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1648 | /* |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1649 | * This method does not check that stacked interfaces are equal, because |
| 1650 | * stacked interfaces are not so much a property of the link as a |
| 1651 | * description of connections between links. |
| 1652 | */ |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1653 | return isIdenticalInterfaceName(target) |
| 1654 | && isIdenticalAddresses(target) |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 1655 | && isIdenticalDhcpServerAddress(target) |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1656 | && isIdenticalDnses(target) |
| 1657 | && isIdenticalPrivateDns(target) |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1658 | && isIdenticalValidatedPrivateDnses(target) |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1659 | && isIdenticalPcscfs(target) |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1660 | && isIdenticalRoutes(target) |
| 1661 | && isIdenticalHttpProxy(target) |
| 1662 | && isIdenticalStackedLinks(target) |
| 1663 | && isIdenticalMtu(target) |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1664 | && isIdenticalTcpBufferSizes(target) |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1665 | && isIdenticalNat64Prefix(target) |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1666 | && isIdenticalWakeOnLan(target) |
| 1667 | && isIdenticalCaptivePortalApiUrl(target) |
| 1668 | && isIdenticalCaptivePortalData(target); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1669 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1670 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 1671 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1672 | * Compares the DNS addresses in this LinkProperties with another |
| 1673 | * LinkProperties, examining only DNS addresses on the base link. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1674 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1675 | * @param target a LinkProperties with the new list of dns addresses |
| 1676 | * @return the differences between the DNS addresses. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1677 | * @hide |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1678 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1679 | public @NonNull CompareResult<InetAddress> compareDnses(@Nullable LinkProperties target) { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1680 | /* |
| 1681 | * Duplicate the InetAddresses into removed, we will be removing |
| 1682 | * dns address which are common between mDnses and target |
| 1683 | * leaving the addresses that are different. And dns address which |
| 1684 | * are in target but not in mDnses are placed in the |
| 1685 | * addedAddresses. |
| 1686 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1687 | return new CompareResult<>(mDnses, target != null ? target.getDnsServers() : null); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | /** |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1691 | * Compares the validated private DNS addresses in this LinkProperties with another |
| 1692 | * LinkProperties. |
| 1693 | * |
| 1694 | * @param target a LinkProperties with the new list of validated private dns addresses |
| 1695 | * @return the differences between the DNS addresses. |
| 1696 | * @hide |
| 1697 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1698 | public @NonNull CompareResult<InetAddress> compareValidatedPrivateDnses( |
| 1699 | @Nullable LinkProperties target) { |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1700 | return new CompareResult<>(mValidatedPrivateDnses, |
| 1701 | target != null ? target.getValidatedPrivateDnsServers() : null); |
| 1702 | } |
| 1703 | |
| 1704 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1705 | * Compares all routes in this LinkProperties with another LinkProperties, |
| 1706 | * examining both the the base link and all stacked links. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1707 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 1708 | * @param target a LinkProperties with the new list of routes |
| 1709 | * @return the differences between the routes. |
Robert Greenwalt | 4f05d55 | 2014-05-18 22:01:38 -0700 | [diff] [blame] | 1710 | * @hide |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1711 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1712 | public @NonNull CompareResult<RouteInfo> compareAllRoutes(@Nullable LinkProperties target) { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1713 | /* |
| 1714 | * Duplicate the RouteInfos into removed, we will be removing |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 1715 | * routes which are common between mRoutes and target |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1716 | * leaving the routes that are different. And route address which |
| 1717 | * are in target but not in mRoutes are placed in added. |
| 1718 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1719 | return new CompareResult<>(getAllRoutes(), target != null ? target.getAllRoutes() : null); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
Paul Jensen | 992f252 | 2014-04-28 10:33:11 -0400 | [diff] [blame] | 1722 | /** |
| 1723 | * Compares all interface names in this LinkProperties with another |
| 1724 | * LinkProperties, examining both the the base link and all stacked links. |
| 1725 | * |
| 1726 | * @param target a LinkProperties with the new list of interface names |
| 1727 | * @return the differences between the interface names. |
| 1728 | * @hide |
| 1729 | */ |
paulhu | d9736de | 2019-03-08 16:35:20 +0800 | [diff] [blame] | 1730 | public @NonNull CompareResult<String> compareAllInterfaceNames( |
| 1731 | @Nullable LinkProperties target) { |
Paul Jensen | 992f252 | 2014-04-28 10:33:11 -0400 | [diff] [blame] | 1732 | /* |
| 1733 | * Duplicate the interface names into removed, we will be removing |
| 1734 | * interface names which are common between this and target |
| 1735 | * leaving the interface names that are different. And interface names which |
| 1736 | * are in target but not in this are placed in added. |
| 1737 | */ |
Rubin Xu | 2fc72f7 | 2017-08-22 16:35:52 +0100 | [diff] [blame] | 1738 | return new CompareResult<>(getAllInterfaceNames(), |
| 1739 | target != null ? target.getAllInterfaceNames() : null); |
Paul Jensen | 992f252 | 2014-04-28 10:33:11 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 1742 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1743 | /** |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1744 | * Generate hashcode based on significant fields |
| 1745 | * |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1746 | * Equal objects must produce the same hash code, while unequal objects |
| 1747 | * may have the same hash codes. |
| 1748 | */ |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1749 | @Override |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1750 | public int hashCode() { |
| 1751 | return ((null == mIfaceName) ? 0 : mIfaceName.hashCode() |
| 1752 | + mLinkAddresses.size() * 31 |
| 1753 | + mDnses.size() * 37 |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1754 | + mValidatedPrivateDnses.size() * 61 |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1755 | + ((null == mDomains) ? 0 : mDomains.hashCode()) |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1756 | + mRoutes.size() * 41 |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1757 | + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()) |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1758 | + mStackedLinks.hashCode() * 47) |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1759 | + mMtu * 51 |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1760 | + ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode()) |
| 1761 | + (mUsePrivateDns ? 57 : 0) |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 1762 | + ((null == mDhcpServerAddress) ? 0 : mDhcpServerAddress.hashCode()) |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1763 | + mPcscfs.size() * 67 |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1764 | + ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode()) |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1765 | + Objects.hash(mNat64Prefix) |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1766 | + (mWakeOnLanSupported ? 71 : 0) |
| 1767 | + Objects.hash(mCaptivePortalApiUrl, mCaptivePortalData); |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1770 | /** |
| 1771 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1772 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1773 | public void writeToParcel(Parcel dest, int flags) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1774 | dest.writeString(getInterfaceName()); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1775 | dest.writeInt(mLinkAddresses.size()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1776 | for (LinkAddress linkAddress : mLinkAddresses) { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1777 | dest.writeParcelable(linkAddress, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1778 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 1779 | |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1780 | writeAddresses(dest, mDnses); |
| 1781 | writeAddresses(dest, mValidatedPrivateDnses); |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1782 | dest.writeBoolean(mUsePrivateDns); |
| 1783 | dest.writeString(mPrivateDnsServerName); |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1784 | writeAddresses(dest, mPcscfs); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1785 | dest.writeString(mDomains); |
Lorenzo Colitti | 348577e | 2020-01-06 19:43:59 +0900 | [diff] [blame] | 1786 | writeAddress(dest, mDhcpServerAddress); |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1787 | dest.writeInt(mMtu); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1788 | dest.writeString(mTcpBufferSizes); |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1789 | dest.writeInt(mRoutes.size()); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1790 | for (RouteInfo route : mRoutes) { |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 1791 | dest.writeParcelable(route, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1792 | } |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 1793 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1794 | if (mHttpProxy != null) { |
| 1795 | dest.writeByte((byte)1); |
| 1796 | dest.writeParcelable(mHttpProxy, flags); |
| 1797 | } else { |
| 1798 | dest.writeByte((byte)0); |
| 1799 | } |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1800 | dest.writeParcelable(mNat64Prefix, 0); |
| 1801 | |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1802 | ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values()); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1803 | dest.writeList(stackedLinks); |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1804 | |
| 1805 | dest.writeBoolean(mWakeOnLanSupported); |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1806 | dest.writeParcelable(mParcelSensitiveFields ? mCaptivePortalApiUrl : null, 0); |
| 1807 | dest.writeParcelable(mParcelSensitiveFields ? mCaptivePortalData : null, 0); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1810 | private static void writeAddresses(@NonNull Parcel dest, @NonNull List<InetAddress> list) { |
| 1811 | dest.writeInt(list.size()); |
| 1812 | for (InetAddress d : list) { |
| 1813 | writeAddress(dest, d); |
| 1814 | } |
| 1815 | } |
| 1816 | |
Lorenzo Colitti | 348577e | 2020-01-06 19:43:59 +0900 | [diff] [blame] | 1817 | private static void writeAddress(@NonNull Parcel dest, @Nullable InetAddress addr) { |
| 1818 | byte[] addressBytes = (addr == null ? null : addr.getAddress()); |
| 1819 | dest.writeByteArray(addressBytes); |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1820 | if (addr instanceof Inet6Address) { |
| 1821 | final Inet6Address v6Addr = (Inet6Address) addr; |
| 1822 | final boolean hasScopeId = v6Addr.getScopeId() != 0; |
| 1823 | dest.writeBoolean(hasScopeId); |
| 1824 | if (hasScopeId) dest.writeInt(v6Addr.getScopeId()); |
| 1825 | } |
| 1826 | } |
| 1827 | |
Lorenzo Colitti | 348577e | 2020-01-06 19:43:59 +0900 | [diff] [blame] | 1828 | @Nullable |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1829 | private static InetAddress readAddress(@NonNull Parcel p) throws UnknownHostException { |
| 1830 | final byte[] addr = p.createByteArray(); |
Lorenzo Colitti | 348577e | 2020-01-06 19:43:59 +0900 | [diff] [blame] | 1831 | if (addr == null) return null; |
| 1832 | |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1833 | if (addr.length == INET6_ADDR_LENGTH) { |
| 1834 | final boolean hasScopeId = p.readBoolean(); |
| 1835 | final int scopeId = hasScopeId ? p.readInt() : 0; |
| 1836 | return Inet6Address.getByAddress(null /* host */, addr, scopeId); |
| 1837 | } |
| 1838 | |
| 1839 | return InetAddress.getByAddress(addr); |
| 1840 | } |
| 1841 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1842 | /** |
| 1843 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1844 | */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1845 | public static final @android.annotation.NonNull Creator<LinkProperties> CREATOR = |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1846 | new Creator<LinkProperties>() { |
| 1847 | public LinkProperties createFromParcel(Parcel in) { |
| 1848 | LinkProperties netProp = new LinkProperties(); |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1849 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1850 | String iface = in.readString(); |
| 1851 | if (iface != null) { |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 1852 | netProp.setInterfaceName(iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1853 | } |
| 1854 | int addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1855 | for (int i = 0; i < addressCount; i++) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1856 | netProp.addLinkAddress(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1857 | } |
| 1858 | addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1859 | for (int i = 0; i < addressCount; i++) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1860 | try { |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1861 | netProp.addDnsServer(readAddress(in)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1862 | } catch (UnknownHostException e) { } |
| 1863 | } |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1864 | addressCount = in.readInt(); |
| 1865 | for (int i = 0; i < addressCount; i++) { |
| 1866 | try { |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1867 | netProp.addValidatedPrivateDnsServer(readAddress(in)); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1868 | } catch (UnknownHostException e) { } |
| 1869 | } |
dalyk | d920134 | 2018-01-17 14:20:55 -0500 | [diff] [blame] | 1870 | netProp.setUsePrivateDns(in.readBoolean()); |
| 1871 | netProp.setPrivateDnsServerName(in.readString()); |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1872 | addressCount = in.readInt(); |
| 1873 | for (int i = 0; i < addressCount; i++) { |
| 1874 | try { |
Remi NGUYEN VAN | f705ea6 | 2019-12-18 14:47:06 +0900 | [diff] [blame] | 1875 | netProp.addPcscfServer(readAddress(in)); |
Hongshik | fa42501 | 2018-06-28 20:42:19 +0900 | [diff] [blame] | 1876 | } catch (UnknownHostException e) { } |
| 1877 | } |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 1878 | netProp.setDomains(in.readString()); |
ruibin zhang | ad2689c | 2019-05-23 19:35:30 +0800 | [diff] [blame] | 1879 | try { |
| 1880 | netProp.setDhcpServerAddress((Inet4Address) InetAddress |
| 1881 | .getByAddress(in.createByteArray())); |
| 1882 | } catch (UnknownHostException e) { } |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 1883 | netProp.setMtu(in.readInt()); |
Robert Greenwalt | 3f05bf4 | 2014-08-06 12:00:25 -0700 | [diff] [blame] | 1884 | netProp.setTcpBufferSizes(in.readString()); |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 1885 | addressCount = in.readInt(); |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1886 | for (int i = 0; i < addressCount; i++) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1887 | netProp.addRoute(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1888 | } |
| 1889 | if (in.readByte() == 1) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1890 | netProp.setHttpProxy(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1891 | } |
Lorenzo Colitti | 59b3447 | 2019-01-08 09:58:59 +0900 | [diff] [blame] | 1892 | netProp.setNat64Prefix(in.readParcelable(null)); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 1893 | ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>(); |
| 1894 | in.readList(stackedLinks, LinkProperties.class.getClassLoader()); |
| 1895 | for (LinkProperties stackedLink: stackedLinks) { |
| 1896 | netProp.addStackedLink(stackedLink); |
| 1897 | } |
Valentin Iftime | c86ebba | 2019-09-24 13:32:13 +0200 | [diff] [blame] | 1898 | netProp.setWakeOnLanSupported(in.readBoolean()); |
Remi NGUYEN VAN | ead1ef4 | 2019-12-17 16:45:42 +0900 | [diff] [blame] | 1899 | |
| 1900 | netProp.setCaptivePortalApiUrl(in.readParcelable(null)); |
| 1901 | netProp.setCaptivePortalData(in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1902 | return netProp; |
| 1903 | } |
| 1904 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 1905 | public LinkProperties[] newArray(int size) { |
| 1906 | return new LinkProperties[size]; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1907 | } |
| 1908 | }; |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 1909 | |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1910 | /** |
| 1911 | * Check the valid MTU range based on IPv4 or IPv6. |
| 1912 | * @hide |
| 1913 | */ |
| 1914 | public static boolean isValidMtu(int mtu, boolean ipv6) { |
| 1915 | if (ipv6) { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1916 | return mtu >= MIN_MTU_V6 && mtu <= MAX_MTU; |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1917 | } else { |
Chalard Jean | b8cfa1d | 2018-06-07 13:27:00 +0900 | [diff] [blame] | 1918 | return mtu >= MIN_MTU && mtu <= MAX_MTU; |
w19976 | 15afd81 | 2014-08-05 15:18:11 -0700 | [diff] [blame] | 1919 | } |
Chalard Jean | 03dbf6b | 2018-04-11 16:36:41 +0900 | [diff] [blame] | 1920 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1921 | } |