Merge "Create configure Wi-Fi screen"
This commit is contained in:
@@ -1486,6 +1486,8 @@
|
|||||||
<string name="wifi_menu_scan">Scan</string>
|
<string name="wifi_menu_scan">Scan</string>
|
||||||
<!-- Menu option to Wi-Fi advanced settings -->
|
<!-- Menu option to Wi-Fi advanced settings -->
|
||||||
<string name="wifi_menu_advanced">Advanced</string>
|
<string name="wifi_menu_advanced">Advanced</string>
|
||||||
|
<!-- Menu option to Wi-Fi configure settings -->
|
||||||
|
<string name="wifi_menu_configure">Configure</string>
|
||||||
<!-- Menu option to connect to a Wi-Fi network -->
|
<!-- Menu option to connect to a Wi-Fi network -->
|
||||||
<string name="wifi_menu_connect">Connect to network</string>
|
<string name="wifi_menu_connect">Connect to network</string>
|
||||||
<!-- Menu option to remember a temporary Wi-Fi network -->
|
<!-- Menu option to remember a temporary Wi-Fi network -->
|
||||||
@@ -1656,6 +1658,8 @@
|
|||||||
<string name="wifi_saved_access_points_titlebar">Saved networks</string>
|
<string name="wifi_saved_access_points_titlebar">Saved networks</string>
|
||||||
<!-- Wi-Fi settings screen, advanced, settings section. This is a header shown above advanced wifi settings. [CHAR LIMIT=30] -->
|
<!-- Wi-Fi settings screen, advanced, settings section. This is a header shown above advanced wifi settings. [CHAR LIMIT=30] -->
|
||||||
<string name="wifi_advanced_titlebar">Advanced Wi\u2011Fi</string>
|
<string name="wifi_advanced_titlebar">Advanced Wi\u2011Fi</string>
|
||||||
|
<!-- Wi-Fi settings screen, configure, settings section. This is a header shown above configure wifi settings. [CHAR LIMIT=30] -->
|
||||||
|
<string name="wifi_configure_titlebar">Configure Wi\u2011Fi</string>
|
||||||
<!-- Wi-Fi settings screen, setting title for setting the band [CHAR LIMIT=50]-->
|
<!-- Wi-Fi settings screen, setting title for setting the band [CHAR LIMIT=50]-->
|
||||||
<string name="wifi_setting_frequency_band_title">Wi\u2011Fi frequency band</string>
|
<string name="wifi_setting_frequency_band_title">Wi\u2011Fi frequency band</string>
|
||||||
<!-- Wi-Fi settings screen, setting summary for setting the wifi frequency band [CHAR LIMIT=50]-->
|
<!-- Wi-Fi settings screen, setting summary for setting the wifi frequency band [CHAR LIMIT=50]-->
|
||||||
|
@@ -17,35 +17,6 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/wifi_advanced_titlebar">
|
android:title="@string/wifi_advanced_titlebar">
|
||||||
|
|
||||||
<!-- android:dependency="enable_wifi" -->
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="notify_open_networks"
|
|
||||||
android:title="@string/wifi_notify_open_networks"
|
|
||||||
android:summary="@string/wifi_notify_open_networks_summary"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:key="sleep_policy"
|
|
||||||
android:title="@string/wifi_setting_sleep_policy_title"
|
|
||||||
android:persistent="false"
|
|
||||||
android:entries="@array/wifi_sleep_policy_entries"
|
|
||||||
android:entryValues="@array/wifi_sleep_policy_values" />
|
|
||||||
|
|
||||||
<com.android.settings.AppListSwitchPreference
|
|
||||||
android:key="wifi_assistant"
|
|
||||||
android:title="@string/wifi_automatically_connect_title"
|
|
||||||
android:summary="@string/wifi_automatically_connect_summary"
|
|
||||||
android:dialogTitle="@string/wifi_select_assistant_dialog_title"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:key="frequency_band"
|
|
||||||
android:title="@string/wifi_setting_frequency_band_title"
|
|
||||||
android:summary="@string/wifi_setting_frequency_band_summary"
|
|
||||||
android:persistent="false"
|
|
||||||
android:entries="@array/wifi_frequency_band_entries"
|
|
||||||
android:entryValues="@array/wifi_frequency_band_values" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="install_credentials"
|
android:key="install_credentials"
|
||||||
android:title="@string/wifi_install_credentials"
|
android:title="@string/wifi_install_credentials"
|
||||||
@@ -66,14 +37,4 @@
|
|||||||
android:title="@string/wifi_menu_wps_pin"
|
android:title="@string/wifi_menu_wps_pin"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<Preference
|
</PreferenceScreen>
|
||||||
android:key="mac_address"
|
|
||||||
android:title="@string/wifi_advanced_mac_address_title"
|
|
||||||
android:layout="@layout/wifi_advance_layout" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="current_ip_address"
|
|
||||||
android:title="@string/wifi_advanced_ip_address_title"
|
|
||||||
android:layout="@layout/wifi_advance_layout" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
||||||
|
64
res/xml/wifi_configure_settings.xml
Normal file
64
res/xml/wifi_configure_settings.xml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2015 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_configure_titlebar">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="saved_networks"
|
||||||
|
android:title="@string/wifi_saved_access_points_label"
|
||||||
|
android:fragment="com.android.settings.wifi.SavedAccessPointsWifiSettings" />
|
||||||
|
|
||||||
|
<!-- android:dependency="enable_wifi" -->
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="notify_open_networks"
|
||||||
|
android:title="@string/wifi_notify_open_networks"
|
||||||
|
android:summary="@string/wifi_notify_open_networks_summary"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="sleep_policy"
|
||||||
|
android:title="@string/wifi_setting_sleep_policy_title"
|
||||||
|
android:persistent="false"
|
||||||
|
android:entries="@array/wifi_sleep_policy_entries"
|
||||||
|
android:entryValues="@array/wifi_sleep_policy_values" />
|
||||||
|
|
||||||
|
<com.android.settings.AppListSwitchPreference
|
||||||
|
android:key="wifi_assistant"
|
||||||
|
android:title="@string/wifi_automatically_connect_title"
|
||||||
|
android:summary="@string/wifi_automatically_connect_summary"
|
||||||
|
android:dialogTitle="@string/wifi_select_assistant_dialog_title"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="frequency_band"
|
||||||
|
android:title="@string/wifi_setting_frequency_band_title"
|
||||||
|
android:summary="@string/wifi_setting_frequency_band_summary"
|
||||||
|
android:persistent="false"
|
||||||
|
android:entries="@array/wifi_frequency_band_entries"
|
||||||
|
android:entryValues="@array/wifi_frequency_band_values" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="mac_address"
|
||||||
|
android:title="@string/wifi_advanced_mac_address_title"
|
||||||
|
android:layout="@layout/wifi_advance_layout" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="current_ip_address"
|
||||||
|
android:title="@string/wifi_advanced_ip_address_title"
|
||||||
|
android:layout="@layout/wifi_advance_layout" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -31,6 +31,7 @@ public abstract class InstrumentedFragment extends PreferenceFragment {
|
|||||||
public static final int ACCESSIBILITY_TOGGLE_AUTOCLICK = UNDECLARED + 1;
|
public static final int ACCESSIBILITY_TOGGLE_AUTOCLICK = UNDECLARED + 1;
|
||||||
public static final int SOUND = UNDECLARED + 2;
|
public static final int SOUND = UNDECLARED + 2;
|
||||||
public static final int CONFIGURE_NOTIFICATION = UNDECLARED + 3;
|
public static final int CONFIGURE_NOTIFICATION = UNDECLARED + 3;
|
||||||
|
public static final int CONFIGURE_WIFI = UNDECLARED + 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare the view of this category.
|
* Declare the view of this category.
|
||||||
|
@@ -18,68 +18,25 @@ package com.android.settings.wifi;
|
|||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
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.net.wifi.WpsInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.provider.Settings.Global;
|
|
||||||
import android.security.Credentials;
|
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;
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
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.internal.logging.MetricsLogger;
|
||||||
import com.android.settings.AppListSwitchPreference;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
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 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_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_WIFI_DIRECT = "wifi_direct";
|
||||||
private static final String KEY_WPS_PUSH = "wps_push_button";
|
private static final String KEY_WPS_PUSH = "wps_push_button";
|
||||||
private static final String KEY_WPS_PIN = "wps_pin_entry";
|
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
|
@Override
|
||||||
protected int getMetricsCategory() {
|
protected int getMetricsCategory() {
|
||||||
return MetricsLogger.WIFI_ADVANCED;
|
return MetricsLogger.WIFI_ADVANCED;
|
||||||
@@ -91,38 +48,14 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
|||||||
addPreferencesFromResource(R.xml.wifi_advanced_settings);
|
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
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
initPreferences();
|
initPreferences();
|
||||||
getActivity().registerReceiver(mReceiver, mFilter);
|
|
||||||
refreshWifiInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
getActivity().unregisterReceiver(mReceiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPreferences() {
|
private void initPreferences() {
|
||||||
SwitchPreference notifyOpenNetworks =
|
final Context context = getActivity();
|
||||||
(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());
|
|
||||||
|
|
||||||
Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
|
Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
|
||||||
intent.setClassName("com.android.certinstaller",
|
intent.setClassName("com.android.certinstaller",
|
||||||
"com.android.certinstaller.CertInstallerMain");
|
"com.android.certinstaller.CertInstallerMain");
|
||||||
@@ -130,16 +63,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
|||||||
Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
|
Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
|
||||||
pref.setIntent(intent);
|
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,
|
Intent wifiDirectIntent = new Intent(context,
|
||||||
com.android.settings.Settings.WifiP2pSettingsActivity.class);
|
com.android.settings.Settings.WifiP2pSettingsActivity.class);
|
||||||
@@ -165,165 +88,6 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
|||||||
return true;
|
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. */
|
/* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
|
||||||
|
293
src/com/android/settings/wifi/ConfigureWifiSettings.java
Normal file
293
src/com/android/settings/wifi/ConfigureWifiSettings.java
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 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.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.net.NetworkScoreManager;
|
||||||
|
import android.net.NetworkScorerAppManager;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
|
import android.support.v7.preference.ListPreference;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import com.android.settings.AppListSwitchPreference;
|
||||||
|
import com.android.settings.InstrumentedFragment;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ConfigureWifiSettings extends SettingsPreferenceFragment
|
||||||
|
implements Preference.OnPreferenceChangeListener {
|
||||||
|
private static final String TAG = "ConfigureWifiSettings";
|
||||||
|
|
||||||
|
private static final String KEY_MAC_ADDRESS = "mac_address";
|
||||||
|
private static final String KEY_SAVED_NETWORKS = "saved_networks";
|
||||||
|
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_WIFI_ASSISTANT = "wifi_assistant";
|
||||||
|
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
private NetworkScoreManager mNetworkScoreManager;
|
||||||
|
private AppListSwitchPreference mWifiAssistantPreference;
|
||||||
|
|
||||||
|
private IntentFilter mFilter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
addPreferencesFromResource(R.xml.wifi_configure_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() {
|
||||||
|
List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
|
||||||
|
if (configs == null || configs.size() == 0) {
|
||||||
|
removePreference(KEY_SAVED_NETWORKS);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
mWifiAssistantPreference = (AppListSwitchPreference) findPreference(KEY_WIFI_ASSISTANT);
|
||||||
|
Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers =
|
||||||
|
NetworkScorerAppManager.getAllValidScorers(context);
|
||||||
|
if (UserManager.get(context).isAdminUser() && !scorers.isEmpty()) {
|
||||||
|
mWifiAssistantPreference.setOnPreferenceChangeListener(this);
|
||||||
|
initWifiAssistantPreference(scorers);
|
||||||
|
} else if (mWifiAssistantPreference != null) {
|
||||||
|
getPreferenceScreen().removePreference(mWifiAssistantPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
|
String key = preference.getKey();
|
||||||
|
|
||||||
|
if (KEY_NOTIFY_OPEN_NETWORKS.equals(key)) {
|
||||||
|
Settings.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)) {
|
||||||
|
NetworkScorerAppManager.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFrequencyBandSummary(Preference frequencyBandPref, int index) {
|
||||||
|
String[] summaries = getResources().getStringArray(R.array.wifi_frequency_band_entries);
|
||||||
|
frequencyBandPref.setSummary(summaries[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initWifiAssistantPreference(
|
||||||
|
Collection<NetworkScorerAppManager.NetworkScorerAppData> scorers) {
|
||||||
|
int count = scorers.size();
|
||||||
|
String[] packageNames = new String[count];
|
||||||
|
int i = 0;
|
||||||
|
for (NetworkScorerAppManager.NetworkScorerAppData scorer : scorers) {
|
||||||
|
packageNames[i] = scorer.mPackageName;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
mWifiAssistantPreference.setPackageNames(packageNames,
|
||||||
|
mNetworkScoreManager.getActiveScorerPackage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getMetricsCategory() {
|
||||||
|
return InstrumentedFragment.CONFIGURE_WIFI;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@@ -32,7 +32,7 @@ import android.content.pm.IPackageManager;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.State;
|
import android.net.NetworkInfo.State;
|
||||||
@@ -47,9 +47,11 @@ import android.os.RemoteException;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.style.TextAppearanceSpan;
|
import android.text.style.TextAppearanceSpan;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
@@ -99,14 +101,13 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
|
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
|
||||||
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
|
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
|
||||||
private static final int MENU_ID_SAVED_NETWORK = Menu.FIRST + 2;
|
|
||||||
/* package */ static final int MENU_ID_ADD_NETWORK = Menu.FIRST + 3;
|
|
||||||
private static final int MENU_ID_ADVANCED = Menu.FIRST + 4;
|
private static final int MENU_ID_ADVANCED = Menu.FIRST + 4;
|
||||||
private static final int MENU_ID_SCAN = Menu.FIRST + 5;
|
private static final int MENU_ID_SCAN = Menu.FIRST + 5;
|
||||||
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
|
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
|
||||||
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
|
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
|
||||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
|
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
|
||||||
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
|
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
|
||||||
|
private static final int MENU_ID_CONFIGURE = Menu.FIRST + 10;
|
||||||
|
|
||||||
public static final int WIFI_DIALOG_ID = 1;
|
public static final int WIFI_DIALOG_ID = 1;
|
||||||
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
||||||
@@ -118,8 +119,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
|
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
|
||||||
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
||||||
|
|
||||||
private static boolean savedNetworksExist;
|
|
||||||
|
|
||||||
protected WifiManager mWifiManager;
|
protected WifiManager mWifiManager;
|
||||||
private WifiManager.ActionListener mConnectListener;
|
private WifiManager.ActionListener mConnectListener;
|
||||||
private WifiManager.ActionListener mSaveListener;
|
private WifiManager.ActionListener mSaveListener;
|
||||||
@@ -157,6 +156,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private HandlerThread mBgThread;
|
private HandlerThread mBgThread;
|
||||||
|
|
||||||
private UserBadgeCache mUserBadgeCache;
|
private UserBadgeCache mUserBadgeCache;
|
||||||
|
private Preference mAddPreference;
|
||||||
|
|
||||||
/* End of "used in Wifi Setup context" */
|
/* End of "used in Wifi Setup context" */
|
||||||
|
|
||||||
@@ -177,6 +177,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
addPreferencesFromResource(R.xml.wifi_settings);
|
addPreferencesFromResource(R.xml.wifi_settings);
|
||||||
|
mAddPreference = new Preference(getContext());
|
||||||
|
Drawable ic_add = getContext().getDrawable(R.drawable.ic_menu_add).mutate();
|
||||||
|
TypedValue tv = new TypedValue();
|
||||||
|
getContext().getTheme().resolveAttribute(android.R.attr.colorAccent, tv, true);
|
||||||
|
ic_add.setTint(getContext().getColor(tv.resourceId));
|
||||||
|
mAddPreference.setIcon(ic_add);
|
||||||
|
mAddPreference.setTitle(R.string.wifi_add_network);
|
||||||
|
|
||||||
mUserBadgeCache = new UserBadgeCache(getPackageManager());
|
mUserBadgeCache = new UserBadgeCache(getPackageManager());
|
||||||
|
|
||||||
mBgThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
|
mBgThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
@@ -343,24 +351,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
*/
|
*/
|
||||||
void addOptionsMenuItems(Menu menu) {
|
void addOptionsMenuItems(Menu menu) {
|
||||||
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
||||||
TypedArray ta = getActivity().getTheme().obtainStyledAttributes(
|
|
||||||
new int[] {R.attr.ic_menu_add, R.attr.ic_wps});
|
|
||||||
menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
|
|
||||||
.setIcon(ta.getDrawable(0))
|
|
||||||
.setEnabled(wifiIsEnabled)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
if (savedNetworksExist) {
|
|
||||||
menu.add(Menu.NONE, MENU_ID_SAVED_NETWORK, 0, R.string.wifi_saved_access_points_label)
|
|
||||||
.setIcon(ta.getDrawable(0))
|
|
||||||
.setEnabled(wifiIsEnabled)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
}
|
|
||||||
menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
|
menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
|
||||||
.setEnabled(wifiIsEnabled)
|
.setEnabled(wifiIsEnabled)
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
ta.recycle();
|
menu.add(Menu.NONE, MENU_ID_CONFIGURE, 0, R.string.wifi_menu_configure)
|
||||||
|
.setIcon(R.drawable.ic_settings_24dp)
|
||||||
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -419,22 +417,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
MetricsLogger.action(getActivity(), MetricsLogger.ACTION_WIFI_FORCE_SCAN);
|
MetricsLogger.action(getActivity(), MetricsLogger.ACTION_WIFI_FORCE_SCAN);
|
||||||
mWifiTracker.forceScan();
|
mWifiTracker.forceScan();
|
||||||
return true;
|
return true;
|
||||||
case MENU_ID_ADD_NETWORK:
|
|
||||||
if (mWifiTracker.isWifiEnabled()) {
|
|
||||||
onAddNetworkPressed();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case MENU_ID_SAVED_NETWORK:
|
|
||||||
if (getActivity() instanceof SettingsActivity) {
|
|
||||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
|
||||||
SavedAccessPointsWifiSettings.class.getCanonicalName(), null,
|
|
||||||
R.string.wifi_saved_access_points_titlebar, null, this, 0);
|
|
||||||
} else {
|
|
||||||
startFragment(this, SavedAccessPointsWifiSettings.class.getCanonicalName(),
|
|
||||||
R.string.wifi_saved_access_points_titlebar,
|
|
||||||
-1 /* Do not request a result */, null);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case MENU_ID_ADVANCED:
|
case MENU_ID_ADVANCED:
|
||||||
if (getActivity() instanceof SettingsActivity) {
|
if (getActivity() instanceof SettingsActivity) {
|
||||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
((SettingsActivity) getActivity()).startPreferencePanel(
|
||||||
@@ -446,6 +428,18 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case MENU_ID_CONFIGURE:
|
||||||
|
if (getActivity() instanceof SettingsActivity) {
|
||||||
|
((SettingsActivity) getActivity()).startPreferencePanel(
|
||||||
|
ConfigureWifiSettings.class.getCanonicalName(), null,
|
||||||
|
R.string.wifi_configure_titlebar, null, this, 0);
|
||||||
|
} else {
|
||||||
|
startFragment(this, ConfigureWifiSettings.class.getCanonicalName(),
|
||||||
|
R.string.wifi_configure_titlebar, -1 /* Do not request a results */,
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -530,16 +524,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE &&
|
if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE &&
|
||||||
!mSelectedAccessPoint.isSaved() && !mSelectedAccessPoint.isActive()) {
|
!mSelectedAccessPoint.isSaved() && !mSelectedAccessPoint.isActive()) {
|
||||||
mSelectedAccessPoint.generateOpenNetworkConfig();
|
mSelectedAccessPoint.generateOpenNetworkConfig();
|
||||||
if (!savedNetworksExist) {
|
|
||||||
savedNetworksExist = true;
|
|
||||||
getActivity().invalidateOptionsMenu();
|
|
||||||
}
|
|
||||||
connect(mSelectedAccessPoint.getConfig());
|
connect(mSelectedAccessPoint.getConfig());
|
||||||
} else if (mSelectedAccessPoint.isSaved()){
|
} else if (mSelectedAccessPoint.isSaved()) {
|
||||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_VIEW);
|
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_VIEW);
|
||||||
} else {
|
} else {
|
||||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
||||||
}
|
}
|
||||||
|
} else if (preference == mAddPreference) {
|
||||||
|
onAddNetworkPressed();
|
||||||
} else {
|
} else {
|
||||||
return super.onPreferenceTreeClick(preference);
|
return super.onPreferenceTreeClick(preference);
|
||||||
}
|
}
|
||||||
@@ -678,8 +670,23 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
if (!hasAvailableAccessPoints) {
|
if (!hasAvailableAccessPoints) {
|
||||||
setProgressBarVisible(true);
|
setProgressBarVisible(true);
|
||||||
addMessagePreference(R.string.wifi_empty_list_wifi_on);
|
Preference pref = new Preference(getContext()) {
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
// Show a line on each side of add network.
|
||||||
|
holder.setDividerAllowedBelow(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
pref.setSelectable(false);
|
||||||
|
pref.setSummary(R.string.wifi_empty_list_wifi_on);
|
||||||
|
pref.setOrder(0);
|
||||||
|
getPreferenceScreen().addPreference(pref);
|
||||||
|
mAddPreference.setOrder(1);
|
||||||
|
getPreferenceScreen().addPreference(mAddPreference);
|
||||||
} else {
|
} else {
|
||||||
|
mAddPreference.setOrder(index++);
|
||||||
|
getPreferenceScreen().addPreference(mAddPreference);
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -699,11 +706,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Update "Saved Networks" menu option.
|
|
||||||
if (savedNetworksExist != mWifiTracker.doSavedNetworksExist()) {
|
|
||||||
savedNetworksExist = !savedNetworksExist;
|
|
||||||
getActivity().invalidateOptionsMenu();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TextView initEmptyView() {
|
protected TextView initEmptyView() {
|
||||||
@@ -768,11 +770,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWifiStateChanged(int state) {
|
public void onWifiStateChanged(int state) {
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
activity.invalidateOptionsMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WifiManager.WIFI_STATE_ENABLING:
|
case WifiManager.WIFI_STATE_ENABLING:
|
||||||
addMessagePreference(R.string.wifi_starting);
|
addMessagePreference(R.string.wifi_starting);
|
||||||
|
@@ -23,7 +23,6 @@ import android.support.v7.preference.Preference;
|
|||||||
import android.support.v7.preference.PreferenceViewHolder;
|
import android.support.v7.preference.PreferenceViewHolder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
public class WifiP2pPeer extends Preference {
|
public class WifiP2pPeer extends Preference {
|
||||||
@@ -41,15 +40,18 @@ public class WifiP2pPeer extends Preference {
|
|||||||
device = dev;
|
device = dev;
|
||||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
||||||
mRssi = 60; //TODO: fix
|
mRssi = 60; //TODO: fix
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
|
||||||
if (TextUtils.isEmpty(device.deviceName)) {
|
if (TextUtils.isEmpty(device.deviceName)) {
|
||||||
setTitle(device.deviceAddress);
|
setTitle(device.deviceAddress);
|
||||||
} else {
|
} else {
|
||||||
setTitle(device.deviceName);
|
setTitle(device.deviceName);
|
||||||
}
|
}
|
||||||
|
String[] statusArray = context.getResources().getStringArray(R.array.wifi_p2p_status);
|
||||||
|
setSummary(statusArray[device.status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||||
|
super.onBindViewHolder(view);
|
||||||
mSignal = (ImageView) view.findViewById(R.id.signal);
|
mSignal = (ImageView) view.findViewById(R.id.signal);
|
||||||
if (mRssi == Integer.MAX_VALUE) {
|
if (mRssi == Integer.MAX_VALUE) {
|
||||||
mSignal.setImageDrawable(null);
|
mSignal.setImageDrawable(null);
|
||||||
@@ -57,8 +59,7 @@ public class WifiP2pPeer extends Preference {
|
|||||||
mSignal.setImageResource(R.drawable.wifi_signal_dark);
|
mSignal.setImageResource(R.drawable.wifi_signal_dark);
|
||||||
mSignal.setImageState(STATE_SECURED, true);
|
mSignal.setImageState(STATE_SECURED, true);
|
||||||
}
|
}
|
||||||
refresh();
|
mSignal.setImageLevel(getLevel());
|
||||||
super.onBindViewHolder(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,14 +88,4 @@ public class WifiP2pPeer extends Preference {
|
|||||||
}
|
}
|
||||||
return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
|
return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh() {
|
|
||||||
if (mSignal == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Context context = getContext();
|
|
||||||
mSignal.setImageLevel(getLevel());
|
|
||||||
String[] statusArray = context.getResources().getStringArray(R.array.wifi_p2p_status);
|
|
||||||
setSummary(statusArray[device.status]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user