Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
tweak reconnection code
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironrabbit committed Nov 30, 2018
1 parent 0f2b39c commit 0d0ecf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4045,7 +4045,8 @@ private void reconnect() {
}

@Override
protected void setState(int state, ImErrorInfo error) {
protected void
setState(int state, ImErrorInfo error) {
debug(TAG, "setState to " + state);
super.setState(state, error);

Expand Down Expand Up @@ -4192,6 +4193,7 @@ private void initServiceDiscovery() {

mPingManager = PingManager.getInstanceFor(mConnection);
mPingManager.setPingInterval(60);

mPingManager.pingServerIfNecessary();
mPingManager.registerPingFailedListener(new PingFailedListener() {
@Override
Expand All @@ -4201,14 +4203,15 @@ public void pingFailed() {
}
});

/**
if (mReconnectionManager != null) {
mReconnectionManager.abortPossiblyRunningReconnection();
mReconnectionManager.disableAutomaticReconnection();
}
}**/

mReconnectionManager = ReconnectionManager.getInstanceFor(mConnection);

mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.RANDOM_INCREASING_DELAY);
mReconnectionManager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
mReconnectionManager.addReconnectionListener(new ReconnectionListener() {
@Override
public void reconnectingIn(int i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,12 @@ private Notification getForegroundNotification() {
.setContentTitle(getString(R.string.app_name))
.setSmallIcon(R.drawable.notify_zom);

mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE);
mNotifyBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
mNotifyBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mNotifyBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
mNotifyBuilder.setOngoing(true);
mNotifyBuilder.setWhen(System.currentTimeMillis());

mNotifyBuilder.setTicker("Zom service restarted at: " + new Date().toLocaleString());

Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

Expand All @@ -331,7 +332,7 @@ private Notification getForegroundNotification() {

}

public void sendHeartbeat() {
public synchronized void sendHeartbeat() {
Debug.onHeartbeat();
try {
if (mNeedCheckAutoLogin && mNetworkState != NetworkConnectivityReceiver.State.NOT_CONNECTED) {
Expand All @@ -346,6 +347,7 @@ public void sendHeartbeat() {
{
conn.sendHeartbeat();
}

} finally {
return;
}
Expand Down

0 comments on commit 0d0ecf4

Please sign in to comment.