// 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;
private boolean mDlgEdit;
private AccessPoint mDlgAccessPoint;
private Bundle mAccessPointSavedState;
+ private Bundle mWifiNfcDialogSavedState;
private WifiTracker mWifiTracker;
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
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
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);
}
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;
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;
}
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
}
}
+ public void saveState(Bundle state) {
+ state.putInt(NETWORK_ID, mNetworkId);
+ state.putInt(SECURITY, mSecurity);
+ }
+
private void handleWriteNfcEvent(Tag tag) {
Ndef ndef = Ndef.get(tag);
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 {