Implement Wi-Fi QR code scanner flow.
1. Implements WifiNetworkConfig Wi-Fi connection method 2. Shows error message when the QR code is not valid and hides it after 2s 3. In configurator mode, launchs AddDeviceFragment for a valid QR code 4. In enrollee mode, connects Wi-Fi for a valid QR code Bug: 118794978 Test: manual test atest WifiQrCodetest atest WifiDppConfiguratorActivityTest atest WifiDppEnrolleeActivityTest atest WifiDppQrCodeScannerFragmentTest Change-Id: Ie4731b22df295c60906156d33ea28dad9c084ce4
This commit is contained in:
@@ -49,7 +49,9 @@ import com.android.settings.R;
|
||||
*/
|
||||
public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
WifiNetworkConfig.Retriever,
|
||||
WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener {
|
||||
WifiDppQrCodeGeneratorFragment.OnQrCodeGeneratorFragmentAddButtonClickedListener,
|
||||
WifiDppQrCodeScannerFragment.OnScanWifiDppSuccessListener,
|
||||
WifiDppQrCodeScannerFragment.OnScanZxingWifiFormatSuccessListener {
|
||||
private static final String TAG = "WifiDppConfiguratorActivity";
|
||||
|
||||
public static final String ACTION_CONFIGURATOR_QR_CODE_SCANNER =
|
||||
@@ -64,6 +66,12 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
/** The Wi-Fi network which will be configured */
|
||||
private WifiNetworkConfig mWifiNetworkConfig;
|
||||
|
||||
/** The public key from Wi-Fi DPP QR code */
|
||||
private String mPublicKey;
|
||||
|
||||
/** The information from Wi-Fi DPP QR code */
|
||||
private String mInformation;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_WIFI_DPP_CONFIGURATOR;
|
||||
@@ -127,8 +135,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
|
||||
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
final WifiDppQrCodeScannerFragment fragment = new WifiDppQrCodeScannerFragment();
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_SCANNER);
|
||||
@@ -145,8 +153,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
|
||||
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
final WifiDppQrCodeGeneratorFragment fragment = new WifiDppQrCodeGeneratorFragment();
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
WifiDppUtils.TAG_FRAGMENT_QR_CODE_GENERATOR);
|
||||
@@ -160,9 +168,9 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
WifiDppChooseSavedWifiNetworkFragment fragment =
|
||||
final WifiDppChooseSavedWifiNetworkFragment fragment =
|
||||
new WifiDppChooseSavedWifiNetworkFragment();
|
||||
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
WifiDppUtils.TAG_FRAGMENT_CHOOSE_SAVED_WIFI_NETWORK);
|
||||
@@ -172,11 +180,38 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void showAddDeviceFragment(boolean addToBackStack) {
|
||||
// Avoid to replace the same fragment during configuration change
|
||||
if (mFragmentManager.findFragmentByTag(
|
||||
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final WifiDppAddDeviceFragment fragment =
|
||||
new WifiDppAddDeviceFragment();
|
||||
final FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
|
||||
fragmentTransaction.replace(R.id.fragment_container, fragment,
|
||||
WifiDppUtils.TAG_FRAGMENT_ADD_DEVICE);
|
||||
if (addToBackStack) {
|
||||
fragmentTransaction.addToBackStack(/* name */ null);
|
||||
}
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WifiNetworkConfig getWifiNetworkConfig() {
|
||||
return mWifiNetworkConfig;
|
||||
}
|
||||
|
||||
public String getPublicKey() {
|
||||
return mPublicKey;
|
||||
}
|
||||
|
||||
public String getInformation() {
|
||||
return mInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setWifiNetworkConfig(WifiNetworkConfig config) {
|
||||
if(!WifiNetworkConfig.isValidConfig(config)) {
|
||||
@@ -201,7 +236,26 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void onQrCodeGeneratorFragmentAddButtonClicked() {
|
||||
@Override
|
||||
public void onQrCodeGeneratorFragmentAddButtonClicked() {
|
||||
showQrCodeScannerFragment(/* addToBackStack */ true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanWifiDppSuccess(String publicKey, String information) {
|
||||
mPublicKey = publicKey;
|
||||
mInformation = information;
|
||||
mWifiNetworkConfig = null;
|
||||
|
||||
showAddDeviceFragment(/* addToBackStack */ true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanZxingWifiFormatSuccess(WifiNetworkConfig wifiNetworkConfig) {
|
||||
mPublicKey = null;
|
||||
mInformation = null;
|
||||
mWifiNetworkConfig = new WifiNetworkConfig(wifiNetworkConfig);
|
||||
|
||||
showAddDeviceFragment(/* addToBackStack */ true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user