fixed #53 aka server not found bug

This commit is contained in:
Daniel Gultsch 2014-05-18 11:25:04 +02:00
parent 66aacf7e3e
commit 0cdd74417f
3 changed files with 39 additions and 27 deletions

View file

@ -135,7 +135,7 @@ public class Account extends AbstractEntity{
} }
public boolean hasErrorStatus() { public boolean hasErrorStatus() {
return getStatus() > STATUS_NO_INTERNET; return getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
} }
public void setResource(String resource) { public void setResource(String resource) {

View file

@ -242,11 +242,18 @@ public class XmppConnectionService extends Service {
} else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) { } else if (account.getStatus() == Account.STATUS_REGISTRATION_SUCCESSFULL) {
databaseBackend.updateAccount(account); databaseBackend.updateAccount(account);
reconnectAccount(account, true); reconnectAccount(account, true);
} else { } else if (account.getStatus() != Account.STATUS_CONNECTING) {
int next = account.getXmppConnection().getTimeToNextAttempt();
Log.d(LOGTAG, account.getJid()
+ ": error connecting account. try again in " + next
+ "s for the "
+ (account.getXmppConnection().getAttempt() + 1)
+ " time");
scheduleWakeupCall(next, false);
}
UIHelper.showErrorNotification(getApplicationContext(), UIHelper.showErrorNotification(getApplicationContext(),
getAccounts()); getAccounts());
} }
}
}; };
private OnPresencePacketReceived presenceListener = new OnPresencePacketReceived() { private OnPresencePacketReceived presenceListener = new OnPresencePacketReceived() {
@ -576,8 +583,6 @@ public class XmppConnectionService extends Service {
statusListener.onStatusChanged(account); statusListener.onStatusChanged(account);
} }
} }
// TODO 3 remaining cases
if (account.getStatus() == Account.STATUS_ONLINE) { if (account.getStatus() == Account.STATUS_ONLINE) {
long lastReceived = account.getXmppConnection().lastPaketReceived; long lastReceived = account.getXmppConnection().lastPaketReceived;
long lastSent = account.getXmppConnection().lastPingSent; long lastSent = account.getXmppConnection().lastPingSent;
@ -605,15 +610,9 @@ public class XmppConnectionService extends Service {
+ ": time out during connect reconnecting"); + ": time out during connect reconnecting");
reconnectAccount(account, true); reconnectAccount(account, true);
} else { } else {
Log.d(LOGTAG, if (account.getXmppConnection().getTimeToNextAttempt() <= 0) {
"seconds since last connect:" reconnectAccount(account, true);
+ ((SystemClock.elapsedRealtime() - account }
.getXmppConnection().lastConnect) / 1000));
Log.d(LOGTAG,
account.getJid() + ": status="
+ account.getStatus());
// TODO notify user of ssl cert problem or auth problem
// or what ever
} }
// in any case. reschedule wakup call // in any case. reschedule wakup call
this.scheduleWakeupCall(PING_MAX_INTERVAL, true); this.scheduleWakeupCall(PING_MAX_INTERVAL, true);
@ -676,7 +675,6 @@ public class XmppConnectionService extends Service {
this.pingIntent, 0); this.pingIntent, 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
timeToWake, pendingPingIntent); timeToWake, pendingPingIntent);
// 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() if (scheduledTime < SystemClock.elapsedRealtime()
@ -687,7 +685,6 @@ public class XmppConnectionService extends Service {
context, 0, this.pingIntent, 0); context, 0, this.pingIntent, 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
timeToWake, pendingPingIntent); timeToWake, pendingPingIntent);
// Log.d(LOGTAG,"reschedule old ping to ping in "+seconds+" seconds");
} }
} }
} else { } else {
@ -1159,8 +1156,7 @@ public class XmppConnectionService extends Service {
if (accountChangedListener != null) { if (accountChangedListener != null) {
accountChangedListener.onAccountListChangedListener(); accountChangedListener.onAccountListChangedListener();
} }
UIHelper.showErrorNotification(getApplicationContext(), UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
getAccounts());
} }
public void deleteAccount(Account account) { public void deleteAccount(Account account) {
@ -1172,8 +1168,7 @@ public class XmppConnectionService extends Service {
if (accountChangedListener != null) { if (accountChangedListener != null) {
accountChangedListener.onAccountListChangedListener(); accountChangedListener.onAccountListChangedListener();
} }
UIHelper.showErrorNotification(getApplicationContext(), UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
getAccounts());
} }
public void setOnConversationListChangedListener( public void setOnConversationListChangedListener(
@ -1493,7 +1488,8 @@ public class XmppConnectionService extends Service {
return false; return false;
} }
public boolean markMessage(Conversation conversation, String uuid, int status) { public boolean markMessage(Conversation conversation, String uuid,
int status) {
for (Message message : conversation.getMessages()) { for (Message message : conversation.getMessages()) {
if (message.getUuid().equals(uuid)) { if (message.getUuid().equals(uuid)) {
markMessage(message, status); markMessage(message, status);

View file

@ -89,6 +89,8 @@ public class XmppConnection implements Runnable {
public long lastConnect = 0; public long lastConnect = 0;
public long lastSessionStarted = 0; public long lastSessionStarted = 0;
private int attempt = 0;
private static final int PACKET_IQ = 0; private static final int PACKET_IQ = 0;
private static final int PACKET_MESSAGE = 1; private static final int PACKET_MESSAGE = 1;
private static final int PACKET_PRESENCE = 2; private static final int PACKET_PRESENCE = 2;
@ -113,6 +115,9 @@ public class XmppConnection implements Runnable {
if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)&&(account.getStatus() != Account.STATUS_DISABLED)) { if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)&&(account.getStatus() != Account.STATUS_DISABLED)) {
return; return;
} }
if (nextStatus == Account.STATUS_ONLINE) {
this.attempt = 0;
}
account.setStatus(nextStatus); account.setStatus(nextStatus);
if (statusListener != null) { if (statusListener != null) {
statusListener.onStatusChanged(account); statusListener.onStatusChanged(account);
@ -123,6 +128,7 @@ public class XmppConnection implements Runnable {
protected void connect() { protected void connect() {
Log.d(LOGTAG,account.getJid()+ ": connecting"); Log.d(LOGTAG,account.getJid()+ ": connecting");
lastConnect = SystemClock.elapsedRealtime(); lastConnect = SystemClock.elapsedRealtime();
this.attempt++;
try { try {
shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER); shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock); tagReader = new XmlReader(wakeLock);
@ -916,4 +922,14 @@ public class XmppConnection implements Runnable {
Log.d(LOGTAG,"adding "+jid+" to pending subscriptions"); Log.d(LOGTAG,"adding "+jid+" to pending subscriptions");
this.pendingSubscriptions.add(jid); this.pendingSubscriptions.add(jid);
} }
public int getTimeToNextAttempt() {
int interval = (int) (25 * Math.pow(1.5,attempt));
int secondsSinceLast = (int) ((SystemClock.elapsedRealtime() - this.lastConnect) / 1000);
return interval - secondsSinceLast;
}
public int getAttempt() {
return this.attempt;
}
} }