Rockchip平台Android应用预安装功能(基于Android13)

2024-01-03 15:20

本文主要是介绍Rockchip平台Android应用预安装功能(基于Android13),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Rockchip平台Android应用预安装功能(基于Android13)

1. 预安装应用类型

Android上的应用预安装功能,主要是指配置产品时,根据厂商要求,将事先准备好的第三方应用预置进Android系统。预安装分为以下几种类型:

  1. 安装不可卸载应用
  2. 安装可永久卸载应用
  3. 安装卸载后恢复出厂设置后自动恢复的应用

2. 功能启用说明

2.1 配置和使用

在进行以下操作之前,首先需要输入命令 get_build_var TARGET_DEVICE_DIR 来找到对应的目标文件夹(比如 device/rockchip/rk3126c/)。

在目标文件夹下有三个文件夹,分别为:

  1. preinstall
  2. preinstall_del_forever
  3. preinstall_del

请将需要预置的应用放入对应的文件夹,注意apk文件名尽量使用英文,避免空格。

顺利的话,执行make之后会在$OUT/oem目录生成对应的文件夹:

  1. bundled_persist-app
  2. bundled_uninstall_gone-app
  3. bundled_uninstall_back-app

仍旧对应概述中的几种类型。在烧录后,系统会自动安装这些应用到对应目录。

注意:不支持带systemuid应用的预制,请使用Android原生方式编写mk文件。可参考vendor/rockchip/common/apps/RkDeviceTest/的集成方式。

2.2 编译结果

编译后配置文件将会输出到odm分区($OUT/oem/),增加后请确认烧写了odm.img来使其生效。

3. 预编译脚本

预置应用编译脚本通过下面脚本完成

ifneq ($(strip $(TARGET_PRODUCT)), )$(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) preinstall bundled_persist-app $(TARGET_ARCH))$(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) preinstall_del bundled_uninstall_back-app $(TARGET_ARCH))$(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) preinstall_del_forever bundled_uninstall_gone-app $(TARGET_ARCH))-include $(TARGET_DEVICE_DIR)/preinstall/preinstall.mk-include $(TARGET_DEVICE_DIR)/preinstall_del/preinstall.mk-include $(TARGET_DEVICE_DIR)/preinstall_del_forever/preinstall.mk
endif

可以看到预置应用的Android.mk主要通过auto_generator.py完成

