Don't auto-register IDLE when gaining connection.
We request a sync in this case anyway, which in turn starts the IDLE connection anyway. If we're starting IDLE earlier, we do unnecessary work as the sync will tear it down just a few moments later. Change-Id: I9b99023fbe1aaab72638f6ef9d29223d9a325b7b
This commit is contained in:
parent
cb4fda8286
commit
739281a727
@ -548,10 +548,9 @@ public class ImapService extends Service {
|
|||||||
sExecutor.execute(new Runnable() {
|
sExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ImapService.registerAllImapIdleMailboxes(mContext, mService);
|
// Initiate a sync for all IDLEd accounts, since there might have
|
||||||
|
// been changes while we lost connectivity. At the end of the sync
|
||||||
// Since we could have missed some changes, request a sync
|
// the IDLE connection will be re-established.
|
||||||
// for the IDLEd accounts
|
|
||||||
ContentResolver cr = mContext.getContentResolver();
|
ContentResolver cr = mContext.getContentResolver();
|
||||||
Cursor c = cr.query(Account.CONTENT_URI,
|
Cursor c = cr.query(Account.CONTENT_URI,
|
||||||
Account.CONTENT_PROJECTION, null, null, null);
|
Account.CONTENT_PROJECTION, null, null, null);
|
||||||
@ -1010,35 +1009,6 @@ public class ImapService extends Service {
|
|||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void registerAllImapIdleMailboxes(Context context, IEmailService service) {
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
|
||||||
Cursor c = cr.query(Account.CONTENT_URI, Account.CONTENT_PROJECTION, null, null, null);
|
|
||||||
if (c != null) {
|
|
||||||
try {
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
final Account account = new Account();
|
|
||||||
account.restore(c);
|
|
||||||
|
|
||||||
// Only imap push accounts
|
|
||||||
if (account.getSyncInterval() != Account.CHECK_INTERVAL_PUSH) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!isLegacyImapProtocol(context, account)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
service.pushModify(account.mId);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
LogUtils.d(LOG_TAG, "Failed to call pushModify for account " + account.mId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
c.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void requestSync(Context context, Account account, long mailbox, boolean full) {
|
private static void requestSync(Context context, Account account, long mailbox, boolean full) {
|
||||||
final EmailServiceUtils.EmailServiceInfo info = EmailServiceUtils.getServiceInfoForAccount(
|
final EmailServiceUtils.EmailServiceInfo info = EmailServiceUtils.getServiceInfoForAccount(
|
||||||
context, account.mId);
|
context, account.mId);
|
||||||
|
@ -18,9 +18,6 @@ package com.android.email.service;
|
|||||||
|
|
||||||
import static com.android.emailcommon.Logging.LOG_TAG;
|
import static com.android.emailcommon.Logging.LOG_TAG;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import android.content.AbstractThreadedSyncAdapter;
|
import android.content.AbstractThreadedSyncAdapter;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentProviderClient;
|
import android.content.ContentProviderClient;
|
||||||
@ -48,8 +45,6 @@ public class LegacyImapSyncAdapterService extends PopImapSyncAdapterService {
|
|||||||
// seconds for it to appear. If it takes longer than that, we will fail the sync.
|
// seconds for it to appear. If it takes longer than that, we will fail the sync.
|
||||||
private static final long MAX_WAIT_FOR_SERVICE_MS = 10 * DateUtils.SECOND_IN_MILLIS;
|
private static final long MAX_WAIT_FOR_SERVICE_MS = 10 * DateUtils.SECOND_IN_MILLIS;
|
||||||
|
|
||||||
private static final ExecutorService sExecutor = Executors.newCachedThreadPool();
|
|
||||||
|
|
||||||
private IEmailService mImapService;
|
private IEmailService mImapService;
|
||||||
|
|
||||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
@ -61,15 +56,6 @@ public class LegacyImapSyncAdapterService extends PopImapSyncAdapterService {
|
|||||||
synchronized (mConnection) {
|
synchronized (mConnection) {
|
||||||
mImapService = IEmailService.Stub.asInterface(binder);
|
mImapService = IEmailService.Stub.asInterface(binder);
|
||||||
mConnection.notify();
|
mConnection.notify();
|
||||||
|
|
||||||
// We need to run this task in the background (not in UI-Thread)
|
|
||||||
sExecutor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final Context context = LegacyImapSyncAdapterService.this;
|
|
||||||
ImapService.registerAllImapIdleMailboxes(context, mImapService);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user