Skip to content

Instantly share code, notes, and snippets.

@Tasssadar
Created February 3, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tasssadar/8792777 to your computer and use it in GitHub Desktop.
Save Tasssadar/8792777 to your computer and use it in GitHub Desktop.
diff --git a/twrp.cpp b/twrp.cpp
index 54f3ea6..0777784 100644
--- a/twrp.cpp
+++ b/twrp.cpp
@@ -60,6 +60,56 @@ static void Print_Prop(const char *key, const char *name, void *cookie) {
printf("%s=%s\n", key, name);
}
+ #include <sys/time.h>
+#include <dirent.h>
+static void fixup_qcom_rtc_shenanigans(void) {
+ static const std::string path = "/data/system/time";
+ DIR *d = opendir(path.c_str());
+ if(!d)
+ return;
+
+ struct dirent *dt;
+ uint64_t offset = 0;
+ while((dt = readdir(d)))
+ {
+ if(dt->d_type != DT_REG)
+ continue;
+
+ if(strncmp(dt->d_name, "ats_", 4) == 0)
+ {
+ FILE *f = fopen((path + "/" + dt->d_name).c_str(), "r");
+ if(f)
+ {
+ printf("Reading offset from file %s\n", dt->d_name);
+ fread(&offset, sizeof(offset), 1, f);
+ fclose(f);
+ break;
+ }
+ }
+ }
+
+ closedir(d);
+
+ if(offset == 0)
+ return;
+
+ printf("got time offset %lld\n", offset);
+
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+
+ tv.tv_sec += offset/1000;
+ tv.tv_usec += (offset%1000)*1000;
+
+ while(tv.tv_usec >= 1000000)
+ {
+ ++tv.tv_sec;
+ tv.tv_usec -= 1000000;
+ }
+ printf("setting time to %llu s and %llu us\n", tv.tv_sec, tv.tv_usec);
+ settimeofday(&tv, NULL);
+}
+
int main(int argc, char **argv) {
// Recovery needs to install world-readable files, so clear umask
// set by init
@@ -245,6 +295,8 @@ int main(int argc, char **argv) {
// Read the settings file
DataManager::ReadSettingsFile();
+ fixup_qcom_rtc_shenanigans();
+
gui_rotate(DataManager::GetIntValue(TW_ROTATION));
// Run any outstanding OpenRecoveryScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment