Merge "Code cleanup." into jb-ub-mail-ur9
This commit is contained in:
commit
99e66178b9
|
@ -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,7 +1178,6 @@ 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);
|
||||
|
@ -1199,28 +1196,6 @@ public abstract class SyncManager extends Service implements Runnable {
|
|||
kick("disconnected");
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1421,15 +1396,8 @@ 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) {
|
||||
if (deviceId == null) {
|
||||
alwaysLog("!!! deviceId unknown; stopping self and retrying");
|
||||
stopSelf();
|
||||
// Try to restart ourselves in a few seconds
|
||||
|
@ -1444,7 +1412,6 @@ public abstract class SyncManager extends Service implements Runnable {
|
|||
}});
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Run the reconciler and clean up mismatched accounts - if we weren't
|
||||
// running when accounts were deleted, it won't have been called.
|
||||
runAccountReconcilerSync(SyncManager.this);
|
||||
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue