diff --git a/emailsync/src/com/android/emailsync/SyncManager.java b/emailsync/src/com/android/emailsync/SyncManager.java index b8e3d3a2d..390381abc 100644 --- a/emailsync/src/com/android/emailsync/SyncManager.java +++ b/emailsync/src/com/android/emailsync/SyncManager.java @@ -226,8 +226,6 @@ public abstract class SyncManager extends Service implements Runnable { // Receiver of connectivity broadcasts private ConnectivityReceiver mConnectivityReceiver = null; - private ConnectivityReceiver mBackgroundDataSettingReceiver = null; - private volatile boolean mBackgroundData = true; // The most current NetworkInfo (from ConnectivityManager) private NetworkInfo mNetworkInfo; @@ -874,7 +872,7 @@ public abstract class SyncManager extends Service implements Runnable { * This would work on a real device as well, but it would be better to use the "real" id if * it's available */ - static public String getDeviceId(Context context) throws IOException { + static public String getDeviceId(Context context) { if (sDeviceId == null) { sDeviceId = new AccountServiceProxy(context).getDeviceId(); alwaysLog("Received deviceId from Email app: " + sDeviceId); @@ -1180,45 +1178,22 @@ public abstract class SyncManager extends Service implements Runnable { @SuppressWarnings("deprecation") @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { - Bundle b = intent.getExtras(); - if (b != null) { - NetworkInfo a = (NetworkInfo)b.get(ConnectivityManager.EXTRA_NETWORK_INFO); - String info = "Connectivity alert for " + a.getTypeName(); - State state = a.getState(); - if (state == State.CONNECTED) { - info += " CONNECTED"; - log(info); - synchronized (sConnectivityLock) { - sConnectivityLock.notifyAll(); - } - kick("connected"); - } else if (state == State.DISCONNECTED) { - info += " DISCONNECTED"; - log(info); - kick("disconnected"); + Bundle b = intent.getExtras(); + if (b != null) { + NetworkInfo a = (NetworkInfo)b.get(ConnectivityManager.EXTRA_NETWORK_INFO); + String info = "Connectivity alert for " + a.getTypeName(); + State state = a.getState(); + if (state == State.CONNECTED) { + info += " CONNECTED"; + log(info); + synchronized (sConnectivityLock) { + sConnectivityLock.notifyAll(); } - } - } else if (intent.getAction().equals( - ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)) { - ConnectivityManager cm = - (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); - mBackgroundData = cm.getBackgroundDataSetting(); - // If background data is now on, we want to kick SyncServiceManager - if (mBackgroundData) { - kick("background data on"); - log("Background data on; restart syncs"); - // Otherwise, stop all syncs - } else { - log("Background data off: stop all syncs"); - EmailAsyncTask.runAsyncParallel(new Runnable() { - @Override - public void run() { - synchronized (mAccountList) { - for (Account account : mAccountList) - SyncManager.stopAccountSyncs(account.mId); - } - }}); + kick("connected"); + } else if (state == State.DISCONNECTED) { + info += " DISCONNECTED"; + log(info); + kick("disconnected"); } } } @@ -1421,29 +1396,21 @@ public abstract class SyncManager extends Service implements Runnable { alwaysLog("!!! Email application not found; stopping self"); stopSelf(); } - if (sDeviceId == null) { - try { - String deviceId = getDeviceId(SyncManager.this); - if (deviceId != null) { - sDeviceId = deviceId; - } - } catch (IOException e) { - } - if (sDeviceId == null) { - alwaysLog("!!! deviceId unknown; stopping self and retrying"); - stopSelf(); - // Try to restart ourselves in a few seconds - Utility.runAsync(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - } - startService(getServiceIntent()); - }}); - return; - } + String deviceId = getDeviceId(SyncManager.this); + if (deviceId == null) { + alwaysLog("!!! deviceId unknown; stopping self and retrying"); + stopSelf(); + // Try to restart ourselves in a few seconds + Utility.runAsync(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + } + startService(getServiceIntent()); + }}); + return; } // Run the reconciler and clean up mismatched accounts - if we weren't // running when accounts were deleted, it won't have been called. @@ -1556,20 +1523,10 @@ public abstract class SyncManager extends Service implements Runnable { mResolver.registerContentObserver(Message.SYNCED_CONTENT_URI, true, mSyncedMessageObserver); - // Set up receivers for connectivity and background data setting mConnectivityReceiver = new ConnectivityReceiver(); registerReceiver(mConnectivityReceiver, new IntentFilter( ConnectivityManager.CONNECTIVITY_ACTION)); - mBackgroundDataSettingReceiver = new ConnectivityReceiver(); - registerReceiver(mBackgroundDataSettingReceiver, new IntentFilter( - ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED)); - // Save away the current background data setting; we'll keep track of it with the - // receiver we just registered - ConnectivityManager cm = (ConnectivityManager)getSystemService( - Context.CONNECTIVITY_SERVICE); - mBackgroundData = cm.getBackgroundDataSetting(); - onStartup(); } } @@ -1640,9 +1597,6 @@ public abstract class SyncManager extends Service implements Runnable { if (mConnectivityReceiver != null) { unregisterReceiver(mConnectivityReceiver); } - if (mBackgroundDataSettingReceiver != null) { - unregisterReceiver(mBackgroundDataSettingReceiver); - } // Unregister observers ContentResolver resolver = getContentResolver(); @@ -1833,11 +1787,10 @@ public abstract class SyncManager extends Service implements Runnable { // Never automatically sync trash } else if (type == Mailbox.TYPE_TRASH) { return false; - // For non-outbox, non-account mail, we do three checks: + // For non-outbox, non-account mail, we do two checks: // 1) are we restricted by policy (i.e. manual sync only), // 2) has the user checked the "Sync Email" box in Account Settings, and - // 3) does the user have the master "background data" box checked in Settings - } else if (!canAutoSync(account) || !canSyncEmail(account.mAmAccount) || !mBackgroundData) { + } else if (!canAutoSync(account) || !canSyncEmail(account.mAmAccount)) { return false; } return true; diff --git a/src/com/android/email/service/PopImapSyncAdapterService.java b/src/com/android/email/service/PopImapSyncAdapterService.java index 35ca449b4..838fda092 100644 --- a/src/com/android/email/service/PopImapSyncAdapterService.java +++ b/src/com/android/email/service/PopImapSyncAdapterService.java @@ -16,7 +16,6 @@ package com.android.email.service; -import android.accounts.OperationCanceledException; import android.app.Service; import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; @@ -46,45 +45,34 @@ import java.util.ArrayList; public class PopImapSyncAdapterService extends Service { private static final String TAG = "PopImapSyncService"; - private static SyncAdapterImpl sSyncAdapter = null; - private static final Object sSyncAdapterLock = new Object(); + private SyncAdapterImpl mSyncAdapter = null; public PopImapSyncAdapterService() { super(); } private static class SyncAdapterImpl extends AbstractThreadedSyncAdapter { - private Context mContext; - public SyncAdapterImpl(Context context) { super(context, true /* autoInitialize */); - mContext = context; } @Override public void onPerformSync(android.accounts.Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { - try { - PopImapSyncAdapterService.performSync(mContext, account, extras, - authority, provider, syncResult); - } catch (OperationCanceledException e) { - } + PopImapSyncAdapterService.performSync(getContext(), account, extras, authority, + provider, syncResult); } } @Override public void onCreate() { super.onCreate(); - synchronized (sSyncAdapterLock) { - if (sSyncAdapter == null) { - sSyncAdapter = new SyncAdapterImpl(getApplicationContext()); - } - } + mSyncAdapter = new SyncAdapterImpl(getApplicationContext()); } @Override public IBinder onBind(Intent intent) { - return sSyncAdapter.getSyncAdapterBinder(); + return mSyncAdapter.getSyncAdapterBinder(); } /** @@ -168,8 +156,8 @@ public class PopImapSyncAdapterService extends Service { * Partial integration with system SyncManager; we initiate manual syncs upon request */ private static void performSync(Context context, android.accounts.Account account, - Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) - throws OperationCanceledException { + Bundle extras, String authority, ContentProviderClient provider, + SyncResult syncResult) { // Find an EmailProvider account with the Account's email address Cursor c = null; try {