Android 9 网络配置

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以在系统目录下的/etc目录中找到网络配置文件,其中最常见的是wpa_supplicant.conf文件,它存储了Wi-Fi网络配置信息。此外,还有dhclient.conf文件和resolv.conf文件等。这些文件的具体路径和内容可能因不同的Android版本和设备而异。 ### 回答2: Android系统的网络配置文件是指用于配置设备上的网络连接信息的文件。它以XML格式保存,并包含了设备的网络连接信息、代理设置、DNS配置等内容,以实现设备与互联网的连接。 Android系统的网络配置文件主要包括以下几个关键元素: 1. SSID和密码:网络配置文件中包含了设备连接Wi-Fi网络所需的SSID和密码信息。这些信息可以让设备自动连接已知的Wi-Fi网络。 2. 代理设置:代理服务器允许设备通过它们来连接互联网。网络配置文件可以配置设备在使用特定网络时使用代理服务器。代理服务器可以为设备提供安全性和访问控制等功能。 3. DNS配置:DNS(Domain Name System)将域名转换为IP地址,使设备能够访问互联网资源。网络配置文件可以配置设备使用特定的DNS服务器。这样可以提高网络解析速度和安全性。 4. IP配置网络配置文件可以配置设备的IP地址、子网掩码和网关信息。这些配置是设备与本地网络通信所必需的,以及设备与外部网络通信的基础。 通过修改网络配置文件,用户可以自定义设备上的网络连接设置,例如添加新的Wi-Fi网络配置代理服务器、更改DNS服务器等。这样可以满足用户对特定网络环境的需求,同时也提高了设备与互联网的连接稳定性和安全性。 总之,Android系统的网络配置文件是重要的网络连接设置文件,它能够帮助设备实现与互联网的连接,并提供了灵活的定制选项,以满足用户对网络连接的特定需求。 ### 回答3: Android系统的网络配置文件是指一组存储在设备上的文件,用于配置和管理设备的网络连接。这些文件包含了设备需要连接到网络所需的信息和参数。 首先,Android系统的网络配置文件主要包括"wifi-internal-config.xml"、"wpa_supplicant.conf"、"dhcpcd.conf"等几个关键文件。其中,"wifi-internal-config.xml"是用于配置设备的Wi-Fi网络连接信息的文件。它包含了设备需要连接到的Wi-Fi网络的名称(SSID)、密码(password)、加密方式(encryption)、IP地址等相关设置。 其次,"wpa_supplicant.conf"是一个用于管理设备的Wi-Fi网络连接及身份验证的配置文件。它存储了设备连接的Wi-Fi网络的身份验证所需的信息,包括网络的SSID、密码、安全协议等。 另外,"dhcpcd.conf"是一个用于配置设备通过动态主机配置协议(DHCP)获取IP地址的文件。在该文件中,可以设置设备需要连接的网络接口、IP地址、子网掩码、网关、DNS服务器等相关参数。 通过这些网络配置文件,Android系统可以根据用户的配置信息,自动连接到合适的Wi-Fi网络并获取IP地址。这样,用户就可以方便地访问互联网、发送和接收数据。 总之,Android系统的网络配置文件是非常重要的,它们定义了设备的网络连接设置和身份验证信息,确保设备能够顺利连接到网络并进行数据交换。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值