首页 > 其他分享 >Android 11 recovery恢复出厂设置保留某些文件

Android 11 recovery恢复出厂设置保留某些文件

时间:2024-07-09 15:30:13浏览次数:11  
标签:11 recovery -- cache Android main data log

/bootable/recovery/recovery.cpp

recovery的注释,流程解释!

/*
 * The recovery tool communicates with the main system through /cache files.
 *   /cache/recovery/command - INPUT - command line for tool, one arg per line
 *   /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
 *
 * The arguments which may be supplied in the recovery.command file:
 *   --update_package=path - verify install an OTA package file
 *   --install_with_fuse - install the update package with FUSE. This allows installation of large
 *       packages on LP32 builds. Since the mmap will otherwise fail due to out of memory.
 *   --wipe_data - erase user data (and cache), then reboot
 *   --prompt_and_wipe_data - prompt the user that data is corrupt, with their consent erase user
 *       data (and cache), then reboot
 *   --wipe_cache - wipe cache (but not user data), then reboot
 *   --show_text - show the recovery text menu, used by some bootloader (e.g. http://b/36872519).
 *   --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
 *   --just_exit - do nothing; exit and reboot
 *
 * After completing, we remove /cache/recovery/command and reboot.
 * Arguments may also be supplied in the bootloader control block (BCB).
 * These important scenarios must be safely restartable at any point:
 *
 * FACTORY RESET
 * 1. user selects "factory reset"
 * 2. main system writes "--wipe_data" to /cache/recovery/command
 * 3. main system reboots into recovery
 * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
 *    -- after this, rebooting will restart the erase --
 * 5. erase_volume() reformats /data
 * 6. erase_volume() reformats /cache
 * 7. FinishRecovery() erases BCB
 *    -- after this, rebooting will restart the main system --
 * 8. main() calls reboot() to boot main system
 *
 * OTA INSTALL
 * 1. main system downloads OTA package to /cache/some-filename.zip
 * 2. main system writes "--update_package=/cache/some-filename.zip"
 * 3. main system reboots into recovery
 * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
 *    -- after this, rebooting will attempt to reinstall the update --
 * 5. InstallPackage() attempts to install the update
 *    NOTE: the package install must itself be restartable from any point
 * 6. FinishRecovery() erases BCB
 *    -- after this, rebooting will (try to) restart the main system --
 * 7. ** if install failed **
 *    7a. PromptAndWait() shows an error icon and waits for the user
 *    7b. the user reboots (pulling the battery, etc) into the main system
 */

RK3228H开发之Rockchip Recovery及android系统升级详解

5.1 RK Log 重定向 Log re-direct

  1. 功能说明:Log 可以输出到串口、SD卡、/cache/recovery/、三个地方。
    Function description: Log can be output to serial port, SD card, or /cache/recovery/.
  2. 打开方式:
(1)<Android 10 
    bootable/recovery/Android.mk: 
    Enable method: modify bootable/recovery/Android.mk file: 
    REDIRECT_LOG_TO := UART   将日志输出到串口  
    REDIRECT_LOG_TO := UART   output the log to serial port 
    
    REDIRECT_LOG_TO := CACHE  将日志输出到/cache/recovery/目录下 
    REDIRECT_LOG_TO := CACHE   output the log to /cache/recovery/ directory 
    
    REDIRECT_LOG_TO := SDCARD  将日志输出到SD卡中recovery.log 
    REDIRECT_LOG_TO := SDCARD   output the log to SD card recovery.log 
(2)>=Android 10 
    bootable/recovery/Android.bp: 
    -DLogToSerial  将日志输出到串口    
    -DLogToSerial  output the log to serial port 
 
    -DLogToCache  将日志输出到/cache/recovery/目录下 
    -DLogToCache  output the log to /cache/recovery/ directory 
    
    -DLogToSDCard  将日志输出到SD卡中recovery.log 
    -DLogToSDCard  output the log to SD card recovery.log 

恢复出厂设置不擦除某个数据

1.创建一个新的文件分区,类似于system/(它只可读),但是可读可写,恢复出厂设置不清理
2.不新建分区,恢复出厂设置,通过代码保留某个数据

