diff options
| author | Scott Mertz <scott@cyngn.com> | 2014-10-01 11:20:35 -0700 |
|---|---|---|
| committer | LorDClockaN <davor@losinj.com> | 2014-10-02 20:41:48 +0200 |
| commit | 0fecdd24c043c6fcb7ca579801adc5f09cadf38a (patch) | |
| tree | 95ff2fe803a9429c981b676377255ac97b1291b9 | |
| parent | 5f1f4553eeb452a02f18405a15ec2963539284b5 (diff) | |
Fixes CYAN-5472
Change-Id: I17700110c6e2bf79baba7103aebb1077258982b5
| -rw-r--r-- | src/com/android/exchange/service/ContactsSyncAdapterService.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/com/android/exchange/service/ContactsSyncAdapterService.java b/src/com/android/exchange/service/ContactsSyncAdapterService.java index 0be647e0..3e699b3e 100644 --- a/src/com/android/exchange/service/ContactsSyncAdapterService.java +++ b/src/com/android/exchange/service/ContactsSyncAdapterService.java @@ -20,6 +20,7 @@ import android.accounts.Account; import android.content.AbstractThreadedSyncAdapter; import android.content.ContentProviderClient; import android.content.ContentResolver; +import android.content.ContentValues; import android.content.Context; import android.content.SyncResult; import android.database.Cursor; @@ -27,6 +28,7 @@ import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract.Groups; import android.provider.ContactsContract.RawContacts; +import android.provider.ContactsContract.Settings; import android.util.Log; import com.android.emailcommon.provider.EmailContent; @@ -72,10 +74,44 @@ public class ContactsSyncAdapterService extends AbstractSyncAdapterService { LogUtils.i(TAG, "onPerformSync Contacts starting %s", extras.toString()); } ContactsSyncAdapterService.performSync(getContext(), account, extras); + ContactsSyncAdapterService.maybeSetAccountContactsVisibility(getContext(), account); LogUtils.d(TAG, "onPerformSync Contacts finished"); } } + private static void maybeSetAccountContactsVisibility(Context context, Account account) { + String[] projection = new String[]{ + Settings.ACCOUNT_NAME, + Settings.ACCOUNT_TYPE + }; + String selection = Settings.ACCOUNT_NAME + "=? AND " + + Settings.ACCOUNT_TYPE + "=?"; + String[] selectionArgs = new String[]{ + account.name, + account.type + }; + ContentResolver resolver = context.getContentResolver(); + Cursor c = resolver.query(Settings.CONTENT_URI, + projection, selection, selectionArgs, null); + if (c != null) { + if (c.getCount() == 0) { + LogUtils.d(TAG, "setting account visibility true for account: " + account.name); + setAccountContactsVisibility(context, account, true); + } + c.close(); + } + } + + private static void setAccountContactsVisibility(Context context, Account account, + boolean visible) { + ContentValues values = new ContentValues(); + values.put(RawContacts.ACCOUNT_NAME, account.name); + values.put(RawContacts.ACCOUNT_TYPE, account.type); + values.put(Settings.UNGROUPED_VISIBLE, visible ? 1 : 0); + + context.getContentResolver().insert(Settings.CONTENT_URI, values); + } + private static boolean hasDirtyRows(ContentResolver resolver, Uri uri, String dirtyColumn) { Cursor c = resolver.query(uri, EmailContent.ID_PROJECTION, dirtyColumn + "=1", null, null); try { |
