aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/services/XmppConnectionService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/gultsch/chat/services/XmppConnectionService.java')
-rw-r--r--src/de/gultsch/chat/services/XmppConnectionService.java41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java
index b8a54523..d078714d 100644
--- a/src/de/gultsch/chat/services/XmppConnectionService.java
+++ b/src/de/gultsch/chat/services/XmppConnectionService.java
@@ -1,22 +1,43 @@
package de.gultsch.chat.services;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.UnknownHostException;
import java.util.List;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
import de.gultsch.chat.entities.Account;
import de.gultsch.chat.entities.Contact;
import de.gultsch.chat.entities.Conversation;
import de.gultsch.chat.entities.Message;
import de.gultsch.chat.persistance.DatabaseBackend;
+import de.gultsch.chat.xml.Tag;
+import de.gultsch.chat.xml.XmlReader;
+import de.gultsch.chat.xmpp.XmppConnection;
import android.app.Service;
+import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
+import android.os.PowerManager;
import android.util.Log;
public class XmppConnectionService extends Service {
- protected static final String LOGTAG = "xmppConnection";
+ protected static final String LOGTAG = "xmppService";
protected DatabaseBackend databaseBackend;
+
+ public long startDate;
+
+ private List<Account> accounts;
+
+ public boolean connectionRunnig = false;
private final IBinder mBinder = new XmppConnectionBinder();
@@ -26,9 +47,27 @@ public class XmppConnectionService extends Service {
}
}
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ Log.d(LOGTAG,"recieved start command. been running for "+((System.currentTimeMillis() - startDate) / 1000)+"s");
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ if (!connectionRunnig) {
+ for(Account account : accounts) {
+ Log.d(LOGTAG,"connection wasnt running");
+ XmppConnection connection = new XmppConnection(account, pm);
+ Thread thread = new Thread(connection);
+ thread.start();
+ }
+ connectionRunnig = true;
+ }
+ return START_STICKY;
+ }
+
@Override
public void onCreate() {
databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
+ this.accounts = databaseBackend.getAccounts();
+ startDate = System.currentTimeMillis();
}
@Override