Merge "Fix crash when rotating NFC dialog"
This commit is contained in:
committed by
Android (Google) Code Review
commit
93564706e1
@@ -111,6 +111,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
// Instance state keys
|
||||
private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
|
||||
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
|
||||
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
||||
|
||||
private static boolean savedNetworksExist;
|
||||
|
||||
@@ -142,6 +143,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
private boolean mDlgEdit;
|
||||
private AccessPoint mDlgAccessPoint;
|
||||
private Bundle mAccessPointSavedState;
|
||||
private Bundle mWifiNfcDialogSavedState;
|
||||
|
||||
private WifiTracker mWifiTracker;
|
||||
|
||||
@@ -209,6 +211,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
mAccessPointSavedState =
|
||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||
}
|
||||
|
||||
if (savedInstanceState.containsKey(SAVED_WIFI_NFC_DIALOG_STATE)) {
|
||||
mWifiNfcDialogSavedState =
|
||||
savedInstanceState.getBundle(SAVED_WIFI_NFC_DIALOG_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
// if we're supposed to enable/disable the Next button based on our current connection
|
||||
@@ -350,6 +357,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
outState.putBundle(SAVE_DIALOG_ACCESS_POINT_STATE, mAccessPointSavedState);
|
||||
}
|
||||
}
|
||||
|
||||
if (mWifiToNfcDialog != null && mWifiToNfcDialog.isShowing()) {
|
||||
Bundle savedState = new Bundle();
|
||||
mWifiToNfcDialog.saveState(savedState);
|
||||
outState.putBundle(SAVED_WIFI_NFC_DIALOG_STATE, savedState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -576,10 +589,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
case WRITE_NFC_DIALOG_ID:
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
||||
getActivity(), mSelectedAccessPoint, mWifiManager);
|
||||
return mWifiToNfcDialog;
|
||||
getActivity(), mSelectedAccessPoint.getConfig().networkId,
|
||||
mSelectedAccessPoint.getSecurity(),
|
||||
mWifiManager);
|
||||
} else if (mWifiNfcDialogSavedState != null) {
|
||||
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
||||
getActivity(), mWifiNfcDialogSavedState, mWifiManager);
|
||||
}
|
||||
|
||||
return mWifiToNfcDialog;
|
||||
}
|
||||
return super.onCreateDialog(dialogId);
|
||||
}
|
||||
|
@@ -56,10 +56,11 @@ 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;
|
||||
|
||||
private AccessPoint mAccessPoint;
|
||||
private View mView;
|
||||
private Button mSubmitButton;
|
||||
private Button mCancelButton;
|
||||
@@ -71,16 +72,31 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
private WifiManager mWifiManager;
|
||||
private String mWpsNfcConfigurationToken;
|
||||
private Context mContext;
|
||||
private int mNetworkId;
|
||||
private int mSecurity;
|
||||
|
||||
WriteWifiConfigToNfcDialog(Context context, AccessPoint accessPoint,
|
||||
WriteWifiConfigToNfcDialog(Context context, int networkId, int security,
|
||||
WifiManager wifiManager) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
|
||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
|
||||
mAccessPoint = accessPoint;
|
||||
mOnTextChangedHandler = new Handler();
|
||||
mNetworkId = networkId;
|
||||
mSecurity = security;
|
||||
mWifiManager = wifiManager;
|
||||
}
|
||||
|
||||
WriteWifiConfigToNfcDialog(Context context, Bundle savedState, WifiManager 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;
|
||||
}
|
||||
|
||||
@@ -120,7 +136,7 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
|
||||
String password = mPasswordView.getText().toString();
|
||||
String wpsNfcConfigurationToken
|
||||
= mWifiManager.getWpsNfcConfigurationToken(mAccessPoint.getConfig().networkId);
|
||||
= mWifiManager.getWpsNfcConfigurationToken(mNetworkId);
|
||||
String passwordHex = byteArrayToHexString(password.getBytes());
|
||||
|
||||
String passwordLength = password.length() >= HEX_RADIX
|
||||
@@ -163,6 +179,11 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
}
|
||||
}
|
||||
|
||||
public void saveState(Bundle state) {
|
||||
state.putInt(NETWORK_ID, mNetworkId);
|
||||
state.putInt(SECURITY, mSecurity);
|
||||
}
|
||||
|
||||
private void handleWriteNfcEvent(Tag tag) {
|
||||
Ndef ndef = Ndef.get(tag);
|
||||
|
||||
@@ -223,9 +244,9 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
||||
private void enableSubmitIfAppropriate() {
|
||||
|
||||
if (mPasswordView != null) {
|
||||
if (mAccessPoint.getSecurity() == AccessPoint.SECURITY_WEP) {
|
||||
if (mSecurity == AccessPoint.SECURITY_WEP) {
|
||||
mSubmitButton.setEnabled(mPasswordView.length() > 0);
|
||||
} else if (mAccessPoint.getSecurity() == AccessPoint.SECURITY_PSK) {
|
||||
} else if (mSecurity == AccessPoint.SECURITY_PSK) {
|
||||
mSubmitButton.setEnabled(mPasswordView.length() >= 8);
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user