aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/services
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
committeriNPUTmice <daniel@gultsch.de>2014-08-31 16:28:21 +0200
commit1ac5be485502e7d6d4c117335e083c684739e6af (patch)
tree279c22e269158dde838f31ebcf3daf4272573583 /src/eu/siacs/conversations/services
parent8d456085e57334dc34707a49666006619e2c77c6 (diff)
some code cleanup
Diffstat (limited to 'src/eu/siacs/conversations/services')
-rw-r--r--src/eu/siacs/conversations/services/Defaults.java11
-rw-r--r--src/eu/siacs/conversations/services/EventReceiver.java1
-rw-r--r--src/eu/siacs/conversations/services/ImageProvider.java29
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java67
4 files changed, 47 insertions, 61 deletions
diff --git a/src/eu/siacs/conversations/services/Defaults.java b/src/eu/siacs/conversations/services/Defaults.java
deleted file mode 100644
index c942dd484..000000000
--- a/src/eu/siacs/conversations/services/Defaults.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package eu.siacs.conversations.services;
-
-import android.graphics.Bitmap;
-
-public final class Defaults {
- public static final int AVATAR_SIZE = 192;
- public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.WEBP;
- private Defaults() {
-
- }
-}
diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java
index a13d51f2b..c0bf67f31 100644
--- a/src/eu/siacs/conversations/services/EventReceiver.java
+++ b/src/eu/siacs/conversations/services/EventReceiver.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+
public class EventReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java
index 7ab57f5e5..15b86802e 100644
--- a/src/eu/siacs/conversations/services/ImageProvider.java
+++ b/src/eu/siacs/conversations/services/ImageProvider.java
@@ -2,8 +2,8 @@ package eu.siacs.conversations.services;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.IOException;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
@@ -27,7 +27,7 @@ public class ImageProvider extends ContentProvider {
DatabaseBackend databaseBackend = DatabaseBackend
.getInstance(getContext());
String uuids = uri.getPath();
- Log.d("xmppService", "uuids = " + uuids+" mode="+mode);
+ Log.d(Config.LOGTAG, "uuids = " + uuids + " mode=" + mode);
if (uuids == null) {
throw new FileNotFoundException();
}
@@ -37,21 +37,21 @@ public class ImageProvider extends ContentProvider {
}
String conversationUuid = uuidsSplited[1];
String messageUuid = uuidsSplited[2].split("\\.")[0];
-
- Log.d("xmppService","messageUuid="+messageUuid);
-
+
+ Log.d(Config.LOGTAG, "messageUuid=" + messageUuid);
+
Conversation conversation = databaseBackend
.findConversationByUuid(conversationUuid);
if (conversation == null) {
- throw new FileNotFoundException("conversation " + conversationUuid
- + " could not be found");
+ throw new FileNotFoundException("conversation "
+ + conversationUuid + " could not be found");
}
Message message = databaseBackend.findMessageByUuid(messageUuid);
if (message == null) {
throw new FileNotFoundException("message " + messageUuid
+ " could not be found");
}
-
+
Account account = databaseBackend.findAccountByUuid(conversation
.getAccountUuid());
if (account == null) {
@@ -60,7 +60,7 @@ public class ImageProvider extends ContentProvider {
}
message.setConversation(conversation);
conversation.setAccount(account);
-
+
File file = fileBackend.getJingleFileLegacy(message);
pfd = ParcelFileDescriptor.open(file,
ParcelFileDescriptor.MODE_READ_ONLY);
@@ -100,13 +100,10 @@ public class ImageProvider extends ContentProvider {
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
return 0;
}
-
+
public static Uri getProviderUri(Message message) {
- return Uri
- .parse("content://eu.siacs.conversations.images/"
- + message.getConversationUuid()
- + "/"
- + message.getUuid()
- + ".webp");
+ return Uri.parse("content://eu.siacs.conversations.images/"
+ + message.getConversationUuid() + "/" + message.getUuid()
+ + ".webp");
}
} \ No newline at end of file
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index f9af57413..2656f7c6f 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -20,6 +20,7 @@ import de.duenndns.ssl.MemorizingTrustManager;
import net.java.otr4j.OtrException;
import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus;
+import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
@@ -83,18 +84,11 @@ import android.util.Log;
public class XmppConnectionService extends Service {
- protected static final String LOGTAG = "xmppService";
public DatabaseBackend databaseBackend;
private FileBackend fileBackend;
public long startDate;
- private static final int PING_MAX_INTERVAL = 300;
- private static final int PING_MIN_INTERVAL = 30;
- private static final int PING_TIMEOUT = 10;
- private static final int CONNECT_TIMEOUT = 90;
- public static final long CARBON_GRACE_PERIOD = 60000L;
-
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
private MemorizingTrustManager mMemorizingTrustManager;
@@ -169,16 +163,17 @@ public class XmppConnectionService extends Service {
}
if (connection != null && connection.getFeatures().csi()) {
if (checkListeners()) {
- Log.d(LOGTAG, account.getJid()
+ Log.d(Config.LOGTAG, account.getJid()
+ " sending csi//inactive");
connection.sendInactive();
} else {
- Log.d(LOGTAG, account.getJid() + " sending csi//active");
+ Log.d(Config.LOGTAG, account.getJid()
+ + " sending csi//active");
connection.sendActive();
}
}
syncDirtyContacts(account);
- scheduleWakeupCall(PING_MAX_INTERVAL, true);
+ scheduleWakeupCall(Config.PING_MAX_INTERVAL, true);
} else if (account.getStatus() == Account.STATUS_OFFLINE) {
resetSendingToWaiting(account);
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
@@ -192,7 +187,7 @@ public class XmppConnectionService extends Service {
&& (account.getStatus() != Account.STATUS_NO_INTERNET)) {
if (connection != null) {
int next = connection.getTimeToNextAttempt();
- Log.d(LOGTAG, account.getJid()
+ Log.d(Config.LOGTAG, account.getJid()
+ ": error connecting account. try again in "
+ next + "s for the "
+ (connection.getAttempt() + 1) + " time");
@@ -355,10 +350,11 @@ public class XmppConnectionService extends Service {
.getLastPacketReceived();
long lastSent = account.getXmppConnection()
.getLastPingSent();
- if (lastSent - lastReceived >= PING_TIMEOUT * 1000) {
- Log.d(LOGTAG, account.getJid() + ": ping timeout");
+ if (lastSent - lastReceived >= Config.PING_TIMEOUT * 1000) {
+ Log.d(Config.LOGTAG, account.getJid()
+ + ": ping timeout");
this.reconnectAccount(account, true);
- } else if (SystemClock.elapsedRealtime() - lastReceived >= PING_MIN_INTERVAL * 1000) {
+ } else if (SystemClock.elapsedRealtime() - lastReceived >= Config.PING_MIN_INTERVAL * 1000) {
account.getXmppConnection().sendPing();
this.scheduleWakeupCall(2, false);
}
@@ -370,8 +366,8 @@ public class XmppConnectionService extends Service {
new Thread(account.getXmppConnection()).start();
} else if ((account.getStatus() == Account.STATUS_CONNECTING)
&& ((SystemClock.elapsedRealtime() - account
- .getXmppConnection().getLastConnect()) / 1000 >= CONNECT_TIMEOUT)) {
- Log.d(LOGTAG, account.getJid()
+ .getXmppConnection().getLastConnect()) / 1000 >= Config.CONNECT_TIMEOUT)) {
+ Log.d(Config.LOGTAG, account.getJid()
+ ": time out during connect reconnecting");
reconnectAccount(account, true);
} else {
@@ -380,7 +376,7 @@ public class XmppConnectionService extends Service {
}
}
// in any case. reschedule wakup call
- this.scheduleWakeupCall(PING_MAX_INTERVAL, true);
+ this.scheduleWakeupCall(Config.PING_MAX_INTERVAL, true);
}
if (mOnAccountUpdate != null) {
mOnAccountUpdate.onAccountUpdate();
@@ -450,7 +446,7 @@ public class XmppConnectionService extends Service {
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, EventReceiver.class);
alarmManager.cancel(PendingIntent.getBroadcast(context, 0, intent, 0));
- Log.d(LOGTAG, "good bye");
+ Log.d(Config.LOGTAG, "good bye");
stopSelf();
}
@@ -673,10 +669,10 @@ public class XmppConnectionService extends Service {
public void fetchRosterFromServer(Account account) {
IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
if (!"".equals(account.getRosterVersion())) {
- Log.d(LOGTAG, account.getJid() + ": fetching roster version "
- + account.getRosterVersion());
+ Log.d(Config.LOGTAG, account.getJid()
+ + ": fetching roster version " + account.getRosterVersion());
} else {
- Log.d(LOGTAG, account.getJid() + ": fetching roster");
+ Log.d(Config.LOGTAG, account.getJid() + ": fetching roster");
}
iqPacket.query("jabber:iq:roster").setAttribute("ver",
account.getRosterVersion());
@@ -1006,7 +1002,8 @@ public class XmppConnectionService extends Service {
XmppConnection connection = account.getXmppConnection();
if (connection != null && connection.getFeatures().csi()) {
connection.sendActive();
- Log.d(LOGTAG, account.getJid() + " sending csi//active");
+ Log.d(Config.LOGTAG, account.getJid()
+ + " sending csi//active");
}
}
}
@@ -1018,7 +1015,8 @@ public class XmppConnectionService extends Service {
XmppConnection connection = account.getXmppConnection();
if (connection != null && connection.getFeatures().csi()) {
connection.sendInactive();
- Log.d(LOGTAG, account.getJid() + " sending csi//inactive");
+ Log.d(Config.LOGTAG, account.getJid()
+ + " sending csi//inactive");
}
}
}
@@ -1040,7 +1038,7 @@ public class XmppConnectionService extends Service {
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.STATUS_ONLINE) {
- Log.d(LOGTAG,
+ Log.d(Config.LOGTAG,
"joining conversation " + conversation.getContactJid());
String nick = conversation.getMucOptions().getProposedNick();
conversation.getMucOptions().setJoinNick(nick);
@@ -1142,8 +1140,8 @@ public class XmppConnectionService extends Service {
sendPresencePacket(conversation.getAccount(), packet);
conversation.getMucOptions().setOffline();
conversation.deregisterWithBookmark();
- Log.d(LOGTAG, conversation.getAccount().getJid() + " leaving muc "
- + conversation.getContactJid());
+ Log.d(Config.LOGTAG, conversation.getAccount().getJid()
+ + " leaving muc " + conversation.getContactJid());
} else {
account.pendingConferenceLeaves.add(conversation);
}
@@ -1184,7 +1182,6 @@ public class XmppConnectionService extends Service {
pushContactToServer(contact);
}
if (contact.getOption(Contact.Options.DIRTY_DELETE)) {
- Log.d(LOGTAG, "dirty delete");
deleteContactOnServer(contact);
}
}
@@ -1204,9 +1201,10 @@ public class XmppConnectionService extends Service {
Account account = conversation.getAccount();
List<Message> messages = conversation.getMessages();
Session otrSession = conversation.getOtrSession();
- Log.d(LOGTAG, account.getJid() + " otr session established with "
- + conversation.getContactJid() + "/"
- + otrSession.getSessionID().getUserID());
+ Log.d(Config.LOGTAG,
+ account.getJid() + " otr session established with "
+ + conversation.getContactJid() + "/"
+ + otrSession.getSessionID().getUserID());
for (int i = 0; i < messages.size(); ++i) {
Message msg = messages.get(i);
if ((msg.getStatus() == Message.STATUS_UNSEND || msg.getStatus() == Message.STATUS_WAITING)
@@ -1280,8 +1278,8 @@ public class XmppConnectionService extends Service {
public void publishAvatar(Account account, Uri image,
final UiCallback<Avatar> callback) {
- final Bitmap.CompressFormat format = Defaults.AVATAR_FORMAT;
- final int size = Defaults.AVATAR_SIZE;
+ final Bitmap.CompressFormat format = Config.AVATAR_FORMAT;
+ final int size = Config.AVATAR_SIZE;
final Avatar avatar = getFileBackend()
.getPepAvatar(image, size, format);
if (avatar != null) {
@@ -1341,7 +1339,7 @@ public class XmppConnectionService extends Service {
public void fetchAvatar(Account account, final Avatar avatar,
final UiCallback<Avatar> callback) {
- Log.d(LOGTAG, account.getJid() + ": retrieving avatar for "
+ Log.d(Config.LOGTAG, account.getJid() + ": retrieving avatar for "
+ avatar.owner);
IqPacket packet = this.mIqGenerator.retrieveAvatar(avatar);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@@ -1439,7 +1437,8 @@ public class XmppConnectionService extends Service {
}
Thread thread = new Thread(account.getXmppConnection());
thread.start();
- scheduleWakeupCall((int) (CONNECT_TIMEOUT * 1.2), false);
+ scheduleWakeupCall((int) (Config.CONNECT_TIMEOUT * 1.2),
+ false);
}
}
}).start();