Dark boot on dark theme.

Bug: 113028175
Test: Toggle dark mode from Settings. Check the value in /misc (`dd bs=1
      skip=2048 if=/dev/block/sda2 count=32 | xxd`).
Change-Id: I22b81aca9623345c26f9a63c3ca12a52b600ff96
diff --git a/init.hardware.rc b/init.hardware.rc
index 6ece1e1..2684a7a 100644
--- a/init.hardware.rc
+++ b/init.hardware.rc
@@ -993,9 +993,24 @@
 
 # Write the dark theme magic (`theme-dark`, or 0x7468656d652d6461726b in hex string) to /misc
 # partition. Offset 0 in vendor space is effectively offset 2048 in /misc partition.
-service vendor.darkboot /vendor/bin/misc_writer --vendor-space-offset 0 --hex-string 0x7468656d652d6461726b
+service vendor.theme_set /vendor/bin/misc_writer --vendor-space-offset 0 --hex-string 0x7468656d652d6461726b
     disabled
     oneshot
 
-on property:persist.sys.device_provisioned=1
-    start vendor.darkboot
+# Clear the 10-byte dark theme magic in /misc partition. Offset 0 in vendor space is effectively
+# offset 2048 in /misc partition.
+service vendor.theme_clear /vendor/bin/misc_writer --vendor-space-offset 0 --hex-string 0x00000000000000000000
+    disabled
+    oneshot
+
+# Set dark boot flag on dark mode (UiModeManager.MODE_NIGHT_YES == 2).
+on property:persist.sys.theme=2
+    start vendor.theme_set
+
+# Clear the dark boot flag on light mode (UiModeManager.MODE_NIGHT_NO == 1) or auto mode
+# (UiModeManager.MODE_NIGHT_AUTO == 0).
+on property:persist.sys.theme=1
+    start vendor.theme_clear
+
+on property:persist.sys.theme=0
+    start vendor.theme_clear