- 论坛徽章:
- 0
|
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分。
方法二的实现:
方法二的实现:
实现的位置在流程中见图片。
- 在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;
- }
复制代码 |
|