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是添加的网卡信息

相关推荐
zzc9214 分钟前
Packet Radio Network,PRNET
网络·tcp/ip·互联网·arpanet·自组网·prnet
sdszoe49223 小时前
0904网络设备配置与管理第二次授课讲义
网络·华为交换机基础
努力的小帅4 小时前
CAN通信入门
网络·stm32·单片机·嵌入式硬件·stm32c8t6·can总线通信
久绊A4 小时前
指定端口-SSH连接的目标(告别 22 端口暴力破解)
linux·网络·ssh
2501_915918415 小时前
uni-app 项目 iOS 上架踩坑经验总结 从证书到审核的避坑指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者85 小时前
iOS 上架 uni-app 流程全解析,从打包到发布的完整实践
android·ios·小程序·https·uni-app·iphone·webview
bantinghy9 小时前
Linux系统TCP/IP网络参数优化
linux·网络·tcp/ip
雨白10 小时前
实现双向滑动的 ScalableImageView(上)
android
wanhengidc10 小时前
云手机可以息屏挂手游吗?
运维·网络·安全·游戏·智能手机
一只小白菜~10 小时前
实战记录:H3C路由器IS-IS Level-1邻居建立与路由发布
运维·网络·计算机网络·智能路由器