Search in sources :

Example 1 with BackgroundMessageRetriever

use of org.thoughtcrime.securesms.messages.BackgroundMessageRetriever in project Signal-Android by WhisperSystems.

the class FcmJobService method onStartJob.

@Override
public boolean onStartJob(JobParameters params) {
    Log.d(TAG, "onStartJob()");
    if (BackgroundMessageRetriever.shouldIgnoreFetch()) {
        Log.i(TAG, "App is foregrounded. No need to run.");
        return false;
    }
    SignalExecutors.UNBOUNDED.execute(() -> {
        Context context = getApplicationContext();
        BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever();
        boolean success = retriever.retrieveMessages(context, new RestStrategy(), new RestStrategy());
        if (success) {
            Log.i(TAG, "Successfully retrieved messages.");
            jobFinished(params, false);
        } else {
            Log.w(TAG, "Failed to retrieve messages. Scheduling a retry.");
            jobFinished(params, true);
        }
    });
    return true;
}
Also used : Context(android.content.Context) BackgroundMessageRetriever(org.thoughtcrime.securesms.messages.BackgroundMessageRetriever) RestStrategy(org.thoughtcrime.securesms.messages.RestStrategy)

Example 2 with BackgroundMessageRetriever

use of org.thoughtcrime.securesms.messages.BackgroundMessageRetriever in project Signal-Android by WhisperSystems.

the class FcmFetchService method retrieveMessages.

static void retrieveMessages(@NonNull Context context) {
    BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever();
    boolean success = retriever.retrieveMessages(context, new RestStrategy(), new RestStrategy());
    if (success) {
        Log.i(TAG, "Successfully retrieved messages.");
    } else {
        if (Build.VERSION.SDK_INT >= 26) {
            Log.w(TAG, "Failed to retrieve messages. Scheduling on the system JobScheduler (API " + Build.VERSION.SDK_INT + ").");
            FcmJobService.schedule(context);
        } else {
            Log.w(TAG, "Failed to retrieve messages. Scheduling on JobManager (API " + Build.VERSION.SDK_INT + ").");
            ApplicationDependencies.getJobManager().add(new PushNotificationReceiveJob());
        }
    }
}
Also used : PushNotificationReceiveJob(org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob) BackgroundMessageRetriever(org.thoughtcrime.securesms.messages.BackgroundMessageRetriever) RestStrategy(org.thoughtcrime.securesms.messages.RestStrategy)

Example 3 with BackgroundMessageRetriever

use of org.thoughtcrime.securesms.messages.BackgroundMessageRetriever in project Signal-Android by WhisperSystems.

the class PushNotificationReceiveJob method onRun.

@Override
public void onRun() throws IOException {
    BackgroundMessageRetriever retriever = ApplicationDependencies.getBackgroundMessageRetriever();
    boolean result = retriever.retrieveMessages(context, foregroundServiceDelayMs, new RestStrategy());
    if (result) {
        Log.i(TAG, "Successfully pulled messages.");
    } else {
        throw new PushNetworkException("Failed to pull messages.");
    }
}
Also used : PushNetworkException(org.whispersystems.signalservice.api.push.exceptions.PushNetworkException) BackgroundMessageRetriever(org.thoughtcrime.securesms.messages.BackgroundMessageRetriever) RestStrategy(org.thoughtcrime.securesms.messages.RestStrategy)

Aggregations

BackgroundMessageRetriever (org.thoughtcrime.securesms.messages.BackgroundMessageRetriever)3 RestStrategy (org.thoughtcrime.securesms.messages.RestStrategy)3 Context (android.content.Context)1 PushNotificationReceiveJob (org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob)1 PushNetworkException (org.whispersystems.signalservice.api.push.exceptions.PushNetworkException)1