[WifiSetup] Mechanism for suspending auto finish
We have been using forget() to prevent auto-reconnection when the user hits back to Wifi setup. This has the side effect of forgetting networks, which is undesirable especially for password protected APs. The new mechanism keeps a flag on whether the user has selected a connection. Only auto-advance if the user has picked a network and there is a valid WiFi connection. The new EXTRA_REQUIRE_USER_SELECTION can specify whether a user selection is required initially. That is, whether to auto finish if the system connected to a network without user input. The default is false so WiFi can be skipped if the user started setup wizard with a valid WiFi connection (e.g. after System Update). Note that a user selection is always required when the user goes back from the next screen. Since the new AP dialog does not have a connect button, the SKIP button in the navigation bar also changes to NEXT when there is a valid WiFi connection, so the user can hit NEXT if they decided not to change the network. Bug: 15333554 Bug: 15999487 Change-Id: I98e935b8e09e470a0c49c44bc299bb2eced98634
This commit is contained in:
@@ -560,13 +560,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_ID_CONNECT: {
|
case MENU_ID_CONNECT: {
|
||||||
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||||
mWifiManager.connect(mSelectedAccessPoint.networkId,
|
connect(mSelectedAccessPoint.networkId);
|
||||||
mConnectListener);
|
|
||||||
} else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
|
} else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
|
||||||
/** Bypass dialog for unsecured networks */
|
/** Bypass dialog for unsecured networks */
|
||||||
mSelectedAccessPoint.generateOpenNetworkConfig();
|
mSelectedAccessPoint.generateOpenNetworkConfig();
|
||||||
mWifiManager.connect(mSelectedAccessPoint.getConfig(),
|
connect(mSelectedAccessPoint.getConfig());
|
||||||
mConnectListener);
|
|
||||||
} else {
|
} else {
|
||||||
showDialog(mSelectedAccessPoint, true);
|
showDialog(mSelectedAccessPoint, true);
|
||||||
}
|
}
|
||||||
@@ -600,7 +598,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
savedNetworksExist = true;
|
savedNetworksExist = true;
|
||||||
getActivity().invalidateOptionsMenu();
|
getActivity().invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
mWifiManager.connect(mSelectedAccessPoint.getConfig(), mConnectListener);
|
connect(mSelectedAccessPoint.getConfig());
|
||||||
} else {
|
} else {
|
||||||
showDialog(mSelectedAccessPoint, false);
|
showDialog(mSelectedAccessPoint, false);
|
||||||
}
|
}
|
||||||
@@ -930,8 +928,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
if (config == null) {
|
if (config == null) {
|
||||||
if (mSelectedAccessPoint != null
|
if (mSelectedAccessPoint != null
|
||||||
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
&& mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
|
||||||
mWifiManager.connect(mSelectedAccessPoint.networkId,
|
connect(mSelectedAccessPoint.networkId);
|
||||||
mConnectListener);
|
|
||||||
}
|
}
|
||||||
} else if (config.networkId != INVALID_NETWORK_ID) {
|
} else if (config.networkId != INVALID_NETWORK_ID) {
|
||||||
if (mSelectedAccessPoint != null) {
|
if (mSelectedAccessPoint != null) {
|
||||||
@@ -941,7 +938,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
if (configController.isEdit()) {
|
if (configController.isEdit()) {
|
||||||
mWifiManager.save(config, mSaveListener);
|
mWifiManager.save(config, mSaveListener);
|
||||||
} else {
|
} else {
|
||||||
mWifiManager.connect(config, mConnectListener);
|
connect(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,6 +966,14 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
changeNextButtonState(false);
|
changeNextButtonState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void connect(final WifiConfiguration config) {
|
||||||
|
mWifiManager.connect(config, mConnectListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void connect(final int networkId) {
|
||||||
|
mWifiManager.connect(networkId, mConnectListener);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refreshes acccess points and ask Wifi module to scan networks again.
|
* Refreshes acccess points and ask Wifi module to scan networks again.
|
||||||
*/
|
*/
|
||||||
|
@@ -16,17 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -51,40 +44,9 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
|
|
||||||
private static final String TAG = "WifiSettingsForSetupWizard";
|
private static final String TAG = "WifiSettingsForSetupWizard";
|
||||||
|
|
||||||
/* Used in Wifi Setup context */
|
|
||||||
|
|
||||||
// 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";
|
|
||||||
|
|
||||||
// show a text regarding data charges when wifi connection is required during setup wizard
|
// show a text regarding data charges when wifi connection is required during setup wizard
|
||||||
protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
|
protected static final String EXTRA_SHOW_WIFI_REQUIRED_INFO = "wifi_show_wifi_required_info";
|
||||||
|
|
||||||
// should activity finish once we have a connection?
|
|
||||||
private boolean mAutoFinishOnConnection;
|
|
||||||
|
|
||||||
private final IntentFilter mFilter;
|
|
||||||
private final BroadcastReceiver mReceiver;
|
|
||||||
|
|
||||||
public WifiSettingsForSetupWizard() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
mFilter = new IntentFilter();
|
|
||||||
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
||||||
|
|
||||||
mReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
|
||||||
WifiManager.EXTRA_NETWORK_INFO);
|
|
||||||
if (mAutoFinishOnConnection && info.isConnected()) {
|
|
||||||
Log.d(TAG, "mReceiver.onReceive context=" + context + " intent=" + intent);
|
|
||||||
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
|
||||||
activity.finishOrNext(Activity.RESULT_OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
@@ -127,48 +89,11 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
|
View.STATUS_BAR_DISABLE_NOTIFICATION_ALERTS |
|
||||||
View.STATUS_BAR_DISABLE_CLOCK);
|
View.STATUS_BAR_DISABLE_CLOCK);
|
||||||
|
|
||||||
final WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
if (hasNextButton()) {
|
||||||
final Intent intent = activity.getIntent();
|
getNextButton().setVisibility(View.GONE);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When entering with a savedInstanceState, we may be returning from a later activity in
|
|
||||||
* the setup flow. It's not clear yet if there are other possible circumstances. It's
|
|
||||||
* not appropriate to refire our activity results, so we skip that here.
|
|
||||||
*/
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
final ConnectivityManager connectivity = (ConnectivityManager)
|
|
||||||
activity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
if (connectivity != null &&
|
|
||||||
connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
|
|
||||||
Log.d(TAG, "onActivityCreated Auto-finishing");
|
|
||||||
activity.finishOrNext(Activity.RESULT_OK);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
getActivity().registerReceiver(mReceiver, mFilter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
getActivity().unregisterReceiver(mReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerForContextMenu(View view) {
|
public void registerForContextMenu(View view) {
|
||||||
// Suppressed during setup wizard
|
// Suppressed during setup wizard
|
||||||
@@ -194,4 +119,18 @@ public class WifiSettingsForSetupWizard extends WifiSettings {
|
|||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
ta.recycle();
|
ta.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void connect(final WifiConfiguration config) {
|
||||||
|
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
||||||
|
activity.networkSelected();
|
||||||
|
super.connect(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void connect(final int networkId) {
|
||||||
|
WifiSetupActivity activity = (WifiSetupActivity) getActivity();
|
||||||
|
activity.networkSelected();
|
||||||
|
super.connect(networkId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,15 +19,15 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
@@ -45,6 +45,13 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
private static final String EXTRA_ALLOW_SKIP = "allowSkip";
|
private static final String EXTRA_ALLOW_SKIP = "allowSkip";
|
||||||
private static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode";
|
private static final String EXTRA_USE_IMMERSIVE_MODE = "useImmersiveMode";
|
||||||
|
|
||||||
|
// 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";
|
||||||
|
|
||||||
|
// Whether auto finish is suspended until user connects to an access point
|
||||||
|
private static final String EXTRA_REQUIRE_USER_NETWORK_SELECTION =
|
||||||
|
"wifi_require_user_network_selection";
|
||||||
|
|
||||||
// Extra containing the resource name of the theme to be used
|
// Extra containing the resource name of the theme to be used
|
||||||
private static final String EXTRA_THEME = "theme";
|
private static final String EXTRA_THEME = "theme";
|
||||||
private static final String THEME_HOLO = "holo";
|
private static final String THEME_HOLO = "holo";
|
||||||
@@ -62,6 +69,85 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
|
private static final String EXTRA_RESULT_CODE = "com.android.setupwizard.ResultCode";
|
||||||
private static final int NEXT_REQUEST = 10000;
|
private static final int NEXT_REQUEST = 10000;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
private boolean mAutoFinishOnConnection;
|
||||||
|
// Whether the user connected to a network. This excludes the auto-connecting by the system.
|
||||||
|
private boolean mUserSelectedNetwork;
|
||||||
|
// Whether the device is connected to WiFi
|
||||||
|
private boolean mWifiConnected;
|
||||||
|
|
||||||
|
private SetupWizardNavBar mNavigationBar;
|
||||||
|
|
||||||
|
private final IntentFilter mFilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
||||||
|
WifiManager.EXTRA_NETWORK_INFO);
|
||||||
|
refreshConnectionState(info.isConnected());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
|
mAutoFinishOnConnection = intent.getBooleanExtra(EXTRA_AUTO_FINISH_ON_CONNECT, false);
|
||||||
|
mAllowSkip = intent.getBooleanExtra(EXTRA_ALLOW_SKIP, true);
|
||||||
|
// Behave like the user already selected a network if we do not require selection
|
||||||
|
mUserSelectedNetwork = !intent.getBooleanExtra(EXTRA_REQUIRE_USER_NETWORK_SELECTION, false);
|
||||||
|
|
||||||
|
refreshConnectionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshConnectionState() {
|
||||||
|
final ConnectivityManager connectivity = (ConnectivityManager)
|
||||||
|
getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
boolean connected = connectivity != null &&
|
||||||
|
connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
|
||||||
|
refreshConnectionState(connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshConnectionState(boolean connected) {
|
||||||
|
mWifiConnected = connected;
|
||||||
|
if (connected) {
|
||||||
|
if (mAutoFinishOnConnection && mUserSelectedNetwork) {
|
||||||
|
Log.d(TAG, "Auto-finishing with connection");
|
||||||
|
finishOrNext(Activity.RESULT_OK);
|
||||||
|
}
|
||||||
|
if (mNavigationBar != null) {
|
||||||
|
mNavigationBar.getNextButton().setText(R.string.setup_wizard_next_button_label);
|
||||||
|
mNavigationBar.getNextButton().setEnabled(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mNavigationBar != null) {
|
||||||
|
mNavigationBar.getNextButton().setText(R.string.skip_label);
|
||||||
|
mNavigationBar.getNextButton().setEnabled(mAllowSkip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* package */ void networkSelected() {
|
||||||
|
Log.d(TAG, "Network selected by user");
|
||||||
|
mUserSelectedNetwork = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
registerReceiver(mReceiver, mFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
unregisterReceiver(mReceiver);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
|
protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
|
||||||
String themeName = getIntent().getStringExtra(EXTRA_THEME);
|
String themeName = getIntent().getStringExtra(EXTRA_THEME);
|
||||||
@@ -86,22 +172,12 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode == Activity.RESULT_CANCELED) {
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
// Before returning to the settings panel, forget any current access point so it will
|
Log.d(TAG, "Back into WifiSetupActivity. Requiring user selection.");
|
||||||
// not attempt to automatically reconnect and advance
|
// Require a user selection before we auto advance again. Or the user can press the
|
||||||
// FIXME: when coming back, it would be better to keep the current connection and
|
// next button if there is a valid WiFi connection.
|
||||||
// override the auto-advance feature
|
mUserSelectedNetwork = false;
|
||||||
final WifiManager wifiManager = (WifiManager)(getSystemService(Context.WIFI_SERVICE));
|
|
||||||
if (wifiManager != null) {
|
|
||||||
final WifiInfo info = wifiManager.getConnectionInfo();
|
|
||||||
if (info != null) {
|
|
||||||
int netId = info.getNetworkId();
|
|
||||||
if (netId != WifiConfiguration.INVALID_NETWORK_ID) {
|
|
||||||
wifiManager.forget(netId, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
@@ -142,6 +218,7 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNavigationBarCreated(final SetupWizardNavBar bar) {
|
public void onNavigationBarCreated(final SetupWizardNavBar bar) {
|
||||||
|
mNavigationBar = bar;
|
||||||
final boolean useImmersiveMode =
|
final boolean useImmersiveMode =
|
||||||
getIntent().getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false);
|
getIntent().getBooleanExtra(EXTRA_USE_IMMERSIVE_MODE, false);
|
||||||
bar.setUseImmersiveMode(useImmersiveMode);
|
bar.setUseImmersiveMode(useImmersiveMode);
|
||||||
@@ -149,11 +226,7 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
getWindow().setNavigationBarColor(Color.TRANSPARENT);
|
getWindow().setNavigationBarColor(Color.TRANSPARENT);
|
||||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||||
}
|
}
|
||||||
bar.getNextButton().setText(R.string.skip_label);
|
refreshConnectionState();
|
||||||
|
|
||||||
if (!getIntent().getBooleanExtra(EXTRA_ALLOW_SKIP, true)) {
|
|
||||||
bar.getNextButton().setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,22 +236,29 @@ public class WifiSetupActivity extends WifiPickerActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNavigateNext() {
|
public void onNavigateNext() {
|
||||||
boolean isConnected = false;
|
if (mWifiConnected) {
|
||||||
|
finishOrNext(RESULT_OK);
|
||||||
|
} else {
|
||||||
|
// Warn of possible data charges if there is a network connection, or lack of updates
|
||||||
|
// if there is none.
|
||||||
|
final int message = isNetworkConnected() ? R.string.wifi_skipped_message :
|
||||||
|
R.string.wifi_and_mobile_skipped_message;
|
||||||
|
WifiSkipDialog.newInstance(message).show(getFragmentManager(), "dialog");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if there is a valid network connection, whether it is via WiFi, mobile data or
|
||||||
|
* other means.
|
||||||
|
*/
|
||||||
|
private boolean isNetworkConnected() {
|
||||||
final ConnectivityManager connectivity = (ConnectivityManager)
|
final ConnectivityManager connectivity = (ConnectivityManager)
|
||||||
getSystemService(Context.CONNECTIVITY_SERVICE);
|
getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
if (connectivity != null) {
|
if (connectivity == null) {
|
||||||
final NetworkInfo info = connectivity.getActiveNetworkInfo();
|
return false;
|
||||||
isConnected = (info != null) && info.isConnected();
|
|
||||||
}
|
|
||||||
if (isConnected) {
|
|
||||||
// Warn of possible data charges
|
|
||||||
WifiSkipDialog.newInstance(R.string.wifi_skipped_message)
|
|
||||||
.show(getFragmentManager(), "dialog");
|
|
||||||
} else {
|
|
||||||
// Warn of lack of updates
|
|
||||||
WifiSkipDialog.newInstance(R.string.wifi_and_mobile_skipped_message)
|
|
||||||
.show(getFragmentManager(), "dialog");
|
|
||||||
}
|
}
|
||||||
|
final NetworkInfo info = connectivity.getActiveNetworkInfo();
|
||||||
|
return info != null && info.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WifiSkipDialog extends DialogFragment {
|
public static class WifiSkipDialog extends DialogFragment {
|
||||||
|
Reference in New Issue
Block a user