----------------------------- AndroidManifest.xml -----------------------------
index b19f5ff..c3b09ad 100644
@@ -499,4 +499,26 @@
</activity-alias>
+
+ <activity android:name="Settings$EthernetSettingsActivity"
+ android:label="@string/ethernet_settings"
+ android:icon="@drawable/ic_ethernet"
+ android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc"
+ android:launchMode="singleInstance"
+ android:parentActivityName="Settings">
+ <intent-filter android:priority="6">
+ <action android:name="android.settings.ETHERNET_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.VOICE_LAUNCH" />
+ <category android:name="com.android.settings.SHORTCUT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.ethernet.EthernetSettings" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
<activity android:name="Settings$WifiP2pSettingsActivity"
android:taskAffinity="com.android.settings"
------------------------- res/drawable/ic_ethernet.xml -------------------------
new file mode 100755
index 0000000..6431a00
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2016 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License
+ -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M7.77,6.76L6.23,5.48 0.82,12l5.41,6.52 1.54,-1.28L3.42,12l4.35,-5.24zM7,13h2v-2L7,11v2zM17,11h-2v2h2v-2zM11,13h2v-2h-2v2zM17.77,5.48l-1.54,1.28L20.58,12l-4.35,5.24 1.54,1.28L23.18,12l-5.41,-6.52z"/>
+</vector>
\ No newline at end of file
----------------------- res/layout/static_ip_dialog.xml -----------------------
new file mode 100755
index 0000000..658c881
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:fadeScrollbars="false" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingBottom="8dip" >
+
+ <LinearLayout
+ android:id="@+id/wifi_advanced_fields"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:id="@+id/proxy_fields"
+ style="@style/wifi_section"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+ android:id="@+id/staticip"
+ style="@style/wifi_section"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <LinearLayout
+ style="@style/wifi_item"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ style="@style/wifi_item_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wifi_ip_address" />
+
+ <EditText
+ android:id="@+id/ipaddress"
+ style="@style/wifi_item_edit_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/wifi_ip_address_hint"
+ android:inputType="textNoSuggestions"
+ android:singleLine="true" />
+ </LinearLayout>
+
+ <LinearLayout
+ style="@style/wifi_item"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ style="@style/wifi_item_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wifi_gateway" />
+
+ <EditText
+ android:id="@+id/gateway"
+ style="@style/wifi_item_edit_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/wifi_gateway_hint"
+ android:inputType="textNoSuggestions"
+ android:singleLine="true" />
+ </LinearLayout>
+
+ <LinearLayout
+ style="@style/wifi_item"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ style="@style/wifi_item_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/ethernet_netmask" />
+
+ <EditText
+ android:id="@+id/network_prefix_length"
+ style="@style/wifi_item_edit_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/ethernet_netmask_hint"
+ android:inputType="textNoSuggestions"
+ android:singleLine="true" />
+ </LinearLayout>
+
+ <LinearLayout
+ style="@style/wifi_item"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ style="@style/wifi_item_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wifi_dns1" />
+
+ <EditText
+ android:id="@+id/dns1"
+ style="@style/wifi_item_edit_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/wifi_dns1_hint"
+ android:inputType="textNoSuggestions"
+ android:singleLine="true" />
+ </LinearLayout>
+
+ <LinearLayout
+ style="@style/wifi_item"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <TextView
+ style="@style/wifi_item_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wifi_dns2" />
+
+ <EditText
+ android:id="@+id/dns2"
+ style="@style/wifi_item_edit_content"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/wifi_dns2_hint"
+ android:inputType="textNoSuggestions"
+ android:singleLine="true" />
+ </LinearLayout>
+ </LinearLayout>
+ </LinearLayout>
+ </LinearLayout>
+ </LinearLayout>
+
+</ScrollView>
\ No newline at end of file
---------------------------- res/values/arrays.xml ----------------------------
index 7b9bee4..04546b9 100644
@@ -1175,4 +1175,13 @@
<item>0</item>
</string-array>
+ <!--ethernet mode select -->
+ <string-array name="ethernet_mode_location">
+ <item>@string/usestatic</item>
+ <item>@string/usedhcp</item>
+ </string-array>
+ <string-array name="ethernet_mode_values">
+ <item>StaticIP</item>
+ <item>DHCP</item>
+ </string-array>
</resources>
---------------------------- res/values/strings.xml ----------------------------
index def3ea6..996ce19 100644
@@ -3401,4 +3401,47 @@
<!-- Reset settings complete toast text [CHAR LIMIT=75] -->
<string name="reset_network_complete_toast">Network settings have been reset</string>
+ <!-- Ethernet Settings -->
+ <string name="ethernet_settings_title">Ethernet</string>
+ <string name="ethernet_netmask_hint" translatable="false"> 255.255.255.0</string>
+ <!--string name="ethernet_info_getting">"getting IP info..."</string-->
+ <string name="ethernet_settings">Ethernet</string>
+ <string name="ethernet_connect">Connect</string>
+ <string name="ethernet_cancel">Cancel</string>
+ <!--Wireless controls screen, settings summary for the item tot ake you to the ethernet settings screen -->
+ <string name="ethernet_settings_summary">Manager ethernet</string>
+ <!-- ethernet hw address -->
+ <string name="ethernet_hw_addr">MAC</string>
+ <!-- ethernet ip address -->
+ <string name="ethernet_ip_addr">IP address</string>
+ <!-- ethernet netmask -->
+ <string name="ethernet_netmask">netmask</string>
+ <!-- ethernet gateway -->
+ <string name="ethernet_gateway">gateway</string>
+ <!-- ethernet dns1 -->
+ <string name="ethernet_dns1">dns1</string>
+ <!-- ethernet dns2 -->
+ <string name="ethernet_dns2">dns2</string>
+ <string name="category_ethernet">Static IP Setttings</string>
+ <string name="usedhcp">dhcp</string>
+ <string name="usestatic">static</string>
+ <string name="ethernet_use_static_ip">Use static IP</string>
+ <string name="ethernet_ip_address">IP address</string>
+ <string name="staticip_save">Save</string>
+ <string name="staticip_cancel">Cancel</string>
+ <string name="str_ok">OK</string>
+ <string name="str_cancel">Cancel</string>
+ <string name="str_about">Important</string>
+ <string name="str_mesg">Whether save Settings?</string>
+ <string name="save_failed">Save failed!</string>
+ <string name="ethernet_ip_settings_invalid_ip">Please type a valid IP address.</string>
+ <string name="eth_ip_settings_please_complete_settings">Please give complete static IP settings!</string>
+ <string name="ethernet_quick_toggle_title">Ethernet</string>
+ <!-- Ethernet settings check box summary for turning on ethernet -->
+ <string name="ethernet_quick_toggle_summary_off">Ethernet is disabled</string>
+ <!--Used as title on second screen after selecting Ethernet settings -->
+ <string name="ethernet_quick_toggle_summary_on">Ethernet is enabled</string>
+ <!--Used as title on second screen after selecting Ethernet settings -->
+ <string name="ethernet_mode_title">Ethernet Ip mode</string>
+ <string name="ethernet_info_getting">"getting IP info..."</string>
<!-- Title of the error message shown when error happens during erase eSIM data [CHAR LIMIT=NONE] -->
<string name="reset_esim_error_title">Cant\u2019t reset eSIMs</string>
------------------------ res/xml/ethernet_settings.xml ------------------------
new file mode 100755
index 0000000..f5ffea6
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+ android:title="@string/ethernet_settings" >
+
+ <!-- $_rbox_$_modify_$_lijiehong: change to support bluetooth checkbox -->
+<!--
+ <SwitchPreference
+ android:key="ethernet"
+ android:title="@string/ethernet_quick_toggle_title"
+ android:summaryOff="@string/ethernet_quick_toggle_summary_off"
+ android:summaryOn="@string/ethernet_quick_toggle_summary_on"
+ android:persistent="false"
+ android:disableDependentsState="true" />
+-->
+ <!--
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_hw_addr"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_hw_addr" />
+ -->
+ <!-- ethernet ip address -->
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_ip_addr"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_ip_addr" />
+
+ <!-- ethernet netmask -->
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_netmask"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_netmask" />
+
+ <!-- ethernet gateway -->
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_gateway"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_gateway" />
+
+ <!-- ethernet dns1 -->
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_dns1"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_dns1" />
+
+ <!-- ethernet dns2 -->
+ <Preference
+ style="?android:preferenceInformationStyle"
+ android:key="ethernet_dns2"
+ android:summary="@string/device_info_default"
+ android:title="@string/ethernet_dns2" />
+
+ <ListPreference
+ android:entries="@array/ethernet_mode_location"
+ android:entryValues="@array/ethernet_mode_values"
+ android:key="ethernet_mode_select"
+ android:persistent="true"
+ android:title="@string/ethernet_mode_title" />
+
+ <!--
+ <CheckBoxPreference
+ android:key="static_ethernet"
+ android:title="@string/usestatic" />
+ <CheckBoxPreference
+ android:key="dhcp_ethernet"
+ android:title="@string/usedhcp" />
+ -->
+</PreferenceScreen>
-------------------- src/com/android/settings/Settings.java --------------------
index 12d3564..54fd3d3 100644
@@ -34,4 +34,5 @@ public class Settings extends SettingsActivity {
public static class AssistGestureSettingsActivity extends SettingsActivity { /* empty */}
public static class BluetoothSettingsActivity extends SettingsActivity { /* empty */ }
+ public static class EthernetSettingsActivity extends SettingsActivity { /* empty */ }
public static class SimSettingsActivity extends SettingsActivity { /* empty */ }
public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
---------------- src/com/android/settings/SettingsActivity.java ----------------
index 3614ba7..fad2469 100644
@@ -79,4 +79,6 @@ import com.mediatek.settings.UtilsExt;
import java.util.ArrayList;
import java.util.List;
+//import com.android.settings.ethernet.EthernetSettings;
+import com.android.settings.Settings.EthernetSettingsActivity;
public class SettingsActivity extends SettingsDrawerActivity
@@ -651,4 +653,10 @@ public class SettingsActivity extends SettingsDrawerActivity
pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
|| somethingChanged;
+ //ethernet settings
+ somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
+ Settings.EthernetSettingsActivity.class.getName()),
+ true,isAdmin)
+ || somethingChanged;
+ //end
---------- src/com/android/settings/core/gateway/SettingsGateway.java ----------
index 3726a46..3b18c12 100644
@@ -144,4 +144,5 @@ import com.mediatek.settings.advancedcalling.AdvancedWifiCallingSettings;
import com.mediatek.settings.DrmSettings;
import com.mediatek.settings.sim.SmartCallFwdFragment;
+import com.android.settings.ethernet.EthernetSettings;
public class SettingsGateway {
@@ -282,5 +283,7 @@ public class SettingsGateway {
AdvancedWifiCallingSettings.class.getName(),
/// M: SmartCallForward setting fragment
- SmartCallFwdFragment.class.getName()
+ SmartCallFwdFragment.class.getName(),
+ /// M: Advanced Calling and Ethernet Settings
+ EthernetSettings.class.getName()
};
@@ -290,4 +293,5 @@ public class SettingsGateway {
Settings.ConnectedDeviceDashboardActivity.class.getName(),
Settings.AppAndNotificationDashboardActivity.class.getName(),
+ Settings.EthernetSettingsActivity.class.getName(),
Settings.DisplaySettingsActivity.class.getName(),
Settings.SoundSettingsActivity.class.getName(),
----------- src/com/android/settings/ethernet/EthernetSettings.java -----------
new file mode 100755
index 0000000..805aece
@@ -0,0 +1,721 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.ethernet;
+
+import com.android.settings.SettingsPreferenceFragment;
+
+import com.android.settings.R;
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.admin.DevicePolicyManager;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceScreen;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.Preference;
+import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.content.Intent;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import android.net.NetworkCapabilities;
+
+import java.util.regex.Pattern;
+import java.lang.Integer;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.util.Iterator;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.Preference.OnPreferenceClickListener;
+import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment;
+
+/*for 5.0*/
+import android.net.EthernetManager;
+import android.net.IpConfiguration;
+import android.net.IpConfiguration.IpAssignment;
+import android.net.IpConfiguration.ProxySettings;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.StaticIpConfiguration;
+import android.net.NetworkUtils;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+import java.util.Enumeration;
+import java.net.NetworkInterface;
+import java.util.Collections;
+import java.net.InterfaceAddress;
+import android.net.RouteInfo;
+import java.util.BitSet;
+
+
+import com.android.settings.ethernet.ethernet_static_ip_dialog;
+
+public class EthernetSettings extends SettingsPreferenceFragment
+ implements DialogInterface.OnClickListener ,Preference.OnPreferenceChangeListener {
+ private static final String TAG = "EthernetSettings";
+
+ private static final String KEY_ETH_IP_ADDRESS = "ethernet_ip_addr";
+ private static final String KEY_ETH_HW_ADDRESS = "ethernet_hw_addr";
+ private static final String KEY_ETH_NET_MASK = "ethernet_netmask";
+ private static final String KEY_ETH_GATEWAY = "ethernet_gateway";
+ private static final String KEY_ETH_DNS1 = "ethernet_dns1";
+ private static final String KEY_ETH_DNS2 = "ethernet_dns2";
+ private static final String KEY_ETH_MODE= "ethernet_mode_select";
+ private ConnectivityManager mConnectivityManager;
+
+ private static StaticIpInfo mStaticIpInfo =null;
+ private static String mEthHwAddress = null;
+ private static String mEthIpAddress = null;
+ private static String mEthNetmask = null;
+ private static String mEthGateway = null;
+ private static String mEthdns1 = null;
+ private static String mEthdns2 = null;
+ private final static String nullIpInfo = "0.0.0.0";
+ private String mInterfaceName;
+ private boolean ethConnected = false;
+
+ private ListPreference mkeyEthMode;
+ private CheckBoxPreference staticEthernet;
+
+ EthernetManager mEthManager;
+ private final IntentFilter mIntentFilter;
+ //IpConfiguration mIpConfiguration = null;
+ //StaticIpConfiguration mStaticIpConfiguration;
+ Context mContext;
+ private ethernet_static_ip_dialog mDialog;
+ private static final int SHOW_RENAME_DIALOG = 0;
+ private static final int ETHER_IFACE_STATE_DOWN = 0;
+ private static final int ETHER_IFACE_STATE_UP = 1;
+ private final BitSet mConnectedTransports = new BitSet();
+
+ private static final String FILE = "/sys/class/net/eth0/flags";
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsEvent.WIFI_TETHER_SETTINGS;
+ }
+
+ @Override
+ public int getDialogMetricsCategory(int dialogId) {
+ switch (dialogId) {
+ case SHOW_RENAME_DIALOG:
+ return MetricsEvent.WIFI_TETHER_SETTINGS;
+ default:
+ return 0;
+ }
+ }
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.e(TAG,"Action :"+action +" getActiveNetworkInfo:"+ mConnectivityManager.getActiveNetworkInfo());
+ NetworkInfo netinfo = (NetworkInfo)intent.getExtras().get(ConnectivityManager.EXTRA_NETWORK_INFO);
+ Log.e(TAG,"intent.NetworkInfo :"+netinfo);
+ int EtherState = EthernetManager.ETHER_STATE_DISCONNECTED;
+ if(netinfo!=null){
+ //CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN
+ if(netinfo.getState()== NetworkInfo.State.DISCONNECTED)
+ EtherState = EthernetManager.ETHER_STATE_DISCONNECTED;
+ else if(netinfo.getState()== NetworkInfo.State.DISCONNECTED)
+ EtherState = EthernetManager.ETHER_STATE_CONNECTING;
+ else if(netinfo.getState() == NetworkInfo.State.CONNECTED)
+ EtherState = EthernetManager.ETHER_STATE_CONNECTED;
+ }
+ handleEtherStateChange(EtherState);
+ /*
+ if(ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
+ mConnectedTransports.clear();
+ for (NetworkCapabilities nc :
+ mConnectivityManager.getDefaultNetworkCapabilitiesForUser(0)) {
+ for (int transportType : nc.getTransportTypes()) {
+ mConnectedTransports.set(transportType);
+ }
+ }
+ ethConnected = mConnectedTransports.get(3);
+ int EtherState;
+ Log.e(TAG,"ethConnected :"+ethConnected);
+ if(ethConnected){
+ EtherState = 2;
+ }else{
+ EtherState = 0;
+ }
+ //int EtherState=intent.getIntExtra(EthernetManager.EXTRA_ETHERNET_STATE, -1);
+ Log.e(TAG,"for BroadcastReceiver");
+ }*/
+ }
+ };
+
+ public EthernetSettings() {
+ mIntentFilter = new IntentFilter();
+ mIntentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ mIntentFilter.addAction(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);
+ //mIntentFilter = new IntentFilter(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);
+ }
+
+ private void handleEtherStateChange(int EtherState ) {
+ log("handleEtherStateChange curEtherState:"+ EtherState);
+ switch(EtherState) {
+ case EthernetManager.ETHER_STATE_DISCONNECTED:
+ mEthHwAddress = nullIpInfo;
+ mEthIpAddress = nullIpInfo;
+ mEthNetmask = nullIpInfo;
+ mEthGateway = nullIpInfo;
+ mEthdns1 = nullIpInfo;
+ mEthdns2 = nullIpInfo;
+ break;
+ case EthernetManager.ETHER_STATE_CONNECTING:
+ String mStatusString = this.getResources().getString(R.string.ethernet_info_getting);
+ mEthHwAddress = mStatusString;
+ mEthIpAddress = mStatusString;
+ mEthNetmask = mStatusString;
+ mEthGateway = mStatusString;
+ mEthdns1 = mStatusString;
+ mEthdns2 = mStatusString;
+ break;
+ case EthernetManager.ETHER_STATE_CONNECTED:
+ Log.e(TAG," for EthernetManager.ETHER_STATE_CONNECTED");
+ getEthInfo();
+ break;
+ }
+
+ refreshUI();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.ethernet_settings);
+ Log.e(TAG," in onCreate");
+ mEthManager = (EthernetManager) getSystemService(Context.ETHERNET_SERVICE);
+
+ //Context.registerReceiver(mReceiver,filter);
+ if (mEthManager == null) {
+ Log.e(TAG, "get ethernet manager failed");
+ return;
+ }
+ Log.e(TAG," in onCreate,before getApplicationContext");
+ mContext= this.getActivity().getApplicationContext();
+ mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if(mStaticIpInfo==null)
+ mStaticIpInfo = new StaticIpInfo();
+ }
+
+ private Inet4Address getIPv4Address(String text) {
+ try {
+ return (Inet4Address) NetworkUtils.numericToInetAddress(text);
+ } catch (IllegalArgumentException|ClassCastException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ Log.e(TAG," onresume()");
+ if(mkeyEthMode==null) {
+ mkeyEthMode=(ListPreference)findPreference(KEY_ETH_MODE);
+ mkeyEthMode.setOnPreferenceChangeListener(this);
+ }
+ String iface ="eth0";
+ boolean isav;
+ int intav;
+ isav = mEthManager.isAvailable(iface);
+ Log.e(TAG,"onresume:,isAvailable:"+isav);
+ if (isav){
+ intav = 2;
+ }
+ else{
+ intav = 0;
+ }
+ handleEtherStateChange(intav);
+ mContext.registerReceiver(mReceiver, mIntentFilter);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ log("destory");
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ }
+
+ @Override
+ public void onStop(){
+ super.onStop();
+ log("stop");
+ mContext.unregisterReceiver(mReceiver);
+ }
+
+ private void setStringSummary(String preference, String value) {
+ try {
+ findPreference(preference).setSummary(value);
+ } catch (RuntimeException e) {
+ findPreference(preference).setSummary("");
+ log("can't find "+preference);
+ }
+ }
+ private String getStringFromPref(String preference) {
+ try {
+ return findPreference(preference).getSummary().toString();
+ } catch (RuntimeException e) {
+ return null;
+ }
+ }
+ private void refreshUI ( ) {
+ log("refreshUI IpAddress:"+mEthIpAddress);
+ setStringSummary(KEY_ETH_IP_ADDRESS, mEthIpAddress);
+ setStringSummary(KEY_ETH_NET_MASK, mEthNetmask);
+ setStringSummary(KEY_ETH_GATEWAY, mEthGateway);
+ setStringSummary(KEY_ETH_DNS1, mEthdns1);
+ setStringSummary(KEY_ETH_DNS2, mEthdns2);
+ updateCheckbox();
+ }
+
+ //This is update Ethernet Mode (Static IP or DHCP)
+ private void updateCheckbox(){
+ String[] ifaces = mEthManager.getAvailableInterfaces();
+ if(mEthManager==null){
+ mkeyEthMode.setSummary("null");
+ } else {
+ if (ifaces.length > 0){
+ mInterfaceName = ifaces[0];
+ log("updateCheckbox(), mInterfaceName:"+mInterfaceName);
+ boolean useStaticIP=(mEthManager.getConfiguration(mInterfaceName).ipAssignment == IpAssignment.STATIC) ? true : false;
+ log("updateCheckbox(), useStaticIP = " + useStaticIP);
+ if(useStaticIP == true){
+ mkeyEthMode.setValue("StaticIP");
+ mkeyEthMode.setSummary(R.string.usestatic);
+ }else {
+ mkeyEthMode.setValue("DHCP");
+ mkeyEthMode.setSummary(R.string.usedhcp);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ log("Enter in onPreferenceChange() "+(String)newValue);
+ if(preference==mkeyEthMode) {
+ String value=(String)newValue;
+ if(value.equals("DHCP")){
+ IpConfiguration ipConfiguration = new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE,null,null);
+ mEthManager.setConfiguration(mInterfaceName, ipConfiguration);
+ log("switch to dhcp");
+ mEthManager.updateIpConfiguration(mInterfaceName, ipConfiguration);
+ }else if(value.equals("StaticIP")){
+ log("static editor");
+ this.showDialog(SHOW_RENAME_DIALOG);
+ }
+ }
+ return true;
+ }
+
+ public String interMask2String(int prefixLength) {
+ String netMask = null;
+ int inetMask = prefixLength;
+
+ int part = inetMask / 8;
+ int remainder = inetMask % 8;
+ int sum = 0;
+
+ for (int i = 8; i > 8 - remainder; i--) {
+ sum = sum + (int) Math.pow(2, i - 1);
+ }
+
+ if (part == 0) {
+ netMask = sum + ".0.0.0";
+ } else if (part == 1) {
+ netMask = "255." + sum + ".0.0";
+ } else if (part == 2) {
+ netMask = "255.255." + sum + ".0";
+ } else if (part == 3) {
+ netMask = "255.255.255." + sum;
+ } else if (part == 4) {
+ netMask = "255.255.255.255";
+ }
+
+ return netMask;
+ }
+
+ /*
+ * convert subMask string to prefix length
+ */
+ private int maskStr2InetMask(String maskStr) {
+ StringBuffer sb ;
+ String str;
+ int inetmask = 0;
+ int count = 0;
+ /*
+ * check the subMask format
+ */
+ 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])$");
+ if (pattern.matcher(maskStr).matches() == false) {
+ Log.e(TAG,"subMask is error");
+ return 0;
+ }
+
+ String[] ipSegment = maskStr.split("\\.");
+ for(int n =0; n<ipSegment.length;n++) {
+ sb = new StringBuffer(Integer.toBinaryString(Integer.parseInt(ipSegment[n])));
+ str = sb.reverse().toString();
+ count=0;
+ for(int i=0; i<str.length();i++) {
+ i=str.indexOf("1",i);
+ if(i==-1)
+ break;
+ count++;
+ }
+ inetmask+=count;
+ }
+ return inetmask;
+ }
+
+ private boolean setStaticIpConfiguration() {
+
+ log("Enter in setStaticIpConfiguration()");
+ StaticIpConfiguration mStaticIpConfiguration = new StaticIpConfiguration();
+
+ Inet4Address inetAddr = getIPv4Address(this.mEthIpAddress);
+ int prefixLength = maskStr2InetMask(this.mEthNetmask);
+ InetAddress gatewayAddr =getIPv4Address(this.mEthGateway);
+ InetAddress dnsAddr = getIPv4Address(this.mEthdns1);
+
+ log("inetAddr:" + inetAddr.toString());
+
+ if (inetAddr.getAddress().toString().isEmpty() || prefixLength ==0 || gatewayAddr.toString().isEmpty()
+ || dnsAddr.toString().isEmpty()) {
+ log("ip,mask or dnsAddr is wrong");
+ return false;
+ }
+
+ String dnsStr2=this.mEthdns2;
+ mStaticIpConfiguration.ipAddress = new LinkAddress(inetAddr, prefixLength);
+ mStaticIpConfiguration.gateway = gatewayAddr;
+ mStaticIpConfiguration.dnsServers.add(dnsAddr);
+
+ if (!dnsStr2.isEmpty()) {
+ mStaticIpConfiguration.dnsServers.add(getIPv4Address(dnsStr2));
+ }
+ IpConfiguration ipConfiguration = new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE,mStaticIpConfiguration,null);
+ ipConfiguration.setIpAssignment(IpAssignment.STATIC);
+ ipConfiguration.setStaticIpConfiguration(mStaticIpConfiguration);
+ mEthManager.setConfiguration(mInterfaceName, ipConfiguration);
+ Log.e(TAG,"setStaticIpConfiguration mInterfaceName: "+mInterfaceName+"mIpConfiguration"+ipConfiguration);
+
+ mEthManager.updateIpConfiguration(mInterfaceName, ipConfiguration);
+
+
+ return true;
+ }
+
+ public void getEthInfoFromDhcp(){
+ String iface ;
+ String tempIpInfo;
+ iface = "eth0";
+ Log.e(TAG,"getEthInfoFromDhcp tempIpInfo");
+ //*SystemProperties.get("dhcp."+ iface +".ipaddress");
+ //tempIpInfo = getEthernetIpAddress();
+ LinkProperties linkProperties = mConnectivityManager.getLinkProperties(ConnectivityManager.TYPE_ETHERNET);
+ if (null == linkProperties) {
+ mEthIpAddress = nullIpInfo;
+ mEthNetmask = nullIpInfo;
+ mEthGateway = nullIpInfo;
+ mEthdns1 = nullIpInfo;
+ mEthdns2 = nullIpInfo;
+ return ;
+ }
+ for (LinkAddress linkAddress: linkProperties.getAllLinkAddresses()) {
+ InetAddress address = linkAddress.getAddress();
+ if (address instanceof Inet4Address) {
+ tempIpInfo = address.getHostAddress();
+ Log.e(TAG,"getEthInfoFromDhcp tempIpInfo:"+tempIpInfo);
+ //Log.e(TAG," for getEthInfoFromDhcp,netmaskInt :"+netmaskInt);
+ if ((tempIpInfo != null) && (!tempIpInfo.equals("")) ){
+ mEthIpAddress = tempIpInfo;
+ } else {
+ mEthIpAddress = nullIpInfo;
+ }
+ }
+ }
+ InetAddress inetAddress = null;
+ int netmaskInt = -1;
+ List<LinkAddress> linkaddress = linkProperties.getLinkAddresses();
+ inetAddress = linkaddress.get(0).getAddress();
+ for (int i = 0; i < linkaddress.size(); i++) {
+ inetAddress = linkaddress.get(i).getAddress();
+ if ((inetAddress instanceof Inet4Address) && !inetAddress.isAnyLocalAddress()) {
+ inetAddress = linkaddress.get(i).getAddress();
+ netmaskInt = NetworkUtils.prefixLengthToNetmaskInt(linkaddress.get(i).getNetworkPrefixLength());
+ tempIpInfo = ipTransfer(netmaskInt);
+ Log.e(TAG,"getEthInfoFromDhcp netmaskInt,tempIpInfo:"+tempIpInfo);
+ Log.e(TAG,"getNetmask "+tempIpInfo);
+ if ((tempIpInfo != null) && (!tempIpInfo.equals("")) ){
+ mEthNetmask = tempIpInfo;
+ } else {
+ mEthNetmask = nullIpInfo;
+ }
+ }
+ }
+ Log.e(TAG,"getEthInfoFromDhcp inetAddress:"+inetAddress);
+ //get Gateway
+ List<RouteInfo> routeInfo = linkProperties.getRoutes();
+ if (routeInfo.size() == 0) {
+ } else {
+ InetAddress gatewayAddr = null;
+ gatewayAddr = routeInfo.get(0).getGateway();
+ for (int i = 0; i < routeInfo.size(); i++) {
+ Log.e(TAG, "updateStaticIP,routeInfo[" + i + "]: " + routeInfo.get(i).getGateway().getHostAddress());
+ gatewayAddr = routeInfo.get(i).getGateway();
+ if ((gatewayAddr instanceof Inet4Address) && !gatewayAddr.isAnyLocalAddress()) {
+ tempIpInfo = routeInfo.get(i).getGateway().getHostAddress();
+ Log.e(TAG,"getGateway "+tempIpInfo);
+
+ if ((tempIpInfo != null) && (!tempIpInfo.equals(""))){
+ mEthGateway = tempIpInfo;
+ } else {
+ mEthGateway = nullIpInfo;
+ }
+ }
+ }
+ }
+ //getDns
+ List<InetAddress> DnsInfo = linkProperties.getDnsServers();
+ if (DnsInfo.size() == 0) {
+ } else {
+ InetAddress DnsAddr = null;
+ for (int i = 0; i < DnsInfo.size(); i++) {
+ DnsAddr = DnsInfo.get(i);
+ if ((DnsAddr instanceof Inet4Address) && !DnsAddr.isAnyLocalAddress()) {
+ tempIpInfo = DnsInfo.get(i).getHostAddress();
+ Log.e(TAG," for Dns:"+tempIpInfo);
+ // Get DNS
+ if ((tempIpInfo != null) && (!tempIpInfo.equals(""))){
+ mEthdns1 = tempIpInfo;
+ mEthdns2 = nullIpInfo;
+ }else{
+ mEthdns1 = nullIpInfo;
+ mEthdns2 = nullIpInfo;
+ }
+ }
+ }
+ }
+ }
+
+ private String ipTransfer(int value) {
+ String result = null;
+ if (value != 0) {
+ if (value < 0) {
+ value += 0x100000000L;
+ }
+ result = String.format("%d.%d.%d.%d", value & 0xFF, (value >> 8) & 0xFF,
+ (value >> 16) & 0xFF, (value >> 24) & 0xFF);
+ }
+
+ return result;
+ }
+ public void getEthInfoFromStaticIp() {
+ String[] ifaces = mEthManager.getAvailableInterfaces();
+ Log.e(TAG," for getEthInfoFromStaticIp,ifaces "+ifaces);
+ if (ifaces.length > 0){
+ mInterfaceName = ifaces[0];
+ StaticIpConfiguration staticIpConfiguration = mEthManager.getConfiguration(mInterfaceName).getStaticIpConfiguration();
+ Log.e(TAG," in getEthInfoFromStaticIp,staticIpConfiguration:"+staticIpConfiguration);
+ LinkAddress ipAddress = staticIpConfiguration.ipAddress;
+ InetAddress gateway = staticIpConfiguration.gateway;
+ ArrayList<InetAddress> dnsServers=staticIpConfiguration.dnsServers;
+
+ if( ipAddress !=null) {
+ mEthIpAddress=ipAddress.getAddress().getHostAddress();
+ mEthNetmask=interMask2String(ipAddress.getPrefixLength());
+ }
+ if(gateway !=null) {
+ mEthGateway=gateway.getHostAddress();
+ }
+ mEthdns1=dnsServers.get(0).getHostAddress();
+
+ if(dnsServers.size() > 1) { /* ?????*/
+ mEthdns2=dnsServers.get(1).getHostAddress();
+ }
+ }
+ return;
+ }
+
+ public void getEthInfo(){
+ boolean isAva = mEthManager.isAvailable();
+ Log.e(TAG,"getEthInfo ethinfo :"+isAva);
+ String[] ifaces = mEthManager.getAvailableInterfaces();
+ if (ifaces.length > 0){
+ mInterfaceName = ifaces[0];
+ Log.e(TAG,"getEthInfo,mInterfaceName:"+mInterfaceName+" getConfiguration:"+mEthManager.getConfiguration(mInterfaceName));
+ getEthInfoFromDhcp();
+ //if (mode== IpAssignment.DHCP || mode == IpAssignment.UNASSIGNED) {
+ // Log.e(TAG," for mode getEthInfoFromDhcp");
+ //getEthInfoFromDhcp();
+ //} else if(mode == IpAssignment.STATIC) {
+ // Log.e(TAG," for mode getEthInfoFromStaticIp");
+ //getEthInfoFromStaticIp();
+ //}
+ }
+ }
+
+ private void log(String s) {
+ Log.e(TAG, s);
+ }
+
+ @Override
+ public void onClick(DialogInterface dialogInterface, int button) {
+ if(button==ethernet_static_ip_dialog.BUTTON_SUBMIT) {
+ mDialog.saveIpSettingInfo();
+ this.mEthIpAddress = mStaticIpInfo.getStaticIp();
+ this.mEthNetmask = mStaticIpInfo.getStaticNetMask();
+ this.mEthGateway = mStaticIpInfo.getStaticGateway();
+ this.mEthdns1 = mStaticIpInfo.getStaticDns1();
+ this.mEthdns2 = mStaticIpInfo.getStaticDns2();
+ Log.i("onClick","mEthIpAddress:" + this.mEthIpAddress +" mEthGateway:"+this.mEthNetmask);
+ if(setStaticIpConfiguration()) {
+ log("onClick() setStaticIpConfiguration success");
+ } else {
+ log("onClick() setStaticIpConfiguration failed");
+ }
+ }
+ updateCheckbox();
+ }
+
+ @Override
+ public Dialog onCreateDialog(int dialogId) {
+ log("onCreateDialog "+dialogId);
+ switch(dialogId) {
+ case SHOW_RENAME_DIALOG:
+ mStaticIpInfo.setStaticIp(mEthIpAddress);
+ mStaticIpInfo.setStaticNetMask(mEthNetmask);
+ mStaticIpInfo.setStaticGateway(mEthGateway);
+ mStaticIpInfo.setStaticDns1(mEthdns1);
+ mStaticIpInfo.setStaticDns2(mEthdns2);
+ mDialog = new ethernet_static_ip_dialog(getActivity(), false, this,mStaticIpInfo);
+ return mDialog;
+ }
+ return super.onCreateDialog(dialogId);
+ }
+ public String getEthernetIpAddress() {
+ LinkProperties linkProperties = mConnectivityManager.getLinkProperties(ConnectivityManager.TYPE_ETHERNET);
+ if (null == linkProperties) {
+ return null;
+ }
+
+ for (LinkAddress linkAddress: linkProperties.getAllLinkAddresses()) {
+ InetAddress address = linkAddress.getAddress();
+ if (address instanceof Inet4Address) {
+ return address.getHostAddress();
+ }
+ }
+
+ return null;
+ }
+ /*
+ public IStaticIpInfo mIStaticIpInfo = new IStaticIpInfo() {
+
+ public boolean getStaticIp(String ipAddr) {
+ mEthIpAddress = ipAddr;
+
+ log("ipAddr: "+ipAddr);
+ return true;
+ }
+ public boolean getStaticNetMask(String netMask) {
+ mEthNetmask =netMask ;
+
+ log("netMask: "+netMask);
+ return true;
+ }
+ public boolean getStaticGateway(String gateway) {
+ mEthGateway=gateway;
+
+ log("gateway: "+gateway);
+ return true;
+ }
+ public boolean getStaticDns1(String dns1) {
+ mEthdns1=dns1;
+
+ log("dns1: "+dns1);
+ return true;
+ }
+ public boolean getStaticDns2(String dns2) {
+ mEthdns2=dns2;
+
+ log("dns2: "+dns2);
+ return true;
+ }
+ };
+ */
+ /*
+ @Override
+ public void onConnectivityChange(){
+ if (mListener != null){
+ mListener.onConnectivityChange();
+ }
+ }
+
+ public interface Listener {
+ void onConnectivityChange();
+ }
+ */
+}
-------- src/com/android/settings/ethernet/EthernetStaticIpDialog.java --------
new file mode 100755
index 0000000..85a2df1
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.ethernet;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+
+import android.net.NetworkUtils;
+
+import com.android.settings.R;
+
+import java.util.regex.Pattern;
+
+import android.content.Context;
+import android.preference.EditTextPreference;
+import android.provider.Settings.System;
+import android.app.AlertDialog;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.provider.Settings.System;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Button;
+
+import android.net.EthernetManager;
+import android.net.IpConfiguration;
+import android.net.IpConfiguration.IpAssignment;
+import android.net.IpConfiguration.ProxySettings;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.net.StaticIpConfiguration;
+import android.net.NetworkUtils;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+
+class ethernet_static_ip_dialog extends AlertDialog implements TextWatcher {
+
+ public StaticIpInfo mStaticInfo;
+ private TextView mIpAddressView;
+ private TextView mIPgateway;
+ private TextView ipnetmask;
+ private TextView mdns1;
+ private TextView mdns2;
+
+ public EditText ip_address;
+ public EditText ip_gateway;
+ public EditText gateway;
+ public EditText dns1;
+ public EditText dns2;
+
+ static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
+ static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
+
+ private final static String nullIpInfo = "0.0.0.0";
+
+ // private final boolean mEdit;
+ private final DialogInterface.OnClickListener mListener;
+
+ private View mView;
+ Context mcontext;
+ EthernetManager mEthManager;
+ StaticIpConfiguration mStaticIpConfiguration;
+
+ // private boolean mHideSubmitButton;
+
+ public ethernet_static_ip_dialog(Context context, boolean cancelable,
+ DialogInterface.OnClickListener listener,StaticIpInfo StaticIpInfo) {
+ super(context);
+ mcontext = context;
+ mListener = listener;
+ mStaticInfo = StaticIpInfo;
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ mView = getLayoutInflater().inflate(R.layout.static_ip_dialog, null);
+ setView(mView);
+ setInverseBackgroundForced(true);
+ Log.e("EthernetStaticDialog","sj log onCreate");
+ mIpAddressView = (TextView) mView.findViewById(R.id.ipaddress);
+ ipnetmask = (TextView) mView.findViewById(R.id.network_prefix_length);
+ mIPgateway = (TextView) mView.findViewById(R.id.gateway);
+ mdns1 = (TextView) mView.findViewById(R.id.dns1);
+ mdns2 = (TextView) mView.findViewById(R.id.dns2);
+
+ mIpAddressView.addTextChangedListener(this);
+ ipnetmask.addTextChangedListener(this);
+ mIPgateway.addTextChangedListener(this);
+ mdns1.addTextChangedListener(this);
+ mdns2.addTextChangedListener(this);
+
+ setButton(BUTTON_SUBMIT, mcontext.getString(R.string.ethernet_connect), mListener);
+ setButton(BUTTON_NEGATIVE,mcontext.getString(R.string.ethernet_cancel), mListener);
+ setTitle(mcontext.getString(R.string.ethernet_settings));
+
+ mEthManager = (EthernetManager) mcontext.getSystemService(Context.ETHERNET_SERVICE);
+
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ Log.e("EthernetStaticDialog","sj log onStart");
+ updateIpSettingsInfo();
+ checkIPValue();
+ }
+ private void updateIpSettingsInfo() {
+ Log.e("EthernetStaticDialog", "Static IP status updateIpSettingsInfo");
+ ContentResolver contentResolver = mcontext.getContentResolver();
+ String staticip = mStaticInfo.getStaticIp();
+ Log.e("EthernetStaticDialog","sj log in updateIpSettingsInfo staticip: "+staticip);
+ if (!TextUtils.isEmpty(staticip)){
+ mIpAddressView.setText(staticip);
+ }
+ String ipmask = mStaticInfo.getStaticNetMask();
+ Log.e("EthernetStaticDialog","sj log in updateIpSettingsInfo ipmask: "+ipmask);
+ if (!TextUtils.isEmpty(ipmask))
+ ipnetmask.setText(ipmask);
+
+ String gateway = mStaticInfo.getStaticGateway();
+ if (!TextUtils.isEmpty(gateway))
+ mIPgateway.setText(gateway);
+
+ String mDns1 = mStaticInfo.getStaticDns1();
+ if (!TextUtils.isEmpty(mDns1))
+ mdns1.setText(mDns1);
+
+ String mDns2 = mStaticInfo.getStaticDns2();
+ if (!TextUtils.isEmpty(mDns2))
+ mdns2.setText(mDns2);
+
+ }
+
+ public void saveIpSettingInfo() {
+ Log.d("EthernetStaticDialog", "Enter in SaveIpSettingInfo");
+ ContentResolver contentResolver = mcontext.getContentResolver();
+ String ipAddr = mIpAddressView.getText().toString();
+ String gateway = mIPgateway.getText().toString();
+ String netMask =ipnetmask.getText().toString();
+ String dns1 = mdns1.getText().toString();
+ String dns2 = mdns2.getText().toString();
+ int network_prefix_length = 24;// Integer.parseInt(ipnetmask.getText().toString());
+
+ Log.i("EthernetStaticDialog","ipAddr:" + ipAddr +" gateway:"+gateway);
+ mStaticInfo.setStaticIp(ipAddr);
+ mStaticInfo.setStaticNetMask(netMask);
+ mStaticInfo.setStaticGateway(gateway);
+ mStaticInfo.setStaticDns1(dns1);
+ mStaticInfo.setStaticDns2(dns2);
+ }
+
+ /*
+ * ?? ??? String ??? ??? IP ??.
+ */
+ private boolean isValidIpAddress(String value) {
+ int start = 0;
+ int end = value.indexOf('.');
+ int numBlocks = 0;
+
+ while (start < value.length()) {
+
+ if (-1 == end) {
+ end = value.length();
+ }
+
+ try {
+ int block = Integer.parseInt(value.substring(start, end));
+ if ((block > 255) || (block < 0)) {
+ Log.w("EthernetIP",
+ "isValidIpAddress() : invalid 'block', block = "+ block);
+ return false;
+ }
+ } catch (NumberFormatException e) {
+ Log.w("EthernetIP", "isValidIpAddress() : e = " + e);
+ return false;
+ }
+
+ numBlocks++;
+
+ start = end + 1;
+ end = value.indexOf('.', start);
+ }
+ return numBlocks == 4;
+ }
+ public void checkIPValue()
+ {
+ boolean enable = false;
+ String ipAddr = mIpAddressView.getText().toString();
+ String gateway = mIPgateway.getText().toString();
+ String dns1 = mdns1.getText().toString();
+ String dns2 = mdns2.getText().toString();
+ String netMask = ipnetmask.getText().toString();
+ 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*/
+ if (isValidIpAddress(ipAddr) && isValidIpAddress(gateway)
+ && isValidIpAddress(dns1) && (pattern.matcher(netMask).matches())) {
+ if (TextUtils.isEmpty(dns2)) { // ???????
+ enable = true;
+ } else {
+ if (isValidIpAddress(dns2)) {
+ enable = true;
+ } else {
+ enable = false;
+ }
+ }
+ } else {
+ enable = false;
+ }
+ getButton(BUTTON_SUBMIT).setEnabled(enable);
+
+ }
+ @Override
+ public void afterTextChanged(Editable s) {
+
+ checkIPValue();
+ Log.e("EthernetStaticDialog", "afterTextChanged");
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count,
+ int after) {
+ // work done in afterTextChanged
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // work done in afterTextChanged
+ }
+}
------------- src/com/android/settings/ethernet/StaticIpInfo.java -------------
new file mode 100755
index 0000000..285d45d
@@ -0,0 +1,57 @@
+package com.android.settings.ethernet;
+
+
+public class StaticIpInfo {
+ public String mEthIpAddress = "192.168.1.1";
+ public String mEthNetmask = "255.255.255.0";
+ public String mEthGateway = "192.168.1.1";
+ public String mEthdns1 = "0.0.0.0";
+ public String mEthdns2 = "0.0.0.0";
+
+ public String getStaticIp(){return mEthIpAddress;};
+ public String getStaticNetMask(){return mEthNetmask;};
+ public String getStaticGateway(){return mEthGateway;};
+ public String getStaticDns1(){return mEthdns1;};
+ public String getStaticDns2(){return mEthdns2;};
+
+
+ public void setStaticIp(String ipAddr){
+ mEthIpAddress = ipAddr;
+ }
+
+ public void setStaticNetMask(String netMask){
+ mEthNetmask = netMask;
+ }
+
+ public void setStaticGateway(String gateway){
+ mEthGateway = gateway;
+ }
+
+ public void setStaticDns1(String dns1){
+ mEthdns1 = dns1;
+ }
+
+ public void setStaticDns2(String dns2){
+ mEthdns2 = dns2;
+ }
+
+
+ }
+
+
+/*
+public interface IStaticIpInfo {
+ public boolean getStaticIp(String ipAddr);
+ public boolean getStaticNetMask(String netMask);
+ public boolean getStaticGateway(String gateway);
+ public boolean getStaticDns1(String dns1);
+ public boolean getStaticDns2(String dns2);
+
+ public boolean setStaticIp(String ipAddr);
+ public boolean setStaticNetMask(String netMask);
+ public boolean setStaticGateway(String gateway);
+ public boolean setStaticDns1(String dns1);
+ public boolean setStaticDns2(String dns2);
+
+}
+*/