parent
55ba57d056
commit
7ba75c3291
@ -0,0 +1,63 @@
|
|||||||
|
package org.thoughtcrime.securesms.jobs;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.whispersystems.jobqueue.JobManager;
|
||||||
|
import org.whispersystems.jobqueue.JobParameters;
|
||||||
|
import org.whispersystems.libaxolotl.InvalidVersionException;
|
||||||
|
import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
|
||||||
|
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||||
|
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
||||||
|
import org.whispersystems.textsecure.api.push.ContactTokenDetails;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PushContentReceiveJob extends PushReceivedJob {
|
||||||
|
|
||||||
|
private static final String TAG = PushContentReceiveJob.class.getSimpleName();
|
||||||
|
|
||||||
|
private final String data;
|
||||||
|
|
||||||
|
public PushContentReceiveJob(Context context) {
|
||||||
|
super(context, JobParameters.newBuilder().create());
|
||||||
|
this.data = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushContentReceiveJob(Context context, String data) {
|
||||||
|
super(context, JobParameters.newBuilder()
|
||||||
|
.withPersistence()
|
||||||
|
.withWakeLock(true)
|
||||||
|
.create());
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAdded() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRun() {
|
||||||
|
try {
|
||||||
|
String sessionKey = TextSecurePreferences.getSignalingKey(context);
|
||||||
|
TextSecureEnvelope envelope = new TextSecureEnvelope(data, sessionKey);
|
||||||
|
|
||||||
|
handle(envelope, true);
|
||||||
|
} catch (IOException | InvalidVersionException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceled() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onShouldRetry(Exception exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
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))
|
||||||
|
.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) {
|
||||||
|
return e instanceof PushNetworkException;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCanceled() {
|
||||||
|
Log.w(TAG, "***** Failed to download pending message!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue