Java Code Examples for android.view.inputmethod.InputMethodInfo#getServiceInfo()

The following examples show how to use android.view.inputmethod.InputMethodInfo#getServiceInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeleteNonRequiredAppsTask.java    From island with Apache License 2.0 6 votes vote down vote up
private Set<String> getSystemInputMethods() {
    // InputMethodManager is final so it cannot be mocked.
    // So, we're using IInputMethodManager directly because it can be mocked.
    List<InputMethodInfo> inputMethods = null;
    try {
        inputMethods = mIInputMethodManager.getInputMethodList();
    } catch (RemoteException e) {
        ProvisionLogger.loge("Could not communicate with IInputMethodManager", e);
        return Collections.<String>emptySet();
    }
    Set<String> systemInputMethods = new HashSet<String>();
    for (InputMethodInfo inputMethodInfo : inputMethods) {
        ApplicationInfo applicationInfo = inputMethodInfo.getServiceInfo().applicationInfo;
        if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            systemInputMethods.add(inputMethodInfo.getPackageName());
        }
    }
    return systemInputMethods;
}
 
Example 2
Source File: PolicyManagementFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
protected List<ResolveInfo> getResolveInfoListFromAvailableComponents(
        List<InputMethodInfo> inputMethodsInfoList) {
    List<ResolveInfo> inputMethodsResolveInfoList = new ArrayList<>();
    for (InputMethodInfo inputMethodInfo: inputMethodsInfoList) {
        ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.serviceInfo = inputMethodInfo.getServiceInfo();
        resolveInfo.resolvePackageName = inputMethodInfo.getPackageName();
        inputMethodsResolveInfoList.add(resolveInfo);
    }
    return inputMethodsResolveInfoList;
}
 
Example 3
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 4 votes vote down vote up
private Pair<InputMethodInfo, InputMethodSubtype>
        findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
    List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
    InputMethodInfo mostApplicableIMI = null;
    InputMethodSubtype mostApplicableSubtype = null;
    boolean foundInSystemIME = false;

    // Search applicable subtype for each InputMethodInfo
    for (InputMethodInfo imi: imis) {
        final String imiId = imi.getId();
        if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
            continue;
        }
        InputMethodSubtype subtype = null;
        final List<InputMethodSubtype> enabledSubtypes =
                mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
        // 1. Search by the current subtype's locale from enabledSubtypes.
        if (mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
        }
        // 2. Search by the system locale from enabledSubtypes.
        // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, enabledSubtypes, mode, null, true);
        }
        final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
                InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
        final ArrayList<InputMethodSubtype> subtypesForSearch =
                overridingImplicitlyEnabledSubtypes.isEmpty()
                        ? InputMethodUtils.getSubtypes(imi)
                        : overridingImplicitlyEnabledSubtypes;
        // 4. Search by the current subtype's locale from all subtypes.
        if (subtype == null && mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
        }
        // 5. Search by the system locale from all subtypes.
        // 6. Search the first enabled subtype matched with mode from all subtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, subtypesForSearch, mode, null, true);
        }
        if (subtype != null) {
            if (imiId.equals(mCurMethodId)) {
                // The current input method is the most applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                break;
            } else if (!foundInSystemIME) {
                // The system input method is 2nd applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                if ((imi.getServiceInfo().applicationInfo.flags
                        & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    foundInSystemIME = true;
                }
            }
        }
    }
    if (DEBUG) {
        if (mostApplicableIMI != null) {
            Slog.w(TAG, "Most applicable shortcut input method was:"
                    + mostApplicableIMI.getId());
            if (mostApplicableSubtype != null) {
                Slog.w(TAG, "Most applicable shortcut input method subtype was:"
                        + "," + mostApplicableSubtype.getMode() + ","
                        + mostApplicableSubtype.getLocale());
            }
        }
    }
    if (mostApplicableIMI != null) {
        return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
                mostApplicableSubtype);
    } else {
        return null;
    }
}