要求在产品中预装大量的第三方app,apk文件有600M多,加上相关资源文件,共计4G。

如何把如此多的文件在安装时内置到系统成了问题。解决方法有三: 1 在update.zip中实现复制。写updater-script 通过使用script 复制。见我的另一篇自定义updater-script的文章。 缺点:script脚本需要自己写,不能随make生成。 2 在update.zip中实现复制。在recovery.c中实现。 缺点:SDCARD fat对zip文件有大小限制。 3 在第一次系统启动后实现自动安装。缺点:太慢,大概需要30分。 方法二的实现:

        
  1. 方法二的实现:
  2. 实现的位置在流程中见图片。
  3. 在install_package()的结尾的try_update_binary函数结尾();在src/bootable/recovery/install.c
  4. 下面是具体实现:
  5. //copysomeresfileto/data/
  6. staticchar*res_list[]={"/sdcard/res1.zip","/sdcard/res2.zip"};
  7. staticvoidunzip_res_to_data(void)
  8. {
  9. inti=0;
  10. for(i=0;i<sizeof(res_list)/sizeof(char*);++i)
  11. {
  12. ZipArchivezip_res;
  13. interr=mzOpenZipArchive(res_list[i],&zip_res);
  14. if(err!=0){
  15. LOGI("Can'topen%s\n",res_list[i]);
  16. }
  17. else{
  18. LOGI("startupdate%s\n",res_list[i]);
  19. //Tocreateaconsistentsystemimage,neverusetheclockfortimestamps.
  20. structutimbuftimestamp={1217592000,1217592000};//8/1/2008default
  21. boolsuccess=mzExtractRecursive(&zip_res,"res-private","/data/res-private",
  22. MZ_EXTRACT_FILES_ONLY,&timestamp,
  23. NULL,NULL);
  24. LOGI("update%s%s\n",res_list[i],((success==true)?"success":"failed"));
  25. mzCloseZipArchive(&zip_res);
  26. }
  27. }
  28. dirSetHierarchyPermissions("/data/res-private",1000,1000,0777,0666);
  29. }
  30. //copysomeappfileto/data/app
  31. voidcpfiles(){
  32. ZipArchivezip_apps;
  33. interr=mzOpenZipArchive("/sdcard/myapps.zip",&zip_apps);
  34. if(err!=0){
  35. LOGI("Can'topen%s\n","/sdcard/myapps.zip");
  36. }
  37. else{
  38. //hereneedfixmountforyourdevice
  39. if(mount("/dev/block/mmcblk0p13","/data","ext4",
  40. MS_NOATIME|MS_NODEV|MS_NODIRATIME,"")<0){
  41. fprintf(stderr,"%s:failedtomount",strerror(errno));
  42. }
  43. LOGI("startupdate3rd-apps\n");
  44. //Tocreateaconsistentsystemimage,neverusetheclockfortimestamps.
  45. structutimbuftimestamp={1217592000,1217592000};//8/1/2008default
  46. boolsuccess=mzExtractRecursive(&zip_appss,"app","/data/app",
  47. MZ_EXTRACT_FILES_ONLY,&timestamp,
  48. NULL,NULL);
  49. dirSetHierarchyPermissions("/data/app",1000,1000,0771,0644);
  50. LOGI("updatemyapps%s\n",((success==true)?"success":"failed"));
  51. mzCloseZipArchive(&zip_apps);
  52. //cpresto/data/
  53. unzip_res_to_data();
  54. scan_mounted_volumes();
  55. constMountedVolume*vol=find_mounted_volume_by_mount_point("/data");
  56. if(vol==NULL){
  57. fprintf(stderr,"unmountof%sfailed;nosuchvolume\n","/data");
  58. }else{
  59. unmount_mounted_volume(vol);
  60. }
  61. }
  62. }
  63. //Ifthepackagecontainsanupdatebinary,extractitandrunit.
  64. staticint
  65. try_update_binary(constchar*path,ZipArchive*zip){
  66. .......
  67. cpfiles();
  68. returnINSTALL_SUCCESS;
  69. }

本文出自 “lhc180” 博客,转载请与作者联系!

更多相关文章

  1. android App集成支付宝
  2. Android个推php后台开发
  3. Android神技之 使用SVG以及自定义IconFont字体库
  4. MUI如何安卓离线打包,在Android(安卓)Studio创建Hello World离线
  5. 宏锦软件 Android(安卓)的 ListView 使用详解
  6. Android的桌面上的应用介绍
  7. react-native启动流程(android端)
  8. Android(安卓)重学系列 资源管理系统 资源的初始化加载(上)
  9. 一步一步在 Windows下搭建 React Native Android(安卓)开发环境

随机推荐

  1. 饿了么:Redis Cluster运维方案
  2. 超赞!墙裂推荐这款开源、轻量无 Agent 自
  3. Oracle中最容易被忽略的那些实用特性
  4. 产品研发做到又快又好的一个核心原则
  5. Go语言开发分布式任务调度 轻松搞定高性
  6. 618大促,苏宁如何通过citus打造分布式数据
  7. python学习之做一个文件增删改查小程序
  8. 降低大数据开发难度,轻量级计算实例
  9. RHEL7.6安装Oracle11g数据库--5、安装数
  10. DMHS-达梦实时同步工具