am 585b53e6: am 0325a858: Merge "[Settings] Wifi Setup responds to other connection state change" into lmp-mr1-dev

* commit '585b53e6d2ddc0725ce69f6f7208ad791e8d256e':
  [Settings] Wifi Setup responds to other connection state change
This commit is contained in:
Lucky Zhang
2015-01-14 12:06:43 +00:00
committed by Android Git Automerger

View File

@@ -42,11 +42,15 @@ public class WifiSetupActivity extends WifiPickerActivity
implements ButtonBarHandler, NavigationBarListener { implements ButtonBarHandler, NavigationBarListener {
private static final String TAG = "WifiSetupActivity"; private static final String TAG = "WifiSetupActivity";
private static final String EXTRA_ALLOW_SKIP = "allowSkip";
// this boolean extra specifies whether to auto finish when connection is established // 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_AUTO_FINISH_ON_CONNECT = "wifi_auto_finish_on_connect";
// This boolean extra specifies whether network is required
private static final String EXTRA_IS_NETWORK_REQUIRED = "is_network_required";
// This boolean extra specifies whether wifi is required
private static final String EXTRA_IS_WIFI_REQUIRED = "is_wifi_required";
// Whether auto finish is suspended until user connects to an access point // Whether auto finish is suspended until user connects to an access point
private static final String EXTRA_REQUIRE_USER_NETWORK_SELECTION = private static final String EXTRA_REQUIRE_USER_NETWORK_SELECTION =
"wifi_require_user_network_selection"; "wifi_require_user_network_selection";
@@ -57,10 +61,12 @@ public class WifiSetupActivity extends WifiPickerActivity
// Activity result when pressing the Skip button // Activity result when pressing the Skip button
private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER; private static final int RESULT_SKIP = Activity.RESULT_FIRST_USER;
// Whether we allow skipping without a valid network connection
private boolean mAllowSkip = true;
// Whether to auto finish when the user selected a network and successfully connected // Whether to auto finish when the user selected a network and successfully connected
private boolean mAutoFinishOnConnection; private boolean mAutoFinishOnConnection;
// Whether network is required to proceed. This is decided in SUW and passed in as an extra.
private boolean mIsNetworkRequired;
// Whether wifi is required to proceed. This is decided in SUW and passed in as an extra.
private boolean mIsWifiRequired;
// Whether the user connected to a network. This excludes the auto-connecting by the system. // Whether the user connected to a network. This excludes the auto-connecting by the system.
private boolean mUserSelectedNetwork; private boolean mUserSelectedNetwork;
// Whether the device is connected to WiFi // Whether the device is connected to WiFi
@@ -75,7 +81,6 @@ public class WifiSetupActivity extends WifiPickerActivity
// Refresh the connection state with the latest connection info. Use the connection info // Refresh the connection state with the latest connection info. Use the connection info
// from ConnectivityManager instead of the one attached in the intent to make sure // from ConnectivityManager instead of the one attached in the intent to make sure
// we have the most up-to-date connection state. b/17511772 // we have the most up-to-date connection state. b/17511772
refreshConnectionState(); refreshConnectionState();
} }
}; };
@@ -89,7 +94,8 @@ public class WifiSetupActivity extends WifiPickerActivity
mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false); mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
mAllowSkip = intent.getBooleanExtra(EXTRA_ALLOW_SKIP, true); mIsNetworkRequired = intent.getBooleanExtra(EXTRA_IS_NETWORK_REQUIRED, false);
mIsWifiRequired = intent.getBooleanExtra(EXTRA_IS_WIFI_REQUIRED, false);
// Behave like the user already selected a network if we do not require selection // Behave like the user already selected a network if we do not require selection
mUserSelectedNetwork = !intent.getBooleanExtra(EXTRA_REQUIRE_USER_NETWORK_SELECTION, false); mUserSelectedNetwork = !intent.getBooleanExtra(EXTRA_REQUIRE_USER_NETWORK_SELECTION, false);
} }
@@ -106,18 +112,17 @@ public class WifiSetupActivity extends WifiPickerActivity
mUserSelectedNetwork = savedInstanceState.getBoolean(PARAM_USER_SELECTED_NETWORK, true); mUserSelectedNetwork = savedInstanceState.getBoolean(PARAM_USER_SELECTED_NETWORK, true);
} }
private void refreshConnectionState() { private boolean isWifiConnected() {
final ConnectivityManager connectivity = (ConnectivityManager) final ConnectivityManager connectivity = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE); getSystemService(Context.CONNECTIVITY_SERVICE);
boolean connected = connectivity != null && boolean wifiConnected = connectivity != null &&
connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
mWifiConnected = wifiConnected;
refreshConnectionState(connected); return wifiConnected;
} }
private void refreshConnectionState(boolean connected) { private void refreshConnectionState() {
mWifiConnected = connected; if (isWifiConnected()) {
if (connected) {
if (mAutoFinishOnConnection && mUserSelectedNetwork) { if (mAutoFinishOnConnection && mUserSelectedNetwork) {
Log.d(TAG, "Auto-finishing with connection"); Log.d(TAG, "Auto-finishing with connection");
finishOrNext(Activity.RESULT_OK); finishOrNext(Activity.RESULT_OK);
@@ -125,15 +130,33 @@ public class WifiSetupActivity extends WifiPickerActivity
// can either connect to a different network or press "next" to proceed. // can either connect to a different network or press "next" to proceed.
mUserSelectedNetwork = false; mUserSelectedNetwork = false;
} }
if (mNavigationBar != null) { setNextButtonText(R.string.setup_wizard_next_button_label);
mNavigationBar.getNextButton().setText(R.string.setup_wizard_next_button_label); setNextButtonEnabled(true);
mNavigationBar.getNextButton().setEnabled(true); } else if (mIsWifiRequired || (mIsNetworkRequired && !isNetworkConnected())) {
} // We do not want the user to skip wifi setting if
// - wifi is required, but wifi connection hasn't been established yet;
// - or network is required, but no valid connection has been established.
setNextButtonText(R.string.skip_label);
setNextButtonEnabled(false);
} else { } else {
if (mNavigationBar != null) { // In other cases, user can choose to skip. Specifically these cases are
mNavigationBar.getNextButton().setText(R.string.skip_label); // - wifi is not required;
mNavigationBar.getNextButton().setEnabled(mAllowSkip); // - and network is not required;
} // - or network is required and a valid connection has been established.
setNextButtonText(R.string.skip_label);
setNextButtonEnabled(true);
}
}
private void setNextButtonEnabled(boolean enabled) {
if (mNavigationBar != null) {
mNavigationBar.getNextButton().setEnabled(enabled);
}
}
private void setNextButtonText(int resId) {
if (mNavigationBar != null) {
mNavigationBar.getNextButton().setText(resId);
} }
} }