在android13中,要预置一个对讲应用,从预置和授权,梳理了一下,以便后续查询使用。在此记录
一放置应用
我的apk应用放在vendor下面,
路径:projectroot/vendor/fly/package/apps/DMR/flydmr.apk (vendor/fly/package/apps下可以放置其他预装应用)
二设置权限
这里我们使用一个新的授权方式,以往我们都在framework/base/data/etc/privapp-permissions-platform.xml 下声明权限,然后再在代码中授予权限。这次我们直接使用xml文件在apk同目录下声明和授予权限
- 声明权限
在步骤一的DMR/目录下创建privapp-permissions-flydmr.xml文件内容如下:
data/etc/privapp-permissions-platform.xml
<?xml version="1.0" encoding="utf-8"?><permissions><privapp-permissions package="com.demo.dmr"> //package是应用的包名<permission name="android.permission.FOREGROUND_SERVICE" /><permission name="android.permission.KILL_BACKGROUND_PROCESSES" /><permission name="android.permission.RECEIVE_BOOT_COMPLETED" /><permission name="android.permission.READ_PHONE_STATE" /><permission name="android.permission.RECORD_AUDIO"/><permission name="android.permission.MODIFY_AUDIO_SETTINGS"/><permission name="android.permission.MODIFY_PHONE_STATE" /><permission name="android.permission.WRITE_EXTERNAL_STORAGE" /><permission name="android.permission.READ_EXTERNAL_STORAGE" /><!--<permission name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />--></privapp-permissions></permissions>
2 授予权限
同样在DMR目录下创建default_permissions_dmr.xml文件,内容如下:
<exceptions><exception package="com.demo.dmr"><permission name="android.permission.FOREGROUND_SERVICE" fixed="false"/><permission name="android.permission.KILL_BACKGROUND_PROCESSES" fixed="false"/><permission name="android.permission.RECEIVE_BOOT_COMPLETED" fixed="false"/><permission name="android.permission.READ_PHONE_STATE" fixed="false"/><permission name="android.permission.RECORD_AUDIO" fixed="false"/><permission name="android.permission.MODIFY_AUDIO_SETTINGS" fixed="false"><permission name="android.permission.MODIFY_PHONE_STATE" fixed="false"/><permission name="android.permission.WRITE_EXTERNAL_STORAGE" fixed="false"/><permission name="android.permission.READ_EXTERNAL_STORAGE" fixed="false"/><!--<permission name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" fixed="false"/>--></exception>
</exceptions>
以上两个权限文件的包名和应用包名必须一致
三创建mk编译文件
在DMR目录下创建Android.mk文件,内容如下
#==================================================
# build apk
#==================================================
LOCAL_PATH:= $(call my-dir)
#dmr method.
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optionalLOCAL_MODULE := DMR
LOCAL_MODULE_STEM :=FlysDmr.apk
LOCAL_MODULE_CLASS :=APPS
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_PATH := $(TARGET_OUT)/priv-app
LOCAL_SRC_FILES := FlysDmr.apk
LOCAL_PRIVILEGED_MODULE := true
LOCAL_ENFORCE_USES_LIBRARIES := false
LOCAL_REPLACE_PREBUILT_APK_INSTALLED := $(LOCAL_PATH)/FlysDmr.apk
include $(BUILD_PREBUILT)
#include $(call all-makefiles-under,$(LOCAL_PATH))#==================================================
# Install priv-app default-permisison file
#==================================================
include $(CLEAR_VARS)
LOCAL_MODULE := default_permissons_dmr.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/default-permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)#==================================================
# Install priv-app permisison file
#==================================================
include $(CLEAR_VARS)
LOCAL_MODULE:=privapp-permissions-flydmr.xml
LOCAL_MODULE_TAGS:=optional
LOCAL_MODULE_CLASS:=ETCLOCAL_MODULE_PATH:=${TARGET_OUT_ETC}/permissions
LOCAL_SRC_FILES:=${LOCAL_MODULE}
include ${BUILD_PREBUILT}
以上代码块,分三部门,第一部分是编译apk,第二部分是授权,第三部分是声明权限
四 集成编译
这个在build目录下 projectroot/build/target/product/handheld_product.mk文件中,添加如下
diff --git a/target/product/handheld_product.mk b/target/product/handheld_product.mk
index 11b09beef..cf1ff9e20 100644
--- a/target/product/handheld_product.mk
+++ b/target/product/handheld_product.mk
@@ -29,7 +29,11 @@ PRODUCT_PACKAGES += \Gallery2 \LatinIME \
+ IFlyIME \ //对应的LOCAL_MOUDEL名称
+ privapp-permissions-flyime.xml \
+ default_permissons_flyime.xml \
+ DMR \ //对应的LOCAL_MOUDEL名称
+ default_permissons_dmr.xml \
+ privapp-permissions-flydmr.xml \Music \OneTimeInitializer \preinstalled-packages-platform-handheld-product.xml \
然后全局编译,记得clean哈~~~~
ps:文件目录如下:
DMR目录有如下文件: (个人感觉xml文件名字无所谓,只要包名对的上就行,阅读etc/permission/下规范最好保持一致)
FlysDmr.apk
Android.mk
default_permissons_dmr.xml
privapp-permissions-flydmr.xml
问题解决:
问题1:编译刷机后,开机无法进入主页报如下错误:
这是应用没有拿到权限的问题,添加default_permissons_dmr.xml 授权
问题2:进入主页,打开应用崩溃,log如下:
这是应用没有找到so库,应用中有so库,因为应用设置为系统应用,需要指明so地址
在Android.mk中增加如下
LOCAL_ENFORCE_USES_LIBRARIES := false
+# LOCAL_PREBUILT_JNI_LIBS:=lib/arm64-v8a/libserialport.so \
+# lib/x86_64/libserialport.so \
+# lib/x86/libserialport.so \
+# lib/armeabi-v7a/libserialport.so
+ifeq ($(TARGET_ARCH),arm64)
+LOCAL_PREBUILT_JNI_LIBS := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/lib/arm64-v8a/*.so))
+else
+LOCAL_PREBUILT_JNI_LIBS := $(subst $(LOCAL_PATH)/,,$(wildcard $(LOCAL_PATH)/lib/armeabi-v7a//*.so))
+endif
+LOCAL_REPLACE_PREBUILT_APK_INSTALLED := $(LOCAL_PATH)/FlyscaleDmr.apkinclude $(BUILD_PREBUILT)#include $(call all-makefiles-under,$(LOCAL_PATH))
记得将apk中的lib目录(里面有so文件)放到Android.mk同级目录下哦。(arm x86,可以根据设备cpu架构只放置必须的so库,我的是arm架构,只放置了 arm相关)
-------------------------2024-11-01补充----------------
突然发现以上只是集成了输入法,但是没有默认为系统输入法,若需要设置默认系统输入法做以下修改
操作1:
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index 2203863b5028..e4e896c955ea 100755
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -18,9 +18,14 @@--><resources><string name="def_system_locales" translatable="false">zh-Hans-CN,en-US</string>
+ <!-- 置触宝默认输入法 -->
+ <!-- <string name="config_enabled_input_methods" translatable="false">com.emoji.keyboard.touchpal.go:com.cootek.smartinput5.TouchPalIME:com.android.inputmethod.latin/.LatinIME</string>
+ <string name="config_default_input_method" translatable="false">com.emoji.keyboard.touchpal.go/com.cootek.smartinput5.TouchPalIME</string> --> <!-- 设置默认输入法 -->
- <string name="config_enabled_input_methods" translatable="false">com.emoji.keyboard.touchpal.go:com.cootek.smartinput5.TouchPalIME:com.android.inputmethod.latin/.LatinIME</string>
- <string name="config_default_input_method" translatable="false">com.emoji.keyboard.touchpal.go/com.cootek.smartinput5.TouchPalIME</string>
+<string name="enabled_input_methods" translatable="false">com.iflytek.inputmethod/.FlyIME</string>
+
+<string name="default_input_method" translatable="false">com.iflytek.inputmethod/.FlyIME</string>
+
操作2:然后在SettingProvider模块里面添加如下
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 54836523e5da..ca7454f4b600 100755
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2345,6 +2345,13 @@ class DatabaseHelper extends SQLiteOpenHelper { loadSecure35Settings(stmt); +
+ loadStringSetting(stmt, Settings.Secure.ENABLED_INPUT_METHODS,
+ R.string.config_enabled_input_methods);
+
+ loadStringSetting(stmt, Settings.Secure.DEFAULT_INPUT_METHOD,
+ R.string.config_default_input_method);
+ loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND, R.bool.def_mount_play_notification_snd);
以上加载的配置是在操作1里面设置的。
over~