Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cbb98fe authored by Gary Mai's avatar Gary Mai Committed by Android (Google) Code Review
Browse files

Merge "Use new GMSCore broadcast for high res photo syncing" into sc-dev

parents 41cb16a7 9b678a83
Loading
Loading
Loading
Loading
+4 −16
Original line number Diff line number Diff line
@@ -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);
                    ((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
+27 −0
Original line number Diff line number Diff line
@@ -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);
    }
}