Always report send errors

pull/183/head
M66B 5 years ago
parent 24aa7fa0f0
commit ff5ec9eb1f

@ -204,20 +204,25 @@ public class ServiceSend extends ServiceBase {
return builder; return builder;
} }
NotificationCompat.Builder getNotificationError(String recipient, Throwable ex) { NotificationCompat.Builder getNotificationError(String recipient, Throwable ex, int tries_left) {
return new NotificationCompat.Builder(this, "error") NotificationCompat.Builder builder = new NotificationCompat.Builder(this, tries_left == 0 ? "error" : "warning")
.setSmallIcon(R.drawable.baseline_warning_white_24) .setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(getString(R.string.title_notification_sending_failed, recipient)) .setContentTitle(getString(R.string.title_notification_sending_failed, recipient))
.setContentText(Log.formatThrowable(ex, false))
.setContentIntent(getPendingIntent(this)) .setContentIntent(getPendingIntent(this))
.setAutoCancel(false) .setAutoCancel(tries_left != 0)
.setShowWhen(true) .setShowWhen(true)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
.setOnlyAlertOnce(true) .setOnlyAlertOnce(false)
.setCategory(NotificationCompat.CATEGORY_ERROR) .setCategory(NotificationCompat.CATEGORY_ERROR)
.setVisibility(NotificationCompat.VISIBILITY_SECRET) .setVisibility(NotificationCompat.VISIBILITY_SECRET);
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false))); if (tries_left == 0) {
builder.setContentText(Log.formatThrowable(ex, false))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false)));
} else
builder.setContentText(getString(R.string.title_notification_sending_left, tries_left));
return builder;
} }
private static PendingIntent getPendingIntent(Context context) { private static PendingIntent getPendingIntent(Context context) {
@ -357,9 +362,18 @@ public class ServiceSend extends ServiceBase {
EntityLog.log(this, outbox.name + " " + Log.formatThrowable(ex, false)); EntityLog.log(this, outbox.name + " " + Log.formatThrowable(ex, false));
db.operation().setOperationError(op.id, Log.formatThrowable(ex)); db.operation().setOperationError(op.id, Log.formatThrowable(ex));
if (message != null) if (message != null) {
db.message().setMessageError(message.id, Log.formatThrowable(ex)); db.message().setMessageError(message.id, Log.formatThrowable(ex));
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.id, 1, getNotificationError(
MessageHelper.formatAddressesShort(message.to), ex, RETRY_MAX - op.tries).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
}
if (op.tries >= RETRY_MAX || if (op.tries >= RETRY_MAX ||
ex instanceof OutOfMemoryError || ex instanceof OutOfMemoryError ||
ex instanceof MessageRemovedException || ex instanceof MessageRemovedException ||
@ -371,18 +385,6 @@ public class ServiceSend extends ServiceBase {
Log.w("Unrecoverable"); Log.w("Unrecoverable");
db.operation().deleteOperation(op.id); db.operation().deleteOperation(op.id);
ops.remove(op); ops.remove(op);
if (message != null) {
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.id, 1, getNotificationError(
MessageHelper.formatAddressesShort(message.to), ex).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
}
continue;
} else } else
throw ex; throw ex;
} finally { } finally {

@ -98,6 +98,7 @@
<string name="title_notification_idle">Idle</string> <string name="title_notification_idle">Idle</string>
<string name="title_notification_failed">\'%1$s\' failed</string> <string name="title_notification_failed">\'%1$s\' failed</string>
<string name="title_notification_alert">\'%1$s\' server alert</string> <string name="title_notification_alert">\'%1$s\' server alert</string>
<string name="title_notification_sending_left">Attempts left: %1$d</string>
<string name="title_notification_sending_failed">Sending to %1$s failed</string> <string name="title_notification_sending_failed">Sending to %1$s failed</string>
<string name="title_of">%1$s/%2$s</string> <string name="title_of">%1$s/%2$s</string>

Loading…
Cancel
Save