Fix NPE when phone number or email is null

Don't crash if phone number or email address is null; instead, skip the
entry.

Bug:12821628
Change-Id: I3f5de7926278fb54941f9cdb59e9366060d420eb
(cherry picked from commit 89095c7a4bb85a54d7e6c56322a7fcbf0b60f93e)
diff --git a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
index d1fa282..36e96a2 100644
--- a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
+++ b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
@@ -199,39 +199,43 @@
         // Phones
         ArrayList<ValuesDelta> phones = state.getMimeEntries(Phone.CONTENT_ITEM_TYPE);
         if (phones != null) {
-            for (int i = 0; i < phones.size(); i++) {
-                ValuesDelta phone = phones.get(i);
-                final String phoneNumber = PhoneNumberUtils.formatNumber(
-                        phone.getPhoneNumber(),
-                        phone.getPhoneNormalizedNumber(),
+            boolean isFirstPhoneBound = true;
+            for (ValuesDelta phone : phones) {
+                final String phoneNumber = phone.getPhoneNumber();
+                if (TextUtils.isEmpty(phoneNumber)) {
+                    continue;
+                }
+                final String formattedNumber = PhoneNumberUtils.formatNumber(
+                        phoneNumber, phone.getPhoneNormalizedNumber(),
                         GeoUtil.getCurrentCountryIso(getContext()));
-                final CharSequence phoneType;
+                CharSequence phoneType = null;
                 if (phone.phoneHasType()) {
                     phoneType = Phone.getTypeLabel(
                             res, phone.getPhoneType(), phone.getPhoneLabel());
-                } else {
-                    phoneType = null;
                 }
-                bindData(mContext.getText(R.string.phoneLabelsGroup), phoneNumber, phoneType,
-                        i == 0, true);
+                bindData(mContext.getText(R.string.phoneLabelsGroup), formattedNumber,
+                        phoneType, isFirstPhoneBound, true);
+                isFirstPhoneBound = false;
             }
         }
 
         // Emails
         ArrayList<ValuesDelta> emails = state.getMimeEntries(Email.CONTENT_ITEM_TYPE);
         if (emails != null) {
-            for (int i = 0; i < emails.size(); i++) {
-                ValuesDelta email = emails.get(i);
+            boolean isFirstEmailBound = true;
+            for (ValuesDelta email : emails) {
                 final String emailAddress = email.getEmailData();
-                final CharSequence emailType;
+                if (TextUtils.isEmpty(emailAddress)) {
+                    continue;
+                }
+                CharSequence emailType = null;
                 if (email.emailHasType()) {
                     emailType = Email.getTypeLabel(
                             res, email.getEmailType(), email.getEmailLabel());
-                } else {
-                    emailType = null;
                 }
                 bindData(mContext.getText(R.string.emailLabelsGroup), emailAddress, emailType,
-                        i == 0);
+                        isFirstEmailBound);
+                isFirstEmailBound = false;
             }
         }