Filter out unsupported security type for DPP configuration.
There is different Wi-Fi security support between ZXing's Wi-Fi QR code format and Wi-Fi DPP QR code format. ZXing's Wi-Fi QR code format: supports WEP / WPA / none security Wi-Fi DPP: supports WPA / SAE So we will have different UI behavior for different security. WEP & none security: only support QR code generator WPA: supports both QR code generator & scanner SAE: only supports QR code scanner others: don't support. The share button is invisible Bug: 123212410 Test: manual test Change-Id: I87962d730282fc2c1b96223dca6feb79235fe5a1
This commit is contained in:
@@ -290,7 +290,8 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
||||
.setButton2OnClickListener(view -> signIntoNetwork())
|
||||
.setButton3Text(R.string.share)
|
||||
.setButton3Icon(R.drawable.ic_qrcode_24dp)
|
||||
.setButton3OnClickListener(view -> shareNetwork());
|
||||
.setButton3OnClickListener(view -> shareNetwork())
|
||||
.setButton3Visible(WifiDppUtils.isSuportConfigurator(mContext, mAccessPoint));
|
||||
|
||||
mSignalStrengthPref = screen.findPreference(KEY_SIGNAL_STRENGTH_PREF);
|
||||
mTxLinkSpeedPref = screen.findPreference(KEY_TX_LINK_SPEED);
|
||||
@@ -558,10 +559,15 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
||||
/**
|
||||
* Show QR code to share the network represented by this preference.
|
||||
*/
|
||||
public void launchQRCodeGenerator() {
|
||||
Intent intent = WifiDppUtils.getConfiguratorQrCodeGeneratorIntent(mContext, mWifiManager,
|
||||
public void launchWifiDppConfiguratorActivity() {
|
||||
final Intent intent = WifiDppUtils.getConfiguratorIntentOrNull(mContext, mWifiManager,
|
||||
mAccessPoint);
|
||||
mContext.startActivity(intent);
|
||||
|
||||
if (intent == null) {
|
||||
Log.e(TAG, "Launch Wi-Fi DPP configurator with a wrong Wi-Fi network!");
|
||||
} else {
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -584,7 +590,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
||||
WifiNetworkDetailsFragment.REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
|
||||
}
|
||||
} else {
|
||||
launchQRCodeGenerator();
|
||||
launchWifiDppConfiguratorActivity();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -152,7 +152,7 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
|
||||
|
||||
if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS
|
||||
&& resultCode == Activity.RESULT_OK) {
|
||||
mWifiDetailPreferenceController.launchQRCodeGenerator();
|
||||
mWifiDetailPreferenceController.launchWifiDppConfiguratorActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -84,9 +84,18 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem item = menu.add(0, Menu.FIRST, 0, R.string.next_label);
|
||||
item.setIcon(R.drawable.ic_scan_24dp);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
final WifiNetworkConfig wifiNetworkConfig = getWifiNetworkConfigFromHostActivity();
|
||||
MenuItem menuItem;
|
||||
if (wifiNetworkConfig.isSupportConfiguratorQrCodeScanner(getActivity())) {
|
||||
menuItem = menu.add(0, Menu.FIRST, 0, R.string.next_label);
|
||||
menuItem.setIcon(R.drawable.ic_scan_24dp);
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
} else {
|
||||
menuItem = menu.findItem(Menu.FIRST);
|
||||
if (menuItem != null) {
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
}
|
||||
}
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
@@ -116,11 +125,7 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
mQrCodeView = view.findViewById(R.id.qrcode_view);
|
||||
|
||||
mHeaderIcon.setImageResource(R.drawable.ic_qrcode_24dp);
|
||||
WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
||||
.getWifiNetworkConfig();
|
||||
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
||||
throw new IllegalStateException("Invalid Wi-Fi network for configuring");
|
||||
}
|
||||
final WifiNetworkConfig wifiNetworkConfig = getWifiNetworkConfigFromHostActivity();
|
||||
mTitle.setText(R.string.wifi_dpp_share_wifi);
|
||||
mSummary.setText(getString(R.string.wifi_dpp_scan_qr_code_with_another_device,
|
||||
wifiNetworkConfig.getSsid()));
|
||||
@@ -139,4 +144,14 @@ public class WifiDppQrCodeGeneratorFragment extends WifiDppQrCodeBaseFragment {
|
||||
Log.e(TAG, "Error generatting QR code bitmap " + e);
|
||||
}
|
||||
}
|
||||
|
||||
WifiNetworkConfig getWifiNetworkConfigFromHostActivity() {
|
||||
final WifiNetworkConfig wifiNetworkConfig = ((WifiNetworkConfig.Retriever) getActivity())
|
||||
.getWifiNetworkConfig();
|
||||
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
||||
throw new IllegalStateException("Invalid Wi-Fi network for configuring");
|
||||
}
|
||||
|
||||
return wifiNetworkConfig;
|
||||
}
|
||||
}
|
||||
|
@@ -134,26 +134,36 @@ public class WifiDppUtils {
|
||||
private static String getSecurityString(AccessPoint accessPoint) {
|
||||
switch(accessPoint.getSecurity()) {
|
||||
case AccessPoint.SECURITY_WEP:
|
||||
return "WEP";
|
||||
return WifiQrCode.SECURITY_WEP;
|
||||
case AccessPoint.SECURITY_PSK:
|
||||
return "WPA";
|
||||
return WifiQrCode.SECURITY_WPA;
|
||||
case AccessPoint.SECURITY_SAE:
|
||||
return WifiQrCode.SECURITY_SAE;
|
||||
default:
|
||||
return "nopass";
|
||||
return WifiQrCode.SECURITY_NO_PASSWORD;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an intent to launch QR code generator.
|
||||
* Returns an intent to launch QR code generator or scanner according to the Wi-Fi network
|
||||
* security. It may return null if the security is not supported by QR code generator nor
|
||||
* scanner.
|
||||
*
|
||||
* @param context The context to use for the content resolver
|
||||
* @param wifiManager An instance of {@link WifiManager}
|
||||
* @param accessPoint An instance of {@link AccessPoint}
|
||||
* @return Intent for launching QR code generator
|
||||
*/
|
||||
public static Intent getConfiguratorQrCodeGeneratorIntent(Context context,
|
||||
public static Intent getConfiguratorIntentOrNull(Context context,
|
||||
WifiManager wifiManager, AccessPoint accessPoint) {
|
||||
final Intent intent = new Intent(context, WifiDppConfiguratorActivity.class);
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
if (isSupportConfiguratorQrCodeGenerator(accessPoint)) {
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_GENERATOR);
|
||||
} else if (isSupportConfiguratorQrCodeScanner(context, accessPoint)) {
|
||||
intent.setAction(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
final WifiConfiguration wifiConfig = accessPoint.getConfig();
|
||||
final String ssid = removeFirstAndLastDoubleQuotes(wifiConfig.SSID);
|
||||
@@ -183,4 +193,43 @@ public class WifiDppUtils {
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Android Q supports Wi-Fi configurator by:
|
||||
*
|
||||
* 1. QR code generator of ZXing's Wi-Fi network config format.
|
||||
* and
|
||||
* 2. QR code scanner of Wi-Fi DPP QR code format.
|
||||
*/
|
||||
public static boolean isSuportConfigurator(Context context, AccessPoint accessPoint) {
|
||||
return isSupportConfiguratorQrCodeScanner(context, accessPoint) ||
|
||||
isSupportConfiguratorQrCodeGenerator(accessPoint);
|
||||
}
|
||||
|
||||
private static boolean isSupportConfiguratorQrCodeScanner(Context context,
|
||||
AccessPoint accessPoint) {
|
||||
if (!isWifiDppEnabled(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// DPP 1.0 only supports SAE and PSK.
|
||||
final int security = accessPoint.getSecurity();
|
||||
if (security == AccessPoint.SECURITY_SAE || security == AccessPoint.SECURITY_PSK) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSupportConfiguratorQrCodeGenerator(AccessPoint accessPoint) {
|
||||
// QR code generator produces QR code with ZXing's Wi-Fi network config format,
|
||||
// it supports PSK and WEP and non security
|
||||
final int security = accessPoint.getSecurity();
|
||||
if (security == AccessPoint.SECURITY_PSK || security == AccessPoint.SECURITY_WEP ||
|
||||
security == AccessPoint.SECURITY_NONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_NO_PASSWORD;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_SAE;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WEP;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WPA;
|
||||
|
||||
@@ -208,6 +209,19 @@ public class WifiNetworkConfig {
|
||||
wifiManager.connect(wifiConfiguration, listener);
|
||||
}
|
||||
|
||||
public boolean isSupportConfiguratorQrCodeScanner(Context context) {
|
||||
if (!WifiDppUtils.isWifiDppEnabled(context)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// DPP 1.0 only supports SAE and PSK.
|
||||
if (SECURITY_SAE.equals(mSecurity) || SECURITY_WPA.equals(mSecurity)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a simplified method from {@code WifiConfigController.getConfig()}
|
||||
*/
|
||||
|
@@ -67,6 +67,7 @@ public class WifiQrCode {
|
||||
public static final String SECURITY_NO_PASSWORD = "nopass";
|
||||
public static final String SECURITY_WEP = "WEP";
|
||||
public static final String SECURITY_WPA = "WPA";
|
||||
public static final String SECURITY_SAE = "WPA3";
|
||||
|
||||
private String mQrCode;
|
||||
|
||||
|
Reference in New Issue
Block a user