1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Add AuthenticatedConnectionInitiallyEstablished timestamp

This commit is contained in:
Florian Schmaus 2019-03-09 19:19:20 +01:00
parent c4289b2c18
commit 569f7417a8
2 changed files with 20 additions and 0 deletions

View file

@ -314,6 +314,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected boolean authenticated = false; protected boolean authenticated = false;
// TODO: Migrate to ZonedDateTime once Smack's minimum required Android SDK level is 26 (8.0, Oreo) or higher.
protected long authenticatedConnectionInitiallyEstablishedTimestamp;
/** /**
* Flag that indicates if the user was authenticated with the server when the connection * Flag that indicates if the user was authenticated with the server when the connection
* to the server was closed (abruptly or not). * to the server was closed (abruptly or not).
@ -590,6 +593,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException, InterruptedException { protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException, InterruptedException {
if (!resumed) {
authenticatedConnectionInitiallyEstablishedTimestamp = System.currentTimeMillis();
}
// Indicate that we're now authenticated. // Indicate that we're now authenticated.
this.authenticated = true; this.authenticated = true;
@ -1729,6 +1735,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return lastStanzaReceived; return lastStanzaReceived;
} }
/**
* Get the timestamp when the connection was the first time authenticated, i.e., when the first successful login was
* performed. Note that this value is not reset on disconnect, so it represents the timestamp from the last
* authenticated connection. The value is also not reset on stream resumption.
*
* @return the timestamp or {@code null}.
* @since 4.3.3
*/
public final long getAuthenticatedConnectionInitiallyEstablishedTimestamp() {
return authenticatedConnectionInitiallyEstablishedTimestamp;
}
/** /**
* Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a * Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a
* stanza. * stanza.

View file

@ -527,6 +527,8 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
// Reset the stream management session id to null, since if the stream is cleanly closed, i.e. sending a closing // Reset the stream management session id to null, since if the stream is cleanly closed, i.e. sending a closing
// stream tag, there is no longer a stream to resume. // stream tag, there is no longer a stream to resume.
smSessionId = null; smSessionId = null;
// Note that we deliberately do not reset authenticatedConnectionInitiallyEstablishedTimestamp here, so that the
// information is available in the connectionClosedOnError() listeners.
} }
authenticated = false; authenticated = false;
connected = false; connected = false;