diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2019-04-19 12:02:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-19 12:02:25 +0200 |
commit | 017a6ab3bcb2dede3b997528ad2bbe83bf724401 (patch) | |
tree | 136d1c9637612fe9fd6533231f503dd4c0e3a545 /core/src/main | |
parent | f4de370f1787e6c8ebef57c91205f668ee17fc43 (diff) | |
parent | 949a05c17a02b1d5d080a5792b8ac8f8bd8465e2 (diff) | |
download | AntennaPod-017a6ab3bcb2dede3b997528ad2bbe83bf724401.zip |
Merge pull request #2957 from orionlee/bugfix_app_anr_in_auto_feed_update_2956
Prevent app crash during some automatic feed update
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java index afaf13390..a0195975f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java @@ -17,15 +17,20 @@ public class FeedUpdateUtils { private FeedUpdateUtils() {} public static void startAutoUpdate(Context context, Runnable callback) { - try { - with().pollInterval(1, TimeUnit.SECONDS) - .await() - .atMost(10, TimeUnit.SECONDS) - .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()); - DBTasks.refreshAllFeeds(context, null, callback); - } catch (ConditionTimeoutException ignore) { - Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); - } + // the network check is blocking for possibly a long time: so run the logic + // in a separate thread to prevent the code blocking the callers + final Runnable runnable = () -> { + try { + with().pollInterval(1, TimeUnit.SECONDS) + .await() + .atMost(10, TimeUnit.SECONDS) + .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()); + DBTasks.refreshAllFeeds(context, null, callback); + } catch (ConditionTimeoutException ignore) { + Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); + } + }; + new Thread(runnable).start(); } } |