#!/usr/bin/env python
import sys
import os
import re
import zipfile
import shutil
import logging
import stringtemplet = """include $(CLEAR_VARS)
LOCAL_MODULE := %s
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/%s
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_ENFORCE_USES_LIBRARIES := false
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_JNI_SHARED_LIBRARIES_ABI := %s
MY_LOCAL_PREBUILT_JNI_LIBS := %s
MY_APP_LIB_PATH := $(TARGET_OUT_ODM)/%s/$(LOCAL_MODULE)/lib/$(LOCAL_JNI_SHARED_LIBRARIES_ABI)
ifneq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI), None)
$(warning MY_APP_LIB_PATH=$(MY_APP_LIB_PATH))
LOCAL_POST_INSTALL_CMD := \mkdir -p $(MY_APP_LIB_PATH) \$(foreach lib, $(MY_LOCAL_PREBUILT_JNI_LIBS), ; cp -f $(LOCAL_PATH)/$(lib) $(MY_APP_LIB_PATH)/$(notdir $(lib)))
endif
include $(BUILD_PREBUILT)"""copy_app_templet = """LOCAL_PATH := $(my-dir)
include $(CLEAR_VARS)
LOCAL_APK_NAME := %s
LOCAL_POST_PROCESS_COMMAND := $(shell mkdir -p $(TARGET_OUT_ODM)/%s/$(LOCAL_APK_NAME) && cp $(LOCAL_PATH)/$(LOCAL_APK_NAME).apk $(TARGET_OUT_ODM)/%s/$(LOCAL_APK_NAME)/)
"""def main(argv):preinstall_dir = os.path.join(argv[1],argv[2])if os.path.exists(preinstall_dir):#Use to include modulesisfound = 'not_found_lib'include_path = preinstall_dir + '/preinstall.mk'android_path = preinstall_dir + '/Android.mk'target_arch = argv[4]if os.path.exists(include_path):os.remove(include_path)if os.path.exists(android_path):os.remove(android_path)includefile = file(include_path, 'w')androidfile = file(android_path, 'w')androidfile.write("include $(call all-subdir-makefiles)\n\n")MY_LOCAL_PREBUILT_JNI_LIBS = '\\' + '\n'for root, dirs, files in os.walk(preinstall_dir):for file_name in files:p = re.compile(r'\S*(?=.apk\b)')found = p.search(file_name)if found:include_apk_path = preinstall_dir + '/' + found.group()makefile_path = include_apk_path + '/Android.mk'apk = preinstall_dir + '/' + found.group() + '.apk'try:zfile = zipfile.ZipFile(apk,'r')except:if os.path.exists(include_apk_path):shutil.rmtree(include_apk_path)os.makedirs(include_apk_path)apkpath = preinstall_dir + '/' + found.group() + '/'shutil.move(apk,apkpath)makefile = file(makefile_path,'w')makefile.write("LOCAL_PATH := $(my-dir)\n\n")makefile.write(templet % (found.group(),argv[3],'None',MY_LOCAL_PREBUILT_JNI_LIBS,argv[3]))continuefor lib_name in zfile.namelist():include_apklib_path = include_apk_path + '/lib' + '/arm'if os.path.exists(include_apk_path):shutil.rmtree(include_apk_path)os.makedirs(include_apklib_path)makefile = file(makefile_path,'w')makefile.write("LOCAL_PATH := $(my-dir)\n\n")apkpath = preinstall_dir + '/' + found.group() + '/'if target_arch == 'arm64':for lib_name in zfile.namelist():lib = re.compile(r'\A(lib/arm64-v8a/)+?')find_name = 'lib/arm64-v8a/'if lib_name.find(find_name) == -1:continuelibfound = lib.search(lib_name)if libfound:isfound = 'arm64-v8a'data = zfile.read(lib_name)string = lib_name.split(libfound.group())libfile = include_apklib_path + '/' + string[1]MY_LOCAL_PREBUILT_JNI_LIBS += '\t' + 'lib/arm64' + '/' + string[1] + '\\' + '\n'if (os.path.isdir(libfile)):continueelse:includelib = file(libfile, 'w')includelib.write(data)try:if cmp(isfound, 'not_found_lib'):include_apklib_path_arm64 = include_apk_path + '/lib/arm64'os.rename(include_apklib_path, include_apklib_path_arm64)except Exception as e:logging.warning('rename dir faild for:' + e)if not cmp(isfound,'not_found_lib'):for lib_name in zfile.namelist():lib = re.compile(r'\A(lib/armeabi-v7a/)+?')find_name = 'lib/armeabi-v7a/'#if not cmp(lib_name,find_name):#    continueif lib_name.find(find_name) == -1:continuelibfound = lib.search(lib_name)if libfound:isfound = 'armeabi-v7a'data = zfile.read(lib_name)string = lib_name.split(libfound.group())libfile = include_apklib_path + '/' + string[1]MY_LOCAL_PREBUILT_JNI_LIBS += '\t' + 'lib/arm' + '/' + string[1] + '\\' + '\n'if(os.path.isdir(libfile)):continueelse:includelib = file(libfile,'w')includelib.write(data)if not cmp(isfound,'not_found_lib'):for lib_name in zfile.namelist():lib = re.compile(r'\A(lib/armeabi/)+?')find_name = 'lib/armeabi/'#if not cmp(lib_name,find_name):#    continueif lib_name.find(find_name) == -1:continuelibfound = lib.search(lib_name)if libfound:data = zfile.read(lib_name)string = lib_name.split(libfound.group())libfile = include_apklib_path + '/' + string[1]MY_LOCAL_PREBUILT_JNI_LIBS += '\t' + 'lib/arm' + '/' + string[1] + '\\' + '\n'if(os.path.isdir(libfile)):continueelse:includelib = file(libfile,'w')includelib.write(data)tmp_jni_libs = '\\' + '\n'if not cmp(MY_LOCAL_PREBUILT_JNI_LIBS,tmp_jni_libs):nolibpath = preinstall_dir + '/' + found.group() + '/lib'shutil.rmtree(nolibpath)makefile.write(templet % (found.group(),argv[3],'None',MY_LOCAL_PREBUILT_JNI_LIBS,argv[3]))else:if isfound == 'arm64-v8a':makefile.write(templet % (found.group(),argv[3], 'arm64', MY_LOCAL_PREBUILT_JNI_LIBS,argv[3]))else:makefile.write(templet % (found.group(),argv[3],'arm',MY_LOCAL_PREBUILT_JNI_LIBS,argv[3]))shutil.move(apk,apkpath)isfound = 'not_found_lib'MY_LOCAL_PREBUILT_JNI_LIBS = '\\' + '\n'makefile.close()breakfor root, dirs,files in os.walk(preinstall_dir):for dir_file in dirs:includefile.write('PRODUCT_PACKAGES += %s\n' %dir_file)breakincludefile.close()if __name__=="__main__":main(sys.argv)

