support location attribute on enable

This commit is contained in:
Daniel Gultsch 2023-12-01 18:29:52 +01:00
parent a11d6638b0
commit f7b5124fd3
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -16,6 +16,7 @@ import android.util.SparseArray;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@ -165,7 +166,7 @@ public class XmppConnection implements Runnable {
private boolean isBound = false; private boolean isBound = false;
private Element streamFeatures; private Element streamFeatures;
private Element boundStreamFeatures; private Element boundStreamFeatures;
private String streamId = null; private StreamId streamId = null;
private int stanzasReceived = 0; private int stanzasReceived = 0;
private int stanzasSent = 0; private int stanzasSent = 0;
private int stanzasSentBeforeAuthentication; private int stanzasSentBeforeAuthentication;
@ -366,6 +367,12 @@ public class XmppConnection implements Runnable {
+ storedBackupResult); + storedBackupResult);
} }
} }
final StreamId streamId = this.streamId;
final Resolver.Result resumeLocation = streamId == null ? null : streamId.location;
if (resumeLocation != null) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": injected resume location on position 0");
results.add(0, resumeLocation);
}
final Resolver.Result seeOtherHost = this.seeOtherHostResolverResult; final Resolver.Result seeOtherHost = this.seeOtherHostResolverResult;
if (seeOtherHost != null) { if (seeOtherHost != null) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": injected see-other-host on position 0"); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": injected see-other-host on position 0");
@ -988,18 +995,27 @@ public class XmppConnection implements Runnable {
} }
private void processEnabled(final Element enabled) { private void processEnabled(final Element enabled) {
final String streamId; final String id;
if (enabled.getAttributeAsBoolean("resume")) { if (enabled.getAttributeAsBoolean("resume")) {
streamId = enabled.getAttribute("id"); id = enabled.getAttribute("id");
Log.d( } else {
Config.LOGTAG, id = null;
account.getJid().asBareJid().toString() }
+ ": stream management enabled (resumable)"); final String locationAttribute = enabled.getAttribute("location");
final Resolver.Result currentResolverResult = this.currentResolverResult;
final Resolver.Result location;
if (Strings.isNullOrEmpty(locationAttribute) || currentResolverResult == null) {
location = null;
} else {
location = currentResolverResult.seeOtherHost(locationAttribute);
}
final StreamId streamId = id == null ? null : new StreamId(id, location);
if (streamId == null) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": stream management enabled");
} else { } else {
Log.d( Log.d(
Config.LOGTAG, Config.LOGTAG,
account.getJid().asBareJid().toString() + ": stream management enabled"); account.getJid().asBareJid() + ": stream management enabled. resume at: " + streamId.location);
streamId = null;
} }
this.streamId = streamId; this.streamId = streamId;
this.stanzasReceived = 0; this.stanzasReceived = 0;
@ -1408,7 +1424,7 @@ public class XmppConnection implements Runnable {
+ ": resuming after stanza #" + ": resuming after stanza #"
+ stanzasReceived); + stanzasReceived);
} }
final ResumePacket resume = new ResumePacket(this.streamId, stanzasReceived); final ResumePacket resume = new ResumePacket(this.streamId.id, stanzasReceived);
this.mSmCatchupMessageCounter.set(0); this.mSmCatchupMessageCounter.set(0);
this.mWaitingForSmCatchup.set(true); this.mWaitingForSmCatchup.set(true);
this.tagWriter.writeStanzaAsync(resume); this.tagWriter.writeStanzaAsync(resume);
@ -1589,7 +1605,7 @@ public class XmppConnection implements Runnable {
authenticate.addChild(generateBindRequest(bind)); authenticate.addChild(generateBindRequest(bind));
} }
if (inlineStreamManagement && streamId != null) { if (inlineStreamManagement && streamId != null) {
final ResumePacket resume = new ResumePacket(this.streamId, stanzasReceived); final ResumePacket resume = new ResumePacket(this.streamId.id, stanzasReceived);
this.mSmCatchupMessageCounter.set(0); this.mSmCatchupMessageCounter.set(0);
this.mWaitingForSmCatchup.set(true); this.mWaitingForSmCatchup.set(true);
authenticate.addChild(resume); authenticate.addChild(resume);
@ -2674,6 +2690,25 @@ public class XmppConnection implements Runnable {
} }
} }
private static class StreamId {
public final String id;
public final Resolver.Result location;
private StreamId(String id, Resolver.Result location) {
this.id = id;
this.location = location;
}
@NonNull
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("location", location)
.toString();
}
}
private static class StateChangingError extends Error { private static class StateChangingError extends Error {
private final Account.State state; private final Account.State state;