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

相关推荐
企业解惑小助手5 小时前
大型企业终端如何统一管理排障实录:批量终端策略不生效问题排查
运维·服务器·网络·域智盾软件
盛世宏博智慧档案6 小时前
IP 温湿度设备频繁断连?TCP 心跳保活机制调试与参数设置指南
网络·网络协议·tcp/ip·php·传感器·温湿度
Gigavision6 小时前
CAS(ME)²数据集 感知图卷积网络算法 CAS(ME)²数据集下载
网络·算法
aodunsoft6 小时前
安全月报 | 傲盾DDoS攻击防御2026年9月简报
网络·安全·ddos
花间相见6 小时前
【计算基础|网络11】TCP(下):拥塞控制与参数优化
网络·tcp/ip·策略模式
lkjaslkdj6 小时前
河马引力Kevlar Mag凯夫拉手机壳,出国旅行eSIM与网络兼容性分析
网络·智能手机
Soari6 小时前
交换机转发模式
开发语言·网络·php
qq_401700416 小时前
QNetworkConfigurationManager 与网络状态监控:Qt 上位机如何判断网络真的可用
网络·智能路由器
hunterandroid6 小时前
android方案 : Multiplatform 跨平台开发实战:一套代码,多端运行
android·前端