Search in sources :

Example 96 with InputMethodInfo

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

the class InputMethodManagerService method updateSystemUiLocked.

// Caution! This method is called in this class. Handle multi-user carefully
private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) {
    if (!calledWithValidToken(token)) {
        final int uid = Binder.getCallingUid();
        Slog.e(TAG, "Ignoring updateSystemUiLocked due to an invalid token. uid:" + uid + " token:" + token);
        return;
    }
    // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure
    // all updateSystemUi happens on system previlege.
    final long ident = Binder.clearCallingIdentity();
    try {
        // apply policy for binder calls
        if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
            vis = 0;
        }
        // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
        final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
        if (mStatusBar != null) {
            mStatusBar.setImeWindowStatus(token, vis, backDisposition, needsToShowImeSwitcher);
        }
        final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
        if (imi != null && needsToShowImeSwitcher) {
            // Used to load label
            final CharSequence title = mRes.getText(com.android.internal.R.string.select_input_method);
            final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(mContext, imi, mCurrentSubtype);
            mImeSwitcherNotification.setContentTitle(title).setContentText(summary).setContentIntent(mImeSwitchPendingIntent);
            try {
                if ((mNotificationManager != null) && !mIWindowManager.hasNavigationBar()) {
                    if (DEBUG) {
                        Slog.d(TAG, "--- show notification: label =  " + summary);
                    }
                    mNotificationManager.notifyAsUser(null, com.android.internal.R.string.select_input_method, mImeSwitcherNotification.build(), UserHandle.ALL);
                    mNotificationShown = true;
                }
            } catch (RemoteException e) {
            }
        } else {
            if (mNotificationShown && mNotificationManager != null) {
                if (DEBUG) {
                    Slog.d(TAG, "--- hide notification");
                }
                mNotificationManager.cancelAsUser(null, com.android.internal.R.string.select_input_method, UserHandle.ALL);
                mNotificationShown = false;
            }
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : RemoteException(android.os.RemoteException) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 97 with InputMethodInfo

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

the class KeyguardPasswordView method hasMultipleEnabledIMEsOrSubtypes.

/**
     * Method adapted from com.android.inputmethod.latin.Utils
     *
     * @param imm The input method manager
     * @param shouldIncludeAuxiliarySubtypes
     * @return true if we have multiple IMEs to choose from
     */
private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, final boolean shouldIncludeAuxiliarySubtypes) {
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    // Number of the filtered IMEs
    int filteredImisCount = 0;
    for (InputMethodInfo imi : enabledImis) {
        // We can return true immediately after we find two or more filtered IMEs.
        if (filteredImisCount > 1)
            return true;
        final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
        // IMEs that have no subtypes should be counted.
        if (subtypes.isEmpty()) {
            ++filteredImisCount;
            continue;
        }
        int auxCount = 0;
        for (InputMethodSubtype subtype : subtypes) {
            if (subtype.isAuxiliary()) {
                ++auxCount;
            }
        }
        final int nonAuxCount = subtypes.size() - auxCount;
        // subtypes should be counted as well.
        if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
            ++filteredImisCount;
            continue;
        }
    }
    return filteredImisCount > 1 || // input method subtype (The current IME should be LatinIME.)
    imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 98 with InputMethodInfo

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

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 99 with InputMethodInfo

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

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 100 with InputMethodInfo

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

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)

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