平台:RK3399 系统:Android7.1 不同于imx6 Android4.4网络配置单独写了个app,Android7.1的以太网配置集成到了Setting系统设置APP中。如下: 不过,Ethernet 静态IP模式中,IP地址、子网掩码等默认是空,没有初始值。下面尝试添加默认值。
涉及文件:
packages/apps/Settings/src/com/android/settings/ethernet/EtherentStaticIpDialog.java
packages/apps/Settings/src/com/android/settings/ethernet/EthernetSettings.java
packages/apps/Settings/src/com/android/settings/ethernet/getStaticIpInfo.java
packages/apps/Settings/src/com/android/settings/ethernet/PppoeDialog.java
网络配置涉及的文件较少,代码量也比较少,相对好操作。
private void updateIpSettingsInfo() {
Log.d("blb", "Static IP status updateIpSettingsInfo");
ContentResolver contentResolver = mcontext.getContentResolver();
String staticip = /*System.getString(contentResolver,System.ETHERNET_STATIC_IP);*/
mEthManager.getIpAddress();
if (!TextUtils.isEmpty(staticip))
mIpAddressView.setText(staticip);
String ipmask = /*System.getString(contentResolver,System.ETHERNET_STATIC_NETMASK);*/
mEthManager.getNetmask();
if (!TextUtils.isEmpty(ipmask))
ipnetmask.setText(ipmask);
String gateway = /*System.getString(contentResolver,System.ETHERNET_STATIC_GATEWAY);*/
mEthManager.getGateway();
if (!TextUtils.isEmpty(gateway))
mIPgateway.setText(gateway);
String dns = /*System.getString(contentResolver,System.ETHERNET_STATIC_DNS1);*/
mEthManager.getDns();
String mDns1 = nullIpInfo;
String mDns2 = nullIpInfo;
if ((dns != null) && (!dns.equals(""))){
String data[] = dns.split(",");
mDns1 = data[0];
if (data.length > 1)
mDns2 = data[1];
}
if (!TextUtils.isEmpty(mDns1))
mdns1.setText(mDns1);
if (!TextUtils.isEmpty(mDns2))
mdns2.setText(mDns2);
/*String dns2 = System.getString(contentResolver,
System.ETHERNET_STATIC_DNS2);
if (!TextUtils.isEmpty(dns2))
mdns2.setText(dns2);*/
}
updateIpSettingsInfo函数中已经有了DNS配置的模板,给mDns1赋初值,调用android.net.EthernetManager类中的getDns方法获取dns,如果dns为空,setText文本框输入刚才设置的初值。如果dns不为空,使用获取的dns重新设置mDns1,再将mDns1输入到文本框。 按照相似的方法设置IPaddress、Gateway和Netmask,修改方法如下:
diff --git a/packages/apps/Settings/src/com/android/settings/ethernet/EtherentStaticIpDialog.java b/packages/apps/Settings/src/com/android/settings/ethernet/EtherentStaticIpDial
og.java
index c7f1198211..077a42486d 100644
--- a/packages/apps/Settings/src/com/android/settings/ethernet/EtherentStaticIpDialog.java
+++ b/packages/apps/Settings/src/com/android/settings/ethernet/EtherentStaticIpDialog.java
@@ -63,6 +63,11 @@ class ethernet_static_ip_dialog extends AlertDialog implements TextWatcher {
static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
private final static String nullIpInfo = "0.0.0.0";
+ private final static String defaultIP = "192.168.0.232";
+ private final static String defaultNetMask = "255.255.255.0";
+ private final static String defaultGateway = "192.168.0.1";
+ private final static String defaultDns1 = "8.8.8.8";
+ private final static String defaultDns2 = "114.114.114.114";
// private final boolean mEdit;
private final DialogInterface.OnClickListener mListener;
@@ -120,23 +125,38 @@ class ethernet_static_ip_dialog extends AlertDialog implements TextWatcher {
ContentResolver contentResolver = mcontext.getContentResolver();
String staticip = /*System.getString(contentResolver,System.ETHERNET_STATIC_IP);*/
mEthManager.getIpAddress();
- if (!TextUtils.isEmpty(staticip))
- mIpAddressView.setText(staticip);
+ String mIP = defaultIP;
+ if ((staticip != null) && (!staticip.equals(""))){
+ String data[] = staticip.split(",");
+ mIP = data[0];
+ }
+ if (!TextUtils.isEmpty(mIP))
+ mIpAddressView.setText(mIP);
String ipmask = /*System.getString(contentResolver,System.ETHERNET_STATIC_NETMASK);*/
mEthManager.getNetmask();
- if (!TextUtils.isEmpty(ipmask))
- ipnetmask.setText(ipmask);
+ String mIpmask = defaultNetMask;
+ if ((ipmask != null) && (!ipmask.equals(""))){
+ String data[] = ipmask.split(",");
+ mIpmask = data[0];
+ }
+ if (!TextUtils.isEmpty(mIpmask))
+ ipnetmask.setText(mIpmask);
String gateway = /*System.getString(contentResolver,System.ETHERNET_STATIC_GATEWAY);*/
mEthManager.getGateway();
- if (!TextUtils.isEmpty(gateway))
- mIPgateway.setText(gateway);
+ String mGateway = defaultGateway;
+ if ((gateway != null) && (!gateway.equals(""))){
+ String data[] = gateway.split(",");
+ mGateway = data[0];
+ }
+ if (!TextUtils.isEmpty(mGateway))
+ mIPgateway.setText(mGateway);
String dns = /*System.getString(contentResolver,System.ETHERNET_STATIC_DNS1);*/
mEthManager.getDns();
- String mDns1 = nullIpInfo;
- String mDns2 = nullIpInfo;
+ String mDns1 = defaultDns1;
+ String mDns2 = defaultDns2;
if ((dns != null) && (!dns.equals(""))){
String data[] = dns.split(",");
mDns1 = data[0];
|