OSDN Git Service

Wifi diagnostic app to enable debug and provide information
authorIrfan Sheriff <isheriff@google.com>
Thu, 3 Dec 2009 18:53:50 +0000 (10:53 -0800)
committerIrfan Sheriff <isheriff@google.com>
Thu, 10 Dec 2009 23:07:05 +0000 (15:07 -0800)
This is the first checkin on the wifi diagnostic app. Right now,
it supports using the WifiManager API, shows the configuration details
and provides status on the supplicant, network and wifi state along with
some additional details.

More to come:
- add more API and status on any additional fields
- provide a way to show some logs

Bug: 2302130

AndroidManifest.xml
res/layout/wifi_api_test.xml [new file with mode: 0644]
res/layout/wifi_config_info.xml [new file with mode: 0644]
res/layout/wifi_status_test.xml [new file with mode: 0644]
res/values/strings.xml
res/xml/testing_settings.xml
res/xml/testing_wifi_settings.xml [new file with mode: 0644]
src/com/android/settings/wifi/WifiAPITest.java [new file with mode: 0644]
src/com/android/settings/wifi/WifiConfigInfo.java [new file with mode: 0644]
src/com/android/settings/wifi/WifiInfo.java [new file with mode: 0644]
src/com/android/settings/wifi/WifiStatusTest.java [new file with mode: 0644]

index 4700fb5..1bed052 100644 (file)
             </intent-filter>
         </activity>
 
+        <activity android:name=".wifi.WifiInfo">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEVELOPMENT_PREFERENCE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".wifi.WifiConfigInfo">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEVELOPMENT_PREFERENCE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".wifi.WifiAPITest">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEVELOPMENT_PREFERENCE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
+        <activity android:name=".wifi.WifiStatusTest">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.DEVELOPMENT_PREFERENCE" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
+
         <activity android:name="ApnSettings" android:label="@string/apn_settings"
                   android:configChanges="orientation|keyboardHidden"
                   android:launchMode="singleTask"
