diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/XmppConnectionService.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 43fd2f875..c332bfae4 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -336,6 +336,7 @@ public class XmppConnectionService extends Service { syncDirtyContacts(account); } }; + private boolean destroyed = false; private int unreadCount = -1; private AtomicLong mLastExpiryRun = new AtomicLong(0); private SecureRandom mRandom; @@ -1116,6 +1117,7 @@ public class XmppConnectionService extends Service { @SuppressLint("TrulyRandom") @Override public void onCreate() { + this.destroyed = false; OmemoSetting.load(this); ExceptionHelper.init(getApplicationContext()); try { @@ -1160,7 +1162,7 @@ public class XmppConnectionService extends Service { } if (Compatibility.hasStoragePermission(this)) { Log.d(Config.LOGTAG, "starting file observer"); - new Thread(fileObserver::startWatching).start(); + mFileAddingExecutor.execute(this.fileObserver::startWatching); mFileAddingExecutor.execute(this::checkForDeletedFiles); } if (Config.supportOpenPgp()) { @@ -1203,9 +1205,17 @@ public class XmppConnectionService extends Service { } private void checkForDeletedFiles() { + if (destroyed) { + Log.d(Config.LOGTAG, "Do not check for deleted files because service has been destroyed"); + return; + } final List<String> deletedUuids = new ArrayList<>(); final List<DatabaseBackend.FilePath> relativeFilePaths = databaseBackend.getAllNonDeletedFilePath(); for (final DatabaseBackend.FilePath filePath : relativeFilePaths) { + if (destroyed) { + Log.d(Config.LOGTAG, "Stop checking for deleted files because service has been destroyed"); + return; + } final File file = fileBackend.getFileForPath(filePath.path); if (!file.exists()) { deletedUuids.add(filePath.uuid.toString()); @@ -1254,8 +1264,8 @@ public class XmppConnectionService extends Service { public void restartFileObserver() { Log.d(Config.LOGTAG, "restarting file observer"); + mFileAddingExecutor.execute(this.fileObserver::restartWatching); mFileAddingExecutor.execute(this::checkForDeletedFiles); - new Thread(fileObserver::restartWatching).start(); } public void toggleScreenEventReceiver() { |