Fix viewing legacy and raw contact URI on tablet

Bug: 5220640
Change-Id: I85c748389921bdff2639fff5f7713e00ba7f9f8c
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index c9fbeae..c711b6c 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -19,6 +19,7 @@
 import com.android.contacts.model.AccountType;
 import com.android.contacts.model.AccountTypeManager;
 import com.android.contacts.model.AccountTypeWithDataSet;
+import com.android.contacts.util.ContactLoaderUtils;
 import com.android.contacts.util.DataStatus;
 import com.android.contacts.util.StreamItemEntry;
 import com.android.contacts.util.StreamItemPhotoEntry;
@@ -681,7 +682,8 @@
         protected Result doInBackground(Void... args) {
             try {
                 final ContentResolver resolver = getContext().getContentResolver();
-                final Uri uriCurrentFormat = ensureIsContactUri(resolver, mLookupUri);
+                final Uri uriCurrentFormat = ContactLoaderUtils.ensureIsContactUri(
+                        resolver, mLookupUri);
                 Result result = loadContactEntity(resolver, uriCurrentFormat);
                 if (!result.isNotFound()) {
                     if (result.isDirectoryEntry()) {
@@ -706,47 +708,6 @@
             }
         }
 
-        /**
-         * Transforms the given Uri and returns a Lookup-Uri that represents the contact.
-         * For legacy contacts, a raw-contact lookup is performed.
-         * @param resolver
-         */
-        private Uri ensureIsContactUri(final ContentResolver resolver, final Uri uri) {
-            if (uri == null) throw new IllegalArgumentException("uri must not be null");
-
-            final String authority = uri.getAuthority();
-
-            // Current Style Uri?
-            if (ContactsContract.AUTHORITY.equals(authority)) {
-                final String type = resolver.getType(uri);
-                // Contact-Uri? Good, return it
-                if (Contacts.CONTENT_ITEM_TYPE.equals(type)) {
-                    return uri;
-                }
-
-                // RawContact-Uri? Transform it to ContactUri
-                if (RawContacts.CONTENT_ITEM_TYPE.equals(type)) {
-                    final long rawContactId = ContentUris.parseId(uri);
-                    return RawContacts.getContactLookupUri(getContext().getContentResolver(),
-                            ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
-                }
-
-                // Anything else? We don't know what this is
-                throw new IllegalArgumentException("uri format is unknown");
-            }
-
-            // Legacy Style? Convert to RawContact
-            final String OBSOLETE_AUTHORITY = "contacts";
-            if (OBSOLETE_AUTHORITY.equals(authority)) {
-                // Legacy Format. Convert to RawContact-Uri and then lookup the contact
-                final long rawContactId = ContentUris.parseId(uri);
-                return RawContacts.getContactLookupUri(resolver,
-                        ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
-            }
-
-            throw new IllegalArgumentException("uri authority is unknown");
-        }
-
         private Result loadContactEntity(ContentResolver resolver, Uri contactUri) {
             Uri entityUri = Uri.withAppendedPath(contactUri, Contacts.Entity.CONTENT_DIRECTORY);
             Cursor cursor = resolver.query(entityUri, ContactQuery.COLUMNS, null, null,