frameworks/base/core/res/res/values/config.xml
<!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION.
Please don't copy them, copy anything else. -->
<!-- This string array should be overridden by the device to present a list of network
attributes. This is used by the connectivity manager to decide which networks can coexist
based on the hardware -->
<!-- An Array of "[Connection name],[ConnectivityManager.TYPE_xxxx],
[associated radio-type],[priority],[restoral-timer(ms)],[dependencyMet] -->
<!-- the 5th element "resore-time" indicates the number of milliseconds to delay
before automatically restore the default connection. Set -1 if the connection
does not require auto-restore. -->
<!-- the 6th element indicates boot-time dependency-met value. -->
<string-array translatable="false" name="networkAttributes">
<item>"wifi,1,1,1,-1,true"</item>
<item>"mobile,0,0,0,-1,true"</item>
<item>"mobile_mms,2,0,2,60000,true"</item>
<item>"mobile_supl,3,0,2,60000,true"</item>
<item>"mobile_dun,4,0,2,60000,true"</item>
<item>"mobile_hipri,5,0,3,60000,true"</item>
<item>"mobile_fota,10,0,2,60000,true"</item>
<item>"mobile_ims,11,0,2,60000,true"</item>
<item>"mobile_cbs,12,0,2,60000,true"</item>
<item>"wifi_p2p,13,1,0,-1,true"</item>
<item>"mobile_ia,14,0,2,-1,true"</item>
<item>"mobile_emergency,15,0,2,-1,true"</item>
</string-array>
<!-- Array of ConnectivityManager.TYPE_xxxx constants for networks that may only
be controlled by systemOrSignature apps. -->
<integer-array translatable="false" name="config_protectedNetworks">
<item>10</item>
<item>11</item>
<item>12</item>
<item>14</item>
<item>15</item>
</integer-array>
<!-- This string array should be overridden by the device to present a list of radio
attributes. This is used by the connectivity manager to decide which networks can coexist
based on the hardware -->
<!-- An Array of "[ConnectivityManager connectionType],
[# simultaneous connection types]" -->
<string-array translatable="false" name="radioAttributes">
<item>"1,1"</item>
<item>"0,1"</item>
</string-array>
<!-- Regex of wired ethernet ifaces -->
<string translatable="false" name="config_ethernet_iface_regex">usb\\d</string>
<!-- Configuration of Ethernet interfaces in the following format:
<interface name|mac address>;[Network Capabilities];[IP config]
Where
[Network Capabilities] Optional. A comma seprated list of network capabilities.
Values must be from NetworkCapabilities#NET_CAPABILITIES_* constants.
[IP config] Optional. If empty or not specified - DHCP will be used, otherwise
use the following format to specify static IP configuration:
ip=<ip-address/mask> gateway=<ip-address> dns=<comma-sep-ip-addresses>
domains=<comma-sep-domains>
-->
<string-array translatable="false" name="config_ethernet_interfaces">
<!--
<item>eth1;12,13,14,15;ip=192.168.1.10/24 gateway=192.168.1.1 dns=4.4.4.4,8.8.8.8</item>
<item>eth2;;ip=192.168.0.11/24</item>
-->
<!--usb0 used for tbox and dynamic ip assignment-->
<item>usb0;12,13,14,15</item>
<!--usb1 used for meter and static ip assignment-->
<item>usb1;12,13,14,15;ip=192.168.5.99/24</item>
</string-array>
frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java文件中对其配置解析,如 config_ethernet_interfaces数组
private void parseEthernetConfig(String configString) {
String[] tokens = configString.split(";");
String name = tokens[0];
String capabilities = tokens.length > 1 ? tokens[1] : null;
NetworkCapabilities nc = createNetworkCapabilities(
!TextUtils.isEmpty(capabilities) /* clear default capabilities */, capabilities);
mNetworkCapabilities.put(name, nc);
if (tokens.length > 2 && !TextUtils.isEmpty(tokens[2])) {
IpConfiguration ipConfig = parseStaticIpConfiguration(tokens[2]);
mIpConfigurations.put(name, ipConfig);
}
}
frameworks\base\core\java\android\net\NetworkCapabilities.java
private static NetworkCapabilities createNetworkCapabilities(
boolean clearDefaultCapabilities, @Nullable String commaSeparatedCapabilities) {
NetworkCapabilities nc = new NetworkCapabilities();
if (clearDefaultCapabilities) {
nc.clearAll(); // Remove default capabilities.
}
nc.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET);
nc.setLinkUpstreamBandwidthKbps(100 * 1000);
nc.setLinkDownstreamBandwidthKbps(100 * 1000);
if (!TextUtils.isEmpty(commaSeparatedCapabilities)) {
for (String strNetworkCapability : commaSeparatedCapabilities.split(",")) {
if (!TextUtils.isEmpty(strNetworkCapability)) {
nc.addCapability(Integer.valueOf(strNetworkCapability));
}
}
}
return nc;
}
frameworks\base\core\java\android\net\NetworkCapabilities.java
<item>usb1;12,13,14,15;ip=192.168.5.99/24</item>
12,13,14,15定义如下:
public @interface NetCapability { }
/**
* Indicates this is a network that has the ability to reach the
* carrier's MMSC for sending and receiving MMS messages.
*/
public static final int NET_CAPABILITY_MMS = 0;
/**
* Indicates this is a network that has the ability to reach the carrier's
* SUPL server, used to retrieve GPS information.
*/
public static final int NET_CAPABILITY_SUPL = 1;
/**
* Indicates this is a network that has the ability to reach the carrier's
* DUN or tethering gateway.
*/
public static final int NET_CAPABILITY_DUN = 2;
/**
* Indicates this is a network that has the ability to reach the carrier's
* FOTA portal, used for over the air updates.
*/
public static final int NET_CAPABILITY_FOTA = 3;
/**
* Indicates this is a network that has the ability to reach the carrier's
* IMS servers, used for network registration and signaling.
*/
public static final int NET_CAPABILITY_IMS = 4;
/**
* Indicates this is a network that has the ability to reach the carrier's
* CBS servers, used for carrier specific services.
*/
public static final int NET_CAPABILITY_CBS = 5;
/**
* Indicates this is a network that has the ability to reach a Wi-Fi direct
* peer.
*/
public static final int NET_CAPABILITY_WIFI_P2P = 6;
/**
* Indicates this is a network that has the ability to reach a carrier's
* Initial Attach servers.
*/
public static final int NET_CAPABILITY_IA = 7;
/**
* Indicates this is a network that has the ability to reach a carrier's
* RCS servers, used for Rich Communication Services.
*/
public static final int NET_CAPABILITY_RCS = 8;
/**
* Indicates this is a network that has the ability to reach a carrier's
* XCAP servers, used for configuration and control.
*/
public static final int NET_CAPABILITY_XCAP = 9;
/**
* Indicates this is a network that has the ability to reach a carrier's
* Emergency IMS servers or other services, used for network signaling
* during emergency calls.
*/
public static final int NET_CAPABILITY_EIMS = 10;
/**
* Indicates that this network is unmetered.
*/
public static final int NET_CAPABILITY_NOT_METERED = 11;
/**
* Indicates that this network should be able to reach the internet.
*/
public static final int NET_CAPABILITY_INTERNET = 12;
/**
* Indicates that this network is available for general use. If this is not set
* applications should not attempt to communicate on this network. Note that this
* is simply informative and not enforcement - enforcement is handled via other means.
* Set by default.
*/
public static final int NET_CAPABILITY_NOT_RESTRICTED = 13;
/**
* Indicates that the user has indicated implicit trust of this network. This
* generally means it's a sim-selected carrier, a plugged in ethernet, a paired
* BT device or a wifi the user asked to connect to. Untrusted networks
* are probably limited to unknown wifi AP. Set by default.
*/
public static final int NET_CAPABILITY_TRUSTED = 14;
/**
* Indicates that this network is not a VPN. This capability is set by default and should be
* explicitly cleared for VPN networks.
*/
public static final int NET_CAPABILITY_NOT_VPN = 15;
/**
* Indicates that connectivity on this network was successfully validated. For example, for a
* network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully
* detected.
*/
public static final int NET_CAPABILITY_VALIDATED = 16;
/**
* Indicates that this network was found to have a captive portal in place last time it was
* probed.
*/
public static final int NET_CAPABILITY_CAPTIVE_PORTAL = 17;
/**
* Indicates that this network is not roaming.
*/
public static final int NET_CAPABILITY_NOT_ROAMING = 18;
/**
* Indicates that this network is available for use by apps, and not a network that is being
* kept up in the background to facilitate fast network switching.
*/
public static final int NET_CAPABILITY_FOREGROUND = 19;
/**
* Indicates that this network is not congested.
* <p>
* When a network is congested, applications should defer network traffic
* that can be done at a later time, such as uploading analytics.
*/
public static final int NET_CAPABILITY_NOT_CONGESTED = 20;
/**
* Indicates that this network is not currently suspended.
* <p>
* When a network is suspended, the network's IP addresses and any connections
* established on the network remain valid, but the network is temporarily unable
* to transfer data. This can happen, for example, if a cellular network experiences
* a temporary loss of signal, such as when driving through a tunnel, etc.
* A network with this capability is not suspended, so is expected to be able to
* transfer data.
*/
public static final int NET_CAPABILITY_NOT_SUSPENDED = 21;
/**
* Indicates that traffic that goes through this network is paid by oem. For example,
* this network can be used by system apps to upload telemetry data.
* @hide
*/
@SystemApi
public static final int NET_CAPABILITY_OEM_PAID = 22;
网络类型
"MOBILE";//移动数据连接,不能与连接共存,如果wifi打开,则自动关闭
"WIFI";//wifi服务,当激活时,默认情况下,所有的数据流量将使用此连接。
"MOBILE_MMS";//运营商的多媒体消息服务
"MOBILE_SUPL";//平面定位特定移动数据连接
"MOBILE_DUN";//网络桥接,很老的一个网络
"MOBILE_HIPRI";//高优先级的移动数据连接。相同的为{TYPE_MOBILE},但路由的设置是不同的。只有请求的进程将有机会获得移动的DNS服务器。
"WIMAX";//全球互通微波存取数据连接
"BLUETOOTH";//蓝牙
"DUMMY";//虚拟连接
"ETHERNET";//以太网
"MOBILE_FOTA";
"MOBILE_IMS";
"MOBILE_CBS";
"WIFI_P2P";//通过wifi直连wifi