cleaner/better logging

This commit is contained in:
Daniel Gultsch 2014-03-11 16:27:33 +01:00
parent 0d516b0603
commit 838270432f
2 changed files with 13 additions and 13 deletions

View file

@ -69,7 +69,7 @@ public class XmppConnectionService extends Service {
public long startDate; public long startDate;
private static final int PING_MAX_INTERVAL = 30; private static final int PING_MAX_INTERVAL = 300;
private static final int PING_MIN_INTERVAL = 10; private static final int PING_MIN_INTERVAL = 10;
private static final int PING_TIMEOUT = 2; private static final int PING_TIMEOUT = 2;
@ -201,7 +201,6 @@ public class XmppConnectionService extends Service {
} }
scheduleWakeupCall(PING_MAX_INTERVAL, true); scheduleWakeupCall(PING_MAX_INTERVAL, true);
} else if (account.getStatus() == Account.STATUS_OFFLINE) { } else if (account.getStatus() == Account.STATUS_OFFLINE) {
Log.d(LOGTAG, "onStatusChanged offline");
databaseBackend.clearPresences(account); databaseBackend.clearPresences(account);
if (!account.isOptionSet(Account.OPTION_DISABLED)) { if (!account.isOptionSet(Account.OPTION_DISABLED)) {
int timeToReconnect = mRandom.nextInt(50) + 10; int timeToReconnect = mRandom.nextInt(50) + 10;
@ -493,7 +492,7 @@ public class XmppConnectionService extends Service {
this.pendingPingIntent = PendingIntent.getBroadcast(context, 0, this.pendingPingIntent = PendingIntent.getBroadcast(context, 0,
this.pingIntent, 0); this.pingIntent, 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,timeToWake, pendingPingIntent); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,timeToWake, pendingPingIntent);
Log.d(LOGTAG,"schedule ping in "+seconds+" seconds"); //Log.d(LOGTAG,"schedule ping in "+seconds+" seconds");
} else { } else {
long scheduledTime = this.pingIntent.getLongExtra("time", 0); long scheduledTime = this.pingIntent.getLongExtra("time", 0);
if (scheduledTime<SystemClock.elapsedRealtime() || (scheduledTime > timeToWake)) { if (scheduledTime<SystemClock.elapsedRealtime() || (scheduledTime > timeToWake)) {
@ -502,7 +501,7 @@ public class XmppConnectionService extends Service {
this.pendingPingIntent = PendingIntent.getBroadcast(context, 0, this.pendingPingIntent = PendingIntent.getBroadcast(context, 0,
this.pingIntent, 0); this.pingIntent, 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,timeToWake, pendingPingIntent); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,timeToWake, pendingPingIntent);
Log.d(LOGTAG,"reschedule old ping to ping in "+seconds+" seconds"); //Log.d(LOGTAG,"reschedule old ping to ping in "+seconds+" seconds");
} }
} }
} else { } else {
@ -1078,13 +1077,13 @@ public class XmppConnectionService extends Service {
public void run() { public void run() {
account.getXmppConnection().disconnect(false); account.getXmppConnection().disconnect(false);
Log.d(LOGTAG, "disconnected account: " + account.getJid()); Log.d(LOGTAG, "disconnected account: " + account.getJid());
account.setXmppConnection(null); //account.setXmppConnection(null);
} }
}).start(); }).start();
} else { } else {
account.getXmppConnection().disconnect(false); account.getXmppConnection().disconnect(false);
Log.d(LOGTAG, "disconnected account: " + account.getJid()); Log.d(LOGTAG, "disconnected account: " + account.getJid());
account.setXmppConnection(null); //account.setXmppConnection(null);
} }
} }
} }

View file

@ -95,14 +95,16 @@ public class XmppConnection implements Runnable {
} }
protected void changeStatus(int nextStatus) { protected void changeStatus(int nextStatus) {
if (account.getStatus() != nextStatus) {
account.setStatus(nextStatus); account.setStatus(nextStatus);
if (statusListener != null) { if (statusListener != null) {
statusListener.onStatusChanged(account); statusListener.onStatusChanged(account);
} }
} }
}
protected void connect() { protected void connect() {
Log.d(LOGTAG, "connecting"); Log.d(LOGTAG,account.getJid()+ ": connecting");
try { try {
tagReader = new XmlReader(wakeLock); tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter(); tagWriter = new TagWriter();
@ -165,7 +167,6 @@ public class XmppConnection implements Runnable {
@Override @Override
public void run() { public void run() {
connect(); connect();
Log.d(LOGTAG, "end run");
} }
private void processStream(Tag currentTag) throws XmlPullParserException, private void processStream(Tag currentTag) throws XmlPullParserException,
@ -598,10 +599,10 @@ public class XmppConnection implements Runnable {
public void sendPing() { public void sendPing() {
if (streamFeatures.hasChild("sm")) { if (streamFeatures.hasChild("sm")) {
Log.d(LOGTAG,"sending r as ping"); Log.d(LOGTAG,account.getJid()+": sending r as ping");
tagWriter.writeStanzaAsync(new RequestPacket()); tagWriter.writeStanzaAsync(new RequestPacket());
} else { } else {
Log.d(LOGTAG,"sending iq as ping"); Log.d(LOGTAG,account.getJid()+": sending iq as ping");
IqPacket iq = new IqPacket(IqPacket.TYPE_GET); IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
Element ping = new Element("ping"); Element ping = new Element("ping");
iq.setAttribute("from",account.getFullJid()); iq.setAttribute("from",account.getFullJid());