Files
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

113 lines
5.2 KiB
C++

/*
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/>.
*/
#ifndef __TWADBSTREAM_H
#define __TWADBSTREAM_H
#define TWRPARG "--twrp"
#define TWRP_BACKUP_ARG "backup"
#define TWRP_RESTORE_ARG "restore"
#define TWRP_STREAM_ARG "stream"
#define TW_ADB_BACKUP "/tmp/twadbbackup" //FIFO for adb backup
#define TW_ADB_RESTORE "/tmp/twadbrestore" //FIFO for adb restore
#define TW_ADB_BU_CONTROL "/tmp/twadbbucontrol" //FIFO for sending control from TWRP to ADB Backup
#define TW_ADB_TWRP_CONTROL "/tmp/twadbtwrpcontrol" //FIFO for sending control from ADB Backup to TWRP
#define TWRP "TWRP" //Magic Value
#define ADB_BU_MAX_ERROR 20 //Max amount of errors for while loops
#define ADB_BACKUP_OP "adbbackup"
#define ADB_RESTORE_OP "adbrestore"
//ADB Backup Control Commands
#define TWSTREAMHDR "twstreamheader" //TWRP Parititon Count Control
#define TWFN "twfilename" //TWRP Filename Control
#define TWIMG "twimage" //TWRP Image name Control
#define TWEOF "tweof" //End of File for Image/File
#define MD5TRAILER "md5trailer" //Image/File MD5 Trailer
#define TWDATA "twdatablock" // twrp adb backup data block header
#define TWMD5 "twverifymd5" //This command is compared to the md5trailer by ORS to verify transfer
#define TWENDADB "twendadb" //End Protocol
#define TWERROR "twerror" //Send error
#define ADB_BACKUP_VERSION 3 //Backup Version
#define DATA_MAX_CHUNK_SIZE 1048576 //Maximum size between each data header
#define MAX_ADB_READ 512 //align with default tar size for amount to read fom adb stream
/*
structs for adb backup need to align to 512 bytes for reading 512
bytes at a time
Each struct contains a crc field so that when we are checking for commands
and the crc doesn't match we still assume it's data matching the command
struct but not really a command
*/
/* stream format:
| TW ADB Backup Header |
| TW File Stream Header |
| File Data |
| File/Image MD5 Trailer |
| TW File Stream Header |
| File Data |
| File/Image MD5 Trailer |
| etc... |
*/
//determine whether struct is 512 bytes, if not fail compilation
#define ADBSTRUCT_STATIC_ASSERT(structure) typedef char adb_assertion[( !!(structure) )*2-1 ]
//generic cmd structure to align fields for sending commands to and from adb backup
struct AdbBackupControlType {
char start_of_header[8]; //stores the magic value #define TWRP
char type[16]; //stores the type of command, TWENDADB, TWCNT, TWEOF, TWMD5, TWDATA and TWERROR
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupControlType struct to allow for making sure we are processing metadata
char space[484]; //stores space to align the struct to 512 bytes
//return a C++ string while not reading outside the type char array
std::string get_type() {
return std::string(type, strnlen(type, sizeof(type)-1));
}
};
//general info for file metadata stored in adb backup header
struct twfilehdr {
char start_of_header[8]; //stores the magic value #define TWRP
char type[16]; //stores the type of file header, TWFN or TWIMG
uint64_t size; //stores the size of the file contained after this header in the backup file
uint64_t compressed; //stores whether the file is compressed or not. 1 == compressed and 0 == uncompressed
uint32_t crc; //stores the zlib 32 bit crc of the twfilehdr struct to allow for making sure we are processing metadata
char name[468]; //stores the filename of the file
};
//md5 for files stored as a trailer to files in the adb backup file to check
//that they are restored correctly
struct AdbBackupFileTrailer {
char start_of_trailer[8]; //stores the magic value #define TWRP
char type[16]; //stores the AdbBackupFileTrailer type MD5TRAILER
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupFileTrailer struct to allow for making sure we are processing metadata
uint32_t ident; //stores crc to determine if header is encapsulated in stream as data
char md5[40]; //stores the md5 computation of the file
char space[440]; //stores space to align the struct to 512 bytes
};
//info for version and number of partitions backed up
struct AdbBackupStreamHeader {
char start_of_header[8]; //stores the magic value #define TWRP
char type[16]; //stores the AdbBackupStreamHeader value TWCNT
uint64_t partition_count; //stores the number of partitions to restore in the stream
uint64_t version; //stores the version of adb backup. increment ADB_BACKUP_VERSION each time the metadata is updated
uint32_t crc; //stores the zlib 32 bit crc of the AdbBackupStreamHeader struct to allow for making sure we are processing metadata
char space[468]; //stores space to align the struct to 512 bytes
};
#endif //__TWADBSTREAM_H