2015-04-15 10:58:29 -07:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
2018-06-18 12:27:04 -07:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.requirements.NetworkRequirement;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.signalservice.api.SignalServiceMessageReceiver;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
|
|
|
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException;
|
2015-04-15 10:58:29 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2016-03-23 10:34:41 -07:00
|
|
|
@Inject transient SignalServiceMessageReceiver receiver;
|
2015-04-15 10:58:29 -07:00
|
|
|
|
|
|
|
public PushNotificationReceiveJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
2015-04-16 12:22:05 -07:00
|
|
|
.withGroupId("__notification_received")
|
2015-04-15 10:58:29 -07:00
|
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS).create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException {
|
2016-03-23 10:34:41 -07:00
|
|
|
receiver.retrieveMessages(new SignalServiceMessageReceiver.MessageReceivedCallback() {
|
2015-04-15 10:58:29 -07:00
|
|
|
@Override
|
2016-03-23 10:34:41 -07:00
|
|
|
public void onMessage(SignalServiceEnvelope envelope) {
|
2017-09-15 22:38:53 -07:00
|
|
|
handle(envelope);
|
2015-04-15 10:58:29 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
2015-06-11 09:43:34 -07:00
|
|
|
Log.w(TAG, e);
|
2015-04-15 10:58:29 -07:00
|
|
|
return e instanceof PushNetworkException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "***** Failed to download pending message!");
|
2017-06-20 10:57:11 -07:00
|
|
|
// MessageNotifier.notifyMessagesPending(getContext());
|
2015-04-15 10:58:29 -07:00
|
|
|
}
|
|
|
|
}
|