• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Révision76bac9ff0eeb22204495283c796306298da11b36 (tree)
l'heure2009-09-05 04:18:04
AuteurYi SUn <beyounn@gmai...>
CommiterChih-Wei Huang

Message de Log

initial commit for ethenet state tracker works

Change Summary

Modification

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -61,6 +61,43 @@
6161 </intent-filter>
6262 </activity>
6363
64+ <!-- Etherent controls -->
65+ <activity android:name="EthernetSettings"
66+ android:label="@string/eth_radio_ctrl_title"
67+ >
68+ <intent-filter>
69+ <action android:name="android.intent.action.MAIN" />
70+ <action android:name="android.settings.ETHERNET_SETTINGS" />
71+ <category android:name="android.intent.category.DEFAULT" />
72+ <category android:name="android.intent.category.VOICE_LAUNCH" />
73+ </intent-filter>
74+ </activity>
75+
76+ <activity android:name=".ethernet.EthernetEnabler" android:label="@string/eth_setting"
77+ android:clearTaskOnLaunch="true"
78+ >
79+ <intent-filter>
80+ <action android:name="android.intent.action.MAIN" />
81+ <action android:name="android.settings.ETHERNET_SETTINGS" />
82+ <category android:name="android.intent.category.DEFAULT" />
83+ <category android:name="android.intent.category.VOICE_LAUNCH" />
84+ <category android:name="com.android.settings.SHORTCUT" />
85+ </intent-filter>
86+ </activity>
87+ <activity android:name=".ethernet.EthernetConfigure" android:label="@string/eth_conf_perf_title"
88+ android:clearTaskOnLaunch="true"
89+ >
90+ <intent-filter>
91+ <action android:name="android.intent.action.MAIN" />
92+ <action android:name="android.settings.ETHERNET_SETTINGS" />
93+ <category android:name="android.intent.category.DEFAULT" />
94+ <category android:name="android.intent.category.VOICE_LAUNCH" />
95+ <category android:name="com.android.settings.SHORTCUT" />
96+ </intent-filter>
97+ </activity>
98+
99+
100+
64101 <!-- Wireless Controls -->
65102
66103 <activity android:name="WirelessSettings"
--- /dev/null
+++ b/res/layout/eth_configure.xml
@@ -0,0 +1,112 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+ android:layout_width="fill_parent"
4+ android:layout_height="wrap_content">
5+
6+ <LinearLayout
7+ android:layout_width="fill_parent"
8+ android:layout_height="wrap_content"
9+ android:padding="8dip"
10+ android:orientation="vertical">
11+
12+ <LinearLayout
13+ android:id="@+id/table"
14+ android:layout_width="fill_parent"
15+ android:layout_height="fill_parent"
16+ android:orientation="vertical">
17+ </LinearLayout>
18+
19+ <!-- Device list -->
20+
21+ <TextView android:id="@+id/eth_dev_list_text"
22+ style="?android:attr/textAppearanceSmallInverse"
23+ android:layout_width="fill_parent"
24+ android:layout_height="wrap_content"
25+ android:layout_marginTop="8dip"
26+ android:text="@string/eth_dev_list" />
27+
28+ <!-- The entries will be set programmatically -->
29+ <Spinner android:id="@+id/eth_dev_spinner"
30+ android:layout_width="fill_parent"
31+ android:layout_height="wrap_content" />
32+
33+ <!-- Connection type -->
34+ <TextView android:id="@+id/eth_con_type"
35+ style="?android:attr/textAppearanceSmallInverse"
36+ android:layout_width="fill_parent"
37+ android:layout_height="wrap_content"
38+ android:layout_marginTop="8dip"
39+ android:text="@string/eth_con_type" />
40+ <RadioGroup android:id="@+id/con_type"
41+ android:layout_width="fill_parent"
42+ android:layout_height="wrap_content"
43+ >
44+ <RadioButton android:id="@+id/dhcp_radio"
45+ style="?android:attr/textAppearanceSmallInverse"
46+ android:layout_width="fill_parent"
47+ android:layout_height="wrap_content"
48+ android:text="@string/eth_con_type_dhcp"
49+ ></RadioButton>
50+ <RadioButton android:id="@+id/manual_radio"
51+ style="?android:attr/textAppearanceSmallInverse"
52+ android:layout_width="fill_parent"
53+ android:layout_height="wrap_content"
54+ android:text="@string/eth_con_type_manual"
55+ ></RadioButton>
56+ </RadioGroup>
57+
58+ <!-- IP address -->
59+ <LinearLayout android:id="@+id/enterprise_wrapper"
60+ android:layout_width="fill_parent"
61+ android:layout_height="wrap_content"
62+ android:padding="0dip"
63+ android:orientation="vertical">
64+ <TextView android:id="@+id/ipaddr_text"
65+ style="?android:attr/textAppearanceSmallInverse"
66+ android:layout_width="fill_parent"
67+ android:layout_height="wrap_content"
68+ android:layout_marginTop="8dip"
69+ android:text="@string/eth_ipaddr" />
70+ <EditText android:id="@+id/ipaddr_edit"
71+ android:layout_width="fill_parent"
72+ android:layout_height="wrap_content"
73+ android:layout_marginTop="2dip"
74+ android:singleLine="true" />
75+ <TextView android:id="@+id/netmask_text"
76+ style="?android:attr/textAppearanceSmallInverse"
77+ android:layout_width="fill_parent"
78+ android:layout_height="wrap_content"
79+ android:layout_marginTop="8dip"
80+ android:text="@string/eth_mask" />
81+ <EditText android:id="@+id/netmask_edit"
82+ android:layout_width="fill_parent"
83+ android:layout_height="wrap_content"
84+ android:layout_marginTop="2dip"
85+ android:singleLine="true" />
86+ <TextView android:id="@+id/dns_text"
87+ style="?android:attr/textAppearanceSmallInverse"
88+ android:layout_width="fill_parent"
89+ android:layout_height="wrap_content"
90+ android:layout_marginTop="8dip"
91+ android:text="@string/eth_dns" />
92+ <EditText android:id="@+id/eth_dns_edit"
93+ android:layout_width="fill_parent"
94+ android:layout_height="wrap_content"
95+ android:layout_marginTop="2dip"
96+ android:singleLine="true" />
97+ <TextView android:id="@+id/gw_text"
98+ style="?android:attr/textAppearanceSmallInverse"
99+ android:layout_width="fill_parent"
100+ android:layout_height="wrap_content"
101+ android:layout_marginTop="8dip"
102+ android:text="@string/eth_gw" />
103+ <EditText android:id="@+id/eth_gw_edit"
104+ android:layout_width="fill_parent"
105+ android:layout_height="wrap_content"
106+ android:layout_marginTop="2dip"
107+ android:singleLine="true" />
108+ </LinearLayout>
109+
110+ </LinearLayout>
111+
112+</ScrollView>
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2014,4 +2014,23 @@ found in the list of installed applications.</string>
20142014 <string name="emergency_tone_title">Emergency tone</string>
20152015 <!-- Sound settings screen, setting option summary text -->
20162016 <string name="emergency_tone_summary">Set behavior when an emergency call is placed</string>
2017+ <!-- Ethernet configuration dialog -->
2018+ <string name="eth_config_title">Configure Ethernet Device</string>
2019+ <string name="eth_setting">Ethernnt Setting</string>
2020+<string name="eth_dev_list">Ethernet Devices:</string>
2021+<string name="eth_con_type">Connection Type</string>
2022+<string name="eth_con_type_dhcp">Dhcp</string>
2023+<string name="eth_con_type_manual">Manual</string>
2024+<string name="eth_dns">DNS address</string>
2025+<string name="eth_gw">Default Router</string>
2026+<string name="eth_ipaddr">IP address</string>
2027+<string name="eth_quick_toggle_title">Toggle Ethernet</string>
2028+<string name="eth_quick_toggle_summary">Toggle Ethernet Configuration</string>
2029+<string name="eth_conf_save">Save</string>
2030+<string name="eth_conf_cancel">Cancel</string>
2031+<string name="eth_radio_ctrl_title">Ethernet Configuration</string>
2032+<string name="eth_radio_ctrl_summary">Configure Ethernet devices</string>
2033+<string name="eth_conf_perf_title">Ethernet Configuration</string>
2034+<string name="eth_conf_summary">Configure Ethernet Devices</string>
2035+<string name="eth_mask">Netmask</string>
20172036 </resources>
--- /dev/null
+++ b/res/xml/ethernet_settings.xml
@@ -0,0 +1,30 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (C) 2008 The Android Open Source Project
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+
17+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
18+ android:title="@string/eth_radio_ctrl_title">
19+ <!-- Programmatically will have dynamic summary, but we provide the fallback summary. -->
20+ <CheckBoxPreference
21+ android:key="toggle_eth"
22+ android:title="@string/eth_quick_toggle_title"
23+ android:summary="@string/eth_quick_toggle_summary"
24+ android:persistent="false" />
25+ <Preference
26+ android:title="@string/eth_conf_perf_title"
27+ android:summary="@string/eth_conf_summary"
28+ android:key="eth_config"
29+ android:persistent="false" />
30+</PreferenceScreen>
--- a/res/xml/settings.xml
+++ b/res/xml/settings.xml
@@ -29,6 +29,15 @@
2929 </PreferenceScreen>
3030
3131 <PreferenceScreen
32+ android:title="@string/eth_radio_ctrl_title"
33+ android:summary="@string/eth_radio_ctrl_summary">
34+ <intent
35+ android:action="android.intent.action.MAIN"
36+ android:targetPackage="com.android.settings"
37+ android:targetClass="com.android.settings.EthernetSettings" />
38+ </PreferenceScreen>
39+
40+ <PreferenceScreen
3241 android:key="call_settings"
3342 android:title="@string/call_settings_title"
3443 android:summary="@string/call_settings_summary">
--- /dev/null
+++ b/src/com/android/settings/EthernetSettings.java
@@ -0,0 +1,66 @@
1+package com.android.settings;
2+
3+import com.android.settings.R;
4+import com.android.settings.ethernet.EthernetConfigDialog;
5+import com.android.settings.ethernet.EthernetEnabler;
6+
7+import android.net.ethernet.EthernetManager;
8+import android.os.Bundle;
9+import android.preference.CheckBoxPreference;
10+import android.preference.Preference;
11+import android.preference.PreferenceActivity;
12+import android.preference.PreferenceScreen;
13+
14+public class EthernetSettings extends PreferenceActivity {
15+ private static final String KEY_TOGGLE_ETH = "toggle_eth";
16+ private static final String KEY_CONF_ETH = "eth_config";
17+ private EthernetEnabler mEthEnabler;
18+ private EthernetConfigDialog mEthConfigDialog;
19+ private Preference mEthConfigPref;
20+
21+ @Override
22+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
23+ super.onPreferenceTreeClick(preferenceScreen, preference);
24+
25+ if (preference == mEthConfigPref) {
26+ mEthConfigDialog.show();
27+ }
28+ return false;
29+ }
30+
31+ @Override
32+ protected void onCreate(Bundle savedInstanceState) {
33+ super.onCreate(savedInstanceState);
34+
35+ addPreferencesFromResource(R.xml.ethernet_settings);
36+ final PreferenceScreen preferenceScreen = getPreferenceScreen();
37+ mEthConfigPref = preferenceScreen.findPreference(KEY_CONF_ETH);
38+ /*
39+ * TO DO:
40+ * Add new perference screen for Etherenet Configuration
41+ */
42+
43+ initToggles();
44+ }
45+ @Override
46+ protected void onResume() {
47+ super.onResume();
48+
49+ mEthEnabler.resume();
50+ }
51+
52+ @Override
53+ protected void onPause() {
54+ super.onPause();
55+ mEthEnabler.pause();
56+ }
57+ private void initToggles() {
58+
59+ mEthEnabler = new EthernetEnabler(
60+ this,
61+ (EthernetManager) getSystemService(ETH_SERVICE),
62+ (CheckBoxPreference) findPreference(KEY_TOGGLE_ETH));
63+ mEthConfigDialog = new EthernetConfigDialog(this, mEthEnabler);
64+ mEthEnabler.setConfigDialog(mEthConfigDialog);
65+ }
66+}
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetConfigDialog.java
@@ -0,0 +1,206 @@
1+package com.android.settings.ethernet;
2+
3+
4+import java.util.List;
5+
6+import com.android.settings.R;
7+
8+import android.app.AlertDialog;
9+import android.content.BroadcastReceiver;
10+import android.content.Context;
11+import android.content.DialogInterface;
12+import android.content.Intent;
13+import android.net.NetworkInfo;
14+import android.net.ethernet.EthernetManager;
15+import android.net.ethernet.EthernetDevInfo;
16+import android.os.Bundle;
17+import android.view.View;
18+import android.view.ViewGroup;
19+import android.widget.AdapterView;
20+import android.widget.ArrayAdapter;
21+import android.widget.CheckBox;
22+import android.widget.EditText;
23+import android.widget.RadioButton;
24+import android.widget.RadioGroup;
25+import android.widget.Spinner;
26+import android.widget.TextView;
27+import android.util.Log;
28+
29+public class EthernetConfigDialog extends AlertDialog implements DialogInterface.OnClickListener,
30+AdapterView.OnItemSelectedListener, View.OnClickListener{
31+ private final String TAG = "EtherenetSettings";
32+ private EthernetEnabler mEthEnabler;
33+ private View mView;
34+ private Spinner mDevList;
35+ private TextView mDevs;
36+ private RadioButton mConTypeDhcp;
37+ private RadioButton mConTypeManual;
38+ private EditText mIpaddr;
39+ private EditText mDns;
40+ private EditText mGw;
41+ private EditText mMask;
42+
43+ private EthernetLayer mEthLayer;
44+ private EthernetManager mEthManager;
45+ private EthernetDevInfo mEthInfo;
46+ private boolean mEnablePending;
47+
48+ public EthernetConfigDialog(Context context, EthernetEnabler Enabler) {
49+ super(context);
50+ mEthLayer = new EthernetLayer(this);
51+ mEthEnabler = Enabler;
52+ mEthManager=Enabler.getManager();
53+ buildDialogContent(context);
54+
55+ }
56+
57+ public int buildDialogContent(Context context) {
58+ this.setTitle(R.string.eth_config_title);
59+ this.setView(mView = getLayoutInflater().inflate(R.layout.eth_configure, null));
60+ mDevs = (TextView) mView.findViewById(R.id.eth_dev_list_text);
61+ mDevList = (Spinner) mView.findViewById(R.id.eth_dev_spinner);
62+ mConTypeDhcp = (RadioButton) mView.findViewById(R.id.dhcp_radio);
63+ mConTypeManual = (RadioButton) mView.findViewById(R.id.manual_radio);
64+ mIpaddr = (EditText)mView.findViewById(R.id.ipaddr_edit);
65+ mMask = (EditText)mView.findViewById(R.id.netmask_edit);
66+ mDns = (EditText)mView.findViewById(R.id.eth_dns_edit);
67+ mGw = (EditText)mView.findViewById(R.id.eth_gw_edit);
68+
69+ mConTypeDhcp.setChecked(true);
70+ mConTypeManual.setChecked(false);
71+ mIpaddr.setEnabled(false);
72+ mMask.setEnabled(false);
73+ mDns.setEnabled(false);
74+ mGw.setEnabled(false);
75+ mConTypeManual.setOnClickListener(new RadioButton.OnClickListener() {
76+ public void onClick(View v) {
77+ mIpaddr.setEnabled(true);
78+ mDns.setEnabled(true);
79+ mGw.setEnabled(true);
80+ mMask.setEnabled(true);
81+ }
82+ });
83+
84+ mConTypeDhcp.setOnClickListener(new RadioButton.OnClickListener() {
85+ public void onClick(View v) {
86+ mIpaddr.setEnabled(false);
87+ mDns.setEnabled(false);
88+ mGw.setEnabled(false);
89+ mMask.setEnabled(false);
90+ }
91+ });
92+
93+ this.setInverseBackgroundForced(true);
94+ this.setButton(BUTTON_POSITIVE, context.getText(R.string.eth_conf_save), this);
95+ this.setButton(BUTTON_NEGATIVE, context.getText(R.string.eth_conf_cancel), this);
96+ String[] Devs = mEthEnabler.getManager().getDeviceNameList();
97+ if (Devs != null) {
98+ Log.i(TAG,"found device: " + Devs[0]);
99+ updateDevNameList(Devs);
100+ if (mEthManager.isEthConfigured()) {
101+ mEthInfo = mEthManager.getSavedEthConfig();
102+ for (int i = 0 ; i < Devs.length; i++) {
103+ if (Devs[i].equals(mEthInfo.getIfName())) {
104+ mDevList.setSelection(i);
105+ break;
106+ }
107+ }
108+
109+ mIpaddr.setText(mEthInfo.getIpAddress());
110+ mGw.setText(mEthInfo.getRouteAddr());
111+ mDns.setText(mEthInfo.getDnsAddr());
112+ if (mEthInfo.getConnectMode().equals(EthernetDevInfo.ETH_CONN_MODE_DHCP))
113+ {
114+ mIpaddr.setEnabled(false);
115+ mDns.setEnabled(false);
116+ mGw.setEnabled(false);
117+ mMask.setEnabled(false);
118+ } else {
119+ mConTypeDhcp.setChecked(false);
120+ mConTypeManual.setChecked(true);
121+ mIpaddr.setEnabled(true);
122+ mDns.setEnabled(true);
123+ mGw.setEnabled(true);
124+ mMask.setEnabled(true);
125+ }
126+ }
127+ }
128+
129+
130+ return 0;
131+ }
132+
133+
134+ private void handle_saveconf() {
135+ EthernetDevInfo info = new EthernetDevInfo();
136+ info.setIfName(mDevList.getSelectedItem().toString());
137+ Log.i(TAG, "Config device for " + mDevList.getSelectedItem().toString());
138+ if (mConTypeDhcp.isChecked()) {
139+ Log.i(TAG,"mode dhcp");
140+ info.setConnectMode(EthernetDevInfo.ETH_CONN_MODE_DHCP);
141+ info.setIpAddress(null);
142+ info.setRouteAddr(null);
143+ info.setDnsAddr(null);
144+ info.setNetMask(null);
145+ } else {
146+ Log.i(TAG,"mode manual");
147+ info.setConnectMode(EthernetDevInfo.ETH_CONN_MODE_MANUAL);
148+ info.setIpAddress(mIpaddr.getText().toString());
149+ info.setRouteAddr(mGw.getText().toString());
150+ info.setDnsAddr(mDns.getText().toString());
151+ info.setNetMask(mMask.getText().toString());
152+ }
153+ mEthManager.UpdateEthDevInfo(info);
154+ if (mEnablePending) {
155+ mEthManager.setEthEnabled(true);
156+ mEnablePending = false;
157+ }
158+ }
159+
160+ public void onClick(DialogInterface dialog, int which) {
161+ switch(which) {
162+ case BUTTON_POSITIVE:
163+ handle_saveconf();
164+ break;
165+ case BUTTON_NEGATIVE:
166+ //Don't need to do anything
167+ break;
168+ default:
169+ Log.e(TAG,"Unknow button");
170+ }
171+
172+ }
173+
174+ public void onItemSelected(AdapterView<?> parent, View view, int position,
175+ long id) {
176+ // TODO Auto-generated method stub
177+
178+ }
179+
180+ public void onNothingSelected(AdapterView<?> parent) {
181+ // TODO Auto-generated method stub
182+
183+ }
184+
185+ public void onClick(View v) {
186+ // TODO Auto-generated method stub
187+
188+ }
189+
190+ public void updateDevNameList(String[] DevList) {
191+ if (DevList != null) {
192+ ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
193+ getContext(), android.R.layout.simple_spinner_item, DevList);
194+ adapter.setDropDownViewResource(
195+ android.R.layout.simple_spinner_dropdown_item);
196+ mDevList.setAdapter(adapter);
197+ }
198+
199+ }
200+
201+ public void enableAfterConfig() {
202+ // TODO Auto-generated method stub
203+ mEnablePending = true;
204+ }
205+
206+}
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetEnabler.java
@@ -0,0 +1,210 @@
1+package com.android.settings.ethernet;
2+
3+
4+import static android.net.ethernet.EthernetManager.ETH_STATE_DISABLED;
5+import static android.net.ethernet.EthernetManager.ETH_STATE_DISABLING;
6+import static android.net.ethernet.EthernetManager.ETH_STATE_ENABLED;
7+import static android.net.ethernet.EthernetManager.ETH_STATE_ENABLING;
8+import static android.net.ethernet.EthernetManager.ETH_STATE_UNKNOWN;
9+
10+import com.android.settings.R;
11+
12+import android.content.BroadcastReceiver;
13+import android.content.Context;
14+import android.content.Intent;
15+import android.content.IntentFilter;
16+import android.net.NetworkInfo;
17+import android.net.ethernet.EthernetManager;
18+import android.preference.Preference;
19+import android.preference.CheckBoxPreference;
20+import android.text.TextUtils;
21+import android.util.Config;
22+import android.util.Log;
23+
24+public class EthernetEnabler implements Preference.OnPreferenceChangeListener{
25+ private static final boolean LOCAL_LOGD = true;
26+ private static final String TAG = "SettingsEthEnabler";
27+ //private final IntentFilter mEthStateFilter;
28+ private Context mContext;
29+ private EthernetManager mEthManager;
30+ private CheckBoxPreference mEthCheckBoxPref;
31+ private final CharSequence mOriginalSummary;
32+ private EthernetConfigDialog mEthConfigDialog;
33+
34+
35+ private final BroadcastReceiver mEthStateReceiver = new BroadcastReceiver() {
36+
37+ @Override
38+ public void onReceive(Context context, Intent intent) {
39+ if (intent.getAction().equals(EthernetManager.ETH_STATE_CHANGED_ACTION)) {
40+ handleEthStateChanged(
41+ intent.getIntExtra(EthernetManager.EXTRA_ETH_STATE,
42+ EthernetManager.ETH_STATE_UNKNOWN),
43+ intent.getIntExtra(EthernetManager.EXTRA_PREVIOUS_ETH_STATE,
44+ EthernetManager.ETH_STATE_UNKNOWN));
45+ } else if (intent.getAction().equals(EthernetManager.NETWORK_STATE_CHANGED_ACTION)) {
46+ handleNetworkStateChanged(
47+ (NetworkInfo) intent.getParcelableExtra(EthernetManager.EXTRA_NETWORK_INFO));
48+ }
49+ }
50+ };
51+
52+ public void setConfigDialog (EthernetConfigDialog Dialog) {
53+ mEthConfigDialog = Dialog;
54+ }
55+
56+ public EthernetEnabler(Context context,
57+ EthernetManager ethernetManager,
58+ CheckBoxPreference ethernetCheckBoxPreference) {
59+ mContext = context;
60+ mEthCheckBoxPref = ethernetCheckBoxPreference;
61+ mEthManager = ethernetManager;
62+
63+ mOriginalSummary = ethernetCheckBoxPreference.getSummary();
64+ ethernetCheckBoxPreference.setPersistent(false);
65+ if(mEthManager.getEthState() == ETH_STATE_ENABLED)
66+ mEthCheckBoxPref.setChecked(true);
67+
68+ /*
69+ mEthStateFilter = new IntentFilter(EthernetManager.ETH_STATE_CHANGED_ACTION);
70+ mEthStateFilter.addAction(EthernetManager.NETWORK_STATE_CHANGED_ACTION);
71+ */
72+
73+ }
74+
75+
76+
77+ public EthernetManager getManager() {
78+ return mEthManager;
79+ }
80+
81+ public void resume() {
82+ /*
83+ int state = mEthManager.getEthState();
84+ // This is the widget enabled state, not the preference toggled state
85+ mEthCheckBoxPref.setEnabled(state == ETH_STATE_ENABLED || state == ETH_STATE_DISABLED
86+ || state == ETH_STATE_UNKNOWN);
87+ */
88+ // mContext.registerReceiver(mEthStateReceiver, mEthStateFilter);
89+ mEthCheckBoxPref.setOnPreferenceChangeListener(this);
90+ }
91+
92+ public void pause() {
93+ // mContext.unregisterReceiver(mEthStateReceiver);
94+ mEthCheckBoxPref.setOnPreferenceChangeListener(null);
95+ }
96+
97+ public boolean onPreferenceChange(Preference preference, Object newValue) {
98+
99+ setEthEnabled((Boolean)newValue);
100+ return false;
101+ }
102+
103+ private void setEthEnabled(final boolean enable) {
104+
105+ int state = mEthManager.getEthState();
106+
107+ Log.i(TAG,"Show configuration dialog " + enable);
108+ // Disable button
109+ mEthCheckBoxPref.setEnabled(false);
110+
111+ if (state != ETH_STATE_ENABLED && enable) {
112+ if (mEthManager.ethConfigured() != true) {
113+ // Now, kick off the setting dialog to get the configurations
114+ mEthConfigDialog.enableAfterConfig();
115+ mEthConfigDialog.show();
116+
117+ } else {
118+ mEthManager.setEthEnabled(enable);
119+ }
120+ } else {
121+ mEthManager.setEthEnabled(enable);
122+ }
123+
124+ mEthCheckBoxPref.setChecked(enable);
125+ // Disable button
126+ mEthCheckBoxPref.setEnabled(true);
127+ }
128+
129+ private void handleEthStateChanged(int ethState, int previousEthState) {
130+
131+ if (LOCAL_LOGD) {
132+ Log.d(TAG, "Received wifi state changed from "
133+ + getHumanReadableEthState(previousEthState) + " to "
134+ + getHumanReadableEthState(ethState));
135+ }
136+ /*
137+ if (ethState == Eth_STATE_DISABLED || ethState == ETH_STATE_ENABLED) {
138+ mEthCheckBoxPref.setChecked(wifiState == ETH_STATE_ENABLED);
139+ mEthCheckBoxPref
140+ .setSummary(wifiState == ETH_STATE_DISABLED ? mOriginalSummary : null);
141+
142+ mEthCheckBoxPref.setEnabled(isEnabledByDependency());
143+
144+ } else if (ethState == ETH_STATE_DISABLING || wifiState == ETH_STATE_ENABLING) {
145+ mEthCheckBoxPref.setSummary(wifiState == ETH_STATE_ENABLING ? R.string.wifi_starting
146+ : R.string.wifi_stopping);
147+
148+ } else if (ethState == ETH_STATE_UNKNOWN) {
149+ int message = R.string.wifi_error;
150+ if (previousEthState == ETH_STATE_ENABLING) message = R.string.error_starting;
151+ else if (previousEthState == ETH_STATE_DISABLING) message = R.string.error_stopping;
152+
153+ mEthCheckBoxPref.setChecked(false);
154+ mEthCheckBoxPref.setSummary(message);
155+ mEthCheckBoxPref.setEnabled(true);
156+ }
157+ */
158+ }
159+
160+ private void handleNetworkStateChanged(NetworkInfo networkInfo) {
161+
162+ if (LOCAL_LOGD) {
163+ Log.d(TAG, "Received network state changed to " + networkInfo);
164+ }
165+ /*
166+ if (mEthernetManager.isEthEnabled()) {
167+ String summary = ethStatus.getStatus(mContext,
168+ mEthManager.getConnectionInfo().getSSID(), networkInfo.getDetailedState());
169+ mEthCheckBoxPref.setSummary(summary);
170+ }
171+ */
172+ }
173+
174+ private boolean isEnabledByDependency() {
175+ Preference dep = getDependencyPreference();
176+ if (dep == null) {
177+ return true;
178+ }
179+
180+ return !dep.shouldDisableDependents();
181+ }
182+
183+ private Preference getDependencyPreference() {
184+ String depKey = mEthCheckBoxPref.getDependency();
185+ if (TextUtils.isEmpty(depKey)) {
186+ return null;
187+ }
188+
189+ return mEthCheckBoxPref.getPreferenceManager().findPreference(depKey);
190+ }
191+
192+ private static String getHumanReadableEthState(int wifiState) {
193+
194+ switch (wifiState) {
195+ case ETH_STATE_DISABLED:
196+ return "Disabled";
197+ case ETH_STATE_DISABLING:
198+ return "Disabling";
199+ case ETH_STATE_ENABLED:
200+ return "Enabled";
201+ case ETH_STATE_ENABLING:
202+ return "Enabling";
203+ case ETH_STATE_UNKNOWN:
204+ return "Unknown";
205+ default:
206+ return "Some other state!";
207+ }
208+
209+ }
210+}
--- /dev/null
+++ b/src/com/android/settings/ethernet/EthernetLayer.java
@@ -0,0 +1,52 @@
1+package com.android.settings.ethernet;
2+
3+import static android.net.ethernet.EthernetManager.ETH_DEVICE_SCAN_RESULT_READY;
4+
5+import com.android.settings.R;
6+import android.content.BroadcastReceiver;
7+import android.content.Context;
8+import android.content.Intent;
9+import android.content.IntentFilter;
10+import android.net.NetworkInfo;
11+import android.net.NetworkInfo.DetailedState;
12+import android.net.NetworkInfo.State;
13+import android.net.ethernet.EthernetManager;
14+import android.os.Handler;
15+import android.os.Message;
16+import android.provider.Settings;
17+import android.text.TextUtils;
18+import android.util.Config;
19+import android.util.Log;
20+
21+import java.util.ArrayList;
22+import java.util.Collections;
23+import java.util.Comparator;
24+import java.util.List;
25+public class EthernetLayer {
26+ private static final String TAG = "EthernetLayer";
27+
28+ private EthernetManager mEthManager;
29+ private String[] mDevList;
30+ private EthernetConfigDialog mDialog;
31+
32+ EthernetLayer (EthernetConfigDialog configdialog){
33+ mDialog = configdialog;
34+ }
35+
36+ private BroadcastReceiver mReceiver = new BroadcastReceiver() {
37+ @Override
38+ public void onReceive(Context context, Intent intent) {
39+ final String action = intent.getAction();
40+ if (action.equals(EthernetManager.ETH_DEVICE_SCAN_RESULT_READY)) {
41+ handleDevListChanges();
42+ }
43+ }
44+ };
45+
46+ private void handleDevListChanges() {
47+ mDevList = mEthManager.getDeviceNameList();
48+ mDialog.updateDevNameList(mDevList);
49+ }
50+
51+
52+}