AOSP内置搜狗输入并设置默认输入法

前期准备

AOSP分支:aosp13_r7
系统版本:Ubuntu 22.04.1 LTS

工具:手,vscode,winscp(因为我是用的服务器编译)

下载搜狗输入法

思路:

1.集成搜狗输入法到aosp

2.删除系统输入法

3.设置搜狗输入法为默认输入法

4.编译测试

5.问题整理

集成搜狗输入法到aosp

搜狗输入法的apk重命名为SougouInput.apk
连接上服务器,进入到
/packages/apps目录

cd /packages/apps/

新建一个命名为SougouInput的文件夹

mkdir SougouInput

将SougouInput.apk上传至SougouInput文件夹下
AOSP内置搜狗输入并设置默认输入法_第1张图片

新建一个Android.mk文件

touch Android.mk

接着

vim Android.mk

将下面的内容粘贴到Android.mk里

LOCAL_PATH := $(my-dir)
 
include $(CLEAR_VARS)
LOCAL_MODULE := SougouInput
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_PRIVILEGED_MODULE := false
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MULTILIB :=64
LOCAL_PREBUILT_JNI_LIBS := \
            @lib/arm64-v8a/libaffinity.so \
            @lib/arm64-v8a/libbugly_dumper.so \
            @lib/arm64-v8a/libBugly_Native.so \
            @lib/arm64-v8a/libc++_shared.so \
            @lib/arm64-v8a/libcleanmmap.so \
            @lib/arm64-v8a/libcrash_collect.so \
            @lib/arm64-v8a/libCtaApiLib.so \
            @lib/arm64-v8a/libframesequence.so \
            @lib/arm64-v8a/libframesequence_doutu.so \
            @lib/arm64-v8a/libhttpdns.so \
            @lib/arm64-v8a/libluajava.so \
            @lib/arm64-v8a/libmarsxlog.so \
            @lib/arm64-v8a/libMMANDKSignature.so \
            @lib/arm64-v8a/libmmkv.so \
            @lib/arm64-v8a/libnative-sec.so \
            @lib/arm64-v8a/libopus_v1.so \
            @lib/arm64-v8a/libostar.so \
            @lib/arm64-v8a/libqmp.so \
            @lib/arm64-v8a/libSGMtlgShell.so \
            @lib/arm64-v8a/libsimple_vad.so \
            @lib/arm64-v8a/libsimplevadwrapper.so \
            @lib/arm64-v8a/libsogou_speex_nt_v01.so \
            @lib/arm64-v8a/libsogouime.so \
            @lib/arm64-v8a/libsogouupdcore.so \
            @lib/arm64-v8a/libtma_blowing_sound_detection.so \
            @lib/arm64-v8a/libtrace-canary.so \
            @lib/arm64-v8a/libturingga.so \
            @lib/arm64-v8a/libvivo_account_wave.so \
            @lib/arm64-v8a/libweibosdkcore.so \
 
include $(BUILD_PREBUILT)

保存Android.mk文件

接着打开文件/build/make/target/product/aosp_product.mk

#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Includes all AOSP product packages
$(call inherit-product, $(SRC_TARGET_DIR)/product/handheld_product.mk)
$(call inherit-product, $(SRC_TARGET_DIR)/product/telephony_product.mk)

# Default AOSP sounds
$(call inherit-product-if-exists, frameworks/base/data/sounds/AllAudio.mk)

# Additional settings used in all AOSP builds
PRODUCT_PRODUCT_PROPERTIES += \
    ro.config.ringtone?=Ring_Synth_04.ogg \
    ro.config.notification_sound?=pixiedust.ogg \
    ro.com.android.dataroaming?=true \

# More AOSP packages
PRODUCT_PACKAGES += \
    messaging \
    PhotoTable \
    preinstalled-packages-platform-aosp-product.xml \
    WallpaperPicker \
    SougouInput \ #这里新加一行

# Telephony:
#   Provide a APN configuration to GSI product
PRODUCT_COPY_FILES += \
    device/sample/etc/apns-full-conf.xml:$(TARGET_COPY_OUT_PRODUCT)/etc/apns-conf.xml

保存文件后,搜狗输入法已经被我们集成到aosp中了

删除系统输入法

刚刚我们在/packages/inputmethods文件夹下的LatinIME就是系统默认的输入法
在这里插入图片描述

既然我们把搜狗输入法内置进去了,那么LatinIME就没有存在的必要了,删除的话需要找到使用LatinIME的地方

这里为了提高效率,使用vscode远程连接到aosp代码目录,全局搜索 LatinIME
AOSP内置搜狗输入并设置默认输入法_第2张图片

从这里看到有很多个,询问度娘后注释handheld_handle.mk里的LatinIME
AOSP内置搜狗输入并设置默认输入法_第3张图片

设置搜狗输入法为默认输入法

接下来把搜狗输入法设置为默认输入法

打开defaults.xml文件

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

在最后加上配置

    
    <string name="def_enabled_input_methods" translatable="false">com.sohu.inputmethod.sogou/.SogouIMEstring>

AOSP内置搜狗输入并设置默认输入法_第4张图片

打开DatabaseHelper.java文件

framwork/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

搜索loadSecureSettings方法,定位到一个比较优雅的位置

private void loadSecureSettings(SQLiteDatabase db) {
     SQLiteStatement stmt = null;
        try {
            stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                    + " VALUES(?,?);");

            // Don't do this.  The SystemServer will initialize ADB_ENABLED from a
            // persistent system property instead.
            //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
        省略.......
        loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD,
                    R.bool.def_accessibility_speak_password);
        //添加到这里
        loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,
                    R.string.def_enabled_input_methods);
        省略.......
}

编译测试

回到aosp目录下,执行

source build/envsetup.sh
//这里的xxx自行选择,例如pixel4就选aosp_flame-userdebug 
lunch xxx
//输入-j32之前心里要对电脑配置有点数,没数的话可以只输入m,它会自己选择适当的核数
m -j32

two thousand years later …

在这里插入图片描述

问题整理

  1. 在执行lunch后发现毛都没有
    AOSP内置搜狗输入并设置默认输入法_第5张图片

问题出在handheld_handle.mk中,#LatinIME \ 引起的错误,解决方法是把LatinIME \删掉
AOSP内置搜狗输入并设置默认输入法_第6张图片

你可能感兴趣的:(android,aosp,内置输入法)