android 恢复出厂设置不清除的分区,Android如何在恢复出厂设置时不删除掉/data/media/0/里面指定的目录...
时间: 2023-08-10 07:18:28 浏览: 224
在 Android 恢复出厂设置时,会清除 /data 分区下的所有数据。但是如果你想保留 /data/media/0/ 目录下的数据,可以通过以下步骤实现:
1. 在 /data/ 目录下创建一个名为 “dontwipe” 的文件夹。
2. 在 /system/etc/ 目录下创建一个名为 “vold.fstab” 的文件,并在其中添加以下代码:
```
dev_mount sdcard /mnt/sdcard auto /data/media/0 auto
```
这段代码将 /data/media/0/ 目录挂载到 /mnt/sdcard 目录下。
3. 在 /system/etc/init.d/ 目录下创建一个名为 “99dontwipe” 的脚本文件,并在其中添加以下代码:
```
#!/system/bin/sh
mount -o bind /data/dontwipe /data/media/0
```
这段代码将 /data/dontwipe 目录绑定到 /data/media/0/ 目录下。
4. 将脚本文件赋予执行权限:
```
chmod +x /system/etc/init.d/99dontwipe
```
完成以上步骤后,当你执行恢复出厂设置操作时,/data/dontwipe 目录不会被删除,因此 /data/media/0/ 目录下的数据也不会被清除。
相关问题
Android恢复出厂设置会删除data/vendor/auth下的东西吗
Android 恢复出厂设置会删除 `/data/vendor/auth` 下的所有文件,因为这个目录是存储供应商授权文件和证书等敏感信息的地方。恢复出厂设置的过程会清除所有用户数据和设置,包括用户数据分区(即 `/data` 目录),因此 `/data/vendor/auth` 目录下的文件也会被删除。
当然,如果您手动备份了 `/data/vendor/auth` 目录下的文件,那么在恢复出厂设置后,您可以将备份文件还原到相应的目录中。但是需要注意的是,这些文件包含敏感信息,如果未经授权地访问或泄露,可能会对系统和用户造成不利影响,因此需要谨慎处理。
bootable/recovery/recovery.cpp 恢复出厂设置走的哪部分
在 `bootable/recovery/recovery.cpp` 文件中,恢复出厂设置是由 `wipe_data()` 函数实现的。该函数会执行以下操作:
1. 显示恢复出厂设置的确认界面。
2. 如果用户确认要执行恢复出厂设置操作,则执行以下步骤:
- 格式化用户数据分区。
- 格式化缓存分区。
- 执行 `format_volume()` 函数,格式化 `/data` 分区中的指定文件系统,例如 `ext4`、`f2fs` 等。
- 执行 `wipe_dalvik_cache()` 函数,清空 `dalvik-cache` 目录。
- 执行 `reboot()` 函数,重启设备。
下面是 `wipe_data()` 函数的部分代码:
```cpp
bool wipe_data(int fd, const std::vector<std::string>& args) {
...
// Show the confirmation screen and wait for user confirmation.
ui->Print("\n-- Wiping data...\n");
ui->ShowProgress(0.0, 0);
if (!ui->PromptYesNo("Confirm wipe?")) {
ui->Print("Cancelled by user\n");
return false;
}
ui->Print("\n");
if (!ui->IsTextVisible()) {
ui->ShowText(true);
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /cache...\n");
if (format_volume(CACHE_MNT_POINT)) {
ui->Print("Cache wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Data wipe complete.\n");
ui->Print("Formatting /cache...\n");
if (format_volume(CACHE_MNT_POINT)) {
ui->Print("Cache wipe failed (unknown reason)\n");
return false;
}
ui->Print("Cache wipe complete.\n");
ui->Print("\n");
// Format /data partition with the specified file system.
std::string fs_type;
if (!android::base::GetProperty("ro.crypto.fs_type", &fs_type)) {
fs_type = "ext4";
}
ui->Print("Formatting /data...\n");
if (format_volume(DATA_MNT_POINT, fs_type)) {
ui->Print("Data wipe failed (unknown reason)\n");
return false;
}
ui->Print("Data wipe complete.\n");
// Wipe dalvik-cache
ui->Print("Wiping dalvik-cache...\n");
if (wipe_dalvik_cache(fd, ui)) {
ui->Print("Error wiping dalvik-cache.\n");
}
ui->Print("\n-- Wipe complete\n");
ui->ShowText(false);
// Reboot the device
ui->Print("\n-- Now rebooting...\n");
reboot(RB_AUTOBOOT);
return true;
}
```
需要注意的是,`wipe_data()` 函数会执行格式化和清空操作,因此请谨慎使用该函数。在实际使用中,一般需要进行适当的修改和定制,以满足特定需求。