Trim edit fields that don't contain printable values.
When persisting edit changes, trim data rows that have no
printable characters. Also wrote unit tests for new method
and building of IM intents to check Uri escaping.
Fixes http://b/2173811
diff --git a/src/com/android/contacts/ContactsUtils.java b/src/com/android/contacts/ContactsUtils.java
index 5f003de..1e3b8ad 100644
--- a/src/com/android/contacts/ContactsUtils.java
+++ b/src/com/android/contacts/ContactsUtils.java
@@ -416,4 +416,12 @@
Uri.fromParts("sms", phoneNumber.toString(), null));
context.startActivity(intent);
}
+
+ /**
+ * Test if the given {@link CharSequence} contains any graphic characters,
+ * first checking {@link TextUtils#isEmpty(CharSequence)} to handle null.
+ */
+ public static boolean isGraphic(CharSequence str) {
+ return !TextUtils.isEmpty(str) && TextUtils.isGraphic(str);
+ }
}
diff --git a/src/com/android/contacts/model/EntityModifier.java b/src/com/android/contacts/model/EntityModifier.java
index 5700df2..519ff80 100644
--- a/src/com/android/contacts/model/EntityModifier.java
+++ b/src/com/android/contacts/model/EntityModifier.java
@@ -16,6 +16,7 @@
package com.android.contacts.model;
+import com.android.contacts.ContactsUtils;
import com.android.contacts.model.ContactsSource.DataKind;
import com.android.contacts.model.ContactsSource.EditField;
import com.android.contacts.model.ContactsSource.EditType;
@@ -412,7 +413,7 @@
for (EditField field : kind.fieldList) {
// If any field has values, we're not empty
final String value = values.getAsString(field.column);
- if (!TextUtils.isEmpty(value)) {
+ if (ContactsUtils.isGraphic(value)) {
hasValues = true;
}
}
@@ -437,12 +438,12 @@
final ValuesDelta child = state.getPrimaryEntry(StructuredName.CONTENT_ITEM_TYPE);
final String name = extras.getString(Insert.NAME);
- if (!TextUtils.isEmpty(name) && TextUtils.isGraphic(name)) {
+ if (ContactsUtils.isGraphic(name)) {
child.put(StructuredName.GIVEN_NAME, name);
}
final String phoneticName = extras.getString(Insert.PHONETIC_NAME);
- if (!TextUtils.isEmpty(phoneticName) && TextUtils.isGraphic(phoneticName)) {
+ if (ContactsUtils.isGraphic(phoneticName)) {
child.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticName);
}
}
diff --git a/src/com/android/contacts/ui/widget/GenericEditorView.java b/src/com/android/contacts/ui/widget/GenericEditorView.java
index 26d4aab..8b50551 100644
--- a/src/com/android/contacts/ui/widget/GenericEditorView.java
+++ b/src/com/android/contacts/ui/widget/GenericEditorView.java
@@ -16,6 +16,7 @@
package com.android.contacts.ui.widget;
+import com.android.contacts.ContactsUtils;
import com.android.contacts.R;
import com.android.contacts.model.Editor;
import com.android.contacts.model.EntityDelta;
@@ -222,7 +223,7 @@
});
// Hide field when empty and optional value
- final boolean couldHide = (TextUtils.isEmpty(value) && field.optional);
+ final boolean couldHide = (!ContactsUtils.isGraphic(value) && field.optional);
final boolean willHide = (mHideOptional && couldHide);
fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE);
fieldView.setEnabled(enabled);
@@ -255,7 +256,7 @@
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
final String customText = customType.getText().toString().trim();
- if (!TextUtils.isEmpty(customText)) {
+ if (ContactsUtils.isGraphic(customText)) {
// Now we're sure it's ok to actually change the type value.
mType = mPendingType;
mPendingType = null;