From 9580f6175da4c5df4b8aa13242aaef8c922dec05 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 3 May 2010 14:14:16 -0700 Subject: [PATCH] Don't sync when the background data system setting is off. Bug 2494703 Change-Id: Ia6f4c9fc86cdcb5ca3276141cb84b4effb6ee87c --- .../android/email/service/MailService.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/service/MailService.java b/src/com/android/email/service/MailService.java index 272818caa..9d910f237 100644 --- a/src/com/android/email/service/MailService.java +++ b/src/com/android/email/service/MailService.java @@ -37,6 +37,7 @@ import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.media.AudioManager; +import android.net.ConnectivityManager; import android.net.Uri; import android.os.IBinder; import android.os.SystemClock; @@ -177,8 +178,15 @@ public class MailService extends Service { if (checkAccountId >= 0) { setWatchdog(checkAccountId, alarmManager); } - // if no account given, or the given account cannot be synced - reschedule - if (checkAccountId == -1 || !syncOneAccount(controller, checkAccountId, startId)) { + + // Start sync if account is given and background data is enabled. + boolean syncStarted = false; + if (checkAccountId != -1 && isBackgroundDataEnabled()) { + syncStarted = syncOneAccount(controller, checkAccountId, startId); + } + + // Reschedule if we didn't start sync. + if (!syncStarted) { // Prevent runaway on the current account by pretending it updated if (checkAccountId != -1) { updateAccountReport(checkAccountId, 0); @@ -715,4 +723,13 @@ public class MailService extends Service { (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID_NEW_MESSAGES, notification); } + + /** + * @see ConnectivityManager#getBackgroundDataSetting() + */ + private boolean isBackgroundDataEnabled() { + ConnectivityManager cm = + (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); + return cm.getBackgroundDataSetting(); + } }