kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix long SMS send with no service failure loop.
rodzic
0838c0be27
commit
f4d6de466b
|
@ -36,8 +36,8 @@ public class SmsSendJob extends SendJob {
|
||||||
private static final String KEY_MESSAGE_ID = "message_id";
|
private static final String KEY_MESSAGE_ID = "message_id";
|
||||||
private static final String KEY_RUN_ATTEMPT = "run_attempt";
|
private static final String KEY_RUN_ATTEMPT = "run_attempt";
|
||||||
|
|
||||||
private long messageId;
|
private final long messageId;
|
||||||
private int runAttempt;
|
private final int runAttempt;
|
||||||
|
|
||||||
public SmsSendJob(long messageId, @NonNull Recipient destination) {
|
public SmsSendJob(long messageId, @NonNull Recipient destination) {
|
||||||
this(messageId, destination, 0);
|
this(messageId, destination, 0);
|
||||||
|
@ -141,7 +141,7 @@ public class SmsSendJob extends SendJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> messages = SmsManager.getDefault().divideMessage(message.getBody());
|
ArrayList<String> messages = SmsManager.getDefault().divideMessage(message.getBody());
|
||||||
ArrayList<PendingIntent> sentIntents = constructSentIntents(message.getId(), message.getType(), messages, false);
|
ArrayList<PendingIntent> sentIntents = constructSentIntents(message.getId(), message.getType(), messages);
|
||||||
ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages);
|
ArrayList<PendingIntent> deliveredIntents = constructDeliveredIntents(message.getId(), message.getType(), messages);
|
||||||
|
|
||||||
// NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
|
// NOTE 11/04/14 -- There's apparently a bug where for some unknown recipients
|
||||||
|
@ -171,14 +171,14 @@ public class SmsSendJob extends SendJob {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<PendingIntent> constructSentIntents(long messageId, long type,
|
private ArrayList<PendingIntent> constructSentIntents(long messageId, long type, ArrayList<String> messages)
|
||||||
ArrayList<String> messages, boolean secure)
|
|
||||||
{
|
{
|
||||||
ArrayList<PendingIntent> sentIntents = new ArrayList<>(messages.size());
|
ArrayList<PendingIntent> sentIntents = new ArrayList<>(messages.size());
|
||||||
|
boolean isMultipart = messages.size() > 1;
|
||||||
|
|
||||||
for (String ignored : messages) {
|
for (String ignored : messages) {
|
||||||
sentIntents.add(PendingIntent.getBroadcast(context, 0,
|
sentIntents.add(PendingIntent.getBroadcast(context, 0,
|
||||||
constructSentIntent(context, messageId, type, secure, false),
|
constructSentIntent(context, messageId, type, isMultipart),
|
||||||
0));
|
0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,19 +191,18 @@ public class SmsSendJob extends SendJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<PendingIntent> deliveredIntents = new ArrayList<>(messages.size());
|
ArrayList<PendingIntent> deliveredIntents = new ArrayList<>(messages.size());
|
||||||
|
boolean isMultipart = messages.size() > 1;
|
||||||
|
|
||||||
for (String ignored : messages) {
|
for (String ignored : messages) {
|
||||||
deliveredIntents.add(PendingIntent.getBroadcast(context, 0,
|
deliveredIntents.add(PendingIntent.getBroadcast(context, 0,
|
||||||
constructDeliveredIntent(context, messageId, type),
|
constructDeliveredIntent(context, messageId, type, isMultipart),
|
||||||
0));
|
0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return deliveredIntents;
|
return deliveredIntents;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent constructSentIntent(Context context, long messageId, long type,
|
private Intent constructSentIntent(Context context, long messageId, long type, boolean isMultipart) {
|
||||||
boolean upgraded, boolean push)
|
|
||||||
{
|
|
||||||
Intent pending = new Intent(SmsDeliveryListener.SENT_SMS_ACTION,
|
Intent pending = new Intent(SmsDeliveryListener.SENT_SMS_ACTION,
|
||||||
Uri.parse("custom://" + messageId + System.currentTimeMillis()),
|
Uri.parse("custom://" + messageId + System.currentTimeMillis()),
|
||||||
context, SmsDeliveryListener.class);
|
context, SmsDeliveryListener.class);
|
||||||
|
@ -211,18 +210,18 @@ public class SmsSendJob extends SendJob {
|
||||||
pending.putExtra("type", type);
|
pending.putExtra("type", type);
|
||||||
pending.putExtra("message_id", messageId);
|
pending.putExtra("message_id", messageId);
|
||||||
pending.putExtra("run_attempt", Math.max(runAttempt, getRunAttempt()));
|
pending.putExtra("run_attempt", Math.max(runAttempt, getRunAttempt()));
|
||||||
pending.putExtra("upgraded", upgraded);
|
pending.putExtra("is_multipart", isMultipart);
|
||||||
pending.putExtra("push", push);
|
|
||||||
|
|
||||||
return pending;
|
return pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent constructDeliveredIntent(Context context, long messageId, long type) {
|
private Intent constructDeliveredIntent(Context context, long messageId, long type, boolean isMultipart) {
|
||||||
Intent pending = new Intent(SmsDeliveryListener.DELIVERED_SMS_ACTION,
|
Intent pending = new Intent(SmsDeliveryListener.DELIVERED_SMS_ACTION,
|
||||||
Uri.parse("custom://" + messageId + System.currentTimeMillis()),
|
Uri.parse("custom://" + messageId + System.currentTimeMillis()),
|
||||||
context, SmsDeliveryListener.class);
|
context, SmsDeliveryListener.class);
|
||||||
pending.putExtra("type", type);
|
pending.putExtra("type", type);
|
||||||
pending.putExtra("message_id", messageId);
|
pending.putExtra("message_id", messageId);
|
||||||
|
pending.putExtra("is_multipart", isMultipart);
|
||||||
|
|
||||||
return pending;
|
return pending;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,36 +21,41 @@ public class SmsSentJob extends BaseJob {
|
||||||
|
|
||||||
private static final String TAG = Log.tag(SmsSentJob.class);
|
private static final String TAG = Log.tag(SmsSentJob.class);
|
||||||
|
|
||||||
private static final String KEY_MESSAGE_ID = "message_id";
|
private static final String KEY_MESSAGE_ID = "message_id";
|
||||||
private static final String KEY_ACTION = "action";
|
private static final String KEY_IS_MULTIPART = "is_multipart";
|
||||||
private static final String KEY_RESULT = "result";
|
private static final String KEY_ACTION = "action";
|
||||||
private static final String KEY_RUN_ATTEMPT = "run_attempt";
|
private static final String KEY_RESULT = "result";
|
||||||
|
private static final String KEY_RUN_ATTEMPT = "run_attempt";
|
||||||
|
|
||||||
private long messageId;
|
private final long messageId;
|
||||||
private String action;
|
private final boolean isMultipart;
|
||||||
private int result;
|
private final String action;
|
||||||
private int runAttempt;
|
private final int result;
|
||||||
|
private final int runAttempt;
|
||||||
|
|
||||||
public SmsSentJob(long messageId, String action, int result, int runAttempt) {
|
public SmsSentJob(long messageId, boolean isMultipart, String action, int result, int runAttempt) {
|
||||||
this(new Job.Parameters.Builder().build(),
|
this(new Job.Parameters.Builder().build(),
|
||||||
messageId,
|
messageId,
|
||||||
|
isMultipart,
|
||||||
action,
|
action,
|
||||||
result,
|
result,
|
||||||
runAttempt);
|
runAttempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SmsSentJob(@NonNull Job.Parameters parameters, long messageId, String action, int result, int runAttempt) {
|
private SmsSentJob(@NonNull Job.Parameters parameters, long messageId, boolean isMultipart, String action, int result, int runAttempt) {
|
||||||
super(parameters);
|
super(parameters);
|
||||||
|
|
||||||
this.messageId = messageId;
|
this.messageId = messageId;
|
||||||
this.action = action;
|
this.isMultipart = isMultipart;
|
||||||
this.result = result;
|
this.action = action;
|
||||||
this.runAttempt = runAttempt;
|
this.result = result;
|
||||||
|
this.runAttempt = runAttempt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Data serialize() {
|
public @NonNull Data serialize() {
|
||||||
return new Data.Builder().putLong(KEY_MESSAGE_ID, messageId)
|
return new Data.Builder().putLong(KEY_MESSAGE_ID, messageId)
|
||||||
|
.putBoolean(KEY_IS_MULTIPART, isMultipart)
|
||||||
.putString(KEY_ACTION, action)
|
.putString(KEY_ACTION, action)
|
||||||
.putInt(KEY_RESULT, result)
|
.putInt(KEY_RESULT, result)
|
||||||
.putInt(KEY_RUN_ATTEMPT, runAttempt)
|
.putInt(KEY_RUN_ATTEMPT, runAttempt)
|
||||||
|
@ -100,8 +105,14 @@ public class SmsSentJob extends BaseJob {
|
||||||
break;
|
break;
|
||||||
case SmsManager.RESULT_ERROR_NO_SERVICE:
|
case SmsManager.RESULT_ERROR_NO_SERVICE:
|
||||||
case SmsManager.RESULT_ERROR_RADIO_OFF:
|
case SmsManager.RESULT_ERROR_RADIO_OFF:
|
||||||
Log.w(TAG, "Service connectivity problem, requeuing...");
|
if (isMultipart) {
|
||||||
ApplicationDependencies.getJobManager().add(new SmsSendJob(messageId, record.getIndividualRecipient(), runAttempt + 1));
|
Log.w(TAG, "Service connectivity problem, but not retrying due to multipart");
|
||||||
|
database.markAsSentFailed(messageId);
|
||||||
|
ApplicationDependencies.getMessageNotifier().notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Service connectivity problem, requeuing...");
|
||||||
|
ApplicationDependencies.getJobManager().add(new SmsSendJob(messageId, record.getIndividualRecipient(), runAttempt + 1));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
database.markAsSentFailed(messageId);
|
database.markAsSentFailed(messageId);
|
||||||
|
@ -117,6 +128,7 @@ public class SmsSentJob extends BaseJob {
|
||||||
public @NonNull SmsSentJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
public @NonNull SmsSentJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
||||||
return new SmsSentJob(parameters,
|
return new SmsSentJob(parameters,
|
||||||
data.getLong(KEY_MESSAGE_ID),
|
data.getLong(KEY_MESSAGE_ID),
|
||||||
|
data.getBooleanOrDefault(KEY_IS_MULTIPART, true),
|
||||||
data.getString(KEY_ACTION),
|
data.getString(KEY_ACTION),
|
||||||
data.getInt(KEY_RESULT),
|
data.getInt(KEY_RESULT),
|
||||||
data.getInt(KEY_RUN_ATTEMPT));
|
data.getInt(KEY_RUN_ATTEMPT));
|
||||||
|
|
|
@ -20,15 +20,16 @@ public class SmsDeliveryListener extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
JobManager jobManager = ApplicationDependencies.getJobManager();
|
JobManager jobManager = ApplicationDependencies.getJobManager();
|
||||||
long messageId = intent.getLongExtra("message_id", -1);
|
long messageId = intent.getLongExtra("message_id", -1);
|
||||||
int runAttempt = intent.getIntExtra("run_attempt", 0);
|
int runAttempt = intent.getIntExtra("run_attempt", 0);
|
||||||
|
boolean isMultipart = intent.getBooleanExtra("is_multipart", true);
|
||||||
|
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case SENT_SMS_ACTION:
|
case SENT_SMS_ACTION:
|
||||||
int result = getResultCode();
|
int result = getResultCode();
|
||||||
|
|
||||||
jobManager.add(new SmsSentJob(messageId, SENT_SMS_ACTION, result, runAttempt));
|
jobManager.add(new SmsSentJob(messageId, isMultipart, SENT_SMS_ACTION, result, runAttempt));
|
||||||
break;
|
break;
|
||||||
case DELIVERED_SMS_ACTION:
|
case DELIVERED_SMS_ACTION:
|
||||||
byte[] pdu = intent.getByteArrayExtra("pdu");
|
byte[] pdu = intent.getByteArrayExtra("pdu");
|
||||||
|
@ -59,7 +60,7 @@ public class SmsDeliveryListener extends BroadcastReceiver {
|
||||||
else if (status >> 24 == 3) status = SmsDatabase.Status.STATUS_FAILED;
|
else if (status >> 24 == 3) status = SmsDatabase.Status.STATUS_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
jobManager.add(new SmsSentJob(messageId, DELIVERED_SMS_ACTION, status, runAttempt));
|
jobManager.add(new SmsSentJob(messageId, isMultipart, DELIVERED_SMS_ACTION, status, runAttempt));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.w(TAG, "Unknown action: " + intent.getAction());
|
Log.w(TAG, "Unknown action: " + intent.getAction());
|
||||||
|
|
Ładowanie…
Reference in New Issue