diff options
Diffstat (limited to 'src/eu/siacs/conversations/services')
-rw-r--r-- | src/eu/siacs/conversations/services/EventReceiver.java | 10 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 24 |
2 files changed, 11 insertions, 23 deletions
diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index 66208bca..d58fb2ec 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -3,9 +3,6 @@ package eu.siacs.conversations.services; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; - public class EventReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { @@ -16,13 +13,6 @@ public class EventReceiver extends BroadcastReceiver { .equals("android.intent.action.BOOT_COMPLETED"))) { } - ConnectivityManager cm = (ConnectivityManager) context - .getSystemService(Context.CONNECTIVITY_SERVICE); - - NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); - boolean isConnected = activeNetwork != null - && activeNetwork.isConnected(); - mIntentForService.putExtra("has_internet", isConnected); context.startService(mIntentForService); } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 8c7d64ce..a10ffb2b 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(); |