Merge "Fix NPE when cursor is null"
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/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 {