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
|
// Instance state keys
|
||||||
private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
|
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 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 static boolean savedNetworksExist;
|
||||||
|
|
||||||
@@ -142,6 +143,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private boolean mDlgEdit;
|
private boolean mDlgEdit;
|
||||||
private AccessPoint mDlgAccessPoint;
|
private AccessPoint mDlgAccessPoint;
|
||||||
private Bundle mAccessPointSavedState;
|
private Bundle mAccessPointSavedState;
|
||||||
|
private Bundle mWifiNfcDialogSavedState;
|
||||||
|
|
||||||
private WifiTracker mWifiTracker;
|
private WifiTracker mWifiTracker;
|
||||||
|
|
||||||
@@ -209,6 +211,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mAccessPointSavedState =
|
mAccessPointSavedState =
|
||||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
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
|
// 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);
|
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
|
@Override
|
||||||
@@ -576,10 +589,15 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
case WRITE_NFC_DIALOG_ID:
|
case WRITE_NFC_DIALOG_ID:
|
||||||
if (mSelectedAccessPoint != null) {
|
if (mSelectedAccessPoint != null) {
|
||||||
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
||||||
getActivity(), mSelectedAccessPoint, mWifiManager);
|
getActivity(), mSelectedAccessPoint.getConfig().networkId,
|
||||||
return mWifiToNfcDialog;
|
mSelectedAccessPoint.getSecurity(),
|
||||||
|
mWifiManager);
|
||||||
|
} else if (mWifiNfcDialogSavedState != null) {
|
||||||
|
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
||||||
|
getActivity(), mWifiNfcDialogSavedState, mWifiManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mWifiToNfcDialog;
|
||||||
}
|
}
|
||||||
return super.onCreateDialog(dialogId);
|
return super.onCreateDialog(dialogId);
|
||||||
}
|
}
|
||||||
|
@@ -56,10 +56,11 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
|||||||
private static final String PASSWORD_FORMAT = "102700%s%s";
|
private static final String PASSWORD_FORMAT = "102700%s%s";
|
||||||
private static final int HEX_RADIX = 16;
|
private static final int HEX_RADIX = 16;
|
||||||
private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
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 final PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
private AccessPoint mAccessPoint;
|
|
||||||
private View mView;
|
private View mView;
|
||||||
private Button mSubmitButton;
|
private Button mSubmitButton;
|
||||||
private Button mCancelButton;
|
private Button mCancelButton;
|
||||||
@@ -71,16 +72,31 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
|||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private String mWpsNfcConfigurationToken;
|
private String mWpsNfcConfigurationToken;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private int mNetworkId;
|
||||||
|
private int mSecurity;
|
||||||
|
|
||||||
WriteWifiConfigToNfcDialog(Context context, AccessPoint accessPoint,
|
WriteWifiConfigToNfcDialog(Context context, int networkId, int security,
|
||||||
WifiManager wifiManager) {
|
WifiManager wifiManager) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
|
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
|
||||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
|
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
|
||||||
mAccessPoint = accessPoint;
|
|
||||||
mOnTextChangedHandler = new Handler();
|
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;
|
mWifiManager = wifiManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +136,7 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
|||||||
|
|
||||||
String password = mPasswordView.getText().toString();
|
String password = mPasswordView.getText().toString();
|
||||||
String wpsNfcConfigurationToken
|
String wpsNfcConfigurationToken
|
||||||
= mWifiManager.getWpsNfcConfigurationToken(mAccessPoint.getConfig().networkId);
|
= mWifiManager.getWpsNfcConfigurationToken(mNetworkId);
|
||||||
String passwordHex = byteArrayToHexString(password.getBytes());
|
String passwordHex = byteArrayToHexString(password.getBytes());
|
||||||
|
|
||||||
String passwordLength = password.length() >= HEX_RADIX
|
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) {
|
private void handleWriteNfcEvent(Tag tag) {
|
||||||
Ndef ndef = Ndef.get(tag);
|
Ndef ndef = Ndef.get(tag);
|
||||||
|
|
||||||
@@ -223,9 +244,9 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
|
|||||||
private void enableSubmitIfAppropriate() {
|
private void enableSubmitIfAppropriate() {
|
||||||
|
|
||||||
if (mPasswordView != null) {
|
if (mPasswordView != null) {
|
||||||
if (mAccessPoint.getSecurity() == AccessPoint.SECURITY_WEP) {
|
if (mSecurity == AccessPoint.SECURITY_WEP) {
|
||||||
mSubmitButton.setEnabled(mPasswordView.length() > 0);
|
mSubmitButton.setEnabled(mPasswordView.length() > 0);
|
||||||
} else if (mAccessPoint.getSecurity() == AccessPoint.SECURITY_PSK) {
|
} else if (mSecurity == AccessPoint.SECURITY_PSK) {
|
||||||
mSubmitButton.setEnabled(mPasswordView.length() >= 8);
|
mSubmitButton.setEnabled(mPasswordView.length() >= 8);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user