From a58de2278ba1c64fbea455ed9089df064b074b0d Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 9 Jan 2025 18:36:12 +0100 Subject: [PATCH 1/3] use synchronized block to avoid IllegalMonitorStateException --- .../securesms/service/FetchForegroundService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java index 47b93b4d8..5481ca8f2 100644 --- a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java +++ b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java @@ -53,7 +53,9 @@ public static void start(Context context) { try { // The `wait()` needs to be enclosed in a while loop because there may be // "spurious wake-ups", i.e. `wait()` may return even though `notifyAll()` wasn't called. - STOP_NOTIFIER.wait(); + synchronized (STOP_NOTIFIER) { + STOP_NOTIFIER.wait(); + } } catch (InterruptedException ex) { } } } @@ -63,7 +65,9 @@ public static void start(Context context) { public static void stop(Context context) { if (fetchingSynchronously) { fetchingSynchronously = false; - STOP_NOTIFIER.notifyAll(); + synchronized (STOP_NOTIFIER) { + STOP_NOTIFIER.notifyAll(); + } } synchronized (SERVICE_LOCK) { From 66fd795763fcec2f48c124261edfcf4f2ea25d54 Mon Sep 17 00:00:00 2001 From: adbenitez Date: Thu, 9 Jan 2025 19:06:15 +0100 Subject: [PATCH 2/3] try to fix CI --- .github/workflows/preview-apk.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-apk.yml b/.github/workflows/preview-apk.yml index cc509841f..e297073fe 100644 --- a/.github/workflows/preview-apk.yml +++ b/.github/workflows/preview-apk.yml @@ -49,7 +49,7 @@ jobs: run: ./gradlew --no-daemon assembleGplayDebug - name: Upload APK - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: app-preview.apk path: 'build/outputs/apk/gplay/debug/*.apk' From 35339161496626077da238460f215e673f54498a Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 10 Jan 2025 11:05:44 +0100 Subject: [PATCH 3/3] Put the `synchronized` around the whole while loop --- .../securesms/service/FetchForegroundService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java index 5481ca8f2..341559663 100644 --- a/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java +++ b/src/main/java/org/thoughtcrime/securesms/service/FetchForegroundService.java @@ -49,14 +49,14 @@ public static void start(Context context) { // The background fetch was successful, but we need to wait until all events were processed. // After all events were processed, we will get DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE, // and stop() will be called. - while (fetchingSynchronously) { - try { - // The `wait()` needs to be enclosed in a while loop because there may be - // "spurious wake-ups", i.e. `wait()` may return even though `notifyAll()` wasn't called. - synchronized (STOP_NOTIFIER) { + synchronized (STOP_NOTIFIER) { + while (fetchingSynchronously) { + try { + // The `wait()` needs to be enclosed in a while loop because there may be + // "spurious wake-ups", i.e. `wait()` may return even though `notifyAll()` wasn't called. STOP_NOTIFIER.wait(); - } - } catch (InterruptedException ex) { } + } catch (InterruptedException ex) {} + } } } }