Enforce "auto-sync app data" setting for POP3/IMAP
* We were using the deprecated ConnectivityManager for this; we should now be using the setting in ContentResolver * Also, remove broadcast receiver code that is no longer relevant Bug: 5405352 Change-Id: I985a95071aea92d235a2708925f775b817ba2328
This commit is contained in:
parent
1d8302e88b
commit
faf9ecc992
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue