`
quanminchaoren
  • 浏览: 912242 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android Recovery 复制大量预装apk方法

阅读更多

要求在产品中预装大量的第三方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. 实现的位置在流程中见图片。 
  4. 在install_package()的结尾的try_update_binary函数结尾(); 在src/bootable/recovery/install.c 
  5.  
  6. 下面是具体实现: 
  7.  
  8. //copy some res file to /data/  
  9.  
  10. static   char  *res_list[] = {  "/sdcard/ res1.zip" "/sdcard/ res2.zip" }; 
  11.  
  12. static   void  unzip_res_to_data( void
  13.     int  i = 0; 
  14.  
  15.     for (i = 0; i <  sizeof ( res_list)/ sizeof ( char  *); ++i) 
  16.     { 
  17.         ZipArchive zip_res; 
  18.         int  err = mzOpenZipArchive( res_list[i], &zip_res); 
  19.         if  (err != 0) { 
  20.             LOGI("Can't open %s\n" ,  res_list[i]); 
  21.         } 
  22.         else  { 
  23.             LOGI("start update %s\n" , res_list[i]); 
  24.             // To create a consistent system image, never use the clock for timestamps.  
  25.             struct  utimbuf timestamp = { 1217592000, 1217592000 };   // 8/1/2008 default  
  26.             bool  success = mzExtractRecursive(&zip_res,  "res-private" "/data/res-private"
  27.                     MZ_EXTRACT_FILES_ONLY, &timestamp, 
  28.                     NULL, NULL); 
  29.             LOGI("update %s %s\n" , res_list[i], ((success== true )? "success" : "failed" )); 
  30.             mzCloseZipArchive(&zip_res); 
  31.         } 
  32.     } 
  33.  
  34.     dirSetHierarchyPermissions("/data/res-private" , 1000, 1000, 0777, 0666); 
  35.  
  36. //copy some app file to /data/app  
  37. void  cpfiles(){ 
  38.  
  39.     ZipArchive zip_apps; 
  40.     int  err = mzOpenZipArchive( "/sdcard/myapps.zip" , &zip_apps); 
  41.     if  (err != 0) { 
  42.         LOGI("Can't open %s\n" "/sdcard/myapps.zip" ); 
  43.     } 
  44.     else  { 
  45.         //here need fix mount for your device  
  46.         if  (mount( "/dev/block/mmcblk0p13" "/data" "ext4"
  47.                     MS_NOATIME | MS_NODEV | MS_NODIRATIME, "" ) < 0) { 
  48.             fprintf(stderr, "%s: failed to mount" , strerror(errno)); 
  49.         } 
  50.  
  51.         LOGI("start update 3rd-apps\n" ); 
  52.         // To create a consistent system image, never use the clock for timestamps.  
  53.         struct  utimbuf timestamp = { 1217592000, 1217592000 };   // 8/1/2008 default  
  54.         bool  success = mzExtractRecursive(&zip_appss,  "app" "/data/app"
  55.                 MZ_EXTRACT_FILES_ONLY, &timestamp, 
  56.                 NULL, NULL); 
  57.         dirSetHierarchyPermissions("/data/app" , 1000, 1000, 0771, 0644); 
  58.         LOGI("update myapps %s\n" , ((success== true )? "success" : "failed" )); 
  59.         mzCloseZipArchive(&zip_apps); 
  60.  
  61. //cp res to /data/  
  62.         unzip_res_to_data(); 
  63.  
  64.         scan_mounted_volumes(); 
  65.         const  MountedVolume* vol = find_mounted_volume_by_mount_point( "/data" ); 
  66.         if  (vol == NULL) { 
  67.             fprintf(stderr, "unmount of %s failed; no such volume\n" "/data" ); 
  68.         } else  { 
  69.             unmount_mounted_volume(vol); 
  70.         } 
  71.     } 
  72.  
  73.  
  74.  
  75. // If the package contains an update binary, extract it and run it.  
  76. static   int  
  77. try_update_binary(const   char  *path, ZipArchive *zip) { 
  78.   
  79. ....... 
  80.  
  81.     cpfiles(); 
  82.     return  INSTALL_SUCCESS; 
  83. }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics