Home | History | Annotate | Download | only in exchange
      1 // Copyright 2013 Google Inc. All Rights Reserved.
      2 
      3 package com.android.exchange;
      4 
      5 import android.accounts.Account;
      6 import android.accounts.AccountManager;
      7 import android.content.BroadcastReceiver;
      8 import android.content.ContentResolver;
      9 import android.content.Context;
     10 import android.content.Intent;
     11 import android.os.Bundle;
     12 import android.provider.CalendarContract;
     13 import android.provider.ContactsContract;
     14 
     15 import com.android.emailcommon.provider.EmailContent;
     16 import com.android.emailcommon.provider.Mailbox;
     17 import com.android.exchange.R.string;
     18 import com.android.mail.utils.LogUtils;
     19 
     20 public class ExchangeBroadcastReceiver extends BroadcastReceiver {
     21 
     22     @Override
     23     public void onReceive(final Context context, final Intent intent) {
     24         final Account[] accounts = AccountManager.get(context)
     25                 .getAccountsByType(context.getString(string.account_manager_type_exchange));
     26         LogUtils.i(Eas.LOG_TAG, "Accounts changed - requesting FolderSync for unsynced accounts");
     27         for (final Account account : accounts) {
     28             // Only do a sync for accounts that are not configured to sync any types, since the
     29             // initial sync will do the right thing if at least one of those is enabled.
     30             if (!ContentResolver.getSyncAutomatically(account, EmailContent.AUTHORITY) &&
     31                     !ContentResolver.getSyncAutomatically(account, CalendarContract.AUTHORITY) &&
     32                     !ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
     33                 final Bundle bundle = new Bundle(3);
     34                 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
     35                 bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
     36                 bundle.putBoolean(Mailbox.SYNC_EXTRA_ACCOUNT_ONLY, true);
     37                 ContentResolver.requestSync(account, EmailContent.AUTHORITY, bundle);
     38             }
     39         }
     40     }
     41 }
     42