Android7.1 修改系统默认输入法

需求

修改系统默认输入法为讯飞输入法

代码修改

  • 添加Android.mk

    packages/inputmethods/**目录下创建 输入法的目录FlyIME, 添加Android.mk**,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := FlyIME
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_CLASS := APPS
LOCAL_PACKAGE_NAME := FlyIME
LOCAL_MODULE_PATH := $(TARGET_OUT_SYSTEM_APPS)
LOCAL_SRC_FILES := FlyIME.apk
LOCAL_CERTIFICATE := PRESIGNED

LOCAL_PREBUILT_JNI_LIBS := \
lib/libcom_iflytek_inputmethod_contact.so \
lib/libMetaVAD-v1.so \
lib/libNativeCrashCollect.so \
lib/libcom_iflytek_inputmethod_mmp.so \
lib/libcom_iflytek_inputmethod_setting.so \
lib/libdexopt.so \
lib/libencdec-jni-v1.so \
lib/libmsc-v8.so \
lib/libnalsocket.so \
lib/libsmartaiwrite-jni-v29.so \
lib/libvadLib-v5.so \
lib/libvipfont.so

#LOCAL_MULTILIB := 64

include $(BUILD_PREBUILT)

其中lib 目录下的文件可以在安装后通过adb pull出来,放到FlyIME目录下。

  • 修改系统makefile
1
2
3
4
5
6
7
8
9
10
11
12
diff --git a/build/target/product/core.mk b/build/target/product/core.mk
index 851cc4b..8270719 100644 (file)
--- a/build/target/product/core.mk
+++ b/build/target/product/core.mk
@@ -45,6 +45,7 @@ PRODUCT_PACKAGES += \
StorageManager \
TeleService \
VpnDialogs \
+ FlyIME

ifneq ($(strip $(TARGET_BOARD_PLATFORM_PRODUCT)), box)
PRODUCT_PACKAGES += \
  • 添加输入法ID

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
    index 7734cfd..0ac5e34 100644 (file)
    --- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
    +++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
    @@ -225,4 +225,6 @@
    <integer name="def_screenshot_button_show">1</integer>
    <!-- the store location of screen capture by default-->
    <string name="def_screenshot_location">internal_storage</string>
    +
    + <string name="def_input_method" translatable="false">com.iflytek.inputmethod/.FlyIME</string>
    </resources>
  • InputMethodUtils.java

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    diff --git a/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
    index 716997f..8c42dee 100644 (file)
    --- a/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
    +++ b/frameworks/base/core/java/com/android/internal/inputmethod/InputMethodUtils.java
    @@ -1083,7 +1083,7 @@ public class InputMethodUtils {
    // At the initial boot, the settings for input methods are not set,
    // so we need to enable IME in that case.
    public void enableAllIMEsIfThereIsNoEnabledIME() {
    - if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
    + if (!TextUtils.isEmpty(getEnabledInputMethodsStr())) {
    StringBuilder sb = new StringBuilder();
    final int N = mMethodList.size();
    for (int i = 0; i < N; i++) {
  • 设置默认值

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    diff --git a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
    index 5e2114d..19c3013 100644 (file)
    --- a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
    +++ b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
    @@ -2463,6 +2463,8 @@ class DatabaseHelper extends SQLiteOpenHelper {

    loadSecure35Settings(stmt);

    + loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,
    + R.string.def_input_method);
    loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
    R.bool.def_mount_play_notification_snd);
  • InputMethodManagerService.java

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    diff --git a/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java b/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
    index df1b6f5..59bbffa 100644 (file)
    --- a/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
    +++ b/frameworks/base/services/core/java/com/android/server/InputMethodManagerService.java
    @@ -3083,24 +3083,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }

    // TODO: The following code should find better place to live.
    - if (!resetDefaultEnabledIme) {
    - boolean enabledImeFound = false;
    - final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked();
    - final int N = enabledImes.size();
    - for (int i = 0; i < N; ++i) {
    - final InputMethodInfo imi = enabledImes.get(i);
    - if (mMethodList.contains(imi)) {
    - enabledImeFound = true;
    - break;
    - }
    - }
    - if (!enabledImeFound) {
    - Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs.");
    - resetDefaultEnabledIme = true;
    - resetSelectedInputMethodAndSubtypeLocked("");
    - }
    - }
    -
    +/*
    + * if (!resetDefaultEnabledIme) {
    + * boolean enabledImeFound = false;
    + * final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked();
    + * final int N = enabledImes.size();
    + * for (int i = 0; i < N; ++i) {
    + * final InputMethodInfo imi = enabledImes.get(i);
    + * if (mMethodList.contains(imi)) {
    + * enabledImeFound = true;
    + * break;
    + * }
    + * }
    + * if (!enabledImeFound) {
    + * Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs.");
    + * resetDefaultEnabledIme = true;
    + * resetSelectedInputMethodAndSubtypeLocked("");
    + * }
    + * }
    + *
    + */
    if (resetDefaultEnabledIme) {
    final ArrayList<InputMethodInfo> defaultEnabledIme =
    InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, mMethodList);
您的支持将鼓励我继续创作!