在Android 系统Udate时,需要删除系统原先的全部数据。这里提供一个方法,在系统Update后,恢复个人自己的私有文件或数据。
1 修改 /bootable/recovery/recovery.c
2 提供一个特定目录保存自己的文件/recovery-bak/data-bak.zip,也可以自定义备份文件夹;要与上面的代码相对应。
- /bootable/recovery/recovery.c main函数:
- .....
- } else if (wipe_data) {
- printf("wipe_data..., default INSTALL_SUCCESS value = %d\n", status);
- if (device_wipe_data()) status = INSTALL_ERROR;
- if (erase_volume("/data")) status = INSTALL_ERROR;
- if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
- if (copy_bak()) status = INSTALL_ERROR;
- if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
- 添加函数
- static int
- copy_bak(void) {
- if (ensure_path_mounted("/data") !=0) {
- LOGE("ensure_path_mounted failed to mount \"%s\"\n", "/data");
- return -1;
- }
- if (ensure_path_mounted("/recovery-bak") !=0) {
- LOGE("ensure_path_mounted failed to mount \"%s\"\n", "/recovery-bak");
- return -1;
- }
- ZipArchive zip_bak;
- int err = mzOpenZipArchive("/recovery-bak/data-bak.zip", &zip_bak);
- if (err != 0) {
- LOGI("Can't open %s\n", "data-bak.zip");
- return -1;
- }
- else {
- LOGI("start copy bak\n");
- // To create a consistent system p_w_picpath, never use the clock for timestamps.
- struct utimbuf timestamp = { 1217592000, 1217592000 }; // 8/1/2008 default
- bool success = mzExtractRecursive(&zip_bak, "data", "/data",
- MZ_EXTRACT_FILES_ONLY, ×tamp,
- NULL, NULL);
- mzCloseZipArchive(&zip_bak);
- LOGI("copy bak %s\n",((success==true)?"success":"failed"));
- dirSetHierarchyPermissions("/data/app", 1000, 1000, 0771, 0644);
- }
- if (ensure_path_unmounted("/data") !=0) {
- LOGE("ensure_path_unmounted failed to unmount \"%s\"\n", "/data");
- return -1;
- }
- if (ensure_path_unmounted("/recovery-bak") !=0) {
- LOGE("ensure_path_unmounted failed to unmount \"%s\"\n", "/recovery-bak");
- return -1;
- }
- return 0;
- }