diff --git a/res/layout/wifi_api_test.xml b/res/layout/wifi_api_test.xml
new file mode 100644 (file)
index 0000000..b3ad18a
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        android:title="@string/wifi_settings_category">
+
+    <Preference
+            android:key="disable_network"
+            android:title="@string/disableNetwork"
+            android:persistent="false" />
+
+    <Preference
+            android:key="disconnect"
+            android:title="@string/disconnect"
+            android:persistent="false" />
+
+    <Preference
+            android:key="enable_network"
+            android:title="@string/enableNetwork"
+            android:persistent="false" />
+
+    <Preference
+            android:key="getConfiguredNetworks"
+            android:title="@string/getConfiguredNetworks"
+            android:persistent="false" />
+
+    <Preference
+            android:key="getConnectionInfo"
+            android:title="@string/getConnectionInfo"
+            android:persistent="false" />
+
+
+</PreferenceScreen>
diff --git a/res/layout/wifi_config_info.xml b/res/layout/wifi_config_info.xml
new file mode 100644 (file)
index 0000000..0aeff6e
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent" >
+
+
+    <LinearLayout style="@style/info_layout">
+
+        <LinearLayout style="@style/entry_layout">
+                <TextView android:text="@string/config_list_label" style="@style/info_label" />
+        </LinearLayout>
+
+        <LinearLayout style="@style/entry_layout">
+                <TextView android:id="@+id/config_list" style="@style/info_value" />
+        </LinearLayout>
+    </LinearLayout>
+
+</ScrollView>
+
diff --git a/res/layout/wifi_status_test.xml b/res/layout/wifi_status_test.xml
new file mode 100644 (file)
index 0000000..5b8ec5d
--- /dev/null
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent" >
+
+
+    <LinearLayout style="@style/info_layout">
+
+        <!-- Update Button -->
+        <Button android:id="@+id/update"
+                android:textSize="14sp"
+                android:layout_marginTop="8dip"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/wifi_update"
+                />
+
+        <!--Wifi State-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/wifi_state_label" style="@style/info_label" />
+            <TextView android:id="@+id/wifi_state" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--Network State-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/network_state_label" style="@style/info_label" />
+            <TextView android:id="@+id/network_state" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--Supplicant State-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/supplicant_state_label" style="@style/info_label" />
+            <TextView android:id="@+id/supplicant_state" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--RSSI Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/rssi_label" style="@style/info_label" />
+            <TextView android:id="@+id/rssi" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--BSSID Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/bssid_label" style="@style/info_label" />
+            <TextView android:id="@+id/bssid" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--SSID Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/ssid_label" style="@style/info_label" />
+            <TextView android:id="@+id/ssid" style="@style/info_value" />
+        </LinearLayout>
+
+
+        <!--Hidden SSID Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/hidden_ssid_label" style="@style/info_label" />
+            <TextView android:id="@+id/hidden_ssid" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--IP address Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/ipaddr_label" style="@style/info_label" />
+            <TextView android:id="@+id/ipaddr" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--MAC address Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/macaddr_label" style="@style/info_label" />
+            <TextView android:id="@+id/macaddr" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--Network ID Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/networkid_label" style="@style/info_label" />
+            <TextView android:id="@+id/networkid" style="@style/info_value" />
+        </LinearLayout>
+
+        <!--Link Speed Value-->
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/link_speed_label" style="@style/info_label" />
+            <TextView android:id="@+id/link_speed" style="@style/info_value" />
+        </LinearLayout>
+
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/scan_list_label" style="@style/info_label" />
+            <TextView android:id="@+id/scan_list" style="@style/info_value" />
+        </LinearLayout>
+
+        <!-- Ping stats -->
+        <Button android:id="@+id/ping_test"
+                android:textSize="14sp"
+                android:layout_marginTop="8dip"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/ping_test_label"
+                />
+
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/radio_info_ping_ipaddr" style="@style/info_label" />
+            <TextView android:id="@+id/pingIpAddr" style="@style/info_value" />
+        </LinearLayout>
+
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/radio_info_ping_hostname" style="@style/info_label" />
+            <TextView android:id="@+id/pingHostname" style="@style/info_value" />
+        </LinearLayout>
+
+        <LinearLayout style="@style/entry_layout">
+            <TextView android:text="@string/radio_info_http_client_test" style="@style/info_label" />
+            <TextView android:id="@+id/httpClientTest" style="@style/info_value" />
+        </LinearLayout>
+
+    </LinearLayout>
+</ScrollView>
index d0d1b5d..b61b908 100644 (file)
     <!-- Wi-Fi settings screen, advanced, title of the item to show the Wi-Fi device's MAC address. -->
     <string name="wifi_advanced_mac_address_title">MAC address</string>
 
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Wi-Fi Testing on the diagnostic screen-->
+    <string name="testing_wifi_info" translatable="false">Wifi information</string>
+
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item for WifiManager disableNetwork API-->
+    <string name="disableNetwork" translatable="false">disableNetwork</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item for WifiManager enableNetwork API-->
+    <string name="enableNetwork" translatable="false">enableNetwork</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item for WifiManager disconnect API-->
+    <string name="disconnect" translatable="false">disconnect</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item for WifiManager getConfiguredNetworks API-->
+    <string name="getConfiguredNetworks" translatable="false">getConfiguredNetworks</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item for WifiManager getConnectionInfo API-->
+    <string name="getConnectionInfo" translatable="false">getConnectionInfo</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item on Wifi information screen-->
+    <string name="wifi_api_test" translatable="false">Wifi API</string>
+
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item on Wifi information screen-->
+    <string name="wifi_status_test" translatable="false">Wifi Status</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Button text on Wifi Status screen-->
+    <string name="wifi_update" translatable="false">Refresh Stats</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="wifi_state_label" translatable="false">Wifi State :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="network_state_label" translatable="false">Network State :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+        Label on Wifi Status screen-->
+    <string name="supplicant_state_label" translatable="false">Supplicant State :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="rssi_label" translatable="false">RSSI :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="bssid_label" translatable="false">BSSID :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="ssid_label" translatable="false">SSID :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="hidden_ssid_label" translatable="false">Hidden SSID :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="ipaddr_label" translatable="false">IPaddr :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="macaddr_label" translatable="false">MAC addr :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="networkid_label" translatable="false">Network ID :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="link_speed_label" translatable="false">Link Speed :</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Status screen-->
+    <string name="scan_list_label" translatable="false">Scan results :</string>
+
+    <!-- wifi state values-->
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary -->
+    <string name="wifi_state_disabling" translatable="false">Disabling</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary -->
+    <string name="wifi_state_disabled" translatable="false">Disabled</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary -->
+    <string name="wifi_state_enabling" translatable="false">Enabling</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary -->
+    <string name="wifi_state_enabled" translatable="false">Enabled</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary -->
+    <string name="wifi_state_unknown" translatable="false">Unknown</string>
+
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Menu item on Wifi information screen-->
+    <string name="wifi_config_info" translatable="false">Wifi Config</string>
+    <!-- Do not translate. Used for diagnostic screens, precise translation is not necessary
+         Label on Wifi Configuration screen-->
+    <string name="config_list_label" translatable="false">Configured Networks</string>
+
+
     <!-- Status message of Wi-Fi when it is scanning -->
     <string name="fragment_status_scanning">Scanning\u2026</string>
     <!-- Status message of Wi-Fi when it is connecting to a particular network -->
