[RK3288][Android6.0] 输入法框架开机初始化部分小结

来源:互联网 发布:虚拟机优化显卡性能 编辑:程序博客网 时间:2024/06/14 10:09
Platform: ROCKCHIP
OS: Android 6.0
Kernel: 3.10.92

之前遇到默认输入法修改有问题,这里对输入法服务开机初始化部分做个小结.

startOtherServices ->    SystemServer.java
    new InputMethodManagerService ->
        IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));    //和windowsmanagerservice建立关系.
        new InputMethodSettings InputMethodUtils.java
        mSettings.getSelectedInputMethod ->    //获取系统默认输入法, SettingsProvider会提前解析默认配置,然后写入数据库,如果没有设置,那么就会返回空.
            getSelectedInputMethod ->    InputMethodUtils.java
                Settings.Secure.getStringForUser(...,Settings.Secure.DEFAULT_INPUT_METHOD, ...);
        buildInputMethodListLocked ->
            new ComponentName    //循环读取系统中所有可用的输入法
            new InputMethodInfo //输入法各自用此结构保存信息.
            InputMethodUtils.getDefaultEnabledImes ->     InputMethodUtils.java //当没有设置输入法时候会自动选择一个, 6.0默认选择了Latin输入法,谷歌拼音输入法已经被移除掉.
                getMinimumKeyboardSetWithSystemLocale
                //默认选择规则如下:
                // Once the system becomes ready, we pick up at least one keyboard in the following order.
                // Secondary users fall into this category in general.
                // 1. checkDefaultAttribute: true, locale: systemLocale, checkCountry: true
                // 2. checkDefaultAttribute: true, locale: systemLocale, checkCountry: false
                // 3. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: true
                // 4. checkDefaultAttribute: true, locale: fallbackLocale, checkCountry: false
                // 5. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: true
                // 6. checkDefaultAttribute: false, locale: fallbackLocale, checkCountry: false
                // TODO: We should check isAsciiCapable instead of relying on fallbackLocale.
            setInputMethodEnabledLocked ->  //存为默认enabled input method.
                mSettings.appendAndPutEnabledInputMethodLocked ->
                    putEnabledInputMethodsStr ->
                         Settings.Secure.putStringForUser(..., Settings.Secure.ENABLED_INPUT_METHODS, str, mCurrentUserId);
        mSettings.enableAllIMEsIfThereIsNoEnabledIME ->    //如果上面依然为空,那么会加载所有的输入法.
            enableAllIMEsIfThereIsNoEnabledIME ->
                putEnabledInputMethodsStr    //从mMethodList中读取所有输入法
        resetDefaultImeLocked ->    //当系统已经有默认输入法并且是第三方的输入法的话不会被reset,这种情况主要用于处理系统语言切换的情况.也就是说,如果是第三方输入法,那么在系统语言切换的时候不做变化.
            InputMethodUtils.getMostApplicableDefaultIME ->    //根据Locale选择一个最合适的.
                mSettings.getEnabledInputMethodListLocked ->    //获取系统当前支持的所有输入法
                    createEnabledInputMethodListLocked ->
                        getEnabledInputMethodsAndSubtypeListLocked ->
                            buildInputMethodsAndSubtypeList ->
                                getEnabledInputMethodsStr ->    //前面有设置过了,所以能得到数据了.
                                    Settings.Secure.getStringForUser(..., Settings.Secure.ENABLED_INPUT_METHODS, ...);    //从数据库中获取当前支持的ims


简单来说就是:

SettingsProvider读取并更新配置到数据库, InputMethodService读取配置,

如果没有读取到默认输入法,那么按照一定规则从现有系统输入法中选择其中

一个最合适的作为默认输入法.


参考:

http://blog.csdn.net/tfslovexizi/article/details/39400181

1 0