Make sure at least one non-aux IME is enabled

Imagine the scenario where three IMEs are installed, and only the last
two are enabled:

 IME A:
  * a pre-installed IME
  * has a subtype [mode="keyboard" && isAuxiliary=false]
  * disabled by user (hence not included in ENABLED_INPUT_METHODS)
 IME B:
  * a pre-installed IME
  * has a subtype [isAuxiliary=true]
  * currently enabled (included in ENABLED_INPUT_METHODS)
 IME X:
  * not a pre-installed IME
  * has a subtype [mode="keyboard" && isAuxiliary=false]
  * currently enabled (included in ENABLED_INPUT_METHODS)

In this scenario, when the IME X is uninstalled, the current
implementation of InputMethodManagerService (IMMS) does not try to
hard reset enabled IMEs because there is still one enabled IME, even
though it is an auxiliary IME.

This can, however, be problematic because an auxiliary IME is just a
supplemental IME and user may not be able to easily access the UI to
re-enable non-auxiliary IME such as IME A.  For instance, on the lock
screen there is no way to manually re-enable the IME A.

With this CL, every time the available IME list is updated, IMMS
ensures that at least one non-auxiliary IME is enabled.  If no
non-auxiliary IME is enabled, then IMMS tries to pick up one from the
pre-installed IME by using the same logic when choosing the default
enabled IMEs for the hard-reset scenario.

Bug: 71509065
Fix: 71509065
Test: atest FrameworksCoreTests:com.android.internal.inputmethod.InputMethodUtilsTest
Test: Manually verified in the above scenario
Change-Id: I88c69f548526b35f0e4ba37489365b2433373b04
3 files changed