OSDN Git Service

Handle IM entries with missing protocol field.
authorEvan Millar <emillar@google.com>
Thu, 8 Oct 2009 17:24:12 +0000 (10:24 -0700)
committerEvan Millar <emillar@google.com>
Thu, 8 Oct 2009 17:41:36 +0000 (10:41 -0700)
Fix bc_triaged bug http://b/issue?id=2174637
Dr. No approval from Tim Sullivan

Change-Id: Ia91c39e91a54e3c58ec94d1c5064a9572519f036

src/com/android/contacts/ContactsUtils.java
src/com/android/contacts/ui/QuickContactWindow.java

index 25da482..5f003de 100644 (file)
@@ -229,6 +229,11 @@ public class ContactsUtils {
      */
     public static Intent buildImIntent(ContentValues values) {
         final boolean isEmail = Email.CONTENT_ITEM_TYPE.equals(values.getAsString(Data.MIMETYPE));
+
+        if (!isEmail && !isProtocolValid(values)) {
+            return null;
+        }
+
         final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK : values.getAsInteger(Im.PROTOCOL);
 
         String host = values.getAsString(Im.CUSTOM_PROTOCOL);
@@ -248,6 +253,19 @@ public class ContactsUtils {
         }
     }
 
+    private static boolean isProtocolValid(ContentValues values) {
+        String protocolString = values.getAsString(Im.PROTOCOL);
+        if (protocolString == null) {
+            return false;
+        }
+        try {
+            Integer.valueOf(protocolString);
+        } catch (NumberFormatException e) {
+            return false;
+        }
+        return true;
+    }
+
     public static Intent getPhotoPickIntent() {
         Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
         intent.setType("image/*");
index 181a2d9..d970b43 100644 (file)
@@ -750,28 +750,30 @@ public class QuickContactWindow implements Window.Callback,
             } else if (Im.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 final boolean isEmail = Email.CONTENT_ITEM_TYPE.equals(
                         getAsString(cursor, Data.MIMETYPE));
-                final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK :
-                        getAsInt(cursor, Im.PROTOCOL);
-
-                if (isEmail) {
-                    // Use Google Talk string when using Email, and clear data
-                    // Uri so we don't try saving Email as primary.
-                    mHeader = context.getText(R.string.chat_gtalk);
-                    mDataUri = null;
-                }
+                if (isEmail || isProtocolValid(cursor)) {
+                    final int protocol = isEmail ? Im.PROTOCOL_GOOGLE_TALK :
+                            getAsInt(cursor, Im.PROTOCOL);
+
+                    if (isEmail) {
+                        // Use Google Talk string when using Email, and clear data
+                        // Uri so we don't try saving Email as primary.
+                        mHeader = context.getText(R.string.chat_gtalk);
+                        mDataUri = null;
+                    }
 
-                String host = getAsString(cursor, Im.CUSTOM_PROTOCOL);
-                String data = getAsString(cursor, isEmail ? Email.DATA : Im.DATA);
-                if (protocol != Im.PROTOCOL_CUSTOM) {
-                    // Try bringing in a well-known host for specific protocols
-                    host = ContactsUtils.lookupProviderNameFromId(protocol);
-                }
+                    String host = getAsString(cursor, Im.CUSTOM_PROTOCOL);
+                    String data = getAsString(cursor, isEmail ? Email.DATA : Im.DATA);
+                    if (protocol != Im.PROTOCOL_CUSTOM) {
+                        // Try bringing in a well-known host for specific protocols
+                        host = ContactsUtils.lookupProviderNameFromId(protocol);
+                    }
 
-                if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) {
-                    final String authority = host.toLowerCase();
-                    final Uri imUri = new Uri.Builder().scheme(Constants.SCHEME_IMTO).authority(
-                            authority).appendPath(data).build();
-                    mIntent = new Intent(Intent.ACTION_SENDTO, imUri);
+                    if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(data)) {
+                        final String authority = host.toLowerCase();
+                        final Uri imUri = new Uri.Builder().scheme(Constants.SCHEME_IMTO).authority(
+                                authority).appendPath(data).build();
+                        mIntent = new Intent(Intent.ACTION_SENDTO, imUri);
+                    }
                 }
             }
 
@@ -784,6 +786,19 @@ public class QuickContactWindow implements Window.Callback,
             mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
         }
 
+        private boolean isProtocolValid(Cursor cursor) {
+            final int columnIndex = cursor.getColumnIndex(Im.PROTOCOL);
+            if (cursor.isNull(columnIndex)) {
+                return false;
+            }
+            try {
+                Integer.valueOf(cursor.getString(columnIndex));
+            } catch (NumberFormatException e) {
+                return false;
+            }
+            return true;
+        }
+
         /** {@inheritDoc} */
         public CharSequence getHeader() {
             return mHeader;