将下面代码添加至packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java
结合之前的添加wifi adb的博客
也要仿照着在xml文件中添加以太网相关的变量接口直接使用网络adb
else if (preference == mEnableWifiAdb) {
if (mEnableWifiAdb.isChecked()) {
Settings.Global.putInt(getActivity().getContentResolver(),ADB_WIFI_ENABLED_KEY, 1);
android.os.SystemProperties.set("sys.connect.adb.wifi","1");
EthernetManager mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
int Ethenable = mEthManager.getEthernetIfaceState();
if( Ethenable == EthernetManager.ETHER_IFACE_STATE_UP )
{
IpAssignment mode =mEthManager.getConfiguration().getIpAssignment();
String inetAddr;
if (mode== IpAssignment.STATIC){ // 如果是静态的
StaticIpConfiguration staticIpConfiguration=mEthManager.getConfiguration().getStaticIpConfiguration();
LinkAddress ipAddress = staticIpConfiguration.ipAddress;
inetAddr=ipAddress.getAddress().getHostAddress();
}
else{
String iface = "eth0";
inetAddr = SystemProperties.get("dhcp."+ iface +".ipaddress");
}
if ("0.0.0.0".equals(inetAddr)) {
mEnableWifiAdb.setSummary(getResources().getString(R.string.enable_wifi_adb_openwifi));
}else{
mEnableWifiAdb.setSummary(getResources().
getString(R.string.enable_wifi_adb_connected_summary,inetAddr));
}
}
else
{
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ipAddressString = (ipAddress & 0xFF ) + "." +((ipAddress >> 8 ) & 0xFF) + "." +
((ipAddress >> 16 ) & 0xFF) + "." +( ipAddress >> 24 & 0xFF) ;
Log.i(TAG, "ipAddress="+ipAddress);
Log.i(TAG, "ipAddressString="+ipAddressString);
if ("0.0.0.0".equals(ipAddressString)) {
mEnableWifiAdb.setSummary(getResources().getString(R.string.enable_wifi_adb_openwifi));
}else{
mEnableWifiAdb.setSummary(getResources().
getString(R.string.enable_wifi_adb_connected_summary,ipAddressString));
}
} } else {
Settings.Global.putInt(getActivity().getContentResolver(),ADB_WIFI_ENABLED_KEY, 0);
android.os.SystemProperties.set("sys.connect.adb.wifi","0");
mEnableWifiAdb.setSummary(getResources().getString(R.string.enable_wifi_adb_summary));
}
}