diff options
author | Gary Mai <garymai@google.com> | 2021-06-29 15:01:35 -0700 |
---|---|---|
committer | Gary Mai <garymai@google.com> | 2021-06-30 12:41:56 -0700 |
commit | 9b678a835f85a2a3d37ef0536e8aa10101c968d4 (patch) | |
tree | bacae82730d1d52233f6b94e4427816f78120c85 | |
parent | f1e700e960cbd4194b12fcfa2ec201b332f675a3 (diff) | |
download | Contacts-9b678a835f85a2a3d37ef0536e8aa10101c968d4.tar.gz |
Use new GMSCore broadcast for high res photo syncing
Fallback to the previous implementation if receivers aren't found
Test: Manual test with adb logcat -s FSA2_SyncHighResIntentOp to see if
the operation started. Verified high res photo appeared and replaced low
res photo in the app
Bug: 188087909
Change-Id: I49ce0e307c6aa22506705a80173bdb8ba1353606
-rw-r--r-- | src/com/android/contacts/model/ContactLoader.java | 20 | ||||
-rw-r--r-- | src/com/android/contacts/model/account/GoogleAccountType.java | 27 |
2 files changed, 31 insertions, 16 deletions
diff --git a/src/com/android/contacts/model/ContactLoader.java b/src/com/android/contacts/model/ContactLoader.java index cf5442f80..9e690e338 100644 --- a/src/com/android/contacts/model/ContactLoader.java +++ b/src/com/android/contacts/model/ContactLoader.java @@ -887,24 +887,12 @@ public class ContactLoader extends AsyncTaskLoader<Contact> { .getViewContactNotifyServicePackageName(); if (!TextUtils.isEmpty(serviceName) && !TextUtils.isEmpty(servicePackageName)) { final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); - final Intent intent = new Intent(); - intent.setDataAndType(uri, RawContacts.CONTENT_ITEM_TYPE); if (accountType instanceof GoogleAccountType) { - intent.setPackage(servicePackageName); - intent - .setAction("com.google.android.syncadapters.contacts.SYNC_HIGH_RES_PHOTO"); - List<ResolveInfo> broadcastReceivers = - context.getPackageManager().queryBroadcastReceivers(intent, 0); - if (!broadcastReceivers.isEmpty()) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - for (ResolveInfo broadcastReceiver : broadcastReceivers) { - Log.d(TAG, broadcastReceiver.activityInfo.toString()); - } - } - context.sendBroadcast(intent); - continue; - } + ((GoogleAccountType) accountType).handleRawContactViewed(context, uri); + continue; } + final Intent intent = new Intent(); + intent.setData(uri); // TODO: Social Stream API is deprecated, and once the opted-in // sync adapters target Android O+, we won't be able to start their services // since they'll likely be in the background, so we'll need to remove the diff --git a/src/com/android/contacts/model/account/GoogleAccountType.java b/src/com/android/contacts/model/account/GoogleAccountType.java index c7aac7639..14d8a3d7e 100644 --- a/src/com/android/contacts/model/account/GoogleAccountType.java +++ b/src/com/android/contacts/model/account/GoogleAccountType.java @@ -18,10 +18,14 @@ package com.android.contacts.model.account; import android.content.ContentValues; import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.net.Uri; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Relation; +import android.util.Log; import com.android.contacts.R; import com.android.contacts.model.dataitem.DataKind; @@ -203,4 +207,27 @@ public class GoogleAccountType extends BaseAccountType { public String getViewContactNotifyServicePackageName() { return "com.google.android.syncadapters.contacts"; } + + /** + * Sends a broadcast to the sync adapter to trigger a high res photo sync for the contact which + * was viewed + * @param context context to send broadcast in + * @param rawContactUri Uri of the raw contact viewed + */ + public void handleRawContactViewed(Context context, Uri rawContactUri) { + final Intent intent = new Intent(); + intent.setData(rawContactUri); + // New broadcast for syncing high res photo. + intent.setPackage(GoogleAccountType.PLUS_EXTENSION_PACKAGE_NAME); + intent.setAction( + "com.google.android.gms.people.sync.focus.SYNC_HIGH_RES_PHOTO"); + + context.sendBroadcast(intent); + + // Old broadcast. This can be removed in T + intent.setPackage(getViewContactNotifyServicePackageName()); + intent.setAction( + "com.google.android.syncadapters.contacts.SYNC_HIGH_RES_PHOTO"); + context.sendBroadcast(intent); + } } |