Cherry-pick Fix for GB upgrade issue with phone lookups.

This is a cherrypick from master for this CL
Iea81bc4163cb89169946f9a33f9e15b13e8868ad

This just generalizes a fix that Shaopeng had for Brazilian phone
numbers, in which it was possible that the caller ID number being
checked was shorter than the normalized number we had stored.  We
essentially accept a phone number as a match if the shorter of
either (caller ID, normalized number) is a trailing prefix of the
other.

Bug: 5638376
Change-Id: Id61d5295272106a05af14d3c2ce1695eaf2dd372
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index b1e5b6d..8940c61 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -4209,20 +4209,20 @@
                 sb.append(',');
                 sb.append(numberLen);
                 sb.append(" - lookup.len + 1) = lookup.normalized_number");
+
                 // Some countries (e.g. Brazil) can have incoming calls which contain only the local
                 // number (no country calling code and no area code). This case is handled below.
                 // Details see b/5197612.
-                if (!hasNumberE164) {
-                  sb.append(" OR (");
-                  sb.append(" lookup.len > ");
-                  sb.append(numberLen);
-                  sb.append(" AND substr(lookup.normalized_number,");
-                  sb.append("lookup.len + 1 - ");
-                  sb.append(numberLen);
-                  sb.append(") = ");
-                  DatabaseUtils.appendEscapedSQLString(sb, number);
-                  sb.append(")");
-                }
+                // This also handles a Gingerbread -> ICS upgrade issue; see b/5638376.
+                sb.append(" OR (");
+                sb.append(" lookup.len > ");
+                sb.append(numberLen);
+                sb.append(" AND substr(lookup.normalized_number,");
+                sb.append("lookup.len + 1 - ");
+                sb.append(numberLen);
+                sb.append(") = ");
+                DatabaseUtils.appendEscapedSQLString(sb, number);
+                sb.append(")");
             }
             sb.append(')');
         }