android 添加USB网卡并配置DNS

工作需要,需要使用TBox分享的网络,Android将TBox当作一个USB网卡,接下来就简单了,配置这个网卡的信息即可。

加载默认网卡的信息在frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java中

复制代码
    EthernetTracker(Context context, Handler handler) {
        mHandler = handler;

        // The services we use.
        IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
        mNMService = INetworkManagementService.Stub.asInterface(b);

        // Interface match regex.
        mIfaceMatch = context.getResources().getString(
                com.android.internal.R.string.config_ethernet_iface_regex);

        // Read default Ethernet interface configuration from resources
        final String[] interfaceConfigs = context.getResources().getStringArray(
                com.android.internal.R.array.config_ethernet_interfaces);
        for (String strConfig : interfaceConfigs) {
            parseEthernetConfig(strConfig);
        }   

        mConfigStore = new EthernetConfigStore();

        NetworkCapabilities nc = createNetworkCapabilities(true /* clear default capabilities */);
        mFactory = new EthernetNetworkFactory(handler, context, nc);
        mFactory.register();
    }  

网卡配置文件在frameworks/base/core/res/res/values/config.xml

复制代码
    <string-array translatable="false" name="config_ethernet_interfaces">
        <item>eth0;30;12,13,14,15;ip=10.100.114.139/24</item>
        <item>usb0;40;12,13,14,15,16</item>
        <item>wwan0;45;12,13,14,15,16;ip=192.168.1.6/24 gateway=192.168.1.5 dns=114.114.114.114</item>
    </string-array>

wwan0是添加的网卡信息

相关推荐
HahaGiver6661 分钟前
Unity与Android原生交互开发入门篇 - 打开Android的设置
android·java·unity·游戏引擎·android studio
QT 小鲜肉7 分钟前
【QT/C++】Qt网络编程进阶:TCP网络编程的基本原理和实际应用(超详细)
c语言·开发语言·网络·c++·qt·学习·tcp/ip
冬天vs不冷21 分钟前
Java基础(十五):注解(Annotation)详解
android·java·python
大隐隐于野8 小时前
tcp 丢包分析
linux·服务器·网络
星释9 小时前
二级等保实战:MySQL安全加固
android·mysql·安全
qqxhb9 小时前
系统架构设计师备考第64天——网络构建关键技术
网络·系统架构·mtbf·mttr·冗余硬件·软件热备·快速检测
哈乐13 小时前
网工应用题:配置命令补全类题目
服务器·前端·网络
梁正雄13 小时前
19、docker跨主机网络 Overlay\Underlay
网络·docker·容器
沧澜sincerely13 小时前
运输层协议概述及UDP
网络·udp·运输层