summaryrefslogtreecommitdiff
path: root/src/com/android/exchange/ExchangeBroadcastReceiver.java
blob: 94542e23ddb8a2fb9af43fc52afc2b0b0b6f385e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2013 Google Inc. All Rights Reserved.

package com.android.exchange;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.provider.ContactsContract;

import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.Mailbox;
import com.android.exchange.R.string;
import com.android.mail.utils.LogUtils;

public class ExchangeBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(final Context context, final Intent intent) {
        final Account[] accounts = AccountManager.get(context)
                .getAccountsByType(context.getString(string.account_manager_type_exchange));
        LogUtils.i(Eas.LOG_TAG, "Accounts changed - requesting FolderSync for unsynced accounts");
        for (final Account account : accounts) {
            // Only do a sync for accounts that are not configured to sync any types, since the
            // initial sync will do the right thing if at least one of those is enabled.
            if (!ContentResolver.getSyncAutomatically(account, EmailContent.AUTHORITY) &&
                    !ContentResolver.getSyncAutomatically(account, CalendarContract.AUTHORITY) &&
                    !ContentResolver.getSyncAutomatically(account, ContactsContract.AUTHORITY)) {
                final Bundle bundle = new Bundle(3);
                bundle.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true);
                bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
                bundle.putBoolean(Mailbox.SYNC_EXTRA_ACCOUNT_ONLY, true);
                ContentResolver.requestSync(account, EmailContent.AUTHORITY, bundle);
            }
        }
    }
}