工作需要,需要使用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是添加的网卡信息