Improved sent failure handling (untested)

pull/182/head
M66B 5 years ago
parent f545281477
commit 63636158d8

@ -3696,7 +3696,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (message.identity != null) {
// Identity can be deleted
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1);
nm.cancel("send:" + message.id, 1);
}
return null;

@ -3689,30 +3689,29 @@ class Core {
// - on connectivity problems when connecting to store
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex) {
// Build pending intent
Intent intent = new Intent(context, ActivityView.class);
intent.setAction("error");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(
context, ActivityView.REQUEST_ERROR, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(context, channel)
.setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(context.getString(R.string.title_notification_failed, title))
.setContentText(Log.formatThrowable(ex, false))
.setContentIntent(pi)
.setAutoCancel(false)
.setShowWhen(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setOnlyAlertOnce(true)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false)));
return builder;
return getNotificationError(context, channel, title, ex, pi);
}
static NotificationCompat.Builder getNotificationError(Context context, String channel, String title, Throwable ex, PendingIntent pi) {
return new NotificationCompat.Builder(context, channel)
.setSmallIcon(R.drawable.baseline_warning_white_24)
.setContentTitle(context.getString(R.string.title_notification_failed, title))
.setContentText(Log.formatThrowable(ex, false))
.setContentIntent(pi)
.setAutoCancel(false)
.setShowWhen(true)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setOnlyAlertOnce(true)
.setCategory(NotificationCompat.CATEGORY_ERROR)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(Log.formatThrowable(ex, "\n", false)));
}
static class State {

@ -21,7 +21,6 @@ package eu.faircode.email;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
@ -898,11 +897,6 @@ public class FragmentIdentity extends FragmentBase {
db.endTransaction();
}
if (!synchronize) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + identity.id, 1);
}
return false;
}

@ -6209,7 +6209,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.identity().setIdentityError(message.identity, null);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1);
nm.cancel("send:" + message.id, 1);
}
} else if (message.uid == null && account.protocol == EntityAccount.TYPE_IMAP) {
db.message().deleteMessage(id);

@ -169,18 +169,11 @@ public class ServiceSend extends ServiceBase {
}
NotificationCompat.Builder getNotificationService() {
// Build pending intent
Intent intent = new Intent(this, ActivityView.class);
intent.setAction("outbox");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(
this, ActivityView.REQUEST_OUTBOX, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, "send")
.setSmallIcon(R.drawable.baseline_send_24)
.setContentTitle(getString(R.string.title_notification_sending))
.setContentIntent(pi)
.setContentIntent(getPendingIntent(this))
.setAutoCancel(false)
.setShowWhen(true)
.setDefaults(0) // disable sound on pre Android 8
@ -200,6 +193,13 @@ public class ServiceSend extends ServiceBase {
return builder;
}
private static PendingIntent getPendingIntent(Context context) {
Intent intent = new Intent(context, ActivityView.class);
intent.setAction("outbox");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(context, ActivityView.REQUEST_OUTBOX, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
@ -349,9 +349,44 @@ public class ServiceSend extends ServiceBase {
Log.w("Unrecoverable");
db.operation().deleteOperation(op.id);
ops.remove(op);
if (message != null) {
String title = MessageHelper.formatAddresses(message.to);
PendingIntent pi = getPendingIntent(this);
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.id, 1,
Core.getNotificationError(this, "error", title, ex, pi).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
}
continue;
} else
} else {
if (message != null) {
String title = MessageHelper.formatAddresses(message.to);
PendingIntent pi = getPendingIntent(this);
EntityLog.log(this, title + " last attempt: " + new Date(message.last_attempt));
long now = new Date().getTime();
long delayed = now - message.last_attempt;
if (delayed > IDENTITY_ERROR_AFTER * 60 * 1000L) {
Log.i("Reporting send error after=" + delayed);
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.id, 1,
Core.getNotificationError(this, "warning", title, ex, pi).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
}
}
throw ex;
}
} finally {
Log.i(outbox.name + " end op=" + op.id + "/" + op.name);
db.operation().setOperationState(op.id, null);
@ -570,7 +605,7 @@ public class ServiceSend extends ServiceBase {
ServiceSynchronize.eval(ServiceSend.this, "sent");
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1);
nm.cancel("send:" + message.id, 1);
} catch (MessagingException ex) {
Log.e(ex);
@ -579,34 +614,6 @@ public class ServiceSend extends ServiceBase {
db.identity().setIdentityError(ident.id, Log.formatThrowable(ex));
if (ex instanceof AuthenticationFailedException ||
ex instanceof SendFailedException) {
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.identity, 1,
Core.getNotificationError(this, "error", ident.name, ex)
.build());
} catch (Throwable ex1) {
Log.w(ex1);
}
throw ex;
}
EntityLog.log(this, ident.name + " last attempt: " + new Date(message.last_attempt));
long now = new Date().getTime();
long delayed = now - message.last_attempt;
if (delayed > IDENTITY_ERROR_AFTER * 60 * 1000L) {
Log.i("Reporting send error after=" + delayed);
try {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("send:" + message.identity, 1,
Core.getNotificationError(this, "warning", ident.name, ex).build());
} catch (Throwable ex1) {
Log.w(ex1);
}
}
throw ex;
} finally {
db.identity().setIdentityState(ident.id, null);

Loading…
Cancel
Save