How to copy a large number of pre-installed apk files in Android recovery

Source: Internet
Author: User

A large number of third-party apps are required to be pre-installed in the product. The apk file is larger than MB, and the related resource files are added, totaling 4 GB.

How to Build so many files into the system during installation becomes a problem. Solution 3: 1. Copy Data in update.zip. Write updater-script and copy it by using script. See my other custom updater-script article. Disadvantage: the script must be written by yourself and cannot be generated with make. 2. copy the file in update.zip. Implemented in recovery. c. Disadvantage: SDCARD fat has a limit on the size of zip files. 3. Automatic Installation is enabled after the first system startup. Disadvantage: It is too slow. It takes about 30 minutes. Implementation of Method 2:

 

650) this. width = 650; "src =" http://img1.51cto.com/attachment/201201/182526857.png "border =" 0 "alt =" "/>

 
 
  1. Implementation of Method 2:
  2.  
  3. See the image in the process.
  4. End of the try_update_binary function at the end of install_package (); in src/bootable/recovery/install. c
  5.  
  6. The specific implementation is as follows:
  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. {
  14. Int I = 0;
  15.  
  16. For (I = 0; I <sizeof (res_list)/sizeof (char *); ++ I)
  17. {
  18. ZipArchive zip_res;
  19. Int err = mzOpenZipArchive (res_list [I], & zip_res );
  20. If (err! = 0 ){
  21. LOGI ("Can't open % s \ n", res_list [I]);
  22. }
  23. Else {
  24. LOGI ("start update % s \ n", res_list [I]);
  25. // To create a consistent system image, never use the clock for timestamps.
  26. Struct utimbuf timestamp = {1217592000,121 7592000}; // 8/1/2008 default
  27. Bool success = mzExtractRecursive (& zip_res, "res-private", "/data/res-private ",
  28. MZ_EXTRACT_FILES_ONLY, & timestamp,
  29. NULL, NULL );
  30. LOGI ("update % s \ n", res_list [I], (success = true )? "Success": "failed "));
  31. MzCloseZipArchive (& zip_res );
  32. }
  33. }
  34.  
  35. DirSetHierarchyPermissions ("/data/res-private", 1000,100 0, 0777,066 6 );
  36. }
  37.  
  38. // Copy some app file to/data/app
  39. Void cpfiles (){
  40.  
  41. ZipArchive zip_apps;
  42. Int err = mzOpenZipArchive ("/sdcard/mydomain.zip", & zip_apps );
  43. If (err! = 0 ){
  44. LOGI ("Can't open % s \ n", "/sdcard/mydomain.zip ");
  45. }
  46. Else {
  47. // Here need fix mount for your device
  48. If (mount ("/dev/block/mmcblk0p13", "/data", "ext4 ",
  49. MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") <0 ){
  50. Fprintf (stderr, "% s: failed to mount", strerror (errno ));
  51. }
  52.  
  53. LOGI ("start update 3rd-apps \ n ");
  54. // To create a consistent system image, never use the clock for timestamps.
  55. Struct utimbuf timestamp = {1217592000,121 7592000}; // 8/1/2008 default
  56. Bool success = mzExtractRecursive (& zip_appss, "app", "/data/app ",
  57. MZ_EXTRACT_FILES_ONLY, & timestamp,
  58. NULL, NULL );
  59. DirSetHierarchyPermissions ("/data/app", 1000,100 0, 0771,064 4 );
  60. LOGI ("update myapps % s \ n", (success = true )? "Success": "failed "));
  61. MzCloseZipArchive (& zip_apps );
  62.  
  63. // Cp res to/data/
  64. Unzip_res_to_data ();
  65.  
  66. Scan_mounted_volumes ();
  67. Const MountedVolume * vol = find_mounted_volume_by_mount_point ("/data ");
  68. If (vol = NULL ){
  69. Fprintf (stderr, "unmount of % s failed; no such volume \ n", "/data ");
  70. } Else {
  71. Unmount_mounted_volume (vol );
  72. }
  73. }
  74.  
  75. }
  76.  
  77.  
  78. // If the package contains an update binary, extract it and run it.
  79. Static int
  80. Try_update_binary (const char * path, ZipArchive * zip ){
  81. .......
  82.  
  83. Cpfiles ();
  84. Return INSTALL_SUCCESS;
  85. }

This article is from the "lhc180" blog. For more information, contact the author!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.