Create configure Wi-Fi screen
Add a gear on Settings menu, and move a bunch of stuff from overflow and advanced screen to there. Also move add network to be the last item in the list rather than in overflow. Also fix WifiP2p breakage. Change-Id: I5c84c25e5ba9224f77dcd988b0b2850ae6e71168
This commit is contained in:
@@ -18,68 +18,25 @@ package com.android.settings.wifi;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.NetworkScoreManager;
|
||||
import android.net.NetworkScorerAppManager;
|
||||
import android.net.NetworkScorerAppManager.NetworkScorerAppData;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WpsInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.security.Credentials;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.AppListSwitchPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
public class AdvancedWifiSettings extends SettingsPreferenceFragment {
|
||||
private static final String TAG = "AdvancedWifiSettings";
|
||||
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_INSTALL_CREDENTIALS = "install_credentials";
|
||||
private static final String KEY_WIFI_ASSISTANT = "wifi_assistant";
|
||||
private static final String KEY_WIFI_DIRECT = "wifi_direct";
|
||||
private static final String KEY_WPS_PUSH = "wps_push_button";
|
||||
private static final String KEY_WPS_PIN = "wps_pin_entry";
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private NetworkScoreManager mNetworkScoreManager;
|
||||
private AppListSwitchPreference mWifiAssistantPreference;
|
||||
|
||||
private IntentFilter mFilter;
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION) ||
|
||||
action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
refreshWifiInfo();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return MetricsLogger.WIFI_ADVANCED;
|
||||
@@ -91,38 +48,14 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
addPreferencesFromResource(R.xml.wifi_advanced_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
mFilter = new IntentFilter();
|
||||
mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
|
||||
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mNetworkScoreManager =
|
||||
(NetworkScoreManager) getSystemService(Context.NETWORK_SCORE_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initPreferences();
|
||||
getActivity().registerReceiver(mReceiver, mFilter);
|
||||
refreshWifiInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getActivity().unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void initPreferences() {
|
||||
SwitchPreference notifyOpenNetworks =
|
||||
(SwitchPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
|
||||
notifyOpenNetworks.setChecked(Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0) == 1);
|
||||
notifyOpenNetworks.setEnabled(mWifiManager.isWifiEnabled());
|
||||
|
||||
final Context context = getActivity();
|
||||
Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
|
||||
intent.setClassName("com.android.certinstaller",
|
||||
"com.android.certinstaller.CertInstallerMain");
|
||||
@@ -130,16 +63,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
|
||||
pref.setIntent(intent);
|
||||
|
||||
final Context context = getActivity();
|
||||
mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
|
||||
Collection<NetworkScorerAppData> scorers =
|
||||
NetworkScorerAppManager.getAllValidScorers(context);
|
||||
if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
|
||||
mWifiAssistantPreference.setOnPreferenceChangeListener(this);
|
||||
initWifiAssistantPreference(scorers);
|
||||
} else if (mWifiAssistantPreference != null) {
|
||||
getPreferenceScreen().removePreference(mWifiAssistantPreference);
|
||||
}
|
||||
|
||||
Intent wifiDirectIntent = new Intent(context,
|
||||
com.android.settings.Settings.WifiP2pSettingsActivity.class);
|
||||
@@ -165,165 +88,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
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));
|
||||
updateFrequencyBandSummary(frequencyPref, 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(context)) {
|
||||
sleepPolicyPref.setEntries(R.array.wifi_sleep_policy_entries_wifi_only);
|
||||
}
|
||||
sleepPolicyPref.setOnPreferenceChangeListener(this);
|
||||
int value = Settings.Global.getInt(getContentResolver(),
|
||||
Settings.Global.WIFI_SLEEP_POLICY,
|
||||
Settings.Global.WIFI_SLEEP_POLICY_NEVER);
|
||||
String stringValue = String.valueOf(value);
|
||||
sleepPolicyPref.setValue(stringValue);
|
||||
updateSleepPolicySummary(sleepPolicyPref, stringValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void initWifiAssistantPreference(Collection<NetworkScorerAppData> scorers) {
|
||||
int count = scorers.size();
|
||||
String[] packageNames = new String[count];
|
||||
int i = 0;
|
||||
for (NetworkScorerAppData scorer : scorers) {
|
||||
packageNames[i] = scorer.mPackageName;
|
||||
i++;
|
||||
}
|
||||
mWifiAssistantPreference.setPackageNames(packageNames,
|
||||
mNetworkScoreManager.getActiveScorerPackage());
|
||||
}
|
||||
|
||||
private void updateSleepPolicySummary(Preference sleepPolicyPref, String value) {
|
||||
if (value != null) {
|
||||
String[] values = getResources().getStringArray(R.array.wifi_sleep_policy_values);
|
||||
final int summaryArrayResId = Utils.isWifiOnly(getActivity()) ?
|
||||
R.array.wifi_sleep_policy_entries_wifi_only : R.array.wifi_sleep_policy_entries;
|
||||
String[] summaries = getResources().getStringArray(summaryArrayResId);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (value.equals(values[i])) {
|
||||
if (i < summaries.length) {
|
||||
sleepPolicyPref.setSummary(summaries[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sleepPolicyPref.setSummary("");
|
||||
Log.e(TAG, "Invalid sleep policy value: " + value);
|
||||
}
|
||||
|
||||
private void updateFrequencyBandSummary(Preference frequencyBandPref, int index) {
|
||||
String[] summaries = getResources().getStringArray(R.array.wifi_frequency_band_entries);
|
||||
frequencyBandPref.setSummary(summaries[index]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
|
||||
if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
|
||||
Global.putInt(getContentResolver(),
|
||||
Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
|
||||
((SwitchPreference) preference).isChecked() ? 1 : 0);
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final Context context = getActivity();
|
||||
String key = preference.getKey();
|
||||
|
||||
if (KEY_FREQUENCY_BAND.equals(key)) {
|
||||
try {
|
||||
int value = Integer.parseInt((String) newValue);
|
||||
mWifiManager.setFrequencyBand(value, true);
|
||||
updateFrequencyBandSummary(preference, value);
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(context, R.string.wifi_setting_frequency_band_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
} else if (KEY_WIFI_ASSISTANT.equals(key)) {
|
||||
NetworkScorerAppData wifiAssistant =
|
||||
NetworkScorerAppManager.getScorer(context, (String) newValue);
|
||||
if (wifiAssistant == null) {
|
||||
mNetworkScoreManager.setActiveScorer(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
if (wifiAssistant.mConfigurationActivityClassName != null) {
|
||||
// App has a custom configuration activity; launch that.
|
||||
// This custom activity will be responsible for launching the system
|
||||
// dialog.
|
||||
intent.setClassName(wifiAssistant.mPackageName,
|
||||
wifiAssistant.mConfigurationActivityClassName);
|
||||
} else {
|
||||
// Fall back on the system dialog.
|
||||
intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
|
||||
intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
|
||||
wifiAssistant.mPackageName);
|
||||
}
|
||||
|
||||
startActivity(intent);
|
||||
// Don't update the preference widget state until the child activity returns.
|
||||
// It will be updated in onResume after the activity finishes.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (KEY_SLEEP_POLICY.equals(key)) {
|
||||
try {
|
||||
String stringValue = (String) newValue;
|
||||
Settings.Global.putInt(getContentResolver(), Settings.Global.WIFI_SLEEP_POLICY,
|
||||
Integer.parseInt(stringValue));
|
||||
updateSleepPolicySummary(preference, stringValue);
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(context, R.string.wifi_setting_sleep_policy_error,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void refreshWifiInfo() {
|
||||
final Context context = getActivity();
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
|
||||
Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS);
|
||||
String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress();
|
||||
wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress
|
||||
: context.getString(R.string.status_unavailable));
|
||||
wifiMacAddressPref.setSelectable(false);
|
||||
|
||||
Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);
|
||||
String ipAddress = Utils.getWifiIpAddresses(context);
|
||||
wifiIpAddressPref.setSummary(ipAddress == null ?
|
||||
context.getString(R.string.status_unavailable) : ipAddress);
|
||||
wifiIpAddressPref.setSelectable(false);
|
||||
}
|
||||
|
||||
/* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
|
||||
|
Reference in New Issue
Block a user