├── 0001-Ethernet-IP-Add-Framework-Function.patch ├── README.md ├── 0001-Ethernet-IP-Add-Framework-Interface.patch └── 0001-Ethernet-Add-Static-IP-Settiings.patch /0001-Ethernet-IP-Add-Framework-Function.patch: -------------------------------------------------------------------------------- 1 | From 9e785856a4769cf3d977a14cc93ec7d40dc51294 Mon Sep 17 00:00:00 2001 2 | From: mtk16536 3 | Date: Mon, 29 Apr 2019 17:59:39 +0800 4 | Subject: [PATCH] Ethernet IP: Add Framework Function 5 | 6 | Add Ethernet Framework Function 7 | Test: OK 8 | 9 | Change-Id: Ide8780f8dd60859e0c57ce067896ad0fa760e825 10 | Signed-off-by: mtk16536 11 | CR-Id: AUTO00032286 12 | --- 13 | java/com/android/server/ethernet/EthernetServiceImpl.java | 7 +++++++ 14 | 1 file changed, 7 insertions(+) 15 | 16 | diff --git a/java/com/android/server/ethernet/EthernetServiceImpl.java b/java/com/android/server/ethernet/EthernetServiceImpl.java 17 | index d5beec1..96b46fc 100644 18 | --- a/java/com/android/server/ethernet/EthernetServiceImpl.java 19 | +++ b/java/com/android/server/ethernet/EthernetServiceImpl.java 20 | @@ -165,6 +165,13 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { 21 | enforceAccessPermission(); 22 | mTracker.removeListener(listener); 23 | } 24 | + 25 | + public void updateIpConfiguration(String iface, IpConfiguration ipConfiguration){ 26 | + Log.i(TAG, "Enter in updateIpConfiguration, iface == " + iface); 27 | + mTracker.updateIpConfiguration(iface, ipConfiguration); 28 | + enforceAccessPermission(); 29 | + start(); 30 | + } 31 | 32 | @Override 33 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { 34 | -- 35 | 2.6.4 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Settings-Ethernet 2 | Android 9.0, Add Ethernet Options on Settings. 3 | 4 | In Android 9.0, Default Settings is not have Ethernet Options(TV Settings have). 5 | But sometimes, we need to choose Ethernet Mode(DHCP or Static IP), and edit Static IP Address. 6 | 7 | # Architecture 8 | - UI 9 | - Framework 10 | 11 | # UI 12 | - Settings -> Network & internet -> Ethernet 13 | - Ethernet Info 14 | - Edit Static IP 15 | 16 | ## Add Ethernet for Settings -> Network & internet -> Ethernet 17 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190429100512809.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEzOTE2Mjk=,size_16,color_FFFFFF,t_70) 18 | - xml(*/packages/apps/Settings/res/xml/network_and_internet.xml*) 19 | - icon(*/packages/apps/Settings/res/drawable/ic_ethernet.xml* -- new file) 20 | - string.xml(*/packages/apps/Settings/res/values/strings.xml*) 21 | 22 | 23 | ## Add Ethernet Info (optional) 24 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190429100547384.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEzOTE2Mjk=,size_16,color_FFFFFF,t_70) 25 | 26 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190429100644713.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEzOTE2Mjk=,size_16,color_FFFFFF,t_70) 27 | ### res 28 | 29 | - xml(*/packages/apps/Settings/res/xml/ethernet_settings.xml* -- new file) 30 | - Preference(IP Adress/Netmask/Gateway/DNS1/DNS2 Informantion) 31 | - List Preference(Show Ethernet Mode: DHCP or Static) 32 | - CheckBox(Ethernet Mode: DHCP or Static) 33 | - string.xml(*/packages/apps/Settings/res/values/strings.xml*) 34 | - array.xml(*/packages/apps/Settings/res/values/arrays.xml*) 35 | 36 | 37 | Reference: 38 | [Android User Guide -> User Interface -> Settings](https://developer.android.com/guide/topics/ui/settings) 39 | 40 | ### java 41 | - AndroidManifest.xml(*/packages/apps/Settings/AndroidManifest.xml*) 42 | - EthernetSettings.java(new file) 43 | 44 | ## Edit Static IP 45 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190429100721222.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEzOTE2Mjk=,size_16,color_FFFFFF,t_70) 46 | 47 | 48 | 49 | # Framework 50 | - /frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetServiceImpl.java 51 | - /frameworks/base/core/java/android/net/EthernetManager.java 52 | - /frameworks/base/core/java/android/net/IEthernetManager.aidl 53 | 54 | APP will call Framework API from EthernetManager, but this API implement in EthernetServiceImpl, and interface is IEthernetManager.aidl. 55 | 56 | For example, when APP need change Static IP, you need write *updateIPAddress()* function. 57 | 58 | EthernetManager.java 59 | ```java 60 | void updateIPAddress(){ 61 | //mService is Proxy of EthernetServiceImpl 62 | mService.updateIPAddress(); 63 | } 64 | ``` 65 | 66 | IEthernetManager.aidl 67 | ```java 68 | void updateIPAddress(); 69 | ``` 70 | EthernetServiceImpl.java 71 | ```java 72 | void updateIPAddress(){ 73 | /* 74 | how to update 75 | */ 76 | } 77 | ``` 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /0001-Ethernet-IP-Add-Framework-Interface.patch: -------------------------------------------------------------------------------- 1 | From 2b59239e18f746313e5018194ac348732e8923b9 Mon Sep 17 00:00:00 2001 2 | From: mtk16536 3 | Date: Mon, 29 Apr 2019 17:57:55 +0800 4 | Subject: [PATCH] Ethernet IP: Add Framework Interface 5 | 6 | Add Framework Interface 7 | Test: OK 8 | 9 | Change-Id: Iac9614286a98806262b101fdfafbcd4d4d66f9e0 10 | Signed-off-by: mtk16536 11 | CR-Id: AUTO00032286 12 | --- 13 | core/java/android/net/EthernetManager.java | 139 ++++++++++++++++++++++++++++ 14 | core/java/android/net/IEthernetManager.aidl | 1 + 15 | 2 files changed, 140 insertions(+) 16 | 17 | diff --git a/core/java/android/net/EthernetManager.java b/core/java/android/net/EthernetManager.java 18 | index ecccda5..038843a 100644 19 | --- a/core/java/android/net/EthernetManager.java 20 | +++ b/core/java/android/net/EthernetManager.java 21 | @@ -33,6 +33,37 @@ import java.util.ArrayList; 22 | public class EthernetManager { 23 | private static final String TAG = "EthernetManager"; 24 | private static final int MSG_AVAILABILITY_CHANGED = 1000; 25 | + 26 | + /** 27 | + * @hide 28 | + */ 29 | + public static final String ETHERNET_STATE_CHANGED_ACTION = "android.net.ethernet.ETHERNET_STATE_CHANGED"; 30 | + 31 | + /** 32 | + * @hide 33 | + */ 34 | + public static final String EXTRA_ETHERNET_STATE = "ethernet_state"; 35 | + 36 | + /** 37 | + * @hide 38 | + */ 39 | + public static final int ETHER_STATE_DISCONNECTED = 0; 40 | + 41 | + /** 42 | + * @hide 43 | + */ 44 | + public static final int ETHER_STATE_CONNECTING = 1; 45 | + 46 | + /** 47 | + * @hide 48 | + */ 49 | + public static final int ETHER_STATE_CONNECTED = 2; 50 | + 51 | + /** 52 | + * @hide 53 | + */ 54 | + public static final int ETHER_STATE_DISCONNECTING = 3; 55 | + 56 | 57 | private final Context mContext; 58 | private final IEthernetManager mService; 59 | @@ -171,4 +202,112 @@ public class EthernetManager { 60 | } 61 | } 62 | } 63 | + 64 | + public int getEthernetCarrierState(String ifname) { 65 | + /* 66 | + try { 67 | + return mService.getEthernetCarrierState(ifname); 68 | + } catch (RemoteException e) { 69 | + throw e.rethrowFromSystemServer(); 70 | + } 71 | + */ 72 | + return 0; 73 | + } 74 | + 75 | + public String getEthernetMacAddress(String ifname) { 76 | + /* 77 | + try { 78 | + return mService.getEthernetMacAddress(ifname); 79 | + } catch (RemoteException e) { 80 | + throw e.rethrowFromSystemServer(); 81 | + } 82 | + */ 83 | + return ""; 84 | + } 85 | + 86 | + public int getEthernetConnectState() { 87 | + /* 88 | + try { 89 | + return mService.getEthernetConnectState(); 90 | + } catch (RemoteException e) { 91 | + throw e.rethrowFromSystemServer(); 92 | + } 93 | + */ 94 | + return 0; 95 | + } 96 | + 97 | + public String getIpAddress() { 98 | + /* 99 | + try { 100 | + return mService.getIpAddress(); 101 | + } catch (RemoteException e) { 102 | + throw e.rethrowFromSystemServer(); 103 | + } 104 | + */ 105 | + return "192.168.1.1"; 106 | + } 107 | + 108 | + public String getNetmask() { 109 | + /* 110 | + try { 111 | + return mService.getNetmask(); 112 | + } catch (RemoteException e) { 113 | + throw e.rethrowFromSystemServer(); 114 | + } 115 | + */ 116 | + return "255.255.255.0"; 117 | + } 118 | + 119 | + public String getGateway() { 120 | + /* 121 | + try { 122 | + return mService.getGateway(); 123 | + } catch (RemoteException e) { 124 | + throw e.rethrowFromSystemServer(); 125 | + } 126 | + */ 127 | + return "0.0.255.255"; 128 | + } 129 | + 130 | + public String getDns() { 131 | + /* 132 | + try { 133 | + return mService.getDns(); 134 | + } catch (RemoteException e) { 135 | + throw e.rethrowFromSystemServer(); 136 | + } 137 | + */ 138 | + return "0.0.0.0"; 139 | + } 140 | + 141 | + public String dumpCurrentState(int state) { 142 | + /* 143 | + try { 144 | + return mService.dumpCurrentState(state); 145 | + } catch (RemoteException e) { 146 | + throw e.rethrowFromSystemServer(); 147 | + } 148 | + */ 149 | + return ""; 150 | + } 151 | + 152 | + public void disconnect(String iface) { 153 | + /* 154 | + try { 155 | + mService.disconnect(iface); 156 | + } catch (RemoteException e) { 157 | + throw e.rethrowFromSystemServer(); 158 | + } 159 | + */ 160 | + } 161 | + 162 | + 163 | + public void updateIpConfiguration(String iface, IpConfiguration ipConfiguration){ 164 | + try { 165 | + mService.updateIpConfiguration(iface, ipConfiguration); 166 | + } catch (RemoteException e) { 167 | + throw e.rethrowFromSystemServer(); 168 | + } 169 | + } 170 | + 171 | } 172 | diff --git a/core/java/android/net/IEthernetManager.aidl b/core/java/android/net/IEthernetManager.aidl 173 | index 94960b5..8e38a3a 100644 174 | --- a/core/java/android/net/IEthernetManager.aidl 175 | +++ b/core/java/android/net/IEthernetManager.aidl 176 | @@ -32,4 +32,5 @@ interface IEthernetManager 177 | boolean isAvailable(String iface); 178 | void addListener(in IEthernetServiceListener listener); 179 | void removeListener(in IEthernetServiceListener listener); 180 | + void updateIpConfiguration(String iface, in IpConfiguration ipConfiguration); 181 | } 182 | -- 183 | 2.6.4 184 | 185 | -------------------------------------------------------------------------------- /0001-Ethernet-Add-Static-IP-Settiings.patch: -------------------------------------------------------------------------------- 1 | From 28f88df43e00276595a8f079d14e24d863900a42 Mon Sep 17 00:00:00 2001 2 | From: mtk16536 3 | Date: Tue, 23 Apr 2019 18:45:07 +0800 4 | Subject: [PATCH] Ethernet: Add Static IP Settiings 5 | 6 | Add Static IP Settings 7 | Test: OK 8 | 9 | Change-Id: I89ef4877dde23447ea42c32f6c3eb9ee18afbceb 10 | Signed-off-by: mtk16536 11 | CR-Id: AUTO00032286 12 | --- 13 | AndroidManifest.xml | 25 + 14 | res/drawable/ic_ethernet.xml | 26 + 15 | res/layout/static_ip_dialog.xml | 156 ++++++ 16 | res/values/arrays.xml | 12 + 17 | res/values/strings.xml | 45 ++ 18 | res/xml/ethernet_settings.xml | 73 +++ 19 | res/xml/network_and_internet.xml | 8 + 20 | .../settings/ethernet/EthernetSettings.java | 583 +++++++++++++++++++++ 21 | .../settings/ethernet/EthernetStaticIpDialog.java | 299 +++++++++++ 22 | .../android/settings/ethernet/getStaticIpInfo.java | 9 + 23 | 10 files changed, 1236 insertions(+) 24 | create mode 100644 res/drawable/ic_ethernet.xml 25 | create mode 100644 res/layout/static_ip_dialog.xml 26 | create mode 100644 res/xml/ethernet_settings.xml 27 | create mode 100644 src/com/android/settings/ethernet/EthernetSettings.java 28 | create mode 100644 src/com/android/settings/ethernet/EthernetStaticIpDialog.java 29 | create mode 100644 src/com/android/settings/ethernet/getStaticIpInfo.java 30 | 31 | diff --git a/AndroidManifest.xml b/AndroidManifest.xml 32 | index 4456aa0..ea33f8a 100644 33 | --- a/AndroidManifest.xml 34 | +++ b/AndroidManifest.xml 35 | @@ -476,6 +476,31 @@ 36 | 38 | 39 | + 40 | + 41 | + 45 | + 46 | + 47 | + 48 | + 49 | + 50 | + 51 | + 53 | + 54 | + 55 | + 56 | + 61 | + 63 | + 64 | 65 | 74 | + 89 | + 95 | + 98 | + 99 | \ No newline at end of file 100 | diff --git a/res/layout/static_ip_dialog.xml b/res/layout/static_ip_dialog.xml 101 | new file mode 100644 102 | index 0000000..658c881 103 | --- /dev/null 104 | +++ b/res/layout/static_ip_dialog.xml 105 | @@ -0,0 +1,156 @@ 106 | + 107 | + 122 | + 123 | + 127 | + 128 | + 133 | + 134 | + 139 | + 140 | + 145 | + 146 | + 151 | + 152 | + 156 | + 157 | + 162 | + 163 | + 171 | + 172 | + 173 | + 177 | + 178 | + 183 | + 184 | + 192 | + 193 | + 194 | + 198 | + 199 | + 204 | + 205 | + 213 | + 214 | + 215 | + 219 | + 220 | + 225 | + 226 | + 234 | + 235 | + 236 | + 240 | + 241 | + 246 | + 247 | + 255 | + 256 | + 257 | + 258 | + 259 | + 260 | + 261 | + 262 | \ No newline at end of file 263 | diff --git a/res/values/arrays.xml b/res/values/arrays.xml 264 | index 5f39738..704dfbb 100644 265 | --- a/res/values/arrays.xml 266 | +++ b/res/values/arrays.xml 267 | @@ -1146,5 +1146,17 @@ 268 | 2 269 | 0 270 | 271 | + 272 | + 273 | + 274 | + 275 | + @string/usestatic 276 | + @string/usedhcp 277 | + 278 | + 279 | + StaticIP 280 | + DHCP 281 | + 282 | + 283 | 284 | 285 | diff --git a/res/values/strings.xml b/res/values/strings.xml 286 | index 1b5f125..af4c591 100644 287 | --- a/res/values/strings.xml 288 | +++ b/res/values/strings.xml 289 | @@ -3398,6 +3398,51 @@ 290 | Network reset is not available for this user 291 | 292 | Network settings have been reset 293 | + 294 | + 295 | + Ethernet 296 | + 255.255.255.0 297 | + 298 | + Ethernet 299 | + Connect 300 | + Cancel 301 | + 302 | + Manager ethernet 303 | + 304 | + MAC 305 | + 306 | + IP address 307 | + 308 | + netmask 309 | + 310 | + gateway 311 | + 312 | + dns1 313 | + 314 | + dns2 315 | + Static IP Setttings 316 | + dhcp 317 | + static 318 | + Use static IP 319 | + IP address 320 | + Save 321 | + Cancel 322 | + OK 323 | + Cancel 324 | + Important 325 | + Whether save Settings? 326 | + Save failed! 327 | + Please type a valid IP address. 328 | + Please give complete static IP settings! 329 | + Ethernet 330 | + 331 | + Ethernet is disabled 332 | + 333 | + Ethernet is enabled 334 | + 335 | + Ethernet Ip mode 336 | + "getting IP info..." 337 | + 338 | 339 | Cant\u2019t reset eSIMs 340 | 341 | diff --git a/res/xml/ethernet_settings.xml b/res/xml/ethernet_settings.xml 342 | new file mode 100644 343 | index 0000000..a6a6309 344 | --- /dev/null 345 | +++ b/res/xml/ethernet_settings.xml 346 | @@ -0,0 +1,73 @@ 347 | + 348 | + 351 | + 352 | + 353 | + 362 | + 369 | + 370 | + 375 | + 376 | + 377 | + 382 | + 383 | + 384 | + 389 | + 390 | + 391 | + 396 | + 397 | + 398 | + 403 | + 404 | + 410 | + 411 | + 419 | + 420 | diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml 421 | index 6eda0b0..e2c3ed7 100644 422 | --- a/res/xml/network_and_internet.xml 423 | +++ b/res/xml/network_and_internet.xml 424 | @@ -100,5 +100,13 @@ 425 | android:dialogLayout="@layout/private_dns_mode_dialog" 426 | android:positiveButtonText="@string/save" 427 | android:negativeButtonText="@android:string/cancel" /> 428 | + 429 | + 436 | 437 | 438 | diff --git a/src/com/android/settings/ethernet/EthernetSettings.java b/src/com/android/settings/ethernet/EthernetSettings.java 439 | new file mode 100644 440 | index 0000000..5ce98e4 441 | --- /dev/null 442 | +++ b/src/com/android/settings/ethernet/EthernetSettings.java 443 | @@ -0,0 +1,583 @@ 444 | +/* 445 | + * Copyright (C) 2009 The Android Open Source Project 446 | + * 447 | + * Licensed under the Apache License, Version 2.0 (the "License"); 448 | + * you may not use this file except in compliance with the License. 449 | + * You may obtain a copy of the License at 450 | + * 451 | + * http://www.apache.org/licenses/LICENSE-2.0 452 | + * 453 | + * Unless required by applicable law or agreed to in writing, software 454 | + * distributed under the License is distributed on an "AS IS" BASIS, 455 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 456 | + * See the License for the specific language governing permissions and 457 | + * limitations under the License. 458 | + */ 459 | +package com.android.settings; 460 | + 461 | +import com.android.settings.R; 462 | +import android.app.Activity; 463 | +import android.app.Fragment; 464 | +import android.app.AlertDialog; 465 | +import android.app.Dialog; 466 | +import android.app.admin.DevicePolicyManager; 467 | +import android.content.ActivityNotFoundException; 468 | +import android.content.BroadcastReceiver; 469 | +import android.content.ComponentName; 470 | +import android.content.Context; 471 | +import android.content.DialogInterface; 472 | +import android.content.Intent; 473 | +import android.content.IntentFilter; 474 | +import android.content.pm.PackageManager; 475 | +import android.content.res.Resources; 476 | +import android.net.ConnectivityManager; 477 | +import android.net.NetworkInfo; 478 | +import android.net.Uri; 479 | +import android.os.Bundle; 480 | +import android.os.SystemProperties; 481 | +import android.os.UserHandle; 482 | +import android.os.UserManager; 483 | +import android.preference.CheckBoxPreference; 484 | +import android.preference.Preference.OnPreferenceChangeListener; 485 | +import android.preference.PreferenceScreen; 486 | +import android.support.v14.preference.SwitchPreference; 487 | +import android.support.v7.preference.ListPreference; 488 | +import android.support.v7.preference.Preference; 489 | +import android.provider.SearchIndexableResource; 490 | +import android.provider.Settings; 491 | +import android.telephony.TelephonyManager; 492 | +import android.text.TextUtils; 493 | +import android.util.Log; 494 | +import android.content.Intent; 495 | + 496 | +import java.io.File; 497 | +import java.io.FileDescriptor; 498 | +import java.io.File; 499 | +import java.io.BufferedReader; 500 | +import java.io.FileInputStream; 501 | +import java.io.FileNotFoundException; 502 | +import java.io.FileOutputStream; 503 | +import java.io.IOException; 504 | +import java.io.InputStreamReader; 505 | + 506 | +import java.util.regex.Pattern; 507 | +import java.lang.Integer; 508 | +import java.net.InetAddress; 509 | +import java.net.Inet4Address; 510 | +import java.util.Iterator; 511 | +import java.util.ArrayList; 512 | +import java.util.Arrays; 513 | +import java.util.Collection; 514 | +import java.util.List; 515 | +import android.preference.Preference.OnPreferenceChangeListener; 516 | +import android.preference.Preference.OnPreferenceClickListener; 517 | +import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment; 518 | + 519 | +/*for 5.0*/ 520 | +import android.net.EthernetManager; 521 | +import android.net.IpConfiguration; 522 | +import android.net.IpConfiguration.IpAssignment; 523 | +import android.net.IpConfiguration.ProxySettings; 524 | +import android.net.wifi.SupplicantState; 525 | +import android.net.wifi.WifiInfo; 526 | +import android.net.wifi.WifiManager; 527 | +import android.net.StaticIpConfiguration; 528 | +import android.net.NetworkUtils; 529 | +import android.net.LinkAddress; 530 | +import android.net.LinkProperties; 531 | +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 532 | + 533 | + 534 | +import com.android.settings.ethernet_static_ip_dialog; 535 | + 536 | +public class EthernetSettings extends SettingsPreferenceFragment 537 | + implements DialogInterface.OnClickListener ,Preference.OnPreferenceChangeListener { 538 | + private static final String TAG = "EthernetSettings"; 539 | + 540 | + private static final String KEY_ETH_IP_ADDRESS = "ethernet_ip_addr"; 541 | + private static final String KEY_ETH_HW_ADDRESS = "ethernet_hw_addr"; 542 | + private static final String KEY_ETH_NET_MASK = "ethernet_netmask"; 543 | + private static final String KEY_ETH_GATEWAY = "ethernet_gateway"; 544 | + private static final String KEY_ETH_DNS1 = "ethernet_dns1"; 545 | + private static final String KEY_ETH_DNS2 = "ethernet_dns2"; 546 | + private static final String KEY_ETH_MODE= "ethernet_mode_select"; 547 | + 548 | + 549 | + private static String mEthHwAddress = null; 550 | + private static String mEthIpAddress = null; 551 | + private static String mEthNetmask = null; 552 | + private static String mEthGateway = null; 553 | + private static String mEthdns1 = null; 554 | + private static String mEthdns2 = null; 555 | + private final static String nullIpInfo = "0.0.0.0"; 556 | + private String mInterfaceName; 557 | + 558 | + private ListPreference mkeyEthMode; 559 | + private CheckBoxPreference staticEthernet; 560 | + 561 | + EthernetManager mEthManager; 562 | + 563 | + private final IntentFilter mIntentFilter; 564 | + IpConfiguration mIpConfiguration; 565 | + StaticIpConfiguration mStaticIpConfiguration; 566 | + Context mContext; 567 | + private ethernet_static_ip_dialog mDialog; 568 | + private static final int SHOW_RENAME_DIALOG = 0; 569 | + private static final int ETHER_IFACE_STATE_DOWN = 0; 570 | + private static final int ETHER_IFACE_STATE_UP = 1; 571 | + 572 | + private static final String FILE = "/sys/class/net/eth0/flags"; 573 | + 574 | + @Override 575 | + public int getMetricsCategory() { 576 | + return MetricsEvent.WIFI_TETHER_SETTINGS; 577 | + } 578 | + 579 | + @Override 580 | + public int getDialogMetricsCategory(int dialogId) { 581 | + switch (dialogId) { 582 | + case SHOW_RENAME_DIALOG: 583 | + return MetricsEvent.WIFI_TETHER_SETTINGS; 584 | + default: 585 | + return 0; 586 | + } 587 | + } 588 | + 589 | + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 590 | + @Override 591 | + public void onReceive(Context context, Intent intent) { 592 | + String action = intent.getAction(); 593 | + log("Action "+action); 594 | + if(EthernetManager.ETHERNET_STATE_CHANGED_ACTION.equals(action)) { 595 | + int EtherState=intent.getIntExtra(EthernetManager.EXTRA_ETHERNET_STATE, -1); 596 | + handleEtherStateChange(EtherState); 597 | + } 598 | + } 599 | + }; 600 | + public EthernetSettings() { 601 | + mIntentFilter = new IntentFilter(EthernetManager.ETHERNET_STATE_CHANGED_ACTION); 602 | + } 603 | + 604 | + 605 | + private void handleEtherStateChange(int EtherState ) { 606 | + log("curEtherState"+ EtherState); 607 | + 608 | + switch(EtherState) { 609 | + case EthernetManager.ETHER_STATE_DISCONNECTED: 610 | + mEthHwAddress = nullIpInfo; 611 | + mEthIpAddress = nullIpInfo; 612 | + mEthNetmask = nullIpInfo; 613 | + mEthGateway = nullIpInfo; 614 | + mEthdns1 = nullIpInfo; 615 | + mEthdns2 = nullIpInfo; 616 | + break; 617 | + case EthernetManager.ETHER_STATE_CONNECTING: 618 | + String mStatusString = this.getResources().getString(R.string.ethernet_info_getting); 619 | + mEthHwAddress = mStatusString; 620 | + mEthIpAddress = mStatusString; 621 | + mEthNetmask = mStatusString; 622 | + mEthGateway = mStatusString; 623 | + mEthdns1 = mStatusString; 624 | + mEthdns2 = mStatusString; 625 | + break; 626 | + case EthernetManager.ETHER_STATE_CONNECTED: 627 | + getEthInfo(); 628 | + break; 629 | + } 630 | + 631 | + refreshUI(); 632 | + } 633 | + 634 | + @Override 635 | + public void onCreate(Bundle savedInstanceState) { 636 | + super.onCreate(savedInstanceState); 637 | + addPreferencesFromResource(R.xml.ethernet_settings); 638 | + 639 | + mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE); 640 | + 641 | + if (mEthManager == null) { 642 | + Log.e(TAG, "get ethernet manager failed"); 643 | + return; 644 | + } 645 | + mContext=this.getActivity().getApplicationContext(); 646 | + } 647 | + 648 | + private Inet4Address getIPv4Address(String text) { 649 | + try { 650 | + return (Inet4Address) NetworkUtils.numericToInetAddress(text); 651 | + } catch (IllegalArgumentException|ClassCastException e) { 652 | + return null; 653 | + } 654 | + } 655 | + 656 | + @Override 657 | + public void onResume() { 658 | + super.onResume(); 659 | + if(mkeyEthMode==null) { 660 | + mkeyEthMode=(ListPreference)findPreference(KEY_ETH_MODE); 661 | + mkeyEthMode.setOnPreferenceChangeListener(this); 662 | + } 663 | + 664 | + handleEtherStateChange(mEthManager.getEthernetConnectState()); 665 | + refreshUI(); 666 | + log("resume"); 667 | + mContext.registerReceiver(mReceiver, mIntentFilter); 668 | + } 669 | + 670 | + @Override 671 | + public void onPause() { 672 | + super.onPause(); 673 | + } 674 | + 675 | + @Override 676 | + public void onDestroy() { 677 | + super.onDestroy(); 678 | + log("destory"); 679 | + } 680 | + 681 | + @Override 682 | + public void onStart() { 683 | + super.onStart(); 684 | + //mEthManager.addListener(mEthernetListener); 685 | + } 686 | + 687 | + @Override 688 | + public void onStop(){ 689 | + super.onStop(); 690 | + log("stop"); 691 | + mContext.unregisterReceiver(mReceiver); 692 | + } 693 | + 694 | + private void setStringSummary(String preference, String value) { 695 | + try { 696 | + findPreference(preference).setSummary(value); 697 | + } catch (RuntimeException e) { 698 | + findPreference(preference).setSummary(""); 699 | + log("can't find "+preference); 700 | + } 701 | + } 702 | + private String getStringFromPref(String preference) { 703 | + try { 704 | + return findPreference(preference).getSummary().toString(); 705 | + } catch (RuntimeException e) { 706 | + return null; 707 | + } 708 | + } 709 | + private void refreshUI ( ) { 710 | + setStringSummary(KEY_ETH_IP_ADDRESS, mEthIpAddress); 711 | + setStringSummary(KEY_ETH_NET_MASK, mEthNetmask); 712 | + setStringSummary(KEY_ETH_GATEWAY, mEthGateway); 713 | + setStringSummary(KEY_ETH_DNS1, mEthdns1); 714 | + setStringSummary(KEY_ETH_DNS2, mEthdns2); 715 | + updateCheckbox(); 716 | + } 717 | + 718 | + //This is update Ethernet Mode (Static IP or DHCP) 719 | + private void updateCheckbox(){ 720 | + String[] ifaces = mEthManager.getAvailableInterfaces(); 721 | + log("Enter in updateCheckbox()"); 722 | + if(mEthManager==null){ 723 | + mkeyEthMode.setSummary("null"); 724 | + } else { 725 | + if (ifaces.length > 0){ 726 | + log("Enter in updateCheckbox(), ifaces.length > 0"); 727 | + mInterfaceName = ifaces[0]; 728 | + boolean useDhcp=(mEthManager.getConfiguration(mInterfaceName).ipAssignment == IpAssignment.DHCP) ? true : false; 729 | + //int useDhcp=Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ETHERNET_MODE, 0); 730 | + log("Enter in updateCheckbox(), useDhcp == " + useDhcp); 731 | + if(useDhcp == true){ 732 | + mkeyEthMode.setValue("DHCP"); 733 | + mkeyEthMode.setSummary(R.string.usedhcp); 734 | + }else { 735 | + mkeyEthMode.setValue("StaticIP"); 736 | + mkeyEthMode.setSummary(R.string.usestatic); 737 | + } 738 | + } 739 | + } 740 | + } 741 | + 742 | + @Override 743 | + public boolean onPreferenceChange(Preference preference, Object newValue) { 744 | + log("Enter in onPreferenceChange()"); 745 | + if(preference==mkeyEthMode) { 746 | + String value=(String)newValue; 747 | + if(value.equals("DHCP")){ 748 | + //IpConfiguration mIpConfiguration = new IpConfiguration(); 749 | + mIpConfiguration.setIpAssignment(IpConfiguration.IpAssignment.DHCP); 750 | + 751 | + mEthManager.setConfiguration(mInterfaceName, mIpConfiguration); 752 | + //mEthManager.setConfiguration(new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null)); 753 | + log("switch to dhcp"); 754 | + }else if(value.equals("StaticIP")){ 755 | + log("static editor"); 756 | + this.showDialog(SHOW_RENAME_DIALOG); 757 | + } 758 | + } 759 | + return true; 760 | + } 761 | + 762 | + public String interMask2String(int prefixLength) { 763 | + String netMask = null; 764 | + int inetMask = prefixLength; 765 | + 766 | + int part = inetMask / 8; 767 | + int remainder = inetMask % 8; 768 | + int sum = 0; 769 | + 770 | + for (int i = 8; i > 8 - remainder; i--) { 771 | + sum = sum + (int) Math.pow(2, i - 1); 772 | + } 773 | + 774 | + if (part == 0) { 775 | + netMask = sum + ".0.0.0"; 776 | + } else if (part == 1) { 777 | + netMask = "255." + sum + ".0.0"; 778 | + } else if (part == 2) { 779 | + netMask = "255.255." + sum + ".0"; 780 | + } else if (part == 3) { 781 | + netMask = "255.255.255." + sum; 782 | + } else if (part == 4) { 783 | + netMask = "255.255.255.255"; 784 | + } 785 | + 786 | + return netMask; 787 | + } 788 | + 789 | + /* 790 | + * convert subMask string to prefix length 791 | + */ 792 | + private int maskStr2InetMask(String maskStr) { 793 | + StringBuffer sb ; 794 | + String str; 795 | + int inetmask = 0; 796 | + int count = 0; 797 | + /* 798 | + * check the subMask format 799 | + */ 800 | + Pattern pattern = Pattern.compile("(^((\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])$)|^(\\d|[1-2]\\d|3[0-2])$"); 801 | + if (pattern.matcher(maskStr).matches() == false) { 802 | + Log.e(TAG,"subMask is error"); 803 | + return 0; 804 | + } 805 | + 806 | + String[] ipSegment = maskStr.split("\\."); 807 | + for(int n =0; n 0){ 907 | + mInterfaceName = ifaces[0]; 908 | + StaticIpConfiguration staticIpConfiguration = mEthManager.getConfiguration(mInterfaceName).getStaticIpConfiguration(); 909 | + 910 | + LinkAddress ipAddress = staticIpConfiguration.ipAddress; 911 | + InetAddress gateway = staticIpConfiguration.gateway; 912 | + ArrayList dnsServers=staticIpConfiguration.dnsServers; 913 | + 914 | + if( ipAddress !=null) { 915 | + mEthIpAddress=ipAddress.getAddress().getHostAddress(); 916 | + mEthNetmask=interMask2String(ipAddress.getPrefixLength()); 917 | + } 918 | + if(gateway !=null) { 919 | + mEthGateway=gateway.getHostAddress(); 920 | + } 921 | + mEthdns1=dnsServers.get(0).getHostAddress(); 922 | + 923 | + if(dnsServers.size() > 1) { /* ?????*/ 924 | + mEthdns2=dnsServers.get(1).getHostAddress(); 925 | + } 926 | + } 927 | + return; 928 | + } 929 | + 930 | + public void getEthInfo(){ 931 | + 932 | + String[] ifaces = mEthManager.getAvailableInterfaces(); 933 | + 934 | + if (ifaces.length > 0){ 935 | + mInterfaceName = ifaces[0]; 936 | + IpAssignment mode = mEthManager.getConfiguration(mInterfaceName).getIpAssignment(); 937 | + 938 | + if (mode== IpAssignment.DHCP) { 939 | + getEthInfoFromDhcp(); 940 | + } else if(mode == IpAssignment.STATIC) { 941 | + getEthInfoFromStaticIp(); 942 | + } 943 | + } 944 | + } 945 | + 946 | + private void log(String s) { 947 | + Log.d(TAG, s); 948 | + } 949 | + 950 | + @Override 951 | + public void onClick(DialogInterface dialogInterface, int button) { 952 | + if(button==ethernet_static_ip_dialog.BUTTON_SUBMIT) { 953 | + log("onClick() -> button==ethernet_static_ip_dialog.BUTTON_SUBMIT"); 954 | + mDialog.saveIpSettingInfo(); 955 | + if(setStaticIpConfiguration()) { 956 | + log("onClick() -> setStaticIpConfiguration()"); 957 | + if (mInterfaceName != null){ 958 | + mEthManager.setConfiguration(mInterfaceName, mIpConfiguration); 959 | + log("onClick() -> setStaticIpConfiguration() -> mInterfaceName!=null"); 960 | + } 961 | + } else { 962 | + Log.e(TAG, mIpConfiguration.toString()); 963 | + } 964 | + } 965 | + updateCheckbox(); 966 | + } 967 | + 968 | + @Override 969 | + public Dialog onCreateDialog(int dialogId) { 970 | + log("onCreateDialog "+dialogId); 971 | + switch(dialogId) { 972 | + case SHOW_RENAME_DIALOG: 973 | + 974 | + mDialog = new ethernet_static_ip_dialog(getActivity(), false, this,mGetStaticIpInfo); 975 | + return mDialog; 976 | + } 977 | + return super.onCreateDialog(dialogId); 978 | + } 979 | + 980 | + public getStaticIpInfo mGetStaticIpInfo =new getStaticIpInfo() { 981 | + 982 | + public boolean getStaticIp(String ipAddr) { 983 | + mEthIpAddress = ipAddr; 984 | + 985 | + log("ipAddr: "+ipAddr); 986 | + return true; 987 | + } 988 | + public boolean getStaticNetMask(String netMask) { 989 | + mEthNetmask =netMask ; 990 | + 991 | + log("netMask: "+netMask); 992 | + return true; 993 | + } 994 | + public boolean getStaticGateway(String gateway) { 995 | + mEthGateway=gateway; 996 | + 997 | + log("gateway: "+gateway); 998 | + return true; 999 | + } 1000 | + public boolean getStaticDns1(String dns1) { 1001 | + mEthdns1=dns1; 1002 | + 1003 | + log("dns1: "+dns1); 1004 | + return true; 1005 | + } 1006 | + public boolean getStaticDns2(String dns2) { 1007 | + mEthdns2=dns2; 1008 | + 1009 | + log("dns2: "+dns2); 1010 | + return true; 1011 | + } 1012 | + }; 1013 | + 1014 | + /* 1015 | + @Override 1016 | + public void onConnectivityChange(){ 1017 | + if (mListener != null){ 1018 | + mListener.onConnectivityChange(); 1019 | + } 1020 | + } 1021 | + 1022 | + public interface Listener { 1023 | + void onConnectivityChange(); 1024 | + } 1025 | + */ 1026 | +} 1027 | \ No newline at end of file 1028 | diff --git a/src/com/android/settings/ethernet/EthernetStaticIpDialog.java b/src/com/android/settings/ethernet/EthernetStaticIpDialog.java 1029 | new file mode 100644 1030 | index 0000000..a3e5e61 1031 | --- /dev/null 1032 | +++ b/src/com/android/settings/ethernet/EthernetStaticIpDialog.java 1033 | @@ -0,0 +1,299 @@ 1034 | +/* 1035 | + * Copyright (C) 2010 The Android Open Source Project 1036 | + * 1037 | + * Licensed under the Apache License, Version 2.0 (the "License"); 1038 | + * you may not use this file except in compliance with the License. 1039 | + * You may obtain a copy of the License at 1040 | + * 1041 | + * http://www.apache.org/licenses/LICENSE-2.0 1042 | + * 1043 | + * Unless required by applicable law or agreed to in writing, software 1044 | + * distributed under the License is distributed on an "AS IS" BASIS, 1045 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1046 | + * See the License for the specific language governing permissions and 1047 | + * limitations under the License. 1048 | + */ 1049 | +package com.android.settings; 1050 | + 1051 | +import java.net.Inet4Address; 1052 | +import java.net.InetAddress; 1053 | + 1054 | +import android.net.NetworkUtils; 1055 | + 1056 | +import com.android.settings.R; 1057 | + 1058 | +import java.util.regex.Pattern; 1059 | + 1060 | +import android.content.Context; 1061 | +import android.preference.EditTextPreference; 1062 | +import android.provider.Settings.System; 1063 | +import android.app.AlertDialog; 1064 | +import android.content.ContentResolver; 1065 | +import android.content.Context; 1066 | +import android.content.DialogInterface; 1067 | +import android.os.Bundle; 1068 | +import android.provider.Settings.System; 1069 | +import android.text.Editable; 1070 | +import android.text.TextUtils; 1071 | +import android.text.TextWatcher; 1072 | +import android.util.Log; 1073 | +import android.view.View; 1074 | +import android.widget.EditText; 1075 | +import android.widget.TextView; 1076 | +import android.widget.Button; 1077 | + 1078 | +import android.net.EthernetManager; 1079 | +import android.net.IpConfiguration; 1080 | +import android.net.IpConfiguration.IpAssignment; 1081 | +import android.net.IpConfiguration.ProxySettings; 1082 | +import android.net.wifi.SupplicantState; 1083 | +import android.net.wifi.WifiInfo; 1084 | +import android.net.wifi.WifiManager; 1085 | +import android.net.StaticIpConfiguration; 1086 | +import android.net.NetworkUtils; 1087 | +import android.net.LinkAddress; 1088 | +import android.net.LinkProperties; 1089 | +import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 1090 | + 1091 | +class ethernet_static_ip_dialog extends AlertDialog implements TextWatcher { 1092 | + 1093 | + public getStaticIpInfo mGetStaticInfo; 1094 | + private TextView mIpAddressView; 1095 | + private TextView mIPgateway; 1096 | + private TextView ipnetmask; 1097 | + private TextView mdns1; 1098 | + private TextView mdns2; 1099 | + 1100 | + public EditText ip_address; 1101 | + public EditText ip_gateway; 1102 | + public EditText gateway; 1103 | + public EditText dns1; 1104 | + public EditText dns2; 1105 | + 1106 | + static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE; 1107 | + static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL; 1108 | + 1109 | + private final static String nullIpInfo = "0.0.0.0"; 1110 | + 1111 | + // private final boolean mEdit; 1112 | + private final DialogInterface.OnClickListener mListener; 1113 | + 1114 | + private View mView; 1115 | + Context mcontext; 1116 | + EthernetManager mEthManager; 1117 | + StaticIpConfiguration mStaticIpConfiguration; 1118 | + 1119 | + // private boolean mHideSubmitButton; 1120 | + 1121 | + public ethernet_static_ip_dialog(Context context, boolean cancelable, 1122 | + DialogInterface.OnClickListener listener,getStaticIpInfo GetgetStaticIpInfo) { 1123 | + super(context); 1124 | + mcontext = context; 1125 | + mListener = listener; 1126 | + mGetStaticInfo=GetgetStaticIpInfo; 1127 | + // TODO Auto-generated constructor stub 1128 | + } 1129 | + 1130 | + @Override 1131 | + protected void onCreate(Bundle savedInstanceState) { 1132 | + mView = getLayoutInflater().inflate(R.layout.static_ip_dialog, null); 1133 | + setView(mView); 1134 | + setInverseBackgroundForced(true); 1135 | + 1136 | + mIpAddressView = (TextView) mView.findViewById(R.id.ipaddress); 1137 | + ipnetmask = (TextView) mView.findViewById(R.id.network_prefix_length); 1138 | + mIPgateway = (TextView) mView.findViewById(R.id.gateway); 1139 | + mdns1 = (TextView) mView.findViewById(R.id.dns1); 1140 | + mdns2 = (TextView) mView.findViewById(R.id.dns2); 1141 | + 1142 | + mIpAddressView.addTextChangedListener(this); 1143 | + ipnetmask.addTextChangedListener(this); 1144 | + mIPgateway.addTextChangedListener(this); 1145 | + mdns1.addTextChangedListener(this); 1146 | + mdns2.addTextChangedListener(this); 1147 | + 1148 | + setButton(BUTTON_SUBMIT, mcontext.getString(R.string.ethernet_connect), mListener); 1149 | + setButton(BUTTON_NEGATIVE,mcontext.getString(R.string.ethernet_cancel), mListener); 1150 | + setTitle(mcontext.getString(R.string.ethernet_settings)); 1151 | + 1152 | + mEthManager = (EthernetManager) mcontext.getSystemService(Context.ETHERNET_SERVICE); 1153 | + 1154 | + super.onCreate(savedInstanceState); 1155 | + } 1156 | + 1157 | + @Override 1158 | + public void onStart() { 1159 | + super.onStart(); 1160 | + updateIpSettingsInfo(); 1161 | + checkIPValue(); 1162 | + } 1163 | + private void updateIpSettingsInfo() { 1164 | + Log.d("EthernetStaticDialog", "Static IP status updateIpSettingsInfo"); 1165 | + ContentResolver contentResolver = mcontext.getContentResolver(); 1166 | + String staticip = /*System.getString(contentResolver,System.ETHERNET_STATIC_IP);*/ 1167 | + mEthManager.getIpAddress(); 1168 | + if (!TextUtils.isEmpty(staticip)){ 1169 | + mIpAddressView.setText(staticip); 1170 | + } 1171 | + String ipmask = /*System.getString(contentResolver,System.ETHERNET_STATIC_NETMASK);*/ 1172 | + mEthManager.getNetmask(); 1173 | + if (!TextUtils.isEmpty(ipmask)) 1174 | + ipnetmask.setText(ipmask); 1175 | + 1176 | + String gateway = /*System.getString(contentResolver,System.ETHERNET_STATIC_GATEWAY);*/ 1177 | + mEthManager.getGateway(); 1178 | + if (!TextUtils.isEmpty(gateway)) 1179 | + mIPgateway.setText(gateway); 1180 | + 1181 | + String dns = /*System.getString(contentResolver,System.ETHERNET_STATIC_DNS1);*/ 1182 | + mEthManager.getDns(); 1183 | + String mDns1 = nullIpInfo; 1184 | + String mDns2 = nullIpInfo; 1185 | + if ((dns != null) && (!dns.equals(""))){ 1186 | + String data[] = dns.split(","); 1187 | + mDns1 = data[0]; 1188 | + if (data.length > 1) 1189 | + mDns2 = data[1]; 1190 | + } 1191 | + if (!TextUtils.isEmpty(mDns1)) 1192 | + mdns1.setText(mDns1); 1193 | + if (!TextUtils.isEmpty(mDns2)) 1194 | + mdns2.setText(mDns2); 1195 | + /* String dns2 = System.getString(contentResolver, 1196 | + System.ETHERNET_STATIC_DNS2); 1197 | + if (!TextUtils.isEmpty(dns2)) 1198 | + mdns2.setText(dns2);*/ 1199 | + } 1200 | + 1201 | + public void saveIpSettingInfo() { 1202 | + Log.d("EthernetStaticDialog", "Enter in SaveIpSettingInfo"); 1203 | + ContentResolver contentResolver = mcontext.getContentResolver(); 1204 | + String ipAddr = mIpAddressView.getText().toString(); 1205 | + String gateway = mIPgateway.getText().toString(); 1206 | + String netMask =ipnetmask.getText().toString(); 1207 | + String dns1 = mdns1.getText().toString(); 1208 | + String dns2 = mdns2.getText().toString(); 1209 | + int network_prefix_length = 24;// Integer.parseInt(ipnetmask.getText().toString()); 1210 | + 1211 | + Log.i("EthernetStaticDialog","ipAddr == " + ipAddr); 1212 | + 1213 | + /* 1214 | + if (!TextUtils.isEmpty(ipAddr)) { // not empty 1215 | + Settings.System.putString(contentResolver, System.ETHERNET_STATIC_IP, ipAddr); 1216 | + } else { 1217 | + Settings.System.putString(contentResolver, System.ETHERNET_STATIC_IP, null); 1218 | + } 1219 | + 1220 | + 1221 | + if (!TextUtils.isEmpty(gateway)) { // not empty 1222 | + System.putString(contentResolver, System.ETHERNET_STATIC_GATEWAY, 1223 | + gateway); 1224 | + } else { 1225 | + System.putString(contentResolver, System.ETHERNET_STATIC_GATEWAY, 1226 | + null); 1227 | + } 1228 | + if (!TextUtils.isEmpty(netMask)) { // not empty 1229 | + System.putString(contentResolver, System.ETHERNET_STATIC_NETMASK, 1230 | + netMask); 1231 | + } else { 1232 | + System.putString(contentResolver, System.ETHERNET_STATIC_NETMASK, 1233 | + null); 1234 | + } 1235 | + if (!TextUtils.isEmpty(dns1)) { // not empty 1236 | + System.putString(contentResolver, System.ETHERNET_STATIC_DNS1, dns1); 1237 | + } else { 1238 | + System.putString(contentResolver, System.ETHERNET_STATIC_DNS1, null); 1239 | + } 1240 | + if (!TextUtils.isEmpty(dns2)) { // not empty 1241 | + System.putString(contentResolver, System.ETHERNET_STATIC_DNS2, dns2); 1242 | + } else { 1243 | + System.putString(contentResolver, System.ETHERNET_STATIC_DNS2, null); 1244 | + }*/ 1245 | + /* 1246 | + * ????EthernetSetting 1247 | + */ 1248 | + mGetStaticInfo.getStaticIp(ipAddr); 1249 | + mGetStaticInfo.getStaticNetMask(netMask); 1250 | + mGetStaticInfo.getStaticGateway(gateway); 1251 | + mGetStaticInfo.getStaticDns1(dns1); 1252 | + mGetStaticInfo.getStaticDns2(dns2); 1253 | + } 1254 | + 1255 | + /* 1256 | + * ?? ??? String ??? ??? IP ??. 1257 | + */ 1258 | + private boolean isValidIpAddress(String value) { 1259 | + int start = 0; 1260 | + int end = value.indexOf('.'); 1261 | + int numBlocks = 0; 1262 | + 1263 | + while (start < value.length()) { 1264 | + 1265 | + if (-1 == end) { 1266 | + end = value.length(); 1267 | + } 1268 | + 1269 | + try { 1270 | + int block = Integer.parseInt(value.substring(start, end)); 1271 | + if ((block > 255) || (block < 0)) { 1272 | + Log.w("EthernetIP", 1273 | + "isValidIpAddress() : invalid 'block', block = " 1274 | + + block); 1275 | + return false; 1276 | + } 1277 | + } catch (NumberFormatException e) { 1278 | + Log.w("EthernetIP", "isValidIpAddress() : e = " + e); 1279 | + return false; 1280 | + } 1281 | + 1282 | + numBlocks++; 1283 | + 1284 | + start = end + 1; 1285 | + end = value.indexOf('.', start); 1286 | + } 1287 | + return numBlocks == 4; 1288 | + } 1289 | + public void checkIPValue() 1290 | + { 1291 | + boolean enable = false; 1292 | + String ipAddr = mIpAddressView.getText().toString(); 1293 | + String gateway = mIPgateway.getText().toString(); 1294 | + String dns1 = mdns1.getText().toString(); 1295 | + String dns2 = mdns2.getText().toString(); 1296 | + String netMask = ipnetmask.getText().toString(); 1297 | + Pattern pattern = Pattern.compile("(^((\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])$)|^(\\d|[1-2]\\d|3[0-2])$"); /*check subnet mask*/ 1298 | + if (isValidIpAddress(ipAddr) && isValidIpAddress(gateway) 1299 | + && isValidIpAddress(dns1) && (pattern.matcher(netMask).matches())) { 1300 | + if (TextUtils.isEmpty(dns2)) { // ??????? 1301 | + enable = true; 1302 | + } else { 1303 | + if (isValidIpAddress(dns2)) { 1304 | + enable = true; 1305 | + } else { 1306 | + enable = false; 1307 | + } 1308 | + } 1309 | + } else { 1310 | + enable = false; 1311 | + } 1312 | + getButton(BUTTON_SUBMIT).setEnabled(enable); 1313 | + 1314 | + } 1315 | + @Override 1316 | + public void afterTextChanged(Editable s) { 1317 | + 1318 | + checkIPValue(); 1319 | + Log.d("EthernetStaticDialog", "afterTextChanged"); 1320 | + } 1321 | + 1322 | + @Override 1323 | + public void beforeTextChanged(CharSequence s, int start, int count, 1324 | + int after) { 1325 | + // work done in afterTextChanged 1326 | + } 1327 | + 1328 | + @Override 1329 | + public void onTextChanged(CharSequence s, int start, int before, int count) { 1330 | + // work done in afterTextChanged 1331 | + } 1332 | +} 1333 | \ No newline at end of file 1334 | diff --git a/src/com/android/settings/ethernet/getStaticIpInfo.java b/src/com/android/settings/ethernet/getStaticIpInfo.java 1335 | new file mode 100644 1336 | index 0000000..022969a 1337 | --- /dev/null 1338 | +++ b/src/com/android/settings/ethernet/getStaticIpInfo.java 1339 | @@ -0,0 +1,9 @@ 1340 | +package com.android.settings; 1341 | + 1342 | +public interface getStaticIpInfo { 1343 | + public boolean getStaticIp(String ipAddr); 1344 | + public boolean getStaticNetMask(String netMask); 1345 | + public boolean getStaticGateway(String gateway); 1346 | + public boolean getStaticDns1(String dns1); 1347 | + public boolean getStaticDns2(String dns2); 1348 | +} 1349 | \ No newline at end of file 1350 | -- 1351 | 2.6.4 1352 | 1353 | --------------------------------------------------------------------------------