Search in sources :

Example 86 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by crdroidandroid.

the class InputMethodUtils method setNonSelectedSystemImesDisabledUntilUsed.

public static void setNonSelectedSystemImesDisabledUntilUsed(IPackageManager packageManager, List<InputMethodInfo> enabledImis, int userId, String callingPackage) {
    if (DEBUG) {
        Slog.d(TAG, "setNonSelectedSystemImesDisabledUntilUsed");
    }
    final String[] systemImesDisabledUntilUsed = Resources.getSystem().getStringArray(com.android.internal.R.array.config_disabledUntilUsedPreinstalledImes);
    if (systemImesDisabledUntilUsed == null || systemImesDisabledUntilUsed.length == 0) {
        return;
    }
    // Only the current spell checker should be treated as an enabled one.
    final SpellCheckerInfo currentSpellChecker = TextServicesManager.getInstance().getCurrentSpellChecker();
    for (final String packageName : systemImesDisabledUntilUsed) {
        if (DEBUG) {
            Slog.d(TAG, "check " + packageName);
        }
        boolean enabledIme = false;
        for (int j = 0; j < enabledImis.size(); ++j) {
            final InputMethodInfo imi = enabledImis.get(j);
            if (packageName.equals(imi.getPackageName())) {
                enabledIme = true;
                break;
            }
        }
        if (enabledIme) {
            // enabled ime. skip
            continue;
        }
        if (currentSpellChecker != null && packageName.equals(currentSpellChecker.getPackageName())) {
            // enabled spell checker. skip
            if (DEBUG) {
                Slog.d(TAG, packageName + " is the current spell checker. skip");
            }
            continue;
        }
        ApplicationInfo ai = null;
        try {
            ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, userId);
        } catch (RemoteException e) {
            Slog.w(TAG, "getApplicationInfo failed. packageName=" + packageName + " userId=" + userId, e);
            continue;
        }
        if (ai == null) {
            // No app found for packageName
            continue;
        }
        final boolean isSystemPackage = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
        if (!isSystemPackage) {
            continue;
        }
        setDisabledUntilUsed(packageManager, packageName, userId, callingPackage);
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

Example 87 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by crdroidandroid.

the class InputMethodUtils method getMostApplicableDefaultIME.

public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) {
    if (enabledImes == null || enabledImes.isEmpty()) {
        return null;
    }
    // We'd prefer to fall back on a system IME, since that is safer.
    int i = enabledImes.size();
    int firstFoundSystemIme = -1;
    while (i > 0) {
        i--;
        final InputMethodInfo imi = enabledImes.get(i);
        if (imi.isAuxiliaryIme()) {
            continue;
        }
        if (InputMethodUtils.isSystemIme(imi) && containsSubtypeOf(imi, ENGLISH_LOCALE, false, /* checkCountry */
        SUBTYPE_MODE_KEYBOARD)) {
            return imi;
        }
        if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi)) {
            firstFoundSystemIme = i;
        }
    }
    return enabledImes.get(Math.max(firstFoundSystemIme, 0));
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 88 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by crdroidandroid.

the class AppRestrictionsHelper method addSystemImes.

/**
     * Find all pre-installed input methods that are marked as default
     * and add them to an exclusion list so that they aren't
     * presented to the user for toggling.
     * Don't add non-default ones, as they may include other stuff that we
     * don't need to auto-include.
     * @param excludePackages the set of package names to append to
     */
private void addSystemImes(Set<String> excludePackages) {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    List<InputMethodInfo> imis = imm.getInputMethodList();
    for (InputMethodInfo imi : imis) {
        try {
            if (imi.isDefault(mContext) && isSystemPackage(imi.getPackageName())) {
                excludePackages.add(imi.getPackageName());
            }
        } catch (Resources.NotFoundException rnfe) {
        // Not default
        }
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) Resources(android.content.res.Resources) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 89 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by crdroidandroid.

the class UiAutomatorTestCase method setDummyIme.

private void setDummyIme() throws RemoteException {
    IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager.getService(Context.INPUT_METHOD_SERVICE));
    List<InputMethodInfo> infos = im.getInputMethodList();
    String id = null;
    for (InputMethodInfo info : infos) {
        if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) {
            id = info.getId();
        }
    }
    if (id == null) {
        throw new RuntimeException(String.format("Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE));
    }
    im.setInputMethod(null, id);
}
Also used : IInputMethodManager(com.android.internal.view.IInputMethodManager) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 90 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by crdroidandroid.

the class InputMethodManagerService method getLastInputMethodSubtype.

@Override
public InputMethodSubtype getLastInputMethodSubtype() {
    if (!calledFromValidUser()) {
        return null;
    }
    synchronized (mMethodMap) {
        final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
        // TODO: Handle the case of the last IME with no subtypes
        if (lastIme == null || TextUtils.isEmpty(lastIme.first) || TextUtils.isEmpty(lastIme.second))
            return null;
        final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
        if (lastImi == null)
            return null;
        try {
            final int lastSubtypeHash = Integer.parseInt(lastIme.second);
            final int lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
            if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
                return null;
            }
            return lastImi.getSubtypeAt(lastSubtypeId);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

InputMethodInfo (android.view.inputmethod.InputMethodInfo)309 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)113 ArrayList (java.util.ArrayList)80 RemoteException (android.os.RemoteException)53 ServiceInfo (android.content.pm.ServiceInfo)34 ComponentName (android.content.ComponentName)33 Intent (android.content.Intent)33 Context (android.content.Context)32 InputMethodManager (android.view.inputmethod.InputMethodManager)29 ApplicationInfo (android.content.pm.ApplicationInfo)27 PendingIntent (android.app.PendingIntent)24 Test (org.junit.Test)24 ResolveInfo (android.content.pm.ResolveInfo)19 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)14 List (java.util.List)14 PackageManager (android.content.pm.PackageManager)13 Drawable (android.graphics.drawable.Drawable)13 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 Printer (android.util.Printer)12