OSDN Git Service

merge ethernet settings support to froyo
authorChih-Wei Huang <cwhuang@linux.org.tw>
Tue, 19 Oct 2010 08:04:18 +0000 (16:04 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 26 Nov 2010 05:52:11 +0000 (13:52 +0800)
Change-Id: I1da7d12ae2b9d0f416b067356fd330ea4cd952d2

AndroidManifest.xml
res/drawable-hdpi/ic_settings_ethernet.png [new file with mode: 0644]
res/drawable-mdpi/ic_settings_ethernet.png [new file with mode: 0644]
res/layout/eth_configure.xml [new file with mode: 0644]
res/values/strings.xml
res/xml/ethernet_settings.xml [new file with mode: 0644]
res/xml/settings.xml
src/com/android/settings/EthernetSettings.java [new file with mode: 0644]
src/com/android/settings/ethernet/EthernetConfigDialog.java [new file with mode: 0644]
src/com/android/settings/ethernet/EthernetEnabler.java [new file with mode: 0644]
src/com/android/settings/ethernet/EthernetLayer.java [new file with mode: 0644]

index 7d29849..7d2045f 100644 (file)
                 <category android:name="android.intent.category.DEFAULT" />
             </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 -->
 
diff --git a/res/drawable-hdpi/ic_settings_ethernet.png b/res/drawable-hdpi/ic_settings_ethernet.png
new file mode 100644 (file)
index 0000000..8ce5ee1
Binary files /dev/null and b/res/drawable-hdpi/ic_settings_ethernet.png differ
diff --git a/res/drawable-mdpi/ic_settings_ethernet.png b/res/drawable-mdpi/ic_settings_ethernet.png
new file mode 100644 (file)
index 0000000..7e5f923
Binary files /dev/null and b/res/drawable-mdpi/ic_settings_ethernet.png differ
diff --git a/res/layout/eth_configure.xml b/res/layout/eth_configure.xml
new file mode 100644 (file)
index 0000000..3f8c91f
--- /dev/null
@@ -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>
index e1deff1..1580606 100644 (file)
@@ -2533,4 +2533,23 @@ found in the list of installed applications.</string>
     <string name="softkeyboard_enable_summary">Enable SoftKeyBoard</string>
     <string name="keyboard_layout_title">Keyboard layout setting</string>
     <string name="keyboard_layout_summary">Choose a keyboard layout</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">Default Router</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>
 </resources>
diff --git a/res/xml/ethernet_settings.xml b/res/xml/ethernet_settings.xml
new file mode 100644 (file)
index 0000000..dc3455c
--- /dev/null
@@ -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>
index 8c92870..8aa7fc1 100644 (file)
         </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:key="call_settings"
             settings:icon="@drawable/ic_settings_call"
             android:title="@string/call_settings_title">
diff --git a/src/com/android/settings/EthernetSettings.java b/src/com/android/settings/EthernetSettings.java
new file mode 100644 (file)
index 0000000..6ec5baa
--- /dev/null
@@ -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 (file)
index 0000000..eff876d
--- /dev/null
@@ -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 (file)
index 0000000..d4eaa7e
--- /dev/null
@@ -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 (file)
index 0000000..b712c35
--- /dev/null
@@ -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);
+    }
+}