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