public static boolean isThisKeyboardEnabled(@NonNull Context context) {
    final String enabledIMEList =
        Settings.Secure.getString(
            context.getContentResolver(), Settings.Secure.ENABLED_INPUT_METHODS);
    return isThisKeyboardEnabled(enabledIMEList, context.getPackageName());
  }
@Test
  public void testIsThisKeyboardEnabled() throws Exception {
    final String MY_IME_PACKAGE = "net.evendanan.ime";
    assertFalse(SetupSupport.isThisKeyboardEnabled("", MY_IME_PACKAGE));
    // one keyboard
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", "net.some.other.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", ".IME").flattenToString(), MY_IME_PACKAGE));
    assertFalse(SetupSupport.isThisKeyboardEnabled(null, MY_IME_PACKAGE));

    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName(MY_IME_PACKAGE, MY_IME_PACKAGE + ".IME").flattenToString(),
            MY_IME_PACKAGE));
    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName(MY_IME_PACKAGE, "net.some.other.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString(), MY_IME_PACKAGE));

    // now, two keyboards
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", "net.some.other.IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", ".IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
            MY_IME_PACKAGE));

    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName(MY_IME_PACKAGE, MY_IME_PACKAGE + ".IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString()
                + ":"
                + new ComponentName(MY_IME_PACKAGE, "net.some.other.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString(),
            MY_IME_PACKAGE));

    // last test, three
    assertFalse(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", "net.some.one.e1.IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e2", "net.some.one.e2.IME").flattenToString(),
            MY_IME_PACKAGE));
    assertTrue(
        SetupSupport.isThisKeyboardEnabled(
            new ComponentName("net.some.one.e2", ".IME").flattenToString()
                + ":"
                + new ComponentName(MY_IME_PACKAGE, ".IME").flattenToString()
                + ":"
                + new ComponentName("net.some.one.e1", ".IME").flattenToString(),
            MY_IME_PACKAGE));
  }