mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 05:39:18 +00:00
Use REST interface instead of WebSockets on GCM events.
Closes #2994 // FREEBIE
This commit is contained in:
@@ -11,13 +11,12 @@ import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
||||
import org.thoughtcrime.securesms.push.TextSecurePushTrustStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
@@ -37,7 +36,8 @@ import dagger.Provides;
|
||||
PushMediaSendJob.class,
|
||||
AttachmentDownloadJob.class,
|
||||
RefreshPreKeysJob.class,
|
||||
MessageRetrievalService.class})
|
||||
MessageRetrievalService.class,
|
||||
PushNotificationReceiveJob.class})
|
||||
public class TextSecureCommunicationModule {
|
||||
|
||||
private final Context context;
|
||||
|
||||
@@ -9,8 +9,8 @@ import android.util.Log;
|
||||
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.jobs.PushReceiveJob;
|
||||
import org.thoughtcrime.securesms.service.MessageRetrievalService;
|
||||
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
|
||||
@@ -42,12 +42,12 @@ public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
|
||||
private void handleReceivedMessage(Context context, String data) {
|
||||
ApplicationContext.getInstance(context)
|
||||
.getJobManager()
|
||||
.add(new PushReceiveJob(context, data));
|
||||
.add(new PushContentReceiveJob(context, data));
|
||||
}
|
||||
|
||||
private void handleReceivedNotification(Context context) {
|
||||
Intent intent = new Intent(context, MessageRetrievalService.class);
|
||||
intent.setAction(MessageRetrievalService.ACTION_PUSH_RECEIVED);
|
||||
startWakefulService(context, intent);
|
||||
ApplicationContext.getInstance(context)
|
||||
.getJobManager()
|
||||
.add(new PushNotificationReceiveJob(context));
|
||||
}
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
@@ -5,60 +5,19 @@ import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.database.NotInDirectoryException;
|
||||
import org.thoughtcrime.securesms.database.TextSecureDirectory;
|
||||
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 abstract class PushReceivedJob extends ContextJob {
|
||||
|
||||
public class PushReceiveJob extends ContextJob {
|
||||
private static final String TAG = PushReceivedJob.class.getSimpleName();
|
||||
|
||||
private static final String TAG = PushReceiveJob.class.getSimpleName();
|
||||
|
||||
private final String data;
|
||||
|
||||
public PushReceiveJob(Context context) {
|
||||
super(context, JobParameters.newBuilder().create());
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
public PushReceiveJob(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;
|
||||
protected PushReceivedJob(Context context, JobParameters parameters) {
|
||||
super(context, parameters);
|
||||
}
|
||||
|
||||
public void handle(TextSecureEnvelope envelope, boolean sendExplicitReceipt) {
|
||||
@@ -105,4 +64,5 @@ public class PushReceiveJob extends ContextJob {
|
||||
return isActiveNumber;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import android.util.Log;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.thoughtcrime.securesms.gcm.GcmBroadcastReceiver;
|
||||
import org.thoughtcrime.securesms.jobs.PushReceiveJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider;
|
||||
@@ -85,7 +85,7 @@ public class MessageRetrievalService extends Service implements Runnable, Inject
|
||||
public void onMessage(TextSecureEnvelope envelope) {
|
||||
Log.w(TAG, "Retrieved envelope! " + envelope.getSource());
|
||||
|
||||
PushReceiveJob receiveJob = new PushReceiveJob(MessageRetrievalService.this);
|
||||
PushContentReceiveJob receiveJob = new PushContentReceiveJob(MessageRetrievalService.this);
|
||||
receiveJob.handle(envelope, false);
|
||||
|
||||
decrementPushReceived();
|
||||
|
||||
Reference in New Issue
Block a user