Merge "Make vertical ratio for dialpad more visible."
diff --git a/src/com/android/contacts/detail/ContactLoaderFragment.java b/src/com/android/contacts/detail/ContactLoaderFragment.java
index 692c2ea..008aff8 100644
--- a/src/com/android/contacts/detail/ContactLoaderFragment.java
+++ b/src/com/android/contacts/detail/ContactLoaderFragment.java
@@ -33,7 +33,9 @@
 import android.content.Loader;
 import android.media.RingtoneManager;
 import android.net.Uri;
+import android.os.AsyncTask;
 import android.os.Bundle;
+import android.provider.ContactsContract;
 import android.provider.ContactsContract.Contacts;
 import android.util.Log;
 import android.view.KeyEvent;
@@ -289,7 +291,13 @@
                 if (mContactData == null) return false;
 
                 final String lookupKey = mContactData.getLookupKey();
-                final Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
+                Uri shareUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey);
+                if (mContactData.isUserProfile()) {
+                    // User is sharing the profile.  We don't want to force the receiver to have
+                    // the highly-privileged READ_PROFILE permission, so we need to request a
+                    // pre-authorized URI from the provider.
+                    shareUri = getPreAuthorizedUri(shareUri);
+                }
 
                 final Intent intent = new Intent(Intent.ACTION_SEND);
                 intent.setType(Contacts.CONTENT_VCARD_TYPE);
@@ -319,6 +327,25 @@
         return false;
     }
 
+    /**
+     * Calls into the contacts provider to get a pre-authorized version of the given URI.
+     */
+    private Uri getPreAuthorizedUri(Uri uri) {
+        Bundle uriBundle = new Bundle();
+        uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri);
+        Bundle authResponse = mContext.getContentResolver().call(
+                ContactsContract.AUTHORITY_URI,
+                ContactsContract.Authorization.AUTHORIZATION_METHOD,
+                null,
+                uriBundle);
+        if (authResponse != null) {
+            return (Uri) authResponse.getParcelable(
+                    ContactsContract.Authorization.KEY_AUTHORIZED_URI);
+        } else {
+            return uri;
+        }
+    }
+
     @Override
     public boolean handleKeyDown(int keyCode) {
         switch (keyCode) {