mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-11 11:45:01 -05:00
fixed #53 aka server not found bug
This commit is contained in:
parent
66aacf7e3e
commit
0cdd74417f
@ -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) {
|
||||||
|
@ -242,10 +242,17 @@ 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) {
|
||||||
UIHelper.showErrorNotification(getApplicationContext(),
|
int next = account.getXmppConnection().getTimeToNextAttempt();
|
||||||
getAccounts());
|
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(),
|
||||||
|
getAccounts());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -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 {
|
||||||
@ -829,16 +826,16 @@ public class XmppConnectionService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resendMessage(Message message) {
|
private void resendMessage(Message message) {
|
||||||
Account account = message.getConversation().getAccount();
|
Account account = message.getConversation().getAccount();
|
||||||
MessagePacket packet = null;
|
MessagePacket packet = null;
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
|
||||||
packet = prepareMessagePacket(account, message,null);
|
packet = prepareMessagePacket(account, message, null);
|
||||||
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
packet = prepareMessagePacket(account, message, null);
|
packet = prepareMessagePacket(account, message, null);
|
||||||
packet.setBody("This is an XEP-0027 encryted message");
|
packet.setBody("This is an XEP-0027 encryted message");
|
||||||
if (message.getEncryptedBody()==null) {
|
if (message.getEncryptedBody() == null) {
|
||||||
markMessage(message, Message.STATUS_SEND_FAILED);
|
markMessage(message, Message.STATUS_SEND_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -850,7 +847,7 @@ public class XmppConnectionService extends Service {
|
|||||||
packet.addChild("x", "jabber:x:encrypted").setContent(
|
packet.addChild("x", "jabber:x:encrypted").setContent(
|
||||||
message.getBody());
|
message.getBody());
|
||||||
}
|
}
|
||||||
if (packet!=null) {
|
if (packet != null) {
|
||||||
account.getXmppConnection().sendMessagePacket(packet);
|
account.getXmppConnection().sendMessagePacket(packet);
|
||||||
markMessage(message, Message.STATUS_SEND);
|
markMessage(message, Message.STATUS_SEND);
|
||||||
}
|
}
|
||||||
@ -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(
|
||||||
@ -1492,8 +1487,9 @@ 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);
|
||||||
|
@ -88,6 +88,8 @@ public class XmppConnection implements Runnable {
|
|||||||
public long lastPingSent = 0;
|
public long lastPingSent = 0;
|
||||||
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;
|
||||||
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user