Only add spaces automatically when appropriate.

Bug: 7164981
Change-Id: Id672104a0fda99c52923913fb0e40c3a1ead4787
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index 2f7608a..ed0aedb 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -65,6 +65,7 @@
             final boolean flagAutoComplete =
                     0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
 
+            // TODO: Have a helper method in InputTypeUtils
             // Make sure that passwords are not displayed in {@link SuggestionStripView}.
             if (InputTypeUtils.isPasswordInputType(inputType)
                     || InputTypeUtils.isVisiblePasswordInputType(inputType)
@@ -161,6 +162,10 @@
             Log.i(TAG, "  TYPE_TEXT_FLAG_AUTO_COMPLETE");
     }
 
+    public boolean shouldInsertSpacesAutomatically() {
+        return InputTypeUtils.isAutoSpaceFriendlyType(mInputType);
+    }
+
     // Pretty print
     @Override
     public String toString() {
diff --git a/java/src/com/android/inputmethod/latin/InputTypeUtils.java b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
index 500866a..f1b4131 100644
--- a/java/src/com/android/inputmethod/latin/InputTypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
@@ -29,31 +29,37 @@
             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD;
     private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+    private static final int SUPPRESSING_AUTO_SPACES_FIELD_TYPE =
+            InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
+            | InputType.TYPE_TEXT_VARIATION_PASSWORD
+            | InputType.TYPE_TEXT_VARIATION_URI
+            | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
+            | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
 
     private InputTypeUtils() {
         // This utility class is not publicly instantiable.
     }
 
-    private static boolean isWebEditTextInputType(int inputType) {
+    private static boolean isWebEditTextInputType(final int inputType) {
         return inputType == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
     }
 
-    private static boolean isWebPasswordInputType(int inputType) {
+    private static boolean isWebPasswordInputType(final int inputType) {
         return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
                 && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
     }
 
-    private static boolean isWebEmailAddressInputType(int inputType) {
+    private static boolean isWebEmailAddressInputType(final int inputType) {
         return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
                 && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
     }
 
-    private static boolean isNumberPasswordInputType(int inputType) {
+    private static boolean isNumberPasswordInputType(final int inputType) {
         return NUMBER_PASSWORD_INPUT_TYPE != 0
                 && inputType == NUMBER_PASSWORD_INPUT_TYPE;
     }
 
-    private static boolean isTextPasswordInputType(int inputType) {
+    private static boolean isTextPasswordInputType(final int inputType) {
         return inputType == TEXT_PASSWORD_INPUT_TYPE;
     }
 
@@ -61,12 +67,12 @@
         return variation == TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
     }
 
-    public static boolean isEmailVariation(int variation) {
+    public static boolean isEmailVariation(final int variation) {
         return variation == TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                 || isWebEmailAddressVariation(variation);
     }
 
-    public static boolean isWebInputType(int inputType) {
+    public static boolean isWebInputType(final int inputType) {
         final int maskedInputType =
                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
         return isWebEditTextInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
@@ -74,7 +80,7 @@
     }
 
     // Please refer to TextView.isPasswordInputType
-    public static boolean isPasswordInputType(int inputType) {
+    public static boolean isPasswordInputType(final int inputType) {
         final int maskedInputType =
                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
         return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
@@ -82,9 +88,13 @@
     }
 
     // Please refer to TextView.isVisiblePasswordInputType
-    public static boolean isVisiblePasswordInputType(int inputType) {
+    public static boolean isVisiblePasswordInputType(final int inputType) {
         final int maskedInputType =
                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
         return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
     }
+
+    public static boolean isAutoSpaceFriendlyType(final int inputType) {
+        return 0 == (inputType & SUPPRESSING_AUTO_SPACES_FIELD_TYPE);
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 023619d..3dca9f4 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -2251,7 +2251,9 @@
 
     // This essentially inserts a space, and that's it.
     public void promotePhantomSpace() {
-        sendKeyCodePoint(Keyboard.CODE_SPACE);
+        if (mCurrentSettings.shouldInsertSpacesAutomatically()) {
+            sendKeyCodePoint(Keyboard.CODE_SPACE);
+        }
     }
 
     // Used by the RingCharBuffer
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 2a778aa..6bf37aa 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -271,6 +271,10 @@
         return mPhantomSpacePromotingSymbols.contains(String.valueOf((char)code));
     }
 
+    public boolean shouldInsertSpacesAutomatically() {
+        return mInputAttributes.shouldInsertSpacesAutomatically();
+    }
+
     private static boolean isAutoCorrectEnabled(final Resources res,
             final String currentAutoCorrectionSetting) {
         final String autoCorrectionOff = res.getString(