Merge "Add UI for WPS"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c001a38c75
@@ -69,8 +69,10 @@ class AccessPoint extends Preference {
|
||||
static final int SECURITY_EAP = 3;
|
||||
|
||||
final String ssid;
|
||||
final String bssid;
|
||||
final int security;
|
||||
final int networkId;
|
||||
boolean wpsAvailable = false;
|
||||
|
||||
private WifiConfiguration mConfig;
|
||||
private int mRssi;
|
||||
@@ -104,6 +106,7 @@ class AccessPoint extends Preference {
|
||||
super(context);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
||||
ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
|
||||
bssid = config.BSSID;
|
||||
security = getSecurity(config);
|
||||
networkId = config.networkId;
|
||||
mConfig = config;
|
||||
@@ -114,7 +117,10 @@ class AccessPoint extends Preference {
|
||||
super(context);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
|
||||
ssid = result.SSID;
|
||||
bssid = result.BSSID;
|
||||
security = getSecurity(result);
|
||||
wpsAvailable = security != SECURITY_NONE && security != SECURITY_EAP &&
|
||||
result.capabilities.contains("WPS");
|
||||
networkId = -1;
|
||||
mRssi = result.level;
|
||||
}
|
||||
@@ -218,8 +224,13 @@ class AccessPoint extends Preference {
|
||||
if (security == SECURITY_NONE) {
|
||||
setSummary(status);
|
||||
} else {
|
||||
String format = context.getString((status == null) ?
|
||||
R.string.wifi_secured : R.string.wifi_secured_with_status);
|
||||
String format;
|
||||
if (wpsAvailable && mConfig == null) {
|
||||
format = context.getString(R.string.wifi_secured_with_wps);
|
||||
} else {
|
||||
format = context.getString((status == null) ?
|
||||
R.string.wifi_secured : R.string.wifi_secured_with_status);
|
||||
}
|
||||
String[] type = context.getResources().getStringArray(R.array.wifi_security);
|
||||
setSummary(String.format(format, type[security], status));
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.IpAssignment;
|
||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
@@ -73,6 +74,13 @@ public class WifiConfigController implements TextWatcher,
|
||||
private TextView mEapAnonymousView;
|
||||
|
||||
private static final String STATIC_IP = "Static";
|
||||
|
||||
/* These values come from "wifi_network_setup" resource array */
|
||||
public static final int MANUAL = 0;
|
||||
public static final int WPS_PBC = 1;
|
||||
public static final int WPS_PIN = 2;
|
||||
|
||||
private Spinner mNetworkSetupSpinner;
|
||||
private Spinner mIpSettingsSpinner;
|
||||
private TextView mIpAddressView;
|
||||
private TextView mGatewayView;
|
||||
@@ -140,7 +148,12 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
}
|
||||
|
||||
if (mAccessPoint.networkId == -1 || mEdit) {
|
||||
/* Show network setup options only for a new network */
|
||||
if (mAccessPoint.networkId == INVALID_NETWORK_ID && mAccessPoint.wpsAvailable) {
|
||||
showNetworkSetupFields();
|
||||
}
|
||||
|
||||
if (mAccessPoint.networkId == INVALID_NETWORK_ID || mEdit) {
|
||||
showSecurityFields();
|
||||
showIpConfigFields();
|
||||
}
|
||||
@@ -151,22 +164,20 @@ public class WifiConfigController implements TextWatcher,
|
||||
if (state == null && level != -1) {
|
||||
mConfigUi.setSubmitButton(context.getString(R.string.wifi_connect));
|
||||
} else {
|
||||
mView.findViewById(R.id.ipfields).setVisibility(View.GONE);
|
||||
mView.findViewById(R.id.ip_fields).setVisibility(View.GONE);
|
||||
}
|
||||
if (mAccessPoint.networkId != -1) {
|
||||
if (mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
mConfigUi.setForgetButton(context.getString(R.string.wifi_forget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mIpSettingsSpinner = ((Spinner) mView.findViewById(R.id.ipsettings));
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != -1) {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
WifiConfiguration config = mAccessPoint.getConfig();
|
||||
if (config.ipAssignment == IpAssignment.STATIC) {
|
||||
setSelection(mIpSettingsSpinner, STATIC_IP);
|
||||
}
|
||||
}
|
||||
mIpSettingsSpinner.setOnItemSelectedListener(this);
|
||||
|
||||
mConfigUi.setCancelButton(context.getString(R.string.wifi_cancel));
|
||||
if (mConfigUi.getSubmitButton() != null) {
|
||||
@@ -184,7 +195,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
/* show submit button if the password is valid */
|
||||
private void enableSubmitIfAppropriate() {
|
||||
if ((mSsidView != null && mSsidView.length() == 0) ||
|
||||
((mAccessPoint == null || mAccessPoint.networkId == -1) &&
|
||||
((mAccessPoint == null || mAccessPoint.networkId == INVALID_NETWORK_ID) &&
|
||||
((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) ||
|
||||
(mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8)))) {
|
||||
mConfigUi.getSubmitButton().setEnabled(false);
|
||||
@@ -194,7 +205,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
|
||||
/* package */ WifiConfiguration getConfig() {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != -1 && !mEdit) {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID && !mEdit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -205,7 +216,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
mSsidView.getText().toString());
|
||||
// If the user adds a network manually, assume that it is hidden.
|
||||
config.hiddenSSID = true;
|
||||
} else if (mAccessPoint.networkId == -1) {
|
||||
} else if (mAccessPoint.networkId == INVALID_NETWORK_ID) {
|
||||
config.SSID = AccessPoint.convertToQuotedString(
|
||||
mAccessPoint.ssid);
|
||||
} else {
|
||||
@@ -299,19 +310,35 @@ public class WifiConfigController implements TextWatcher,
|
||||
return config;
|
||||
}
|
||||
|
||||
int chosenNetworkSetupMethod() {
|
||||
if (mNetworkSetupSpinner != null) {
|
||||
return mNetworkSetupSpinner.getSelectedItemPosition();
|
||||
}
|
||||
return MANUAL;
|
||||
}
|
||||
|
||||
int getWpsPin() {
|
||||
try {
|
||||
String wpsPin = ((TextView) mView.findViewById(R.id.wps_pin)).getText().toString();
|
||||
return Integer.parseInt(wpsPin);
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void showSecurityFields() {
|
||||
if (mAccessPointSecurity == AccessPoint.SECURITY_NONE) {
|
||||
mView.findViewById(R.id.fields).setVisibility(View.GONE);
|
||||
mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
mView.findViewById(R.id.fields).setVisibility(View.VISIBLE);
|
||||
mView.findViewById(R.id.security_fields).setVisibility(View.VISIBLE);
|
||||
|
||||
if (mPasswordView == null) {
|
||||
mPasswordView = (TextView) mView.findViewById(R.id.password);
|
||||
mPasswordView.addTextChangedListener(this);
|
||||
((CheckBox) mView.findViewById(R.id.show_password)).setOnClickListener(this);
|
||||
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != -1) {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
mPasswordView.setHint(R.string.wifi_unchanged);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +360,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE);
|
||||
loadCertificates(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY);
|
||||
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != -1) {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
WifiConfiguration config = mAccessPoint.getConfig();
|
||||
setSelection(mEapMethodSpinner, config.eap.value());
|
||||
setSelection(mPhase2Spinner, config.phase2.value());
|
||||
@@ -347,16 +374,43 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
}
|
||||
|
||||
private void showNetworkSetupFields() {
|
||||
mView.findViewById(R.id.setup_fields).setVisibility(View.VISIBLE);
|
||||
|
||||
if (mNetworkSetupSpinner == null) {
|
||||
mNetworkSetupSpinner = (Spinner) mView.findViewById(R.id.network_setup);
|
||||
mNetworkSetupSpinner.setOnItemSelectedListener(this);
|
||||
}
|
||||
|
||||
int pos = mNetworkSetupSpinner.getSelectedItemPosition();
|
||||
|
||||
/* Show pin text input if needed */
|
||||
if (pos == WPS_PIN) {
|
||||
mView.findViewById(R.id.wps_fields).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mView.findViewById(R.id.wps_fields).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
/* show/hide manual security fields appropriately */
|
||||
if ((pos == WPS_PIN) || (pos == WPS_PBC)) {
|
||||
mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
|
||||
} else {
|
||||
mView.findViewById(R.id.security_fields).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void showIpConfigFields() {
|
||||
WifiConfiguration config = null;
|
||||
|
||||
mView.findViewById(R.id.ipfields).setVisibility(View.VISIBLE);
|
||||
mView.findViewById(R.id.ip_fields).setVisibility(View.VISIBLE);
|
||||
|
||||
if (mIpSettingsSpinner == null) {
|
||||
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ipsettings);
|
||||
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
|
||||
mIpSettingsSpinner.setOnItemSelectedListener(this);
|
||||
}
|
||||
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != -1) {
|
||||
if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
config = mAccessPoint.getConfig();
|
||||
}
|
||||
|
||||
@@ -451,6 +505,8 @@ public class WifiConfigController implements TextWatcher,
|
||||
mAccessPointSecurity = position;
|
||||
showSecurityFields();
|
||||
enableSubmitIfAppropriate();
|
||||
} else if (parent == mNetworkSetupSpinner){
|
||||
showNetworkSetupFields();
|
||||
} else {
|
||||
showIpConfigFields();
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.SupplicantState;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
@@ -44,7 +45,6 @@ import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.Menu;
|
||||
@@ -102,7 +102,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
private DetailedState mLastState;
|
||||
private WifiInfo mLastInfo;
|
||||
|
||||
private int mKeyStoreNetworkId = -1;
|
||||
private int mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
|
||||
// should Next button only be enabled when we have a connection?
|
||||
private boolean mEnableNextOnConnection;
|
||||
@@ -198,10 +198,11 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
mWifiEnabler.resume();
|
||||
}
|
||||
getActivity().registerReceiver(mReceiver, mFilter);
|
||||
if (mKeyStoreNetworkId != -1 && KeyStore.getInstance().test() == KeyStore.NO_ERROR) {
|
||||
if (mKeyStoreNetworkId != INVALID_NETWORK_ID &&
|
||||
KeyStore.getInstance().test() == KeyStore.NO_ERROR) {
|
||||
mWifiManager.connectNetwork(mKeyStoreNetworkId);
|
||||
}
|
||||
mKeyStoreNetworkId = -1;
|
||||
mKeyStoreNetworkId = INVALID_NETWORK_ID;
|
||||
if (mInXlSetupWizard) {
|
||||
// We show "Now scanning"
|
||||
final int wifiState = mWifiManager.getWifiState();
|
||||
@@ -285,7 +286,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
&& mSelectedAccessPoint.getState() == null) {
|
||||
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
|
||||
}
|
||||
if (mSelectedAccessPoint.networkId != -1) {
|
||||
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
menu.add(Menu.NONE, MENU_ID_FORGET, 0, R.string.wifi_menu_forget);
|
||||
menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
|
||||
}
|
||||
@@ -300,7 +301,7 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
switch (item.getItemId()) {
|
||||
case MENU_ID_CONNECT: {
|
||||
if (mSelectedAccessPoint.networkId != -1) {
|
||||
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||
if (!requireKeyStore(mSelectedAccessPoint.getConfig())) {
|
||||
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
||||
}
|
||||
@@ -601,23 +602,36 @@ public class WifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
/* package */ void submit() {
|
||||
final WifiConfigUiBase uiBase = (mDialog != null ? mDialog : mConfigPreference);
|
||||
final WifiConfiguration config = uiBase.getController().getConfig();
|
||||
final WifiConfigController configController = uiBase.getController();
|
||||
|
||||
if (config == null) {
|
||||
if (mSelectedAccessPoint != null
|
||||
&& !requireKeyStore(mSelectedAccessPoint.getConfig())) {
|
||||
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
||||
}
|
||||
} else if (config.networkId != -1) {
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
}
|
||||
} else {
|
||||
if (uiBase.isEdit() || requireKeyStore(config)) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
} else {
|
||||
mWifiManager.connectNetwork(config);
|
||||
}
|
||||
switch(configController.chosenNetworkSetupMethod()) {
|
||||
case WifiConfigController.WPS_PBC:
|
||||
mWifiManager.startWpsPbc(mSelectedAccessPoint.bssid);
|
||||
break;
|
||||
case WifiConfigController.WPS_PIN:
|
||||
int apPin = configController.getWpsPin();
|
||||
mWifiManager.startWpsPin(mSelectedAccessPoint.bssid, apPin);
|
||||
break;
|
||||
case WifiConfigController.MANUAL:
|
||||
final WifiConfiguration config = configController.getConfig();
|
||||
|
||||
if (config == null) {
|
||||
if (mSelectedAccessPoint != null
|
||||
&& !requireKeyStore(mSelectedAccessPoint.getConfig())) {
|
||||
mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
|
||||
}
|
||||
} else if (config.networkId != INVALID_NETWORK_ID) {
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
}
|
||||
} else {
|
||||
if (uiBase.isEdit() || requireKeyStore(config)) {
|
||||
mWifiManager.saveNetwork(config);
|
||||
} else {
|
||||
mWifiManager.connectNetwork(config);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
detachConfigPreference();
|
||||
|
Reference in New Issue
Block a user