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

Commit 7c34c0a4 authored by Dave Santoro's avatar Dave Santoro
Browse files

Handle removal of local raw contact in profiles.

Bug 5284316

Change-Id: I40160543af3cb717791ee8109f0cbf5d06327111
parent cd27711b
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -323,10 +323,26 @@ public class ContactSaveService extends IntentService {
                if (rawContactId == -1) {
                    throw new IllegalStateException("Could not determine RawContact ID after save");
                }
                final Uri rawContactUri = ContentUris.withAppendedId(
                        isProfile ? Profile.CONTENT_RAW_CONTACTS_URI : RawContacts.CONTENT_URI,
                if (isProfile) {
                    // Since the profile supports local raw contacts, which may have been completely
                    // removed if all information was removed, we need to do a special query to
                    // get the lookup URI for the profile contact (if it still exists).
                    Cursor c = resolver.query(Profile.CONTENT_URI,
                            new String[] {Contacts._ID, Contacts.LOOKUP_KEY},
                            null, null, null);
                    try {
                        c.moveToFirst();
                        final long contactId = c.getLong(0);
                        final String lookupKey = c.getString(1);
                        lookupUri = Contacts.getLookupUri(contactId, lookupKey);
                    } finally {
                        c.close();
                    }
                } else {
                    final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI,
                                    rawContactId);
                    lookupUri = RawContacts.getContactLookupUri(resolver, rawContactUri);
                }
                Log.v(TAG, "Saved contact. New URI: " + lookupUri);
                break;