2015-04-15 10:58:29 -07:00
|
|
|
package org.thoughtcrime.securesms.jobs;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-08-09 10:15:43 -04:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.jobmanager.SafeData;
|
2018-08-01 11:09:24 -04:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-04-15 10:58:29 -07:00
|
|
|
|
2018-06-18 12:27:04 -07:00
|
|
|
import org.thoughtcrime.securesms.jobmanager.JobParameters;
|
2015-04-15 10:58:29 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.InvalidVersionException;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
2015-04-15 10:58:29 -07:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2018-08-09 10:15:43 -04:00
|
|
|
import androidx.work.Data;
|
2018-11-27 12:34:42 -08:00
|
|
|
import androidx.work.WorkerParameters;
|
2018-08-09 10:15:43 -04:00
|
|
|
|
2015-04-15 10:58:29 -07:00
|
|
|
public class PushContentReceiveJob extends PushReceivedJob {
|
|
|
|
|
2018-06-19 19:22:39 -07:00
|
|
|
private static final long serialVersionUID = 5685475456901715638L;
|
|
|
|
private static final String TAG = PushContentReceiveJob.class.getSimpleName();
|
2015-04-15 10:58:29 -07:00
|
|
|
|
2018-08-09 10:15:43 -04:00
|
|
|
private static final String KEY_DATA = "data";
|
|
|
|
|
|
|
|
private String data;
|
|
|
|
|
2018-11-27 12:34:42 -08:00
|
|
|
public PushContentReceiveJob(@NonNull Context context, @NonNull WorkerParameters workerParameters) {
|
|
|
|
super(context, workerParameters);
|
2018-08-09 10:15:43 -04:00
|
|
|
}
|
2015-04-15 10:58:29 -07:00
|
|
|
|
|
|
|
public PushContentReceiveJob(Context context) {
|
|
|
|
super(context, JobParameters.newBuilder().create());
|
|
|
|
this.data = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PushContentReceiveJob(Context context, String data) {
|
2018-08-09 10:15:43 -04:00
|
|
|
super(context, JobParameters.newBuilder().create());
|
2015-04-15 10:58:29 -07:00
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-09 10:15:43 -04:00
|
|
|
protected void initialize(@NonNull SafeData data) {
|
2018-10-02 12:31:12 -07:00
|
|
|
this.data = data.getString(KEY_DATA);
|
2018-08-09 10:15:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected @NonNull Data serialize(@NonNull Data.Builder dataBuilder) {
|
|
|
|
return dataBuilder.putString(KEY_DATA, data).build();
|
|
|
|
}
|
2015-04-15 10:58:29 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRun() {
|
|
|
|
try {
|
2016-03-23 10:34:41 -07:00
|
|
|
String sessionKey = TextSecurePreferences.getSignalingKey(context);
|
|
|
|
SignalServiceEnvelope envelope = new SignalServiceEnvelope(data, sessionKey);
|
2015-04-15 10:58:29 -07:00
|
|
|
|
2018-10-05 15:23:33 -07:00
|
|
|
processEnvelope(envelope);
|
2015-04-15 10:58:29 -07:00
|
|
|
} catch (IOException | InvalidVersionException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onShouldRetry(Exception exception) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|