2015-04-15 17:58:29 +00:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
|
|
|
import org.whispersystems.jobqueue.JobParameters;
|
|
|
|
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
|
|
|
import org.whispersystems.textsecure.api.TextSecureMessageReceiver;
|
|
|
|
import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
|
|
|
|
import org.whispersystems.textsecure.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 TextSecureMessageReceiver receiver;
|
|
|
|
|
|
|
|
public PushNotificationReceiveJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder()
|
|
|
|
.withRequirement(new NetworkRequirement(context))
|
2015-04-16 19:22:05 +00:00
|
|
|
.withGroupId("__notification_received")
|
2015-04-15 17:58:29 +00:00
|
|
|
.withWakeLock(true, 30, TimeUnit.SECONDS).create());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAdded() {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() throws IOException {
|
|
|
|
receiver.retrieveMessages(new TextSecureMessageReceiver.MessageReceivedCallback() {
|
|
|
|
@Override
|
|
|
|
public void onMessage(TextSecureEnvelope envelope) {
|
|
|
|
handle(envelope, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception e) {
|
2015-06-11 16:43:34 +00:00
|
|
|
Log.w(TAG, e);
|
2015-04-15 17:58:29 +00:00
|
|
|
return e instanceof PushNetworkException;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
Log.w(TAG, "***** Failed to download pending message!");
|
|
|
|
}
|
|
|
|
}
|