From 9af37fef61c0bb42b8d1bd39452ba904f021f566 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Thu, 27 Jun 2019 11:31:59 -0700 Subject: Dark boot on dark theme. Bug: 113028175 Bug: 136156133 Test: Build and flash sailfish. Check serial log regarding the start of vendor.darkboot and vendor.darkboot_clear services when toggling dark theme in Settings. Also read the value via `dd bs=1 skip=12862 if=/dev/block/sdd1 count=32 | xxd` to confirm the change. Test: Trigger a factory reset via Settings. Check the value in /misc after the reset. Change-Id: Ib34fc88a7dd056bc3d43ee7368e16d8c8270be99 --- device-common.mk | 3 +++ init.common.rc | 24 +++++++++++++++++ marlin/BoardConfig.mk | 3 ++- recovery/nanohub/Android.mk | 6 +++-- recovery/nanohub/nanohub_recovery_ui.cpp | 46 +++++++++++++++++++++----------- sailfish/BoardConfig.mk | 3 ++- 6 files changed, 66 insertions(+), 19 deletions(-) diff --git a/device-common.mk b/device-common.mk index 61c01af8..72fc8f2c 100644 --- a/device-common.mk +++ b/device-common.mk @@ -658,3 +658,6 @@ PRODUCT_PACKAGES += \ # a_sns_test for sensor testing PRODUCT_PACKAGES_DEBUG += a_sns_test +# Write flags to the vendor space in /misc partition. +PRODUCT_PACKAGES += \ + misc_writer diff --git a/init.common.rc b/init.common.rc index ec470912..46f697b8 100644 --- a/init.common.rc +++ b/init.common.rc @@ -886,3 +886,27 @@ on property:sys.vdso=64 on property:sys.vdso=32 write /sys/module/vdso/parameters/enable_64 0 + +# Write the dark theme magic (`theme-dark`, or 0x7468656d652d6461726b in hex string) to /misc +# partition. Offset 10814 in vendor space is effectively offset 12862 in /misc partition. +service vendor.darkboot /vendor/bin/misc_writer --vendor-space-offset 10814 --hex-string 0x7468656d652d6461726b + disabled + oneshot + +# Clear the 10-byte dark theme magic in /misc partition. Offset 10814 in vendor space is effectively +# offset 12862 in /misc partition. +service vendor.darkboot_clear /vendor/bin/misc_writer --vendor-space-offset 10814 --hex-string 0x00000000000000000000 + disabled + oneshot + +# Set the dark boot flag on dark mode (UiModeManager.MODE_NIGHT_YES == 2). +on property:persist.sys.theme=2 + start vendor.darkboot + +# Clear the dark theme 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.darkboot_clear + +on property:persist.sys.theme=0 + start vendor.darkboot_clear diff --git a/marlin/BoardConfig.mk b/marlin/BoardConfig.mk index 776b8513..eb1e364f 100644 --- a/marlin/BoardConfig.mk +++ b/marlin/BoardConfig.mk @@ -168,7 +168,8 @@ PROTOBUF_SUPPORTED := false #Add NON-HLOS files for ota upgrade ADD_RADIO_FILES := true -TARGET_RECOVERY_UI_LIB := librecovery_ui_nanohub + +TARGET_RECOVERY_UI_LIB := librecovery_ui_nanohub libbootloader_message libfstab #Add support for firmare upgrade on 8996 HAVE_SYNAPTICS_DSX_FW_UPGRADE := true diff --git a/recovery/nanohub/Android.mk b/recovery/nanohub/Android.mk index 70ccb376..29bf1717 100644 --- a/recovery/nanohub/Android.mk +++ b/recovery/nanohub/Android.mk @@ -14,7 +14,7 @@ # limitations under the License. # -ifeq ($(TARGET_RECOVERY_UI_LIB),librecovery_ui_nanohub) +ifneq (,$(filter librecovery_ui_nanohub,$(TARGET_RECOVERY_UI_LIB))) LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) @@ -24,7 +24,9 @@ LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := nanohub_recovery_ui.cpp -LOCAL_SHARED_LIBRARIES := librecovery_ui +LOCAL_SHARED_LIBRARIES := libbase librecovery_ui + +LOCAL_STATIC_LIBRARIES := libbootloader_message include $(BUILD_STATIC_LIBRARY) endif diff --git a/recovery/nanohub/nanohub_recovery_ui.cpp b/recovery/nanohub/nanohub_recovery_ui.cpp index 9298c059..6f175305 100644 --- a/recovery/nanohub/nanohub_recovery_ui.cpp +++ b/recovery/nanohub/nanohub_recovery_ui.cpp @@ -20,38 +20,54 @@ #include #include -#include "recovery_ui/device.h" -#include "recovery_ui/screen_ui.h" +#include -class Nanohub_Device : public Device -{ -public: +#include +#include +#include +#include + +// Wipes the dark theme flag as part of data wipe. +static bool WipeDarkThemeFlag() { + // Must be consistent with the one in init.hardware.rc (10-byte `theme-dark`). The magic is at + // 10814 in vendor space, or (2048 + 10814) since the start of /misc. + const std::string wipe_str(10, '\x00'); + constexpr size_t kDarkThemeFlagOffsetInVendorSpace = 10814; + if (std::string err; !WriteMiscPartitionVendorSpace( + wipe_str.data(), wipe_str.size(), kDarkThemeFlagOffsetInVendorSpace, &err)) { + LOG(ERROR) << "Failed to write wipe string: " << err; + return false; + } + LOG(INFO) << "Dark theme flag wiped successfully"; + return true; +} + +class Nanohub_Device : public Device { + public: Nanohub_Device(ScreenRecoveryUI* ui) : Device(ui) {} bool PostWipeData(); }; -bool Nanohub_Device::PostWipeData() -{ - int fd; - - fd = open("/sys/class/nanohub/nanohub/erase_shared", O_WRONLY); +bool Nanohub_Device::PostWipeData() { + int fd = open("/sys/class/nanohub/nanohub/erase_shared", O_WRONLY); if (fd < 0) { - printf("error: open erase_shared failed: %s\n", strerror(errno)); + PLOG(ERROR) << "open erase_shared failed"; } else { if (write(fd, "1\n", 2) != 2) { - printf("error: write to erase_shared failed: %s\n", strerror(errno)); + PLOG(ERROR) << "write to erase_shared failed"; } else { - printf("Successfully erased nanoapps.\n"); + LOG(INFO) << "Successfully erased nanoapps"; } close(fd); } + WipeDarkThemeFlag(); + // open/write failure caused by permissions issues would persist across // reboots, so always return true to prevent a factory reset failure loop. return true; } -Device *make_device() -{ +Device* make_device() { return new Nanohub_Device(new ScreenRecoveryUI); } diff --git a/sailfish/BoardConfig.mk b/sailfish/BoardConfig.mk index 3c90f23f..ed8ea87d 100644 --- a/sailfish/BoardConfig.mk +++ b/sailfish/BoardConfig.mk @@ -167,7 +167,8 @@ PROTOBUF_SUPPORTED := false #Add NON-HLOS files for ota upgrade ADD_RADIO_FILES := true -TARGET_RECOVERY_UI_LIB := librecovery_ui_nanohub + +TARGET_RECOVERY_UI_LIB := librecovery_ui_nanohub libbootloader_message libfstab #Add support for firmare upgrade on 8996 HAVE_SYNAPTICS_DSX_FW_UPGRADE := true -- cgit v1.2.3