加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Android recovery 复制大量预装 APK的技巧

发布时间:2021-11-24 15:56:26 所属栏目:PHP教程 来源:互联网
导读:要求在产品中预装大量的第三方app,apk文件有600M多,加上相关资源文件,共计4G。 如何把如此多的文件在安装时内置到系统成了问题。解决方法有三: 1 在update.zip中实现复制。写updater-script 通过使用script 复制。见我的另一篇自定义updater-script的文章。
要求在产品中预装大量的第三方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 %sn",  res_list[i]);
        }
        else {
            LOGI("start update %sn", 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 %sn", 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 %sn", "/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-appsn");
        // 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 %sn", ((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 volumen", "/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;

 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读