aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2014-03-06 03:57:29 +0100
committerDaniel Gultsch <daniel@gultsch.de>2014-03-06 03:57:29 +0100
commitac93f7419a40d9f94203d58dc00a5b51bea42ba5 (patch)
treeeb0981a42c3e36c49296555f0684390099a295ac
parent2f0b2b865e4ec1b34d37120f085a9841ea11d1ed (diff)
bug fixes. stuff more smoother
Diffstat (limited to '')
-rw-r--r--AndroidManifest.xml2
-rw-r--r--src/eu/siacs/conversations/services/EventReceiver.java10
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java24
-rw-r--r--src/eu/siacs/conversations/ui/ManageAccountActivity.java8
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java20
5 files changed, 32 insertions, 32 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 881ed7e3..7855986d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
@@ -24,6 +25,7 @@
<receiver android:name="eu.siacs.conversations.services.EventReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
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();
diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java
index 1a5ee902..76824114 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 3b3faaed..ec395de3 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();