Send RESULT_CANCELED when missing, return legacy Uris.
When no contact was persisted (for example a save that has
been trimmed to a no-op) we return RESULT_CANCELED.
When an Intent like ACTION_INSERT requests a legacy Uri we
correctly return a legacy Uri instead of lookup-style.
Fixes http://b/2219805 and http://b/2219813
diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java
index 94b8020..914a2e8 100644
--- a/src/com/android/contacts/ui/EditContactActivity.java
+++ b/src/com/android/contacts/ui/EditContactActivity.java
@@ -720,10 +720,28 @@
private void onSaveCompleted(boolean success, int saveMode, Uri contactLookupUri) {
switch (saveMode) {
case SAVE_MODE_DEFAULT:
- if (success) {
- Intent intent = new Intent();
- intent.setData(contactLookupUri);
- setResult(RESULT_OK, intent);
+ if (success && contactLookupUri != null) {
+ final Intent resultIntent = new Intent();
+
+ final Uri requestData = getIntent().getData();
+ final String requestAuthority = requestData == null ? null : requestData
+ .getAuthority();
+
+ if (android.provider.Contacts.AUTHORITY.equals(requestAuthority)) {
+ // Build legacy Uri when requested by caller
+ final long contactId = ContentUris.parseId(Contacts.lookupContact(
+ getContentResolver(), contactLookupUri));
+ final Uri legacyUri = ContentUris.withAppendedId(
+ android.provider.Contacts.People.CONTENT_URI, contactId);
+ resultIntent.setData(legacyUri);
+ } else {
+ // Otherwise pass back a lookup-style Uri
+ resultIntent.setData(contactLookupUri);
+ }
+
+ setResult(RESULT_OK, resultIntent);
+ } else {
+ setResult(RESULT_CANCELED, null);
}
finish();
break;