650) this.width=650;">
- 方法二的實現:
- 實現的位置在流程中見圖片。
- 在install_package()的結尾的try_update_binary函數結尾(); 在src/bootable/recovery/install.c
- 下面是具體實現:
- //copy some res file to /data/
- static char *res_list[] = { "/sdcard/ res1.zip", "/sdcard/ res2.zip"};
- static void unzip_res_to_data(void)
- {
- int i = 0;
- for(i = 0; i < sizeof( res_list)/sizeof(char *); ++i)
- {
- ZipArchive zip_res;
- int err = mzOpenZipArchive( res_list[i], &zip_res);
- if (err != 0) {
- LOGI("Can't open %s\n", res_list[i]);
- }
- else {
- LOGI("start update %s\n", res_list[i]);
- // To create a consistent system image, never use the clock for timestamps.
- struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
- bool success = 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);
- }
- //copy some app file to /data/app
- void cpfiles(){
- ZipArchive zip_apps;
- int err = mzOpenZipArchive("/sdcard/myapps.zip", &zip_apps);
- if (err != 0) {
- LOGI("Can't open %s\n", "/sdcard/myapps.zip");
- }
- else {
- //here need fix mount for your device
- if (mount("/dev/block/mmcblk0p13", "/data", "ext4",
- MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
- fprintf(stderr, "%s: failed to mount", strerror(errno));
- }
- LOGI("start update 3rd-apps\n");
- // To create a consistent system image, never use the clock for timestamps.
- struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
- bool success = mzExtractRecursive(&zip_appss, "app", "/data/app",
- MZ_EXTRACT_FILES_ONLY, ×tamp,
- NULL, NULL);
- dirSetHierarchyPermissions("/data/app", 1000, 1000, 0771, 0644);
- LOGI("update myapps %s\n", ((success==true)?"success":"failed"));
- mzCloseZipArchive(&zip_apps);
- //cp res to /data/
- unzip_res_to_data();
- scan_mounted_volumes();
- const MountedVolume* vol = find_mounted_volume_by_mount_point("/data");
- if (vol == NULL) {
- fprintf(stderr, "unmount of %s failed; no such volume\n", "/data");
- } else {
- unmount_mounted_volume(vol);
- }
- }
- }
- // If the package contains an update binary, extract it and run it.
- static int
- try_update_binary(const char *path, ZipArchive *zip) {
- .......
- cpfiles();
- return INSTALL_SUCCESS;
- }