Protect against IllegalArgumentExceptions when reading contacts.
Also rename contactUri to phoneUri.
Bug:35873712
Test: runtest --path packages/apps/EmergencyInfo/tests/src/com/android/emergency/

Change-Id: I667ac74caf027b19aeeac94bb563c3a6b1cbb416
diff --git a/src/com/android/emergency/EmergencyContactManager.java b/src/com/android/emergency/EmergencyContactManager.java
index b7cce21..0ce3501 100644
--- a/src/com/android/emergency/EmergencyContactManager.java
+++ b/src/com/android/emergency/EmergencyContactManager.java
@@ -36,18 +36,18 @@
 
     /**
      * Returns a {@link Contact} that contains all the relevant information of the contact indexed
-     * by {@code @contactUri}.
+     * by {@code @phoneUri}.
      */
-    public static Contact getContact(Context context, Uri contactUri) {
+    public static Contact getContact(Context context, Uri phoneUri) {
         String phoneNumber = null;
         String phoneType = null;
         String name = null;
         Bitmap photo = null;
         final Uri contactLookupUri =
                 ContactsContract.Contacts.getLookupUri(context.getContentResolver(),
-                        contactUri);
+                        phoneUri);
         Cursor cursor = context.getContentResolver().query(
-                contactUri,
+                phoneUri,
                 new String[]{ContactsContract.Contacts.DISPLAY_NAME,
                         ContactsContract.CommonDataKinds.Phone.NUMBER,
                         ContactsContract.CommonDataKinds.Phone.TYPE,
@@ -73,7 +73,9 @@
                     try {
                         if (cursor2.moveToNext()) {
                             byte[] data = cursor2.getBlob(0);
-                            photo = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
+                            if (data != null) {
+                                photo = BitmapFactory.decodeStream(new ByteArrayInputStream(data));
+                            }
                         }
                     } finally {
                         if (cursor2 != null) {
@@ -87,7 +89,7 @@
                 cursor.close();
             }
         }
-        return new Contact(contactLookupUri, contactUri, name, phoneNumber, phoneType, photo);
+        return new Contact(contactLookupUri, phoneUri, name, phoneNumber, phoneType, photo);
     }
 
     /** Returns whether the phone uri is not null and corresponds to an existing phone number. */
@@ -96,7 +98,7 @@
     }
 
     private static boolean phoneExists(Context context, Uri phoneUri) {
-	Cursor cursor = null;
+        Cursor cursor = null;
         try {
             cursor = context.getContentResolver().query(phoneUri, null, null, null, null);
             if (cursor != null && cursor.moveToFirst()) {
@@ -124,7 +126,7 @@
          * The contact uri is associated to a particular phone number and can be used to reload that
          * number and keep the number displayed in the preferences fresh.
          */
-        private final Uri mContactUri;
+        private final Uri mPhoneUri;
         /** The display name of the contact. */
         private final String mName;
         /** The emergency contact's phone number selected by the user. */
@@ -136,13 +138,13 @@
 
         /** Constructs a new contact. */
         public Contact(Uri contactLookupUri,
-                       Uri contactUri,
+                       Uri phoneUri,
                        String name,
                        String phoneNumber,
                        String phoneType,
                        Bitmap photo) {
             mContactLookupUri = contactLookupUri;
-            mContactUri = contactUri;
+            mPhoneUri = phoneUri;
             mName = name;
             mPhoneNumber = phoneNumber;
             mPhoneType = phoneType;
@@ -155,12 +157,12 @@
         }
 
         /**
-         * The contact uri as defined in ContactsContract.CommonDataKinds.Phone.CONTENT_URI. Use
+         * The phone uri as defined in ContactsContract.CommonDataKinds.Phone.CONTENT_URI. Use
          * this to reload the contact. This links to a particular phone number of the emergency
-         * contact
+         * contact.
          */
-        public Uri getContactUri() {
-            return mContactUri;
+        public Uri getPhoneUri() {
+            return mPhoneUri;
         }
 
         /** Returns the display name of the contact. */