aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/services/XmppConnectionService.java')
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index 8c7d64ce1..a10ffb2be 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -52,6 +52,8 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.database.DatabaseUtils;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@@ -378,19 +380,15 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- boolean internet;
- if ((intent!=null)&&(intent.hasExtra("has_internet"))) {
- if (intent.getExtras().getBoolean("has_internet",true)) {
- internet = true;
- } else {
- internet = false;
- }
- } else {
- internet = true;
- }
+ ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
+ boolean isConnected = activeNetwork != null
+ && activeNetwork.isConnected();
for (Account account : accounts) {
- if (!internet) {
+ if (!isConnected) {
account.setStatus(Account.STATUS_NO_INTERNET);
+ Log.d(LOGTAG,"set no internet status to account");
break;
} else {
if (account.getStatus() == Account.STATUS_NO_INTERNET) {
@@ -398,13 +396,13 @@ public class XmppConnectionService extends Service {
}
}
if (account.getXmppConnection() == null) {
- if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) {
+ if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) {
account.setXmppConnection(this.createConnection(account));
Thread thread = new Thread(account.getXmppConnection());
thread.start();
}
} else {
- if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(internet)) {
+ if ((!account.isOptionSet(Account.OPTION_DISABLED))&&(isConnected)) {
if (account.getStatus()==Account.STATUS_OFFLINE) {
Thread thread = new Thread(account.getXmppConnection());
thread.start();