Android(安卓)recovery 复制大量预装 apk的方法
16lz
2021-01-26
要求在产品中预装大量的第三方app,apk文件有600M多,加上相关资源文件,共计4G。
如何把如此多的文件在安装时内置到系统成了问题。解决方法有三: 1 在update.zip中实现复制。写updater-script 通过使用script 复制。见我的另一篇自定义updater-script的文章。 缺点:script脚本需要自己写,不能随make生成。 2 在update.zip中实现复制。在recovery.c中实现。 缺点:SDCARD fat对zip文件有大小限制。 3 在第一次系统启动后实现自动安装。缺点:太慢,大概需要30分。 方法二的实现:
- 方法二的实现:
- 实现的位置在流程中见图片。
- 在install_package()的结尾的try_update_binary函数结尾();在src/bootable/recovery/install.c
- 下面是具体实现:
- //copysomeresfileto/data/
- staticchar*res_list[]={"/sdcard/res1.zip","/sdcard/res2.zip"};
- staticvoidunzip_res_to_data(void)
- {
- inti=0;
- for(i=0;i<sizeof(res_list)/sizeof(char*);++i)
- {
- ZipArchivezip_res;
- interr=mzOpenZipArchive(res_list[i],&zip_res);
- if(err!=0){
- LOGI("Can'topen%s\n",res_list[i]);
- }
- else{
- LOGI("startupdate%s\n",res_list[i]);
- //Tocreateaconsistentsystemimage,neverusetheclockfortimestamps.
- structutimbuftimestamp={1217592000,1217592000};//8/1/2008default
- boolsuccess=mzExtractRecursive(&zip_res,"res-private","/data/res-private",
- MZ_EXTRACT_FILES_ONLY,×tamp,
- NULL,NULL);
- LOGI("update%s%s\n",res_list[i],((success==true)?"success":"failed"));
- mzCloseZipArchive(&zip_res);
- }
- }
- dirSetHierarchyPermissions("/data/res-private",1000,1000,0777,0666);
- }
- //copysomeappfileto/data/app
- voidcpfiles(){
- ZipArchivezip_apps;
- interr=mzOpenZipArchive("/sdcard/myapps.zip",&zip_apps);
- if(err!=0){
- LOGI("Can'topen%s\n","/sdcard/myapps.zip");
- }
- else{
- //hereneedfixmountforyourdevice
- if(mount("/dev/block/mmcblk0p13","/data","ext4",
- MS_NOATIME|MS_NODEV|MS_NODIRATIME,"")<0){
- fprintf(stderr,"%s:failedtomount",strerror(errno));
- }
- LOGI("startupdate3rd-apps\n");
- //Tocreateaconsistentsystemimage,neverusetheclockfortimestamps.
- structutimbuftimestamp={1217592000,1217592000};//8/1/2008default
- boolsuccess=mzExtractRecursive(&zip_appss,"app","/data/app",
- MZ_EXTRACT_FILES_ONLY,×tamp,
- NULL,NULL);
- dirSetHierarchyPermissions("/data/app",1000,1000,0771,0644);
- LOGI("updatemyapps%s\n",((success==true)?"success":"failed"));
- mzCloseZipArchive(&zip_apps);
- //cpresto/data/
- unzip_res_to_data();
- scan_mounted_volumes();
- constMountedVolume*vol=find_mounted_volume_by_mount_point("/data");
- if(vol==NULL){
- fprintf(stderr,"unmountof%sfailed;nosuchvolume\n","/data");
- }else{
- unmount_mounted_volume(vol);
- }
- }
- }
- //Ifthepackagecontainsanupdatebinary,extractitandrunit.
- staticint
- try_update_binary(constchar*path,ZipArchive*zip){
- .......
- cpfiles();
- returnINSTALL_SUCCESS;
- }
本文出自 “lhc180” 博客,转载请与作者联系!
更多相关文章
- android App集成支付宝
- Android个推php后台开发
- Android神技之 使用SVG以及自定义IconFont字体库
- MUI如何安卓离线打包,在Android(安卓)Studio创建Hello World离线
- 宏锦软件 Android(安卓)的 ListView 使用详解
- Android的桌面上的应用介绍
- react-native启动流程(android端)
- Android(安卓)重学系列 资源管理系统 资源的初始化加载(上)
- 一步一步在 Windows下搭建 React Native Android(安卓)开发环境