Wi-Fi DPP code refine
1. call Activity#setResult only for RESULT_OK case 2. refine @VisibleForTesting usage remove redundant assignment otherwise = PRIVATE set all @VisibleForTesting annotated methods package scope 3. rename WifiQrCode#SECURITY_WPA to WifiQrCode#SECURITY_WPA_PSK Bug: 120645817 Test: atest WifiQrCodeTest atest WifiDppConfiguratorActivityTest atest WifiDppEnrolleeActivityTest atest WifiDppQrCodeGeneratorFragmentTest atest WifiDppQrCodeScannerFragmentTest atest WifiNetworkListFragmentTest atest WifiDppChooseSavedWifiNetworkFragmentTest Change-Id: Id5de7eadc73185716422fc0d197f82bdd025ce45
This commit is contained in:
@@ -63,7 +63,11 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
mButtonLeft.setText(R.string.wifi_dpp_add_another_device);
|
||||
mButtonLeft.setOnClickListener(v -> getFragmentManager().popBackStack());
|
||||
mButtonRight.setText(R.string.done);
|
||||
mButtonRight.setOnClickListener(v -> getActivity().finish());
|
||||
mButtonRight.setOnClickListener(v -> {
|
||||
final Activity activity = getActivity();
|
||||
activity.setResult(Activity.RESULT_OK);
|
||||
activity.finish();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,10 +142,7 @@ public class WifiDppAddDeviceFragment extends WifiDppQrCodeBaseFragment {
|
||||
|
||||
mButtonLeft = view.findViewById(R.id.button_left);
|
||||
mButtonLeft.setText(R.string.cancel);
|
||||
mButtonLeft.setOnClickListener(v -> {
|
||||
getActivity().setResult(Activity.RESULT_CANCELED);
|
||||
getActivity().finish();
|
||||
});
|
||||
mButtonLeft.setOnClickListener(v -> getActivity().finish());
|
||||
|
||||
mButtonRight = view.findViewById(R.id.button_right);
|
||||
mButtonRight.setText(R.string.wifi_dpp_share_wifi);
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -100,9 +99,7 @@ public class WifiDppChooseSavedWifiNetworkFragment extends WifiDppQrCodeBaseFrag
|
||||
.ACTION_CONFIGURATOR_QR_CODE_GENERATOR.equals(action)) {
|
||||
getFragmentManager().popBackStack();
|
||||
} else {
|
||||
final Activity activity = getActivity();
|
||||
activity.setResult(Activity.RESULT_CANCELED);
|
||||
activity.finish();
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -17,7 +17,6 @@
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -160,7 +159,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
|
||||
if (cancelActivity) {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -279,8 +277,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
return mWifiDppQrCode;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
protected boolean setWifiNetworkConfig(WifiNetworkConfig config) {
|
||||
@VisibleForTesting
|
||||
boolean setWifiNetworkConfig(WifiNetworkConfig config) {
|
||||
if(!WifiNetworkConfig.isValidConfig(config)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -289,8 +287,8 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
protected boolean setWifiDppQrCode(WifiQrCode wifiQrCode) {
|
||||
@VisibleForTesting
|
||||
boolean setWifiDppQrCode(WifiQrCode wifiQrCode) {
|
||||
if (wifiQrCode == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -307,7 +305,6 @@ public class WifiDppConfiguratorActivity extends InstrumentedActivity implements
|
||||
public boolean onNavigateUp() {
|
||||
Fragment fragment = mFragmentManager.findFragmentById(R.id.fragment_container);
|
||||
if (fragment instanceof WifiDppQrCodeGeneratorFragment) {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
return true;
|
||||
} else if (fragment instanceof WifiDppQrCodeScannerFragment) {
|
||||
|
@@ -117,7 +117,6 @@ public class WifiDppEnrolleeActivity extends InstrumentedActivity implements
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Launch with an invalid action");
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -141,7 +140,6 @@ public class WifiDppEnrolleeActivity extends InstrumentedActivity implements
|
||||
|
||||
@Override
|
||||
public boolean onNavigateUp(){
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ public class WifiDppUtils {
|
||||
case AccessPoint.SECURITY_WEP:
|
||||
return WifiQrCode.SECURITY_WEP;
|
||||
case AccessPoint.SECURITY_PSK:
|
||||
return WifiQrCode.SECURITY_WPA;
|
||||
return WifiQrCode.SECURITY_WPA_PSK;
|
||||
case AccessPoint.SECURITY_SAE:
|
||||
return WifiQrCode.SECURITY_SAE;
|
||||
default:
|
||||
|
@@ -19,7 +19,7 @@ package com.android.settings.wifi.dpp;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_NO_PASSWORD;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_SAE;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WEP;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WPA;
|
||||
import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WPA_PSK;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -53,8 +53,8 @@ public class WifiNetworkConfig {
|
||||
private boolean mHiddenSsid;
|
||||
private int mNetworkId;
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
protected WifiNetworkConfig(String security, String ssid, String preSharedKey,
|
||||
@VisibleForTesting
|
||||
WifiNetworkConfig(String security, String ssid, String preSharedKey,
|
||||
boolean hiddenSsid, int networkId) {
|
||||
mSecurity = security;
|
||||
mSsid = ssid;
|
||||
@@ -218,7 +218,7 @@ public class WifiNetworkConfig {
|
||||
}
|
||||
|
||||
// DPP 1.0 only supports SAE and PSK.
|
||||
if (SECURITY_SAE.equals(mSecurity) || SECURITY_WPA.equals(mSecurity)) {
|
||||
if (SECURITY_SAE.equals(mSecurity) || SECURITY_WPA_PSK.equals(mSecurity)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class WifiNetworkConfig {
|
||||
} else {
|
||||
wifiConfiguration.wepKeys[0] = addQuotationIfNeeded(mPreSharedKey);
|
||||
}
|
||||
} else if (mSecurity.startsWith(SECURITY_WPA)) {
|
||||
} else if (mSecurity.startsWith(SECURITY_WPA_PSK)) {
|
||||
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
|
||||
|
||||
if (mPreSharedKey.matches("[0-9A-Fa-f]{64}")) {
|
||||
|
@@ -235,7 +235,7 @@ public class WifiNetworkListFragment extends SettingsPreferenceFragment implemen
|
||||
if (mOnChooseNetworkListener != null) {
|
||||
mOnChooseNetworkListener.onChooseNetwork(
|
||||
new WifiNetworkConfig(
|
||||
WifiQrCode.SECURITY_WPA,
|
||||
WifiQrCode.SECURITY_WPA_PSK,
|
||||
/* ssid */ WifiNetworkConfig.FAKE_SSID,
|
||||
/* preSharedKey */ WifiNetworkConfig.FAKE_PASSWORD,
|
||||
/* hiddenSsid */ true,
|
||||
|
@@ -66,7 +66,7 @@ public class WifiQrCode {
|
||||
// Ignores password if security is SECURITY_NO_PASSWORD or absent
|
||||
public static final String SECURITY_NO_PASSWORD = "nopass";
|
||||
public static final String SECURITY_WEP = "WEP";
|
||||
public static final String SECURITY_WPA = "WPA";
|
||||
public static final String SECURITY_WPA_PSK = "WPA";
|
||||
public static final String SECURITY_SAE = "WPA3";
|
||||
|
||||
private String mQrCode;
|
||||
@@ -169,8 +169,8 @@ public class WifiQrCode {
|
||||
return null;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
protected String removeBackSlash(String input) {
|
||||
@VisibleForTesting
|
||||
String removeBackSlash(String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -210,8 +210,8 @@ public class WifiQrCode {
|
||||
}
|
||||
|
||||
/** Available when {@code getScheme()} returns SCHEME_DPP */
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
protected String getPublicKey() {
|
||||
@VisibleForTesting
|
||||
String getPublicKey() {
|
||||
return mPublicKey;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user