Skip to content

Commit

Permalink
Fix websocket service crashing when trying to reconnect while there i…
Browse files Browse the repository at this point in the history
…s no connection. Fix for displaying the wrong status message when there is no connection while using websocket.
  • Loading branch information
freeflyk committed May 13, 2024
1 parent 5fb4555 commit b64b713
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.polar.nextcloudservices.Services;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
Expand Down Expand Up @@ -134,7 +133,9 @@ public void onWebsocketConnected() {

@Override
public String getStatus() {
if(mNotificationWebsocket == null && mWsThread.isAlive()){
if(!mConnectionController.checkConnection(this)){
return "Disconnected: no suitable network found";
}else if(mNotificationWebsocket == null && mWsThread.isAlive()){
return "Disconnected: can not connect to websocket. Are login details correct? Is notify_push installed on server?";
}else if(mNotificationWebsocket == null && !mWsThread.isAlive()){
mWsThread = new Thread(this::listenForever);
Expand All @@ -152,15 +153,14 @@ private void safeCloseWebsocket(){

@Override
public void onPreferencesChanged() {
safeCloseWebsocket();
if(!mServiceSettings.isWebsocketEnabled()){
Log.i(TAG, "Websocket is no more enabled. Disconnecting websocket and stopping service");
safeCloseWebsocket();
stopForeground(true);
}else{
Log.i(TAG, "Preferences changed. Re-connecting to websocket.");
mAPI = mServiceSettings.getAPIFromSettings();
}
Log.i(TAG, "Preferences changed. Re-connecting to websocket.");
safeCloseWebsocket();
mAPI = mServiceSettings.getAPIFromSettings();
startListening();
}

@Override
Expand Down

0 comments on commit b64b713

Please sign in to comment.