Remove unused supportsSwitchingToShortcutIme attribute

Change-Id: I51c5247ac925a158facb79057f704b763b903552
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 775a90c..a1f478b 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -437,7 +437,6 @@
         <attr name="navigatePrevious" format="boolean" />
         <attr name="passwordInput" format="boolean" />
         <attr name="clobberSettingsKey" format="boolean" />
-        <attr name="supportsSwitchingToShortcutIme" format="boolean" />
         <attr name="hasShortcutKey" format="boolean" />
         <attr name="languageSwitchKeyEnabled" format="boolean" />
         <attr name="isMultiLine" format="boolean" />
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 93a55fe..3c11675 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -70,7 +70,6 @@
     public final int mElementId;
     public final EditorInfo mEditorInfo;
     public final boolean mClobberSettingsKey;
-    public final boolean mSupportsSwitchingToShortcutIme;
     public final boolean mLanguageSwitchKeyEnabled;
     public final String mCustomActionLabel;
     public final boolean mHasShortcutKey;
@@ -86,11 +85,10 @@
         mElementId = elementId;
         mEditorInfo = params.mEditorInfo;
         mClobberSettingsKey = params.mNoSettingsKey;
-        mSupportsSwitchingToShortcutIme = params.mSupportsSwitchingToShortcutIme;
         mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
         mCustomActionLabel = (mEditorInfo.actionLabel != null)
                 ? mEditorInfo.actionLabel.toString() : null;
-        mHasShortcutKey = mSupportsSwitchingToShortcutIme && params.mShowsVoiceInputKey;
+        mHasShortcutKey = params.mVoiceInputKeyEnabled;
 
         mHashCode = computeHashCode(this);
     }
@@ -103,7 +101,6 @@
                 id.mHeight,
                 id.passwordInput(),
                 id.mClobberSettingsKey,
-                id.mSupportsSwitchingToShortcutIme,
                 id.mHasShortcutKey,
                 id.mLanguageSwitchKeyEnabled,
                 id.isMultiLine(),
@@ -124,7 +121,6 @@
                 && other.mHeight == mHeight
                 && other.passwordInput() == passwordInput()
                 && other.mClobberSettingsKey == mClobberSettingsKey
-                && other.mSupportsSwitchingToShortcutIme == mSupportsSwitchingToShortcutIme
                 && other.mHasShortcutKey == mHasShortcutKey
                 && other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
                 && other.isMultiLine() == isMultiLine()
