android 9.0 添加自定义恢复出厂设置标识

说明

    android 恢复出厂设置的处理逻辑是RecoverySystem.java中的rebootWipeUserData,源码在recovery.cpp中的main中,前面有想过在recovery的wipe_data方法执行完后设置persist系统属性,但是恢复出厂设置重启后会被置为空,所以只能在/ system/core/bootstat/bootstat.cpp重启原因*(sys.boot.reason)的位置加,

diff --git a/packages/services/Car/service/src/com/android/car/tbox/cartboxservice/tbox/CarTBoxServiceBinder.java b/packages/servic
index d973cfc..9b126c4 100755
--- a/packages/services/Car/service/src/com/android/car/tbox/cartboxservice/tbox/CarTBoxServiceBinder.java
+++ b/packages/services/Car/service/src/com/android/car/tbox/cartboxservice/tbox/CarTBoxServiceBinder.java
@@ -672,9 +672,15 @@ public class CarTBoxServiceBinder extends ITboxInterface.Stub {

                                case CarCabinManager.ID_IP_LANGUAGE_SWITCH_SET:
                                        try {
-                                               int launguage_switch = (int) carPropertyValue.getValue();
-                                               Log.d(TAG, "launguage_switch = " + launguage_switch);
-                                               if (1 == launguage_switch) {
+                                               int language_switch = (int) carPropertyValue.getValue();
+                                               String flag = SystemProperties.get("persist.sys.reboot_wipe_data", "0");
+                                               if (flag.equals("1")) {
+                                                       language_switch = 0;
+                                                       SystemProperties.set("persist.sys.reboot_wipe_data", "0");
+                                                       Log.d(TAG, "reboot_wipe_data");
+                                               }
+                                               Log.d(TAG, "language_switch = " + language_switch);
+                                               if (1 == language_switch) {
                                                        LocalePicker.updateLocale(Locale.ENGLISH);
                                                } else {
                                                        LocalePicker.updateLocale(Locale.CHINESE);
diff --git a/system/core/bootstat/bootstat.cpp b/system/core/bootstat/bootstat.cpp
old mode 100644
new mode 100755
index 7a67894..4e728e3
--- a/system/core/bootstat/bootstat.cpp
+++ b/system/core/bootstat/bootstat.cpp
@@ -527,6 +527,7 @@ void transformReason(std::string& reason) {
 }

 const char system_reboot_reason_property[] = "sys.boot.reason";
+const char system_reboot_wipe_data[] = "persist.sys.reboot_wipe_data";
 const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
 const char bootloader_reboot_reason_property[] = "ro.boot.bootreason";

@@ -831,6 +832,7 @@ std::string CalculateBootCompletePrefix() {
     boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
     LOG(INFO) << "Canonical boot reason: reboot,factory_reset";
     SetProperty(system_reboot_reason_property, "reboot,factory_reset");
+    SetProperty(system_reboot_wipe_data, "1");
   } else if (build_date != record.second) {
     boot_complete_prefix = "ota_" + boot_complete_prefix;
     boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
@@ -956,6 +958,10 @@ void SetSystemBootReason() {
   const std::string system_boot_reason(BootReasonStrToReason(bootloader_boot_reason));
   // Record the scrubbed system_boot_reason to the property
   SetProperty(system_reboot_reason_property, system_boot_reason);
+  if(system_boot_reason.compare("reboot,factory_reset") == 0) {
+       SetProperty(system_reboot_wipe_data, "1");
+       LOG(DEBUG) << "zjy factory reset";
+  }
 }

 // Gets the boot time offset. This is useful when Android is running in a
(END)

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值