aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-25 22:39:01 +0100
committerChristian Schneppe <christian@pix-art.de>2019-01-25 22:39:01 +0100
commit55c83afb676e5d4c5d2fe58132dceeefa7e9ee71 (patch)
treeed7118ba9243d53df4e20bd4ec7add8423460d18 /src/main/java/de/pixart/messenger/services
parentc9d9e7ea8114b7a23cfa46fcafa1b3e491bc33b4 (diff)
stop file watching when service has been destroyed
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java14
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() {