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

Commit 3bb8514a authored by Marcus Hagerott's avatar Marcus Hagerott
Browse files

Return display_name after joining multiple contacts.

The ContactSaveService includes the display name of the resulting
contact in the data bundle when several contacts are joined.

Bug: 29687036
Change-Id: I14c0ae151178d279a4c0c71f574247cc645cfea9
parent df8e73c1
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ public class ContactSaveService extends IntentService {
    public static final String EXTRA_CONTACT_URI = "contactUri";
    public static final String EXTRA_CONTACT_IDS = "contactIds";
    public static final String EXTRA_STARRED_FLAG = "starred";
    public static final String EXTRA_DISPLAY_NAME = "extraDisplayName";

    public static final String ACTION_SET_SUPER_PRIMARY = "setSuperPrimary";
    public static final String ACTION_CLEAR_PRIMARY = "clearPrimary";
@@ -1293,6 +1294,7 @@ public class ContactSaveService extends IntentService {

    private void joinSeveralContacts(Intent intent) {
        final long[] contactIds = intent.getLongArrayExtra(EXTRA_CONTACT_IDS);

        final ResultReceiver receiver = intent.getParcelableExtra(EXTRA_RESULT_RECEIVER);

        // Load raw contact IDs for all contacts involved.
@@ -1334,15 +1336,39 @@ public class ContactSaveService extends IntentService {
            }
            return;
        }

        if (receiver != null) {
            final Bundle result = new Bundle();
            result.putSerializable(EXTRA_RAW_CONTACT_IDS, separatedRawContactIds);
            result.putString(EXTRA_DISPLAY_NAME, queryNameOfLinkedContacts(contactIds));
            receiver.send(CONTACTS_LINKED, result);
        } else {
            showToast(R.string.contactsJoinedMessage);
        }
    }

    // Get the display name of the top-level contact after the contacts have been linked.
    private String queryNameOfLinkedContacts(long[] contactIds) {
        final StringBuilder whereBuilder = new StringBuilder(Contacts._ID).append(" IN (");
        final String[] whereArgs = new String[contactIds.length];
        for (int i = 0; i < contactIds.length; i++) {
            whereArgs[i] = String.valueOf(contactIds[i]);
            whereBuilder.append("?,");
        }
        whereBuilder.deleteCharAt(whereBuilder.length() - 1).append(')');
        final Cursor cursor = getContentResolver().query(Contacts.CONTENT_URI,
                new String[]{Contacts.DISPLAY_NAME}, whereBuilder.toString(), whereArgs, null);
        try {
            if (cursor.moveToFirst()) {
                return cursor.getString(0);
            }
            return null;
        } finally {
            cursor.close();
        }
    }


    /** Returns true if the batch was successfully applied and false otherwise. */
    private boolean applyOperations(ContentResolver resolver,
            ArrayList<ContentProviderOperation> operations) {