Update WriteWifiConfigToNfcDialog.
- Use the new WifiManager API to retrieve the WPS NFC token for the current network. - Add WifiManagerWrapper class to support testing because Robolectric does not yet support testing Android O. Bug: 35725168 Test: m RunSettingsRoboTests Change-Id: I7805bdcbe02dc262083bcd371d4ad88d256f8089
This commit is contained in:
@@ -56,7 +56,6 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
private static final String PASSWORD_FORMAT = "102700%s%s";
|
||||
private static final int HEX_RADIX = 16;
|
||||
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
private static final String NETWORK_ID = "network_id";
|
||||
private static final String SECURITY = "security";
|
||||
|
||||
private final PowerManager.WakeLock mWakeLock;
|
||||
@@ -69,33 +68,29 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
private TextView mLabelView;
|
||||
private CheckBox mPasswordCheckBox;
|
||||
private ProgressBar mProgressBar;
|
||||
private WifiManager mWifiManager;
|
||||
private WifiManagerWrapper mWifiManager;
|
||||
private String mWpsNfcConfigurationToken;
|
||||
private Context mContext;
|
||||
private int mNetworkId;
|
||||
private int mSecurity;
|
||||
|
||||
WriteWifiConfigToNfcDialog(Context context, int networkId, int security,
|
||||
WifiManager wifiManager) {
|
||||
WriteWifiConfigToNfcDialog(Context context, int security, WifiManagerWrapper wifiManager) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
|
||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
|
||||
mOnTextChangedHandler = new Handler();
|
||||
mNetworkId = networkId;
|
||||
mSecurity = security;
|
||||
mWifiManager = wifiManager;
|
||||
}
|
||||
|
||||
WriteWifiConfigToNfcDialog(Context context, Bundle savedState, WifiManager wifiManager) {
|
||||
WriteWifiConfigToNfcDialog(Context context, Bundle savedState, WifiManagerWrapper wifiManager) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
|
||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
|
||||
mOnTextChangedHandler = new Handler();
|
||||
mNetworkId = savedState.getInt(NETWORK_ID);
|
||||
mSecurity = savedState.getInt(SECURITY);
|
||||
mWifiManager = wifiManager;
|
||||
}
|
||||
@@ -114,12 +109,12 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
mContext.getResources().getString(com.android.internal.R.string.cancel),
|
||||
(OnClickListener) null);
|
||||
|
||||
mPasswordView = (TextView) mView.findViewById(R.id.password);
|
||||
mLabelView = (TextView) mView.findViewById(R.id.password_label);
|
||||
mPasswordView = mView.findViewById(R.id.password);
|
||||
mLabelView = mView.findViewById(R.id.password_label);
|
||||
mPasswordView.addTextChangedListener(this);
|
||||
mPasswordCheckBox = (CheckBox) mView.findViewById(R.id.show_password);
|
||||
mPasswordCheckBox = mView.findViewById(R.id.show_password);
|
||||
mPasswordCheckBox.setOnCheckedChangeListener(this);
|
||||
mProgressBar = (ProgressBar) mView.findViewById(R.id.progress_bar);
|
||||
mProgressBar = mView.findViewById(R.id.progress_bar);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@@ -135,8 +130,7 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
mWakeLock.acquire();
|
||||
|
||||
String password = mPasswordView.getText().toString();
|
||||
String wpsNfcConfigurationToken
|
||||
= mWifiManager.getWpsNfcConfigurationToken(mNetworkId);
|
||||
String wpsNfcConfigurationToken = mWifiManager.getCurrentNetworkWpsNfcConfigurationToken();
|
||||
String passwordHex = byteArrayToHexString(password.getBytes());
|
||||
|
||||
String passwordLength = password.length() >= HEX_RADIX
|
||||
@@ -180,7 +174,6 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
}
|
||||
|
||||
public void saveState(Bundle state) {
|
||||
state.putInt(NETWORK_ID, mNetworkId);
|
||||
state.putInt(SECURITY, mSecurity);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user