From c448eacc868779eecbe6cdf901f2e72edf254a3c Mon Sep 17 00:00:00 2001
From: Nicu Pavel <npavel@mini-box.com>
Date: Mon, 20 Jun 2011 13:59:46 +0300
Subject: [PATCH] [picopc] Added Ethernet Settings based on Yi Sun <beyounn@gmail.com> patch from android-x86.org

Change-Id: I6da2c35d6609bdd980a02de9794d7dec43b640dd
---
 AndroidManifest.xml                                |   35 ++++
 res/drawable-hdpi/ic_settings_ethernet.png         |  Bin 0 -> 1576 bytes
 res/drawable-mdpi/ic_settings_ethernet.png         |  Bin 0 -> 946 bytes
 res/layout/eth_configure.xml                       |  112 ++++++++++
 res/values/strings.xml                             |   19 ++
 res/xml/ethernet_settings.xml                      |   31 +++
 res/xml/settings.xml                               |    9 +
 src/com/android/settings/EthernetSettings.java     |   83 ++++++++
 .../settings/ethernet/EthernetConfigDialog.java    |  214 ++++++++++++++++++++
 .../android/settings/ethernet/EthernetEnabler.java |  170 ++++++++++++++++
 .../android/settings/ethernet/EthernetLayer.java   |   68 ++++++
 11 files changed, 741 insertions(+), 0 deletions(-)
 create mode 100644 res/drawable-hdpi/ic_settings_ethernet.png
 create mode 100644 res/drawable-mdpi/ic_settings_ethernet.png
 create mode 100644 res/layout/eth_configure.xml
 create mode 100644 res/xml/ethernet_settings.xml
 create mode 100644 src/com/android/settings/EthernetSettings.java
 create mode 100644 src/com/android/settings/ethernet/EthernetConfigDialog.java
 create mode 100644 src/com/android/settings/ethernet/EthernetEnabler.java
 create mode 100644 src/com/android/settings/ethernet/EthernetLayer.java

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c685613..9056cb9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -71,6 +71,41 @@
             </intent-filter>
         </activity>
 
+         <!-- Ethernet controls -->
+        <activity android:name="EthernetSettings"
+                android:label="@string/eth_radio_ctrl_title"
+                >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <action android:name="android.settings.ETHERNET_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE_LAUNCH" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".ethernet.EthernetEnabler" android:label="@string/eth_setting"
+                android:clearTaskOnLaunch="true"
+                >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <action android:name="android.settings.ETHERNET_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE_LAUNCH" />
+                <category android:name="com.android.settings.SHORTCUT" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".ethernet.EthernetConfigure" android:label="@string/eth_conf_perf_title"
+                android:clearTaskOnLaunch="true"
+                >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <action android:name="android.settings.ETHERNET_SETTINGS" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE_LAUNCH" />
+                <category android:name="com.android.settings.SHORTCUT" />
+            </intent-filter>
+        </activity>
+
         <!-- Wireless Controls -->
 
         <activity android:name="WirelessSettings"