最终生成的Android.mk脚本如下:

LOCAL_PATH := $(my-dir)include $(CLEAR_VARS)
LOCAL_MODULE := MySysManager
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_PATH := $(TARGET_OUT_ODM)/bundled_persist-app
LOCAL_SRC_FILES := $(LOCAL_MODULE)$(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_DEX_PREOPT := false
LOCAL_ENFORCE_USES_LIBRARIES := false
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_JNI_SHARED_LIBRARIES_ABI := None
MY_LOCAL_PREBUILT_JNI_LIBS := \MY_APP_LIB_PATH := $(TARGET_OUT_ODM)/bundled_persist-app/$(LOCAL_MODULE)/lib/$(LOCAL_JNI_SHARED_LIBRARIES_ABI)
ifneq ($(LOCAL_JNI_SHARED_LIBRARIES_ABI), None)
$(warning MY_APP_LIB_PATH=$(MY_APP_LIB_PATH))
LOCAL_POST_INSTALL_CMD :=     mkdir -p $(MY_APP_LIB_PATH)     $(foreach lib, $(MY_LOCAL_PREBUILT_JNI_LIBS), ; cp -f $(LOCAL_PATH)/$(lib) $(MY_APP_LIB_PATH)/$(notdir $(lib)))
endif
include $(BUILD_PREBUILT)

PackageManagerService对预安装应用的处理

//PackageManagerService.javapublic static final String BUNDLED_PERSIST_DIR = "/odm/bundled_persist-app";public static final String BUNDLED_UNINSTALL_GONE_DIR = "/odm/bundled_uninstall_gone-app";//Environment.java
private static final File DIR_PREBUNDLED_UNINSTALL_BACK_ROOT = getDirectory(ENV_PREBUNDLED_UNINSTALL_BACK_ROOT, "/odm/bundled_uninstall_back-app");private static final File DIR_PREBUNDLED_UNINSTALL_GONE_ROOT = getDirectory(ENV_PREBUNDLED_UNINSTALL_GONE_ROOT, "/odm/bundled_uninstall_gone-app");//InitAppsHelper.javapublic void preinstallThirdPartyAPK(PackageParser2 packageParser, ExecutorService executorService,int scanFlags){preinstallPrebundledpersist(packageParser,executorService,scanFlags);preinstallPrebundledUninstallBack(packageParser,executorService,scanFlags);preinstallPrebundledUninstallGone(packageParser,executorService,scanFlags);}private void preinstallPrebundledpersist(PackageParser2 packageParser, ExecutorService executorService,int scanFlags){scanDirTracedLI(new File(mPm.BUNDLED_PERSIST_DIR),null,mPm.getDefParseFlags() | ParsingPackageUtils.PARSE_IS_SYSTEM_DIR| ParsingPackageUtils.PARSE_IS_PREINSTALL,scanFlags | mPm.SCAN_AS_PREINSTALL| SCAN_AS_SYSTEM,packageParser, executorService);}private void preinstallPrebundledUninstallBack(PackageParser2 packageParser, ExecutorService executorService,int scanFlags){scanDirTracedLI(Environment.getPrebundledUninstallBackDirectory(),null,mPm.getDefParseFlags() | ParsingPackageUtils.PARSE_IS_PREBUNDLED_DIR,scanFlags | mPm.SCAN_AS_PREBUNDLED_DIR,packageParser, executorService);}private void preinstallPrebundledUninstallGone(PackageParser2 packageParser, ExecutorService executorService,int scanFlags){scanDirTracedLI(Environment.getPrebundledUninstallGoneDirectory(),null,mPm.getDefParseFlags() | ParsingPackageUtils.PARSE_IS_PREBUNDLED_DIR,scanFlags | mPm.SCAN_AS_PREBUNDLED_DIR,packageParser, executorService);}

需要进一步了解预安装应用相关流程,请查看preinstallPrebundled相关代码流程。

这篇关于Rockchip平台Android应用预安装功能(基于Android13)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/566144

相关文章

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

python管理工具之conda安装部署及使用详解

《python管理工具之conda安装部署及使用详解》这篇文章详细介绍了如何安装和使用conda来管理Python环境,它涵盖了从安装部署、镜像源配置到具体的conda使用方法,包括创建、激活、安装包... 目录pytpshheraerUhon管理工具:conda部署+使用一、安装部署1、 下载2、 安装3

Go语言实现将中文转化为拼音功能

《Go语言实现将中文转化为拼音功能》这篇文章主要为大家详细介绍了Go语言中如何实现将中文转化为拼音功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 有这么一个需求:新用户入职 创建一系列账号比较麻烦,打算通过接口传入姓名进行初始化。想把姓名转化成拼音。因为有些账号即需要中文也需要英

龙蜥操作系统Anolis OS-23.x安装配置图解教程(保姆级)

《龙蜥操作系统AnolisOS-23.x安装配置图解教程(保姆级)》:本文主要介绍了安装和配置AnolisOS23.2系统,包括分区、软件选择、设置root密码、网络配置、主机名设置和禁用SELinux的步骤,详细内容请阅读本文,希望能对你有所帮助... ‌AnolisOS‌是由阿里云推出的开源操作系统,旨

基于WinForm+Halcon实现图像缩放与交互功能

《基于WinForm+Halcon实现图像缩放与交互功能》本文主要讲述在WinForm中结合Halcon实现图像缩放、平移及实时显示灰度值等交互功能,包括初始化窗口的不同方式,以及通过特定事件添加相应... 目录前言初始化窗口添加图像缩放功能添加图像平移功能添加实时显示灰度值功能示例代码总结最后前言本文将

Ubuntu系统怎么安装Warp? 新一代AI 终端神器安装使用方法

《Ubuntu系统怎么安装Warp?新一代AI终端神器安装使用方法》Warp是一款使用Rust开发的现代化AI终端工具,该怎么再Ubuntu系统中安装使用呢?下面我们就来看看详细教程... Warp Terminal 是一款使用 Rust 开发的现代化「AI 终端」工具。最初它只支持 MACOS,但在 20

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d

将Python应用部署到生产环境的小技巧分享

《将Python应用部署到生产环境的小技巧分享》文章主要讲述了在将Python应用程序部署到生产环境之前,需要进行的准备工作和最佳实践,包括心态调整、代码审查、测试覆盖率提升、配置文件优化、日志记录完... 目录部署前夜:从开发到生产的心理准备与检查清单环境搭建:打造稳固的应用运行平台自动化流水线:让部署像

LinuxMint怎么安装? Linux Mint22下载安装图文教程

《LinuxMint怎么安装?LinuxMint22下载安装图文教程》LinuxMint22发布以后,有很多新功能,很多朋友想要下载并安装,该怎么操作呢?下面我们就来看看详细安装指南... linux Mint 是一款基于 Ubuntu 的流行发行版,凭借其现代、精致、易于使用的特性,深受小伙伴们所喜爱。对

Linux(Centos7)安装Mysql/Redis/MinIO方式

《Linux(Centos7)安装Mysql/Redis/MinIO方式》文章总结:介绍了如何安装MySQL和Redis,以及如何配置它们为开机自启,还详细讲解了如何安装MinIO,包括配置Syste... 目录安装mysql安装Redis安装MinIO总结安装Mysql安装Redis搜索Red