2010-06-15 15:43:39 -07:00
|
|
|
/*
|
2010-09-21 09:15:35 -07:00
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
2010-06-15 15:43:39 -07:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package android.net;
|
|
|
|
|
|
2023-02-09 16:29:16 +09:00
|
|
|
import static android.net.connectivity.ConnectivityCompatChanges.EXCLUDED_ROUTES;
|
|
|
|
|
|
2014-08-11 15:22:51 -07:00
|
|
|
import android.annotation.NonNull;
|
2014-08-14 12:55:00 -07:00
|
|
|
import android.annotation.Nullable;
|
2018-12-12 17:52:57 +08:00
|
|
|
import android.annotation.SystemApi;
|
2021-08-02 18:06:35 +02:00
|
|
|
import android.app.compat.CompatChanges;
|
2019-12-10 17:47:52 +00:00
|
|
|
import android.compat.annotation.UnsupportedAppUsage;
|
2018-12-20 15:30:45 +00:00
|
|
|
import android.os.Build;
|
2010-06-15 15:43:39 -07:00
|
|
|
import android.os.Parcel;
|
2017-09-05 18:40:49 +01:00
|
|
|
import android.os.Parcelable;
|
2011-04-04 12:35:42 -07:00
|
|
|
import android.text.TextUtils;
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2022-07-14 18:50:10 +09:00
|
|
|
import com.android.modules.utils.build.SdkLevel;
|
|
|
|
|
import com.android.net.module.util.CollectionUtils;
|
2020-08-19 16:07:22 +09:00
|
|
|
import com.android.net.module.util.LinkPropertiesUtils;
|
|
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
import java.net.Inet4Address;
|
2013-08-08 11:00:12 +09:00
|
|
|
import java.net.Inet6Address;
|
2017-09-05 18:40:49 +01:00
|
|
|
import java.net.InetAddress;
|
2010-06-15 15:43:39 -07:00
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
2010-08-30 10:56:47 -07:00
|
|
|
import java.util.Collections;
|
2013-03-07 10:59:25 -08:00
|
|
|
import java.util.Hashtable;
|
2014-06-06 10:30:11 -07:00
|
|
|
import java.util.List;
|
2014-06-12 23:10:17 +09:00
|
|
|
import java.util.Objects;
|
2018-06-07 13:27:00 +09:00
|
|
|
import java.util.StringJoiner;
|
2010-06-15 15:43:39 -07:00
|
|
|
|
|
|
|
|
/**
|
2010-08-30 10:56:47 -07:00
|
|
|
* Describes the properties of a network link.
|
2011-02-09 13:56:06 -08:00
|
|
|
*
|
|
|
|
|
* A link represents a connection to a network.
|
|
|
|
|
* It may have multiple addresses and multiple gateways,
|
2014-05-18 22:01:38 -07:00
|
|
|
* multiple dns servers but only one http proxy and one
|
|
|
|
|
* network interface.
|
2011-02-09 13:56:06 -08:00
|
|
|
*
|
2014-05-18 22:01:38 -07:00
|
|
|
* Note that this is just a holder of data. Modifying it
|
|
|
|
|
* does not affect live networks.
|
2011-02-09 13:56:06 -08:00
|
|
|
*
|
2010-06-15 15:43:39 -07:00
|
|
|
*/
|
2014-06-12 16:24:38 -07:00
|
|
|
public final class LinkProperties implements Parcelable {
|
2013-03-07 10:59:25 -08:00
|
|
|
// The interface described by the network link.
|
2018-12-20 15:30:45 +00:00
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
2012-10-31 14:32:53 -07:00
|
|
|
private String mIfaceName;
|
2019-03-08 16:35:20 +08:00
|
|
|
private final ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>();
|
|
|
|
|
private final ArrayList<InetAddress> mDnses = new ArrayList<>();
|
2018-06-28 20:42:19 +09:00
|
|
|
// PCSCF addresses are addresses of SIP proxies that only exist for the IMS core service.
|
2019-03-08 16:35:20 +08:00
|
|
|
private final ArrayList<InetAddress> mPcscfs = new ArrayList<InetAddress>();
|
|
|
|
|
private final ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>();
|
2018-01-17 14:20:55 -05:00
|
|
|
private boolean mUsePrivateDns;
|
|
|
|
|
private String mPrivateDnsServerName;
|
2012-11-09 10:52:27 -08:00
|
|
|
private String mDomains;
|
2018-06-07 13:27:00 +09:00
|
|
|
private ArrayList<RouteInfo> mRoutes = new ArrayList<>();
|
2019-05-23 19:35:30 +08:00
|
|
|
private Inet4Address mDhcpServerAddress;
|
2014-04-25 15:00:09 -04:00
|
|
|
private ProxyInfo mHttpProxy;
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
private int mMtu;
|
2014-08-06 12:00:25 -07:00
|
|
|
// in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
|
|
|
|
|
private String mTcpBufferSizes;
|
2019-01-08 09:58:59 +09:00
|
|
|
private IpPrefix mNat64Prefix;
|
2019-09-24 13:32:13 +02:00
|
|
|
private boolean mWakeOnLanSupported;
|
2019-12-17 16:45:42 +09:00
|
|
|
private Uri mCaptivePortalApiUrl;
|
|
|
|
|
private CaptivePortalData mCaptivePortalData;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates whether parceling should preserve fields that are set based on permissions of
|
|
|
|
|
* the process receiving the {@link LinkProperties}.
|
|
|
|
|
*/
|
|
|
|
|
private final transient boolean mParcelSensitiveFields;
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2014-08-05 15:18:11 -07:00
|
|
|
private static final int MIN_MTU = 68;
|
2020-11-19 00:17:29 -08:00
|
|
|
|
2020-11-30 16:35:43 +09:00
|
|
|
private static final int MIN_MTU_V6 = 1280;
|
2020-11-19 00:17:29 -08:00
|
|
|
|
2014-08-05 15:18:11 -07:00
|
|
|
private static final int MAX_MTU = 10000;
|
|
|
|
|
|
2019-12-18 14:47:06 +09:00
|
|
|
private static final int INET6_ADDR_LENGTH = 16;
|
|
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
// Stores the properties of links that are "stacked" above this link.
|
|
|
|
|
// Indexed by interface name to allow modification and to prevent duplicates being added.
|
2018-06-07 13:27:00 +09:00
|
|
|
private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>();
|
2013-03-07 10:59:25 -08:00
|
|
|
|
2015-05-21 16:15:02 +09:00
|
|
|
/**
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-11-04 17:50:59 +00:00
|
|
|
@UnsupportedAppUsage(implicitMember =
|
|
|
|
|
"values()[Landroid/net/LinkProperties$ProvisioningChange;")
|
2015-05-21 16:15:02 +09:00
|
|
|
public enum ProvisioningChange {
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2015-05-21 16:15:02 +09:00
|
|
|
STILL_NOT_PROVISIONED,
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2015-05-21 16:15:02 +09:00
|
|
|
LOST_PROVISIONING,
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2015-05-21 16:15:02 +09:00
|
|
|
GAINED_PROVISIONING,
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2015-05-21 16:15:02 +09:00
|
|
|
STILL_PROVISIONED,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compare the provisioning states of two LinkProperties instances.
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2020-11-04 09:29:36 +00:00
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
2015-05-21 16:15:02 +09:00
|
|
|
public static ProvisioningChange compareProvisioning(
|
|
|
|
|
LinkProperties before, LinkProperties after) {
|
|
|
|
|
if (before.isProvisioned() && after.isProvisioned()) {
|
2018-06-07 13:27:00 +09:00
|
|
|
// On dual-stack networks, DHCPv4 renewals can occasionally fail.
|
2015-05-21 16:15:02 +09:00
|
|
|
// When this happens, IPv6-reachable services continue to function
|
|
|
|
|
// normally but IPv4-only services (naturally) fail.
|
|
|
|
|
//
|
|
|
|
|
// When an application using an IPv4-only service reports a bad
|
|
|
|
|
// network condition to the framework, attempts to re-validate
|
|
|
|
|
// the network succeed (since we support IPv6-only networks) and
|
|
|
|
|
// nothing is changed.
|
|
|
|
|
//
|
|
|
|
|
// For users, this is confusing and unexpected behaviour, and is
|
|
|
|
|
// not necessarily easy to diagnose. Therefore, we treat changing
|
2018-06-07 13:27:00 +09:00
|
|
|
// from a dual-stack network to an IPv6-only network equivalent to
|
2015-05-21 16:15:02 +09:00
|
|
|
// a total loss of provisioning.
|
|
|
|
|
//
|
|
|
|
|
// For one such example of this, see b/18867306.
|
|
|
|
|
//
|
2015-08-14 12:16:55 +09:00
|
|
|
// Additionally, losing IPv6 provisioning can result in TCP
|
|
|
|
|
// connections getting stuck until timeouts fire and other
|
|
|
|
|
// baffling failures. Therefore, loss of either IPv4 or IPv6 on a
|
2018-06-07 13:27:00 +09:00
|
|
|
// previously dual-stack network is deemed a lost of provisioning.
|
2019-03-08 16:35:20 +08:00
|
|
|
if ((before.isIpv4Provisioned() && !after.isIpv4Provisioned())
|
|
|
|
|
|| (before.isIpv6Provisioned() && !after.isIpv6Provisioned())) {
|
2015-05-21 16:15:02 +09:00
|
|
|
return ProvisioningChange.LOST_PROVISIONING;
|
|
|
|
|
}
|
|
|
|
|
return ProvisioningChange.STILL_PROVISIONED;
|
|
|
|
|
} else if (before.isProvisioned() && !after.isProvisioned()) {
|
|
|
|
|
return ProvisioningChange.LOST_PROVISIONING;
|
|
|
|
|
} else if (!before.isProvisioned() && after.isProvisioned()) {
|
|
|
|
|
return ProvisioningChange.GAINED_PROVISIONING;
|
|
|
|
|
} else { // !before.isProvisioned() && !after.isProvisioned()
|
|
|
|
|
return ProvisioningChange.STILL_NOT_PROVISIONED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-03 18:41:43 -07:00
|
|
|
/**
|
2019-03-08 16:35:20 +08:00
|
|
|
* Constructs a new {@code LinkProperties} with default values.
|
2014-06-03 18:41:43 -07:00
|
|
|
*/
|
2010-08-30 10:56:47 -07:00
|
|
|
public LinkProperties() {
|
2019-12-17 16:45:42 +09:00
|
|
|
mParcelSensitiveFields = false;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2014-06-03 18:41:43 -07:00
|
|
|
/**
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-23 21:35:52 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public LinkProperties(@Nullable LinkProperties source) {
|
2019-12-17 16:45:42 +09:00
|
|
|
this(source, false /* parcelSensitiveFields */);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-16 14:48:37 +09:00
|
|
|
/**
|
|
|
|
|
* Create a copy of a {@link LinkProperties} that may preserve fields that were set
|
|
|
|
|
* based on the permissions of the process that originally received it.
|
|
|
|
|
*
|
|
|
|
|
* <p>By default {@link LinkProperties} does not preserve such fields during parceling, as
|
|
|
|
|
* they should not be shared outside of the process that receives them without appropriate
|
|
|
|
|
* checks.
|
|
|
|
|
* @param parcelSensitiveFields Whether the sensitive fields should be kept when parceling
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
public LinkProperties(@Nullable LinkProperties source, boolean parcelSensitiveFields) {
|
2019-12-17 16:45:42 +09:00
|
|
|
mParcelSensitiveFields = parcelSensitiveFields;
|
|
|
|
|
if (source == null) return;
|
|
|
|
|
mIfaceName = source.mIfaceName;
|
|
|
|
|
mLinkAddresses.addAll(source.mLinkAddresses);
|
|
|
|
|
mDnses.addAll(source.mDnses);
|
|
|
|
|
mValidatedPrivateDnses.addAll(source.mValidatedPrivateDnses);
|
|
|
|
|
mUsePrivateDns = source.mUsePrivateDns;
|
|
|
|
|
mPrivateDnsServerName = source.mPrivateDnsServerName;
|
|
|
|
|
mPcscfs.addAll(source.mPcscfs);
|
|
|
|
|
mDomains = source.mDomains;
|
|
|
|
|
mRoutes.addAll(source.mRoutes);
|
|
|
|
|
mHttpProxy = (source.mHttpProxy == null) ? null : new ProxyInfo(source.mHttpProxy);
|
|
|
|
|
for (LinkProperties l: source.mStackedLinks.values()) {
|
|
|
|
|
addStackedLink(l);
|
2010-08-30 20:37:17 -07:00
|
|
|
}
|
2019-12-17 16:45:42 +09:00
|
|
|
setMtu(source.mMtu);
|
|
|
|
|
setDhcpServerAddress(source.getDhcpServerAddress());
|
|
|
|
|
mTcpBufferSizes = source.mTcpBufferSizes;
|
|
|
|
|
mNat64Prefix = source.mNat64Prefix;
|
|
|
|
|
mWakeOnLanSupported = source.mWakeOnLanSupported;
|
|
|
|
|
mCaptivePortalApiUrl = source.mCaptivePortalApiUrl;
|
|
|
|
|
mCaptivePortalData = source.mCaptivePortalData;
|
2010-08-30 10:56:47 -07:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the interface name for this link. All {@link RouteInfo} already set for this
|
|
|
|
|
* will have their interface changed to match this new value.
|
|
|
|
|
*
|
|
|
|
|
* @param iface The name of the network interface used for this link.
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setInterfaceName(@Nullable String iface) {
|
2010-10-01 16:08:28 -07:00
|
|
|
mIfaceName = iface;
|
2018-06-07 13:27:00 +09:00
|
|
|
ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size());
|
2013-03-08 11:30:39 -08:00
|
|
|
for (RouteInfo route : mRoutes) {
|
|
|
|
|
newRoutes.add(routeWithInterface(route));
|
|
|
|
|
}
|
|
|
|
|
mRoutes = newRoutes;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Gets the interface name for this link. May be {@code null} if not set.
|
|
|
|
|
*
|
|
|
|
|
* @return The interface name set for this link or {@code null}.
|
|
|
|
|
*/
|
2014-08-14 12:55:00 -07:00
|
|
|
public @Nullable String getInterfaceName() {
|
2010-10-01 16:08:28 -07:00
|
|
|
return mIfaceName;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2010-10-01 16:08:28 -07:00
|
|
|
|
2014-06-06 10:30:11 -07:00
|
|
|
/**
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<String> getAllInterfaceNames() {
|
2018-06-07 13:27:00 +09:00
|
|
|
List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1);
|
|
|
|
|
if (mIfaceName != null) interfaceNames.add(mIfaceName);
|
2013-03-20 19:22:58 +09:00
|
|
|
for (LinkProperties stacked: mStackedLinks.values()) {
|
|
|
|
|
interfaceNames.addAll(stacked.getAllInterfaceNames());
|
|
|
|
|
}
|
|
|
|
|
return interfaceNames;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 23:23:21 +09:00
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Returns all the addresses on this link. We often think of a link having a single address,
|
|
|
|
|
* however, particularly with Ipv6 several addresses are typical. Note that the
|
|
|
|
|
* {@code LinkProperties} actually contains {@link LinkAddress} objects which also include
|
|
|
|
|
* prefix lengths for each address. This is a simplified utility alternative to
|
|
|
|
|
* {@link LinkProperties#getLinkAddresses}.
|
|
|
|
|
*
|
2018-06-07 13:27:00 +09:00
|
|
|
* @return An unmodifiable {@link List} of {@link InetAddress} for this link.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-07-31 23:23:21 +09:00
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<InetAddress> getAddresses() {
|
|
|
|
|
final List<InetAddress> addresses = new ArrayList<>();
|
2010-10-01 16:08:28 -07:00
|
|
|
for (LinkAddress linkAddress : mLinkAddresses) {
|
|
|
|
|
addresses.add(linkAddress.getAddress());
|
|
|
|
|
}
|
2014-06-06 10:30:11 -07:00
|
|
|
return Collections.unmodifiableList(addresses);
|
2010-10-01 16:08:28 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-31 23:23:21 +09:00
|
|
|
/**
|
|
|
|
|
* Returns all the addresses on this link and all the links stacked above it.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-07-31 23:23:21 +09:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<InetAddress> getAllAddresses() {
|
2018-06-07 13:27:00 +09:00
|
|
|
List<InetAddress> addresses = new ArrayList<>();
|
2013-07-31 23:23:21 +09:00
|
|
|
for (LinkAddress linkAddress : mLinkAddresses) {
|
|
|
|
|
addresses.add(linkAddress.getAddress());
|
|
|
|
|
}
|
|
|
|
|
for (LinkProperties stacked: mStackedLinks.values()) {
|
|
|
|
|
addresses.addAll(stacked.getAllAddresses());
|
|
|
|
|
}
|
|
|
|
|
return addresses;
|
|
|
|
|
}
|
|
|
|
|
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
private int findLinkAddressIndex(LinkAddress address) {
|
|
|
|
|
for (int i = 0; i < mLinkAddresses.size(); i++) {
|
|
|
|
|
if (mLinkAddresses.get(i).isSameAddressAs(address)) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 11:00:12 +09:00
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Adds a {@link LinkAddress} to this {@code LinkProperties} if a {@link LinkAddress} of the
|
|
|
|
|
* same address/prefix does not already exist. If it does exist it is replaced.
|
2013-08-08 11:00:12 +09:00
|
|
|
* @param address The {@code LinkAddress} to add.
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
* @return true if {@code address} was added or updated, false otherwise.
|
2014-06-06 10:30:11 -07:00
|
|
|
* @hide
|
2013-08-08 11:00:12 +09:00
|
|
|
*/
|
2019-01-29 12:08:43 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addLinkAddress(@NonNull LinkAddress address) {
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
if (address == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int i = findLinkAddressIndex(address);
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
// Address was not present. Add it.
|
2013-08-08 11:00:12 +09:00
|
|
|
mLinkAddresses.add(address);
|
|
|
|
|
return true;
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
} else if (mLinkAddresses.get(i).equals(address)) {
|
|
|
|
|
// Address was present and has same properties. Do nothing.
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// Address was present and has different properties. Update it.
|
|
|
|
|
mLinkAddresses.set(i, address);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Removes a {@link LinkAddress} from this {@code LinkProperties}. Specifically, matches
|
|
|
|
|
* and {@link LinkAddress} with the same address and prefix.
|
|
|
|
|
*
|
|
|
|
|
* @param toRemove A {@link LinkAddress} specifying the address to remove.
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
* @return true if the address was removed, false if it did not exist.
|
2014-06-06 10:30:11 -07:00
|
|
|
* @hide
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
*/
|
2019-01-29 12:08:43 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removeLinkAddress(@NonNull LinkAddress toRemove) {
|
Add address flags and scope to LinkAddress.
This is necessary so that the framework can know whether an IPv6
address is likely to be usable (i.e., if it's global scope and
preferred). Also, it will simplify the address notification
methods in INetworkManagementEventObserver, which currently take
the address, the flags, and the scope as separate arguments.
1. Add flags and scope to the class and update the unit test.
Use the IFA_F_* and RT_SCOPE_* constants defined by libcore.
Since most callers don't know about flags and scope, provide
constructors that default the flags to zero and determine the
scope from the address. Addresses notified by the kernel will
have these properly set. Make multicast addresses invalid.
Update the class documentation.
2. Provide an isSameAddressAs() method that compares only the
address and prefix information between two LinkAddress
objects. This is necessary because an interface can't have
two addresses with the same address/prefix but different
flags.
3. Update LinkProperties's addLinkAddress and removeLinkAddress
to identify existing addresses to add/remove using
isSameAddressAs instead of implicit equals(). Specifically:
- If addLinkAddress is called with an address that is already
present, the existing address's flags and scope are updated.
This allows, for example, an address on an interface to go
from preferred to deprecated when it expires, without it
having to be removed and re-added.
- If removeLinkAddress is called with an address that is
present but with different flags, it deletes that address
instead of failing to find a match.
4. Update the INetworkManagementEventObserver address
notification methods to take just a LinkAddress instead of
LinkAddress, flags, and scope. While I'm at it, change the
order of the arguments for consistency with the other
functions in the interface.
Change-Id: Id8fe0f09a7e8f6bee1ea3b52102178b689a9336e
2013-11-15 18:43:52 +09:00
|
|
|
int i = findLinkAddressIndex(toRemove);
|
|
|
|
|
if (i >= 0) {
|
|
|
|
|
mLinkAddresses.remove(i);
|
|
|
|
|
return true;
|
2013-08-08 11:00:12 +09:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 23:23:21 +09:00
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Returns all the {@link LinkAddress} on this link. Typically a link will have
|
|
|
|
|
* one IPv4 address and one or more IPv6 addresses.
|
|
|
|
|
*
|
2014-06-06 10:30:11 -07:00
|
|
|
* @return An unmodifiable {@link List} of {@link LinkAddress} for this link.
|
2013-07-31 23:23:21 +09:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<LinkAddress> getLinkAddresses() {
|
2014-06-06 10:30:11 -07:00
|
|
|
return Collections.unmodifiableList(mLinkAddresses);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-07-31 23:23:21 +09:00
|
|
|
/**
|
|
|
|
|
* Returns all the addresses on this link and all the links stacked above it.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-07-31 23:23:21 +09:00
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
|
|
|
|
public @NonNull List<LinkAddress> getAllLinkAddresses() {
|
2018-06-07 13:27:00 +09:00
|
|
|
List<LinkAddress> addresses = new ArrayList<>(mLinkAddresses);
|
2013-07-31 23:23:21 +09:00
|
|
|
for (LinkProperties stacked: mStackedLinks.values()) {
|
|
|
|
|
addresses.addAll(stacked.getAllLinkAddresses());
|
|
|
|
|
}
|
|
|
|
|
return addresses;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-23 20:54:49 +09:00
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Replaces the {@link LinkAddress} in this {@code LinkProperties} with
|
|
|
|
|
* the given {@link Collection} of {@link LinkAddress}.
|
|
|
|
|
*
|
|
|
|
|
* @param addresses The {@link Collection} of {@link LinkAddress} to set in this
|
|
|
|
|
* object.
|
2013-08-23 20:54:49 +09:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setLinkAddresses(@NonNull Collection<LinkAddress> addresses) {
|
2013-08-23 20:54:49 +09:00
|
|
|
mLinkAddresses.clear();
|
|
|
|
|
for (LinkAddress address: addresses) {
|
|
|
|
|
addLinkAddress(address);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
2014-06-24 00:34:39 +09:00
|
|
|
* Adds the given {@link InetAddress} to the list of DNS servers, if not present.
|
2014-05-18 22:01:38 -07:00
|
|
|
*
|
2014-06-06 10:30:11 -07:00
|
|
|
* @param dnsServer The {@link InetAddress} to add to the list of DNS servers.
|
2014-06-24 00:34:39 +09:00
|
|
|
* @return true if the DNS server was added, false if it was already present.
|
2014-06-06 10:30:11 -07:00
|
|
|
* @hide
|
2014-05-18 22:01:38 -07:00
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addDnsServer(@NonNull InetAddress dnsServer) {
|
2014-06-24 00:34:39 +09:00
|
|
|
if (dnsServer != null && !mDnses.contains(dnsServer)) {
|
|
|
|
|
mDnses.add(dnsServer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 16:15:02 +09:00
|
|
|
/**
|
|
|
|
|
* Removes the given {@link InetAddress} from the list of DNS servers.
|
|
|
|
|
*
|
|
|
|
|
* @param dnsServer The {@link InetAddress} to remove from the list of DNS servers.
|
|
|
|
|
* @return true if the DNS server was removed, false if it did not exist.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removeDnsServer(@NonNull InetAddress dnsServer) {
|
2019-03-22 16:35:06 +08:00
|
|
|
return mDnses.remove(dnsServer);
|
2015-05-21 16:15:02 +09:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 00:34:39 +09:00
|
|
|
/**
|
|
|
|
|
* Replaces the DNS servers in this {@code LinkProperties} with
|
|
|
|
|
* the given {@link Collection} of {@link InetAddress} objects.
|
|
|
|
|
*
|
2018-04-11 16:36:41 +09:00
|
|
|
* @param dnsServers The {@link Collection} of DNS servers to set in this object.
|
2014-06-24 00:34:39 +09:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setDnsServers(@NonNull Collection<InetAddress> dnsServers) {
|
2014-06-24 00:34:39 +09:00
|
|
|
mDnses.clear();
|
|
|
|
|
for (InetAddress dnsServer: dnsServers) {
|
|
|
|
|
addDnsServer(dnsServer);
|
|
|
|
|
}
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2010-10-01 16:08:28 -07:00
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
2014-06-03 18:41:43 -07:00
|
|
|
* Returns all the {@link InetAddress} for DNS servers on this link.
|
2014-05-18 22:01:38 -07:00
|
|
|
*
|
2018-06-07 13:27:00 +09:00
|
|
|
* @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on
|
2014-05-18 22:01:38 -07:00
|
|
|
* this link.
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<InetAddress> getDnsServers() {
|
2014-06-06 10:30:11 -07:00
|
|
|
return Collections.unmodifiableList(mDnses);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2018-01-17 14:20:55 -05:00
|
|
|
/**
|
|
|
|
|
* Set whether private DNS is currently in use on this network.
|
|
|
|
|
*
|
|
|
|
|
* @param usePrivateDns The private DNS state.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2018-01-17 14:20:55 -05:00
|
|
|
public void setUsePrivateDns(boolean usePrivateDns) {
|
|
|
|
|
mUsePrivateDns = usePrivateDns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether private DNS is currently in use on this network. When
|
|
|
|
|
* private DNS is in use, applications must not send unencrypted DNS
|
|
|
|
|
* queries as doing so could reveal private user information. Furthermore,
|
|
|
|
|
* if private DNS is in use and {@link #getPrivateDnsServerName} is not
|
|
|
|
|
* {@code null}, DNS queries must be sent to the specified DNS server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if private DNS is in use, {@code false} otherwise.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isPrivateDnsActive() {
|
|
|
|
|
return mUsePrivateDns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the name of the private DNS server to which private DNS queries
|
|
|
|
|
* should be sent when in strict mode. This value should be {@code null}
|
|
|
|
|
* when private DNS is off or in opportunistic mode.
|
|
|
|
|
*
|
|
|
|
|
* @param privateDnsServerName The private DNS server name.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2018-01-17 14:20:55 -05:00
|
|
|
public void setPrivateDnsServerName(@Nullable String privateDnsServerName) {
|
|
|
|
|
mPrivateDnsServerName = privateDnsServerName;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 19:35:30 +08:00
|
|
|
/**
|
|
|
|
|
* Set DHCP server address.
|
|
|
|
|
*
|
|
|
|
|
* @param serverAddress the server address to set.
|
|
|
|
|
*/
|
|
|
|
|
public void setDhcpServerAddress(@Nullable Inet4Address serverAddress) {
|
|
|
|
|
mDhcpServerAddress = serverAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get DHCP server address
|
|
|
|
|
*
|
|
|
|
|
* @return The current DHCP server address.
|
|
|
|
|
*/
|
|
|
|
|
public @Nullable Inet4Address getDhcpServerAddress() {
|
|
|
|
|
return mDhcpServerAddress;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 14:20:55 -05:00
|
|
|
/**
|
|
|
|
|
* Returns the private DNS server name that is in use. If not {@code null},
|
|
|
|
|
* private DNS is in strict mode. In this mode, applications should ensure
|
|
|
|
|
* that all DNS queries are encrypted and sent to this hostname and that
|
|
|
|
|
* queries are only sent if the hostname's certificate is valid. If
|
|
|
|
|
* {@code null} and {@link #isPrivateDnsActive} is {@code true}, private
|
|
|
|
|
* DNS is in opportunistic mode, and applications should ensure that DNS
|
|
|
|
|
* queries are encrypted and sent to a DNS server returned by
|
|
|
|
|
* {@link #getDnsServers}. System DNS will handle each of these cases
|
|
|
|
|
* correctly, but applications implementing their own DNS lookups must make
|
|
|
|
|
* sure to follow these requirements.
|
|
|
|
|
*
|
|
|
|
|
* @return The private DNS server name.
|
|
|
|
|
*/
|
|
|
|
|
public @Nullable String getPrivateDnsServerName() {
|
|
|
|
|
return mPrivateDnsServerName;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 16:36:41 +09:00
|
|
|
/**
|
|
|
|
|
* Adds the given {@link InetAddress} to the list of validated private DNS servers,
|
|
|
|
|
* if not present. This is distinct from the server name in that these are actually
|
|
|
|
|
* resolved addresses.
|
|
|
|
|
*
|
|
|
|
|
* @param dnsServer The {@link InetAddress} to add to the list of validated private DNS servers.
|
|
|
|
|
* @return true if the DNS server was added, false if it was already present.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) {
|
2018-04-11 16:36:41 +09:00
|
|
|
if (dnsServer != null && !mValidatedPrivateDnses.contains(dnsServer)) {
|
|
|
|
|
mValidatedPrivateDnses.add(dnsServer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the given {@link InetAddress} from the list of validated private DNS servers.
|
|
|
|
|
*
|
|
|
|
|
* @param dnsServer The {@link InetAddress} to remove from the list of validated private DNS
|
|
|
|
|
* servers.
|
|
|
|
|
* @return true if the DNS server was removed, false if it did not exist.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removeValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) {
|
|
|
|
|
return mValidatedPrivateDnses.remove(dnsServer);
|
2018-04-11 16:36:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replaces the validated private DNS servers in this {@code LinkProperties} with
|
|
|
|
|
* the given {@link Collection} of {@link InetAddress} objects.
|
|
|
|
|
*
|
|
|
|
|
* @param dnsServers The {@link Collection} of validated private DNS servers to set in this
|
|
|
|
|
* object.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setValidatedPrivateDnsServers(@NonNull Collection<InetAddress> dnsServers) {
|
2018-04-11 16:36:41 +09:00
|
|
|
mValidatedPrivateDnses.clear();
|
|
|
|
|
for (InetAddress dnsServer: dnsServers) {
|
|
|
|
|
addValidatedPrivateDnsServer(dnsServer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all the {@link InetAddress} for validated private DNS servers on this link.
|
|
|
|
|
* These are resolved from the private DNS server name.
|
|
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @return An unmodifiable {@link List} of {@link InetAddress} for validated private
|
2018-04-11 16:36:41 +09:00
|
|
|
* DNS servers on this link.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<InetAddress> getValidatedPrivateDnsServers() {
|
2018-04-11 16:36:41 +09:00
|
|
|
return Collections.unmodifiableList(mValidatedPrivateDnses);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 20:42:19 +09:00
|
|
|
/**
|
|
|
|
|
* Adds the given {@link InetAddress} to the list of PCSCF servers, if not present.
|
|
|
|
|
*
|
|
|
|
|
* @param pcscfServer The {@link InetAddress} to add to the list of PCSCF servers.
|
|
|
|
|
* @return true if the PCSCF server was added, false otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addPcscfServer(@NonNull InetAddress pcscfServer) {
|
2018-06-28 20:42:19 +09:00
|
|
|
if (pcscfServer != null && !mPcscfs.contains(pcscfServer)) {
|
|
|
|
|
mPcscfs.add(pcscfServer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the given {@link InetAddress} from the list of PCSCF servers.
|
|
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @param pcscfServer The {@link InetAddress} to remove from the list of PCSCF servers.
|
2018-06-28 20:42:19 +09:00
|
|
|
* @return true if the PCSCF server was removed, false otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removePcscfServer(@NonNull InetAddress pcscfServer) {
|
|
|
|
|
return mPcscfs.remove(pcscfServer);
|
2018-06-28 20:42:19 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replaces the PCSCF servers in this {@code LinkProperties} with
|
|
|
|
|
* the given {@link Collection} of {@link InetAddress} objects.
|
|
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @param pcscfServers The {@link Collection} of PCSCF servers to set in this object.
|
2018-06-28 20:42:19 +09:00
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-23 21:35:52 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setPcscfServers(@NonNull Collection<InetAddress> pcscfServers) {
|
2018-06-28 20:42:19 +09:00
|
|
|
mPcscfs.clear();
|
|
|
|
|
for (InetAddress pcscfServer: pcscfServers) {
|
|
|
|
|
addPcscfServer(pcscfServer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all the {@link InetAddress} for PCSCF servers on this link.
|
|
|
|
|
*
|
|
|
|
|
* @return An unmodifiable {@link List} of {@link InetAddress} for PCSCF servers on
|
|
|
|
|
* this link.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-23 21:35:52 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<InetAddress> getPcscfServers() {
|
2018-06-28 20:42:19 +09:00
|
|
|
return Collections.unmodifiableList(mPcscfs);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the DNS domain search path used on this link.
|
|
|
|
|
*
|
|
|
|
|
* @param domains A {@link String} listing in priority order the comma separated
|
|
|
|
|
* domains to search when resolving host names on this link.
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setDomains(@Nullable String domains) {
|
2012-11-09 10:52:27 -08:00
|
|
|
mDomains = domains;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
2019-03-08 16:35:20 +08:00
|
|
|
* Get the DNS domains search path set for this link. May be {@code null} if not set.
|
2014-05-18 22:01:38 -07:00
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @return A {@link String} containing the comma separated domains to search when resolving host
|
|
|
|
|
* names on this link or {@code null}.
|
2014-05-18 22:01:38 -07:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public @Nullable String getDomains() {
|
2014-05-18 22:01:38 -07:00
|
|
|
return mDomains;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the Maximum Transmission Unit size to use on this link. This should not be used
|
|
|
|
|
* unless the system default (1500) is incorrect. Values less than 68 or greater than
|
|
|
|
|
* 10000 will be ignored.
|
|
|
|
|
*
|
|
|
|
|
* @param mtu The MTU to use for this link.
|
|
|
|
|
*/
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
public void setMtu(int mtu) {
|
|
|
|
|
mMtu = mtu;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Gets any non-default MTU size set for this link. Note that if the default is being used
|
|
|
|
|
* this will return 0.
|
|
|
|
|
*
|
|
|
|
|
* @return The mtu value set for this link.
|
|
|
|
|
*/
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
public int getMtu() {
|
|
|
|
|
return mMtu;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-06 12:00:25 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the tcp buffers sizes to be used when this link is the system default.
|
|
|
|
|
* Should be of the form "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max".
|
|
|
|
|
*
|
|
|
|
|
* @param tcpBufferSizes The tcp buffers sizes to use.
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setTcpBufferSizes(@Nullable String tcpBufferSizes) {
|
2014-08-06 12:00:25 -07:00
|
|
|
mTcpBufferSizes = tcpBufferSizes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-08 16:35:20 +08:00
|
|
|
* Gets the tcp buffer sizes. May be {@code null} if not set.
|
2014-08-06 12:00:25 -07:00
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @return the tcp buffer sizes to use when this link is the system default or {@code null}.
|
2014-08-06 12:00:25 -07:00
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @Nullable String getTcpBufferSizes() {
|
2014-08-06 12:00:25 -07:00
|
|
|
return mTcpBufferSizes;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 11:30:39 -08:00
|
|
|
private RouteInfo routeWithInterface(RouteInfo route) {
|
|
|
|
|
return new RouteInfo(
|
|
|
|
|
route.getDestination(),
|
|
|
|
|
route.getGateway(),
|
2014-09-19 01:49:05 +09:00
|
|
|
mIfaceName,
|
2019-12-05 14:55:30 -08:00
|
|
|
route.getType(),
|
|
|
|
|
route.getMtu());
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 20:49:43 +08:00
|
|
|
private int findRouteIndexByRouteKey(RouteInfo route) {
|
2019-12-05 14:55:30 -08:00
|
|
|
for (int i = 0; i < mRoutes.size(); i++) {
|
2020-03-23 20:49:43 +08:00
|
|
|
if (mRoutes.get(i).getRouteKey().equals(route.getRouteKey())) {
|
2019-12-05 14:55:30 -08:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2013-03-08 11:30:39 -08:00
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
2021-04-15 16:04:00 +08:00
|
|
|
* Adds a {@link RouteInfo} to this {@code LinkProperties}. If there is a {@link RouteInfo}
|
|
|
|
|
* with the same destination, gateway and interface with different properties
|
2020-03-23 20:49:43 +08:00
|
|
|
* (e.g., different MTU), it will be updated. If the {@link RouteInfo} had an
|
|
|
|
|
* interface name set and that differs from the interface set for this
|
|
|
|
|
* {@code LinkProperties} an {@link IllegalArgumentException} will be thrown.
|
|
|
|
|
* The proper course is to add either un-named or properly named {@link RouteInfo}.
|
2014-05-18 22:01:38 -07:00
|
|
|
*
|
|
|
|
|
* @param route A {@link RouteInfo} to add to this object.
|
2019-12-05 14:55:30 -08:00
|
|
|
* @return {@code true} was added or updated, false otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addRoute(@NonNull RouteInfo route) {
|
|
|
|
|
String routeIface = route.getInterface();
|
|
|
|
|
if (routeIface != null && !routeIface.equals(mIfaceName)) {
|
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
|
"Route added with non-matching interface: " + routeIface
|
|
|
|
|
+ " vs. " + mIfaceName);
|
|
|
|
|
}
|
|
|
|
|
route = routeWithInterface(route);
|
2019-12-05 14:55:30 -08:00
|
|
|
|
2020-03-23 20:49:43 +08:00
|
|
|
int i = findRouteIndexByRouteKey(route);
|
2019-12-05 14:55:30 -08:00
|
|
|
if (i == -1) {
|
|
|
|
|
// Route was not present. Add it.
|
2019-03-08 16:35:20 +08:00
|
|
|
mRoutes.add(route);
|
|
|
|
|
return true;
|
2019-12-05 14:55:30 -08:00
|
|
|
} else if (mRoutes.get(i).equals(route)) {
|
|
|
|
|
// Route was present and has same properties. Do nothing.
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// Route was present and has different properties. Update it.
|
|
|
|
|
mRoutes.set(i, route);
|
|
|
|
|
return true;
|
2013-03-08 11:30:39 -08:00
|
|
|
}
|
2014-06-12 23:10:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a {@link RouteInfo} from this {@code LinkProperties}, if present. The route must
|
|
|
|
|
* specify an interface and the interface must match the interface of this
|
|
|
|
|
* {@code LinkProperties}, or it will not be removed.
|
|
|
|
|
*
|
2019-12-05 14:55:30 -08:00
|
|
|
* @param route A {@link RouteInfo} specifying the route to remove.
|
2014-06-12 23:10:17 +09:00
|
|
|
* @return {@code true} if the route was removed, {@code false} if it was not present.
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removeRoute(@NonNull RouteInfo route) {
|
|
|
|
|
return Objects.equals(mIfaceName, route.getInterface()) && mRoutes.remove(route);
|
2013-03-08 11:30:39 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
/**
|
2014-05-18 22:01:38 -07:00
|
|
|
* Returns all the {@link RouteInfo} set on this link.
|
|
|
|
|
*
|
2021-08-02 18:06:35 +02:00
|
|
|
* Only unicast routes are returned for apps targeting Android S or below.
|
|
|
|
|
*
|
2014-06-06 10:30:11 -07:00
|
|
|
* @return An unmodifiable {@link List} of {@link RouteInfo} for this link.
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<RouteInfo> getRoutes() {
|
2022-07-14 18:50:10 +09:00
|
|
|
// Before T, there's no throw routes because VpnService is not updatable, so no need to
|
|
|
|
|
// filter them out.
|
|
|
|
|
if (CompatChanges.isChangeEnabled(EXCLUDED_ROUTES) || !SdkLevel.isAtLeastT()) {
|
2021-08-02 18:06:35 +02:00
|
|
|
return Collections.unmodifiableList(mRoutes);
|
|
|
|
|
} else {
|
2022-07-14 18:50:10 +09:00
|
|
|
// Apps that added a throw route themselves (not obtaining LinkProperties from the
|
|
|
|
|
// system) will not see it in getRoutes on T+ if they do not have the compat change
|
|
|
|
|
// enabled (target SDK < T); but this is expected to be rare and typically only affect
|
|
|
|
|
// tests creating LinkProperties themselves (like CTS v12, which is only running on S).
|
2022-07-15 16:42:49 +09:00
|
|
|
return Collections.unmodifiableList(getUnicastRoutes());
|
2021-08-02 18:06:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-07-15 16:42:49 +09:00
|
|
|
* Returns all the {@link RouteInfo} of type {@link RouteInfo#RTN_UNICAST} set on this link.
|
2021-08-02 18:06:35 +02:00
|
|
|
*/
|
2022-07-15 16:42:49 +09:00
|
|
|
private @NonNull List<RouteInfo> getUnicastRoutes() {
|
|
|
|
|
return CollectionUtils.filter(mRoutes, route -> route.getType() == RouteInfo.RTN_UNICAST);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-05 18:40:49 +01:00
|
|
|
/**
|
|
|
|
|
* Make sure this LinkProperties instance contains routes that cover the local subnet
|
|
|
|
|
* of its link addresses. Add any route that is missing.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public void ensureDirectlyConnectedRoutes() {
|
2018-06-07 13:27:00 +09:00
|
|
|
for (LinkAddress addr : mLinkAddresses) {
|
2017-09-05 18:40:49 +01:00
|
|
|
addRoute(new RouteInfo(addr, null, mIfaceName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
/**
|
|
|
|
|
* Returns all the routes on this link and all the links stacked above it.
|
2021-08-02 18:06:35 +02:00
|
|
|
*
|
|
|
|
|
* Only unicast routes are returned for apps targeting Android S or below.
|
|
|
|
|
*
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public @NonNull List<RouteInfo> getAllRoutes() {
|
2021-08-02 18:06:35 +02:00
|
|
|
final List<RouteInfo> routes = new ArrayList<>(getRoutes());
|
2013-03-07 10:59:25 -08:00
|
|
|
for (LinkProperties stacked: mStackedLinks.values()) {
|
|
|
|
|
routes.addAll(stacked.getAllRoutes());
|
|
|
|
|
}
|
2013-03-15 11:28:50 -07:00
|
|
|
return routes;
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the recommended {@link ProxyInfo} to use on this link, or {@code null} for none.
|
|
|
|
|
* Note that Http Proxies are only a hint - the system recommends their use, but it does
|
|
|
|
|
* not enforce it and applications may ignore them.
|
|
|
|
|
*
|
2015-06-26 19:21:34 +09:00
|
|
|
* @param proxy A {@link ProxyInfo} defining the HTTP Proxy to use on this link.
|
2014-05-18 22:01:38 -07:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setHttpProxy(@Nullable ProxyInfo proxy) {
|
2010-06-15 15:43:39 -07:00
|
|
|
mHttpProxy = proxy;
|
|
|
|
|
}
|
2014-05-18 22:01:38 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link.
|
|
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @return The {@link ProxyInfo} set on this link or {@code null}.
|
2014-05-18 22:01:38 -07:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public @Nullable ProxyInfo getHttpProxy() {
|
2010-06-15 15:43:39 -07:00
|
|
|
return mHttpProxy;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 09:58:59 +09:00
|
|
|
/**
|
|
|
|
|
* Returns the NAT64 prefix in use on this link, if any.
|
|
|
|
|
*
|
2019-03-08 16:35:20 +08:00
|
|
|
* @return the NAT64 prefix or {@code null}.
|
2019-01-08 09:58:59 +09:00
|
|
|
*/
|
|
|
|
|
public @Nullable IpPrefix getNat64Prefix() {
|
|
|
|
|
return mNat64Prefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the NAT64 prefix in use on this link.
|
|
|
|
|
*
|
|
|
|
|
* Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the
|
2019-03-08 16:35:20 +08:00
|
|
|
* 128-bit IPv6 address) are supported or {@code null} for no prefix.
|
2019-01-08 09:58:59 +09:00
|
|
|
*
|
|
|
|
|
* @param prefix the NAT64 prefix.
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public void setNat64Prefix(@Nullable IpPrefix prefix) {
|
2019-01-08 09:58:59 +09:00
|
|
|
if (prefix != null && prefix.getPrefixLength() != 96) {
|
|
|
|
|
throw new IllegalArgumentException("Only 96-bit prefixes are supported: " + prefix);
|
|
|
|
|
}
|
|
|
|
|
mNat64Prefix = prefix; // IpPrefix objects are immutable.
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
/**
|
|
|
|
|
* Adds a stacked link.
|
|
|
|
|
*
|
2018-06-07 13:27:00 +09:00
|
|
|
* If there is already a stacked link with the same interface name as link,
|
2013-03-07 10:59:25 -08:00
|
|
|
* that link is replaced with link. Otherwise, link is added to the list
|
2019-03-08 16:35:20 +08:00
|
|
|
* of stacked links.
|
2013-03-07 10:59:25 -08:00
|
|
|
*
|
|
|
|
|
* @param link The link to add.
|
2013-08-08 11:00:12 +09:00
|
|
|
* @return true if the link was stacked, false otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean addStackedLink(@NonNull LinkProperties link) {
|
|
|
|
|
if (link.getInterfaceName() != null) {
|
2013-03-07 10:59:25 -08:00
|
|
|
mStackedLinks.put(link.getInterfaceName(), link);
|
2013-08-08 11:00:12 +09:00
|
|
|
return true;
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
2013-08-08 11:00:12 +09:00
|
|
|
return false;
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a stacked link.
|
|
|
|
|
*
|
2014-10-20 11:08:03 +09:00
|
|
|
* If there is a stacked link with the given interface name, it is
|
2013-03-07 10:59:25 -08:00
|
|
|
* removed. Otherwise, nothing changes.
|
|
|
|
|
*
|
2014-10-20 11:08:03 +09:00
|
|
|
* @param iface The interface name of the link to remove.
|
2013-08-08 11:00:12 +09:00
|
|
|
* @return true if the link was removed, false otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean removeStackedLink(@NonNull String iface) {
|
|
|
|
|
LinkProperties removed = mStackedLinks.remove(iface);
|
|
|
|
|
return removed != null;
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all the links stacked on top of this link.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2020-11-04 09:29:36 +00:00
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
2014-08-11 15:22:51 -07:00
|
|
|
public @NonNull List<LinkProperties> getStackedLinks() {
|
|
|
|
|
if (mStackedLinks.isEmpty()) {
|
2018-06-07 13:27:00 +09:00
|
|
|
return Collections.emptyList();
|
2014-08-11 15:22:51 -07:00
|
|
|
}
|
2019-03-08 16:35:20 +08:00
|
|
|
final List<LinkProperties> stacked = new ArrayList<>();
|
2013-03-07 10:59:25 -08:00
|
|
|
for (LinkProperties link : mStackedLinks.values()) {
|
2014-08-11 15:22:51 -07:00
|
|
|
stacked.add(new LinkProperties(link));
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
2014-06-06 10:30:11 -07:00
|
|
|
return Collections.unmodifiableList(stacked);
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 22:01:38 -07:00
|
|
|
/**
|
|
|
|
|
* Clears this object to its initial state.
|
|
|
|
|
*/
|
2010-08-30 10:56:47 -07:00
|
|
|
public void clear() {
|
2019-12-17 16:45:42 +09:00
|
|
|
if (mParcelSensitiveFields) {
|
|
|
|
|
throw new UnsupportedOperationException(
|
|
|
|
|
"Cannot clear LinkProperties when parcelSensitiveFields is set");
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 16:08:28 -07:00
|
|
|
mIfaceName = null;
|
2011-07-13 13:44:13 -07:00
|
|
|
mLinkAddresses.clear();
|
|
|
|
|
mDnses.clear();
|
2018-01-17 14:20:55 -05:00
|
|
|
mUsePrivateDns = false;
|
|
|
|
|
mPrivateDnsServerName = null;
|
2018-06-28 20:42:19 +09:00
|
|
|
mPcscfs.clear();
|
2012-11-09 10:52:27 -08:00
|
|
|
mDomains = null;
|
2011-07-13 13:44:13 -07:00
|
|
|
mRoutes.clear();
|
2010-06-15 15:43:39 -07:00
|
|
|
mHttpProxy = null;
|
2013-03-07 10:59:25 -08:00
|
|
|
mStackedLinks.clear();
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
mMtu = 0;
|
2019-05-23 19:35:30 +08:00
|
|
|
mDhcpServerAddress = null;
|
2014-08-06 12:00:25 -07:00
|
|
|
mTcpBufferSizes = null;
|
2019-01-08 09:58:59 +09:00
|
|
|
mNat64Prefix = null;
|
2019-09-24 13:32:13 +02:00
|
|
|
mWakeOnLanSupported = false;
|
2019-12-17 16:45:42 +09:00
|
|
|
mCaptivePortalApiUrl = null;
|
|
|
|
|
mCaptivePortalData = null;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implement the Parcelable interface
|
|
|
|
|
*/
|
|
|
|
|
public int describeContents() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-27 11:15:18 -07:00
|
|
|
@Override
|
2010-08-30 10:56:47 -07:00
|
|
|
public String toString() {
|
2018-06-07 13:27:00 +09:00
|
|
|
// Space as a separator, so no need for spaces at start/end of the individual fragments.
|
|
|
|
|
final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}");
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
if (mIfaceName != null) {
|
|
|
|
|
resultJoiner.add("InterfaceName:");
|
|
|
|
|
resultJoiner.add(mIfaceName);
|
|
|
|
|
}
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("LinkAddresses: [");
|
|
|
|
|
if (!mLinkAddresses.isEmpty()) {
|
|
|
|
|
resultJoiner.add(TextUtils.join(",", mLinkAddresses));
|
|
|
|
|
}
|
|
|
|
|
resultJoiner.add("]");
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("DnsAddresses: [");
|
|
|
|
|
if (!mDnses.isEmpty()) {
|
|
|
|
|
resultJoiner.add(TextUtils.join(",", mDnses));
|
|
|
|
|
}
|
|
|
|
|
resultJoiner.add("]");
|
|
|
|
|
|
|
|
|
|
if (mUsePrivateDns) {
|
|
|
|
|
resultJoiner.add("UsePrivateDns: true");
|
|
|
|
|
}
|
2018-01-17 14:20:55 -05:00
|
|
|
|
2018-06-07 13:28:09 +09:00
|
|
|
if (mPrivateDnsServerName != null) {
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("PrivateDnsServerName:");
|
|
|
|
|
resultJoiner.add(mPrivateDnsServerName);
|
2018-01-17 14:20:55 -05:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 20:42:19 +09:00
|
|
|
if (!mPcscfs.isEmpty()) {
|
|
|
|
|
resultJoiner.add("PcscfAddresses: [");
|
|
|
|
|
resultJoiner.add(TextUtils.join(",", mPcscfs));
|
|
|
|
|
resultJoiner.add("]");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 16:36:41 +09:00
|
|
|
if (!mValidatedPrivateDnses.isEmpty()) {
|
2018-06-07 13:27:00 +09:00
|
|
|
final StringJoiner validatedPrivateDnsesJoiner =
|
|
|
|
|
new StringJoiner(",", "ValidatedPrivateDnsAddresses: [", "]");
|
|
|
|
|
for (final InetAddress addr : mValidatedPrivateDnses) {
|
|
|
|
|
validatedPrivateDnsesJoiner.add(addr.getHostAddress());
|
2018-04-11 16:36:41 +09:00
|
|
|
}
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add(validatedPrivateDnsesJoiner.toString());
|
2018-04-11 16:36:41 +09:00
|
|
|
}
|
|
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("Domains:");
|
|
|
|
|
resultJoiner.add(mDomains);
|
2012-11-09 10:52:27 -08:00
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("MTU:");
|
|
|
|
|
resultJoiner.add(Integer.toString(mMtu));
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
|
2019-09-24 13:32:13 +02:00
|
|
|
if (mWakeOnLanSupported) {
|
|
|
|
|
resultJoiner.add("WakeOnLanSupported: true");
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 19:35:30 +08:00
|
|
|
if (mDhcpServerAddress != null) {
|
|
|
|
|
resultJoiner.add("ServerAddress:");
|
|
|
|
|
resultJoiner.add(mDhcpServerAddress.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 16:45:42 +09:00
|
|
|
if (mCaptivePortalApiUrl != null) {
|
|
|
|
|
resultJoiner.add("CaptivePortalApiUrl: " + mCaptivePortalApiUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mCaptivePortalData != null) {
|
|
|
|
|
resultJoiner.add("CaptivePortalData: " + mCaptivePortalData);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-06 12:00:25 -07:00
|
|
|
if (mTcpBufferSizes != null) {
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("TcpBufferSizes:");
|
|
|
|
|
resultJoiner.add(mTcpBufferSizes);
|
2014-08-06 12:00:25 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add("Routes: [");
|
|
|
|
|
if (!mRoutes.isEmpty()) {
|
|
|
|
|
resultJoiner.add(TextUtils.join(",", mRoutes));
|
|
|
|
|
}
|
|
|
|
|
resultJoiner.add("]");
|
2010-06-15 15:43:39 -07:00
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
if (mHttpProxy != null) {
|
|
|
|
|
resultJoiner.add("HttpProxy:");
|
|
|
|
|
resultJoiner.add(mHttpProxy.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 09:58:59 +09:00
|
|
|
if (mNat64Prefix != null) {
|
|
|
|
|
resultJoiner.add("Nat64Prefix:");
|
|
|
|
|
resultJoiner.add(mNat64Prefix.toString());
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values();
|
|
|
|
|
if (!stackedLinksValues.isEmpty()) {
|
|
|
|
|
final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]");
|
|
|
|
|
for (final LinkProperties lp : stackedLinksValues) {
|
|
|
|
|
stackedLinksJoiner.add("[ " + lp + " ]");
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
2018-06-07 13:27:00 +09:00
|
|
|
resultJoiner.add(stackedLinksJoiner.toString());
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
2018-06-07 13:27:00 +09:00
|
|
|
|
|
|
|
|
return resultJoiner.toString();
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv4 address.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 address, {@code false} otherwise.
|
2014-06-06 10:30:11 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv4Address() {
|
2013-03-07 10:59:25 -08:00
|
|
|
for (LinkAddress address : mLinkAddresses) {
|
2017-10-10 16:29:06 +09:00
|
|
|
if (address.getAddress() instanceof Inet4Address) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-03-07 10:59:25 -08:00
|
|
|
}
|
|
|
|
|
return false;
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is an IPv4 address, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasIPv4Address() {
|
|
|
|
|
return hasIpv4Address();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-27 16:35:33 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link or any of its stacked interfaces has an IPv4 address.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 address, {@code false} otherwise.
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
private boolean hasIpv4AddressOnInterface(String iface) {
|
2015-07-30 23:41:43 +09:00
|
|
|
// mIfaceName can be null.
|
2019-03-08 16:35:20 +08:00
|
|
|
return (Objects.equals(iface, mIfaceName) && hasIpv4Address())
|
|
|
|
|
|| (iface != null && mStackedLinks.containsKey(iface)
|
|
|
|
|
&& mStackedLinks.get(iface).hasIpv4Address());
|
2015-07-27 16:35:33 +09:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 11:00:12 +09:00
|
|
|
/**
|
2014-06-23 22:33:43 +09:00
|
|
|
* Returns true if this link has a global preferred IPv6 address.
|
2013-08-08 11:00:12 +09:00
|
|
|
*
|
2014-06-23 22:33:43 +09:00
|
|
|
* @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise.
|
2014-06-06 10:30:11 -07:00
|
|
|
* @hide
|
2013-08-08 11:00:12 +09:00
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasGlobalIpv6Address() {
|
2013-08-08 11:00:12 +09:00
|
|
|
for (LinkAddress address : mLinkAddresses) {
|
2014-06-23 22:33:43 +09:00
|
|
|
if (address.getAddress() instanceof Inet6Address && address.isGlobalPreferred()) {
|
2013-08-08 11:00:12 +09:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 14:37:05 +01:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv4 unreachable default route.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 unreachable default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasIpv4UnreachableDefaultRoute() {
|
|
|
|
|
for (RouteInfo r : mRoutes) {
|
|
|
|
|
if (r.isIPv4UnreachableDefault()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasGlobalIPv6Address() {
|
|
|
|
|
return hasGlobalIpv6Address();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 22:33:43 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv4 default route.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv4DefaultRoute() {
|
2014-06-23 22:33:43 +09:00
|
|
|
for (RouteInfo r : mRoutes) {
|
2017-10-10 16:29:06 +09:00
|
|
|
if (r.isIPv4Default()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-23 22:33:43 +09:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 14:37:05 +01:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv6 unreachable default route.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv6 unreachable default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasIpv6UnreachableDefaultRoute() {
|
|
|
|
|
for (RouteInfo r : mRoutes) {
|
|
|
|
|
if (r.isIPv6UnreachableDefault()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is an IPv4 default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasIPv4DefaultRoute() {
|
|
|
|
|
return hasIpv4DefaultRoute();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 22:33:43 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv6 default route.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv6 default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv6DefaultRoute() {
|
2014-06-23 22:33:43 +09:00
|
|
|
for (RouteInfo r : mRoutes) {
|
2017-10-10 16:29:06 +09:00
|
|
|
if (r.isIPv6Default()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-23 22:33:43 +09:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is an IPv6 default route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasIPv6DefaultRoute() {
|
|
|
|
|
return hasIpv6DefaultRoute();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 22:33:43 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv4 DNS server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv4DnsServer() {
|
2014-06-23 22:33:43 +09:00
|
|
|
for (InetAddress ia : mDnses) {
|
2017-10-10 16:29:06 +09:00
|
|
|
if (ia instanceof Inet4Address) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-23 22:33:43 +09:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasIPv4DnsServer() {
|
|
|
|
|
return hasIpv4DnsServer();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 22:33:43 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv6 DNS server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-10-02 20:07:38 +08:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv6DnsServer() {
|
2014-06-23 22:33:43 +09:00
|
|
|
for (InetAddress ia : mDnses) {
|
2017-10-10 16:29:06 +09:00
|
|
|
if (ia instanceof Inet6Address) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-23 22:33:43 +09:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean hasIPv6DnsServer() {
|
|
|
|
|
return hasIpv6DnsServer();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 20:42:19 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv4 PCSCF server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv4 PCSCF server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv4PcscfServer() {
|
2018-06-28 20:42:19 +09:00
|
|
|
for (InetAddress ia : mPcscfs) {
|
|
|
|
|
if (ia instanceof Inet4Address) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if this link has an IPv6 PCSCF server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an IPv6 PCSCF server, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean hasIpv6PcscfServer() {
|
2018-06-28 20:42:19 +09:00
|
|
|
for (InetAddress ia : mPcscfs) {
|
|
|
|
|
if (ia instanceof Inet6Address) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-23 22:33:43 +09:00
|
|
|
/**
|
2014-10-24 21:50:20 +09:00
|
|
|
* Returns true if this link is provisioned for global IPv4 connectivity.
|
|
|
|
|
* This requires an IP address, default route, and DNS server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if the link is provisioned, {@code false} otherwise.
|
2015-05-21 16:15:02 +09:00
|
|
|
* @hide
|
2014-10-24 21:50:20 +09:00
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIpv4Provisioned() {
|
|
|
|
|
return (hasIpv4Address()
|
|
|
|
|
&& hasIpv4DefaultRoute()
|
|
|
|
|
&& hasIpv4DnsServer());
|
2014-10-24 21:50:20 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if this link is provisioned for global IPv6 connectivity.
|
|
|
|
|
* This requires an IP address, default route, and DNS server.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if the link is provisioned, {@code false} otherwise.
|
2015-05-21 16:15:02 +09:00
|
|
|
* @hide
|
2014-10-24 21:50:20 +09:00
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIpv6Provisioned() {
|
|
|
|
|
return (hasGlobalIpv6Address()
|
|
|
|
|
&& hasIpv6DefaultRoute()
|
|
|
|
|
&& hasIpv6DnsServer());
|
2014-10-24 21:50:20 +09:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:35:20 +08:00
|
|
|
/**
|
|
|
|
|
* For backward compatibility.
|
|
|
|
|
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
|
|
|
|
|
* just yet.
|
|
|
|
|
* @return {@code true} if the link is provisioned, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
|
|
|
|
public boolean isIPv6Provisioned() {
|
|
|
|
|
return isIpv6Provisioned();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-24 21:50:20 +09:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link is provisioned for global connectivity,
|
|
|
|
|
* for at least one Internet Protocol family.
|
2014-06-23 22:33:43 +09:00
|
|
|
*
|
|
|
|
|
* @return {@code true} if the link is provisioned, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2014-06-23 22:33:43 +09:00
|
|
|
public boolean isProvisioned() {
|
2019-03-08 16:35:20 +08:00
|
|
|
return (isIpv4Provisioned() || isIpv6Provisioned());
|
2014-06-23 22:33:43 +09:00
|
|
|
}
|
|
|
|
|
|
2015-06-26 19:21:34 +09:00
|
|
|
/**
|
|
|
|
|
* Evaluate whether the {@link InetAddress} is considered reachable.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if the given {@link InetAddress} is considered reachable,
|
|
|
|
|
* {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-01-20 12:38:10 +09:00
|
|
|
@SystemApi
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isReachable(@NonNull InetAddress ip) {
|
2015-06-26 19:21:34 +09:00
|
|
|
final List<RouteInfo> allRoutes = getAllRoutes();
|
|
|
|
|
// If we don't have a route to this IP address, it's not reachable.
|
|
|
|
|
final RouteInfo bestRoute = RouteInfo.selectBestRoute(allRoutes, ip);
|
|
|
|
|
if (bestRoute == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: better source address evaluation for destination addresses.
|
|
|
|
|
|
|
|
|
|
if (ip instanceof Inet4Address) {
|
|
|
|
|
// For IPv4, it suffices for now to simply have any address.
|
2019-03-08 16:35:20 +08:00
|
|
|
return hasIpv4AddressOnInterface(bestRoute.getInterface());
|
2015-06-26 19:21:34 +09:00
|
|
|
} else if (ip instanceof Inet6Address) {
|
|
|
|
|
if (ip.isLinkLocalAddress()) {
|
|
|
|
|
// For now, just make sure link-local destinations have
|
|
|
|
|
// scopedIds set, since transmits will generally fail otherwise.
|
|
|
|
|
// TODO: verify it matches the ifindex of one of the interfaces.
|
|
|
|
|
return (((Inet6Address)ip).getScopeId() != 0);
|
|
|
|
|
} else {
|
|
|
|
|
// For non-link-local destinations check that either the best route
|
|
|
|
|
// is directly connected or that some global preferred address exists.
|
|
|
|
|
// TODO: reconsider all cases (disconnected ULA networks, ...).
|
2019-03-08 16:35:20 +08:00
|
|
|
return (!bestRoute.hasGateway() || hasGlobalIpv6Address());
|
2015-06-26 19:21:34 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 04:02:05 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if this link has a throw route.
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if there is an exclude route, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasExcludeRoute() {
|
|
|
|
|
for (RouteInfo r : mRoutes) {
|
|
|
|
|
if (r.getType() == RouteInfo.RTN_THROW) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 13:44:13 -07:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} interface name against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2011-07-13 13:44:13 -07:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalInterfaceName(@NonNull LinkProperties target) {
|
2019-12-17 00:33:18 +08:00
|
|
|
return LinkPropertiesUtils.isIdenticalInterfaceName(target, this);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 19:35:30 +08:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} DHCP server address against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean isIdenticalDhcpServerAddress(@NonNull LinkProperties target) {
|
|
|
|
|
return Objects.equals(mDhcpServerAddress, target.mDhcpServerAddress);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 13:44:13 -07:00
|
|
|
/**
|
2012-10-31 14:32:53 -07:00
|
|
|
* Compares this {@code LinkProperties} interface addresses against the target
|
2011-07-13 13:44:13 -07:00
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2011-07-13 13:44:13 -07:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalAddresses(@NonNull LinkProperties target) {
|
2019-12-17 00:33:18 +08:00
|
|
|
return LinkPropertiesUtils.isIdenticalAddresses(target, this);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} DNS addresses against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2011-07-13 13:44:13 -07:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalDnses(@NonNull LinkProperties target) {
|
2019-12-17 00:33:18 +08:00
|
|
|
return LinkPropertiesUtils.isIdenticalDnses(target, this);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
|
|
|
|
|
2018-01-17 14:20:55 -05:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} private DNS settings against the
|
|
|
|
|
* target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalPrivateDns(@NonNull LinkProperties target) {
|
2018-01-17 14:20:55 -05:00
|
|
|
return (isPrivateDnsActive() == target.isPrivateDnsActive()
|
|
|
|
|
&& TextUtils.equals(getPrivateDnsServerName(),
|
|
|
|
|
target.getPrivateDnsServerName()));
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 16:36:41 +09:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} validated private DNS addresses against
|
|
|
|
|
* the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalValidatedPrivateDnses(@NonNull LinkProperties target) {
|
2018-04-11 16:36:41 +09:00
|
|
|
Collection<InetAddress> targetDnses = target.getValidatedPrivateDnsServers();
|
|
|
|
|
return (mValidatedPrivateDnses.size() == targetDnses.size())
|
|
|
|
|
? mValidatedPrivateDnses.containsAll(targetDnses) : false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 20:42:19 +09:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} PCSCF addresses against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalPcscfs(@NonNull LinkProperties target) {
|
2018-06-28 20:42:19 +09:00
|
|
|
Collection<InetAddress> targetPcscfs = target.getPcscfServers();
|
|
|
|
|
return (mPcscfs.size() == targetPcscfs.size()) ?
|
|
|
|
|
mPcscfs.containsAll(targetPcscfs) : false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 13:44:13 -07:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} Routes against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2011-07-13 13:44:13 -07:00
|
|
|
*/
|
2018-08-08 14:52:47 +01:00
|
|
|
@UnsupportedAppUsage
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalRoutes(@NonNull LinkProperties target) {
|
2019-12-17 00:33:18 +08:00
|
|
|
return LinkPropertiesUtils.isIdenticalRoutes(target, this);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} HttpProxy against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2011-07-13 13:44:13 -07:00
|
|
|
*/
|
2018-12-20 15:30:45 +00:00
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalHttpProxy(@NonNull LinkProperties target) {
|
2019-12-17 00:33:18 +08:00
|
|
|
return LinkPropertiesUtils.isIdenticalHttpProxy(target, this);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
2011-04-04 12:35:42 -07:00
|
|
|
|
2013-03-07 10:59:25 -08:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} stacked links against the target
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
2013-03-07 10:59:25 -08:00
|
|
|
*/
|
2020-11-04 09:29:36 +00:00
|
|
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalStackedLinks(@NonNull LinkProperties target) {
|
2013-04-01 10:47:43 +09:00
|
|
|
if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) {
|
2013-03-07 10:59:25 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
for (LinkProperties stacked : mStackedLinks.values()) {
|
|
|
|
|
// Hashtable values can never be null.
|
|
|
|
|
String iface = stacked.getInterfaceName();
|
|
|
|
|
if (!stacked.equals(target.mStackedLinks.get(iface))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} MTU against the target
|
|
|
|
|
*
|
2013-09-06 22:53:16 -07:00
|
|
|
* @param target LinkProperties to compare.
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
2014-05-18 22:01:38 -07:00
|
|
|
* @hide
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalMtu(@NonNull LinkProperties target) {
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
return getMtu() == target.getMtu();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-06 12:00:25 -07:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} Tcp buffer sizes against the target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalTcpBufferSizes(@NonNull LinkProperties target) {
|
2014-08-06 12:00:25 -07:00
|
|
|
return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-08 09:58:59 +09:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} NAT64 prefix against the target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
2019-03-08 16:35:20 +08:00
|
|
|
public boolean isIdenticalNat64Prefix(@NonNull LinkProperties target) {
|
2019-01-08 09:58:59 +09:00
|
|
|
return Objects.equals(mNat64Prefix, target.mNat64Prefix);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 13:32:13 +02:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} WakeOnLan supported against the target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean isIdenticalWakeOnLan(LinkProperties target) {
|
|
|
|
|
return isWakeOnLanSupported() == target.isWakeOnLanSupported();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 16:45:42 +09:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties}'s CaptivePortalApiUrl against the target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean isIdenticalCaptivePortalApiUrl(LinkProperties target) {
|
|
|
|
|
return Objects.equals(mCaptivePortalApiUrl, target.mCaptivePortalApiUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties}'s CaptivePortalData against the target.
|
|
|
|
|
*
|
|
|
|
|
* @param target LinkProperties to compare.
|
|
|
|
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public boolean isIdenticalCaptivePortalData(LinkProperties target) {
|
|
|
|
|
return Objects.equals(mCaptivePortalData, target.mCaptivePortalData);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 13:32:13 +02:00
|
|
|
/**
|
|
|
|
|
* Set whether the network interface supports WakeOnLAN
|
|
|
|
|
*
|
|
|
|
|
* @param supported WakeOnLAN supported value
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public void setWakeOnLanSupported(boolean supported) {
|
|
|
|
|
mWakeOnLanSupported = supported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the network interface supports WakeOnLAN
|
|
|
|
|
*
|
|
|
|
|
* @return {@code true} if interface supports WakeOnLAN, {@code false} otherwise.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isWakeOnLanSupported() {
|
|
|
|
|
return mWakeOnLanSupported;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 16:45:42 +09:00
|
|
|
/**
|
|
|
|
|
* Set the URL of the captive portal API endpoint to get more information about the network.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
public void setCaptivePortalApiUrl(@Nullable Uri url) {
|
|
|
|
|
mCaptivePortalApiUrl = url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the URL of the captive portal API endpoint to get more information about the network.
|
|
|
|
|
*
|
|
|
|
|
* <p>This is null unless the application has
|
|
|
|
|
* {@link android.Manifest.permission.NETWORK_SETTINGS} or
|
|
|
|
|
* {@link NetworkStack#PERMISSION_MAINLINE_NETWORK_STACK} permissions, and the network provided
|
|
|
|
|
* the URL.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
@Nullable
|
|
|
|
|
public Uri getCaptivePortalApiUrl() {
|
|
|
|
|
return mCaptivePortalApiUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the CaptivePortalData obtained from the captive portal API (RFC7710bis).
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
public void setCaptivePortalData(@Nullable CaptivePortalData data) {
|
|
|
|
|
mCaptivePortalData = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the CaptivePortalData obtained from the captive portal API (RFC7710bis).
|
|
|
|
|
*
|
|
|
|
|
* <p>This is null unless the application has
|
|
|
|
|
* {@link android.Manifest.permission.NETWORK_SETTINGS} or
|
|
|
|
|
* {@link NetworkStack#PERMISSION_MAINLINE_NETWORK_STACK} permissions.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
@Nullable
|
|
|
|
|
public CaptivePortalData getCaptivePortalData() {
|
|
|
|
|
return mCaptivePortalData;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 12:35:42 -07:00
|
|
|
/**
|
|
|
|
|
* Compares this {@code LinkProperties} instance against the target
|
|
|
|
|
* LinkProperties in {@code obj}. Two LinkPropertieses are equal if
|
|
|
|
|
* all their fields are equal in values.
|
|
|
|
|
*
|
|
|
|
|
* For collection fields, such as mDnses, containsAll() is used to check
|
|
|
|
|
* if two collections contains the same elements, independent of order.
|
|
|
|
|
* There are two thoughts regarding containsAll()
|
|
|
|
|
* 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal.
|
|
|
|
|
* 2. Worst case performance is O(n^2).
|
|
|
|
|
*
|
|
|
|
|
* @param obj the object to be tested for equality.
|
|
|
|
|
* @return {@code true} if both objects are equal, {@code false} otherwise.
|
|
|
|
|
*/
|
2018-06-07 13:27:00 +09:00
|
|
|
@Override
|
2020-10-14 15:59:06 -07:00
|
|
|
public boolean equals(@Nullable Object obj) {
|
2011-04-04 12:35:42 -07:00
|
|
|
if (this == obj) return true;
|
|
|
|
|
|
|
|
|
|
if (!(obj instanceof LinkProperties)) return false;
|
|
|
|
|
|
|
|
|
|
LinkProperties target = (LinkProperties) obj;
|
2018-06-07 13:27:00 +09:00
|
|
|
/*
|
2014-05-18 22:01:38 -07:00
|
|
|
* This method does not check that stacked interfaces are equal, because
|
|
|
|
|
* stacked interfaces are not so much a property of the link as a
|
|
|
|
|
* description of connections between links.
|
|
|
|
|
*/
|
2018-01-17 14:20:55 -05:00
|
|
|
return isIdenticalInterfaceName(target)
|
|
|
|
|
&& isIdenticalAddresses(target)
|
2019-05-23 19:35:30 +08:00
|
|
|
&& isIdenticalDhcpServerAddress(target)
|
2018-01-17 14:20:55 -05:00
|
|
|
&& isIdenticalDnses(target)
|
|
|
|
|
&& isIdenticalPrivateDns(target)
|
2018-04-11 16:36:41 +09:00
|
|
|
&& isIdenticalValidatedPrivateDnses(target)
|
2018-06-28 20:42:19 +09:00
|
|
|
&& isIdenticalPcscfs(target)
|
2018-01-17 14:20:55 -05:00
|
|
|
&& isIdenticalRoutes(target)
|
|
|
|
|
&& isIdenticalHttpProxy(target)
|
|
|
|
|
&& isIdenticalStackedLinks(target)
|
|
|
|
|
&& isIdenticalMtu(target)
|
2019-01-08 09:58:59 +09:00
|
|
|
&& isIdenticalTcpBufferSizes(target)
|
2019-09-24 13:32:13 +02:00
|
|
|
&& isIdenticalNat64Prefix(target)
|
2019-12-17 16:45:42 +09:00
|
|
|
&& isIdenticalWakeOnLan(target)
|
|
|
|
|
&& isIdenticalCaptivePortalApiUrl(target)
|
|
|
|
|
&& isIdenticalCaptivePortalData(target);
|
2011-07-13 13:44:13 -07:00
|
|
|
}
|
2011-04-04 12:35:42 -07:00
|
|
|
|
|
|
|
|
/**
|
2018-06-07 13:27:00 +09:00
|
|
|
* Generate hashcode based on significant fields
|
|
|
|
|
*
|
2011-04-04 12:35:42 -07:00
|
|
|
* Equal objects must produce the same hash code, while unequal objects
|
|
|
|
|
* may have the same hash codes.
|
|
|
|
|
*/
|
2018-06-07 13:27:00 +09:00
|
|
|
@Override
|
2011-04-04 12:35:42 -07:00
|
|
|
public int hashCode() {
|
|
|
|
|
return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
|
|
|
|
|
+ mLinkAddresses.size() * 31
|
|
|
|
|
+ mDnses.size() * 37
|
2018-04-11 16:36:41 +09:00
|
|
|
+ mValidatedPrivateDnses.size() * 61
|
2012-11-09 10:52:27 -08:00
|
|
|
+ ((null == mDomains) ? 0 : mDomains.hashCode())
|
2011-04-28 14:28:50 -07:00
|
|
|
+ mRoutes.size() * 41
|
2013-03-07 10:59:25 -08:00
|
|
|
+ ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
+ mStackedLinks.hashCode() * 47)
|
2014-08-06 12:00:25 -07:00
|
|
|
+ mMtu * 51
|
2018-01-17 14:20:55 -05:00
|
|
|
+ ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode())
|
|
|
|
|
+ (mUsePrivateDns ? 57 : 0)
|
2019-05-23 19:35:30 +08:00
|
|
|
+ ((null == mDhcpServerAddress) ? 0 : mDhcpServerAddress.hashCode())
|
2018-06-28 20:42:19 +09:00
|
|
|
+ mPcscfs.size() * 67
|
2019-01-08 09:58:59 +09:00
|
|
|
+ ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode())
|
2019-09-24 13:32:13 +02:00
|
|
|
+ Objects.hash(mNat64Prefix)
|
2019-12-17 16:45:42 +09:00
|
|
|
+ (mWakeOnLanSupported ? 71 : 0)
|
|
|
|
|
+ Objects.hash(mCaptivePortalApiUrl, mCaptivePortalData);
|
2011-04-04 12:35:42 -07:00
|
|
|
}
|
|
|
|
|
|
2010-06-15 15:43:39 -07:00
|
|
|
/**
|
|
|
|
|
* Implement the Parcelable interface.
|
|
|
|
|
*/
|
2010-08-30 10:56:47 -07:00
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
2010-06-15 15:43:39 -07:00
|
|
|
dest.writeString(getInterfaceName());
|
2010-10-01 16:08:28 -07:00
|
|
|
dest.writeInt(mLinkAddresses.size());
|
2018-04-11 16:36:41 +09:00
|
|
|
for (LinkAddress linkAddress : mLinkAddresses) {
|
2010-10-01 16:08:28 -07:00
|
|
|
dest.writeParcelable(linkAddress, flags);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2010-10-01 16:08:28 -07:00
|
|
|
|
2019-12-18 14:47:06 +09:00
|
|
|
writeAddresses(dest, mDnses);
|
|
|
|
|
writeAddresses(dest, mValidatedPrivateDnses);
|
2018-01-17 14:20:55 -05:00
|
|
|
dest.writeBoolean(mUsePrivateDns);
|
|
|
|
|
dest.writeString(mPrivateDnsServerName);
|
2019-12-18 14:47:06 +09:00
|
|
|
writeAddresses(dest, mPcscfs);
|
2012-11-09 10:52:27 -08:00
|
|
|
dest.writeString(mDomains);
|
2020-01-06 19:43:59 +09:00
|
|
|
writeAddress(dest, mDhcpServerAddress);
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
dest.writeInt(mMtu);
|
2014-08-06 12:00:25 -07:00
|
|
|
dest.writeString(mTcpBufferSizes);
|
2011-04-28 14:28:50 -07:00
|
|
|
dest.writeInt(mRoutes.size());
|
2018-04-11 16:36:41 +09:00
|
|
|
for (RouteInfo route : mRoutes) {
|
2011-04-28 14:28:50 -07:00
|
|
|
dest.writeParcelable(route, flags);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2011-02-09 13:56:06 -08:00
|
|
|
|
2010-06-15 15:43:39 -07:00
|
|
|
if (mHttpProxy != null) {
|
|
|
|
|
dest.writeByte((byte)1);
|
|
|
|
|
dest.writeParcelable(mHttpProxy, flags);
|
|
|
|
|
} else {
|
|
|
|
|
dest.writeByte((byte)0);
|
|
|
|
|
}
|
2019-01-08 09:58:59 +09:00
|
|
|
dest.writeParcelable(mNat64Prefix, 0);
|
|
|
|
|
|
2018-06-07 13:27:00 +09:00
|
|
|
ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values());
|
2013-03-07 10:59:25 -08:00
|
|
|
dest.writeList(stackedLinks);
|
2019-09-24 13:32:13 +02:00
|
|
|
|
|
|
|
|
dest.writeBoolean(mWakeOnLanSupported);
|
2019-12-17 16:45:42 +09:00
|
|
|
dest.writeParcelable(mParcelSensitiveFields ? mCaptivePortalApiUrl : null, 0);
|
|
|
|
|
dest.writeParcelable(mParcelSensitiveFields ? mCaptivePortalData : null, 0);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
|
2019-12-18 14:47:06 +09:00
|
|
|
private static void writeAddresses(@NonNull Parcel dest, @NonNull List<InetAddress> list) {
|
|
|
|
|
dest.writeInt(list.size());
|
|
|
|
|
for (InetAddress d : list) {
|
|
|
|
|
writeAddress(dest, d);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 19:43:59 +09:00
|
|
|
private static void writeAddress(@NonNull Parcel dest, @Nullable InetAddress addr) {
|
|
|
|
|
byte[] addressBytes = (addr == null ? null : addr.getAddress());
|
|
|
|
|
dest.writeByteArray(addressBytes);
|
2019-12-18 14:47:06 +09:00
|
|
|
if (addr instanceof Inet6Address) {
|
|
|
|
|
final Inet6Address v6Addr = (Inet6Address) addr;
|
|
|
|
|
final boolean hasScopeId = v6Addr.getScopeId() != 0;
|
|
|
|
|
dest.writeBoolean(hasScopeId);
|
|
|
|
|
if (hasScopeId) dest.writeInt(v6Addr.getScopeId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 19:43:59 +09:00
|
|
|
@Nullable
|
2019-12-18 14:47:06 +09:00
|
|
|
private static InetAddress readAddress(@NonNull Parcel p) throws UnknownHostException {
|
|
|
|
|
final byte[] addr = p.createByteArray();
|
2020-01-06 19:43:59 +09:00
|
|
|
if (addr == null) return null;
|
|
|
|
|
|
2019-12-18 14:47:06 +09:00
|
|
|
if (addr.length == INET6_ADDR_LENGTH) {
|
|
|
|
|
final boolean hasScopeId = p.readBoolean();
|
|
|
|
|
final int scopeId = hasScopeId ? p.readInt() : 0;
|
|
|
|
|
return Inet6Address.getByAddress(null /* host */, addr, scopeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return InetAddress.getByAddress(addr);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-15 15:43:39 -07:00
|
|
|
/**
|
|
|
|
|
* Implement the Parcelable interface.
|
|
|
|
|
*/
|
2019-02-28 12:06:45 -07:00
|
|
|
public static final @android.annotation.NonNull Creator<LinkProperties> CREATOR =
|
2010-08-30 10:56:47 -07:00
|
|
|
new Creator<LinkProperties>() {
|
|
|
|
|
public LinkProperties createFromParcel(Parcel in) {
|
|
|
|
|
LinkProperties netProp = new LinkProperties();
|
2012-10-31 14:32:53 -07:00
|
|
|
|
2010-06-15 15:43:39 -07:00
|
|
|
String iface = in.readString();
|
|
|
|
|
if (iface != null) {
|
2012-10-31 14:32:53 -07:00
|
|
|
netProp.setInterfaceName(iface);
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
int addressCount = in.readInt();
|
2018-04-11 16:36:41 +09:00
|
|
|
for (int i = 0; i < addressCount; i++) {
|
2018-06-07 13:27:00 +09:00
|
|
|
netProp.addLinkAddress(in.readParcelable(null));
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
addressCount = in.readInt();
|
2018-04-11 16:36:41 +09:00
|
|
|
for (int i = 0; i < addressCount; i++) {
|
2010-06-15 15:43:39 -07:00
|
|
|
try {
|
2019-12-18 14:47:06 +09:00
|
|
|
netProp.addDnsServer(readAddress(in));
|
2010-06-15 15:43:39 -07:00
|
|
|
} catch (UnknownHostException e) { }
|
|
|
|
|
}
|
2018-04-11 16:36:41 +09:00
|
|
|
addressCount = in.readInt();
|
|
|
|
|
for (int i = 0; i < addressCount; i++) {
|
|
|
|
|
try {
|
2019-12-18 14:47:06 +09:00
|
|
|
netProp.addValidatedPrivateDnsServer(readAddress(in));
|
2018-04-11 16:36:41 +09:00
|
|
|
} catch (UnknownHostException e) { }
|
|
|
|
|
}
|
2018-01-17 14:20:55 -05:00
|
|
|
netProp.setUsePrivateDns(in.readBoolean());
|
|
|
|
|
netProp.setPrivateDnsServerName(in.readString());
|
2018-06-28 20:42:19 +09:00
|
|
|
addressCount = in.readInt();
|
|
|
|
|
for (int i = 0; i < addressCount; i++) {
|
|
|
|
|
try {
|
2019-12-18 14:47:06 +09:00
|
|
|
netProp.addPcscfServer(readAddress(in));
|
2018-06-28 20:42:19 +09:00
|
|
|
} catch (UnknownHostException e) { }
|
|
|
|
|
}
|
2012-11-09 10:52:27 -08:00
|
|
|
netProp.setDomains(in.readString());
|
2019-05-23 19:35:30 +08:00
|
|
|
try {
|
|
|
|
|
netProp.setDhcpServerAddress((Inet4Address) InetAddress
|
|
|
|
|
.getByAddress(in.createByteArray()));
|
|
|
|
|
} catch (UnknownHostException e) { }
|
Setting MTU size for specific network.
Able to config network specific MTU size. Normally, the default size of MTU is 1500.
US - ATT 1410, TMUS 1440, SPRINT 1422
KR - SKT 1440, KT 1450, LGU+ 1428
JP - KDDI 1420, SoftBank 1340
CA - RGS 1430, FIDO 1430, MTS 1430, BELL 1358, SaskTel 1358
AU - TEL 1400
Bug: 10195070
Change-Id: Ie18650b37a3d44af944f2dae4aa97c04fb12cd5e
2013-09-02 05:24:09 +09:00
|
|
|
netProp.setMtu(in.readInt());
|
2014-08-06 12:00:25 -07:00
|
|
|
netProp.setTcpBufferSizes(in.readString());
|
2011-02-09 13:56:06 -08:00
|
|
|
addressCount = in.readInt();
|
2018-04-11 16:36:41 +09:00
|
|
|
for (int i = 0; i < addressCount; i++) {
|
2018-06-07 13:27:00 +09:00
|
|
|
netProp.addRoute(in.readParcelable(null));
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
if (in.readByte() == 1) {
|
2018-06-07 13:27:00 +09:00
|
|
|
netProp.setHttpProxy(in.readParcelable(null));
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
2019-01-08 09:58:59 +09:00
|
|
|
netProp.setNat64Prefix(in.readParcelable(null));
|
2013-03-07 10:59:25 -08:00
|
|
|
ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>();
|
|
|
|
|
in.readList(stackedLinks, LinkProperties.class.getClassLoader());
|
|
|
|
|
for (LinkProperties stackedLink: stackedLinks) {
|
|
|
|
|
netProp.addStackedLink(stackedLink);
|
|
|
|
|
}
|
2019-09-24 13:32:13 +02:00
|
|
|
netProp.setWakeOnLanSupported(in.readBoolean());
|
2019-12-17 16:45:42 +09:00
|
|
|
|
|
|
|
|
netProp.setCaptivePortalApiUrl(in.readParcelable(null));
|
|
|
|
|
netProp.setCaptivePortalData(in.readParcelable(null));
|
2010-06-15 15:43:39 -07:00
|
|
|
return netProp;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 10:56:47 -07:00
|
|
|
public LinkProperties[] newArray(int size) {
|
|
|
|
|
return new LinkProperties[size];
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|
|
|
|
|
};
|
2014-08-05 15:18:11 -07:00
|
|
|
|
2018-04-11 16:36:41 +09:00
|
|
|
/**
|
|
|
|
|
* Check the valid MTU range based on IPv4 or IPv6.
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isValidMtu(int mtu, boolean ipv6) {
|
|
|
|
|
if (ipv6) {
|
2018-06-07 13:27:00 +09:00
|
|
|
return mtu >= MIN_MTU_V6 && mtu <= MAX_MTU;
|
2018-04-11 16:36:41 +09:00
|
|
|
} else {
|
2018-06-07 13:27:00 +09:00
|
|
|
return mtu >= MIN_MTU && mtu <= MAX_MTU;
|
2014-08-05 15:18:11 -07:00
|
|
|
}
|
2018-04-11 16:36:41 +09:00
|
|
|
}
|
2010-06-15 15:43:39 -07:00
|
|
|
}
|