From ce8f83c48d200106ff61ad530c863b15c16949d9 Mon Sep 17 00:00:00 2001 From: bigbiff Date: Sat, 12 Dec 2015 18:30:21 -0500 Subject: ADB: Add adb backup for TWRP. Functionality for client side to backup tar and image streams over adbd to the client under backup.ab. Using adb backup on the client side you can backup the partitions TWRP knows about. On the client side you can do the following: adb backup -f --twrp where options are --compress: compress data system: backup system cache: backup cache data: backup data boot: backup boot etc for each partition. You can string multiple options, i.e. adb backup -f --twrp --compress cache system data adb backup in TWRP will take any option corresponding to TWRP fstab partitions, e.g. efs boot as well. If you do not specify the filename with the -f option, adb will backup your data to a filename backup.ab on the client. You can then rename the file and encrypt it with desktop tools. If you don't want to use command line arguments: adb backup --twrp will bring up the gui and allow you to choose partitions from the backup page. To restore the backup use the following convention: adb restore Structures are used to store metadata in binary inside of the file itself. If the metadata structure is modified, update the adb version so that it will invalidate older backups and not cause issues on restore. When restoring, we currently do not support picking specific partitions. It's all or nothing. Change-Id: Idb92c37fc9801dc8d89ed2a4570e9d12e76facf8 --- twrp-functions.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'twrp-functions.cpp') diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 1c633e7e4..8cc094fc2 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -151,7 +151,7 @@ bool TWFunc::Path_Exists(string Path) { return true; } -int TWFunc::Get_File_Type(string fn) { +Archive_Type TWFunc::Get_File_Type(string fn) { string::size_type i = 0; int firstbyte = 0, secondbyte = 0; char header[3]; @@ -164,13 +164,10 @@ int TWFunc::Get_File_Type(string fn) { secondbyte = header[++i] & 0xff; if (firstbyte == 0x1f && secondbyte == 0x8b) - return 1; // Compressed + return COMPRESSED; else if (firstbyte == 0x4f && secondbyte == 0x41) - return 2; // Encrypted - else - return 0; // Unknown - - return 0; + return ENCRYPTED; + return UNCOMPRESSED; // default } int TWFunc::Try_Decrypting_File(string fn, string password) { @@ -752,7 +749,7 @@ bool TWFunc::Try_Decrypting_Backup(string Restore_Path, string Password) { while ((de = readdir(d)) != NULL) { Filename = Restore_Path; Filename += de->d_name; - if (TWFunc::Get_File_Type(Filename) == 2) { + if (TWFunc::Get_File_Type(Filename) == ENCRYPTED) { if (TWFunc::Try_Decrypting_File(Filename, Password) < 2) { DataManager::SetValue("tw_restore_password", ""); // Clear the bad password DataManager::SetValue("tw_restore_display", ""); // Also clear the display mask -- cgit v1.2.3