Merge changes I6abbfc5d,I1ce1b014
* changes: Fix Wi-Fi DPP activity crash after configuration change. Implement Wi-Fi DPP flow
This commit is contained in:
@@ -2104,6 +2104,12 @@
|
|||||||
<string name="wifi_dpp_add_another_device">Add another device</string>
|
<string name="wifi_dpp_add_another_device">Add another device</string>
|
||||||
<!-- Button label to choose different Wi-Fi network [CHAR LIMIT=80] -->
|
<!-- Button label to choose different Wi-Fi network [CHAR LIMIT=80] -->
|
||||||
<string name="wifi_dpp_choose_different_network">Choose different network</string>
|
<string name="wifi_dpp_choose_different_network">Choose different network</string>
|
||||||
|
<!-- Hint for QR code detection [CHAR LIMIT=50] -->
|
||||||
|
<string name="wifi_dpp_could_not_add_device">Couldn\u2019t add device</string>
|
||||||
|
<!-- Title for the fragment to show that device found but naming known [CHAR LIMIT=50] -->
|
||||||
|
<string name="wifi_dpp_device_found">Device found</string>
|
||||||
|
<!-- Label for the try again button [CHAR LIMIT=20]-->
|
||||||
|
<string name="retry">Retry</string>
|
||||||
<!-- Label for the check box to share a network with other users on the same device -->
|
<!-- Label for the check box to share a network with other users on the same device -->
|
||||||
<string name="wifi_shared">Share with other device users</string>
|
<string name="wifi_shared">Share with other device users</string>
|
||||||
<!-- Hint for unchanged fields -->
|
<!-- Hint for unchanged fields -->
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -55,6 +56,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
// Update success UI.
|
// Update success UI.
|
||||||
mTitle.setText(R.string.wifi_dpp_wifi_shared_with_device);
|
mTitle.setText(R.string.wifi_dpp_wifi_shared_with_device);
|
||||||
mSummary.setVisibility(View.INVISIBLE);
|
mSummary.setVisibility(View.INVISIBLE);
|
||||||
|
mChooseDifferentNetwork.setVisibility(View.INVISIBLE);
|
||||||
mButtonLeft.setText(R.string.wifi_dpp_add_another_device);
|
mButtonLeft.setText(R.string.wifi_dpp_add_another_device);
|
||||||
mButtonLeft.setOnClickListener(v -> getFragmentManager().popBackStack());
|
mButtonLeft.setOnClickListener(v -> getFragmentManager().popBackStack());
|
||||||
mButtonRight.setText(R.string.done);
|
mButtonRight.setText(R.string.done);
|
||||||
@@ -63,8 +65,13 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(int code) {
|
public void onFailure(int code) {
|
||||||
//TODO(b/122429170): Show DPP configuration error state UI
|
|
||||||
Log.d(TAG, "DppStatusCallback.onFailure " + code);
|
Log.d(TAG, "DppStatusCallback.onFailure " + code);
|
||||||
|
|
||||||
|
// Update fail UI.
|
||||||
|
mTitle.setText(R.string.wifi_dpp_could_not_add_device);
|
||||||
|
mSummary.setVisibility(View.INVISIBLE);
|
||||||
|
mChooseDifferentNetwork.setVisibility(View.INVISIBLE);
|
||||||
|
mButtonRight.setText(R.string.retry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,6 +106,15 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
final WifiQrCode wifiQrCode = ((WifiDppConfiguratorActivity) getActivity())
|
||||||
|
.getWifiDppQrCode();
|
||||||
|
final String information = wifiQrCode.getInformation();
|
||||||
|
if (TextUtils.isEmpty(information)) {
|
||||||
|
mTitle.setText(R.string.wifi_dpp_device_found);
|
||||||
|
} else {
|
||||||
|
mTitle.setText(information);
|
||||||
|
}
|
||||||
|
|
||||||
final WifiNetworkConfig wifiNetworkConfig = ((WifiDppConfiguratorActivity) getActivity())
|
final WifiNetworkConfig wifiNetworkConfig = ((WifiDppConfiguratorActivity) getActivity())
|
||||||
.getWifiNetworkConfig();
|
.getWifiNetworkConfig();
|
||||||
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
if (!WifiNetworkConfig.isValidConfig(wifiNetworkConfig)) {
|
||||||
@@ -110,7 +126,8 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
mWifiApPictureView = view.findViewById(R.id.wifi_ap_picture_view);
|
mWifiApPictureView = view.findViewById(R.id.wifi_ap_picture_view);
|
||||||
|
|
||||||
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
|
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
|
||||||
mChooseDifferentNetwork.setOnClickListener(v -> getFragmentManager().popBackStack());
|
mChooseDifferentNetwork.setOnClickListener(v ->
|
||||||
|
mClickChooseDifferentNetworkListener.onClickChooseDifferentNetwork());
|
||||||
|
|
||||||
mButtonLeft = view.findViewById(R.id.button_left);
|
mButtonLeft = view.findViewById(R.id.button_left);
|
||||||
mButtonLeft.setText(R.string.cancel);
|
mButtonLeft.setText(R.string.cancel);
|
||||||
@@ -125,11 +142,34 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startWifiDppInitiator() {
|
private void startWifiDppInitiator() {
|
||||||
final String enrolleeUri = ((WifiDppConfiguratorActivity) getActivity()).getDppUri();
|
final WifiQrCode wifiQrCode = ((WifiDppConfiguratorActivity) getActivity())
|
||||||
|
.getWifiDppQrCode();
|
||||||
|
final String qrCode = wifiQrCode.getQrCode();
|
||||||
final int networkId =
|
final int networkId =
|
||||||
((WifiDppConfiguratorActivity) getActivity()).getWifiNetworkConfig().getNetworkId();
|
((WifiDppConfiguratorActivity) getActivity()).getWifiNetworkConfig().getNetworkId();
|
||||||
final WifiManager wifiManager = getContext().getSystemService(WifiManager.class);
|
final WifiManager wifiManager = getContext().getSystemService(WifiManager.class);
|
||||||
wifiManager.startDppAsConfiguratorInitiator(enrolleeUri, networkId,
|
|
||||||
|
wifiManager.startDppAsConfiguratorInitiator(qrCode, networkId,
|
||||||
WifiManager.DPP_NETWORK_ROLE_STA, /* handler */ null, new DppStatusCallback());
|
WifiManager.DPP_NETWORK_ROLE_STA, /* handler */ null, new DppStatusCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container Activity must implement this interface
|
||||||
|
public interface OnClickChooseDifferentNetworkListener {
|
||||||
|
public void onClickChooseDifferentNetwork();
|
||||||
|
}
|
||||||
|
OnClickChooseDifferentNetworkListener mClickChooseDifferentNetworkListener;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
|
||||||
|
mClickChooseDifferentNetworkListener = (OnClickChooseDifferentNetworkListener) context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
mClickChooseDifferentNetworkListener = null;
|
||||||
|
|
||||||
|
super.onDetach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
@@ -51,7 +52,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
WifiNetworkConfig.Retriever,
|
WifiNetworkConfig.Retriever,
|
||||||
WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener,
|
WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener,
|
||||||
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener,
|
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener,
|
||||||
WifiDppQrCodeScannerFragment.OnScanZxingWifiFormatSuccessListener {
|
WifiDppQrCodeScannerFragment.OnScanZxingWifiFormatSuccessListener,
|
||||||
|
WifiDppAddDeviceFragment.OnClickChooseDifferentNetworkListener {
|
||||||
private static final String TAG = "WifiDppConfiguratorActivity";
|
private static final String TAG = "WifiDppConfiguratorActivity";
|
||||||
|
|
||||||
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
||||||
@@ -61,14 +63,19 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
public static final String ACTION_PROCESS_WIFI_DPP_QR_CODE =
|
public static final String ACTION_PROCESS_WIFI_DPP_QR_CODE =
|
||||||
"android.settings.PROCESS_WIFI_DPP_QR_CODE";
|
"android.settings.PROCESS_WIFI_DPP_QR_CODE";
|
||||||
|
|
||||||
|
// Key for Bundle usage
|
||||||
|
private static final String KEY_QR_CODE = "key_qr_code";
|
||||||
|
private static final String KEY_WIFI_SECURITY = "key_wifi_security";
|
||||||
|
private static final String KEY_WIFI_SSID = "key_wifi_ssid";
|
||||||
|
private static final String KEY_WIFI_PRESHARED_KEY = "key_wifi_preshared_key";
|
||||||
|
private static final String KEY_WIFI_HIDDEN_SSID = "key_wifi_hidden_ssid";
|
||||||
|
private static final String KEY_WIFI_NETWORK_ID = "key_wifi_network_id";
|
||||||
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
|
|
||||||
/** The Wi-Fi network which will be configured */
|
/** The Wi-Fi network which will be configured */
|
||||||
private WifiNetworkConfig mWifiNetworkConfig;
|
private WifiNetworkConfig mWifiNetworkConfig;
|
||||||
|
|
||||||
/** The uri from Wi-Fi DPP QR code */
|
|
||||||
private String mDppUri;
|
|
||||||
|
|
||||||
/** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_DPP_QR_CODE */
|
/** The Wi-Fi DPP QR code from intent ACTION_PROCESS_WIFI_DPP_QR_CODE */
|
||||||
private WifiQrCode mWifiDppQrCode;
|
private WifiQrCode mWifiDppQrCode;
|
||||||
|
|
||||||
@@ -81,6 +88,21 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
String qrCode = savedInstanceState.getString(KEY_QR_CODE);
|
||||||
|
|
||||||
|
mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode);
|
||||||
|
|
||||||
|
String security = savedInstanceState.getString(KEY_WIFI_SECURITY);
|
||||||
|
String ssid = savedInstanceState.getString(KEY_WIFI_SSID);
|
||||||
|
String preSharedKey = savedInstanceState.getString(KEY_WIFI_PRESHARED_KEY);
|
||||||
|
boolean hiddenSsid = savedInstanceState.getBoolean(KEY_WIFI_HIDDEN_SSID);
|
||||||
|
int networkId = savedInstanceState.getInt(KEY_WIFI_NETWORK_ID);
|
||||||
|
|
||||||
|
mWifiNetworkConfig = WifiNetworkConfig.getValidConfigOrNull(security, ssid,
|
||||||
|
preSharedKey, hiddenSsid, networkId);
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(R.layout.wifi_dpp_activity);
|
setContentView(R.layout.wifi_dpp_activity);
|
||||||
mFragmentManager = getSupportFragmentManager();
|
mFragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
@@ -117,7 +139,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
break;
|
break;
|
||||||
case ACTION_PROCESS_WIFI_DPP_QR_CODE:
|
case ACTION_PROCESS_WIFI_DPP_QR_CODE:
|
||||||
String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE);
|
String qrCode = intent.getStringExtra(WifiDppUtils.EXTRA_QR_CODE);
|
||||||
mWifiDppQrCode = getValidWiFiDppQrCodeOrNull(qrCode);
|
mWifiDppQrCode = getValidWifiDppQrCodeOrNull(qrCode);
|
||||||
if (mWifiDppQrCode == null) {
|
if (mWifiDppQrCode == null) {
|
||||||
cancelActivity = true;
|
cancelActivity = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -205,7 +227,7 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private WifiQrCode getValidWiFiDppQrCodeOrNull(String qrCode) {
|
private WifiQrCode getValidWifiDppQrCodeOrNull(String qrCode) {
|
||||||
WifiQrCode wifiQrCode;
|
WifiQrCode wifiQrCode;
|
||||||
try {
|
try {
|
||||||
wifiQrCode = new WifiQrCode(qrCode);
|
wifiQrCode = new WifiQrCode(qrCode);
|
||||||
@@ -225,16 +247,12 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
return mWifiNetworkConfig;
|
return mWifiNetworkConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDppUri() {
|
|
||||||
return mDppUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WifiQrCode getWifiDppQrCode() {
|
public WifiQrCode getWifiDppQrCode() {
|
||||||
return mWifiDppQrCode;
|
return mWifiDppQrCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
public boolean setWifiNetworkConfig(WifiNetworkConfig config) {
|
protected boolean setWifiNetworkConfig(WifiNetworkConfig config) {
|
||||||
if(!WifiNetworkConfig.isValidConfig(config)) {
|
if(!WifiNetworkConfig.isValidConfig(config)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -243,6 +261,20 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
|
protected boolean setWifiDppQrCode(WifiQrCode wifiQrCode) {
|
||||||
|
if (wifiQrCode == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!WifiQrCode.SCHEME_DPP.equals(wifiQrCode.getScheme())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mWifiDppQrCode = new WifiQrCode(wifiQrCode.getQrCode());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigateUp() {
|
public boolean onNavigateUp() {
|
||||||
Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
|
Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
|
||||||
@@ -263,17 +295,38 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScanWifiDppSuccess(String uri) {
|
public void onScanWifiDppSuccess(WifiQrCode wifiQrCode) {
|
||||||
mDppUri = uri;
|
mWifiDppQrCode = wifiQrCode;
|
||||||
|
|
||||||
showAddDeviceFragment(/* addToBackStack */ true);
|
showAddDeviceFragment(/* addToBackStack */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScanZxingWifiFormatSuccess(WifiNetworkConfig wifiNetworkConfig) {
|
public void onScanZxingWifiFormatSuccess(WifiNetworkConfig wifiNetworkConfig) {
|
||||||
mDppUri = null;
|
// Do nothing, it's impossible to be a configurator without a Wi-Fi DPP QR code
|
||||||
mWifiNetworkConfig = new WifiNetworkConfig(wifiNetworkConfig);
|
}
|
||||||
|
|
||||||
showAddDeviceFragment(/* addToBackStack */ true);
|
@Override
|
||||||
|
public void onClickChooseDifferentNetwork() {
|
||||||
|
mWifiNetworkConfig = null;
|
||||||
|
|
||||||
|
showChooseSavedWifiNetworkFragment(/* addToBackStack */ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
if (mWifiDppQrCode != null) {
|
||||||
|
outState.putString(KEY_QR_CODE, mWifiDppQrCode.getQrCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mWifiNetworkConfig != null) {
|
||||||
|
outState.putString(KEY_WIFI_SECURITY, mWifiNetworkConfig.getSecurity());
|
||||||
|
outState.putString(KEY_WIFI_SSID, mWifiNetworkConfig.getSsid());
|
||||||
|
outState.putString(KEY_WIFI_PRESHARED_KEY, mWifiNetworkConfig.getPreSharedKey());
|
||||||
|
outState.putBoolean(KEY_WIFI_HIDDEN_SSID, mWifiNetworkConfig.getHiddenSsid());
|
||||||
|
outState.putInt(KEY_WIFI_NETWORK_ID, mWifiNetworkConfig.getNetworkId());
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,9 +145,10 @@ public class WifiDppEnrolleeActivity extends InstrumentedActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScanWifiDppSuccess(String uri) {
|
public void onScanWifiDppSuccess(WifiQrCode wifiQrCode) {
|
||||||
final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||||
wifiManager.startDppAsEnrolleeInitiator(uri, /* handler */ null, new DppStatusCallback());
|
wifiManager.startDppAsEnrolleeInitiator(wifiQrCode.getQrCode(), /* handler */ null,
|
||||||
|
new DppStatusCallback());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
|
|
||||||
// Container Activity must implement this interface
|
// Container Activity must implement this interface
|
||||||
public interface OnScanWifiDppSuccessListener {
|
public interface OnScanWifiDppSuccessListener {
|
||||||
public void onScanWifiDppSuccess(String uri);
|
public void onScanWifiDppSuccess(WifiQrCode wifiQrCode);
|
||||||
}
|
}
|
||||||
OnScanWifiDppSuccessListener mScanWifiDppSuccessListener;
|
OnScanWifiDppSuccessListener mScanWifiDppSuccessListener;
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
public interface OnScanZxingWifiFormatSuccessListener {
|
public interface OnScanZxingWifiFormatSuccessListener {
|
||||||
public void onScanZxingWifiFormatSuccess(WifiNetworkConfig wifiNetworkConfig);
|
public void onScanZxingWifiFormatSuccess(WifiNetworkConfig wifiNetworkConfig);
|
||||||
}
|
}
|
||||||
OnScanZxingWifiFormatSuccessListener mScanScanZxingWifiFormatSuccessListener;
|
OnScanZxingWifiFormatSuccessListener mScanZxingWifiFormatSuccessListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configurator container activity of the fragment should create instance with this constructor.
|
* Configurator container activity of the fragment should create instance with this constructor.
|
||||||
@@ -146,13 +146,13 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
mScanWifiDppSuccessListener = (OnScanWifiDppSuccessListener) context;
|
mScanWifiDppSuccessListener = (OnScanWifiDppSuccessListener) context;
|
||||||
mScanScanZxingWifiFormatSuccessListener = (OnScanZxingWifiFormatSuccessListener) context;
|
mScanZxingWifiFormatSuccessListener = (OnScanZxingWifiFormatSuccessListener) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
mScanWifiDppSuccessListener = null;
|
mScanWifiDppSuccessListener = null;
|
||||||
mScanScanZxingWifiFormatSuccessListener = null;
|
mScanZxingWifiFormatSuccessListener = null;
|
||||||
|
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
@@ -272,17 +272,17 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is only called when QrCamera.ScannerCallback.isValid returns true;
|
* This method is only called when QrCamera.ScannerCallback.isValid returns true;
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handleSuccessfulResult(String qrCode) {
|
public void handleSuccessfulResult(String qrCode) {
|
||||||
switch (mWifiQrCode.getScheme()) {
|
switch (mWifiQrCode.getScheme()) {
|
||||||
case WifiQrCode.SCHEME_DPP:
|
case WifiQrCode.SCHEME_DPP:
|
||||||
handleWifiDpp(qrCode);
|
handleWifiDpp();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG:
|
case WifiQrCode.SCHEME_ZXING_WIFI_NETWORK_CONFIG:
|
||||||
handleZxingWifiFormat(mWifiQrCode.getWifiNetworkConfig());
|
handleZxingWifiFormat();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -290,25 +290,22 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleWifiDpp(String uri) {
|
private void handleWifiDpp() {
|
||||||
destroyCamera();
|
destroyCamera();
|
||||||
mDecorateView.setFocused(true);
|
mDecorateView.setFocused(true);
|
||||||
|
|
||||||
final Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(KEY_PUBLIC_URI, uri);
|
|
||||||
|
|
||||||
Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS);
|
Message message = mHandler.obtainMessage(MESSAGE_SCAN_WIFI_DPP_SUCCESS);
|
||||||
message.setData(bundle);
|
message.obj = new WifiQrCode(mWifiQrCode.getQrCode());
|
||||||
|
|
||||||
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleZxingWifiFormat(WifiNetworkConfig wifiNetworkConfig) {
|
private void handleZxingWifiFormat() {
|
||||||
destroyCamera();
|
destroyCamera();
|
||||||
mDecorateView.setFocused(true);
|
mDecorateView.setFocused(true);
|
||||||
|
|
||||||
Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
|
Message message = mHandler.obtainMessage(MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS);
|
||||||
message.obj = wifiNetworkConfig;
|
message.obj = new WifiQrCode(mWifiQrCode.getQrCode()).getWifiNetworkConfig();
|
||||||
|
|
||||||
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
mHandler.sendMessageDelayed(message, SHOW_SUCCESS_SQUARE_INTERVAL);
|
||||||
}
|
}
|
||||||
@@ -359,17 +356,14 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
if (mScanWifiDppSuccessListener == null) {
|
if (mScanWifiDppSuccessListener == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Bundle bundle = msg.getData();
|
mScanWifiDppSuccessListener.onScanWifiDppSuccess((WifiQrCode)msg.obj);
|
||||||
final String uri = bundle.getString(KEY_PUBLIC_URI);
|
|
||||||
|
|
||||||
mScanWifiDppSuccessListener.onScanWifiDppSuccess(uri);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS:
|
case MESSAGE_SCAN_ZXING_WIFI_FORMAT_SUCCESS:
|
||||||
if (mScanScanZxingWifiFormatSuccessListener == null) {
|
if (mScanZxingWifiFormatSuccessListener == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mScanScanZxingWifiFormatSuccessListener.onScanZxingWifiFormatSuccess(
|
mScanZxingWifiFormatSuccessListener.onScanZxingWifiFormatSuccess(
|
||||||
(WifiNetworkConfig)msg.obj);
|
(WifiNetworkConfig)msg.obj);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -381,8 +375,8 @@ public class WifiDppQrCodeScannerFragment extends WifiDppQrCodeBaseFragment impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
outState.putBoolean(KEY_IS_CONFIGURATOR_MODE, mIsConfiguratorMode);
|
outState.putBoolean(KEY_IS_CONFIGURATOR_MODE, mIsConfiguratorMode);
|
||||||
|
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
import androidx.annotation.Keep;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the parameters of ZXing reader library's Wi-Fi Network config format.
|
* Wraps the parameters of ZXing reader library's Wi-Fi Network config format.
|
||||||
@@ -48,8 +49,9 @@ public class WifiNetworkConfig {
|
|||||||
private boolean mHiddenSsid;
|
private boolean mHiddenSsid;
|
||||||
private int mNetworkId;
|
private int mNetworkId;
|
||||||
|
|
||||||
private WifiNetworkConfig(String security, String ssid, String preSharedKey, boolean hiddenSsid,
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
int networkId) {
|
protected WifiNetworkConfig(String security, String ssid, String preSharedKey,
|
||||||
|
boolean hiddenSsid, int networkId) {
|
||||||
mSecurity = security;
|
mSecurity = security;
|
||||||
mSsid = ssid;
|
mSsid = ssid;
|
||||||
mPreSharedKey = preSharedKey;
|
mPreSharedKey = preSharedKey;
|
||||||
@@ -71,7 +73,6 @@ public class WifiNetworkConfig {
|
|||||||
*/
|
*/
|
||||||
public interface Retriever {
|
public interface Retriever {
|
||||||
public WifiNetworkConfig getWifiNetworkConfig();
|
public WifiNetworkConfig getWifiNetworkConfig();
|
||||||
public boolean setWifiNetworkConfig(WifiNetworkConfig config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.content.Intent;
|
|||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -49,7 +48,6 @@ import java.util.regex.Pattern;
|
|||||||
* H true Optional. True if the network SSID is hidden.
|
* H true Optional. True if the network SSID is hidden.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Keep
|
|
||||||
public class WifiQrCode {
|
public class WifiQrCode {
|
||||||
public static final String SCHEME_DPP = "DPP";
|
public static final String SCHEME_DPP = "DPP";
|
||||||
public static final String SCHEME_ZXING_WIFI_NETWORK_CONFIG = "WIFI";
|
public static final String SCHEME_ZXING_WIFI_NETWORK_CONFIG = "WIFI";
|
||||||
@@ -86,7 +84,6 @@ public class WifiQrCode {
|
|||||||
// Data from parsed ZXing reader library's Wi-Fi Network config format
|
// Data from parsed ZXing reader library's Wi-Fi Network config format
|
||||||
private WifiNetworkConfig mWifiNetworkConfig;
|
private WifiNetworkConfig mWifiNetworkConfig;
|
||||||
|
|
||||||
@Keep
|
|
||||||
public WifiQrCode(String qrCode) throws IllegalArgumentException {
|
public WifiQrCode(String qrCode) throws IllegalArgumentException {
|
||||||
if (TextUtils.isEmpty(qrCode)) {
|
if (TextUtils.isEmpty(qrCode)) {
|
||||||
throw new IllegalArgumentException("Empty QR code");
|
throw new IllegalArgumentException("Empty QR code");
|
||||||
@@ -172,7 +169,6 @@ public class WifiQrCode {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
protected String removeBackSlash(String input) {
|
protected String removeBackSlash(String input) {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
@@ -199,7 +195,6 @@ public class WifiQrCode {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
|
||||||
public String getQrCode() {
|
public String getQrCode() {
|
||||||
return mQrCode;
|
return mQrCode;
|
||||||
}
|
}
|
||||||
@@ -210,25 +205,22 @@ 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
|
||||||
*/
|
*/
|
||||||
@Keep
|
|
||||||
public String getScheme() {
|
public String getScheme() {
|
||||||
return mScheme;
|
return mScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Available when {@code getScheme()} returns SCHEME_DPP */
|
/** Available when {@code getScheme()} returns SCHEME_DPP */
|
||||||
@Keep
|
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||||
public String getPublicKey() {
|
protected String getPublicKey() {
|
||||||
return mPublicKey;
|
return mPublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** May be available when {@code getScheme()} returns SCHEME_DPP */
|
/** May be available when {@code getScheme()} returns SCHEME_DPP */
|
||||||
@Keep
|
|
||||||
public String getInformation() {
|
public String getInformation() {
|
||||||
return mInformation;
|
return mInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Available when {@code getScheme()} returns SCHEME_ZXING_WIFI_NETWORK_CONFIG */
|
/** Available when {@code getScheme()} returns SCHEME_ZXING_WIFI_NETWORK_CONFIG */
|
||||||
@Keep
|
|
||||||
public WifiNetworkConfig getWifiNetworkConfig() {
|
public WifiNetworkConfig getWifiNetworkConfig() {
|
||||||
if (mWifiNetworkConfig == null) {
|
if (mWifiNetworkConfig == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.settings.wifi.dpp;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
|
||||||
import androidx.test.rule.ActivityTestRule;
|
import androidx.test.rule.ActivityTestRule;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
@@ -29,6 +30,10 @@ import org.junit.runner.RunWith;
|
|||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class WifiDppConfiguratorActivityTest {
|
public class WifiDppConfiguratorActivityTest {
|
||||||
|
// Valid Wi-Fi DPP QR code & it's parameters
|
||||||
|
private static final String VALID_WIFI_DPP_QR_CODE = "DPP:I:SN=4774LH2b4044;M:010203040506;K:"
|
||||||
|
+ "MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
public final ActivityTestRule<WifiDppConfiguratorActivity> mActivityRule =
|
||||||
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
|
new ActivityTestRule<>(WifiDppConfiguratorActivity.class);
|
||||||
@@ -62,9 +67,7 @@ public class WifiDppConfiguratorActivityTest {
|
|||||||
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
|
public void launchActivity_chooseSavedWifiNetwork_shouldNotAutoFinish() {
|
||||||
Intent intent = new Intent(
|
Intent intent = new Intent(
|
||||||
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||||
String qrCode = "DPP:I:SN=4774LH2b4044;M:010203040506;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD"
|
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||||
+ "IgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";
|
|
||||||
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, qrCode);
|
|
||||||
|
|
||||||
mActivityRule.launchActivity(intent);
|
mActivityRule.launchActivity(intent);
|
||||||
|
|
||||||
@@ -101,4 +104,59 @@ public class WifiDppConfiguratorActivityTest {
|
|||||||
assertThat(activity instanceof WifiDppQrCodeScannerFragment
|
assertThat(activity instanceof WifiDppQrCodeScannerFragment
|
||||||
.OnScanZxingWifiFormatSuccessListener).isEqualTo(true);
|
.OnScanZxingWifiFormatSuccessListener).isEqualTo(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testActivity_shouldImplementsOnClickChooseDifferentNetworkCallback() {
|
||||||
|
WifiDppConfiguratorActivity activity = mActivityRule.getActivity();
|
||||||
|
|
||||||
|
assertThat(activity instanceof WifiDppAddDeviceFragment
|
||||||
|
.OnClickChooseDifferentNetworkListener).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rotateScreen_shouldGetCorrectWifiDppQrCode() {
|
||||||
|
WifiQrCode wifiQrCode = new WifiQrCode(VALID_WIFI_DPP_QR_CODE);
|
||||||
|
Intent intent = new Intent(WifiDppConfiguratorActivity.ACTION_CONFIGURATOR_QR_CODE_SCANNER);
|
||||||
|
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SECURITY, "WEP");
|
||||||
|
intent.putExtra(WifiDppUtils.EXTRA_WIFI_SSID, "GoogleGuest");
|
||||||
|
intent.putExtra(WifiDppUtils.EXTRA_WIFI_PRE_SHARED_KEY, "password");
|
||||||
|
|
||||||
|
// setWifiDppQrCode and check if getWifiDppQrCode correctly after rotation
|
||||||
|
mActivityRule.launchActivity(intent);
|
||||||
|
mActivityRule.getActivity().setWifiDppQrCode(wifiQrCode);
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
WifiQrCode restoredWifiDppQrCode = mActivityRule.getActivity().getWifiDppQrCode();
|
||||||
|
|
||||||
|
assertThat(restoredWifiDppQrCode).isNotNull();
|
||||||
|
assertThat(restoredWifiDppQrCode.getQrCode()).isEqualTo(VALID_WIFI_DPP_QR_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rotateScreen_shouldGetCorrectWifiNetworkConfig() {
|
||||||
|
WifiNetworkConfig wifiNetworkConfig = new WifiNetworkConfig("WPA", "WifiSsid", "password",
|
||||||
|
/* hiddenSsid */ false, /* networkId */ 0);
|
||||||
|
Intent intent = new Intent(
|
||||||
|
WifiDppConfiguratorActivity.ACTION_PROCESS_WIFI_DPP_QR_CODE);
|
||||||
|
intent.putExtra(WifiDppUtils.EXTRA_QR_CODE, VALID_WIFI_DPP_QR_CODE);
|
||||||
|
|
||||||
|
// setWifiNetworkConfig and check if getWifiNetworkConfig correctly after rotation
|
||||||
|
mActivityRule.launchActivity(intent);
|
||||||
|
mActivityRule.getActivity().setWifiNetworkConfig(wifiNetworkConfig);
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
mActivityRule.getActivity().setRequestedOrientation(
|
||||||
|
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
WifiNetworkConfig restoredWifiNetworkConfig =
|
||||||
|
mActivityRule.getActivity().getWifiNetworkConfig();
|
||||||
|
|
||||||
|
assertThat(restoredWifiNetworkConfig).isNotNull();
|
||||||
|
assertThat(restoredWifiNetworkConfig.getSecurity()).isEqualTo("WPA");
|
||||||
|
assertThat(restoredWifiNetworkConfig.getSsid()).isEqualTo("WifiSsid");
|
||||||
|
assertThat(restoredWifiNetworkConfig.getPreSharedKey()).isEqualTo("password");
|
||||||
|
assertThat(restoredWifiNetworkConfig.getHiddenSsid()).isFalse();
|
||||||
|
assertThat(restoredWifiNetworkConfig.getNetworkId()).isEqualTo(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user