Merge "Try to show the "right" name on the compact contact editor"
diff --git a/src/com/android/contacts/activities/AttachPhotoActivity.java b/src/com/android/contacts/activities/AttachPhotoActivity.java
index bc1de8a..262c602 100644
--- a/src/com/android/contacts/activities/AttachPhotoActivity.java
+++ b/src/com/android/contacts/activities/AttachPhotoActivity.java
@@ -167,7 +167,10 @@
             // we can add the FLAG_GRANT_WRITE_URI_PERMISSION flag to the eventual
             // crop intent for read-only URI's.
             // TODO: With b/10837468 fixed should be able to avoid this copy.
-            ContactPhotoUtils.savePhotoFromUriToUri(this, inputUri, mTempPhotoUri, false);
+            if (!ContactPhotoUtils.savePhotoFromUriToUri(this, inputUri, mTempPhotoUri, false)) {
+                finish();
+                return;
+            }
             toCrop = mTempPhotoUri;
 
             final Intent intent = new Intent("com.android.camera.action.CROP", toCrop);
diff --git a/src/com/android/contacts/detail/PhotoSelectionHandler.java b/src/com/android/contacts/detail/PhotoSelectionHandler.java
index 9919773..8b9a381 100644
--- a/src/com/android/contacts/detail/PhotoSelectionHandler.java
+++ b/src/com/android/contacts/detail/PhotoSelectionHandler.java
@@ -161,8 +161,10 @@
                     } else {
                         toCrop = mTempPhotoUri;
                         try {
-                            ContactPhotoUtils.savePhotoFromUriToUri(mContext, uri,
-                                    toCrop, false);
+                            if (!ContactPhotoUtils.savePhotoFromUriToUri(mContext, uri,
+                                            toCrop, false)) {
+                                return false;
+                            }
                         } catch (SecurityException e) {
                             Log.d(TAG, "Did not have read-access to uri : " + uri);
                             return false;
diff --git a/src/com/android/contacts/interactions/ContactDeletionInteraction.java b/src/com/android/contacts/interactions/ContactDeletionInteraction.java
index f3db36c..b10963b 100644
--- a/src/com/android/contacts/interactions/ContactDeletionInteraction.java
+++ b/src/com/android/contacts/interactions/ContactDeletionInteraction.java
@@ -32,6 +32,7 @@
 import android.os.Bundle;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Contacts.Entity;
+import android.util.Log;
 
 import com.android.contacts.ContactSaveService;
 import com.android.contacts.R;
@@ -48,6 +49,7 @@
 public class ContactDeletionInteraction extends Fragment
         implements LoaderCallbacks<Cursor>, OnDismissListener {
 
+    private static final String TAG = "ContactDeletionInteraction";
     private static final String FRAGMENT_TAG = "deleteContact";
 
     private static final String KEY_ACTIVE = "active";
@@ -224,6 +226,11 @@
             return;
         }
 
+        if (cursor == null || cursor.isClosed()) {
+            Log.e(TAG, "Failed to load contacts");
+            return;
+        }
+
         long contactId = 0;
         String lookupKey = null;
 
diff --git a/src/com/android/contacts/util/ContactPhotoUtils.java b/src/com/android/contacts/util/ContactPhotoUtils.java
index 53ea396..01f8267 100644
--- a/src/com/android/contacts/util/ContactPhotoUtils.java
+++ b/src/com/android/contacts/util/ContactPhotoUtils.java
@@ -148,6 +148,9 @@
      */
     public static boolean savePhotoFromUriToUri(Context context, Uri inputUri, Uri outputUri,
             boolean deleteAfterSave) {
+        if (inputUri == null || outputUri == null) {
+            return false;
+        }
         FileOutputStream outputStream = null;
         InputStream inputStream = null;
         try {