欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > android 添加USB网卡并配置DNS

android 添加USB网卡并配置DNS

2024/10/26 20:25:28 来源:https://blog.csdn.net/qq_34694875/article/details/143184924  浏览:    关键词: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 resourcesfinal 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是添加的网卡信息

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com