index 87c9cf8..4b3ea0b 100644 (file)
                 android:targetPackage="com.android.settings"
                 android:targetClass="com.android.settings.UsageStats" />
     </PreferenceScreen>
+
+    <PreferenceScreen
+            android:title="@string/testing_wifi_info" >
+        <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.wifi.WifiInfo" />
+    </PreferenceScreen>
+
     <!--    
     <PreferenceScreen
             android:title="@string/testing_sim_toolkit">
diff --git a/res/xml/testing_wifi_settings.xml b/res/xml/testing_wifi_settings.xml
new file mode 100644 (file)
index 0000000..7844aaa
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<PreferenceScreen
+xmlns:android="http://schemas.android.com/apk/res/android"
+android:title="@string/testing_wifi_info"
+android:key="parent">
+
+    <Preference
+        android:title="@string/wifi_api_test" >
+                <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.wifi.WifiAPITest" />
+    </Preference>
+
+    <Preference
+        android:title="@string/wifi_config_info" >
+        <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.wifi.WifiConfigInfo" />
+    </Preference>
+
+    <Preference
+        android:title="@string/wifi_status_test" >
+        <intent
+                android:action="android.intent.action.MAIN"
+                android:targetPackage="com.android.settings"
+                android:targetClass="com.android.settings.wifi.WifiStatusTest" />
+    </Preference>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/wifi/WifiAPITest.java b/src/com/android/settings/wifi/WifiAPITest.java
new file mode 100644 (file)
index 0000000..4a9a075
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import com.android.settings.R;
+
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.wifi.WifiManager;
+
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.text.Editable;
+import android.widget.EditText;
+
+
+/**
+ * Provide an interface for testing out the Wifi API
+ */
+public class WifiAPITest extends PreferenceActivity implements
+Preference.OnPreferenceClickListener {
+
+    private static final String TAG = "WifiAPITest";
+    private int netid;
+
+    //============================
+    // Preference/activity member variables
+    //============================
+
+    private static final String KEY_DISCONNECT = "disconnect";
+    private static final String KEY_DISABLE_NETWORK = "disable_network";
+    private static final String KEY_ENABLE_NETWORK = "enable_network";
+
+    private Preference mWifiDisconnect;
+    private Preference mWifiDisableNetwork;
+    private Preference mWifiEnableNetwork;
+
+    private WifiManager mWifiManager;
+
+
+    //============================
+    // Activity lifecycle
+    //============================
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        onCreatePreferences();
+        mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+    }
+
+
+    private void onCreatePreferences() {
+        addPreferencesFromResource(R.layout.wifi_api_test);
+
+        final PreferenceScreen preferenceScreen = getPreferenceScreen();
+
+        mWifiDisconnect = (Preference) preferenceScreen.findPreference(KEY_DISCONNECT);
+        mWifiDisconnect.setOnPreferenceClickListener(this);
+
+        mWifiDisableNetwork = (Preference) preferenceScreen.findPreference(KEY_DISABLE_NETWORK);
+        mWifiDisableNetwork.setOnPreferenceClickListener(this);
+
+        mWifiEnableNetwork = (Preference) preferenceScreen.findPreference(KEY_ENABLE_NETWORK);
+        mWifiEnableNetwork.setOnPreferenceClickListener(this);
+
+    }
+
+    //============================
+    // Preference callbacks
+    //============================
+
+    @Override
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+        super.onPreferenceTreeClick(preferenceScreen, preference);
+        return false;
+    }
+
+    /**
+     *  Implements OnPreferenceClickListener interface
+     */
+    public boolean onPreferenceClick(Preference pref) {
+        if (pref == mWifiDisconnect) {
+            mWifiManager.disconnect();
+        } else if (pref == mWifiDisableNetwork) {
+            AlertDialog.Builder alert = new AlertDialog.Builder(this);
+            alert.setTitle("Input");
+            alert.setMessage("Enter Network ID");
+            // Set an EditText view to get user input
+            final EditText input = new EditText(this);
+            alert.setView(input);
+            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int whichButton) {
+                    Editable value = input.getText();
+                    netid = Integer.parseInt(value.toString());
+                    mWifiManager.disableNetwork(netid);
+                    }
+                    });
+            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int whichButton) {
+                    // Canceled.
+                    }
+                    });
+            alert.show();
+        } else if (pref == mWifiEnableNetwork) {
+            AlertDialog.Builder alert = new AlertDialog.Builder(this);
+            alert.setTitle("Input");
+            alert.setMessage("Enter Network ID");
+            // Set an EditText view to get user input
+            final EditText input = new EditText(this);
+            alert.setView(input);
+            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int whichButton) {
+                    Editable value = input.getText();
+                    netid =  Integer.parseInt(value.toString());
+                    mWifiManager.enableNetwork(netid, false);
+                    }
+                    });
+            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int whichButton) {
+                    // Canceled.
+                    }
+                    });
+            alert.show();
+        }
+        return true;
+    }
+}
diff --git a/src/com/android/settings/wifi/WifiConfigInfo.java b/src/com/android/settings/wifi/WifiConfigInfo.java
new file mode 100644 (file)
index 0000000..2ed4f02
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import android.app.Activity;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.widget.TextView;
+import android.net.wifi.WifiConfiguration;
+import java.util.List;
+
+import com.android.settings.R;
+
+
+/**
+ * Configuration details saved by the user on the WifiSettings screen
+ */
+public class WifiConfigInfo extends Activity {
+
+    private static final String TAG = "WifiConfigInfo";
+
+    private TextView mConfigList;
+    private WifiManager mWifiManager;
+
+    //============================
+    // Activity lifecycle
+    //============================
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+        setContentView(R.layout.wifi_config_info);
+        mConfigList = (TextView) findViewById(R.id.config_list);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        final List<WifiConfiguration> wifiConfigs = mWifiManager.getConfiguredNetworks();
+        StringBuffer configList  = new StringBuffer();
+        for (int i = wifiConfigs.size() - 1; i >= 0; i--) {
+            configList.append(wifiConfigs.get(i));
+        }
+        mConfigList.setText(configList);
+    }
+
+}
diff --git a/src/com/android/settings/wifi/WifiInfo.java b/src/com/android/settings/wifi/WifiInfo.java
new file mode 100644 (file)
index 0000000..291a495
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import com.android.settings.R;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+
+/**
+ * Wifi information menu item on the diagnostic screen
+ */
+public class WifiInfo extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.testing_wifi_settings);
+    }
+
+}
diff --git a/src/com/android/settings/wifi/WifiStatusTest.java b/src/com/android/settings/wifi/WifiStatusTest.java
new file mode 100644 (file)
index 0000000..e440a33
--- /dev/null
@@ -0,0 +1,408 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.wifi;
+
+import com.android.settings.R;
+import com.android.settings.wifi.WifiStatus;
+import android.net.wifi.ScanResult;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import java.util.List;
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.NetworkInfo;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+import java.io.IOException;
+import java.net.UnknownHostException;
+
+
+/**
+ * Show the current status details of Wifi related fields
+ */
+public class WifiStatusTest extends Activity {
+
+    private static final String TAG = "WifiStatusTest";
+
+    private Button updateButton;
+    private TextView mWifiState;
+    private TextView mNetworkState;
+    private TextView mSupplicantState;
+    private TextView mRSSI;
+    private TextView mBSSID;
+    private TextView mSSID;
+    private TextView mHiddenSSID;
+    private TextView mIPAddr;
+    private TextView mMACAddr;
+    private TextView mNetworkId;
+    private TextView mLinkSpeed;
+    private TextView mScanList;
+
+
+    private TextView mPingIpAddr;
+    private TextView mPingHostname;
+    private TextView mHttpClientTest;
+    private Button pingTestButton;
+
+    private String mPingIpAddrResult;
+    private String mPingHostnameResult;
+    private String mHttpClientTestResult;
+
+
+    private WifiManager mWifiManager;
+    private IntentFilter mWifiStateFilter;
+
+
+    //============================
+    // Activity lifecycle
+    //============================
+
+    private final BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+                handleWifiStateChanged(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+                            WifiManager.WIFI_STATE_UNKNOWN));
+            } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
+                handleNetworkStateChanged(
+                        (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
+            } else if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
+                handleScanResultsAvailable();
+            } else if (intent.getAction().equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
+                /* TODO: handle supplicant connection change later */
+            } else if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
+                handleSupplicantStateChanged(
+                        (SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),
+                        intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR),
+                        intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 0));
+            } else if (intent.getAction().equals(WifiManager.RSSI_CHANGED_ACTION)) {
+                handleSignalChanged(intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, 0));
+            } else if (intent.getAction().equals(WifiManager.NETWORK_IDS_CHANGED_ACTION)) {
+                /* TODO: handle network id change info later */
+            } else {
+                Log.e(TAG, "Received an unknown Wifi Intent");
+            }
+        }
+    };
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
+
+        mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
+        mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        mWifiStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
+        mWifiStateFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+        mWifiStateFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
+        mWifiStateFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+
+        registerReceiver(mWifiStateReceiver, mWifiStateFilter);
+
+        setContentView(R.layout.wifi_status_test);
+
+        updateButton = (Button) findViewById(R.id.update);
+        updateButton.setOnClickListener(updateButtonHandler);
+
+        mWifiState = (TextView) findViewById(R.id.wifi_state);
+        mNetworkState = (TextView) findViewById(R.id.network_state);
+        mSupplicantState = (TextView) findViewById(R.id.supplicant_state);
+        mRSSI = (TextView) findViewById(R.id.rssi);
+        mBSSID = (TextView) findViewById(R.id.bssid);
+        mSSID = (TextView) findViewById(R.id.ssid);
+        mHiddenSSID = (TextView) findViewById(R.id.hidden_ssid);
+        mIPAddr = (TextView) findViewById(R.id.ipaddr);
+        mMACAddr = (TextView) findViewById(R.id.macaddr);
+        mNetworkId = (TextView) findViewById(R.id.networkid);
+        mLinkSpeed = (TextView) findViewById(R.id.link_speed);
+        mScanList = (TextView) findViewById(R.id.scan_list);
+
+
+        mPingIpAddr = (TextView) findViewById(R.id.pingIpAddr);
+        mPingHostname = (TextView) findViewById(R.id.pingHostname);
+        mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);
+
+        pingTestButton = (Button) findViewById(R.id.ping_test);
+        pingTestButton.setOnClickListener(mPingButtonHandler);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        registerReceiver(mWifiStateReceiver, mWifiStateFilter);
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        unregisterReceiver(mWifiStateReceiver);
+    }
+
+    OnClickListener mPingButtonHandler = new OnClickListener() {
+        public void onClick(View v) {
+            updatePingState();
+        }
+    };
+
+    OnClickListener updateButtonHandler = new OnClickListener() {
+        public void onClick(View v) {
+            final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
+
+            setWifiStateText(mWifiManager.getWifiState());
+            mBSSID.setText(wifiInfo.getBSSID());
+            mHiddenSSID.setText(String.valueOf(wifiInfo.getHiddenSSID()));
+            int ipAddr = wifiInfo.getIpAddress();
+            StringBuffer ipBuf = new StringBuffer();
+            ipBuf.append(ipAddr  & 0xff).append('.').
+                append((ipAddr >>>= 8) & 0xff).append('.').
+                append((ipAddr >>>= 8) & 0xff).append('.').
+                append((ipAddr >>>= 8) & 0xff);
+
+            mIPAddr.setText(ipBuf);
+            mLinkSpeed.setText(String.valueOf(wifiInfo.getLinkSpeed())+" Mbps");
+            mMACAddr.setText(wifiInfo.getMacAddress());
+            mNetworkId.setText(String.valueOf(wifiInfo.getNetworkId()));
+            mRSSI.setText(String.valueOf(wifiInfo.getRssi()));
+            mSSID.setText(wifiInfo.getSSID());
+
+            SupplicantState supplicantState = wifiInfo.getSupplicantState();
+            setSupplicantStateText(supplicantState);
+        }
+    };
+
+    private void setSupplicantStateText(SupplicantState supplicantState) {
+        if(SupplicantState.FOUR_WAY_HANDSHAKE.equals(supplicantState)) {
+            mSupplicantState.setText("FOUR WAY HANDSHAKE");
+        } else if(SupplicantState.ASSOCIATED.equals(supplicantState)) {
+            mSupplicantState.setText("ASSOCIATED");
+        } else if(SupplicantState.ASSOCIATING.equals(supplicantState)) {
+            mSupplicantState.setText("ASSOCIATING");
+        } else if(SupplicantState.COMPLETED.equals(supplicantState)) {
+            mSupplicantState.setText("COMPLETED");
+        } else if(SupplicantState.DISCONNECTED.equals(supplicantState)) {
+            mSupplicantState.setText("DISCONNECTED");
+        } else if(SupplicantState.DORMANT.equals(supplicantState)) {
+            mSupplicantState.setText("DORMANT");
+        } else if(SupplicantState.GROUP_HANDSHAKE.equals(supplicantState)) {
+            mSupplicantState.setText("GROUP HANDSHAKE");
+        } else if(SupplicantState.INACTIVE.equals(supplicantState)) {
+            mSupplicantState.setText("INACTIVE");
+        } else if(SupplicantState.INVALID.equals(supplicantState)) {
+            mSupplicantState.setText("INVALID");
+        } else if(SupplicantState.SCANNING.equals(supplicantState)) {
+            mSupplicantState.setText("SCANNING");
+        } else if(SupplicantState.UNINITIALIZED.equals(supplicantState)) {
+            mSupplicantState.setText("UNINITIALIZED");
+        } else {
+            mSupplicantState.setText("BAD");
+            Log.e(TAG, "supplicant state is bad");
+        }
+    }
+
+    private void setWifiStateText(int wifiState) {
+        String wifiStateString;
+        switch(wifiState) {
+            case WifiManager.WIFI_STATE_DISABLING:
+                wifiStateString = getString(R.string.wifi_state_disabling);
+                break;
+            case WifiManager.WIFI_STATE_DISABLED:
+                wifiStateString = getString(R.string.wifi_state_disabled);
+                break;
+            case WifiManager.WIFI_STATE_ENABLING:
+                wifiStateString = getString(R.string.wifi_state_enabling);
+                break;
+            case WifiManager.WIFI_STATE_ENABLED:
+                wifiStateString = getString(R.string.wifi_state_enabled);
+                break;
+            case WifiManager.WIFI_STATE_UNKNOWN:
+                wifiStateString = getString(R.string.wifi_state_unknown);
+                break;
+            default:
+                wifiStateString = "BAD";
+                Log.e(TAG, "wifi state is bad");
+                break;
+        }
+
+        mWifiState.setText(wifiStateString);
+    }
+
+    private void handleSignalChanged(int rssi) {
+        mRSSI.setText(String.valueOf(rssi));
+    }
+
+    private void handleWifiStateChanged(int wifiState) {
+        setWifiStateText(wifiState);
+    }
+
+    private void handleScanResultsAvailable() {
+        List<ScanResult> list = mWifiManager.getScanResults();
+
+        StringBuffer scanList = new StringBuffer();
+        if (list != null) {
+            for (int i = list.size() - 1; i >= 0; i--) {
+                final ScanResult scanResult = list.get(i);
+
+                if (scanResult == null) {
+                    continue;
+                }
+
+                if (TextUtils.isEmpty(scanResult.SSID)) {
+                    continue;
+                }
+
+                scanList.append(scanResult.SSID+" ");
+            }
+        }
+        mScanList.setText(scanList);
+    }
+
+    private void handleSupplicantStateChanged(SupplicantState state, boolean hasError, int error) {
+        if (hasError) {
+            mSupplicantState.setText("ERROR AUTHENTICATING");
+        } else {
+            setSupplicantStateText(state);
+        }
+    }
+
+    private void handleNetworkStateChanged(NetworkInfo networkInfo) {
+        if (mWifiManager.isWifiEnabled()) {
+            String summary = WifiStatus.getStatus(this,
+                    mWifiManager.getConnectionInfo().getSSID(), networkInfo.getDetailedState());
+            mNetworkState.setText(summary);
+        }
+    }
+
+    private final void updatePingState() {
+        final Handler handler = new Handler();
+        // Set all to unknown since the threads will take a few secs to update.
+        mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown);
+        mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown);
+        mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
+
+        mPingIpAddr.setText(mPingIpAddrResult);
+        mPingHostname.setText(mPingHostnameResult);
+        mHttpClientTest.setText(mHttpClientTestResult);
+
+        final Runnable updatePingResults = new Runnable() {
+            public void run() {
+                mPingIpAddr.setText(mPingIpAddrResult);
+                mPingHostname.setText(mPingHostnameResult);
+                mHttpClientTest.setText(mHttpClientTestResult);
+            }
+        };
+        Thread ipAddrThread = new Thread() {
+            @Override
+            public void run() {
+                pingIpAddr();
+                handler.post(updatePingResults);
+            }
+        };
+        ipAddrThread.start();
+
+        Thread hostnameThread = new Thread() {
+            @Override
+            public void run() {
+                pingHostname();
+                handler.post(updatePingResults);
+            }
+        };
+        hostnameThread.start();
+
+        Thread httpClientThread = new Thread() {
+            @Override
+            public void run() {
+                httpClientTest();
+                handler.post(updatePingResults);
+            }
+        };
+        httpClientThread.start();
+    }
+
+    /**
+     * The ping functions have been borrowed from Radio diagnostic app to
+     * enable quick access on the wifi status screen
+     */
+    private final void pingIpAddr() {
+        try {
+            // TODO: Hardcoded for now, make it UI configurable
+            String ipAddress = "74.125.47.104";
+            Process p = Runtime.getRuntime().exec("ping -c 1 -w 100 " + ipAddress);
+            int status = p.waitFor();
+            if (status == 0) {
+                mPingIpAddrResult = "Pass";
+            } else {
+                mPingIpAddrResult = "Fail: IP addr not reachable";
+            }
+        } catch (IOException e) {
+            mPingIpAddrResult = "Fail: IOException";
+        } catch (InterruptedException e) {
+            mPingIpAddrResult = "Fail: InterruptedException";
+        }
+    }
+
+    private final void pingHostname() {
+        try {
+            // TODO: Hardcoded for now, make it UI configurable
+            Process p = Runtime.getRuntime().exec("ping -c 1 -w 100 www.google.com");
+            int status = p.waitFor();
+            if (status == 0) {
+                mPingHostnameResult = "Pass";
+            } else {
+                mPingHostnameResult = "Fail: Host unreachable";
+            }
+        } catch (UnknownHostException e) {
+            mPingHostnameResult = "Fail: Unknown Host";
+        } catch (IOException e) {
+            mPingHostnameResult= "Fail: IOException";
+        } catch (InterruptedException e) {
+            mPingHostnameResult = "Fail: InterruptedException";
+        }
+    }
+
+    private void httpClientTest() {
+        HttpClient client = new DefaultHttpClient();
+        try {
+            // TODO: Hardcoded for now, make it UI configurable
+            HttpGet request = new HttpGet("http://www.google.com");
+            HttpResponse response = client.execute(request);
+            if (response.getStatusLine().getStatusCode() == 200) {
+                mHttpClientTestResult = "Pass";
+            } else {
+                mHttpClientTestResult = "Fail: Code: " + String.valueOf(response);
+            }
+            request.abort();
+        } catch (IOException e) {
+            mHttpClientTestResult = "Fail: IOException";
+        }
+    }
+
+}