@@ -179,7 +175,7 @@
 
     @Override
     public String toString() {
-        return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s%s]",
+        return String.format(Locale.ROOT, "[%s %s:%s %dx%d %s %s%s%s%s%s%s%s%s]",
                 elementIdToName(mElementId),
                 mLocale, mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
                 mWidth, mHeight,
@@ -189,7 +185,6 @@
                 (navigatePrevious() ? " navigatePrevious" : ""),
                 (mClobberSettingsKey ? " clobberSettingsKey" : ""),
                 (passwordInput() ? " passwordInput" : ""),
-                (mSupportsSwitchingToShortcutIme ? " supportsSwitchingToShortcutIme" : ""),
                 (mHasShortcutKey ? " hasShortcutKey" : ""),
                 (mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
                 (isMultiLine() ? " isMultiLine" : "")
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index aa64699..3e5cfc1 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -17,8 +17,6 @@
 package com.android.inputmethod.keyboard;
 
 import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII;
-import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE;
-import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT;
 import static com.android.inputmethod.latin.Constants.ImeOption.NO_SETTINGS_KEY;
 
 import android.content.Context;
@@ -102,12 +100,11 @@
     public static final class Params {
         String mKeyboardLayoutSetName;
         int mMode;
-        EditorInfo mEditorInfo;
         boolean mDisableTouchPositionCorrectionDataForTest;
+        // TODO: Use {@link InputAttributes} instead of these variables.
+        EditorInfo mEditorInfo;
         boolean mIsPasswordField;
-        boolean mSupportsSwitchingToShortcutIme;
-        boolean mShowsVoiceInputKey;
-        boolean mNoMicrophoneKey;
+        boolean mVoiceInputKeyEnabled;
         boolean mNoSettingsKey;
         boolean mLanguageSwitchKeyEnabled;
         InputMethodSubtype mSubtype;
@@ -228,14 +225,9 @@
 
             final EditorInfo editorInfo = (ei != null) ? ei : EMPTY_EDITOR_INFO;
             params.mMode = getKeyboardMode(editorInfo);
+            // TODO: Consolidate those with {@link InputAttributes}.
             params.mEditorInfo = editorInfo;
             params.mIsPasswordField = InputTypeUtils.isPasswordInputType(editorInfo.inputType);
-            @SuppressWarnings("deprecation")
-            final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions(
-                    null, NO_MICROPHONE_COMPAT, editorInfo);
-            params.mNoMicrophoneKey = InputAttributes.inPrivateImeOptions(
-                    mPackageName, NO_MICROPHONE, editorInfo)
-                    || deprecatedNoMicrophone;
             params.mNoSettingsKey = InputAttributes.inPrivateImeOptions(
                     mPackageName, NO_SETTINGS_KEY, editorInfo);
         }
@@ -248,6 +240,7 @@
 
         public Builder setSubtype(final InputMethodSubtype subtype) {
             final boolean asciiCapable = InputMethodSubtypeCompatUtils.isAsciiCapable(subtype);
+            // TODO: Consolidate with {@link InputAttributes}.
             @SuppressWarnings("deprecation")
             final boolean deprecatedForceAscii = InputAttributes.inPrivateImeOptions(
                     mPackageName, FORCE_ASCII, mParams.mEditorInfo);
@@ -268,12 +261,13 @@
             return this;
         }
 
-        public Builder setOptions(final boolean isShortcutImeEnabled,
-                final boolean showsVoiceInputKey, final boolean languageSwitchKeyEnabled) {
-            mParams.mSupportsSwitchingToShortcutIme =
-                    isShortcutImeEnabled && !mParams.mNoMicrophoneKey && !mParams.mIsPasswordField;
-            mParams.mShowsVoiceInputKey = showsVoiceInputKey;
-            mParams.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
+        public Builder setVoiceInputKeyEnabled(final boolean enabled) {
+            mParams.mVoiceInputKeyEnabled = enabled;
+            return this;
+        }
+
+        public Builder setLanguageSwitchKeyEnabled(final boolean enabled) {
+            mParams.mLanguageSwitchKeyEnabled = enabled;
             return this;
         }
 
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index ef5fabb..c36216e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -115,10 +115,10 @@
         final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
         builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
         builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
-        builder.setOptions(
-                mSubtypeSwitcher.isShortcutImeEnabled(),
-                settingsValues.mShowsVoiceInputKey,
-                mLatinIME.shouldShowLanguageSwitchKey());
+        builder.setVoiceInputKeyEnabled(mSubtypeSwitcher.isShortcutImeEnabled()
+                && settingsValues.mShowsVoiceInputKey
+                && !settingsValues.mInputAttributes.hasNoMicrophoneKeyOption());
+        builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
         mKeyboardLayoutSet = builder.build();
         mCurrentSettingsValues = settingsValues;
         try {
diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
index 81d8cda..abed520 100644
--- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
@@ -115,8 +115,6 @@
         builder.setSubtype(SubtypeSwitcher.getInstance().getEmojiSubtype());
         builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res),
                 mEmojiLayoutParams.mEmojiKeyboardHeight);
-        builder.setOptions(false /* shortcutImeEnabled */, false /* showsVoiceInputKey */,
-                false /* languageSwitchKeyEnabled */);
         final KeyboardLayoutSet layoutSet = builder.build();
         final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs,
                 R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 2aeeed8..e694998 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -652,9 +652,6 @@
                     R.styleable.Keyboard_Case_passwordInput, id.passwordInput());
             final boolean clobberSettingsKeyMatched = matchBoolean(caseAttr,
                     R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey);
-            final boolean supportsSwitchingToShortcutImeMatched = matchBoolean(caseAttr,
-                    R.styleable.Keyboard_Case_supportsSwitchingToShortcutIme,
-                    id.mSupportsSwitchingToShortcutIme);
             final boolean hasShortcutKeyMatched = matchBoolean(caseAttr,
                     R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey);
             final boolean languageSwitchKeyEnabledMatched = matchBoolean(caseAttr,
@@ -674,14 +671,13 @@
                     R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry());
             final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched
                     && modeMatched && navigateNextMatched && navigatePreviousMatched
-                    && passwordInputMatched && clobberSettingsKeyMatched
-                    && supportsSwitchingToShortcutImeMatched && hasShortcutKeyMatched
+                    && passwordInputMatched && clobberSettingsKeyMatched && hasShortcutKeyMatched
                     && languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched
                     && isIconDefinedMatched && localeCodeMatched && languageCodeMatched
                     && countryCodeMatched;
 
             if (DEBUG) {
-                startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE,
+                startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE,
                         textAttr(caseAttr.getString(
                                 R.styleable.Keyboard_Case_keyboardLayoutSet), "keyboardLayoutSet"),
                         textAttr(caseAttr.getString(
@@ -698,9 +694,6 @@
                                 "clobberSettingsKey"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_passwordInput,
                                 "passwordInput"),
-                        booleanAttr(
-                                caseAttr, R.styleable.Keyboard_Case_supportsSwitchingToShortcutIme,
-                                "supportsSwitchingToShortcutIme"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_hasShortcutKey,
                                 "hasShortcutKey"),
                         booleanAttr(caseAttr, R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index 378acb3..e1ae3df 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -16,6 +16,9 @@
 
 package com.android.inputmethod.latin;
 
+import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE;
+import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT;
+
 import android.text.InputType;
 import android.util.Log;
 import android.view.inputmethod.EditorInfo;
@@ -39,8 +42,13 @@
     final public boolean mApplicationSpecifiedCompletionOn;
     final public boolean mShouldInsertSpacesAutomatically;
     final private int mInputType;
+    final private EditorInfo mEditorInfo;
+    final private String mPackageNameForPrivateImeOptions;
 
-    public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode) {
+    public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode,
+            final String packageNameForPrivateImeOptions) {
+        mEditorInfo = editorInfo;
+        mPackageNameForPrivateImeOptions = packageNameForPrivateImeOptions;
         mTargetApplicationPackageName = null != editorInfo ? editorInfo.packageName : null;
         final int inputType = null != editorInfo ? editorInfo.inputType : 0;
         final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
@@ -111,6 +119,15 @@
         return editorInfo.inputType == mInputType;
     }
 
+    public boolean hasNoMicrophoneKeyOption() {
+        @SuppressWarnings("deprecation")
+        final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions(
+                null, NO_MICROPHONE_COMPAT, mEditorInfo);
+        final boolean noMicrophone = InputAttributes.inPrivateImeOptions(
+                mPackageNameForPrivateImeOptions, NO_MICROPHONE, mEditorInfo);
+        return noMicrophone || deprecatedNoMicrophone;
+    }
+
     @SuppressWarnings("unused")
     private void dumpFlags(final int inputType) {
         final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index deaf6cd..4e12a0a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -522,7 +522,8 @@
     void loadSettings() {
         final Locale locale = mSubtypeSwitcher.getCurrentSubtypeLocale();
         final EditorInfo editorInfo = getCurrentInputEditorInfo();
-        final InputAttributes inputAttributes = new InputAttributes(editorInfo, isFullscreenMode());
+        final InputAttributes inputAttributes = new InputAttributes(
+                editorInfo, isFullscreenMode(), getPackageName());
         mSettings.loadSettings(this, locale, inputAttributes);
         final SettingsValues currentSettingsValues = mSettings.getCurrent();
         AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 4cdc6e3..e53408d 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -109,7 +109,8 @@
 
         // Store the input attributes
         if (null == inputAttributes) {
-            mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
+            mInputAttributes = new InputAttributes(
+                    null, false /* isFullscreenMode */, context.getPackageName());
         } else {
             mInputAttributes = inputAttributes;
         }
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
index 15e2647..ab7d1b2 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java
@@ -114,13 +114,13 @@
 
     protected final KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
             final EditorInfo editorInfo) {
-        return createKeyboardLayoutSet(subtype, editorInfo, false /* isShortcutImeEnabled */,
-                false /* showsVoiceInputKey */, false /* isLanguageSwitchKeyEnabled */);
+        return createKeyboardLayoutSet(subtype, editorInfo, false /* voiceInputKeyEnabled */,
+                false /* languageSwitchKeyEnabled */);
     }
 
     protected final KeyboardLayoutSet createKeyboardLayoutSet(final InputMethodSubtype subtype,
-            final EditorInfo editorInfo, final boolean isShortcutImeEnabled,
-            final boolean showsVoiceInputKey, final boolean isLanguageSwitchKeyEnabled) {
+            final EditorInfo editorInfo, final boolean voiceInputKeyEnabled,
+            final boolean languageSwitchKeyEnabled) {
         final Context context = mThemeContext;
         final Resources res = context.getResources();
         final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
@@ -128,7 +128,8 @@
         final Builder builder = new Builder(context, editorInfo);
         builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
                 .setSubtype(subtype)
-                .setOptions(isShortcutImeEnabled, showsVoiceInputKey, isLanguageSwitchKeyEnabled);
+                .setVoiceInputKeyEnabled(voiceInputKeyEnabled)
+                .setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled);
         return builder.build();
     }
 }
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
index 0d90055..a22ed60 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/LayoutTestsBase.java
@@ -54,8 +54,7 @@
                 + (isPhone() ? "phone" : "tablet");
         // TODO: Test with language switch key enabled and disabled.
         mKeyboardLayoutSet = createKeyboardLayoutSet(mSubtype, null /* editorInfo */,
-                true /* isShortcutImeEnabled */, true /* showsVoiceInputKey */,
-                true /* isLanguageSwitchKeyEnabled */);
+                true /* voiceInputKeyEnabled */, true /* languageSwitchKeyEnabled */);
     }
 
     @Override