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

相关推荐
cocologin10 分钟前
防火墙虚拟系统实验【华为】
网络
kgduu19 分钟前
js之网络请求与远程资源
开发语言·javascript·网络
qq_2837200523 分钟前
MySQL技巧(三):慢查询开启与分析优化案例
android·adb
常利兵24 分钟前
从Groovy到KTS:Android Gradle脚本的华丽转身
android
穷人小水滴25 分钟前
使用 WebRTC 实现局域网投屏: PC (GNOME ArchLinux) -> 平板 (Android)
android·linux·webrtc·浏览器·js·gnome·投屏
虾..25 分钟前
网络其他重要协议或技术
开发语言·网络·php
zh_xuan26 分钟前
Android compose 无限滚动列表
android
apocalypsx26 分钟前
含并行连接的网络GoogLeNet
网络·人工智能·深度学习
诸神黄昏EX28 分钟前
Android Binder 系列专题【篇六:自定义AIDL HAL进程】
android
Fate_I_C30 分钟前
Android现代开发:Kotlin&Jetpack
android·开发语言·kotlin·android jetpack