歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android recovery 復制大量預裝 APK的方法

Android recovery 復制大量預裝 APK的方法

日期:2017/3/1 10:36:23   编辑:Linux編程
要求在產品中預裝大量的第三方app,apk文件有600M多,加上相關資源文件,共計4G。 如何把如此多的文件在安裝時內置到系統成了問題。解決方法有三: 1 在update.zip中實現復制。寫updater-script 通過使用script 復制。見我的另一篇自定義updater-script的文章。 缺點:script腳本需要自己寫,不能隨make生成。 2 在update.zip中實現復制。在recovery.c中實現。 缺點:SDCARD fat對zip文件有大小限制。 3 在第一次系統啟動後實現自動安裝。缺點:太慢,大概需要30分。 方法二的實現:

650) this.width=650;">

  1. 方法二的實現:
  2. 實現的位置在流程中見圖片。
  3. 在install_package()的結尾的try_update_binary函數結尾(); 在src/bootable/recovery/install.c
  4. 下面是具體實現:
  5. //copy some res file to /data/
  6. static char *res_list[] = { "/sdcard/ res1.zip", "/sdcard/ res2.zip"};
  7. static void unzip_res_to_data(void)
  8. {
  9. int i = 0;
  10. for(i = 0; i < sizeof( res_list)/sizeof(char *); ++i)
  11. {
  12. ZipArchive zip_res;
  13. int err = mzOpenZipArchive( res_list[i], &zip_res);
  14. if (err != 0) {
  15. LOGI("Can't open %s\n", res_list[i]);
  16. }
  17. else {
  18. LOGI("start update %s\n", res_list[i]);
  19. // To create a consistent system image, never use the clock for timestamps.
  20. struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
  21. bool success = 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. //copy some app file to /data/app
  31. void cpfiles(){
  32. ZipArchive zip_apps;
  33. int err = mzOpenZipArchive("/sdcard/myapps.zip", &zip_apps);
  34. if (err != 0) {
  35. LOGI("Can't open %s\n", "/sdcard/myapps.zip");
  36. }
  37. else {
  38. //here need fix mount for your device
  39. if (mount("/dev/block/mmcblk0p13", "/data", "ext4",
  40. MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
  41. fprintf(stderr, "%s: failed to mount", strerror(errno));
  42. }
  43. LOGI("start update 3rd-apps\n");
  44. // To create a consistent system image, never use the clock for timestamps.
  45. struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
  46. bool success = 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("update myapps %s\n", ((success==true)?"success":"failed"));
  51. mzCloseZipArchive(&zip_apps);
  52. //cp res to /data/
  53. unzip_res_to_data();
  54. scan_mounted_volumes();
  55. const MountedVolume* vol = find_mounted_volume_by_mount_point("/data");
  56. if (vol == NULL) {
  57. fprintf(stderr, "unmount of %s failed; no such volume\n", "/data");
  58. } else {
  59. unmount_mounted_volume(vol);
  60. }
  61. }
  62. }
  63. // If the package contains an update binary, extract it and run it.
  64. static int
  65. try_update_binary(const char *path, ZipArchive *zip) {
  66. .......
  67. cpfiles();
  68. return INSTALL_SUCCESS;
  69. }
Copyright © Linux教程網 All Rights Reserved