diff options
Diffstat (limited to 'src/eu')
4 files changed, 30 insertions, 32 deletions
diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index 66208bca3..d58fb2ec3 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 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(); diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 1a5ee902c..768241147 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -90,6 +90,10 @@ public class ManageAccountActivity extends XmppActivity { statusView.setText("online"); statusView.setTextColor(0xFF83b600); break; + case Account.STATUS_CONNECTING: + statusView.setText("connecting\u2026"); + statusView.setTextColor(0xFF1da9da); + break; case Account.STATUS_OFFLINE: statusView.setText("offline"); statusView.setTextColor(0xFFe92727); @@ -102,6 +106,10 @@ public class ManageAccountActivity extends XmppActivity { statusView.setText("server not found"); statusView.setTextColor(0xFFe92727); break; + case Account.STATUS_NO_INTERNET: + statusView.setText("no internet"); + statusView.setTextColor(0xFFe92727); + break; default: break; } diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 3b3faaed5..ec395de31 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -66,10 +66,17 @@ public class XmppConnection implements Runnable { tagReader = new XmlReader(wakeLock); tagWriter = new TagWriter(); } + + protected void changeStatus(int nextStatus) { + account.setStatus(nextStatus); + if (statusListener != null) { + statusListener.onStatusChanged(account); + } + } protected void connect() { try { - account.setStatus(Account.STATUS_CONNECTING); + this.changeStatus(Account.STATUS_CONNECTING); Bundle namePort = DNSHelper.getSRVRecord(account.getServer()); String srvRecordServer = namePort.getString("name"); int srvRecordPort = namePort.getInt("port"); @@ -100,24 +107,19 @@ public class XmppConnection implements Runnable { socket.close(); } } catch (UnknownHostException e) { - account.setStatus(Account.STATUS_SERVER_NOT_FOUND); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + this.changeStatus(Account.STATUS_SERVER_NOT_FOUND); if (wakeLock.isHeld()) { wakeLock.release(); } return; } catch (IOException e) { - account.setStatus(Account.STATUS_OFFLINE); - if (statusListener != null) { - statusListener.onStatusChanged(account); - } + this.changeStatus(Account.STATUS_OFFLINE); if (wakeLock.isHeld()) { wakeLock.release(); } return; } catch (XmlPullParserException e) { + this.changeStatus(Account.STATUS_OFFLINE); Log.d(LOGTAG, "xml exception " + e.getMessage()); if (wakeLock.isHeld()) { wakeLock.release(); |