AdvancedSettings replaced by AdvancedWifiSettings
Change-Id: Ie51d14c9961e8780c8774bbe56e113cf85357817
This commit is contained in:
@@ -157,6 +157,18 @@
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<activity-alias android:name=".wifi.AdvancedSettings"
|
||||
android:label="@string/wifi_advanced_settings_label"
|
||||
android:targetActivity="Settings"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.settings.WIFI_IP_SETTINGS" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<activity android:name=".wifi.WifiInfo"
|
||||
android:theme="@android:style/Theme.Holo.DialogWhenLarge">
|
||||
<intent-filter>
|
||||
@@ -237,7 +249,7 @@
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.settings.BLUETOOTH_ADVANCED_SETTINGS" />
|
||||
<action android:name="android.settings.ADVANCED_BLUETOOTH_SETTINGS" />
|
||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
@@ -1,174 +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 android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
public class AdvancedSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = "AdvancedSettings";
|
||||
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
|
||||
private static final String KEY_FREQUENCY_BAND = "frequency_band";
|
||||
private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
|
||||
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
||||
private static final String KEY_ENABLE_WIFI_WATCHDOG = "wifi_enable_watchdog_service";
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.wifi_advanced_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initPreferences();
|
||||
refreshWifiInfo();
|
||||
}
|
||||
|
||||
private void initPreferences() {
|
||||
CheckBoxPreference notifyOpenNetworks =
|
||||
(CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
|
||||
notifyOpenNetworks.setChecked(Secure.getInt(getContentResolver(),
|
||||
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
|
||||
|
||||
CheckBoxPreference watchdogEnabled =
|
||||
(CheckBoxPreference) findPreference(KEY_ENABLE_WIFI_WATCHDOG);
|
||||
watchdogEnabled.setChecked(Secure.getInt(getContentResolver(),
|
||||
Secure.WIFI_WATCHDOG_ON, 1) == 1);
|
||||
|
||||
watchdogEnabled.setEnabled(mWifiManager.isWifiEnabled());
|
||||
|
||||
ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
|
||||
|
||||
if (mWifiManager.isDualBandSupported()) {
|
||||
frequencyPref.setOnPreferenceChangeListener(this);
|
||||
int value = mWifiManager.getFrequencyBand();
|
||||
if (value != -1) {
|
||||
frequencyPref.setValue(String.valueOf(value));
|
||||
} else {
|
||||
Log.e(TAG, "Failed to fetch frequency band");
|
||||
}
|
||||
} else {
|
||||
if (frequencyPref != null) {
|
||||
// null if it has already been removed before resume
|
||||
getPreferenceScreen().removePreference(frequencyPref);
|
||||
}
|
||||
}
|
||||
|
||||
ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
|
||||
if (sleepPolicyPref != null) {
|
||||
if (Utils.isWifiOnly()) {
|
||||
sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
|
||||
sleepPolicyPref.setSummary(R.string.wifi_setting_sleep_policy_summary_wifi_only);
|
||||
}
|
||||
sleepPolicyPref.setOnPreferenceChangeListener(this);
|
||||
int value = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.WIFI_SLEEP_POLICY,
|
||||
Settings.System.WIFI_SLEEP_POLICY_NEVER);
|
||||
sleepPolicyPref.setValue(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||
String key = preference.getKey();
|
||||
|
||||
if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
|
||||
Secure.putInt(getContentResolver(),
|
||||
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
((CheckBoxPreference) preference).isChecked() ? 1 : 0);
|
||||
} else if (KEY_ENABLE_WIFI_WATCHDOG.equals(key)) {
|
||||
Secure.putInt(getContentResolver(),
|
||||
Secure.WIFI_WATCHDOG_ON,
|
||||
((CheckBoxPreference) preference).isChecked() ? 1 : 0);
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
|
||||
if (KEY_FREQUENCY_BAND.equals(key)) {
|
||||
try {
|
||||
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getActivity(), R.string.wifi_setting_frequency_band_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (KEY_SLEEP_POLICY.equals(key)) {
|
||||
try {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void refreshWifiInfo() {
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
|
||||
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
|
||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
||||
: getActivity().getString(R.string.status_unavailable));
|
||||
|
||||
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
|
||||
String ipAddress = Utils.getWifiIpAddresses(getActivity());
|
||||
wifiIpAddressPref.setSummary(ipAddress == null ?
|
||||
getActivity().getString(R.string.status_unavailable) : ipAddress);
|
||||
}
|
||||
|
||||
}
|
@@ -20,8 +20,12 @@ import android.content.Context;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
@@ -37,6 +41,9 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||
private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address";
|
||||
private static final String KEY_FREQUENCY_BAND = "frequency_band";
|
||||
private static final String KEY_NOTIFY_OPEN_NETWORKS = "notify_open_networks";
|
||||
private static final String KEY_SLEEP_POLICY = "sleep_policy";
|
||||
private static final String KEY_ENABLE_WIFI_WATCHDOG = "wifi_enable_watchdog_service";
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
@@ -60,28 +67,73 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private void initPreferences() {
|
||||
CheckBoxPreference notifyOpenNetworks =
|
||||
(CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
|
||||
notifyOpenNetworks.setChecked(Secure.getInt(getContentResolver(),
|
||||
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
|
||||
|
||||
ListPreference pref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
|
||||
CheckBoxPreference watchdogEnabled =
|
||||
(CheckBoxPreference) findPreference(KEY_ENABLE_WIFI_WATCHDOG);
|
||||
watchdogEnabled.setChecked(Secure.getInt(getContentResolver(),
|
||||
Secure.WIFI_WATCHDOG_ON, 1) == 1);
|
||||
|
||||
watchdogEnabled.setEnabled(mWifiManager.isWifiEnabled());
|
||||
|
||||
ListPreference frequencyPref = (ListPreference) findPreference(KEY_FREQUENCY_BAND);
|
||||
|
||||
if (mWifiManager.isDualBandSupported()) {
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
frequencyPref.setOnPreferenceChangeListener(this);
|
||||
int value = mWifiManager.getFrequencyBand();
|
||||
if (value != -1) {
|
||||
pref.setValue(String.valueOf(value));
|
||||
frequencyPref.setValue(String.valueOf(value));
|
||||
} else {
|
||||
Log.e(TAG, "Failed to fetch frequency band");
|
||||
}
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(pref);
|
||||
if (frequencyPref != null) {
|
||||
// null if it has already been removed before resume
|
||||
getPreferenceScreen().removePreference(frequencyPref);
|
||||
}
|
||||
}
|
||||
|
||||
ListPreference sleepPolicyPref = (ListPreference) findPreference(KEY_SLEEP_POLICY);
|
||||
if (sleepPolicyPref != null) {
|
||||
if (Utils.isWifiOnly()) {
|
||||
sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
|
||||
sleepPolicyPref.setSummary(R.string.wifi_setting_sleep_policy_summary_wifi_only);
|
||||
}
|
||||
sleepPolicyPref.setOnPreferenceChangeListener(this);
|
||||
int value = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.WIFI_SLEEP_POLICY,
|
||||
Settings.System.WIFI_SLEEP_POLICY_NEVER);
|
||||
sleepPolicyPref.setValue(String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||
String key = preference.getKey();
|
||||
|
||||
if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
|
||||
Secure.putInt(getContentResolver(),
|
||||
Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
((CheckBoxPreference) preference).isChecked() ? 1 : 0);
|
||||
} else if (KEY_ENABLE_WIFI_WATCHDOG.equals(key)) {
|
||||
Secure.putInt(getContentResolver(),
|
||||
Secure.WIFI_WATCHDOG_ON,
|
||||
((CheckBoxPreference) preference).isChecked() ? 1 : 0);
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
if (key == null) return true;
|
||||
|
||||
if (key.equals(KEY_FREQUENCY_BAND)) {
|
||||
if (KEY_FREQUENCY_BAND.equals(key)) {
|
||||
try {
|
||||
mWifiManager.setFrequencyBand(Integer.parseInt(((String) newValue)), true);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -91,6 +143,17 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
if (KEY_SLEEP_POLICY.equals(key)) {
|
||||
try {
|
||||
Settings.System.putInt(getContentResolver(),
|
||||
Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue)));
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getActivity(), R.string.wifi_setting_sleep_policy_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -283,12 +283,12 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
case MENU_ID_ADVANCED:
|
||||
if (getActivity() instanceof PreferenceActivity) {
|
||||
((PreferenceActivity) getActivity()).startPreferencePanel(
|
||||
AdvancedSettings.class.getCanonicalName(),
|
||||
AdvancedWifiSettings.class.getCanonicalName(),
|
||||
null,
|
||||
R.string.wifi_advanced_titlebar, null,
|
||||
this, 0);
|
||||
} else {
|
||||
startFragment(this, AdvancedSettings.class.getCanonicalName(), -1, null);
|
||||
startFragment(this, AdvancedWifiSettings.class.getCanonicalName(), -1, null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user