Supports to share Wi-Fi networks of WPA3 security SAE & OWE via QR code generator
When scanned a no password ZXing QR code, add both open network & enhanced open network to configured Wi-Fi network list because this kind of QR code may refer to a open network or an enhanced open network. Bug: 124131581 Test: manual Change-Id: Id9f85ef8dcdf72347be8106938437aecd0eed9f5
This commit is contained in:
@@ -46,6 +46,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -57,6 +58,7 @@ import com.android.settingslib.wifi.AccessPoint;
|
||||
import com.android.settingslib.wifi.WifiTracker;
|
||||
import com.android.settingslib.wifi.WifiTrackerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment implements
|
||||
@@ -104,7 +106,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
private WifiQrCode mWifiQrCode;
|
||||
|
||||
/** The WifiConfiguration connecting for enrollee usage */
|
||||
private WifiConfiguration mWifiConfiguration;
|
||||
private WifiConfiguration mEnrolleeWifiConfiguration;
|
||||
|
||||
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
|
||||
|
||||
@@ -140,14 +142,8 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
break;
|
||||
|
||||
case MESSAGE_SCAN_WIFI_DPP_SUCCESS:
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
}
|
||||
|
||||
mDecorateView.setFocused(true);
|
||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||
|
||||
if (mScanWifiDppSuccessListener == null) {
|
||||
// mScanWifiDppSuccessListener may be null after onDetach(), do nothing here
|
||||
return;
|
||||
}
|
||||
mScanWifiDppSuccessListener.onScanWifiDppSuccess((WifiQrCode)msg.obj);
|
||||
@@ -160,23 +156,43 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
|
||||
}
|
||||
|
||||
WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext());
|
||||
notifyUserForQrCodeRecognition();
|
||||
break;
|
||||
|
||||
case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS:
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
// We may get 2 WifiConfiguration if the QR code has no password in it,
|
||||
// one for open network and one for enhanced open network.
|
||||
final WifiManager wifiManager =
|
||||
getContext().getSystemService(WifiManager.class);
|
||||
final WifiNetworkConfig qrCodeWifiNetworkConfig =
|
||||
(WifiNetworkConfig)msg.obj;
|
||||
final List<WifiConfiguration> qrCodeWifiConfigurations =
|
||||
qrCodeWifiNetworkConfig.getWifiConfigurations();
|
||||
|
||||
// Adds all Wi-Fi networks in QR code to the set of configured networks and
|
||||
// connects to it if it's reachable.
|
||||
boolean hasReachableWifiNetwork = false;
|
||||
for (WifiConfiguration qrCodeWifiConfiguration : qrCodeWifiConfigurations) {
|
||||
final int id = wifiManager.addNetwork(qrCodeWifiConfiguration);
|
||||
if (id == -1) {
|
||||
continue;
|
||||
}
|
||||
wifiManager.enableNetwork(id, /* attemptConnect */ false);
|
||||
if (isReachableWifiNetwork(qrCodeWifiConfiguration)) {
|
||||
hasReachableWifiNetwork = true;
|
||||
mEnrolleeWifiConfiguration = qrCodeWifiConfiguration;
|
||||
wifiManager.connect(id,
|
||||
/* listener */ WifiDppQrCodeScannerFragment.this);
|
||||
}
|
||||
}
|
||||
|
||||
mDecorateView.setFocused(true);
|
||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||
if (hasReachableWifiNetwork == false) {
|
||||
showErrorMessageAndRestartCamera(
|
||||
R.string.wifi_dpp_check_connection_try_again);
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiNetworkConfig wifiNetworkConfig = (WifiNetworkConfig)msg.obj;
|
||||
mWifiConfiguration = wifiNetworkConfig.getWifiConfigurationOrNull();
|
||||
wifiNetworkConfig.connect(getContext(),
|
||||
/* listener */ WifiDppQrCodeScannerFragment.this);
|
||||
|
||||
WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext());
|
||||
notifyUserForQrCodeRecognition();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -185,6 +201,30 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
}
|
||||
};
|
||||
|
||||
@UiThread
|
||||
private void notifyUserForQrCodeRecognition() {
|
||||
if (mCamera != null) {
|
||||
mCamera.stop();
|
||||
}
|
||||
|
||||
mDecorateView.setFocused(true);
|
||||
mErrorMessage.setVisibility(View.INVISIBLE);
|
||||
|
||||
WifiDppUtils.triggerVibrationForQrCodeRecognition(getContext());
|
||||
}
|
||||
|
||||
private boolean isReachableWifiNetwork(WifiConfiguration wifiConfiguration) {
|
||||
final List<AccessPoint> scannedAccessPoints = mWifiTracker.getAccessPoints();
|
||||
|
||||
for (AccessPoint scannedAccessPoint : scannedAccessPoints) {
|
||||
if (scannedAccessPoint.matches(wifiConfiguration) &&
|
||||
scannedAccessPoint.isReachable()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -192,7 +232,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
if (savedInstanceState != null) {
|
||||
mIsConfiguratorMode = savedInstanceState.getBoolean(KEY_IS_CONFIGURATOR_MODE);
|
||||
mLatestStatusCode = savedInstanceState.getInt(KEY_LATEST_ERROR_CODE);
|
||||
mWifiConfiguration = savedInstanceState.getParcelable(KEY_WIFI_CONFIGURATION);
|
||||
mEnrolleeWifiConfiguration = savedInstanceState.getParcelable(KEY_WIFI_CONFIGURATION);
|
||||
}
|
||||
|
||||
final WifiDppInitiatorViewModel model =
|
||||
@@ -480,7 +520,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBoolean(KEY_IS_CONFIGURATOR_MODE, mIsConfiguratorMode);
|
||||
outState.putInt(KEY_LATEST_ERROR_CODE, mLatestStatusCode);
|
||||
outState.putParcelable(KEY_WIFI_CONFIGURATION, mWifiConfiguration);
|
||||
outState.putParcelable(KEY_WIFI_CONFIGURATION, mEnrolleeWifiConfiguration);
|
||||
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
@@ -496,7 +536,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
for (WifiConfiguration wifiConfig : wifiConfigs) {
|
||||
if (wifiConfig.networkId == newNetworkId) {
|
||||
mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_SUCCESS;
|
||||
mWifiConfiguration = wifiConfig;
|
||||
mEnrolleeWifiConfiguration = wifiConfig;
|
||||
wifiManager.connect(wifiConfig, WifiDppQrCodeScannerFragment.this);
|
||||
return;
|
||||
}
|
||||
@@ -588,17 +628,13 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (isEnrollingWifiNetworkReachable()) {
|
||||
final Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra(WifiDialogActivity.KEY_WIFI_CONFIGURATION, mWifiConfiguration);
|
||||
final Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra(WifiDialogActivity.KEY_WIFI_CONFIGURATION,
|
||||
mEnrolleeWifiConfiguration);
|
||||
|
||||
final Activity hostActivity = getActivity();
|
||||
hostActivity.setResult(Activity.RESULT_OK, resultIntent);
|
||||
hostActivity.finish();
|
||||
} else {
|
||||
Log.d(TAG, "Enroll Wi-Fi network succeeded but it's not reachable");
|
||||
showErrorMessageAndRestartCamera(R.string.wifi_dpp_check_connection_try_again);
|
||||
}
|
||||
final Activity hostActivity = getActivity();
|
||||
hostActivity.setResult(Activity.RESULT_OK, resultIntent);
|
||||
hostActivity.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -607,22 +643,6 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
||||
showErrorMessageAndRestartCamera(R.string.wifi_dpp_check_connection_try_again);
|
||||
}
|
||||
|
||||
private boolean isEnrollingWifiNetworkReachable() {
|
||||
if (mWifiConfiguration == null) {
|
||||
Log.e(TAG, "Connect succeeded but lost WifiConfiguration");
|
||||
return false;
|
||||
}
|
||||
|
||||
final List<AccessPoint> scannedAccessPoints = mWifiTracker.getAccessPoints();
|
||||
for (AccessPoint accessPoint : scannedAccessPoints) {
|
||||
if (accessPoint.matches(mWifiConfiguration) &&
|
||||
accessPoint.isReachable()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check is Easy Connect handshaking or not
|
||||
private boolean isGoingInitiator() {
|
||||
final WifiDppInitiatorViewModel model =
|
||||
|
Reference in New Issue
Block a user