FP2-1501: [ST_2][Amaze]"Unfortunately, Contacts has stopped" pops up when open a file by contacts

Fix ContactLoader IllegalArgumentException crash
Display toast instead of crashing when unable to load contact due to
acore crash or invalid URI.
AOSP-Bug: 18689131

JIRA ID:FPII-1501

Change-Id: Iaa05d00ebd8ccb0dffcc58ae27aa3ac203a5c953
diff --git a/src/com/android/contacts/list/ContactBrowseListFragment.java b/src/com/android/contacts/list/ContactBrowseListFragment.java
index 855f923..2381ea5 100644
--- a/src/com/android/contacts/list/ContactBrowseListFragment.java
+++ b/src/com/android/contacts/list/ContactBrowseListFragment.java
@@ -126,6 +126,9 @@
 
                 Log.e(TAG, "Error: No contact ID or lookup key for contact " + mUri);
                 return null;
+            } catch (Exception e) {
+                Log.e(TAG, "Error loading the contact: " + mUri, e);
+                return null;
             } finally {
                 if (cursor != null) {
                     cursor.close();
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 000e0a2..e7d1c0d 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -1761,30 +1761,37 @@
         @Override
         public void onLoadFinished(Loader<Contact> loader, Contact data) {
             Trace.beginSection("onLoadFinished()");
-
-            if (isFinishing()) {
-                return;
-            }
-            if (data.isError()) {
-                // This shouldn't ever happen, so throw an exception. The {@link ContactLoader}
-                // should log the actual exception.
-                throw new IllegalStateException("Failed to load contact", data.getException());
-            }
-            if (data.isNotFound()) {
-                if (mHasAlreadyBeenOpened) {
-                    finish();
-                } else {
-                    Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri());
+            try {
+                
+                if (isFinishing()) {
+                    return;
+                }
+                if (data.isError()) {
+                    // This means either the contact is invalid or we had an
+                    // internal error such as an acore crash.
+                    Log.i(TAG, "Failed to load contact: " + ((ContactLoader)loader).getLookupUri());
                     Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage,
                             Toast.LENGTH_LONG).show();
                     finish();
+                    return;
                 }
-                return;
+                if (data.isNotFound()) {
+                    if (mHasAlreadyBeenOpened) {
+                        finish();
+                    } else {
+                        Log.i(TAG, "No contact found: " + ((ContactLoader)loader).getLookupUri());
+                        Toast.makeText(QuickContactActivity.this, R.string.invalidContactMessage,
+                                Toast.LENGTH_LONG).show();
+                        finish();
+                    }
+                    return;
+                }
+
+                bindContactData(data);
+                
+            } finally {
+                Trace.endSection();
             }
-
-            bindContactData(data);
-
-            Trace.endSection();
         }
 
         @Override