WifiSettings: remove dead code.
This commit is contained in:
@@ -80,19 +80,6 @@
|
||||
|
||||
<!-- Top-level settings -->
|
||||
|
||||
<activity android:name=".wifi.WifiSettings" android:label="@string/wifi_settings"
|
||||
android:clearTaskOnLaunch="true"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.settings.WIFI_SETTINGS" />
|
||||
<action android:name="android.net.wifi.PICK_WIFI_NETWORK" />
|
||||
<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=".wifi.WifiSettings2"
|
||||
android:label="@string/wifi_settings"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
|
@@ -1,162 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/table"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- SSID -->
|
||||
|
||||
<TextView android:id="@+id/ssid_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/wifi_type_ssid" />
|
||||
|
||||
<EditText android:id="@+id/ssid_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true"
|
||||
android:inputType="textNoSuggestions" />
|
||||
|
||||
<!-- Security -->
|
||||
|
||||
<TextView android:id="@+id/security_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_security" />
|
||||
|
||||
<!-- The entries will be set programmatically -->
|
||||
<Spinner android:id="@+id/security_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<!-- Enterprise Fields -->
|
||||
<LinearLayout android:id="@+id/enterprise_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="0dip"
|
||||
android:orientation="vertical">
|
||||
<TextView android:id="@+id/eap_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_select_eap" />
|
||||
<Spinner android:id="@+id/eap_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView android:id="@+id/phase2_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_select_phase2" />
|
||||
<Spinner android:id="@+id/phase2_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView android:id="@+id/ca_certificate_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_select_ca_certificate" />
|
||||
<Spinner android:id="@+id/ca_certificate_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView android:id="@+id/client_certificate_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_select_client_certificate" />
|
||||
<Spinner android:id="@+id/client_certificate_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView android:id="@+id/identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_identity" />
|
||||
<EditText android:id="@+id/identity_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true"
|
||||
android:inputType="textNoSuggestions" />
|
||||
<TextView android:id="@+id/anonymous_identity_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_anonymous_identity" />
|
||||
<EditText android:id="@+id/anonymous_identity_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Password -->
|
||||
|
||||
<TextView android:id="@+id/password_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_passphrase" />
|
||||
|
||||
<EditText android:id="@+id/password_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true"
|
||||
android:password="true" />
|
||||
|
||||
<CheckBox android:id="@+id/show_password_checkbox"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:text="@string/wifi_show_password" />
|
||||
|
||||
<Spinner android:id="@+id/wep_type_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:entries="@array/wifi_wep_type" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@@ -1,61 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/table"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Info dynamically added here. -->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Password -->
|
||||
<TextView android:id="@+id/password_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_passphrase" />
|
||||
|
||||
<EditText android:id="@+id/password_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true"
|
||||
android:password="true" />
|
||||
|
||||
<CheckBox android:id="@+id/show_password_checkbox"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:text="@string/wifi_show_password" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@@ -1,32 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="8dip"
|
||||
android:textAppearance="?android:attr/textAppearanceSmallInverse" />
|
||||
<TextView
|
||||
android:id="@+id/value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmallInverse"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
@@ -1,57 +0,0 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/wifi_password_incorrect_error" />
|
||||
|
||||
<!-- Password -->
|
||||
<TextView android:id="@+id/password_text"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/please_type_passphrase" />
|
||||
|
||||
<EditText android:id="@+id/password_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:singleLine="true"
|
||||
android:password="true" />
|
||||
|
||||
<CheckBox android:id="@+id/show_password_checkbox"
|
||||
style="?android:attr/textAppearanceSmallInverse"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dip"
|
||||
android:text="@string/wifi_show_password" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@@ -263,45 +263,6 @@
|
||||
<item>Excellent</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Match this with code. --> <skip />
|
||||
<!-- Wi-Fi settings. The type of security a Wi-Fi network has. The user can choose this when he adds a manual network, or configures an existing network. -->
|
||||
<string-array name="wifi_security_entries">
|
||||
<!-- Let the phone figure out the security type auutomatically. -->
|
||||
<item>Auto</item>
|
||||
<!-- The Wi-Fi network does not have any security. -->
|
||||
<item>None</item>
|
||||
<!-- Do not translate. The Wi-Fi network has WEP security. -->
|
||||
<item>WEP</item>
|
||||
<!-- The Wi-Fi network has WPA personal security. WPA Personal is a tech term, and might be better left untranslated? -->
|
||||
<item>WPA/WPA2 PSK</item>
|
||||
<!-- The Wi-Fi network has WPA EAP extensible authentication protocol. -->
|
||||
<item>802.1x Enterprise</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Match this with code. --> <skip />
|
||||
<!-- Wi-Fi settings. The type of security a Wi-Fi network has. The user can choose this when he adds a manual network, or configures an existing network. -->
|
||||
<string-array name="wifi_security_without_auto_entries">
|
||||
<!-- The Wi-Fi network does not have any security. -->
|
||||
<item>None</item>
|
||||
<!-- Do not translate. The Wi-Fi network has WEP security. -->
|
||||
<item>WEP</item>
|
||||
<!-- The Wi-Fi network has WPA personal security. WPA Personal is a tech term, and might be better left untranslated? -->
|
||||
<item>WPA/WPA2 PSK</item>
|
||||
<!-- The Wi-Fi network has WPA enterprise security. WPA Enterprise is a tech term, and might be better left untranslated? -->
|
||||
<item>802.1x Enterprise</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Match this with code. --> <skip />
|
||||
<!-- Wi-Fi settings. Presented as a list dialog to the user. He chooses the type of WEP key he entered. -->
|
||||
<string-array name="wifi_wep_type">
|
||||
<!-- This means the phone should figure out the type automatically the best it can. -->
|
||||
<item>Auto</item>
|
||||
<!-- Do not translate. -->
|
||||
<item>WEP ASCII</item>
|
||||
<!-- WEP key that is in hexadecimal. -->
|
||||
<item>WEP hexadecimal</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Wi-Fi settings. Presented as a list dialog to the user to choose the Wi-Fi sleep policy. -->
|
||||
<string-array name="wifi_sleep_policy_entries">
|
||||
<!-- Wi-Fi should go to sleep when the screen turns off. -->
|
||||
|
@@ -790,133 +790,6 @@
|
||||
<!-- Label for the netmask of the network -->
|
||||
<string name="wifi_netmask">Netmask</string>
|
||||
|
||||
<!-- Button caption to forget a wifi network -->
|
||||
<string name="forget_network">Forget</string>
|
||||
<!-- Label for link speed (wifi) -->
|
||||
<string name="wifi_link_speed">Speed</string>
|
||||
<!-- Verbose wifi signal strength. This is the best out of 4 levels. -->
|
||||
<string name="wifi_signal_3">Excellent</string>
|
||||
<!-- Verbose wifi signal strength. This is the 2nd best out of 4 levels. -->
|
||||
<string name="wifi_signal_2">Good</string>
|
||||
<!-- Verbose wifi signal strength. This is the 3rd best out of 4 levels. -->
|
||||
<string name="wifi_signal_1">Fair</string>
|
||||
<!-- Verbose wifi signal strength. This is the worst out of 4 levels. -->
|
||||
<string name="wifi_signal_0">Poor</string>
|
||||
<!-- Label for the security of a wifi network -->
|
||||
<string name="security">Security</string>
|
||||
<!-- Value for the wifi security. This means no encryption. -->
|
||||
<string name="wifi_security_open">Open</string>
|
||||
<!-- Value for the wifi security -->
|
||||
<string name="wifi_security_wep">WEP</string>
|
||||
<!-- Value for the wifi security -->
|
||||
<string name="wifi_security_psk">WPA/WPA2 PSK</string>
|
||||
<!-- Value for the wifi security -->
|
||||
<string name="wifi_security_eap">Enterprise(802.1x)</string>
|
||||
<!-- Value for the wifi security -->
|
||||
|
||||
<!-- Value for the wifi security when it is unknown -->
|
||||
<string name="wifi_security_unknown">Unknown</string>
|
||||
<!-- Verbose security type of a wifi network. Open means no security. Capitalized by app. -->
|
||||
<string name="wifi_security_verbose_open">open network</string>
|
||||
<!-- Verbose security type of a wifi network. Capitalized by app. -->
|
||||
<string name="wifi_security_verbose_wep">secured with WEP</string>
|
||||
<!-- Verbose security type of a wifi network. Capitalized by app. -->
|
||||
<string name="wifi_security_verbose_psk">secured with WPA/WPA2 PSK</string>
|
||||
<!-- Verbose security type of a wifi network. Capitalized by app. -->
|
||||
<string name="wifi_security_verbose_eap">secured with 802.1x EAP</string>
|
||||
<!-- Label for the signal strength -->
|
||||
<string name="signal">Signal strength</string>
|
||||
<!-- Error message when Wi-Fi can't start -->
|
||||
<string name="error_starting">Unable to start Wi-Fi</string>
|
||||
<!-- Error message when Wi-Fi can't stop -->
|
||||
<string name="error_stopping">Unable to stop Wi-Fi</string>
|
||||
<!-- Error message when Wi-Fi can't scan for networks -->
|
||||
<string name="error_scanning">Unable to scan for networks</string>
|
||||
<!-- Error message when Wi-Fi can't connect -->
|
||||
<string name="error_connecting">Unable to connect to the network</string>
|
||||
<!-- Error message when Wi-Fi can't save the network -->
|
||||
<string name="error_saving">Unable to save the network</string>
|
||||
<!-- Button label to connect to a wifi network-->
|
||||
<string name="connect">Connect</string>
|
||||
<!-- Dialog title for when the user is trying to connect to a particular network-->
|
||||
<string name="connect_to_blank"><xliff:g id="network_name">%1$s</xliff:g></string>
|
||||
<!-- Caption for the eap method -->
|
||||
<string name="please_select_eap">EAP method</string>
|
||||
<!-- Caption for the phase2 -->
|
||||
<string name="please_select_phase2">Phase 2 authentication</string>
|
||||
<!-- Caption for the identity -->
|
||||
<string name="please_type_identity">Identity</string>
|
||||
<!-- Caption for the anonymous_identity -->
|
||||
<string name="please_type_anonymous_identity">Anonymous identity</string>
|
||||
<!-- Caption for the client_certificate -->
|
||||
<string name="please_select_client_certificate">Client certificate</string>
|
||||
<!-- Caption for the ca certificate -->
|
||||
<string name="please_select_ca_certificate">CA certificate</string>
|
||||
<!-- Caption for the wireless password -->
|
||||
<string name="please_type_passphrase">Wireless password</string>
|
||||
<!--Wi-Fi settings screen, connect to network dialog box, field label and hint text -->
|
||||
<string name="please_type_hex_key">WEP hex key (0-9, A-F)</string>
|
||||
<!--Wi-Fi settings screen menu option -->
|
||||
<string name="scan_wifi">Scan</string>
|
||||
<!-- Wifi network summary when not in nearby. -->
|
||||
<string name="summary_not_in_range">Not in range</string>
|
||||
<!-- Wifi network summary when the network is configured previously, capitalized by app -->
|
||||
<string name="summary_remembered">remembered</string>
|
||||
<!-- Wifi network summary when there was an error connecting -->
|
||||
<string name="summary_connection_failed">Connection unsuccessful, touch to try again</string>
|
||||
<!-- Caption for entering the SSID of a wifi network -->
|
||||
<string name="wifi_type_ssid">Network SSID</string>
|
||||
<!-- Button caption to save a configuration wifi -->
|
||||
<string name="wifi_save_config">Save</string>
|
||||
<!-- An edit field's grayed out value when it has not been modified -->
|
||||
<string name="wifi_password_unchanged">(unchanged)</string>
|
||||
<!-- Action message to add a wifi network -->
|
||||
<string name="wifi_add_other_network">Add Wi-Fi network</string>
|
||||
<!-- This dialog will use the error_title as the title. -->
|
||||
<string name="wifi_password_incorrect_error">The network password you typed is not correct. Please try again.</string>
|
||||
<!-- Generic error message -->
|
||||
<string name="wifi_generic_connection_error">There is a problem connecting to the network. Please try again.</string>
|
||||
<!--Wi-Fi settings screen, network context menu item -->
|
||||
<string name="wifi_context_menu_connect">Connect to network</string>
|
||||
<!--Wi-Fi settings screen, network context menu item -->
|
||||
<string name="wifi_context_menu_forget">Forget network</string>
|
||||
<!--Wi-Fi settings screen, network context menu item -->
|
||||
<string name="wifi_context_menu_change_password">Change password</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 -->
|
||||
<string name="fragment_status_connecting">Connecting to <xliff:g id="network_name">%1$s</xliff:g>\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is authenticating with a network -->
|
||||
<string name="fragment_status_authenticating">Authenticating with <xliff:g id="network_name">%1$s</xliff:g>\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is obtaining the IP address from a netwrok -->
|
||||
<string name="fragment_status_obtaining_ip">Obtaining IP address from <xliff:g id="network_name">%1$s</xliff:g>\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is connect to a network -->
|
||||
<string name="fragment_status_connected">Connected to <xliff:g id="network_name">%1$s</xliff:g></string>
|
||||
<!-- Status message of Wi-Fi when it is disconnecting from a network -->
|
||||
<string name="fragment_status_disconnecting">Disconnecting from <xliff:g id="network_name">%1$s</xliff:g>\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is disconnected from a network-->
|
||||
<string name="fragment_status_disconnected">Disconnected</string>
|
||||
<!-- Status message of Wi-Fi when it is a failure (connection) -->
|
||||
<string name="fragment_status_failed">Unsuccessful</string>
|
||||
|
||||
<!-- Status message of Wi-Fi when it is scanning -->
|
||||
<string name="status_scanning">Scanning\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is connecting (but the network is not known right now) -->
|
||||
<string name="status_connecting">Connecting\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is authenticating (but the network is not known right now) -->
|
||||
<string name="status_authenticating">Authenticating\u2026</string>
|
||||
<!--Wi-Fi settings screen, summary text for network when connecting -->
|
||||
<string name="status_obtaining_ip">Obtaining address\u2026</string>
|
||||
<!--Wi-Fi settings screen, summary text for network when connected -->
|
||||
<string name="status_connected">Connected</string>
|
||||
<!-- Status message of Wi-Fi when it is disconnecting (but the network is not known right now) -->
|
||||
<string name="status_disconnecting">Disconnecting\u2026</string>
|
||||
<!-- Status message of Wi-Fi when it is disconnected (but the network is not known right now) -->
|
||||
<string name="status_disconnected">Disconnected</string>
|
||||
<!-- Status message of Wi-Fi when it is a failure (but the network is not known right now) -->
|
||||
<string name="status_failed">Unsuccessful</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>
|
||||
|
@@ -1,30 +0,0 @@
|
||||
<?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">
|
||||
|
||||
<com.android.settings.ProgressCategory
|
||||
android:key="access_points"
|
||||
android:title="@string/wifi_access_points"
|
||||
android:persistent="false" />
|
||||
|
||||
<Preference
|
||||
android:key="add_other_network"
|
||||
android:title="@string/wifi_add_other_network"
|
||||
android:persistent="false" />
|
||||
|
||||
</PreferenceScreen>
|
@@ -1,45 +0,0 @@
|
||||
<?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/wifi_settings_category">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="wifi_enabled"
|
||||
android:title="@string/wifi"
|
||||
android:summary="@string/wifi_quick_toggle_summary"
|
||||
android:persistent="false" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="open_network_notifications_enabled"
|
||||
android:dependency="wifi_enabled"
|
||||
android:title="@string/wifi_notify_open_networks"
|
||||
android:summary="@string/wifi_notify_open_networks_summary"
|
||||
android:persistent="false" />
|
||||
|
||||
<com.android.settings.ProgressCategory
|
||||
android:key="access_points"
|
||||
android:dependency="wifi_enabled"
|
||||
android:title="@string/wifi_access_points"
|
||||
android:persistent="false" />
|
||||
|
||||
<Preference
|
||||
android:key="add_other_network"
|
||||
android:dependency="wifi_enabled"
|
||||
android:title="@string/wifi_add_other_network"
|
||||
android:persistent="false" />
|
||||
|
||||
</PreferenceScreen>
|
@@ -1,847 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class AccessPointDialog extends AlertDialog implements DialogInterface.OnClickListener,
|
||||
AdapterView.OnItemSelectedListener, View.OnClickListener {
|
||||
|
||||
private static final String TAG = "AccessPointDialog";
|
||||
private static final String INSTANCE_KEY_ACCESS_POINT_STATE =
|
||||
"com.android.settings.wifi.AccessPointDialog:accessPointState";
|
||||
private static final String INSTANCE_KEY_MODE =
|
||||
"com.android.settings.wifi.AccessPointDialog:mode";
|
||||
private static final String INSTANCE_KEY_CUSTOM_TITLE =
|
||||
"com.android.settings.wifi.AccessPointDialog:customTitle";
|
||||
private static final String INSTANCE_KEY_AUTO_SECURITY_ALLOWED =
|
||||
"com.android.settings.wifi.AccessPointDialog:autoSecurityAllowed";
|
||||
|
||||
private static final int POSITIVE_BUTTON = BUTTON1;
|
||||
private static final int NEGATIVE_BUTTON = BUTTON2;
|
||||
private static final int NEUTRAL_BUTTON = BUTTON3;
|
||||
|
||||
/** The dialog should show info connectivity functionality */
|
||||
public static final int MODE_INFO = 0;
|
||||
/** The dialog should configure the detailed AP properties */
|
||||
public static final int MODE_CONFIGURE = 1;
|
||||
/** The dialog should have the password field and connect/cancel */
|
||||
public static final int MODE_RETRY_PASSWORD = 2;
|
||||
|
||||
// These should be matched with the XML. Both arrays in XML depend on this
|
||||
// ordering!
|
||||
private static final int SECURITY_AUTO = 0;
|
||||
private static final int SECURITY_NONE = 1;
|
||||
private static final int SECURITY_WEP = 2;
|
||||
private static final int SECURITY_PSK = 3;
|
||||
private static final int SECURITY_EAP = 4;
|
||||
|
||||
private static final int[] WEP_TYPE_VALUES = {
|
||||
AccessPointState.WEP_PASSWORD_AUTO, AccessPointState.WEP_PASSWORD_ASCII,
|
||||
AccessPointState.WEP_PASSWORD_HEX
|
||||
};
|
||||
private static final String NOT_APPLICABLE = "N/A";
|
||||
private static final String KEYSTORE_HEADER = "keystore://";
|
||||
|
||||
// Button positions, default to impossible values
|
||||
private int mConnectButtonPos = Integer.MAX_VALUE;
|
||||
private int mForgetButtonPos = Integer.MAX_VALUE;
|
||||
private int mSaveButtonPos = Integer.MAX_VALUE;
|
||||
|
||||
// Client configurable items. Generally, these should be saved in instance state
|
||||
private int mMode = MODE_INFO;
|
||||
private boolean mAutoSecurityAllowed = true;
|
||||
private CharSequence mCustomTitle;
|
||||
// This does not need to be saved in instance state.
|
||||
private WifiLayer mWifiLayer;
|
||||
private AccessPointState mState;
|
||||
|
||||
// General views
|
||||
private View mView;
|
||||
private View mEnterpriseView;
|
||||
private TextView mPasswordText;
|
||||
private EditText mPasswordEdit;
|
||||
private CheckBox mShowPasswordCheckBox;
|
||||
|
||||
// Enterprise fields
|
||||
private TextView mEapText;
|
||||
private Spinner mEapSpinner;
|
||||
private TextView mPhase2Text;
|
||||
private Spinner mPhase2Spinner;
|
||||
private TextView mIdentityText;
|
||||
private EditText mIdentityEdit;
|
||||
private TextView mAnonymousIdentityText;
|
||||
private EditText mAnonymousIdentityEdit;
|
||||
private TextView mCaCertText;
|
||||
private Spinner mCaCertSpinner;
|
||||
private TextView mClientCertText;
|
||||
private Spinner mClientCertSpinner;
|
||||
private EditText[] mEnterpriseTextFields;
|
||||
|
||||
|
||||
// Info-specific views
|
||||
private ViewGroup mTable;
|
||||
|
||||
// Configure-specific views
|
||||
private EditText mSsidEdit;
|
||||
private TextView mSsidText;
|
||||
private TextView mSecurityText;
|
||||
private Spinner mSecuritySpinner;
|
||||
private Spinner mWepTypeSpinner;
|
||||
private KeyStore mKeyStore;
|
||||
|
||||
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
||||
super(context);
|
||||
|
||||
mWifiLayer = wifiLayer;
|
||||
mKeyStore = KeyStore.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
onLayout();
|
||||
onFill();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (mMode == MODE_CONFIGURE) {
|
||||
Button saveButton = getButton(mSaveButtonPos);
|
||||
saveButton.setEnabled(false);
|
||||
saveButton.setFocusable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private final TextWatcher mSsidEditorWatcher = new TextWatcher() {
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (mSaveButtonPos != Integer.MAX_VALUE) {
|
||||
boolean enable = true;
|
||||
if (s.length() == 0) {
|
||||
enable = false;
|
||||
}
|
||||
Button saveButton = getButton(mSaveButtonPos);
|
||||
saveButton.setEnabled(enable);
|
||||
saveButton.setFocusable(enable);
|
||||
}
|
||||
}
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
// Set to a class loader that can find AccessPointState
|
||||
savedInstanceState.setClassLoader(getClass().getClassLoader());
|
||||
|
||||
mState = savedInstanceState.getParcelable(INSTANCE_KEY_ACCESS_POINT_STATE);
|
||||
mState.setContext(getContext());
|
||||
|
||||
mMode = savedInstanceState.getInt(INSTANCE_KEY_MODE, mMode);
|
||||
mAutoSecurityAllowed = savedInstanceState.getBoolean(INSTANCE_KEY_AUTO_SECURITY_ALLOWED,
|
||||
mAutoSecurityAllowed);
|
||||
mCustomTitle = savedInstanceState.getCharSequence(INSTANCE_KEY_CUSTOM_TITLE);
|
||||
if (mCustomTitle != null) {
|
||||
setTitle(mCustomTitle);
|
||||
}
|
||||
|
||||
// This is called last since it depends on the above values
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
if (mShowPasswordCheckBox != null) {
|
||||
// Restore the show-password-state on the edit text
|
||||
setShowPassword(mShowPasswordCheckBox.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle onSaveInstanceState() {
|
||||
Bundle bundle = super.onSaveInstanceState();
|
||||
bundle.putParcelable(INSTANCE_KEY_ACCESS_POINT_STATE, mState);
|
||||
bundle.putInt(INSTANCE_KEY_MODE, mMode);
|
||||
bundle.putBoolean(INSTANCE_KEY_AUTO_SECURITY_ALLOWED, mAutoSecurityAllowed);
|
||||
bundle.putCharSequence(INSTANCE_KEY_CUSTOM_TITLE, mCustomTitle);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets state to show in this dialog.
|
||||
*
|
||||
* @param state The state.
|
||||
*/
|
||||
public void setState(AccessPointState state) {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dialog mode.
|
||||
* @param mode One of {@link #MODE_CONFIGURE} or {@link #MODE_INFO}
|
||||
*/
|
||||
public void setMode(int mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
public void setAutoSecurityAllowed(boolean autoSecurityAllowed) {
|
||||
mAutoSecurityAllowed = autoSecurityAllowed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(CharSequence title) {
|
||||
super.setTitle(title);
|
||||
mCustomTitle = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(int titleId) {
|
||||
setTitle(getContext().getString(titleId));
|
||||
}
|
||||
|
||||
public void enableEnterpriseFields() {
|
||||
setEnterpriseFieldsVisible(true);
|
||||
updateCertificateSelection();
|
||||
setGenericPasswordVisible(true);
|
||||
// Both WPA and WPA2 show the same caption, so either is ok
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
}
|
||||
|
||||
/** Called after flags are set, the dialog's layout/etc should be set up here */
|
||||
private void onLayout() {
|
||||
final Context context = getContext();
|
||||
final String ssid = mState.ssid;
|
||||
|
||||
int positiveButtonResId = 0;
|
||||
int negativeButtonResId = R.string.cancel;
|
||||
int neutralButtonResId = 0;
|
||||
|
||||
if (mCustomTitle == null) {
|
||||
// Generic title is the SSID
|
||||
// We don't want to trigger this as a custom title, so call super's
|
||||
super.setTitle(ssid);
|
||||
}
|
||||
setInverseBackgroundForced(true);
|
||||
|
||||
boolean defaultPasswordVisibility = true;
|
||||
|
||||
if (mMode == MODE_CONFIGURE) {
|
||||
setLayout(R.layout.wifi_ap_configure);
|
||||
|
||||
positiveButtonResId = R.string.wifi_save_config;
|
||||
mSaveButtonPos = POSITIVE_BUTTON;
|
||||
|
||||
setEnterpriseFieldsVisible(false);
|
||||
|
||||
} else if (mMode == MODE_INFO) {
|
||||
if (mState.isEnterprise() && !mState.configured) {
|
||||
setLayout(R.layout.wifi_ap_configure);
|
||||
setEnterpriseFieldsVisible(true);
|
||||
} else {
|
||||
setLayout(R.layout.wifi_ap_info);
|
||||
}
|
||||
|
||||
if (mState.isConnectable()) {
|
||||
if (mCustomTitle == null) {
|
||||
// We don't want to trigger this as a custom title, so call super's
|
||||
super.setTitle(context.getString(R.string.connect_to_blank, ssid));
|
||||
}
|
||||
positiveButtonResId = R.string.connect;
|
||||
mConnectButtonPos = POSITIVE_BUTTON;
|
||||
}
|
||||
|
||||
if (mState.isForgetable()) {
|
||||
if (positiveButtonResId == 0) {
|
||||
positiveButtonResId = R.string.forget_network;
|
||||
mForgetButtonPos = POSITIVE_BUTTON;
|
||||
} else {
|
||||
neutralButtonResId = R.string.forget_network;
|
||||
mForgetButtonPos = NEUTRAL_BUTTON;
|
||||
}
|
||||
}
|
||||
} else if (mMode == MODE_RETRY_PASSWORD) {
|
||||
setLayout(R.layout.wifi_ap_retry_password);
|
||||
|
||||
positiveButtonResId = R.string.connect;
|
||||
mConnectButtonPos = POSITIVE_BUTTON;
|
||||
|
||||
setGenericPasswordVisible(true);
|
||||
defaultPasswordVisibility = false;
|
||||
}
|
||||
|
||||
if (defaultPasswordVisibility) {
|
||||
if (!mState.configured && mState.seen && mState.hasSecurity()) {
|
||||
setGenericPasswordVisible(true);
|
||||
} else {
|
||||
setGenericPasswordVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
setButtons(positiveButtonResId, negativeButtonResId, neutralButtonResId);
|
||||
|
||||
}
|
||||
|
||||
/** Called when we need to set our member variables to point to the views. */
|
||||
private void onReferenceViews(View view) {
|
||||
mPasswordText = (TextView) view.findViewById(R.id.password_text);
|
||||
mPasswordEdit = (EditText) view.findViewById(R.id.password_edit);
|
||||
mSsidText = (TextView) view.findViewById(R.id.ssid_text);
|
||||
mSsidEdit = (EditText) view.findViewById(R.id.ssid_edit);
|
||||
if (mSsidEdit != null) {
|
||||
mSsidEdit.addTextChangedListener(mSsidEditorWatcher);
|
||||
}
|
||||
mSecurityText = (TextView) view.findViewById(R.id.security_text);
|
||||
mSecuritySpinner = (Spinner) view.findViewById(R.id.security_spinner);
|
||||
mWepTypeSpinner = (Spinner) view.findViewById(R.id.wep_type_spinner);
|
||||
mEnterpriseView = mView.findViewById(R.id.enterprise_wrapper);
|
||||
|
||||
mShowPasswordCheckBox = (CheckBox) view.findViewById(R.id.show_password_checkbox);
|
||||
if (mShowPasswordCheckBox != null) {
|
||||
mShowPasswordCheckBox.setOnClickListener(this);
|
||||
}
|
||||
if (mMode == MODE_CONFIGURE) {
|
||||
mSecuritySpinner.setOnItemSelectedListener(this);
|
||||
mSecuritySpinner.setPromptId(R.string.security);
|
||||
setSpinnerAdapter(mSecuritySpinner, mAutoSecurityAllowed ?
|
||||
R.array.wifi_security_entries
|
||||
: R.array.wifi_security_without_auto_entries);
|
||||
} else if (mMode == MODE_INFO) {
|
||||
mTable = (ViewGroup) view.findViewById(R.id.table);
|
||||
}
|
||||
/* for enterprise one */
|
||||
if (mMode == MODE_CONFIGURE ||
|
||||
(mState.isEnterprise() && !mState.configured)) {
|
||||
setEnterpriseFields(view);
|
||||
updateCertificateSelection();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCertificateSelection() {
|
||||
setSpinnerAdapter(mClientCertSpinner, getAllUserCertificateKeys());
|
||||
setSpinnerAdapter(mCaCertSpinner, getAllCaCertificateKeys());
|
||||
|
||||
mPhase2Spinner.setSelection(getSelectionIndex(
|
||||
R.array.wifi_phase2_entries, mState.getPhase2()));
|
||||
mEapSpinner.setSelection(getSelectionIndex(
|
||||
R.array.wifi_eap_entries, mState.getEap()));
|
||||
mClientCertSpinner.setSelection(getSelectionIndex(
|
||||
getAllUserCertificateKeys(), mState.getEnterpriseField(
|
||||
AccessPointState.CLIENT_CERT)));
|
||||
mCaCertSpinner.setSelection(getSelectionIndex(
|
||||
getAllCaCertificateKeys(), mState.getEnterpriseField(
|
||||
AccessPointState.CA_CERT)));
|
||||
}
|
||||
|
||||
private String[] getAllCaCertificateKeys() {
|
||||
return appendEmptyInSelection(mKeyStore.saw(Credentials.CA_CERTIFICATE));
|
||||
}
|
||||
|
||||
private String[] getAllUserCertificateKeys() {
|
||||
return appendEmptyInSelection(mKeyStore.saw(Credentials.USER_CERTIFICATE));
|
||||
}
|
||||
|
||||
private String[] appendEmptyInSelection(String[] keys) {
|
||||
if (keys == null) {
|
||||
return new String[] {NOT_APPLICABLE};
|
||||
} else {
|
||||
String[] selections = new String[keys.length + 1];
|
||||
System.arraycopy(keys, 0, selections, 0, keys.length);
|
||||
selections[keys.length] = NOT_APPLICABLE;
|
||||
return selections;
|
||||
}
|
||||
}
|
||||
|
||||
private void setEnterpriseFields(View view) {
|
||||
mIdentityText = (TextView) view.findViewById(R.id.identity_text);
|
||||
mIdentityEdit = (EditText) view.findViewById(R.id.identity_edit);
|
||||
mAnonymousIdentityText =
|
||||
(TextView) view.findViewById(R.id.anonymous_identity_text);
|
||||
mAnonymousIdentityEdit =
|
||||
(EditText) view.findViewById(R.id.anonymous_identity_edit);
|
||||
mClientCertText =
|
||||
(TextView) view.findViewById(R.id.client_certificate_text);
|
||||
mCaCertText = (TextView) view.findViewById(R.id.ca_certificate_text);
|
||||
mEapText = (TextView) view.findViewById(R.id.eap_text);
|
||||
mEapSpinner = (Spinner) view.findViewById(R.id.eap_spinner);
|
||||
mEapSpinner.setOnItemSelectedListener(this);
|
||||
mEapSpinner.setPromptId(R.string.please_select_eap);
|
||||
setSpinnerAdapter(mEapSpinner, R.array.wifi_eap_entries);
|
||||
|
||||
mPhase2Text = (TextView) view.findViewById(R.id.phase2_text);
|
||||
mPhase2Spinner = (Spinner) view.findViewById(R.id.phase2_spinner);
|
||||
mPhase2Spinner.setOnItemSelectedListener(this);
|
||||
mPhase2Spinner.setPromptId(R.string.please_select_phase2);
|
||||
setSpinnerAdapter(mPhase2Spinner, R.array.wifi_phase2_entries);
|
||||
|
||||
mClientCertSpinner =
|
||||
(Spinner) view.findViewById(R.id.client_certificate_spinner);
|
||||
mClientCertSpinner.setOnItemSelectedListener(this);
|
||||
mClientCertSpinner.setPromptId(
|
||||
R.string.please_select_client_certificate);
|
||||
setSpinnerAdapter(mClientCertSpinner, getAllUserCertificateKeys());
|
||||
|
||||
mCaCertSpinner =
|
||||
(Spinner) view.findViewById(R.id.ca_certificate_spinner);
|
||||
mCaCertSpinner.setOnItemSelectedListener(this);
|
||||
mCaCertSpinner.setPromptId(R.string.please_select_ca_certificate);
|
||||
setSpinnerAdapter(mCaCertSpinner, getAllCaCertificateKeys());
|
||||
|
||||
mEnterpriseTextFields = new EditText[] {
|
||||
mIdentityEdit, mAnonymousIdentityEdit
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private void setSpinnerAdapter(Spinner spinner, String[] items) {
|
||||
if (items != null) {
|
||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
|
||||
getContext(), android.R.layout.simple_spinner_item, items);
|
||||
adapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSpinnerAdapter(Spinner spinner, int arrayResId) {
|
||||
setSpinnerAdapter(spinner,
|
||||
getContext().getResources().getStringArray(arrayResId));
|
||||
}
|
||||
|
||||
/** Called when the widgets are in-place waiting to be filled with data */
|
||||
private void onFill() {
|
||||
|
||||
// Appears in the order added
|
||||
if (mMode == MODE_INFO) {
|
||||
if (mState.primary) {
|
||||
addInfoRow(R.string.wifi_status, mState.getSummarizedStatus());
|
||||
addInfoRow(R.string.wifi_link_speed, mState.linkSpeed + WifiInfo.LINK_SPEED_UNITS);
|
||||
}
|
||||
|
||||
if (mState.seen) {
|
||||
addInfoRow(R.string.signal, getSignalResId(mState.signal));
|
||||
}
|
||||
|
||||
if (mState.security != null) {
|
||||
addInfoRow(R.string.security, mState.getHumanReadableSecurity());
|
||||
}
|
||||
|
||||
if (mState.primary && mState.ipAddress != 0) {
|
||||
addInfoRow(R.string.ip_address, Formatter.formatIpAddress(mState.ipAddress));
|
||||
}
|
||||
|
||||
} else if (mMode == MODE_CONFIGURE) {
|
||||
String ssid = mState.ssid;
|
||||
if (!TextUtils.isEmpty(ssid)) {
|
||||
mSsidEdit.setText(ssid);
|
||||
}
|
||||
if (mState.configured) {
|
||||
mPasswordEdit.setHint(R.string.wifi_password_unchanged);
|
||||
}
|
||||
}
|
||||
|
||||
updatePasswordCaption(mState.security);
|
||||
}
|
||||
|
||||
private void updatePasswordCaption(String security) {
|
||||
if (mPasswordText != null) {
|
||||
if (security != null && security.equals(AccessPointState.WEP)) {
|
||||
mPasswordText.setText(R.string.please_type_hex_key);
|
||||
} else {
|
||||
mPasswordText.setText(R.string.please_type_passphrase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addInfoRow(int nameResId, String value) {
|
||||
View rowView = getLayoutInflater().inflate(R.layout.wifi_ap_info_row, mTable, false);
|
||||
((TextView) rowView.findViewById(R.id.name)).setText(nameResId);
|
||||
((TextView) rowView.findViewById(R.id.value)).setText(value);
|
||||
mTable.addView(rowView);
|
||||
}
|
||||
|
||||
private void addInfoRow(int nameResId, int valueResId) {
|
||||
addInfoRow(nameResId, getContext().getString(valueResId));
|
||||
}
|
||||
|
||||
private void setButtons(int positiveResId, int negativeResId, int neutralResId) {
|
||||
final Context context = getContext();
|
||||
|
||||
if (positiveResId > 0) {
|
||||
setButton(context.getString(positiveResId), this);
|
||||
}
|
||||
|
||||
if (negativeResId > 0) {
|
||||
setButton2(context.getString(negativeResId), this);
|
||||
}
|
||||
|
||||
if (neutralResId > 0) {
|
||||
setButton3(context.getString(neutralResId), this);
|
||||
}
|
||||
}
|
||||
|
||||
private void setLayout(int layoutResId) {
|
||||
setView(mView = getLayoutInflater().inflate(layoutResId, null));
|
||||
onReferenceViews(mView);
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == mForgetButtonPos) {
|
||||
handleForget();
|
||||
} else if (which == mConnectButtonPos) {
|
||||
handleConnect();
|
||||
} else if (which == mSaveButtonPos) {
|
||||
handleSave();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleForget() {
|
||||
if (!replaceStateWithWifiLayerInstance()) return;
|
||||
mWifiLayer.forgetNetwork(mState);
|
||||
}
|
||||
|
||||
private void handleConnect() {
|
||||
if (!replaceStateWithWifiLayerInstance()) {
|
||||
Log.w(TAG, "Assuming connecting to a new network.");
|
||||
}
|
||||
|
||||
if (mState.isEnterprise()) {
|
||||
if(!mState.configured) {
|
||||
updateEnterpriseFields();
|
||||
}
|
||||
}
|
||||
updatePasswordField();
|
||||
|
||||
mWifiLayer.connectToNetwork(mState);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the network is secured and they haven't entered a password, popup an
|
||||
* error. Allow empty passwords if the state already has a password set
|
||||
* (since in that scenario, an empty password means keep the old password).
|
||||
*/
|
||||
private void updatePasswordField() {
|
||||
|
||||
String password = getEnteredPassword();
|
||||
boolean passwordIsEmpty = TextUtils.isEmpty(password);
|
||||
/*
|
||||
* When 'retry password', they can not enter a blank password. In any
|
||||
* other mode, we let them enter a blank password if the state already
|
||||
* has a password.
|
||||
*/
|
||||
if (passwordIsEmpty && (!mState.hasPassword() ||
|
||||
mMode == MODE_RETRY_PASSWORD) &&
|
||||
(mState.security != null) &&
|
||||
!mState.security.equals(AccessPointState.OPEN) &&
|
||||
!mState.isEnterprise()) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.error_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(R.string.wifi_password_incorrect_error)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!passwordIsEmpty) {
|
||||
mState.setPassword(password);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSave() {
|
||||
replaceStateWithWifiLayerInstance();
|
||||
|
||||
String ssid = mSsidEdit.getText().toString();
|
||||
String password = mPasswordEdit.getText().toString();
|
||||
|
||||
mState.setSsid(ssid);
|
||||
|
||||
int securityType = getSecurityTypeFromSpinner();
|
||||
|
||||
if (!TextUtils.isEmpty(password) && (securityType != SECURITY_WEP)) {
|
||||
mState.setPassword(password);
|
||||
}
|
||||
|
||||
switch (securityType) {
|
||||
case SECURITY_PSK: {
|
||||
mState.setSecurity(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_AUTO: {
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_WEP: {
|
||||
mState.setSecurity(AccessPointState.WEP);
|
||||
mState.setPassword(password, WEP_TYPE_VALUES[
|
||||
mWepTypeSpinner.getSelectedItemPosition()]);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_EAP:
|
||||
mState.setSecurity(AccessPointState.EAP);
|
||||
break;
|
||||
|
||||
case SECURITY_NONE:
|
||||
default:
|
||||
mState.setSecurity(AccessPointState.OPEN);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mState.isEnterprise() && !mState.configured) {
|
||||
updateEnterpriseFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* AP state on the current scan list needs update to enable "Forget" capability.
|
||||
* This is not required for newly added APs.
|
||||
*/
|
||||
AccessPointState ap = mWifiLayer.getWifiLayerApInstance(mState);
|
||||
if(ap != null) {
|
||||
ap.setConfigured(true);
|
||||
}
|
||||
|
||||
if (!mWifiLayer.saveNetwork(mState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Connect right away if they've touched it
|
||||
if (!mWifiLayer.connectToNetwork(mState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getSelectionIndex(String[] array, String selection) {
|
||||
if(selection != null) {
|
||||
for (int i = 0 ; i < array.length ; i++) {
|
||||
if (selection.contains(array[i])) return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getSelectionIndex(int arrayResId, String selection) {
|
||||
return getSelectionIndex(
|
||||
getContext().getResources().getStringArray(arrayResId), selection);
|
||||
}
|
||||
|
||||
private void updateEnterpriseFields() {
|
||||
int i;
|
||||
String value;
|
||||
for (i = AccessPointState.IDENTITY ;
|
||||
i <= AccessPointState.ANONYMOUS_IDENTITY ; i++) {
|
||||
value = mEnterpriseTextFields[i].getText().toString();
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
mState.setEnterpriseField(i, value);
|
||||
}
|
||||
}
|
||||
Spinner spinner = mClientCertSpinner;
|
||||
int index = spinner.getSelectedItemPosition();
|
||||
if (index != (spinner.getCount() - 1)) {
|
||||
String key = (String) spinner.getSelectedItem();
|
||||
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
|
||||
KEYSTORE_HEADER + Credentials.USER_CERTIFICATE + key);
|
||||
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
|
||||
KEYSTORE_HEADER + Credentials.USER_PRIVATE_KEY + key);
|
||||
}
|
||||
spinner = mCaCertSpinner;
|
||||
index = spinner.getSelectedItemPosition();
|
||||
if (index != (spinner.getCount() - 1)) {
|
||||
String key = (String) spinner.getSelectedItem();
|
||||
mState.setEnterpriseField(AccessPointState.CA_CERT,
|
||||
KEYSTORE_HEADER + Credentials.CA_CERTIFICATE + key);
|
||||
}
|
||||
mState.setSecurity(AccessPointState.EAP);
|
||||
mState.setEap(mEapSpinner.getSelectedItemPosition());
|
||||
mState.setPhase2((String) mPhase2Spinner.getSelectedItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces our {@link #mState} with the equal WifiLayer instance. This is useful after
|
||||
* we unparceled the state previously and before we are calling methods on {@link #mWifiLayer}.
|
||||
*
|
||||
* @return Whether WifiLayer was able to find an equal state in its set.
|
||||
*/
|
||||
private boolean replaceStateWithWifiLayerInstance() {
|
||||
AccessPointState state = mWifiLayer.getWifiLayerApInstance(mState);
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mState = state;
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getSecurityTypeFromSpinner() {
|
||||
int position = mSecuritySpinner.getSelectedItemPosition();
|
||||
// If there is no AUTO choice, the position needs 1 added to get
|
||||
// to the proper spinner position -> security constants mapping
|
||||
return mAutoSecurityAllowed ? position : position + 1;
|
||||
}
|
||||
|
||||
private String getEnteredPassword() {
|
||||
return mPasswordEdit != null ? mPasswordEdit.getText().toString() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the one you want to hide first.
|
||||
*/
|
||||
private void setWepVisible(boolean visible) {
|
||||
setGenericPasswordVisible(visible);
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
mWepTypeSpinner.setVisibility(visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #setWepVisible(boolean)
|
||||
*/
|
||||
private void setGenericPasswordVisible(boolean visible) {
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
mPasswordText.setVisibility(visibility);
|
||||
mPasswordEdit.setVisibility(visibility);
|
||||
mShowPasswordCheckBox.setVisibility(visibility);
|
||||
}
|
||||
|
||||
private void setEnterpriseFieldsVisible(boolean visible) {
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
mEnterpriseView.setVisibility(visibility);
|
||||
if (visible) {
|
||||
setWepVisible(false);
|
||||
}
|
||||
if (mMode != MODE_CONFIGURE) {
|
||||
mSsidText.setVisibility(View.GONE);
|
||||
mSsidEdit.setVisibility(View.GONE);
|
||||
mSecurityText.setVisibility(View.GONE);
|
||||
mSecuritySpinner.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void onItemSelected(AdapterView parent, View view, int position, long id) {
|
||||
if (parent == mSecuritySpinner) {
|
||||
handleSecurityChange(getSecurityTypeFromSpinner());
|
||||
}
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView parent) {
|
||||
}
|
||||
|
||||
private void handleSecurityChange(int security) {
|
||||
setEnterpriseFieldsVisible(false);
|
||||
switch (security) {
|
||||
|
||||
case SECURITY_NONE: {
|
||||
setWepVisible(false);
|
||||
setGenericPasswordVisible(false);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_WEP: {
|
||||
setGenericPasswordVisible(false);
|
||||
setWepVisible(true);
|
||||
updatePasswordCaption(AccessPointState.WEP);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_AUTO: {
|
||||
setWepVisible(false);
|
||||
setGenericPasswordVisible(mState.hasSecurity());
|
||||
// Shows the generic 'wireless password'
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECURITY_PSK: {
|
||||
setWepVisible(false);
|
||||
setGenericPasswordVisible(true);
|
||||
// Both WPA and WPA2 show the same caption, so either is ok
|
||||
updatePasswordCaption(AccessPointState.PSK);
|
||||
break;
|
||||
}
|
||||
case SECURITY_EAP: {
|
||||
// Unlock the keystore if it is not unlocked yet.
|
||||
if (mKeyStore.test() != KeyStore.NO_ERROR) {
|
||||
Credentials.getInstance().unlock(getContext());
|
||||
return;
|
||||
}
|
||||
enableEnterpriseFields();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getSignalResId(int signal) {
|
||||
switch (WifiManager.calculateSignalLevel(signal, 4)) {
|
||||
case 0: {
|
||||
return R.string.wifi_signal_0;
|
||||
}
|
||||
case 1: {
|
||||
return R.string.wifi_signal_1;
|
||||
}
|
||||
case 2: {
|
||||
return R.string.wifi_signal_2;
|
||||
}
|
||||
case 3: {
|
||||
return R.string.wifi_signal_3;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public void onClick(View v) {
|
||||
if (v == mShowPasswordCheckBox) {
|
||||
setShowPassword(mShowPasswordCheckBox.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
private void setShowPassword(boolean showPassword) {
|
||||
if (mPasswordEdit != null) {
|
||||
mPasswordEdit.setInputType(InputType.TYPE_CLASS_TEXT |
|
||||
(showPassword ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||
: InputType.TYPE_TEXT_VARIATION_PASSWORD));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.net.wifi.WifiManager;
|
||||
import android.preference.Preference;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class AccessPointPreference extends Preference implements
|
||||
AccessPointState.AccessPointStateCallback {
|
||||
|
||||
// UI states
|
||||
private static final int[] STATE_ENCRYPTED = { R.attr.state_encrypted };
|
||||
private static final int[] STATE_EMPTY = { };
|
||||
|
||||
// Signal strength indicator
|
||||
private static final int UI_SIGNAL_LEVELS = 4;
|
||||
|
||||
private AccessPointState mState;
|
||||
|
||||
public AccessPointPreference(WifiSettings wifiSettings, AccessPointState state) {
|
||||
super(wifiSettings, null);
|
||||
|
||||
mState = state;
|
||||
|
||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
||||
|
||||
state.setCallback(this);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
setTitle(mState.ssid);
|
||||
setSummary(mState.getSummarizedStatus());
|
||||
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void refreshAccessPointState() {
|
||||
refresh();
|
||||
|
||||
// The ordering of access points could have changed due to the state change, so
|
||||
// re-evaluate ordering
|
||||
notifyHierarchyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
|
||||
ImageView signal = (ImageView) view.findViewById(R.id.signal);
|
||||
if (mState.seen) {
|
||||
signal.setImageResource(R.drawable.wifi_signal);
|
||||
signal.setImageState(mState.hasSecurity() ? STATE_ENCRYPTED : STATE_EMPTY, true);
|
||||
signal.setImageLevel(getUiSignalLevel());
|
||||
} else {
|
||||
signal.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
private int getUiSignalLevel() {
|
||||
return mState != null ? WifiManager.calculateSignalLevel(mState.signal, UI_SIGNAL_LEVELS)
|
||||
: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link AccessPointState} associated with this preference.
|
||||
* @return The {@link AccessPointState}.
|
||||
*/
|
||||
public AccessPointState getAccessPointState() {
|
||||
return mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Preference another) {
|
||||
if (!(another instanceof AccessPointPreference)) {
|
||||
// Let normal preferences go before us.
|
||||
// NOTE: we should only be compared to Preference in our
|
||||
// category.
|
||||
return 1;
|
||||
}
|
||||
|
||||
return mState.compareTo(((AccessPointPreference) another).mState);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,878 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.content.Context;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||
import android.net.wifi.WifiConfiguration.GroupCipher;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiConfiguration.PairwiseCipher;
|
||||
import android.net.wifi.WifiConfiguration.Protocol;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public final class AccessPointState implements Comparable<AccessPointState>, Parcelable {
|
||||
|
||||
private static final String TAG = "AccessPointState";
|
||||
|
||||
// Constants used for different security types
|
||||
public static final String PSK = "PSK";
|
||||
public static final String WEP = "WEP";
|
||||
public static final String EAP = "EAP";
|
||||
public static final String OPEN = "Open";
|
||||
|
||||
public static final String[] EAP_METHOD = { "PEAP", "TLS", "TTLS" };
|
||||
|
||||
/** String present in capabilities if the scan result is ad-hoc */
|
||||
private static final String ADHOC_CAPABILITY = "[IBSS]";
|
||||
/** String present in capabilities if the scan result is enterprise secured */
|
||||
private static final String ENTERPRISE_CAPABILITY = "-EAP-";
|
||||
|
||||
public static final String BSSID_ANY = "any";
|
||||
public static final int NETWORK_ID_NOT_SET = -1;
|
||||
/** This should be used with care! */
|
||||
static final int NETWORK_ID_ANY = -2;
|
||||
|
||||
public static final int MATCH_NONE = 0;
|
||||
public static final int MATCH_WEAK = 1;
|
||||
public static final int MATCH_STRONG = 2;
|
||||
public static final int MATCH_EXACT = 3;
|
||||
|
||||
// Don't set these directly, use the setters.
|
||||
public int networkId;
|
||||
public int priority;
|
||||
public boolean hiddenSsid;
|
||||
public int linkSpeed;
|
||||
public int ipAddress;
|
||||
public String bssid;
|
||||
public String ssid;
|
||||
public int signal;
|
||||
public boolean primary;
|
||||
public boolean seen;
|
||||
public boolean configured;
|
||||
public NetworkInfo.DetailedState status;
|
||||
public String security;
|
||||
public boolean disabled;
|
||||
|
||||
/**
|
||||
* Use this for sorting based on signal strength. It is a heavily-damped
|
||||
* time-averaged weighted signal.
|
||||
*/
|
||||
private float signalForSorting = Float.MIN_VALUE;
|
||||
|
||||
private static final float DAMPING_FACTOR = 0.2f;
|
||||
|
||||
/**
|
||||
* This will be a user entered password, and NOT taken from wpa_supplicant
|
||||
* (since it would give us *)
|
||||
*/
|
||||
private String mPassword;
|
||||
private boolean mConfigHadPassword;
|
||||
|
||||
public static final int WEP_PASSWORD_AUTO = 0;
|
||||
public static final int WEP_PASSWORD_ASCII = 1;
|
||||
public static final int WEP_PASSWORD_HEX = 2;
|
||||
private int mWepPasswordType;
|
||||
|
||||
/* Enterprise Fields */
|
||||
public static final int IDENTITY = 0;
|
||||
public static final int ANONYMOUS_IDENTITY = 1;
|
||||
public static final int CLIENT_CERT = 2;
|
||||
public static final int CA_CERT = 3;
|
||||
public static final int PRIVATE_KEY = 4;
|
||||
public static final int MAX_ENTRPRISE_FIELD = 5;
|
||||
private String mEnterpriseFields[] = new String[MAX_ENTRPRISE_FIELD];
|
||||
private String mEap;
|
||||
private String mPhase2;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
/**
|
||||
* If > 0, don't refresh (changes are being batched), use
|
||||
* {@link #blockRefresh()} and {@link #unblockRefresh()} only.
|
||||
*/
|
||||
private int mBlockRefresh;
|
||||
/**
|
||||
* This will be set by {@link #requestRefresh} and shouldn't be written to
|
||||
* elsewhere.
|
||||
*/
|
||||
private boolean mNeedsRefresh;
|
||||
|
||||
private AccessPointStateCallback mCallback;
|
||||
|
||||
private StringBuilder mSummaryBuilder = new StringBuilder();
|
||||
|
||||
interface AccessPointStateCallback {
|
||||
void refreshAccessPointState();
|
||||
}
|
||||
|
||||
public AccessPointState(Context context) {
|
||||
this();
|
||||
|
||||
setContext(context);
|
||||
}
|
||||
|
||||
private AccessPointState() {
|
||||
bssid = BSSID_ANY;
|
||||
ssid = "";
|
||||
networkId = NETWORK_ID_NOT_SET;
|
||||
hiddenSsid = false;
|
||||
}
|
||||
|
||||
void setContext(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void setNetworkId(int networkId) {
|
||||
this.networkId = networkId;
|
||||
}
|
||||
|
||||
public void setBssid(String bssid) {
|
||||
if (bssid != null) {
|
||||
// If the BSSID is a wildcard, do NOT let a specific BSSID replace it
|
||||
if (!this.bssid.equals(BSSID_ANY)) {
|
||||
this.bssid = bssid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getWpaSupplicantBssid() {
|
||||
return bssid.equals(BSSID_ANY) ? null : bssid;
|
||||
}
|
||||
|
||||
public static String convertToQuotedString(String string) {
|
||||
if (TextUtils.isEmpty(string)) {
|
||||
return "";
|
||||
}
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
|
||||
public void setPrimary(boolean primary) {
|
||||
if (this.primary != primary) {
|
||||
this.primary = primary;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSeen(boolean seen) {
|
||||
if (this.seen != seen) {
|
||||
this.seen = seen;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
if (this.disabled != disabled) {
|
||||
this.disabled = disabled;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSignal(int signal) {
|
||||
|
||||
if (signalForSorting == Float.MIN_VALUE) {
|
||||
signalForSorting = signal;
|
||||
} else {
|
||||
signalForSorting = (DAMPING_FACTOR * signal) + ((1-DAMPING_FACTOR) * signalForSorting);
|
||||
}
|
||||
|
||||
if (this.signal != signal) {
|
||||
this.signal = signal;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSsid(String ssid) {
|
||||
if (ssid != null) {
|
||||
this.ssid = ssid;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPriority(int priority) {
|
||||
if (this.priority != priority) {
|
||||
this.priority = priority;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setHiddenSsid(boolean hiddenSsid) {
|
||||
if (this.hiddenSsid != hiddenSsid) {
|
||||
this.hiddenSsid = hiddenSsid;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLinkSpeed(int linkSpeed) {
|
||||
if (this.linkSpeed != linkSpeed) {
|
||||
this.linkSpeed = linkSpeed;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setIpAddress(int address) {
|
||||
if (ipAddress != address) {
|
||||
ipAddress = address;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfigured(boolean configured) {
|
||||
if (this.configured != configured) {
|
||||
this.configured = configured;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatus(NetworkInfo.DetailedState status) {
|
||||
if (this.status != status) {
|
||||
this.status = status;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnterprise() {
|
||||
return (AccessPointState.EAP.equals(security));
|
||||
}
|
||||
|
||||
public void setSecurity(String security) {
|
||||
if (TextUtils.isEmpty(this.security) || !this.security.equals(security)) {
|
||||
this.security = security;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSecurity() {
|
||||
return security != null && !security.contains(OPEN);
|
||||
}
|
||||
|
||||
public String getHumanReadableSecurity() {
|
||||
if (security.equals(OPEN)) return mContext.getString(R.string.wifi_security_open);
|
||||
else if (security.equals(WEP)) return mContext.getString(R.string.wifi_security_wep);
|
||||
else if (security.equals(PSK)) return mContext.getString(R.string.wifi_security_psk);
|
||||
else if (security.equals(EAP)) return mContext.getString(R.string.wifi_security_eap);
|
||||
|
||||
return mContext.getString(R.string.wifi_security_unknown);
|
||||
}
|
||||
|
||||
public void updateFromScanResult(ScanResult scanResult) {
|
||||
blockRefresh();
|
||||
|
||||
// We don't keep specific AP BSSIDs and instead leave that as wildcard
|
||||
|
||||
setSeen(true);
|
||||
setSsid(scanResult.SSID);
|
||||
if (networkId == NETWORK_ID_NOT_SET) {
|
||||
// Since ScanResults don't cross-reference network ID, we set it as a wildcard
|
||||
setNetworkId(NETWORK_ID_ANY);
|
||||
}
|
||||
setSignal(scanResult.level);
|
||||
setSecurity(getScanResultSecurity(scanResult));
|
||||
unblockRefresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The security of a given {@link ScanResult}.
|
||||
*/
|
||||
public static String getScanResultSecurity(ScanResult scanResult) {
|
||||
final String cap = scanResult.capabilities;
|
||||
final String[] securityModes = { WEP, PSK, EAP };
|
||||
for (int i = securityModes.length - 1; i >= 0; i--) {
|
||||
if (cap.contains(securityModes[i])) {
|
||||
return securityModes[i];
|
||||
}
|
||||
}
|
||||
|
||||
return OPEN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the given ScanResult represents an adhoc network.
|
||||
*/
|
||||
public static boolean isAdhoc(ScanResult scanResult) {
|
||||
return scanResult.capabilities.contains(ADHOC_CAPABILITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether the given ScanResult has enterprise security.
|
||||
*/
|
||||
public static boolean isEnterprise(ScanResult scanResult) {
|
||||
return scanResult.capabilities.contains(ENTERPRISE_CAPABILITY);
|
||||
}
|
||||
|
||||
public void updateFromWifiConfiguration(WifiConfiguration wifiConfig) {
|
||||
if (wifiConfig != null) {
|
||||
blockRefresh();
|
||||
setBssid(wifiConfig.BSSID);
|
||||
setNetworkId(wifiConfig.networkId);
|
||||
setPriority(wifiConfig.priority);
|
||||
setHiddenSsid(wifiConfig.hiddenSSID);
|
||||
setSsid(wifiConfig.SSID);
|
||||
setConfigured(true);
|
||||
setDisabled(wifiConfig.status == WifiConfiguration.Status.DISABLED);
|
||||
parseWifiConfigurationSecurity(wifiConfig);
|
||||
unblockRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
setPassword(password, WEP_PASSWORD_AUTO);
|
||||
}
|
||||
|
||||
public void setPassword(String password, int wepPasswordType) {
|
||||
mPassword = password;
|
||||
mWepPasswordType = wepPasswordType;
|
||||
}
|
||||
|
||||
/* For Enterprise Fields */
|
||||
public void setEnterpriseField(int field, String value) {
|
||||
if ((value != null) && (field >= 0) && (field < MAX_ENTRPRISE_FIELD)) {
|
||||
this.mEnterpriseFields[field] = value;
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPhase2(String phase2) {
|
||||
if (!TextUtils.isEmpty(phase2) && (!phase2.equals("None"))) {
|
||||
mPhase2 = phase2;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPhase2() {
|
||||
return mPhase2;
|
||||
}
|
||||
|
||||
public void setEap(int method) {
|
||||
mEap = EAP_METHOD[method];
|
||||
requestRefresh();
|
||||
}
|
||||
|
||||
public String getEap() {
|
||||
return mEap;
|
||||
}
|
||||
public String getEnterpriseField(int field) {
|
||||
if(field >=0 && field < MAX_ENTRPRISE_FIELD) {
|
||||
return mEnterpriseFields[field];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPassword() {
|
||||
return !TextUtils.isEmpty(mPassword) || mConfigHadPassword;
|
||||
}
|
||||
|
||||
private static boolean hasPassword(WifiConfiguration wifiConfig) {
|
||||
return !TextUtils.isEmpty(wifiConfig.preSharedKey)
|
||||
|| !TextUtils.isEmpty(wifiConfig.wepKeys[0])
|
||||
|| !TextUtils.isEmpty(wifiConfig.wepKeys[1])
|
||||
|| !TextUtils.isEmpty(wifiConfig.wepKeys[2])
|
||||
|| !TextUtils.isEmpty(wifiConfig.wepKeys[3]);
|
||||
}
|
||||
|
||||
private void parseWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
|
||||
setSecurity(getWifiConfigurationSecurity(wifiConfig));
|
||||
mConfigHadPassword = hasPassword(wifiConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The security of a given {@link WifiConfiguration}.
|
||||
*/
|
||||
public static String getWifiConfigurationSecurity(WifiConfiguration wifiConfig) {
|
||||
if (!TextUtils.isEmpty(wifiConfig.eap.value())) {
|
||||
return EAP;
|
||||
} else if (!TextUtils.isEmpty(wifiConfig.preSharedKey)) {
|
||||
return PSK;
|
||||
} else if (!TextUtils.isEmpty(wifiConfig.wepKeys[0])) {
|
||||
return WEP;
|
||||
}
|
||||
return OPEN;
|
||||
}
|
||||
|
||||
public void updateFromWifiInfo(WifiInfo wifiInfo, NetworkInfo.DetailedState state) {
|
||||
if (wifiInfo != null) {
|
||||
blockRefresh();
|
||||
setBssid(wifiInfo.getBSSID());
|
||||
setLinkSpeed(wifiInfo.getLinkSpeed());
|
||||
setNetworkId(wifiInfo.getNetworkId());
|
||||
setIpAddress(wifiInfo.getIpAddress());
|
||||
setSsid(wifiInfo.getSSID());
|
||||
if (state != null) {
|
||||
setStatus(state);
|
||||
}
|
||||
setHiddenSsid(wifiInfo.getHiddenSSID());
|
||||
unblockRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether this AP can be connected to at the moment.
|
||||
*/
|
||||
public boolean isConnectable() {
|
||||
return !primary && seen;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether this AP can be forgotten at the moment.
|
||||
*/
|
||||
public boolean isForgetable() {
|
||||
return configured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state as if it were never configured.
|
||||
* <p>
|
||||
* Note: This will not pass the forget call to the Wi-Fi API.
|
||||
*/
|
||||
public void forget() {
|
||||
blockRefresh();
|
||||
setConfigured(false);
|
||||
setNetworkId(NETWORK_ID_NOT_SET);
|
||||
setPrimary(false);
|
||||
setStatus(null);
|
||||
setDisabled(false);
|
||||
unblockRefresh();
|
||||
}
|
||||
|
||||
public void updateWifiConfiguration(WifiConfiguration config) {
|
||||
config.BSSID = getWpaSupplicantBssid();
|
||||
config.priority = priority;
|
||||
config.hiddenSSID = hiddenSsid;
|
||||
config.SSID = ssid;
|
||||
config.eap.setValue(mEap);
|
||||
|
||||
if (!TextUtils.isEmpty(mPhase2)) {
|
||||
config.phase2.setValue("auth=" + mPhase2);
|
||||
} else {
|
||||
config.phase2.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[IDENTITY])) {
|
||||
config.identity.setValue(mEnterpriseFields[IDENTITY]);
|
||||
} else {
|
||||
config.identity.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[ANONYMOUS_IDENTITY])) {
|
||||
config.anonymous_identity.setValue(
|
||||
mEnterpriseFields[ANONYMOUS_IDENTITY]);
|
||||
} else {
|
||||
config.anonymous_identity.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[CLIENT_CERT])) {
|
||||
config.client_cert.setValue(
|
||||
mEnterpriseFields[CLIENT_CERT]);
|
||||
} else {
|
||||
config.client_cert.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[CA_CERT])) {
|
||||
config.ca_cert.setValue(
|
||||
mEnterpriseFields[CA_CERT]);
|
||||
} else {
|
||||
config.ca_cert.setValue(null);
|
||||
}
|
||||
if (!TextUtils.isEmpty(mEnterpriseFields[PRIVATE_KEY])) {
|
||||
config.private_key.setValue(
|
||||
mEnterpriseFields[PRIVATE_KEY]);
|
||||
} else {
|
||||
config.private_key.setValue(null);
|
||||
}
|
||||
setupSecurity(config);
|
||||
}
|
||||
|
||||
private void setupSecurity(WifiConfiguration config) {
|
||||
config.allowedAuthAlgorithms.clear();
|
||||
config.allowedGroupCiphers.clear();
|
||||
config.allowedKeyManagement.clear();
|
||||
config.allowedPairwiseCiphers.clear();
|
||||
config.allowedProtocols.clear();
|
||||
|
||||
if (TextUtils.isEmpty(security)) {
|
||||
security = OPEN;
|
||||
Log.w(TAG, "Empty security, assuming open");
|
||||
}
|
||||
|
||||
if (security.equals(WEP)) {
|
||||
// If password is empty, it should be left untouched
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
if (mWepPasswordType == WEP_PASSWORD_AUTO) {
|
||||
if (isHexWepKey(mPassword)) {
|
||||
config.wepKeys[0] = mPassword;
|
||||
} else {
|
||||
config.wepKeys[0] = convertToQuotedString(mPassword);
|
||||
}
|
||||
} else {
|
||||
config.wepKeys[0] = mWepPasswordType == WEP_PASSWORD_ASCII
|
||||
? convertToQuotedString(mPassword)
|
||||
: mPassword;
|
||||
}
|
||||
}
|
||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
config.wepTxKeyIndex = 0;
|
||||
} else if (security.equals(PSK)){
|
||||
// If password is empty, it should be left untouched
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
if (mPassword.length() == 64 && isHex(mPassword)) {
|
||||
// Goes unquoted as hex
|
||||
config.preSharedKey = mPassword;
|
||||
} else {
|
||||
// Goes quoted as ASCII
|
||||
config.preSharedKey = convertToQuotedString(mPassword);
|
||||
}
|
||||
}
|
||||
} else if (security.equals(EAP)) {
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
|
||||
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
|
||||
if (!TextUtils.isEmpty(mPassword)) {
|
||||
config.password.setValue(mPassword);
|
||||
}
|
||||
} else if (security.equals(OPEN)) {
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isHexWepKey(String wepKey) {
|
||||
final int len = wepKey.length();
|
||||
|
||||
// WEP-40, WEP-104, and some vendors using 256-bit WEP (WEP-232?)
|
||||
if (len != 10 && len != 26 && len != 58) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isHex(wepKey);
|
||||
}
|
||||
|
||||
private static boolean isHex(String key) {
|
||||
for (int i = key.length() - 1; i >= 0; i--) {
|
||||
final char c = key.charAt(i);
|
||||
if (!(c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCallback(AccessPointStateCallback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
void blockRefresh() {
|
||||
mBlockRefresh++;
|
||||
}
|
||||
|
||||
void unblockRefresh() {
|
||||
if (--mBlockRefresh == 0 && mNeedsRefresh) {
|
||||
requestRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void requestRefresh() {
|
||||
if (mBlockRefresh > 0) {
|
||||
mNeedsRefresh = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCallback != null) {
|
||||
mCallback.refreshAccessPointState();
|
||||
}
|
||||
|
||||
mNeedsRefresh = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see #hashCode()
|
||||
* @see #equals(Object)
|
||||
*/
|
||||
public int matches(int otherNetworkId, String otherBssid, String otherSsid,
|
||||
String otherSecurity) {
|
||||
|
||||
// Whenever this method is touched, please ensure #equals and #hashCode
|
||||
// still work with the changes here!
|
||||
|
||||
if (otherSsid == null) {
|
||||
if (WifiLayer.LOGV) {
|
||||
Log.w(TAG, "BSSID: " + otherBssid + ", SSID: " + otherSsid);
|
||||
}
|
||||
return MATCH_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we both have 'security' set, it must match (an open network still
|
||||
* has 'security' set to OPEN)
|
||||
*/
|
||||
if (security != null && otherSecurity != null) {
|
||||
if (!security.equals(otherSecurity)) {
|
||||
return MATCH_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
// WifiConfiguration gives an empty bssid as a BSSID wildcard
|
||||
if (TextUtils.isEmpty(otherBssid)) {
|
||||
otherBssid = AccessPointState.BSSID_ANY;
|
||||
}
|
||||
|
||||
final boolean networkIdMatches = networkId == otherNetworkId;
|
||||
if (!networkIdMatches && networkId != NETWORK_ID_ANY && otherNetworkId != NETWORK_ID_ANY) {
|
||||
// Network IDs don't match (e.g., 1 & 2 or unset & 1) and neither is a wildcard
|
||||
return MATCH_NONE;
|
||||
}
|
||||
|
||||
if (networkIdMatches && otherNetworkId != NETWORK_ID_NOT_SET
|
||||
&& otherNetworkId != NETWORK_ID_ANY) {
|
||||
// Network ID matches (they're set to the same ID)
|
||||
return MATCH_EXACT;
|
||||
}
|
||||
|
||||
// So now, network IDs aren't set or at least one is a wildcard
|
||||
|
||||
final boolean bssidMatches = bssid.equals(otherBssid);
|
||||
final boolean otherBssidIsWildcard = otherBssid.equals(BSSID_ANY);
|
||||
if (bssidMatches && !otherBssidIsWildcard) {
|
||||
// BSSID matches (and neither is a wildcard)
|
||||
return MATCH_STRONG;
|
||||
}
|
||||
|
||||
if (!bssidMatches && !bssid.equals(BSSID_ANY) && !otherBssidIsWildcard) {
|
||||
// BSSIDs don't match (e.g., 00:24:21:21:42:12 & 42:12:44:21:22:52)
|
||||
// and neither is a wildcard
|
||||
return MATCH_NONE;
|
||||
}
|
||||
|
||||
// So now, BSSIDs are both wildcards
|
||||
|
||||
final boolean ssidMatches = ssid.equals(otherSsid);
|
||||
if (ssidMatches) {
|
||||
// SSID matches
|
||||
return MATCH_WEAK;
|
||||
}
|
||||
|
||||
return MATCH_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see #matches(int, String, String)
|
||||
* @see #equals(Object)
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Two equal() objects must have same hashCode.
|
||||
// With Wi-Fi, the broadest match is if two SSIDs are the same. The finer-grained matches
|
||||
// imply this (for example, the same network IDs means the same WifiConfiguration which
|
||||
// means the same SSID).
|
||||
// See #matches for the exact matching algorithm we use.
|
||||
return ssid != null ? ssid.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @see #matches(int, String, String)
|
||||
* @see #hashCode()
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!o.getClass().equals(getClass())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final AccessPointState other = (AccessPointState) o;
|
||||
|
||||
// To see which conditions cause two AccessPointStates to be equal, see
|
||||
// where #matches returns MATCH_WEAK or greater.
|
||||
|
||||
return matches(other.networkId, other.bssid, other.ssid, other.security) >= MATCH_WEAK;
|
||||
}
|
||||
|
||||
public int matchesWifiConfiguration(WifiConfiguration wifiConfig) {
|
||||
String security = getWifiConfigurationSecurity(wifiConfig);
|
||||
return matches(wifiConfig.networkId, wifiConfig.BSSID, wifiConfig.SSID, security);
|
||||
}
|
||||
|
||||
String getSummarizedStatus() {
|
||||
StringBuilder sb = mSummaryBuilder;
|
||||
sb.delete(0, sb.length());
|
||||
|
||||
if (primary && status != null) {
|
||||
buildSummary(sb, WifiStatus.getPrintable(mContext, status), true);
|
||||
|
||||
} else if (!seen) {
|
||||
buildSummary(sb, mContext.getString(R.string.summary_not_in_range), true);
|
||||
|
||||
// Remembered comes second in this case
|
||||
if (!primary && configured) {
|
||||
buildSummary(sb, mContext.getString(R.string.summary_remembered), true);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (configured && disabled) {
|
||||
// The connection failure overrides all in this case
|
||||
return mContext.getString(R.string.summary_connection_failed);
|
||||
}
|
||||
|
||||
// Remembered comes first in this case
|
||||
if (!primary && configured) {
|
||||
buildSummary(sb, mContext.getString(R.string.summary_remembered), true);
|
||||
}
|
||||
|
||||
// If it is seen (and not the primary), show the security type
|
||||
String verboseSecurity = getVerboseSecurity();
|
||||
if (verboseSecurity != null) {
|
||||
buildSummary(sb, verboseSecurity, true);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getVerboseSecurity() {
|
||||
if (WEP.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_wep);
|
||||
} else if (PSK.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_psk);
|
||||
} else if (EAP.equals(security)) {
|
||||
return mContext.getString(R.string.wifi_security_verbose_eap);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buildSummary(StringBuilder sb, String string, boolean autoUpperCaseFirstLetter) {
|
||||
if (sb.length() == 0) {
|
||||
if (autoUpperCaseFirstLetter && string.length() > 1
|
||||
&& Character.isLowerCase(string.charAt(0))
|
||||
&& !Character.isUpperCase(string.charAt(1))) {
|
||||
sb.append(Character.toUpperCase(string.charAt(0))).append(string, 1,
|
||||
string.length());
|
||||
} else {
|
||||
sb.append(string);
|
||||
}
|
||||
} else {
|
||||
sb.append(", ");
|
||||
sb.append(string);
|
||||
}
|
||||
}
|
||||
|
||||
public int compareTo(AccessPointState other) {
|
||||
// This ranks the states for displaying in the AP list, not for
|
||||
// connecting to (wpa_supplicant does that using the WifiConfiguration's
|
||||
// priority field).
|
||||
|
||||
// Clarity > efficiency, of this logic:
|
||||
int comparison;
|
||||
|
||||
// Primary
|
||||
comparison = (other.primary ? 1 : 0) - (primary ? 1 : 0);
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
// Currently seen (similar to, but not always the same as within range)
|
||||
comparison = (other.seen ? 1 : 0) - (seen ? 1 : 0);
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
// Configured
|
||||
comparison = (other.configured ? 1 : 0) - (configured ? 1 : 0);
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
if (!configured) {
|
||||
// Neither are configured
|
||||
|
||||
// Open network
|
||||
comparison = (hasSecurity() ? 1 : 0) - (other.hasSecurity() ? 1 : 0);
|
||||
if (comparison != 0) return comparison;
|
||||
}
|
||||
|
||||
// Signal strength
|
||||
comparison = (int) (other.signalForSorting - signalForSorting);
|
||||
if (comparison != 0) return comparison;
|
||||
|
||||
// Alphabetical
|
||||
return ssid.compareToIgnoreCase(other.ssid);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ssid + " (" + bssid + ", " + networkId + ", " + super.toString() + ")";
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(bssid);
|
||||
dest.writeInt(configured ? 1 : 0);
|
||||
dest.writeInt(ipAddress);
|
||||
dest.writeInt(linkSpeed);
|
||||
dest.writeInt(networkId);
|
||||
dest.writeInt(primary ? 1 : 0);
|
||||
dest.writeInt(priority);
|
||||
dest.writeInt(hiddenSsid ? 1 : 0);
|
||||
dest.writeString(security);
|
||||
dest.writeInt(seen ? 1 : 0);
|
||||
dest.writeInt(disabled ? 1 : 0);
|
||||
dest.writeInt(signal);
|
||||
dest.writeString(ssid);
|
||||
dest.writeString(status != null ? status.toString() : null);
|
||||
dest.writeString(mPassword);
|
||||
dest.writeInt(mConfigHadPassword ? 1 : 0);
|
||||
dest.writeInt(mWepPasswordType);
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Implement the Parcelable interface */
|
||||
public static final Creator<AccessPointState> CREATOR =
|
||||
new Creator<AccessPointState>() {
|
||||
public AccessPointState createFromParcel(Parcel in) {
|
||||
AccessPointState state = new AccessPointState();
|
||||
state.bssid = in.readString();
|
||||
state.configured = in.readInt() == 1;
|
||||
state.ipAddress = in.readInt();
|
||||
state.linkSpeed = in.readInt();
|
||||
state.networkId = in.readInt();
|
||||
state.primary = in.readInt() == 1;
|
||||
state.priority = in.readInt();
|
||||
state.hiddenSsid = in.readInt() == 1;
|
||||
state.security = in.readString();
|
||||
state.seen = in.readInt() == 1;
|
||||
state.disabled = in.readInt() == 1;
|
||||
state.signal = in.readInt();
|
||||
state.ssid = in.readString();
|
||||
String statusStr = in.readString();
|
||||
if (statusStr != null) {
|
||||
state.status = NetworkInfo.DetailedState.valueOf(statusStr);
|
||||
}
|
||||
state.mPassword = in.readString();
|
||||
state.mConfigHadPassword = in.readInt() == 1;
|
||||
state.mWepPasswordType = in.readInt();
|
||||
return state;
|
||||
}
|
||||
|
||||
public AccessPointState[] newArray(int size) {
|
||||
return new AccessPointState[size];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,483 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.ProgressCategory;
|
||||
import com.android.settings.R;
|
||||
|
||||
import android.app.Dialog;
|
||||
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.preference.CheckBoxPreference;
|
||||
import android.provider.Settings;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* Settings screen for WiFi. This will be launched from the main system settings.
|
||||
*/
|
||||
public class WifiSettings extends PreferenceActivity implements WifiLayer.Callback,
|
||||
DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String TAG = "WifiSettings";
|
||||
|
||||
//============================
|
||||
// Preference/activity member variables
|
||||
//============================
|
||||
|
||||
private static final String INSTANCE_KEY_DIALOG_BUNDLE =
|
||||
"com.android.settings.wifi.WifiSettings:dialogBundle";
|
||||
/*
|
||||
* We don't use Activity's dialog management because AlertDialog isn't fully
|
||||
* able to change many of its features after it's been created, and the
|
||||
* dialog management only creates once.
|
||||
*/
|
||||
private Dialog mDialog;
|
||||
|
||||
private static final String KEY_ONLY_ACCESS_POINTS = "only_access_points";
|
||||
private static final String KEY_ADD_OTHER_NETWORK = "add_other_network";
|
||||
|
||||
private static final int CONTEXT_MENU_ID_CONNECT = Menu.FIRST;
|
||||
private static final int CONTEXT_MENU_ID_FORGET = Menu.FIRST + 1;
|
||||
private static final int CONTEXT_MENU_ID_CHANGE_PASSWORD = Menu.FIRST + 2;
|
||||
|
||||
private static final int MENU_ID_SCAN = Menu.FIRST;
|
||||
private static final int MENU_ID_ADVANCED = Menu.FIRST + 1;
|
||||
|
||||
private static final String KEY_WIFI_ENABLED = "wifi_enabled";
|
||||
private static final String KEY_OPEN_NETWORK_NOTIFICATIONS_ENABLED =
|
||||
"open_network_notifications_enabled";
|
||||
private static final String KEY_ACCESS_POINTS = "access_points";
|
||||
|
||||
private ProgressCategory mApCategory;
|
||||
private CheckBoxPreference mWifiEnabled;
|
||||
private WifiEnabler mWifiEnabler;
|
||||
private CheckBoxPreference mOpenNetworkNotificationsEnabled;
|
||||
private Preference mAddOtherNetwork;
|
||||
|
||||
private WeakHashMap<AccessPointState, AccessPointPreference> mAps;
|
||||
|
||||
private KeyStore mKeyStore = KeyStore.getInstance();
|
||||
private AccessPointState mResumeState = null;
|
||||
private int mResumeMode;
|
||||
|
||||
//============================
|
||||
// Wifi member variables
|
||||
//============================
|
||||
|
||||
private WifiLayer mWifiLayer;
|
||||
|
||||
//============================
|
||||
// Activity lifecycle
|
||||
//============================
|
||||
|
||||
public WifiSettings() {
|
||||
mAps = new WeakHashMap<AccessPointState, AccessPointPreference>();
|
||||
mWifiLayer = new WifiLayer(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
onCreatePreferences();
|
||||
mWifiLayer.onCreate();
|
||||
|
||||
onCreatedWifi();
|
||||
mWifiLayer.onCreatedCallback();
|
||||
}
|
||||
|
||||
private int getPreferenceResource() {
|
||||
if (getIntent().getBooleanExtra(KEY_ONLY_ACCESS_POINTS, false)) {
|
||||
return R.xml.wifi_access_points;
|
||||
} else {
|
||||
return R.xml.wifi_settings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shouldn't have any dependency on the wifi layer.
|
||||
*/
|
||||
private void onCreatePreferences() {
|
||||
addPreferencesFromResource(getPreferenceResource());
|
||||
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
|
||||
mApCategory = (ProgressCategory) preferenceScreen.findPreference(KEY_ACCESS_POINTS);
|
||||
// We don't want the ordering to be the order preferences are added,
|
||||
// instead we want*:
|
||||
// 1) preferred, visible APs
|
||||
// 2) visible APs
|
||||
// 3) preferred, APs out of range
|
||||
// * this ordering logic is in AccessPointPreference's compareTo
|
||||
mApCategory.setOrderingAsAdded(false);
|
||||
|
||||
if (!getIntent().getBooleanExtra(KEY_ONLY_ACCESS_POINTS, false)) {
|
||||
mWifiEnabled = (CheckBoxPreference) preferenceScreen.findPreference(KEY_WIFI_ENABLED);
|
||||
mWifiEnabler = new WifiEnabler(this, (WifiManager) getSystemService(WIFI_SERVICE),
|
||||
mWifiEnabled);
|
||||
|
||||
mOpenNetworkNotificationsEnabled = (CheckBoxPreference) preferenceScreen
|
||||
.findPreference(KEY_OPEN_NETWORK_NOTIFICATIONS_ENABLED);
|
||||
mOpenNetworkNotificationsEnabled.setChecked(Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
}
|
||||
|
||||
mAddOtherNetwork = preferenceScreen.findPreference(KEY_ADD_OTHER_NETWORK);
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
private void onCreatedWifi() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mWifiLayer.onResume();
|
||||
if (mWifiEnabler != null) {
|
||||
mWifiEnabler.resume();
|
||||
}
|
||||
// do what we should have after keystore is unlocked.
|
||||
if (mResumeState != null) {
|
||||
if (mKeyStore.test() == KeyStore.NO_ERROR) {
|
||||
showAccessPointDialog(mResumeState, mResumeMode);
|
||||
}
|
||||
mResumeMode = -1;
|
||||
mResumeState = null;
|
||||
} else {
|
||||
if (mResumeMode == AccessPointDialog.MODE_CONFIGURE) {
|
||||
if (mKeyStore.test() == KeyStore.NO_ERROR) {
|
||||
((AccessPointDialog) mDialog).enableEnterpriseFields();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mWifiLayer.onPause();
|
||||
if (mWifiEnabler != null) {
|
||||
mWifiEnabler.pause();
|
||||
}
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
|
||||
menu.add(0, MENU_ID_SCAN, 0, R.string.scan_wifi)
|
||||
.setIcon(R.drawable.ic_menu_scan_network);
|
||||
|
||||
menu.add(0, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
||||
.setIcon(android.R.drawable.ic_menu_manage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case MENU_ID_SCAN:
|
||||
mWifiLayer.attemptScan();
|
||||
return true;
|
||||
|
||||
case MENU_ID_ADVANCED:
|
||||
Intent intent = new Intent(this, AdvancedSettings.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
if (mDialog != null) {
|
||||
Bundle dialogBundle = mDialog.onSaveInstanceState();
|
||||
outState.putBundle(INSTANCE_KEY_DIALOG_BUNDLE, dialogBundle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle state) {
|
||||
super.onRestoreInstanceState(state);
|
||||
|
||||
Bundle dialogBundle = state.getBundle(INSTANCE_KEY_DIALOG_BUNDLE);
|
||||
if (dialogBundle != null) {
|
||||
mDialog = new AccessPointDialog(this, mWifiLayer);
|
||||
mDialog.onRestoreInstanceState(dialogBundle);
|
||||
showDialog(mDialog);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (dialog == mDialog) {
|
||||
mDialog = null;
|
||||
mResumeMode = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
||||
AccessPointState state = getStateFromMenuInfo(menuInfo);
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
menu.setHeaderTitle(state.ssid);
|
||||
|
||||
if (state.isConnectable()) {
|
||||
menu.add(0, CONTEXT_MENU_ID_CONNECT, 0, R.string.wifi_context_menu_connect);
|
||||
}
|
||||
|
||||
if (state.isForgetable()) {
|
||||
menu.add(0, CONTEXT_MENU_ID_FORGET, 1, R.string.wifi_context_menu_forget);
|
||||
|
||||
if (state.hasPassword()) {
|
||||
menu.add(0, CONTEXT_MENU_ID_CHANGE_PASSWORD, 2,
|
||||
R.string.wifi_context_menu_change_password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
|
||||
AccessPointState state = getStateFromMenuInfo(item.getMenuInfo());
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case CONTEXT_MENU_ID_CONNECT:
|
||||
connectToNetwork(state);
|
||||
return true;
|
||||
|
||||
case CONTEXT_MENU_ID_FORGET:
|
||||
mWifiLayer.forgetNetwork(state);
|
||||
return true;
|
||||
|
||||
case CONTEXT_MENU_ID_CHANGE_PASSWORD:
|
||||
showAccessPointDialog(state, AccessPointDialog.MODE_CONFIGURE);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides what needs to happen to connect to a particular access point. If
|
||||
* it is secured and doesn't already have a password, it will bring up a
|
||||
* password box. Otherwise it will just connect.
|
||||
*/
|
||||
private void connectToNetwork(AccessPointState state) {
|
||||
if (state.hasSecurity() && !state.hasPassword()) {
|
||||
showAccessPointDialog(state, AccessPointDialog.MODE_INFO);
|
||||
} else {
|
||||
mWifiLayer.connectToNetwork(state);
|
||||
}
|
||||
}
|
||||
|
||||
private AccessPointState getStateFromMenuInfo(ContextMenuInfo menuInfo) {
|
||||
if ((menuInfo == null) || !(menuInfo instanceof AdapterContextMenuInfo)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AdapterContextMenuInfo adapterMenuInfo = (AdapterContextMenuInfo) menuInfo;
|
||||
Preference pref = (Preference) getPreferenceScreen().getRootAdapter().getItem(
|
||||
adapterMenuInfo.position);
|
||||
if (pref == null || !(pref instanceof AccessPointPreference)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ((AccessPointPreference) pref).getAccessPointState();
|
||||
}
|
||||
|
||||
//============================
|
||||
// Preference callbacks
|
||||
//============================
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
|
||||
if (preference == mAddOtherNetwork) {
|
||||
showAddOtherNetworkDialog();
|
||||
} else if (preference == mOpenNetworkNotificationsEnabled) {
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
mOpenNetworkNotificationsEnabled.isChecked() ? 1 : 0);
|
||||
} else if (preference instanceof AccessPointPreference) {
|
||||
AccessPointState state = ((AccessPointPreference) preference).getAccessPointState();
|
||||
showAccessPointDialog(state, AccessPointDialog.MODE_INFO);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//============================
|
||||
// Wifi-related
|
||||
//============================
|
||||
|
||||
public WifiLayer getWifiLayer() {
|
||||
return mWifiLayer;
|
||||
}
|
||||
|
||||
private void showAddOtherNetworkDialog() {
|
||||
AccessPointDialog dialog = new AccessPointDialog(this, mWifiLayer);
|
||||
dialog.setState(new AccessPointState(this));
|
||||
dialog.setMode(AccessPointDialog.MODE_CONFIGURE);
|
||||
dialog.setTitle(R.string.wifi_add_other_network);
|
||||
dialog.setAutoSecurityAllowed(false);
|
||||
mResumeMode = AccessPointDialog.MODE_CONFIGURE;
|
||||
showDialog(dialog);
|
||||
}
|
||||
|
||||
public void showAccessPointDialog(AccessPointState state, int mode) {
|
||||
if (state.isEnterprise() && mKeyStore.test() != KeyStore.NO_ERROR) {
|
||||
Credentials.getInstance().unlock(this);
|
||||
mResumeState = state;
|
||||
mResumeMode = mode;
|
||||
return;
|
||||
}
|
||||
AccessPointDialog dialog = new AccessPointDialog(this, mWifiLayer);
|
||||
dialog.setMode(mode);
|
||||
dialog.setState(state);
|
||||
showDialog(dialog);
|
||||
}
|
||||
|
||||
private void showDialog(Dialog dialog) {
|
||||
// Have only one dialog open at a time
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
||||
mDialog = dialog;
|
||||
if (dialog != null) {
|
||||
dialog.setOnDismissListener(this);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
//============================
|
||||
// Wifi callbacks
|
||||
//============================
|
||||
|
||||
public void onError(int messageResId) {
|
||||
Toast.makeText(this, messageResId, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void onScanningStatusChanged(boolean started) {
|
||||
mApCategory.setProgress(started);
|
||||
}
|
||||
|
||||
public void onAccessPointSetChanged(AccessPointState ap, boolean added) {
|
||||
|
||||
AccessPointPreference pref = mAps.get(ap);
|
||||
|
||||
if (WifiLayer.LOGV) {
|
||||
Log.v(TAG, "onAccessPointSetChanged with " + ap + " and "
|
||||
+ (added ? "added" : "removed") + ", found pref " + pref);
|
||||
}
|
||||
|
||||
if (added) {
|
||||
|
||||
if (pref == null) {
|
||||
pref = new AccessPointPreference(this, ap);
|
||||
mAps.put(ap, pref);
|
||||
} else {
|
||||
pref.setEnabled(true);
|
||||
}
|
||||
|
||||
mApCategory.addPreference(pref);
|
||||
|
||||
} else {
|
||||
|
||||
mAps.remove(ap);
|
||||
|
||||
if (pref != null) {
|
||||
mApCategory.removePreference(pref);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onAccessPointsStateChanged(boolean enabled) {
|
||||
if (enabled) {
|
||||
mApCategory.setEnabled(true);
|
||||
} else {
|
||||
mApCategory.removeAll();
|
||||
mAps.clear();
|
||||
}
|
||||
|
||||
mAddOtherNetwork.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void onRetryPassword(AccessPointState ap) {
|
||||
|
||||
if ((mDialog != null) && mDialog.isShowing()) {
|
||||
// If we're already showing a dialog, ignore this request
|
||||
return;
|
||||
}
|
||||
|
||||
showAccessPointDialog(ap, AccessPointDialog.MODE_RETRY_PASSWORD);
|
||||
}
|
||||
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.content.Context;
|
||||
import android.net.NetworkInfo;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class WifiStatus {
|
||||
public static String getStatus(Context context, String ssid,
|
||||
NetworkInfo.DetailedState detailedState) {
|
||||
|
||||
if (!TextUtils.isEmpty(ssid) && isLiveConnection(detailedState)) {
|
||||
return getPrintableFragment(context, detailedState, ssid);
|
||||
} else {
|
||||
return getPrintable(context, detailedState);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLiveConnection(NetworkInfo.DetailedState detailedState) {
|
||||
return detailedState != NetworkInfo.DetailedState.DISCONNECTED
|
||||
&& detailedState != NetworkInfo.DetailedState.FAILED
|
||||
&& detailedState != NetworkInfo.DetailedState.IDLE
|
||||
&& detailedState != NetworkInfo.DetailedState.SCANNING;
|
||||
}
|
||||
|
||||
public static String getPrintable(Context context,
|
||||
NetworkInfo.DetailedState detailedState) {
|
||||
|
||||
switch (detailedState) {
|
||||
case AUTHENTICATING:
|
||||
return context.getString(R.string.status_authenticating);
|
||||
case CONNECTED:
|
||||
return context.getString(R.string.status_connected);
|
||||
case CONNECTING:
|
||||
return context.getString(R.string.status_connecting);
|
||||
case DISCONNECTED:
|
||||
return context.getString(R.string.status_disconnected);
|
||||
case DISCONNECTING:
|
||||
return context.getString(R.string.status_disconnecting);
|
||||
case FAILED:
|
||||
return context.getString(R.string.status_failed);
|
||||
case OBTAINING_IPADDR:
|
||||
return context.getString(R.string.status_obtaining_ip);
|
||||
case SCANNING:
|
||||
return context.getString(R.string.status_scanning);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPrintableFragment(Context context,
|
||||
NetworkInfo.DetailedState detailedState, String apName) {
|
||||
|
||||
String fragment = null;
|
||||
switch (detailedState) {
|
||||
case AUTHENTICATING:
|
||||
fragment = context.getString(R.string.fragment_status_authenticating);
|
||||
break;
|
||||
case CONNECTED:
|
||||
fragment = context.getString(R.string.fragment_status_connected);
|
||||
break;
|
||||
case CONNECTING:
|
||||
fragment = context.getString(R.string.fragment_status_connecting);
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
fragment = context.getString(R.string.fragment_status_disconnected);
|
||||
break;
|
||||
case DISCONNECTING:
|
||||
fragment = context.getString(R.string.fragment_status_disconnecting);
|
||||
break;
|
||||
case FAILED:
|
||||
fragment = context.getString(R.string.fragment_status_failed);
|
||||
break;
|
||||
case OBTAINING_IPADDR:
|
||||
fragment = context.getString(R.string.fragment_status_obtaining_ip);
|
||||
break;
|
||||
case SCANNING:
|
||||
fragment = context.getString(R.string.fragment_status_scanning);
|
||||
break;
|
||||
}
|
||||
|
||||
return String.format(fragment, apName);
|
||||
}
|
||||
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
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;
|
||||
@@ -295,8 +294,8 @@ public class WifiStatusTest extends Activity {
|
||||
|
||||
private void handleNetworkStateChanged(NetworkInfo networkInfo) {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
String summary = WifiStatus.getStatus(this,
|
||||
mWifiManager.getConnectionInfo().getSSID(), networkInfo.getDetailedState());
|
||||
String summary = Summary.get(this, mWifiManager.getConnectionInfo().getSSID(),
|
||||
networkInfo.getDetailedState());
|
||||
mNetworkState.setText(summary);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user