Android recovery 清除数据,跟随源码看,它自己会保留某个文件不被清理!

其实也就是保留了/cache/下的部分文件!(如果不格式化刷机,保留的东西就不会被清理掉)

bootable/recovery/install/wipe_data.cpp

//清理函数入口
bool WipeData(Device* device, bool convert_fbe) {
  RecoveryUI* ui = device->GetUI();
  ui->Print("\n-- Wiping data...\n");

  if (!FinishPendingSnapshotMerges(device)) {
    ui->Print("Unable to check update status or complete merge, cannot wipe partitions.\n");
    return false;
  }

  bool success = device->PreWipeData();
  if (success) {
    success &= EraseVolume(DATA_ROOT, ui, convert_fbe);//erase_volume()重点
    bool has_cache = volume_for_mount_point("/cache") != nullptr;
    if (has_cache) {
      success &= EraseVolume(CACHE_ROOT, ui, false);
    }
    if (volume_for_mount_point(METADATA_ROOT) != nullptr) {
      success &= EraseVolume(METADATA_ROOT, ui, false);
    }
  }
  if (success) {
    success &= device->PostWipeData();
  }
  erase_baseparameter();
  ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
  return success;
}

static bool EraseVolume(const char* volume, RecoveryUI* ui, bool convert_fbe) {
  bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);
  bool is_data = (strcmp(volume, DATA_ROOT) == 0);

  ui->SetBackground(RecoveryUI::ERASING);
  ui->SetProgressType(RecoveryUI::INDETERMINATE);

  std::vector<saved_log_file> log_files;
  if (is_cache) {
    // If we're reformatting /cache, we load any past logs (i.e. "/cache/recovery/last_*") and the
    // current log ("/cache/recovery/log") into memory, so we can restore them after the reformat.
    log_files = ReadLogFilesToMemory();//保存("/cache/recovery/log")到内存,不清理掉
  }

  ui->Print("Formatting %s...\n", volume);
  ...
}
--- a/bootable/recovery/recovery_utils/logging.cpp
+++ b/bootable/recovery/recovery_utils/logging.cpp
@@ -270,7 +270,8 @@ std::vector<saved_log_file> ReadLogFilesToMemory() {

   std::vector<saved_log_file> log_files;
   while ((de = readdir(d.get())) != nullptr) {
-    if (strncmp(de->d_name, "last_", 5) == 0 || strcmp(de->d_name, "log") == 0 || strncmp(de->d_name, "Recovery_", 9) == 0) {
+    if (strncmp(de->d_name, "last_", 5) == 0 || strcmp(de->d_name, "log") == 0 || strncmp(de->d_name, "Recovery_", 9) == 0
+    || strcmp(de->d_name, "bootanimation") == 0) {
       std::string path = android::base::StringPrintf("%s/%s", CACHE_LOG_DIR, de->d_name);

       struct stat sb;
diff --git a/frameworks/base/core/java/android/os/RecoverySystem.java b/frameworks/base/core/java/android/os/RecoverySystem.java
index 769f1d34d4..224a0f19a6 100755
--- a/frameworks/base/core/java/android/os/RecoverySystem.java
+++ b/frameworks/base/core/java/android/os/RecoverySystem.java
@@ -1213,6 +1213,7 @@ public class RecoverySystem {
        public static String handleAftermath(Context context) {
             if (names[i].equals(RECOVERY_TEST_STATE)) continue;
             if (reservePackage && names[i].equals(BLOCK_MAP_FILE.getName())) continue;
             if (reservePackage && names[i].equals(UNCRYPT_PACKAGE_FILE.getName())) continue;
+            if (names[i].equals("bootanimation.zip")) continue;
             Log.i(TAG,"names[i]:" + names[i]);//开机完成后,如果不是上面判断的东西,就都清理掉 TAG = RecoverySystem

             recursiveDelete(new File(RECOVERY_DIR, names[i]));
    

Android7.x 通过Recovery保留特定文件实现恢复出厂设置后保留系统语言设置

Android如何在恢复出厂设置时不删除掉/data/media/0/里面指定的目录

Android 恢复出厂设置流程-CSDN博客

标签:11,recovery,--,cache,Android,main,data,log
From: https://www.cnblogs.com/kato-T/p/18292032

相关文章

  • 将android studio安装到D盘
    双击exe安装,勾选指定到D盘复选框为[不创建快捷方式],点击[Install]安装完成启动不导入设置不发送信息取消下一步自定义设置设置主题指定sdk下载位置下一步下一步同意开始下载下载完成点击查看详情Preparing"......
  • Lunaproxy与711Proxy的对比与优劣分析
    今天我们来深入对比两款在市场上备受关注的代理IP服务:Lunaproxy和711Proxy。接下来,我们将从多个角度对这两款服务进行详细分析,帮助大家做出明智的选择。优势分析711Proxy的优势1.性价比高:711Proxy提供多种灵活的套餐选择,价格经济实惠,性价比在所有代理服务商中数一数二,从小......
  • Android面试题之Activity的启动模式和flag
    本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点Activity中的几种启动模式activity的几种启动模式是android中常考的知识点,一般会考察有哪几种启动模式,以及每种启动模式在什么场景下使用:standard:这个是android......
  • Python酷库之旅-第三方库Pandas(011)
    目录一、用法精讲25、pandas.HDFStore.get函数25-1、语法25-2、参数25-3、功能25-4、返回值25-5、说明25-6、用法25-6-1、数据准备25-6-2、代码示例25-6-3、结果输出26、pandas.HDFStore.select函数26-1、语法26-2、参数26-3、功能26-4、返回值26-5、说明26-......
  • Android |(六)基础控件10 RecycleView 滑动【进阶】
      RecyclerView是官方在5.0之后新添加的控件,推出用来替代传统的ListView和GridView列表控件。一、RecycleView(一)总:添加RecycleView控件(1)activity_main中(2)初始化 (3)setLayoutManager()listRv.setLayoutManager(newLinearLayoutManager(this));RecyclerView提供......
  • Android全局替换字体
    一、概述由于业务需要,各端之间统一字体(Android、IOS、PC、网页)。所以android也需要替换成特定的字体。以后有可能还会增加其他的字体。方案:使用LayoutInflaterCompat.setFactory2来全局替换字体。这样做的好处是可以一次性的替换大部分的字体。剩余的个性......
  • P3022 [USACO11OPEN] Odd degrees G
    P3022[USACO11OPEN]OdddegreesG构造每个连通块独立,考虑其中一个如何构造。因为无向图的度数一定是偶数,而每个点的度数是奇数,所以点数为奇数,否则无解。考虑建dfs树,不关心非树边,只考虑树边的取舍构造。自底向上构造,假如当前\(u\)的儿子\(v\)为偶数,那么就不能取\((u,v)......
  • 纯小白uni-app+Android Studio离线打包
    一、HBulderX(1)cloud:开发者中心 注册登录(2)HBulderX登录开发者中心的账号,创建uni-app项目-》test,此时点击test下文件mainfest.json,会出现如下uni-app的AppID 同时在CLOUD上也会出现此项目,注意,项目名称和AppID要对上 (3)HBulderX本地打包 打包结果如下,期间要下什么插件,就让......
  • 1154java jsp SSM古董拍卖网站系统(源码+文档+PPT+运行视频+讲解视频)
     项目技术:SSM+Maven+Vue等等组成,B/S模式+Maven管理等等。环境需要1.运行环境:最好是javajdk1.8,我们在这个平台上运行的。其他版本理论上也可以。2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;3.tomcat环境:Tomcat7.x,8.x,9.x版本均可4.硬件环境:windows7/8/1......
  • Android:如何绘制View
    点击查看Android如何绘制视图官网一、简介Android框架会在Activity获得焦点时请求Activity绘制其布局。Android框架会处理绘制流程,但该Activity必须提供其布局层次结构的根节点。Android框架会绘制布局的根节点,并测量和绘制布局树。它会通过遍历布局树并渲染......