android.view.inputmethod.InputMethodInfo#getServiceInfo ( )源码实例Demo

下面列出了android.view.inputmethod.InputMethodInfo#getServiceInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: island   文件: DeleteNonRequiredAppsTask.java
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;
}
 
@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;
}
 
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;
    }
}