Swap out AsyncTask usage in notification action receivers with bounded threadpool.
This commit is contained in:
parent
ce20dd97ff
commit
744b79419b
2 changed files with 54 additions and 63 deletions
|
@ -4,13 +4,13 @@ import android.annotation.SuppressLint;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.annimon.stream.Collectors;
|
import com.annimon.stream.Collectors;
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
|
|
||||||
|
import org.signal.core.util.concurrent.SignalExecutors;
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.ApplicationContext;
|
import org.thoughtcrime.securesms.ApplicationContext;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
|
@ -45,24 +45,19 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||||
if (threadIds != null) {
|
if (threadIds != null) {
|
||||||
NotificationCancellationHelper.cancelLegacy(context, intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));
|
NotificationCancellationHelper.cancelLegacy(context, intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1));
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
SignalExecutors.BOUNDED.execute(() -> {
|
||||||
@Override
|
List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
List<MarkedMessageInfo> messageIdsCollection = new LinkedList<>();
|
|
||||||
|
|
||||||
for (long threadId : threadIds) {
|
for (long threadId : threadIds) {
|
||||||
Log.i(TAG, "Marking as read: " + threadId);
|
Log.i(TAG, "Marking as read: " + threadId);
|
||||||
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
||||||
messageIdsCollection.addAll(messageIds);
|
messageIdsCollection.addAll(messageIds);
|
||||||
}
|
|
||||||
|
|
||||||
process(context, messageIdsCollection);
|
|
||||||
|
|
||||||
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
|
process(context, messageIdsCollection);
|
||||||
|
|
||||||
|
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.core.app.RemoteInput;
|
import androidx.core.app.RemoteInput;
|
||||||
|
|
||||||
|
import org.signal.core.util.concurrent.SignalExecutors;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo;
|
import org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
|
@ -67,56 +68,51 @@ public class RemoteReplyReceiver extends BroadcastReceiver {
|
||||||
if (replyMethod == null) throw new AssertionError("No reply method specified");
|
if (replyMethod == null) throw new AssertionError("No reply method specified");
|
||||||
|
|
||||||
if (responseText != null) {
|
if (responseText != null) {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
SignalExecutors.BOUNDED.execute(() -> {
|
||||||
@Override
|
long threadId;
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
long threadId;
|
|
||||||
|
|
||||||
Recipient recipient = Recipient.resolved(recipientId);
|
Recipient recipient = Recipient.resolved(recipientId);
|
||||||
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
int subscriptionId = recipient.getDefaultSubscriptionId().or(-1);
|
||||||
long expiresIn = recipient.getExpireMessages() * 1000L;
|
long expiresIn = recipient.getExpireMessages() * 1000L;
|
||||||
|
|
||||||
switch (replyMethod) {
|
switch (replyMethod) {
|
||||||
case GroupMessage: {
|
case GroupMessage: {
|
||||||
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient,
|
OutgoingMediaMessage reply = new OutgoingMediaMessage(recipient,
|
||||||
responseText.toString(),
|
responseText.toString(),
|
||||||
new LinkedList<>(),
|
new LinkedList<>(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
expiresIn,
|
expiresIn,
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
null,
|
null,
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
threadId = MessageSender.send(context, reply, -1, false, null);
|
threadId = MessageSender.send(context, reply, -1, false, null);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case SecureMessage: {
|
|
||||||
OutgoingEncryptedMessage reply = new OutgoingEncryptedMessage(recipient, responseText.toString(), expiresIn);
|
|
||||||
threadId = MessageSender.send(context, reply, -1, false, null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case UnsecuredSmsMessage: {
|
|
||||||
OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
|
|
||||||
threadId = MessageSender.send(context, reply, -1, true, null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new AssertionError("Unknown Reply method");
|
|
||||||
}
|
}
|
||||||
|
case SecureMessage: {
|
||||||
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
OutgoingEncryptedMessage reply = new OutgoingEncryptedMessage(recipient, responseText.toString(), expiresIn);
|
||||||
|
threadId = MessageSender.send(context, reply, -1, false, null);
|
||||||
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
break;
|
||||||
MarkReadReceiver.process(context, messageIds);
|
}
|
||||||
|
case UnsecuredSmsMessage: {
|
||||||
return null;
|
OutgoingTextMessage reply = new OutgoingTextMessage(recipient, responseText.toString(), expiresIn, subscriptionId);
|
||||||
|
threadId = MessageSender.send(context, reply, -1, true, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new AssertionError("Unknown Reply method");
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setRead(threadId, true);
|
||||||
|
|
||||||
|
ApplicationDependencies.getMessageNotifier().updateNotification(context);
|
||||||
|
MarkReadReceiver.process(context, messageIds);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue