Files
android_vendor_pawlet/recovery_toolkit/helpers/progresstracking.cpp
T
oxmc f6176009b1 Add recovery_ui and recovery_toolkit scaffolding (first draft, not build-tested)
Stages TWRP's GUI engine and standalone tooling as PawletOS-owned modules
instead of a bootable/recovery fork, per the plugin-architecture finding in
NOTES-ota-recovery-ab.md: stock recovery_main.cpp already dlopen()s
librecovery_ui_ext.so and dlsym()s make_device() from it at runtime, so the
UI layer doesn't require touching stock bootable/recovery at all. Confirmed
via source grep that recovery.cpp/install.cpp have zero references into the
partition manager/backup engine/GUI code and vice versa.

recovery_ui/: TWRP's gui/, minuitwrp/, libpixelflinger/ (copied verbatim,
GPL-3.0), plus a new device/ providing PawletTwrpUI (a ScreenRecoveryUI
subclass) and make_device() — written from scratch against stock's
RecoveryUI/ScreenRecoveryUI virtual-method contract, since TWRP's own fork
never ships a make_device() (every real TWRP device provides its own, and
no reference device tree was available to copy from). Top-level Android.bp
defines librecovery_ui_pawlet_twrp, the module TARGET_RECOVERY_UI_LIB should
point at. gui/Android.bp and minuitwrp/Android.bp had their include_dirs
rewritten for the new paths.

recovery_toolkit/: partition manager, backup engine (tar/digest/adbbu/apex),
filesystem/format support (exfat/dosfstools/gpt/fuse/mtp/crypto), scripting
(openrecoveryscript/orscmd/twrpinstall), shared helpers. Source only, no
Android.bp yet for any of it.

Known gap blocking recovery_ui from actually linking: gui/'s libguitwrp
depends on libaosprecovery, built from recovery_toolkit/helpers/twrp.cpp via
a Go Soong plugin (libaosprecovery_defaults.go) not yet ported. Neither repo
has been build-tested — no local AOSP build environment available in this
workspace. See each directory's README.md for a precise done/not-done
breakdown.
2026-07-11 16:34:35 -07:00

109 lines
3.7 KiB
C++

/*
Copyright 2016 bigbiff/Dees_Troy TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
// Progress tracking class for tracking backup progess and updating the progress bar as appropriate
#include "progresstracking.hpp"
#include "twcommon.h"
#ifndef BUILD_TWRPTAR_MAIN
#include "gui/gui.hpp"
#include "data.hpp"
#endif
#include "twrp-functions.hpp"
#include <time.h>
const int32_t update_interval_ms = 200; // Update interval in ms
ProgressTracking::ProgressTracking(const unsigned long long backup_size) {
total_backup_size = backup_size;
partition_size = 0;
file_count = 0;
current_size = 0;
current_count = 0;
previous_partitions_size = 0;
display_file_count = false;
clock_gettime(CLOCK_MONOTONIC, &last_update);
}
void ProgressTracking::SetPartitionSize(const unsigned long long part_size) {
previous_partitions_size += partition_size;
partition_size = part_size;
UpdateDisplayDetails(true);
}
void ProgressTracking::SetSizeCount(const unsigned long long part_size, unsigned long long f_count) {
previous_partitions_size += partition_size;
partition_size = part_size;
file_count = f_count;
display_file_count = (file_count != 0);
UpdateDisplayDetails(true);
}
void ProgressTracking::UpdateSize(const unsigned long long size) {
current_size = size;
UpdateDisplayDetails(false);
}
void ProgressTracking::UpdateSizeCount(const unsigned long long size, const unsigned long long count) {
current_size = size;
current_count = count;
UpdateDisplayDetails(false);
}
void ProgressTracking::DisplayFileCount(const bool display) {
display_file_count = display;
UpdateDisplayDetails(true);
}
void ProgressTracking::UpdateDisplayDetails(const bool force) {
#ifndef BUILD_TWRPTAR_MAIN
if (!force) {
// Do something to check the time frame and only update periodically to reduce the total number of GUI updates
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
int32_t diff = TWFunc::timespec_diff_ms(last_update, now);
if (diff < update_interval_ms)
return;
}
clock_gettime(CLOCK_MONOTONIC, &last_update);
double display_percent = 0.0, progress_percent;
string size_prog = gui_lookup("size_progress", "%lluMB of %lluMB, %i%%");
char size_progress[1024];
if (total_backup_size != 0) // prevent division by 0
display_percent = (double)(current_size + previous_partitions_size) / (double)(total_backup_size) * 100;
sprintf(size_progress, size_prog.c_str(), (current_size + previous_partitions_size) / 1048576, total_backup_size / 1048576, (int)(display_percent));
DataManager::SetValue("tw_size_progress", size_progress);
progress_percent = (display_percent / 100);
DataManager::SetProgress((float)(progress_percent));
if (!display_file_count || file_count == 0) {
DataManager::SetValue("tw_file_progress", "");
} else {
string file_prog = gui_lookup("file_progress", "%llu of %llu files, %i%%");
char file_progress[1024];
display_percent = (double)(current_count) / (double)(file_count) * 100;
sprintf(file_progress, file_prog.c_str(), current_count, file_count, (int)(display_percent));
DataManager::SetValue("tw_file_progress", file_progress);
}
#endif
}