Small improvement

pull/172/head
M66B 6 years ago
parent bee37b2b17
commit e73d8f4329

@ -789,9 +789,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
EntityLog.log(ServiceSynchronize.this, account.name + " alert: " + message); EntityLog.log(ServiceSynchronize.this, account.name + " alert: " + message);
if (state.getBackoff() > CONNECT_BACKOFF_MAX || if (!isMaxConnections(message) || state.getBackoff() > CONNECT_BACKOFF_MAX) {
!(message.startsWith("Maximum number of connections") /* Dovecot */ ||
message.startsWith("Too many simultaneous connections") /* Gmail */)) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("alert:" + account.id, 1, nm.notify("alert:" + account.id, 1,
getNotificationAlert(account.name, message).build()); getNotificationAlert(account.name, message).build());
@ -814,16 +812,25 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iservice.connect(account); iservice.connect(account);
} catch (Throwable ex) { } catch (Throwable ex) {
// Immediately report auth errors // Immediately report auth errors
if (ex instanceof AuthenticationFailedException && if (ex instanceof AuthenticationFailedException) {
!(ex.getCause() instanceof IOException) && boolean ioError = false;
!(ex.getMessage() != null && Throwable c = ex;
ex.getMessage().contains("Too many simultaneous connections"))) { while (c != null) {
if (c instanceof IOException || isMaxConnections(c.getMessage())) {
ioError = true;
break;
}
c = c.getCause();
}
if (!ioError) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("receive:" + account.id, 1, nm.notify("receive:" + account.id, 1,
Core.getNotificationError(this, "error", account.name, ex) Core.getNotificationError(this, "error", account.name, ex)
.build()); .build());
throw ex; throw ex;
} }
}
// Report account connection error // Report account connection error
if (account.last_connected != null && !ConnectionHelper.airplaneMode(this)) { if (account.last_connected != null && !ConnectionHelper.airplaneMode(this)) {
@ -1388,6 +1395,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
} }
private boolean isMaxConnections(String message) {
return (message != null &&
(message.contains("Maximum number of connections") /* Dovecot */ ||
message.contains("Too many simultaneous connections") /* Gmail */));
}
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override @Override
public void onAvailable(@NonNull Network network) { public void onAvailable(@NonNull Network network) {

Loading…
Cancel
Save