From b54f6ee11b1f6b7c7fe59643f2f8ea9ed5212f10 Mon Sep 17 00:00:00 2001 From: Philip Whitehouse Date: Thu, 24 Nov 2016 00:09:23 +0000 Subject: [PATCH] Provide a better explanation as to why sync is disabled --- .../fsck/k9/activity/ActivityListener.java | 13 ++++++++++++ .../java/com/fsck/k9/service/MailService.java | 20 +++++++++++++++++++ k9mail/src/main/res/values/strings.xml | 4 ++++ .../k9/activity/ActivityListenerTest.java | 19 +++++++++++++++--- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/ActivityListener.java b/k9mail/src/main/java/com/fsck/k9/activity/ActivityListener.java index 798fb96df..d314e16c1 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/ActivityListener.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/ActivityListener.java @@ -8,6 +8,7 @@ import android.text.format.DateUtils; import com.fsck.k9.Account; import com.fsck.k9.AccountStats; +import com.fsck.k9.K9; import com.fsck.k9.R; import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.service.MailService; @@ -44,6 +45,18 @@ public class ActivityListener extends MessagingListener { return context.getString(R.string.status_next_poll, DateUtils.getRelativeTimeSpanString(nextPollTime, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0)); + } else if (K9.DEBUG && MailService.isSyncDisabled()) { + if (MailService.hasNoConnectivity()) { + return context.getString(R.string.status_no_network); + } else if (MailService.isSyncNoBackground()) { + return context.getString(R.string.status_no_background); + } else if (MailService.isSyncBlocked()) { + return context.getString(R.string.status_syncing_blocked); + } else if (MailService.isPollAndPushDisabled()) { + return context.getString(R.string.status_poll_and_push_disabled); + } else { + return context.getString(R.string.status_syncing_off); + } } else if (MailService.isSyncDisabled()) { return context.getString(R.string.status_syncing_off); } else { diff --git a/k9mail/src/main/java/com/fsck/k9/service/MailService.java b/k9mail/src/main/java/com/fsck/k9/service/MailService.java index 291dbb766..256ee739c 100644 --- a/k9mail/src/main/java/com/fsck/k9/service/MailService.java +++ b/k9mail/src/main/java/com/fsck/k9/service/MailService.java @@ -34,6 +34,8 @@ public class MailService extends CoreService { private static long nextCheck = -1; private static boolean pushingRequested = false; private static boolean pollingRequested = false; + private static boolean syncNoBackground = false; + private static boolean syncNoConnectivity = false; private static boolean syncBlocked = false; public static void actionReset(Context context, Integer wakeLockId) { @@ -106,6 +108,8 @@ public class MailService extends CoreService { break; } + syncNoBackground = !doBackground; + syncNoConnectivity = !hasConnectivity; syncBlocked = !(doBackground && hasConnectivity); if (K9.DEBUG) @@ -315,6 +319,22 @@ public class MailService extends CoreService { return syncBlocked || (!pollingRequested && !pushingRequested); } + public static boolean hasNoConnectivity() { + return syncNoConnectivity; + } + + public static boolean isSyncNoBackground() { + return syncNoBackground; + } + + public static boolean isSyncBlocked() { + return syncBlocked; + } + + public static boolean isPollAndPushDisabled() { + return (!pollingRequested && !pushingRequested); + } + private void stopPushers() { MessagingController.getInstance(getApplication()).stopAllPushing(); PushService.stopService(MailService.this); diff --git a/k9mail/src/main/res/values/strings.xml b/k9mail/src/main/res/values/strings.xml index 901644d6f..983993b4a 100644 --- a/k9mail/src/main/res/values/strings.xml +++ b/k9mail/src/main/res/values/strings.xml @@ -107,6 +107,10 @@ Please submit bug reports, contribute new features and ask questions at \u0020%d/%d Next poll %s + Sync disabled - No network + Sync disabled - No background activity + Polling and pushing disabled + Syncing blocked Syncing disabled %d selected diff --git a/k9mail/src/test/java/com/fsck/k9/activity/ActivityListenerTest.java b/k9mail/src/test/java/com/fsck/k9/activity/ActivityListenerTest.java index 1aac238b1..90ba052a5 100644 --- a/k9mail/src/test/java/com/fsck/k9/activity/ActivityListenerTest.java +++ b/k9mail/src/test/java/com/fsck/k9/activity/ActivityListenerTest.java @@ -4,6 +4,7 @@ package com.fsck.k9.activity; import android.content.Context; import com.fsck.k9.Account; +import com.fsck.k9.K9; import com.fsck.k9.K9RobolectricTestRunner; import com.fsck.k9.mail.Message; import org.junit.Before; @@ -74,7 +75,11 @@ public class ActivityListenerTest { String operation = activityListener.getOperation(context); - assertEquals("Syncing disabled", operation); + if (K9.DEBUG) { + assertEquals("Polling and pushing disabled", operation); + } else { + assertEquals("Syncing disabled", operation); + } } @Test @@ -85,7 +90,11 @@ public class ActivityListenerTest { String operation = activityListener.getOperation(context); - assertEquals("Syncing disabled", operation); + if (K9.DEBUG) { + assertEquals("Polling and pushing disabled", operation); + } else { + assertEquals("Syncing disabled", operation); + } } @Test @@ -95,7 +104,11 @@ public class ActivityListenerTest { String operation = activityListener.getOperation(context); - assertEquals("Syncing disabled", operation); + if (K9.DEBUG) { + assertEquals("Polling and pushing disabled", operation); + } else { + assertEquals("Syncing disabled", operation); + } } @Test