<commit_before>package de.danoeh.antennapod.core.service;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

import androidx.work.Worker;
import androidx.work.WorkerParameters;

import org.awaitility.Awaitility;

import java.util.concurrent.atomic.AtomicBoolean;

import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.NetworkUtils;

public class FeedUpdateWorker extends Worker {

    private static final String TAG = "FeedUpdateWorker";

    public static final String PARAM_RUN_IMMEDIATE = "runImmediate";

    public FeedUpdateWorker(@NonNull Context context, @NonNull WorkerParameters params) {
        super(context, params);
    }

    @Override
    @NonNull
    public Result doWork() {
        final boolean isImmediate = getInputData() != null ?
                getInputData().getBoolean(PARAM_RUN_IMMEDIATE, false) : false;
        Log.d(TAG, "doWork() : isImmediate = " + isImmediate);
        ClientConfig.initialize(getApplicationContext());

        AtomicBoolean finished = new AtomicBoolean(false);
        if (NetworkUtils.networkAvailable() && NetworkUtils.isFeedRefreshAllowed()) {
            DBTasks.refreshAllFeeds(getApplicationContext(), null, () -> finished.set(true));
        } else {
            Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
        }
        Awaitility.await().until(finished::get);

        if (!isImmediate && UserPreferences.isAutoUpdateTimeOfDay()) {
            // WorkManager does not allow to set specific time for repeated tasks.
            // We repeatedly schedule a OneTimeWorkRequest instead.
            UserPreferences.restartUpdateAlarm();
        }

        return Result.success();
    }
}
<commit_msg>prevent deadlock in case auto feed update is blocked per review.<commit_after>package de.danoeh.antennapod.core.service;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

import androidx.work.Worker;
import androidx.work.WorkerParameters;

import org.awaitility.Awaitility;

import java.util.concurrent.atomic.AtomicBoolean;

import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.util.NetworkUtils;

public class FeedUpdateWorker extends Worker {

    private static final String TAG = "FeedUpdateWorker";

    public static final String PARAM_RUN_IMMEDIATE = "runImmediate";

    public FeedUpdateWorker(@NonNull Context context, @NonNull WorkerParameters params) {
        super(context, params);
    }

    @Override
    @NonNull
    public Result doWork() {
        final boolean isImmediate = getInputData() != null ?
                getInputData().getBoolean(PARAM_RUN_IMMEDIATE, false) : false;
        Log.d(TAG, "doWork() : isImmediate = " + isImmediate);
        ClientConfig.initialize(getApplicationContext());

        if (NetworkUtils.networkAvailable() && NetworkUtils.isFeedRefreshAllowed()) {
            AtomicBoolean finished = new AtomicBoolean(false);
            DBTasks.refreshAllFeeds(getApplicationContext(), null, () -> finished.set(true));
            Awaitility.await().until(finished::get);
        } else {
            Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed");
        }

        if (!isImmediate && UserPreferences.isAutoUpdateTimeOfDay()) {
            // WorkManager does not allow to set specific time for repeated tasks.
            // We repeatedly schedule a OneTimeWorkRequest instead.
            UserPreferences.restartUpdateAlarm();
        }

        return Result.success();
    }
}

{'fraction_non_alphanumeric': 0.09805950840879689, 'fraction_numerical': 0.0, 'mean_word_length': 3.474537037037037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3752966', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1061, 'n_words': 238}