bootable/recovery目录里有什么?
时间: 2024-01-16 07:04:14 浏览: 23
bootable/recovery目录是Android系统源代码中的一个目录,主要包含了Android系统的恢复模式相关的代码和资源。具体来说,该目录中包含了以下内容:
1. bootable/recovery/Android.mk:Android系统构建系统使用的Makefile文件,用于编译恢复模式相关的代码。
2. bootable/recovery/recovery.cpp:恢复模式的主要入口点,包含了恢复模式的初始化代码、命令解析等核心逻辑。
3. bootable/recovery/roots.cpp:定义了恢复模式中的文件系统根目录,包括/system、/data等。
4. bootable/recovery/variables.cpp:定义了一些恢复模式中的全局变量和常量,如恢复模式的版本号等。
5. bootable/recovery/res/:包含了恢复模式中使用的一些资源文件,如界面布局、图片等。
6. bootable/recovery/etc/:包含了恢复模式中使用的一些配置文件,如recovery.fstab、recovery.twrpbak等。
总之,bootable/recovery目录是Android系统中一个非常重要的目录,它提供了从恢复模式进入到Android系统的关键功能。
相关问题
bootable/recovery//recovery.cpp
`bootable/recovery/recovery.cpp` 是 Android 源码中 `recovery` 模块的主要启动代码,该文件定义了 `main()` 函数,用于启动 `recovery` 程序,并执行相应的操作。下面是 `recovery.cpp` 文件的部分代码:
```cpp
int main(int argc, char **argv) {
RecoveryUI::Options ui_options;
ui_options.allow_toggle_display = true;
ui_options.locale = "";
RecoveryUI ui(ui_options);
...
// Initialize the recovery API.
if (register_update_callback(&on_update, &ui)) {
LOGE("Can't register the update callback\n");
return EXIT_FAILURE;
}
...
// Initialize the command listener.
if (!strcmp(basename(argv[0]), "recovery")) {
// In recovery mode, only listen on the socket.
if (socket_name.empty()) {
socket_name = DEFAULT_SOCKET;
}
if (start_recovery_socket(socket_name, &should_abort)) {
LOGE("Can't start recovery service with socket '%s'\n", socket_name.c_str());
return EXIT_FAILURE;
}
} else {
...
}
...
}
```
在 `main()` 函数中,首先创建了一个 `RecoveryUI` 对象,用于管理 `recovery` 界面的显示。接着,通过调用 `register_update_callback()` 函数注册了更新回调函数 `on_update()`,用于在更新过程中更新 `recovery` 界面的显示。最后,根据启动命令行参数,启动相应的服务,包括 `recovery` 服务和 `adb` 服务。
需要注意的是,`recovery` 模块的启动和执行过程比较复杂,涉及到诸多细节问题。如果想深入了解 `recovery` 模块的实现原理,需要仔细阅读 `bootable/recovery` 目录下的其他源代码文件。
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()` 函数会执行格式化和清空操作,因此请谨慎使用该函数。在实际使用中,一般需要进行适当的修改和定制,以满足特定需求。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)