diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index 0887fc5532c..ac11510761c 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -55,6 +55,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; @@ -64,6 +65,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.ProxySelector; import com.android.settings.R; import com.android.settings.wifi.details.WifiPrivacyPreferenceController; +import com.android.settings.wifi.dpp.WifiDppUtils; import com.android.settingslib.Utils; import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.wifi.AccessPoint; @@ -129,6 +131,8 @@ public class WifiConfigController implements TextWatcher, @VisibleForTesting int mAccessPointSecurity; private TextView mPasswordView; + private ImageButton mSsidScanButton; + private ImageButton mPasswordScanButton; private String mUnspecifiedCertString; private String mMultipleCertSetString; @@ -239,6 +243,8 @@ public class WifiConfigController implements TextWatcher, mDoNotValidateEapServerString = mContext.getString(R.string.wifi_do_not_validate_eap_server); + mSsidScanButton = (ImageButton) mView.findViewById(R.id.ssid_scanner_button); + mPasswordScanButton = (ImageButton) mView.findViewById(R.id.password_scanner_button); mDialogContainer = mView.findViewById(R.id.dialog_scrollview); mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings); mIpSettingsSpinner.setOnItemSelectedListener(this); @@ -264,6 +270,7 @@ public class WifiConfigController implements TextWatcher, if (mAccessPoint == null) { // new network configureSecuritySpinner(); mConfigUi.setSubmitButton(res.getString(R.string.wifi_save)); + mPasswordScanButton.setVisibility(View.GONE); } else { mConfigUi.setTitle(mAccessPoint.getTitle()); @@ -408,6 +415,11 @@ public class WifiConfigController implements TextWatcher, mConfigUi.setForgetButton(res.getString(R.string.wifi_forget)); } } + + if (!WifiDppUtils.isSupportEnrolleeQrCodeScanner(mContext, mAccessPointSecurity)) { + mPasswordScanButton.setVisibility(View.GONE); + } + mSsidScanButton.setVisibility(View.GONE); } if (!isSplitSystemUser()) { @@ -1444,6 +1456,12 @@ public class WifiConfigController implements TextWatcher, // Convert menu position to actual Wi-Fi security type mAccessPointSecurity = mSecurityInPosition[position]; showSecurityFields(); + + if (WifiDppUtils.isSupportEnrolleeQrCodeScanner(mContext, mAccessPointSecurity)) { + mSsidScanButton.setVisibility(View.VISIBLE); + } else { + mSsidScanButton.setVisibility(View.GONE); + } } else if (parent == mEapMethodSpinner || parent == mEapCaCertSpinner) { showSecurityFields(); } else if (parent == mPhase2Spinner diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index 6c6444c7d9d..42e88a57b02 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -323,31 +323,36 @@ public class WifiDppUtils { } } + /** + * Checks if QR code scanner supports to config other devices with the Wi-Fi network + * + * @param context The context to use for {@link WifiManager#isEasyConnectSupported()} + * @param accessPoint The {@link AccessPoint} of the Wi-Fi network + */ public 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; + return isSupportWifiDpp(context, accessPoint.getSecurity()); } + /** + * Checks if QR code generator supports to config other devices with the Wi-Fi network + * + * @param accessPoint The {@link AccessPoint} of the Wi-Fi network + */ public 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 isSupportZxing(accessPoint.getSecurity()); + } - return false; + /** + * Checks if this device supports to be configured by the Wi-Fi network of the security + * + * @param context The context to use for {@link WifiManager#isEasyConnectSupported()} + * @param accesspointSecurity The security constants defined in {@link AccessPoint} + */ + public static boolean isSupportEnrolleeQrCodeScanner(Context context, + int accesspointSecurity) { + return isSupportWifiDpp(context, accesspointSecurity) || + isSupportZxing(accesspointSecurity); } private static boolean isSupportHotspotConfiguratorQrCodeGenerator( @@ -358,4 +363,27 @@ public class WifiDppUtils { return wifiConfiguration.allowedKeyManagement.get(KeyMgmt.WPA2_PSK) || wifiConfiguration.allowedKeyManagement.get(KeyMgmt.NONE); } + + private static boolean isSupportWifiDpp(Context context, int accesspointSecurity) { + if (!isWifiDppEnabled(context)) { + return false; + } + + // DPP 1.0 only supports SAE and PSK. + if (accesspointSecurity == AccessPoint.SECURITY_SAE || + accesspointSecurity == AccessPoint.SECURITY_PSK) { + return true; + } + return false; + } + + // TODO (b/124131581 b/129396816): TO support WPA3 securities (SAE & OWE), change here at first + private static boolean isSupportZxing(int accesspointSecurity) { + if (accesspointSecurity == AccessPoint.SECURITY_PSK || + accesspointSecurity == AccessPoint.SECURITY_WEP || + accesspointSecurity == AccessPoint.SECURITY_NONE) { + return true; + } + return false; + } }