From 550a199e676f879fcaa1ca65e65b72fdc7ff3f21 Mon Sep 17 00:00:00 2001 From: Captain Throwback Date: Wed, 19 Jan 2022 13:25:54 -0500 Subject: [PATCH] Add TW_QCOM_ATS_OFFSET flag to manually set time/date offset Needed if no ats_ files are present on qcom device Offset is the difference between the current time and the time since_epoch To calculate the offset in Android, the following expression (from a root shell) can be used: echo "$(( ($(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)) ))" Add 3 zeros to the output and use that in the TW_QCOM_ATS_OFFSET flag in your BoardConfig.mk For example, if the result of the calculation is 1642433544, use 1642433544000 as the offset Change-Id: I5d58125dffc3fdbfb76a5ffde4e27659376185f1 --- Android.mk | 3 +++ twrp-functions.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/Android.mk b/Android.mk index 167ad4ff..67e7d4cc 100755 --- a/Android.mk +++ b/Android.mk @@ -383,6 +383,9 @@ ifneq ($(TW_DEFAULT_LANGUAGE),) else LOCAL_CFLAGS += -DTW_DEFAULT_LANGUAGE=en endif +ifneq ($(TW_QCOM_ATS_OFFSET),) + LOCAL_CFLAGS += -DTW_QCOM_ATS_OFFSET=$(TW_QCOM_ATS_OFFSET) +endif ifneq ($(TW_CLOCK_OFFSET),) LOCAL_CFLAGS += -DTW_CLOCK_OFFSET=$(TW_CLOCK_OFFSET) endif diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 15d4bdd4..f30206bd 100755 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -1052,6 +1052,16 @@ void TWFunc::Fixup_Time_On_Boot(const string& time_paths /* = "" */) } if (!fixed) { +#ifdef TW_QCOM_ATS_OFFSET + // Offset is the difference between the current time and the time since_epoch + // To calculate the offset in Android, the following expression (from a root shell) can be used: + // echo "$(( ($(date +%s) - $(cat /sys/class/rtc/rtc0/since_epoch)) ))" + // Add 3 zeros to the output and use that in the TW_QCOM_ATS_OFFSET flag in your BoardConfig.mk + // For example, if the result of the calculation is 1642433544, use 1642433544000 as the offset + offset = (uint64_t) TW_QCOM_ATS_OFFSET; + DataManager::SetValue("tw_qcom_ats_offset", (unsigned long long) offset, 1); + LOGINFO("TWFunc::Fixup_Time: Setting time offset from TW_QCOM_ATS_OFFSET, offset %llu\n", (unsigned long long) offset); +#else // Failed to get offset from ats file, check twrp settings unsigned long long value; if (DataManager::GetValue("tw_qcom_ats_offset", value) < 0) { @@ -1061,6 +1071,7 @@ void TWFunc::Fixup_Time_On_Boot(const string& time_paths /* = "" */) LOGINFO("TWFunc::Fixup_Time: Setting time offset from twrp setting file, offset %llu\n", (unsigned long long) offset); // Do not consider the settings file as a definitive answer, keep fixed=false so next run will try ats files again } +#endif } gettimeofday(&tv, NULL);