Fix crash from using third party gallery apps

Some third party apps return unexpected URI's when photos are
cropped. An example is the Piktures app.
Instead of trusting their URI returned in the intent, copy the
photo from theirs into one which was generated by us and use that.

Test: Verified saving a contact with a picture that was cropped
from the Piktures app doesn't crash.

Bug: 33617676
Change-Id: I33e8922e5d89fabfcb90009d32b82a8a3f26c262
diff --git a/src/com/android/contacts/detail/PhotoSelectionHandler.java b/src/com/android/contacts/detail/PhotoSelectionHandler.java
index d2e5763..dbd36a4 100644
--- a/src/com/android/contacts/detail/PhotoSelectionHandler.java
+++ b/src/com/android/contacts/detail/PhotoSelectionHandler.java
@@ -127,17 +127,16 @@
             switch (requestCode) {
                 // Cropped photo was returned
                 case REQUEST_CROP_PHOTO: {
-                    final Uri uri;
                     if (data != null && data.getData() != null) {
-                        uri = data.getData();
-                    } else {
-                        uri = mCroppedPhotoUri;
+                        final Uri croppedUri = data.getData();
+                        ContactPhotoUtils.savePhotoFromUriToUri(mContext, croppedUri,
+                                mCroppedPhotoUri, /* deleteAfterSave */ false);
                     }
 
                     try {
                         // delete the original temporary photo if it exists
                         mContext.getContentResolver().delete(mTempPhotoUri, null, null);
-                        listener.onPhotoSelected(uri);
+                        listener.onPhotoSelected(mCroppedPhotoUri);
                         return true;
                     } catch (FileNotFoundException e) {
                         return false;