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) { if (message.identity != null) {
// Identity can be deleted // Identity can be deleted
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1); nm.cancel("send:" + message.id, 1);
} }
return null; return null;

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

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

@ -6209,7 +6209,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.identity().setIdentityError(message.identity, null); db.identity().setIdentityError(message.identity, null);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 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) { } else if (message.uid == null && account.protocol == EntityAccount.TYPE_IMAP) {
db.message().deleteMessage(id); db.message().deleteMessage(id);

@ -169,18 +169,11 @@ public class ServiceSend extends ServiceBase {
} }
NotificationCompat.Builder getNotificationService() { 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 = NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, "send") new NotificationCompat.Builder(this, "send")
.setSmallIcon(R.drawable.baseline_send_24) .setSmallIcon(R.drawable.baseline_send_24)
.setContentTitle(getString(R.string.title_notification_sending)) .setContentTitle(getString(R.string.title_notification_sending))
.setContentIntent(pi) .setContentIntent(getPendingIntent(this))
.setAutoCancel(false) .setAutoCancel(false)
.setShowWhen(true) .setShowWhen(true)
.setDefaults(0) // disable sound on pre Android 8 .setDefaults(0) // disable sound on pre Android 8
@ -200,6 +193,13 @@ public class ServiceSend extends ServiceBase {
return builder; 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() { ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override @Override
public void onAvailable(Network network) { public void onAvailable(Network network) {
@ -349,9 +349,44 @@ 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) {
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; 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; throw ex;
}
} finally { } finally {
Log.i(outbox.name + " end op=" + op.id + "/" + op.name); Log.i(outbox.name + " end op=" + op.id + "/" + op.name);
db.operation().setOperationState(op.id, null); db.operation().setOperationState(op.id, null);
@ -570,7 +605,7 @@ public class ServiceSend extends ServiceBase {
ServiceSynchronize.eval(ServiceSend.this, "sent"); ServiceSynchronize.eval(ServiceSend.this, "sent");
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1); nm.cancel("send:" + message.id, 1);
} catch (MessagingException ex) { } catch (MessagingException ex) {
Log.e(ex); Log.e(ex);
@ -579,34 +614,6 @@ public class ServiceSend extends ServiceBase {
db.identity().setIdentityError(ident.id, Log.formatThrowable(ex)); 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; throw ex;
} finally { } finally {
db.identity().setIdentityState(ident.id, null); db.identity().setIdentityState(ident.id, null);

Loading…
Cancel
Save