session-android/src/org/thoughtcrime/securesms/jobs/PushNotificationReceiveJob.java
Greyson Parrelli 42f1baaf61 Imported JobManager as a source dependency.
We have to make some changes, and it's gotten to the point where
maintaining it as a separate library is more hassle than it's worth,
especially with Google releasing WorkManager as the preferred job
scheduling library.
2018-06-22 10:59:53 -07:00

56 lines
1.8 KiB
Java

package org.thoughtcrime.securesms.jobs;
import android.content.Context;
import android.util.Log;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.jobmanager.JobParameters;
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
public class PushNotificationReceiveJob extends PushReceivedJob implements InjectableType {
private static final String TAG = PushNotificationReceiveJob.class.getSimpleName();
@Inject transient SignalServiceMessageReceiver receiver;
public PushNotificationReceiveJob(Context context) {
super(context, JobParameters.newBuilder()
.withRequirement(new NetworkRequirement(context))
.withGroupId("__notification_received")
.withWakeLock(true, 30, TimeUnit.SECONDS).create());
}
@Override
public void onAdded() {}
@Override
public void onRun() throws IOException {
receiver.retrieveMessages(new SignalServiceMessageReceiver.MessageReceivedCallback() {
@Override
public void onMessage(SignalServiceEnvelope envelope) {
handle(envelope);
}
});
}
@Override
public boolean onShouldRetry(Exception e) {
Log.w(TAG, e);
return e instanceof PushNetworkException;
}
@Override
public void onCanceled() {
Log.w(TAG, "***** Failed to download pending message!");
// MessageNotifier.notifyMessagesPending(getContext());
}
}