Skip to content

Commit

Permalink
Backend: expose server name and last error
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0rg committed Apr 15, 2020
1 parent 5a483c1 commit 5f95152
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/org/yaxim/androidclient/data/YaximConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,11 @@ public String getPushNodeId() {
}
return pushNodeId;
}

/** return the hostname / service domain used for connection purposes */
public String getServerHost() {
if (TextUtils.isEmpty(customServer))
return server;
else return customServer;
}
}
15 changes: 13 additions & 2 deletions src/org/yaxim/androidclient/service/SmackableImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public class SmackableImp implements Smackable {
private ConnectionState mRequestedState = ConnectionState.OFFLINE;
private ConnectionState mState = ConnectionState.OFFLINE;
private String mLastError;
private Exception mLastLoginError; // StanzaError for IBR, SASLErrorException for login issues
private long mLastOnline = 0; //< timestamp of last successful full login (XEP-0198 does not count)
private long mLastOffline = 0; //< timestamp of the end of last successful login

Expand Down Expand Up @@ -389,7 +390,7 @@ public void fetchMam() {
for (Message m : mq.getPage().getMamResultCarrierMessages())
processMessage(m, true);
}
mLastError = "99%";
mLastError = "";
updateConnectionState(ConnectionState.LOADING);
// TODO: use "connected" logo, not hollow one
mServiceCallBack.displayPendingNotifications(null);
Expand Down Expand Up @@ -491,6 +492,7 @@ public synchronized void requestConnectionState(ConnectionState new_state, final
// update state before starting thread to prevent race conditions
updateConnectionState(ConnectionState.CONNECTING);

mLastLoginError = null;
// register ping (connection) timeout handler: 2*PACKET_TIMEOUT(30s) + 3s
registerPongTimeout(2*PACKET_TIMEOUT + 3000, "connection");

Expand Down Expand Up @@ -622,8 +624,10 @@ public long getConnectionStateTimestamp() {

// called at the end of a state transition
private synchronized void updateConnectionState(ConnectionState new_state) {
if (new_state == ConnectionState.ONLINE || new_state == ConnectionState.RECONNECT_NETWORK)
if (new_state == ConnectionState.ONLINE || new_state == ConnectionState.RECONNECT_NETWORK) {
mLastError = null;
mLastLoginError = null;
}
Log.d(TAG, "updateConnectionState: " + mState + " -> " + new_state + " (" + mLastError + ")");
if (new_state == mState && mState != ConnectionState.LOADING)
return;
Expand Down Expand Up @@ -768,6 +772,9 @@ private void onDisconnected(Throwable reason) {
onDisconnected(se.getCondition() + " " + se.getDescriptiveText());
return;
}
if (reason instanceof XMPPException || reason instanceof SmackException) {
mLastLoginError = (Exception)reason;
}
// iterate through to the deepest exception
while (reason.getCause() != null && !(reason.getCause().getClass().getSimpleName().equals("GaiException")))
reason = reason.getCause();
Expand Down Expand Up @@ -2358,6 +2365,10 @@ public String getLastError() {
return mLastError;
}

public Exception getLastLoginError() {
return mLastLoginError;
}

public synchronized void updateNickname() {
mConfig.nickchange_required = false;
new Thread("updateNickname " + mConfig.screenName) {
Expand Down

0 comments on commit 5f95152

Please sign in to comment.