Loading k9mail/src/main/java/io/eelo/mail/controller/MessagingController.java +104 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import android.accounts.AccountManager; import android.annotation.SuppressLint; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -116,6 +117,11 @@ import timber.log.Timber; import static io.eelo.mail.K9.MAX_SEND_ATTEMPTS; import static io.eelo.mail.mail.Flag.X_REMOTE_COPY_STARTED; import static io.eelo.mail.account.OAuthConstants.ACCOUNT_EMAIL_ADDRESS_KEY; import static io.eelo.mail.account.OAuthConstants.EELO_ACCOUNT_TYPE; import static io.eelo.mail.account.OAuthConstants.GOOGLE_ACCOUNT_TYPE; import static io.eelo.mail.account.OAuthConstants.MAIL_CONTENT_AUTHORITY; /** * Starts a long running (application) Thread that will run through commands Loading Loading @@ -3443,6 +3449,95 @@ public class MessagingController { context.startActivity(Intent.createChooser(msg, context.getString(R.string.send_alternate_chooser_title))); } private android.accounts.Account[] getEeloAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType( EELO_ACCOUNT_TYPE); } private android.accounts.Account[] getGoogleAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType( GOOGLE_ACCOUNT_TYPE); } private boolean isAccountSignedInOnDevice(AccountManager accountManager, Account account){ try { android.accounts.Account[] eeloAccounts = getEeloAccountsOnDevice(accountManager); android.accounts.Account[] googleAccounts = getGoogleAccountsOnDevice(accountManager); if (account.isDeviceAccount()) { boolean accountIsSignedInOnDevice = false; for (android.accounts.Account eeloAccount : eeloAccounts) { String emailId = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { accountIsSignedInOnDevice = true; break; } } for (android.accounts.Account googleAccount : googleAccounts) { String emailId = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { accountIsSignedInOnDevice = true; break; } } if (accountIsSignedInOnDevice) { return true; } } } catch (SecurityException e) { e.printStackTrace(); } return false; } private boolean isSyncEnabled(AccountManager accountManager, Account account) { try { android.accounts.Account[] eeloAccounts = getEeloAccountsOnDevice(accountManager); android.accounts.Account[] googleAccounts = getGoogleAccountsOnDevice(accountManager); if (account.isDeviceAccount()) { for (android.accounts.Account eeloAccount : eeloAccounts) { String emailId = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { if (ContentResolver.getSyncAutomatically(eeloAccount, MAIL_CONTENT_AUTHORITY)) { account.setAutomaticCheckIntervalMinutes(5); return true; } else { account.setAutomaticCheckIntervalMinutes(-1); return false; } } } for (android.accounts.Account googleAccount : googleAccounts) { String emailId = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { if (ContentResolver.getSyncAutomatically(googleAccount, MAIL_CONTENT_AUTHORITY)) { account.setAutomaticCheckIntervalMinutes(5); return true; } else { account.setAutomaticCheckIntervalMinutes(-1); return false; } } } } } catch (SecurityException e) { e.printStackTrace(); } return false; } /** * Checks mail for one or multiple accounts. If account is null all accounts * are checked. Loading Loading @@ -3483,8 +3578,16 @@ public class MessagingController { } for (final Account account : accounts) { if (account.isDeviceAccount()) { if (isAccountSignedInOnDevice(AccountManager.get(context), account) && isSyncEnabled(AccountManager.get(context), account)) { checkMailForAccount(context, account, ignoreLastCheckedTime, listener); } } else { checkMailForAccount(context, account, ignoreLastCheckedTime, listener); } } } catch (Exception e) { Timber.e(e, "Unable to synchronize mail"); Loading Loading
k9mail/src/main/java/io/eelo/mail/controller/MessagingController.java +104 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import android.accounts.AccountManager; import android.annotation.SuppressLint; import android.content.ContentResolver; import android.content.Context; Loading Loading @@ -116,6 +117,11 @@ import timber.log.Timber; import static io.eelo.mail.K9.MAX_SEND_ATTEMPTS; import static io.eelo.mail.mail.Flag.X_REMOTE_COPY_STARTED; import static io.eelo.mail.account.OAuthConstants.ACCOUNT_EMAIL_ADDRESS_KEY; import static io.eelo.mail.account.OAuthConstants.EELO_ACCOUNT_TYPE; import static io.eelo.mail.account.OAuthConstants.GOOGLE_ACCOUNT_TYPE; import static io.eelo.mail.account.OAuthConstants.MAIL_CONTENT_AUTHORITY; /** * Starts a long running (application) Thread that will run through commands Loading Loading @@ -3443,6 +3449,95 @@ public class MessagingController { context.startActivity(Intent.createChooser(msg, context.getString(R.string.send_alternate_chooser_title))); } private android.accounts.Account[] getEeloAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType( EELO_ACCOUNT_TYPE); } private android.accounts.Account[] getGoogleAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType( GOOGLE_ACCOUNT_TYPE); } private boolean isAccountSignedInOnDevice(AccountManager accountManager, Account account){ try { android.accounts.Account[] eeloAccounts = getEeloAccountsOnDevice(accountManager); android.accounts.Account[] googleAccounts = getGoogleAccountsOnDevice(accountManager); if (account.isDeviceAccount()) { boolean accountIsSignedInOnDevice = false; for (android.accounts.Account eeloAccount : eeloAccounts) { String emailId = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { accountIsSignedInOnDevice = true; break; } } for (android.accounts.Account googleAccount : googleAccounts) { String emailId = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { accountIsSignedInOnDevice = true; break; } } if (accountIsSignedInOnDevice) { return true; } } } catch (SecurityException e) { e.printStackTrace(); } return false; } private boolean isSyncEnabled(AccountManager accountManager, Account account) { try { android.accounts.Account[] eeloAccounts = getEeloAccountsOnDevice(accountManager); android.accounts.Account[] googleAccounts = getGoogleAccountsOnDevice(accountManager); if (account.isDeviceAccount()) { for (android.accounts.Account eeloAccount : eeloAccounts) { String emailId = accountManager.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { if (ContentResolver.getSyncAutomatically(eeloAccount, MAIL_CONTENT_AUTHORITY)) { account.setAutomaticCheckIntervalMinutes(5); return true; } else { account.setAutomaticCheckIntervalMinutes(-1); return false; } } } for (android.accounts.Account googleAccount : googleAccounts) { String emailId = accountManager.getUserData(googleAccount, ACCOUNT_EMAIL_ADDRESS_KEY); if (account.getEmail().equals(emailId)) { if (ContentResolver.getSyncAutomatically(googleAccount, MAIL_CONTENT_AUTHORITY)) { account.setAutomaticCheckIntervalMinutes(5); return true; } else { account.setAutomaticCheckIntervalMinutes(-1); return false; } } } } } catch (SecurityException e) { e.printStackTrace(); } return false; } /** * Checks mail for one or multiple accounts. If account is null all accounts * are checked. Loading Loading @@ -3483,8 +3578,16 @@ public class MessagingController { } for (final Account account : accounts) { if (account.isDeviceAccount()) { if (isAccountSignedInOnDevice(AccountManager.get(context), account) && isSyncEnabled(AccountManager.get(context), account)) { checkMailForAccount(context, account, ignoreLastCheckedTime, listener); } } else { checkMailForAccount(context, account, ignoreLastCheckedTime, listener); } } } catch (Exception e) { Timber.e(e, "Unable to synchronize mail"); Loading