From 472f506817bb1af2fceb039ba148d15723944562 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 25 Feb 2016 13:47:30 -0600 Subject: Improve progress bar handling for backup / restore / image flash The progress bar will now be updated during image backups, restores and during image flashing (except for sparse images which will require significant changes to libsparse, and except for mtd nand using flash_utils). The progress bar will now be updated mid-file for file systems (tar) so the user will see changes even during large file backup / restore. Add a new progress tracking class to simplify handling of progress bar updates. The class will only update the progress bar 5 times a second to reduce the CPU load from updating the GUI frequently which does affect backup times. Change-Id: Iff382faef3df1f86604af336c1a8ce8993cd12c5 --- twrp-functions.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index eb1f4c2f7..8d85ccf04 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -38,6 +38,7 @@ #include #include "twrp-functions.hpp" #include "twcommon.h" +#include "gui/gui.hpp" #ifndef BUILD_TWRPTAR_MAIN #include "data.hpp" #include "partitions.hpp" @@ -45,7 +46,6 @@ #include "bootloader.h" #include "cutils/properties.h" #include "cutils/android_reboot.h" -#include "gui/gui.hpp" #include #endif // ndef BUILD_TWRPTAR_MAIN #ifndef TW_EXCLUDE_ENCRYPTED_BACKUPS @@ -272,7 +272,7 @@ int TWFunc::Try_Decrypting_File(string fn, string password) { #endif } -unsigned long TWFunc::Get_File_Size(string Path) { +unsigned long TWFunc::Get_File_Size(const string& Path) { struct stat st; if (stat(Path.c_str(), &st) != 0) @@ -329,6 +329,25 @@ vector TWFunc::split_string(const string &in, char del, bool skip_empty) return res; } +timespec TWFunc::timespec_diff(timespec& start, timespec& end) +{ + timespec temp; + if ((end.tv_nsec-start.tv_nsec)<0) { + temp.tv_sec = end.tv_sec-start.tv_sec-1; + temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; + } else { + temp.tv_sec = end.tv_sec-start.tv_sec; + temp.tv_nsec = end.tv_nsec-start.tv_nsec; + } + return temp; +} + +int32_t TWFunc::timespec_diff_ms(timespec& start, timespec& end) +{ + return ((end.tv_sec * 1000) + end.tv_nsec/1000000) - + ((start.tv_sec * 1000) + start.tv_nsec/1000000); +} + #ifndef BUILD_TWRPTAR_MAIN // Returns "/path" from a full /path/to/file.name @@ -703,25 +722,6 @@ int TWFunc::write_file(string fn, string& line) { return -1; } -timespec TWFunc::timespec_diff(timespec& start, timespec& end) -{ - timespec temp; - if ((end.tv_nsec-start.tv_nsec)<0) { - temp.tv_sec = end.tv_sec-start.tv_sec-1; - temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; - } else { - temp.tv_sec = end.tv_sec-start.tv_sec; - temp.tv_nsec = end.tv_nsec-start.tv_nsec; - } - return temp; -} - -int32_t TWFunc::timespec_diff_ms(timespec& start, timespec& end) -{ - return ((end.tv_sec * 1000) + end.tv_nsec/1000000) - - ((start.tv_sec * 1000) + start.tv_nsec/1000000); -} - bool TWFunc::Install_SuperSU(void) { if (!PartitionManager.Mount_By_Path("/system", true)) return false; -- cgit v1.2.3