Distinguish different errors of wifi QR code
When failure occurs after scanning wifi QR code, only "Check connection
and try again" will show, which is confusing for user to understand the
errors and take next action.
Add more string resources to cover different errors.
Co-authored-by: Yufan Cao <Yufan.Cao@sony.com>
Flag: EXEMPT bugfix
Test: manual test
Bug: 362305039
Change-Id: I85145eb67eecdc3aa06bb7b8a7b3e7f0ffea1f62
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fb95aa3..3fe6187 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2287,6 +2287,10 @@
<string name="wifi_dpp_failure_enrollee_rejected_configuration">Contact the device manufacturer</string>
<!-- Hint for Wi-Fi connection fail [CHAR LIMIT=NONE] -->
<string name="wifi_dpp_check_connection_try_again">Check connection and try again</string>
+ <!-- Hint for Wi-Fi connection fail [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_check_connection_no_matched_ssid">This Wi\u2011Fi network isn\u2019t available right now</string>
+ <!-- Hint for Wi-Fi connection fail [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_check_connection_no_matched_security">There\u2019s a problem with this QR code. Try connecting another way.</string>
<!-- Title for the fragment choose network [CHAR LIMIT=50] -->
<string name="wifi_dpp_choose_network">Choose network</string>
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=NONE] -->
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index 34948dc..97e41b4 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.wifi.dpp;
+import static android.content.res.Resources.ID_NULL;
import static android.net.wifi.WifiInfo.sanitizeSsid;
import android.app.Activity;
@@ -101,6 +102,8 @@
// Interval between initiating WifiPickerTracker scans.
private static final long SCAN_INTERVAL_MILLIS = 10_000;
+ private static final @StringRes int REACHABLE_WIFI_NETWORK = ID_NULL;
+
private QrCamera mCamera;
private TextureView mTextureView;
private QrDecorateView mDecorateView;
@@ -201,8 +204,9 @@
wifiManager.enableNetwork(id, /* attemptConnect */ false);
// WifiTracker only contains a hidden SSID Wi-Fi network if it's saved.
// We can't check if a hidden SSID Wi-Fi network is reachable in advance.
- if (qrCodeWifiConfiguration.hiddenSSID
- || isReachableWifiNetwork(qrCodeWifiConfiguration)) {
+ @StringRes int wifiReachabilityStringId =
+ getWifiReachabilityStringId(qrCodeWifiConfiguration);
+ if (wifiReachabilityStringId == REACHABLE_WIFI_NETWORK) {
hasHiddenOrReachableWifiNetwork = true;
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
wifiManager.connect(id,
@@ -210,8 +214,7 @@
}
if (!hasHiddenOrReachableWifiNetwork) {
- showErrorMessageAndRestartCamera(
- R.string.wifi_dpp_check_connection_try_again);
+ showErrorMessageAndRestartCamera(wifiReachabilityStringId);
return;
}
@@ -242,7 +245,10 @@
WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext());
}
- private boolean isReachableWifiNetwork(WifiConfiguration wifiConfiguration) {
+ private @StringRes int getWifiReachabilityStringId(WifiConfiguration wifiConfiguration) {
+ if (wifiConfiguration.hiddenSSID) {
+ return REACHABLE_WIFI_NETWORK;
+ }
final List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
if (connectedWifiEntry != null) {
@@ -250,24 +256,29 @@
wifiEntries.add(connectedWifiEntry);
}
+ boolean canFindNetwork = false;
for (WifiEntry wifiEntry : wifiEntries) {
if (!TextUtils.equals(wifiEntry.getSsid(), sanitizeSsid(wifiConfiguration.SSID))) {
continue;
}
+ canFindNetwork = true;
final int security =
WifiDppUtils.getSecurityTypeFromWifiConfiguration(wifiConfiguration);
if (security == wifiEntry.getSecurity()) {
- return true;
+ return REACHABLE_WIFI_NETWORK;
}
// Default security type of PSK/SAE transition mode WifiEntry is SECURITY_PSK and
// there is no way to know if a WifiEntry is of transition mode. Give it a chance.
if (security == WifiEntry.SECURITY_SAE
&& wifiEntry.getSecurity() == WifiEntry.SECURITY_PSK) {
- return true;
+ return REACHABLE_WIFI_NETWORK;
}
}
- return false;
+ if (canFindNetwork) {
+ return R.string.wifi_dpp_check_connection_no_matched_security;
+ }
+ return R.string.wifi_dpp_check_connection_no_matched_ssid;
}
@VisibleForTesting