switch ServerConfigurableFlagsMarkBoot to flag_health_check.rc
am: b702ba60dd

Change-Id: Id86885d486a2e8d36ad6ea1c469947cafe2b4727
diff --git a/disaster_recovery/Android.bp b/disaster_recovery/Android.bp
index e6cc22e..8522fa7 100644
--- a/disaster_recovery/Android.bp
+++ b/disaster_recovery/Android.bp
@@ -11,4 +11,5 @@
     cflags: [
         "-Werror",
     ],
+    init_rc: ["flags_health_check.rc"],
 }
\ No newline at end of file
diff --git a/disaster_recovery/flags_health_check.rc b/disaster_recovery/flags_health_check.rc
new file mode 100644
index 0000000..13f9dfd
--- /dev/null
+++ b/disaster_recovery/flags_health_check.rc
@@ -0,0 +1,7 @@
+on load_persist_props_action
+    # check server configurable flags(which is based on persistent properties) related
+    # disaster recovery
+    exec - system system -- /system/bin/flags_health_check
+
+on property:sys.boot_completed=1
+    setprop persist.device_config.attempted_boot_count 0
\ No newline at end of file
diff --git a/libflags/include/server_configurable_flags/disaster_recovery.h b/libflags/include/server_configurable_flags/disaster_recovery.h
index 823010d..4c009b3 100644
--- a/libflags/include/server_configurable_flags/disaster_recovery.h
+++ b/libflags/include/server_configurable_flags/disaster_recovery.h
@@ -18,9 +18,6 @@
 
 namespace server_configurable_flags {
 
-// Mark the boot as success from Server Configurable Flags' perspective.
-void ServerConfigurableFlagsMarkBoot();
-
 // Check failed reboot count, if it exceeds the threshold, server configurable
 // flags will be reset.
 void ServerConfigurableFlagsReset();
diff --git a/libflags/server_configurable_flags.cc b/libflags/server_configurable_flags.cc
index aabfe56..31eaae2 100644
--- a/libflags/server_configurable_flags.cc
+++ b/libflags/server_configurable_flags.cc
@@ -51,15 +51,13 @@
   }
 }
 
-void ServerConfigurableFlagsMarkBoot() {
-  LOG(INFO) << __FUNCTION__ << " mark boot as success from server configurable flag perspective.";
-  android::base::SetProperty(ATTEMPTED_BOOT_COUNT_PROPERTY, "");
-}
-
 void ServerConfigurableFlagsReset() {
   int fail_count = android::base::GetIntProperty(ATTEMPTED_BOOT_COUNT_PROPERTY, 0);
   if (fail_count < ATTEMPTED_BOOT_COUNT_THRESHOLD) {
     LOG(INFO) << __FUNCTION__ << " attempted boot count is under threshold, skipping reset.";
+
+    // ATTEMPTED_BOOT_COUNT_PROPERTY will be reset to 0 when sys.boot_completed is set to 1.
+    // The code lives in flags_health_check.rc.
     android::base::SetProperty(ATTEMPTED_BOOT_COUNT_PROPERTY, std::to_string(fail_count + 1));
   } else {
     LOG(INFO) << __FUNCTION__ << " attempted boot count reaches threshold, resetting flags.";
diff --git a/libflags/server_configurable_flags_test.cc b/libflags/server_configurable_flags_test.cc
index 601a16d..8556885 100644
--- a/libflags/server_configurable_flags_test.cc
+++ b/libflags/server_configurable_flags_test.cc
@@ -54,14 +54,6 @@
   ASSERT_EQ("default", result);
 }
 
-TEST(server_configurable_flags, mark_boot_clears_fail_count_property) {
-  android::base::SetProperty("persist.device_config.attempted_boot_count", "1");
-  server_configurable_flags::ServerConfigurableFlagsMarkBoot();
-
-  std::string actual = android::base::GetProperty("persist.device_config.attempted_boot_count", "");
-  ASSERT_EQ("", actual);
-}
-
 TEST(server_configurable_flags, flags_reset_skip_under_threshold) {
   android::base::SetProperty("persist.device_config.attempted_boot_count", "1");
   android::base::SetProperty("persist.device_config.category1.prop1", "val1");