diff --git a/res/drawable-hdpi/ic_settings_ethernet.png b/res/drawable-hdpi/ic_settings_ethernet.png
new file mode 100644
index 0000000000000000000000000000000000000000..8ce5ee18c9d64c4d8ab2a877912e0168dea3ddd8
GIT binary patch
literal 1576
zcmV+@2G{wCP)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm00001b5ch_0Itp)
z=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iXiB
z0|6Ty>ueqX00pQ?L_t(&-tC#ok5okz#(&kfAJan1Fbq&S0Y?Qjh(>{^iQ)zmV_ax7
zCdRmP>(2khgulQTH!fVb#%M73gkTg9K^V9&;4nO9reF8C`HEC7{hV$!CSA$Rt?ubt
z_k8C&=R2orU@|6SGA84{9By0-nb`(lC$JsZ1QfOYdfs6`2DE^iz$xe4rA|LAj>&i@
z!(Rgq0lTzzHlkyj!0*6e;GYAaQ3ZC0g&J@Q_yc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im_u0j^P
z9%6YxZNXLbLyZpGLyKOv0-STsE$h3s40}j_doVIC0BGoUTO_CV32c2m09I8I5seps
zU)0ofI`fGcu*jg247o0C->tT!9<?ilh@tQ~Y$-3PB_Hl&&dl}zuc)N2%4_vp$LV@(
z?n9xfs1+$FmP0q|as_OkT9ri|W}Vmk0&v7RcVbuoQ}X;<!29xAX~?6(;LT$?UHeIn
z$a1ZC1^5tn8~7ghLIrFoB(`&|IqY%aPBVMY%sw--Wz)EP`SMVAjZ0?sv6;PYX0u)1
z_mP<$H?zZLc1UNfBkc!v10MiSsjpcBENsFDsHU+(l~k0bb&_#HEpy1DO4NOZ8d4e+
zKut=qq$+q-Nm*2ty{rFS?iSUM$8|PzKnCv9x*>$h!1FrMNQODp?gbzuU<&-89)2zA
z(cJ*WFN;p=_N%&<qJx5>{$7-`R`mT!u8Upwejw<2RSJ?sG&2N%szA4+w!9f7a$9P1
z12`@9X^sjYR7NlQ_iE8WD7Hu<!x2kO(s)#7pG&!QOa}mGwFe&=z_J$GrK;HNV0I8G
zttf|%>V)IC09Xz{CN|oG{&S>P9hg(H%|u(ue4*-Rc)VF@iGkC=qI0e_`48V@OvYsV
a|Ht1T&&6^D9RL{s0000<MNUMnLSTY1U))gu

literal 0
HcmV?d00001

diff --git a/res/drawable-mdpi/ic_settings_ethernet.png b/res/drawable-mdpi/ic_settings_ethernet.png
new file mode 100644
index 0000000000000000000000000000000000000000..7e5f923402682119d69f855e74e115a48a964afd
GIT binary patch
literal 946
zcmV;j15NyiP)<h;3K|Lk000e1NJLTq001BW001Be1^@s6b9#F800001b5ch_0Itp)
z=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iXiB
z0|YKMFI;#400S~fL_t(o!|m74Yg|<n2k_6Enb@QamM+p<YeLPYLcw2PQNbTeDX!{H
zT&M`5YtcWzZ8z>k1r@h~pe|f!aUnucK}D*?pRIX_F^#pxW+rpooPozUlg!kmx$t<*
zd-t9Dz32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 b/res/layout/eth_configure.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content">
+
+    <LinearLayout
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:padding="8dip"
+            android:orientation="vertical">
+
+            <LinearLayout
+                android:id="@+id/table"
+                android:layout_width="fill_parent"
+                android:layout_height="fill_parent"
+                android:orientation="vertical">
+            </LinearLayout>
+
+       <!-- Device list -->
+
+        <TextView android:id="@+id/eth_dev_list_text"
+                style="?android:attr/textAppearanceSmallInverse"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="8dip"
+                android:text="@string/eth_dev_list" />
+
+        <!-- The entries will be set programmatically -->
+        <Spinner android:id="@+id/eth_dev_spinner"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content" />
+
+        <!-- Connection type -->
+	<TextView android:id="@+id/eth_con_type"
+                style="?android:attr/textAppearanceSmallInverse"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginTop="8dip"
+                android:text="@string/eth_con_type" />
+        <RadioGroup android:id="@+id/con_type"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                >
+                <RadioButton android:id="@+id/dhcp_radio"
+			style="?android:attr/textAppearanceSmallInverse"
+			android:layout_width="fill_parent"
+			android:layout_height="wrap_content"
+			android:text="@string/eth_con_type_dhcp"
+                ></RadioButton>
+                <RadioButton android:id="@+id/manual_radio"
+			style="?android:attr/textAppearanceSmallInverse"
+			android:layout_width="fill_parent"
+			android:layout_height="wrap_content"
+			android:text="@string/eth_con_type_manual"
+                ></RadioButton>
+        </RadioGroup>
+
+        <!-- IP address -->
+        <LinearLayout android:id="@+id/enterprise_wrapper"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:padding="0dip"
+            android:orientation="vertical">
+                <TextView android:id="@+id/ipaddr_text"
+                        style="?android:attr/textAppearanceSmallInverse"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/eth_ipaddr" />
+                <EditText android:id="@+id/ipaddr_edit"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="2dip"
+                        android:singleLine="true" />
+                <TextView android:id="@+id/netmask_text"
+                        style="?android:attr/textAppearanceSmallInverse"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/eth_mask" />
+                <EditText android:id="@+id/netmask_edit"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="2dip"
+                        android:singleLine="true" />
+                <TextView android:id="@+id/dns_text"
+                        style="?android:attr/textAppearanceSmallInverse"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/eth_dns" />
+                <EditText android:id="@+id/eth_dns_edit"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="2dip"
+                        android:singleLine="true" />
+                <TextView android:id="@+id/gw_text"
+                        style="?android:attr/textAppearanceSmallInverse"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="8dip"
+                        android:text="@string/eth_gw" />
+                <EditText android:id="@+id/eth_gw_edit"
+                        android:layout_width="fill_parent"
+                        android:layout_height="wrap_content"
+                        android:layout_marginTop="2dip"
+                        android:singleLine="true" />
+        </LinearLayout>
+
+    </LinearLayout>
+
+</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a8059c6..d24dd05 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -788,6 +788,25 @@
     <string name="nfc_quick_toggle_summary">Use Near Field Communication to read and exchange tags</string>
     <string name="nfc_toggle_error" msgid="8998642457947607263">An error occurred.</string>
 
+    <!-- Ethernet configuration dialog -->
+    <string name="eth_config_title">Configure Ethernet device</string>
+    <string name="eth_setting">Ethernet setting</string>
+    <string name="eth_dev_list">Ethernet Devices:</string>
+    <string name="eth_con_type">Connection Type</string>
+    <string name="eth_con_type_dhcp">DHCP</string>
+    <string name="eth_con_type_manual">Static IP</string>
+    <string name="eth_dns">DNS address</string>
+    <string name="eth_gw">Gateway address</string>
+    <string name="eth_ipaddr">IP address</string>
+    <string name="eth_quick_toggle_title">Ethernet</string>
+    <string name="eth_quick_toggle_summary">Turn on Ethernet</string>
+    <string name="eth_radio_ctrl_title">Ethernet configuration</string>
+    <string name="eth_conf_perf_title">Ethernet configuration</string>
+    <string name="eth_conf_summary">Configure Ethernet devices</string>
+    <string name="eth_mask">Netmask</string>
+    <string name="eth_toggle_summary_off">Turn off Ethernet</string>
+    <string name="eth_toggle_summary_on">Turn on Ethernet</string>
+
     <!-- Wi-Fi Settings --> <skip />
     <!-- Used in the 1st-level settings screen to turn on Wi-Fi -->
     <string name="wifi_quick_toggle_title">Wi-Fi</string>
diff --git a/res/xml/ethernet_settings.xml b/res/xml/ethernet_settings.xml
new file mode 100644
index 0000000..dc3455c
--- /dev/null
+++ b/res/xml/ethernet_settings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        android:title="@string/eth_radio_ctrl_title">
+        <!-- Programmatically will have dynamic summary, but we provide the fallback summary. -->
+        <CheckBoxPreference
+            android:key="toggle_eth"
+            android:title="@string/eth_quick_toggle_title"
+            android:summaryOn="@string/eth_toggle_summary_off"
+            android:summaryOff="@string/eth_toggle_summary_on"
+            android:persistent="false" />
+        <Preference
+            android:title="@string/eth_conf_perf_title"
+            android:summary="@string/eth_conf_summary"
+            android:key="ETHERNET_config"
+            android:persistent="false" />
+</PreferenceScreen>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
index 6ddbf7c..041e562 100644
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -35,6 +35,15 @@
         </com.android.settings.IconPreferenceScreen>
 
         <com.android.settings.IconPreferenceScreen
+             android:title="@string/eth_radio_ctrl_title"
+            settings:icon="@drawable/ic_settings_ethernet">
+            <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.EthernetSettings" />
+        </com.android.settings.IconPreferenceScreen>
+
+        <com.android.settings.IconPreferenceScreen
             android:title="@string/radio_controls_title"
             settings:icon="@drawable/ic_settings_wireless">
             <intent
diff --git a/src/com/android/settings/EthernetSettings.java b/src/com/android/settings/EthernetSettings.java
new file mode 100644
index 0000000..6ec5baa
--- /dev/null
+++ b/src/com/android/settings/EthernetSettings.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2010 The Android-x86 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.
+ *
+ * Author: Yi Sun <beyounn@gmail.com>
+ */
+
+package com.android.settings;
+
+import com.android.settings.R;
+import com.android.settings.ethernet.EthernetConfigDialog;
+import com.android.settings.ethernet.EthernetEnabler;
+
+import android.net.ethernet.EthernetManager;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+
+public class EthernetSettings extends PreferenceActivity {
+    private static final String KEY_TOGGLE_ETH = "toggle_eth";
+    private static final String KEY_CONF_ETH = "ETHERNET_config";
+    private EthernetEnabler mEthEnabler;
+    private EthernetConfigDialog mEthConfigDialog;
+    private Preference mEthConfigPref;
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        super.onPreferenceTreeClick(preferenceScreen, preference);
+
+        if (preference == mEthConfigPref) {
+            mEthConfigDialog.show();
+        }
+        return false;
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        addPreferencesFromResource(R.xml.ethernet_settings);
+        final PreferenceScreen preferenceScreen = getPreferenceScreen();
+        mEthConfigPref = preferenceScreen.findPreference(KEY_CONF_ETH);
+        /*
+         * TO DO:
+         * Add new perference screen for Etherenet Configuration
+         */
+
+        initToggles();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mEthEnabler.resume();
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        mEthEnabler.pause();
+    }
+
+    private void initToggles() {
+        mEthEnabler = new EthernetEnabler(this,
+                (EthernetManager) getSystemService(ETHERNET_SERVICE),
+                (CheckBoxPreference) findPreference(KEY_TOGGLE_ETH));
+        mEthConfigDialog = new EthernetConfigDialog(this, mEthEnabler);
+        mEthEnabler.setConfigDialog(mEthConfigDialog);
+    }
+}
diff --git a/src/com/android/settings/ethernet/EthernetConfigDialog.java b/src/com/android/settings/ethernet/EthernetConfigDialog.java
new file mode 100644
index 0000000..eff876d
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetConfigDialog.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2010 The Android-x86 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.
+ *
+ * Author: Yi Sun <beyounn@gmail.com>
+ */
+
+package com.android.settings.ethernet;
+
+
+import java.util.List;
+
+import com.android.settings.R;
+
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.NetworkInfo;
+import android.net.ethernet.EthernetManager;
+import android.net.ethernet.EthernetDevInfo;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.util.Slog;
+
+public class EthernetConfigDialog extends AlertDialog implements
+        DialogInterface.OnClickListener, AdapterView.OnItemSelectedListener, View.OnClickListener {
+    private final String TAG = "EtherenetSettings";
+    private static final boolean localLOGV = false;
+
+    private EthernetEnabler mEthEnabler;
+    private View mView;
+    private Spinner mDevList;
+    private TextView mDevs;
+    private RadioButton mConTypeDhcp;
+    private RadioButton mConTypeManual;
+    private EditText mIpaddr;
+    private EditText mDns;
+    private EditText mGw;
+    private EditText mMask;
+
+    private EthernetLayer mEthLayer;
+    private EthernetManager mEthManager;
+    private EthernetDevInfo mEthInfo;
+    private boolean mEnablePending;
+
+    public EthernetConfigDialog(Context context, EthernetEnabler Enabler) {
+        super(context);
+        mEthLayer = new EthernetLayer(this);
+        mEthEnabler = Enabler;
+        mEthManager=Enabler.getManager();
+        buildDialogContent(context);
+    }
+
+    public int buildDialogContent(Context context) {
+        this.setTitle(R.string.eth_config_title);
+        this.setView(mView = getLayoutInflater().inflate(R.layout.eth_configure, null));
+        mDevs = (TextView) mView.findViewById(R.id.eth_dev_list_text);
+        mDevList = (Spinner) mView.findViewById(R.id.eth_dev_spinner);
+        mConTypeDhcp = (RadioButton) mView.findViewById(R.id.dhcp_radio);
+        mConTypeManual = (RadioButton) mView.findViewById(R.id.manual_radio);
+        mIpaddr = (EditText)mView.findViewById(R.id.ipaddr_edit);
+        mMask = (EditText)mView.findViewById(R.id.netmask_edit);
+        mDns = (EditText)mView.findViewById(R.id.eth_dns_edit);
+        mGw = (EditText)mView.findViewById(R.id.eth_gw_edit);
+
+        mConTypeDhcp.setChecked(true);
+        mConTypeManual.setChecked(false);
+        mIpaddr.setEnabled(false);
+        mMask.setEnabled(false);
+        mDns.setEnabled(false);
+        mGw.setEnabled(false);
+        mConTypeManual.setOnClickListener(new RadioButton.OnClickListener() {
+            public void onClick(View v) {
+                mIpaddr.setEnabled(true);
+                mDns.setEnabled(true);
+                mGw.setEnabled(true);
+                mMask.setEnabled(true);
+            }
+        });
+
+        mConTypeDhcp.setOnClickListener(new RadioButton.OnClickListener() {
+            public void onClick(View v) {
+                mIpaddr.setEnabled(false);
+                mDns.setEnabled(false);
+                mGw.setEnabled(false);
+                mMask.setEnabled(false);
+            }
+        });
+
+        this.setInverseBackgroundForced(true);
+        this.setButton(BUTTON_POSITIVE, context.getText(R.string.menu_save), this);
+        this.setButton(BUTTON_NEGATIVE, context.getText(R.string.menu_cancel), this);
+        String[] Devs = mEthEnabler.getManager().getDeviceNameList();
+        if (Devs != null) {
+            if (localLOGV)
+                Slog.v(TAG, "found device: " + Devs[0]);
+            updateDevNameList(Devs);
+            if (mEthManager.isConfigured()) {
+                mEthInfo = mEthManager.getSavedConfig();
+                for (int i = 0 ; i < Devs.length; i++) {
+                    if (Devs[i].equals(mEthInfo.getIfName())) {
+                        mDevList.setSelection(i);
+                        break;
+                    }
+                }
+                mIpaddr.setText(mEthInfo.getIpAddress());
+                mGw.setText(mEthInfo.getRouteAddr());
+                mDns.setText(mEthInfo.getDnsAddr());
+                mMask.setText(mEthInfo.getNetMask());
+                if (mEthInfo.getConnectMode().equals(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP)) {
+                    mIpaddr.setEnabled(false);
+                    mDns.setEnabled(false);
+                    mGw.setEnabled(false);
+                    mMask.setEnabled(false);
+                } else {
+                    mConTypeDhcp.setChecked(false);
+                    mConTypeManual.setChecked(true);
+                    mIpaddr.setEnabled(true);
+                    mDns.setEnabled(true);
+                    mGw.setEnabled(true);
+                    mMask.setEnabled(true);
+                }
+            }
+        }
+        return 0;
+    }
+
+    private void handle_saveconf() {
+        EthernetDevInfo info = new EthernetDevInfo();
+        info.setIfName(mDevList.getSelectedItem().toString());
+        if (localLOGV)
+            Slog.v(TAG, "Config device for " + mDevList.getSelectedItem().toString());
+        if (mConTypeDhcp.isChecked()) {
+            info.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP);
+            info.setIpAddress(null);
+            info.setRouteAddr(null);
+            info.setDnsAddr(null);
+            info.setNetMask(null);
+        } else {
+            info.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_MANUAL);
+            info.setIpAddress(mIpaddr.getText().toString());
+            info.setRouteAddr(mGw.getText().toString());
+            info.setDnsAddr(mDns.getText().toString());
+            info.setNetMask(mMask.getText().toString());
+        }
+        mEthManager.updateDevInfo(info);
+        if (mEnablePending) {
+            mEthManager.setEnabled(true);
+            mEnablePending = false;
+        }
+    }
+
+    public void onClick(DialogInterface dialog, int which) {
+        switch (which) {
+            case BUTTON_POSITIVE:
+                handle_saveconf();
+                break;
+            case BUTTON_NEGATIVE:
+                //Don't need to do anything
+                break;
+            default:
+                Slog.e(TAG,"Unknow button");
+        }
+    }
+
+    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+
+    }
+
+    public void onNothingSelected(AdapterView<?> parent) {
+
+    }
+
+    public void onClick(View v) {
+
+    }
+
+    public void updateDevNameList(String[] DevList) {
+        if (DevList != null) {
+            ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
+                    getContext(), android.R.layout.simple_spinner_item, DevList);
+            adapter.setDropDownViewResource(
+                    android.R.layout.simple_spinner_dropdown_item);
+            mDevList.setAdapter(adapter);
+        }
+
+    }
+
+    public void enableAfterConfig() {
+        mEnablePending = true;
+    }
+}
diff --git a/src/com/android/settings/ethernet/EthernetEnabler.java b/src/com/android/settings/ethernet/EthernetEnabler.java
new file mode 100644
index 0000000..d4eaa7e
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetEnabler.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2010 The Android-x86 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.
+ *
+ * Author: Yi Sun <beyounn@gmail.com>
+ */
+
+package com.android.settings.ethernet;
+
+
+import static android.net.ethernet.EthernetManager.ETHERNET_STATE_DISABLED;
+import static android.net.ethernet.EthernetManager.ETHERNET_STATE_ENABLED;
+import static android.net.ethernet.EthernetManager.ETHERNET_STATE_UNKNOWN;
+
+import com.android.settings.R;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.NetworkInfo;
+import android.net.ethernet.EthernetManager;
+import android.preference.Preference;
+import android.preference.CheckBoxPreference;
+import android.text.TextUtils;
+import android.util.Config;
+import android.util.Slog;
+
+public class EthernetEnabler implements Preference.OnPreferenceChangeListener {
+    private static final boolean LOCAL_LOGD = true;
+    private static final String TAG = "SettingsEthEnabler";
+    //private final IntentFilter mEthStateFilter;
+    private Context mContext;
+    private EthernetManager mEthManager;
+    private CheckBoxPreference mEthCheckBoxPref;
+    private final CharSequence mOriginalSummary;
+    private EthernetConfigDialog mEthConfigDialog;
+
+    private final BroadcastReceiver mEthStateReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(EthernetManager.ETHERNET_STATE_CHANGED_ACTION)) {
+                handleEthStateChanged(
+                        intent.getIntExtra(EthernetManager.EXTRA_ETHERNET_STATE,
+                                EthernetManager.ETHERNET_STATE_UNKNOWN),
+                        intent.getIntExtra(EthernetManager.EXTRA_PREVIOUS_ETHERNET_STATE,
+                                EthernetManager.ETHERNET_STATE_UNKNOWN));
+            } else if (intent.getAction().equals(EthernetManager.NETWORK_STATE_CHANGED_ACTION)) {
+                handleNetworkStateChanged(
+                        (NetworkInfo) intent.getParcelableExtra(EthernetManager.EXTRA_NETWORK_INFO));
+            }
+        }
+    };
+
+    public void setConfigDialog (EthernetConfigDialog Dialog) {
+        mEthConfigDialog = Dialog;
+    }
+
+    public EthernetEnabler(Context context, EthernetManager ethernetManager, CheckBoxPreference ethernetCheckBoxPreference) {
+        mContext = context;
+        mEthCheckBoxPref = ethernetCheckBoxPreference;
+        mEthManager = ethernetManager;
+
+        mOriginalSummary = ethernetCheckBoxPreference.getSummary();
+        ethernetCheckBoxPreference.setPersistent(false);
+        if (mEthManager.getState() == ETHERNET_STATE_ENABLED) {
+            mEthCheckBoxPref.setChecked(true);
+        }
+
+        /*
+        mEthStateFilter = new IntentFilter(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);
+        mEthStateFilter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION);
+        */
+    }
+
+    public EthernetManager getManager() {
+        return mEthManager;
+    }
+
+    public void resume() {
+        mEthCheckBoxPref.setOnPreferenceChangeListener(this);
+    }
+
+    public void pause() {
+        //  mContext.unregisterReceiver(mEthStateReceiver);
+        mEthCheckBoxPref.setOnPreferenceChangeListener(null);
+    }
+
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        setEthEnabled((Boolean)newValue);
+        return false;
+    }
+
+    private void setEthEnabled(final boolean enable) {
+
+        int state = mEthManager.getState();
+
+        Slog.i(TAG,"Show configuration dialog " + enable);
+        // Disable button
+        mEthCheckBoxPref.setEnabled(false);
+
+        if (state != ETHERNET_STATE_ENABLED && enable) {
+            if (mEthManager.isConfigured() != true) {
+                // Now, kick off the setting dialog to get the configurations
+                mEthConfigDialog.enableAfterConfig();
+                mEthConfigDialog.show();
+            } else {
+                mEthManager.setEnabled(enable);
+            }
+        } else {
+            mEthManager.setEnabled(enable);
+        }
+
+        mEthCheckBoxPref.setChecked(enable);
+        // Disable button
+        mEthCheckBoxPref.setEnabled(true);
+    }
+
+    private void handleEthStateChanged(int ethState, int previousEthState) {
+
+    }
+
+    private void handleNetworkStateChanged(NetworkInfo networkInfo) {
+        if (LOCAL_LOGD) {
+            Slog.d(TAG, "Received network state changed to " + networkInfo);
+        }
+    }
+
+    private boolean isEnabledByDependency() {
+        Preference dep = getDependencyPreference();
+        if (dep == null) {
+            return true;
+        }
+
+        return !dep.shouldDisableDependents();
+    }
+
+    private Preference getDependencyPreference() {
+        String depKey = mEthCheckBoxPref.getDependency();
+        if (TextUtils.isEmpty(depKey)) {
+            return null;
+        }
+
+        return mEthCheckBoxPref.getPreferenceManager().findPreference(depKey);
+    }
+
+    private static String getHumanReadableEthState(int wifiState) {
+        switch (wifiState) {
+            case ETHERNET_STATE_DISABLED:
+                return "Disabled";
+            case ETHERNET_STATE_ENABLED:
+                return "Enabled";
+            case ETHERNET_STATE_UNKNOWN:
+                return "Unknown";
+            default:
+                return "Some other state!";
+        }
+    }
+}
diff --git a/src/com/android/settings/ethernet/EthernetLayer.java b/src/com/android/settings/ethernet/EthernetLayer.java
new file mode 100644
index 0000000..b712c35
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetLayer.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 The Android-x86 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.
+ *
+ * Author: Yi Sun <beyounn@gmail.com>
+ */
+
+package com.android.settings.ethernet;
+
+import static android.net.ethernet.EthernetManager.ETHERNET_DEVICE_SCAN_RESULT_READY;
+
+import com.android.settings.R;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkInfo.State;
+import android.net.ethernet.EthernetManager;
+import android.os.Handler;
+import android.os.Message;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.Config;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class EthernetLayer {
+    private static final String TAG = "EthernetLayer";
+
+    private EthernetManager mEthManager;
+    private String[] mDevList;
+    private EthernetConfigDialog mDialog;
+
+    EthernetLayer (EthernetConfigDialog configdialog) {
+        mDialog = configdialog;
+    }
+
+    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (action.equals(EthernetManager.ETHERNET_DEVICE_SCAN_RESULT_READY)) {
+                handleDevListChanges();
+            }
+        }
+    };
+
+    private void handleDevListChanges() {
+        mDevList = mEthManager.getDeviceNameList();
+        mDialog.updateDevNameList(mDevList);
+    }
+}
-- 
1.7.1


