完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
Platform: RK3288
OS: Android 6.0 Kernel: 3.10.92 Rockchip默认提供了机制来预置第三方APK, 方法很简单: 1. 在device/rockchip/rk3288创建preinstall目录(如果要可卸载,那就创建preinstall_del目录) 2. 将你要预安装的APK放进此目录即可 下面看下实现原理过程: device/rockchip/common/device.mk中有: ifneq ($(strip $(TARGET_DEVICE)), ) TARGET_DEVICE_DIR=$(shell test -d device && find device -maxdepth 4 -path '*/$(TARGET_DEVICE)/BoardConfig.mk') TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(TARGET_DEVICE_DIR))) $(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) system_app) $(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) preinstall) $(shell python device/rockchip/common/auto_generator.py $(TARGET_DEVICE_DIR) preinstall_del) -include $(TARGET_DEVICE_DIR)/system_app/preinstall.mk -include $(TARGET_DEVICE_DIR)/preinstall/preinstall.mk -include $(TARGET_DEVICE_DIR)/preinstall_del/preinstall.mk endif auto_generator.py是个python脚本,用于生成Android.mk和preinstall.mk文件, def main(argv): preinstall_dir = os.path.join(argv[1] + '/' + argv[2]) if os.path.exists(preinstall_dir): #Use to define modules for install makefile_path = preinstall_dir + '/Android.mk' #Use to include modules include_path = preinstall_dir + '/preinstall.mk' if os.path.exists(makefile_path): os.remove(makefile_path) if os.path.exists(include_path): os.remove(include_path) makefile = file(makefile_path, 'w') includefile = file(include_path, 'w') makefile.write("LOCAL_PATH := $(my-dir)nn") for root, dirs, files in os.walk(preinstall_dir): for file_name in files: p = re.compile(r'S*(?=.apkb)') found = p.search(file_name) if found: makefile.write(templet %(found.group(), argv[2])) includefile.write('PRODUCT_PACKAGES += %sn' %found.group()) makefile.close() includefile.close() Android.mk用于制定编译规则,如我在preinstall目录下放了个AVSourceTester.apk,那么生成的文件内容是 LOCAL_PATH := $(my-dir) include $(CLEAR_VARS) LOCAL_MODULE := AVSourceTester LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_PATH := $(TARGET_OUT)/preinstall LOCAL_SRC_FILES := $(LOCAL_MODULE)$(COMMON_ANDROID_PACKAGE_SUFFIX) LOCAL_CERTIFICATE := PRESIGNED LOCAL_DEX_PREOPT := false LOCAL_MODULE_TAGS := optional LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) include $(BUILD_PREBUILT) preinstall.mk内容如下: PRODUCT_PACKAGES += AVSourceTester 编译系统之后,生成路径是 out/target/product/rk3288/system/preinstall/AVSourceTester/AVSourceTester.apk 系统开机之后会调用copyDirectory()@PackageManagerService.java File preinstallAppDir = new File(Environment.getRootDirectory(), "preinstall"); File preinstallAppDelDir = new File(Environment.getRootDirectory(), "preinstall_del"); if ((!SystemProperties.getBoolean("persist.sys.preinstalled", false)) && (!"trigger_restart_min_framework".equals(SystemProperties.get("vold.decrypt", null)))) { // mPreInstallObserver = new AppDirObserver( // mPreinstallAppDir.getPath(), OBSERVER_EVENTS, false); // mPreInstallObserver.startWatching(); if (preinstallAppDir.exists()) { // scanDirLI(mPreinstallAppDir, 0, scanMode, 0); copyPackagesToAppInstallDir(preinstallAppDir); } // mPreInstallDelObserver = new AppDirObserver( // mPreinstallAppDelDir.getPath(), OBSERVER_EVENTS, false); // mPreInstallDelObserver.startWatching(); if (preinstallAppDelDir.exists()) { copyPackagesToAppInstallDir(preinstallAppDelDir); deletePreinstallDir(preinstallAppDelDir); } SystemProperties.set("persist.sys.preinstalled", "1"); }//$_rockchip_$_modify_end 关键函数是copyPackagesToAppInstallDir(),它会把preinstall目录下的安装文件copy到安装目录。 这样安装就成功了。 安装preinstall和preinstall_del的区别在于后者在安装完之后会删除系统目录下的apk,因此要是做了恢复出厂设置或者卸载动作,那就不能恢复了。 删除函数是deletePreinstallDir(),通过init中的ctl命令实现。 private void deletePreinstallDir(File dir) { String[] files = dir.list(); if (files != null) { Slog.d(TAG, "Ready to cleanup preinstall"); SystemProperties.set("ctl.start", "preinst_clr"); } } 不过在source code中并没有找到preinst_clr这个service,可以在init.rc中自己添加下, 参考的是 Nu3001/device_rockchip_rksdk service preinst_clr /system/bin/preinstall_cleanup.sh disabled oneshot preinstall_cleanup.sh这个文件默认是有的,本质是直接删除apk。 #!/system/bin/sh log -t PackageManager "Start to clean up /system/preinstall_del/" mount -o rw,remount -t ext4 /system rm system/preinstall_del/*.* mount -o ro,remount -t ext4 /system |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于米尔瑞芯微RK3576核心板/开发板的人脸疲劳检测应用方案
3237 浏览 0 评论
3081 浏览 1 评论
2559 浏览 1 评论
3897 浏览 1 评论
4629 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-2-2 15:28 , Processed in 0.558440 second(s), Total 70, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号