mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Run PushProcessMessageJobs in parallel.
This commit is contained in:
committed by
Alex Hart
parent
ed33e048ad
commit
f099c3591c
@@ -38,7 +38,7 @@ public class JobManager implements ConstraintObserver.Notifier {
|
||||
|
||||
private static final String TAG = JobManager.class.getSimpleName();
|
||||
|
||||
public static final int CURRENT_VERSION = 5;
|
||||
public static final int CURRENT_VERSION = 6;
|
||||
|
||||
private final Application application;
|
||||
private final Configuration configuration;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.jobmanager;
|
||||
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -90,6 +91,7 @@ public class JobTracker {
|
||||
}
|
||||
|
||||
public interface JobListener {
|
||||
@AnyThread
|
||||
void onStateChanged(@NonNull Job job, @NonNull JobState jobState);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.migrations;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.groups.BadGroupIdException;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* We changed the format of the queue key for {@link org.thoughtcrime.securesms.jobs.PushProcessMessageJob}
|
||||
* to have the recipient ID in it, so this migrates existing jobs to be in that format.
|
||||
*/
|
||||
public class PushProcessMessageQueueJobMigration extends JobMigration {
|
||||
|
||||
private static final String TAG = Log.tag(PushProcessMessageQueueJobMigration.class);
|
||||
|
||||
private final Context context;
|
||||
|
||||
public PushProcessMessageQueueJobMigration(@NonNull Context context) {
|
||||
super(6);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull JobData migrate(@NonNull JobData jobData) {
|
||||
if ("PushProcessJob".equals(jobData.getFactoryKey())) {
|
||||
Log.i(TAG, "Found a PushProcessMessageJob to migrate.");
|
||||
try {
|
||||
return migratePushProcessMessageJob(context, jobData);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "Failed to migrate message job.", e);
|
||||
return jobData;
|
||||
}
|
||||
}
|
||||
return jobData;
|
||||
}
|
||||
|
||||
private static @NonNull JobData migratePushProcessMessageJob(@NonNull Context context, @NonNull JobData jobData) throws IOException {
|
||||
Data data = jobData.getData();
|
||||
|
||||
String suffix = "";
|
||||
|
||||
if (data.getInt("message_state") == 0) {
|
||||
SignalServiceContent content = SignalServiceContent.deserialize(Base64.decode(data.getString("message_content")));
|
||||
|
||||
if (content != null && content.getDataMessage().isPresent() && content.getDataMessage().get().getGroupContext().isPresent()) {
|
||||
Log.i(TAG, "Migrating a group message.");
|
||||
try {
|
||||
GroupId groupId = GroupUtil.idFromGroupContext(content.getDataMessage().get().getGroupContext().get());
|
||||
Recipient recipient = Recipient.externalGroup(context, groupId);
|
||||
|
||||
suffix = recipient.getId().toQueueKey();
|
||||
} catch (BadGroupIdException e) {
|
||||
Log.w(TAG, "Bad groupId! Using default queue.");
|
||||
}
|
||||
} else if (content != null) {
|
||||
Log.i(TAG, "Migrating an individual message.");
|
||||
suffix = RecipientId.from(content.getSender()).toQueueKey();
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Migrating an exception message.");
|
||||
|
||||
String exceptionSender = data.getString("exception_sender");
|
||||
GroupId exceptionGroup = GroupId.parseNullableOrThrow(data.getStringOrDefault("exception_groupId", null));
|
||||
|
||||
if (exceptionGroup != null) {
|
||||
suffix = Recipient.externalGroup(context, exceptionGroup).getId().toQueueKey();
|
||||
} else if (exceptionSender != null) {
|
||||
suffix = Recipient.external(context, exceptionSender).getId().toQueueKey();
|
||||
}
|
||||
}
|
||||
|
||||
return jobData.withQueueKey("__PUSH_PROCESS_JOB__" + suffix);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user