Merge "Distinguish different errors of wifi QR code" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
78153998c7
@@ -2291,6 +2291,10 @@
|
|||||||
<string name="wifi_dpp_failure_enrollee_rejected_configuration">Contact the device manufacturer</string>
|
<string name="wifi_dpp_failure_enrollee_rejected_configuration">Contact the device manufacturer</string>
|
||||||
<!-- Hint for Wi-Fi connection fail [CHAR LIMIT=NONE] -->
|
<!-- Hint for Wi-Fi connection fail [CHAR LIMIT=NONE] -->
|
||||||
<string name="wifi_dpp_check_connection_try_again">Check connection and try again</string>
|
<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] -->
|
<!-- Title for the fragment choose network [CHAR LIMIT=50] -->
|
||||||
<string name="wifi_dpp_choose_network">Choose network</string>
|
<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] -->
|
<!-- Hint for the user to center another device's QR code in the below camera window [CHAR LIMIT=NONE] -->
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
|
import static android.content.res.Resources.ID_NULL;
|
||||||
import static android.net.wifi.WifiInfo.sanitizeSsid;
|
import static android.net.wifi.WifiInfo.sanitizeSsid;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -101,6 +102,8 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
// Interval between initiating WifiPickerTracker scans.
|
// Interval between initiating WifiPickerTracker scans.
|
||||||
private static final long SCAN_INTERVAL_MILLIS = 10_000;
|
private static final long SCAN_INTERVAL_MILLIS = 10_000;
|
||||||
|
|
||||||
|
private static final @StringRes int REACHABLE_WIFI_NETWORK = ID_NULL;
|
||||||
|
|
||||||
private QrCamera mCamera;
|
private QrCamera mCamera;
|
||||||
private TextureView mTextureView;
|
private TextureView mTextureView;
|
||||||
private QrDecorateView mDecorateView;
|
private QrDecorateView mDecorateView;
|
||||||
@@ -201,8 +204,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
wifiManager.enableNetwork(id, /* attemptConnect */ false);
|
wifiManager.enableNetwork(id, /* attemptConnect */ false);
|
||||||
// WifiTracker only contains a hidden SSID Wi-Fi network if it's saved.
|
// 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.
|
// We can't check if a hidden SSID Wi-Fi network is reachable in advance.
|
||||||
if (qrCodeWifiConfiguration.hiddenSSID
|
@StringRes int wifiReachabilityStringId =
|
||||||
|| isReachableWifiNetwork(qrCodeWifiConfiguration)) {
|
getWifiReachabilityStringId(qrCodeWifiConfiguration);
|
||||||
|
if (wifiReachabilityStringId == REACHABLE_WIFI_NETWORK) {
|
||||||
hasHiddenOrReachableWifiNetwork = true;
|
hasHiddenOrReachableWifiNetwork = true;
|
||||||
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
|
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
|
||||||
wifiManager.connect(id,
|
wifiManager.connect(id,
|
||||||
@@ -210,8 +214,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!hasHiddenOrReachableWifiNetwork) {
|
if (!hasHiddenOrReachableWifiNetwork) {
|
||||||
showErrorMessageAndRestartCamera(
|
showErrorMessageAndRestartCamera(wifiReachabilityStringId);
|
||||||
R.string.wifi_dpp_check_connection_try_again);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +245,10 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext());
|
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 List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
|
||||||
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
|
final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
|
||||||
if (connectedWifiEntry != null) {
|
if (connectedWifiEntry != null) {
|
||||||
@@ -250,24 +256,29 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
wifiEntries.add(connectedWifiEntry);
|
wifiEntries.add(connectedWifiEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean canFindNetwork = false;
|
||||||
for (WifiEntry wifiEntry : wifiEntries) {
|
for (WifiEntry wifiEntry : wifiEntries) {
|
||||||
if (!TextUtils.equals(wifiEntry.getSsid(), sanitizeSsid(wifiConfiguration.SSID))) {
|
if (!TextUtils.equals(wifiEntry.getSsid(), sanitizeSsid(wifiConfiguration.SSID))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
canFindNetwork = true;
|
||||||
final int security =
|
final int security =
|
||||||
WifiDppUtils.getSecurityTypeFromWifiConfiguration(wifiConfiguration);
|
WifiDppUtils.getSecurityTypeFromWifiConfiguration(wifiConfiguration);
|
||||||
if (security == wifiEntry.getSecurity()) {
|
if (security == wifiEntry.getSecurity()) {
|
||||||
return true;
|
return REACHABLE_WIFI_NETWORK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default security type of PSK/SAE transition mode WifiEntry is SECURITY_PSK and
|
// 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.
|
// there is no way to know if a WifiEntry is of transition mode. Give it a chance.
|
||||||
if (security == WifiEntry.SECURITY_SAE
|
if (security == WifiEntry.SECURITY_SAE
|
||||||
&& wifiEntry.getSecurity() == WifiEntry.SECURITY_PSK) {
|
&& 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
|
@VisibleForTesting
|
||||||
|
|||||||
Reference in New Issue
Block a user