diff --git a/src/com/android/email/EmailConnectivityManager.java b/src/com/android/email/EmailConnectivityManager.java index 7f549cbb1..c618c3870 100644 --- a/src/com/android/email/EmailConnectivityManager.java +++ b/src/com/android/email/EmailConnectivityManager.java @@ -17,6 +17,7 @@ package com.android.email; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; @@ -75,8 +76,8 @@ public class EmailConnectivityManager extends BroadcastReceiver { mContext.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); } - public boolean isBackgroundDataAllowed() { - return mConnectivityManager.getBackgroundDataSetting(); + public boolean isAutoSyncAllowed() { + return ContentResolver.getMasterSyncAutomatically(); } public void stopWait() { @@ -103,14 +104,6 @@ public class EmailConnectivityManager extends BroadcastReceiver { public void onConnectivityLost(int networkType) { } - /** - * Called when the user changes the state of the "Background Data" setting; this method should - * be overridden by subclasses as necessary. NOTE: CALLED ON UI THREAD - * @param state the new state of the "Background Data" setting - */ - public void onBackgroundDataChanged(boolean state) { - } - public void unregister() { try { mContext.unregisterReceiver(this); @@ -139,9 +132,6 @@ public class EmailConnectivityManager extends BroadcastReceiver { onConnectivityLost(networkInfo.getType()); } } - } else if (intent.getAction().equals( - ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)) { - onBackgroundDataChanged(isBackgroundDataAllowed()); } } diff --git a/src/com/android/email/service/AttachmentDownloadService.java b/src/com/android/email/service/AttachmentDownloadService.java index f570f156c..b0db0bb01 100644 --- a/src/com/android/email/service/AttachmentDownloadService.java +++ b/src/com/android/email/service/AttachmentDownloadService.java @@ -339,7 +339,7 @@ public class AttachmentDownloadService extends Service implements Runnable { // Don't prefetch if background downloading is disallowed EmailConnectivityManager ecm = mConnectivityManager; if (ecm == null) return; - if (!ecm.isBackgroundDataAllowed()) return; + if (!ecm.isAutoSyncAllowed()) return; // Don't prefetch unless we're on a WiFi network if (ecm.getActiveNetworkType() != ConnectivityManager.TYPE_WIFI) { return; diff --git a/src/com/android/email/service/MailService.java b/src/com/android/email/service/MailService.java index f7eb48e0f..4b3f31a54 100644 --- a/src/com/android/email/service/MailService.java +++ b/src/com/android/email/service/MailService.java @@ -27,7 +27,6 @@ import android.content.Context; import android.content.Intent; import android.content.SyncStatusObserver; import android.database.Cursor; -import android.net.ConnectivityManager; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; @@ -175,9 +174,9 @@ public class MailService extends Service { setWatchdog(accountId, alarmManager); } - // Start sync if account is given && bg data enabled && account has sync enabled + // Start sync if account is given && auto-sync is allowed boolean syncStarted = false; - if (accountId != -1 && isBackgroundDataEnabled()) { + if (accountId != -1 && ContentResolver.getMasterSyncAutomatically()) { synchronized(mSyncReports) { for (AccountSyncReport report: mSyncReports.values()) { if (report.accountId == accountId) { @@ -656,15 +655,6 @@ public class MailService extends Service { } } - /** - * @see ConnectivityManager#getBackgroundDataSetting() - */ - private boolean isBackgroundDataEnabled() { - ConnectivityManager cm = - (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); - return cm.getBackgroundDataSetting(); - } - public class EmailSyncStatusObserver implements SyncStatusObserver { @Override public void onStatusChanged(int which) { diff --git a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java index c3398cd20..4c182b9a0 100644 --- a/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java +++ b/tests/src/com/android/email/service/AttachmentDownloadServiceTests.java @@ -16,6 +16,9 @@ package com.android.email.service; +import android.content.Context; +import android.content.Intent; + import com.android.email.AccountTestCase; import com.android.email.EmailConnectivityManager; import com.android.email.provider.ProviderTestUtils; @@ -28,9 +31,6 @@ import com.android.emailcommon.provider.EmailContent.Message; import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.service.EmailServiceStatus; -import android.content.Context; -import android.content.Intent; - import java.io.File; import java.util.Iterator; @@ -226,7 +226,7 @@ public class AttachmentDownloadServiceTests extends AccountTestCase { } @Override - public boolean isBackgroundDataAllowed() { + public boolean isAutoSyncAllowed() { return true; } }