Merge "wifi: Using framework uri parsing" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
c310438a82
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -26,6 +27,7 @@ import android.debug.IAdbManager;
|
|||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@@ -47,7 +49,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SetupWizardUtils;
|
import com.android.settings.SetupWizardUtils;
|
||||||
import com.android.settings.wifi.dpp.AdbQrCode;
|
import com.android.settings.wifi.dpp.AdbQrCode;
|
||||||
import com.android.settings.wifi.dpp.WifiDppQrCodeBaseFragment;
|
import com.android.settings.wifi.dpp.WifiDppQrCodeBaseFragment;
|
||||||
import com.android.settings.wifi.dpp.WifiNetworkConfig;
|
|
||||||
import com.android.settingslib.qrcode.QrCamera;
|
import com.android.settingslib.qrcode.QrCamera;
|
||||||
import com.android.settingslib.qrcode.QrDecorateView;
|
import com.android.settingslib.qrcode.QrDecorateView;
|
||||||
|
|
||||||
@@ -81,7 +82,8 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
|
|||||||
|
|
||||||
/** QR code data scanned by camera */
|
/** QR code data scanned by camera */
|
||||||
private AdbQrCode mAdbQrCode;
|
private AdbQrCode mAdbQrCode;
|
||||||
private WifiNetworkConfig mAdbConfig;
|
@Nullable
|
||||||
|
private WifiConfiguration mAdbConfig;
|
||||||
|
|
||||||
private IAdbManager mAdbManager;
|
private IAdbManager mAdbManager;
|
||||||
|
|
||||||
@@ -287,14 +289,17 @@ public class AdbQrcodeScannerFragment extends WifiDppQrCodeBaseFragment implemen
|
|||||||
AdbQrCode.triggerVibrationForQrCodeRecognition(getContext());
|
AdbQrCode.triggerVibrationForQrCodeRecognition(getContext());
|
||||||
mVerifyingTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
mVerifyingTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
||||||
try {
|
try {
|
||||||
mAdbManager.enablePairingByQrCode(mAdbConfig.getSsid(),
|
if (mAdbConfig != null) {
|
||||||
mAdbConfig.getPreSharedKey());
|
mAdbManager.enablePairingByQrCode(mAdbConfig.SSID,
|
||||||
|
mAdbConfig.preSharedKey);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Unable to enable QR code pairing");
|
Log.e(TAG, "Unable to enable QR code pairing" + e);
|
||||||
|
}
|
||||||
getActivity().setResult(Activity.RESULT_CANCELED);
|
getActivity().setResult(Activity.RESULT_CANCELED);
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleCameraFailure() {
|
public void handleCameraFailure() {
|
||||||
|
@@ -16,8 +16,12 @@
|
|||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.wifi.UriParserResults;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of WifiQrCode to support ADB QR code format.
|
* Extension of WifiQrCode to support ADB QR code format.
|
||||||
* It will be based on the ZXing format:
|
* It will be based on the ZXing format:
|
||||||
@@ -27,31 +31,31 @@ import android.text.TextUtils;
|
|||||||
public class AdbQrCode extends WifiQrCode {
|
public class AdbQrCode extends WifiQrCode {
|
||||||
static final String SECURITY_ADB = "ADB";
|
static final String SECURITY_ADB = "ADB";
|
||||||
|
|
||||||
private WifiNetworkConfig mAdbConfig;
|
private WifiConfiguration mAdbConfig;
|
||||||
|
|
||||||
public AdbQrCode(String qrCode) throws IllegalArgumentException {
|
public AdbQrCode(String qrCode) throws IllegalArgumentException {
|
||||||
super(qrCode);
|
super(qrCode);
|
||||||
|
|
||||||
// Only accept the zxing format.
|
// Only accept the zxing format.
|
||||||
if (!WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG.equals(getScheme())) {
|
if (getScheme() != UriParserResults.URI_SCHEME_ZXING_WIFI_NETWORK_CONFIG) {
|
||||||
throw new IllegalArgumentException("DPP format not supported for ADB QR code");
|
throw new IllegalArgumentException("DPP format not supported for ADB QR code");
|
||||||
}
|
}
|
||||||
|
mAdbConfig = getWifiConfiguration();
|
||||||
|
|
||||||
mAdbConfig = getWifiNetworkConfig();
|
if (mAdbConfig == null) {
|
||||||
if (!SECURITY_ADB.equals(mAdbConfig.getSecurity())) {
|
throw new IllegalArgumentException("Null config when parsing ADB QR code");
|
||||||
throw new IllegalArgumentException("Invalid security type");
|
|
||||||
}
|
}
|
||||||
|
if (TextUtils.isEmpty(mAdbConfig.SSID)) {
|
||||||
if (TextUtils.isEmpty(mAdbConfig.getSsid())) {
|
|
||||||
throw new IllegalArgumentException("Empty service name");
|
throw new IllegalArgumentException("Empty service name");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty(mAdbConfig.getPreSharedKey())) {
|
if (TextUtils.isEmpty(mAdbConfig.preSharedKey)) {
|
||||||
throw new IllegalArgumentException("Empty password");
|
throw new IllegalArgumentException("Empty password");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiNetworkConfig getAdbNetworkConfig() {
|
@NonNull
|
||||||
|
public WifiConfiguration getAdbNetworkConfig() {
|
||||||
return mAdbConfig;
|
return mAdbConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ import android.graphics.Matrix;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
import android.net.wifi.EasyConnectStatusCallback;
|
import android.net.wifi.EasyConnectStatusCallback;
|
||||||
|
import android.net.wifi.UriParserResults;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -183,33 +184,30 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
// one for open network and one for enhanced open network.
|
// one for open network and one for enhanced open network.
|
||||||
final WifiManager wifiManager =
|
final WifiManager wifiManager =
|
||||||
context.getSystemService(WifiManager.class);
|
context.getSystemService(WifiManager.class);
|
||||||
final WifiNetworkConfig qrCodeWifiNetworkConfig =
|
final WifiConfiguration qrCodeWifiConfiguration = (WifiConfiguration) msg.obj;
|
||||||
(WifiNetworkConfig)msg.obj;
|
|
||||||
final List<WifiConfiguration> qrCodeWifiConfigurations =
|
|
||||||
qrCodeWifiNetworkConfig.getWifiConfigurations();
|
|
||||||
|
|
||||||
// Adds all Wi-Fi networks in QR code to the set of configured networks and
|
// Adds all Wi-Fi networks in QR code to the set of configured networks and
|
||||||
// connects to it if it's reachable.
|
// connects to it if it's reachable.
|
||||||
boolean hasHiddenOrReachableWifiNetwork = false;
|
boolean hasHiddenOrReachableWifiNetwork = false;
|
||||||
for (WifiConfiguration qrCodeWifiConfiguration : qrCodeWifiConfigurations) {
|
|
||||||
final int id = wifiManager.addNetwork(qrCodeWifiConfiguration);
|
final int id = wifiManager.addNetwork(qrCodeWifiConfiguration);
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canConnectWifi(qrCodeWifiConfiguration.SSID)) return;
|
if (!canConnectWifi(qrCodeWifiConfiguration.SSID)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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 ||
|
if (qrCodeWifiConfiguration.hiddenSSID
|
||||||
isReachableWifiNetwork(qrCodeWifiConfiguration)) {
|
|| isReachableWifiNetwork(qrCodeWifiConfiguration)) {
|
||||||
hasHiddenOrReachableWifiNetwork = true;
|
hasHiddenOrReachableWifiNetwork = true;
|
||||||
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
|
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
|
||||||
wifiManager.connect(id,
|
wifiManager.connect(id,
|
||||||
/* listener */ WifiDppQrCodeScannerFragment.this);
|
/* listener */ WifiDppQrCodeScannerFragment.this);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasHiddenOrReachableWifiNetwork) {
|
if (!hasHiddenOrReachableWifiNetwork) {
|
||||||
showErrorMessageAndRestartCamera(
|
showErrorMessageAndRestartCamera(
|
||||||
@@ -530,8 +528,9 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// It's impossible to provision other device with ZXing Wi-Fi Network config format
|
// It's impossible to provision other device with ZXing Wi-Fi Network config format
|
||||||
final String scheme = mWifiQrCode.getScheme();
|
if (mIsConfiguratorMode
|
||||||
if (mIsConfiguratorMode && WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG.equals(scheme)) {
|
&& mWifiQrCode.getScheme()
|
||||||
|
== UriParserResults.URI_SCHEME_ZXING_WIFI_NETWORK_CONFIG) {
|
||||||
showErrorMessage(R.string.wifi_dpp_qr_code_is_not_valid_format);
|
showErrorMessage(R.string.wifi_dpp_qr_code_is_not_valid_format);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -545,11 +544,11 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
@Override
|
@Override
|
||||||
public void handleSuccessfulResult(String qrCode) {
|
public void handleSuccessfulResult(String qrCode) {
|
||||||
switch (mWifiQrCode.getScheme()) {
|
switch (mWifiQrCode.getScheme()) {
|
||||||
case WifiQrCode.SCHEME_DPP:
|
case UriParserResults.URI_SCHEME_DPP:
|
||||||
handleWifiDpp();
|
handleWifiDpp();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG:
|
case UriParserResults.URI_SCHEME_ZXING_WIFI_NETWORK_CONFIG:
|
||||||
handleZxingWifiFormat();
|
handleZxingWifiFormat();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -567,7 +566,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
|
|
||||||
private void handleZxingWifiFormat() {
|
private void handleZxingWifiFormat() {
|
||||||
Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
|
Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
|
||||||
message.obj = new WifiQrCode(mWifiQrCode.getQrCode()).getWifiNetworkConfig();
|
message.obj = new WifiQrCode(mWifiQrCode.getQrCode()).getWifiConfiguration();
|
||||||
|
|
||||||
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
@@ -16,14 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
package com.android.settings.wifi.dpp;
|
||||||
|
|
||||||
|
import android.annotation.NonNull;
|
||||||
|
import android.net.wifi.UriParserResults;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
|
import android.net.wifi.WifiUriParser;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supports to parse 2 types of QR code
|
* Supports to parse 2 types of QR code
|
||||||
@@ -70,19 +68,8 @@ public class WifiQrCode {
|
|||||||
static final String SECURITY_SAE = "SAE";
|
static final String SECURITY_SAE = "SAE";
|
||||||
|
|
||||||
private String mQrCode;
|
private String mQrCode;
|
||||||
|
@NonNull
|
||||||
/**
|
private UriParserResults mUriParserResults;
|
||||||
* SCHEME_DPP for standard Wi-Fi device provision protocol; SCHEME_ZXING_WIFI_NETWORK_CONFIG
|
|
||||||
* for ZXing reader library' Wi-Fi Network config format
|
|
||||||
*/
|
|
||||||
private String mScheme;
|
|
||||||
|
|
||||||
// Data from parsed Wi-Fi DPP QR code
|
|
||||||
private String mPublicKey;
|
|
||||||
private String mInformation;
|
|
||||||
|
|
||||||
// Data from parsed ZXing reader library's Wi-Fi Network config format
|
|
||||||
private WifiNetworkConfig mWifiNetworkConfig;
|
|
||||||
|
|
||||||
public WifiQrCode(String qrCode) throws IllegalArgumentException {
|
public WifiQrCode(String qrCode) throws IllegalArgumentException {
|
||||||
if (TextUtils.isEmpty(qrCode)) {
|
if (TextUtils.isEmpty(qrCode)) {
|
||||||
@@ -90,111 +77,14 @@ public class WifiQrCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mQrCode = qrCode;
|
mQrCode = qrCode;
|
||||||
|
try {
|
||||||
if (qrCode.startsWith(PREFIX_DPP)) {
|
mUriParserResults = WifiUriParser.parseUri(mQrCode);
|
||||||
mScheme = SCHEME_DPP;
|
Log.i("WifiQrCode", "mUriParserResults = " + mUriParserResults);
|
||||||
parseWifiDppQrCode(qrCode);
|
} catch (IllegalArgumentException ie) {
|
||||||
} else if (qrCode.startsWith(PREFIX_ZXING_WIFI_NETWORK_CONFIG)) {
|
|
||||||
mScheme = SCHEME_ZXING_WIFI_NETWORK_CONFIG;
|
|
||||||
parseZxingWifiQrCode(qrCode);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid scheme");
|
throw new IllegalArgumentException("Invalid scheme");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parses Wi-Fi DPP QR code string */
|
|
||||||
private void parseWifiDppQrCode(String qrCode) throws IllegalArgumentException {
|
|
||||||
List<String> keyValueList = getKeyValueList(qrCode, PREFIX_DPP, DELIMITER_QR_CODE);
|
|
||||||
|
|
||||||
String publicKey = getValueOrNull(keyValueList, PREFIX_DPP_PUBLIC_KEY);
|
|
||||||
if (TextUtils.isEmpty(publicKey)) {
|
|
||||||
throw new IllegalArgumentException("Invalid format");
|
|
||||||
}
|
|
||||||
mPublicKey = publicKey;
|
|
||||||
|
|
||||||
mInformation = getValueOrNull(keyValueList, PREFIX_DPP_INFORMATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Parses ZXing reader library's Wi-Fi Network config format */
|
|
||||||
private void parseZxingWifiQrCode(String qrCode) throws IllegalArgumentException {
|
|
||||||
List<String> keyValueList = getKeyValueList(qrCode, PREFIX_ZXING_WIFI_NETWORK_CONFIG,
|
|
||||||
DELIMITER_QR_CODE);
|
|
||||||
|
|
||||||
String security = getValueOrNull(keyValueList, PREFIX_ZXING_SECURITY);
|
|
||||||
String ssid = getValueOrNull(keyValueList, PREFIX_ZXING_SSID);
|
|
||||||
String password = getValueOrNull(keyValueList, PREFIX_ZXING_PASSWORD);
|
|
||||||
String hiddenSsidString = getValueOrNull(keyValueList, PREFIX_ZXING_HIDDEN_SSID);
|
|
||||||
|
|
||||||
boolean hiddenSsid = "true".equalsIgnoreCase(hiddenSsidString);
|
|
||||||
|
|
||||||
//"\", ";", "," and ":" are escaped with a backslash "\", should remove at first
|
|
||||||
security = removeBackSlash(security);
|
|
||||||
ssid = removeBackSlash(ssid);
|
|
||||||
password = removeBackSlash(password);
|
|
||||||
|
|
||||||
mWifiNetworkConfig = WifiNetworkConfig.getValidConfigOrNull(security, ssid, password,
|
|
||||||
hiddenSsid, WifiConfiguration.INVALID_NETWORK_ID, /* isHotspot */ false);
|
|
||||||
|
|
||||||
if (mWifiNetworkConfig == null) {
|
|
||||||
throw new IllegalArgumentException("Invalid format");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Splits key/value pairs from qrCode
|
|
||||||
*
|
|
||||||
* @param qrCode the QR code raw string
|
|
||||||
* @param prefixQrCode the string before all key/value pairs in qrCode
|
|
||||||
* @param delimiter the string to split key/value pairs, can't contain a backslash
|
|
||||||
* @return a list contains string of key/value (e.g. K:key1)
|
|
||||||
*/
|
|
||||||
private List<String> getKeyValueList(String qrCode, String prefixQrCode,
|
|
||||||
String delimiter) {
|
|
||||||
String keyValueString = qrCode.substring(prefixQrCode.length());
|
|
||||||
|
|
||||||
// Should not treat \delimiter as a delimiter
|
|
||||||
String regex = "(?<!\\\\)" + Pattern.quote(delimiter);
|
|
||||||
|
|
||||||
return Arrays.asList(keyValueString.split(regex));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getValueOrNull(List<String> keyValueList, String prefix) {
|
|
||||||
for (String keyValue : keyValueList) {
|
|
||||||
String strippedKeyValue = keyValue.stripLeading();
|
|
||||||
if (strippedKeyValue.startsWith(prefix)) {
|
|
||||||
return strippedKeyValue.substring(prefix.length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
String removeBackSlash(String input) {
|
|
||||||
if (input == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
boolean backSlash = false;
|
|
||||||
for (char ch : input.toCharArray()) {
|
|
||||||
if (ch != '\\') {
|
|
||||||
sb.append(ch);
|
|
||||||
backSlash = false;
|
|
||||||
} else {
|
|
||||||
if (backSlash) {
|
|
||||||
sb.append(ch);
|
|
||||||
backSlash = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
backSlash = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
String getQrCode() {
|
String getQrCode() {
|
||||||
return mQrCode;
|
return mQrCode;
|
||||||
}
|
}
|
||||||
@@ -205,28 +95,23 @@ public class WifiQrCode {
|
|||||||
* SCHEME_DPP for standard Wi-Fi device provision protocol; SCHEME_ZXING_WIFI_NETWORK_CONFIG
|
* SCHEME_DPP for standard Wi-Fi device provision protocol; SCHEME_ZXING_WIFI_NETWORK_CONFIG
|
||||||
* for ZXing reader library' Wi-Fi Network config format
|
* for ZXing reader library' Wi-Fi Network config format
|
||||||
*/
|
*/
|
||||||
public String getScheme() {
|
public int getScheme() {
|
||||||
return mScheme;
|
return mUriParserResults.getUriScheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Available when {@code getScheme()} returns SCHEME_DPP */
|
/** Available when {@code getScheme()} returns SCHEME_DPP */
|
||||||
@VisibleForTesting
|
|
||||||
String getPublicKey() {
|
String getPublicKey() {
|
||||||
return mPublicKey;
|
return mUriParserResults.getPublicKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** May be available when {@code getScheme()} returns SCHEME_DPP */
|
/** May be available when {@code getScheme()} returns SCHEME_DPP */
|
||||||
public String getInformation() {
|
public String getInformation() {
|
||||||
return mInformation;
|
return mUriParserResults.getInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Available when {@code getScheme()} returns SCHEME_ZXING_WIFI_NETWORK_CONFIG */
|
/** Available when {@code getScheme()} returns SCHEME_ZXING_WIFI_NETWORK_CONFIG */
|
||||||
WifiNetworkConfig getWifiNetworkConfig() {
|
WifiConfiguration getWifiConfiguration() {
|
||||||
if (mWifiNetworkConfig == null) {
|
return mUriParserResults.getWifiConfiguration();
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WifiNetworkConfig(mWifiNetworkConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static WifiQrCode getValidWifiDppQrCodeOrNull(String qrCode) {
|
static WifiQrCode getValidWifiDppQrCodeOrNull(String qrCode) {
|
||||||
|
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.wifi.dpp;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class WifiQrCodeTest {
|
|
||||||
@Test
|
|
||||||
public void testZxParsing_validCode() {
|
|
||||||
WifiNetworkConfig config = new WifiQrCode("WIFI:S:testAbC;T:nopass").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("testAbC");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("nopass");
|
|
||||||
|
|
||||||
config = new WifiQrCode(
|
|
||||||
"WIFI:S:reallyLONGone;T:WEP;P:somepasswo#%^**123rd").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("reallyLONGone");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("WEP");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("somepasswo#%^**123rd");
|
|
||||||
|
|
||||||
config = new WifiQrCode("WIFI:S:anotherone;T:WPA;P:3#=3j9asicla").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("anotherone");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("WPA");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("3#=3j9asicla");
|
|
||||||
|
|
||||||
config = new WifiQrCode("WIFI:S:xx;T:SAE;P:a").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("xx");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("SAE");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("a");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testZxParsing_invalidCodeButShouldWork() {
|
|
||||||
WifiNetworkConfig config = new WifiQrCode(
|
|
||||||
"WIFI:S:testAbC; T:nopass").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("testAbC");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("nopass");
|
|
||||||
|
|
||||||
config = new WifiQrCode(
|
|
||||||
"WIFI:S:reallyLONGone;T:WEP; P:somepassword").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("reallyLONGone");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("WEP");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("somepassword");
|
|
||||||
|
|
||||||
config = new WifiQrCode("WIFI: S:anotherone;T:WPA;P:abcdefghihklmn").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("anotherone");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("WPA");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("abcdefghihklmn");
|
|
||||||
|
|
||||||
config = new WifiQrCode("WIFI: S:xx; T:SAE; P:a").getWifiNetworkConfig();
|
|
||||||
assertThat(config.getSsid()).isEqualTo("xx");
|
|
||||||
assertThat(config.getSecurity()).isEqualTo("SAE");
|
|
||||||
assertThat(config.getPreSharedKey()).isEqualTo("a");
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user