Allow no item selected in IME Switcher Menu

This starts the checkedItem variable at -1, instead of 0, so when no
item is found to be checked we don't incorrectly show the first value as
selected.

This scenario can happen when we have a list of explicitly enabled
subtypes, which would no longer list the implicit subtype,
but the selected subtype is still the implicit one, which cannot be
found in the list.

Test: install a separate version of Gboard, disable and re-enable it
  from System Settings and switch to it, go to its app settings and
  add a new subtype, and show the IME switcher menu again. No items
  should be shown as selected.
Bug: 328579802
Change-Id: I431bdb0185b78be44b43a50910543f8b18a8c5ed
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
index 3bd0a9f..326ef7e 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
@@ -98,7 +98,10 @@
         final int size = imList.size();
         mIms = new InputMethodInfo[size];
         mSubtypeIds = new int[size];
-        int checkedItem = 0;
+        // No items are checked by default. When we have a list of explicitly enabled subtypes,
+        // the implicit subtype is no longer listed, but if it is still the selected one,
+        // no items will be shown as checked.
+        int checkedItem = -1;
         for (int i = 0; i < size; ++i) {
             final ImeSubtypeListItem item = imList.get(i);
             mIms[i] = item.mImi;
@@ -113,6 +116,12 @@
             }
         }
 
+        if (checkedItem == -1) {
+            Slog.w(TAG, "Switching menu shown with no item selected"
+                    + ", IME id: " + preferredInputMethodId
+                    + ", subtype index: " + preferredInputMethodSubtypeId);
+        }
+
         if (mDialogWindowContext == null) {
             mDialogWindowContext = new InputMethodDialogWindowContext();
         }