Allow WiFi picker to exit after a valid connection is made

Choice is passed in via boolean extra and has two effects:
* A valid network connection exits the picker.
* The next button (if there is one) is hidden.

This functionality will be used for SetupWizard initially.

Bug: 6428046
Change-Id: Ieeed3a9f1013cccd76bd4762131747a57a38ce9c
This commit is contained in:
Andrew Flynn
2012-05-06 14:59:11 -07:00
parent 98d262df0d
commit 0575736cdc

View File

@@ -133,6 +133,10 @@ public class WifiSettings extends SettingsPreferenceFragment
// this boolean extra specifies whether to disable the Next button when not connected // this boolean extra specifies whether to disable the Next button when not connected
private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect"; private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";
// this boolean extra specifies whether to auto finish when connection is established
private static final String EXTRA_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
private static final String EXTRA_WIFI_SHOW_ACTION_BAR = "wifi_show_action_bar"; private static final String EXTRA_WIFI_SHOW_ACTION_BAR = "wifi_show_action_bar";
private static final String EXTRA_WIFI_SHOW_MENUS = "wifi_show_menus"; private static final String EXTRA_WIFI_SHOW_MENUS = "wifi_show_menus";
private static final String EXTRA_WIFI_DISABLE_BACK = "wifi_disable_back"; private static final String EXTRA_WIFI_DISABLE_BACK = "wifi_disable_back";
@@ -140,6 +144,9 @@ public class WifiSettings extends SettingsPreferenceFragment
// should Next button only be enabled when we have a connection? // should Next button only be enabled when we have a connection?
private boolean mEnableNextOnConnection; private boolean mEnableNextOnConnection;
// should activity finish once we have a connection?
private boolean mAutoFinishOnConnection;
// Save the dialog details // Save the dialog details
private boolean mDlgEdit; private boolean mDlgEdit;
private AccessPoint mDlgAccessPoint; private AccessPoint mDlgAccessPoint;
@@ -220,6 +227,24 @@ public class WifiSettings extends SettingsPreferenceFragment
final Activity activity = getActivity(); final Activity activity = getActivity();
final Intent intent = activity.getIntent(); final Intent intent = activity.getIntent();
// first if we're supposed to finish once we have a connection
mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
if (mAutoFinishOnConnection) {
// Hide the next button
if (hasNextButton()) {
getNextButton().setVisibility(View.GONE);
}
final ConnectivityManager connectivity = (ConnectivityManager)
getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null
&& connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
activity.finish();
return;
}
}
// 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
// state, start it off in the right state // state, start it off in the right state
mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false); mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
@@ -656,6 +681,10 @@ public class WifiSettings extends SettingsPreferenceFragment
changeNextButtonState(info.isConnected()); changeNextButtonState(info.isConnected());
updateAccessPoints(); updateAccessPoints();
updateConnectionState(info.getDetailedState()); updateConnectionState(info.getDetailedState());
if (mAutoFinishOnConnection && info.isConnected()) {
getActivity().finish();
return;
}
} else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
updateConnectionState(null); updateConnectionState(null);
} }