Commit Graph

202 Commits

Author SHA1 Message Date
Ethan Yonker
007de98f69 Fix header file for property_get
Change-Id: Id8a8c0e2b5a0a6d5b656fe8f517ded5df512b1a1
2018-08-31 14:24:41 -05:00
Ethan Yonker
e9afc3de0f Decrypt FBE on 9.0 (backwards compatible)
Building in 9.0 may require you to add a flag to your twrp fstab
with the fileencryption details like:
fileencryption=ice:aes-256-heh

Verify this against your device's stock fstab of course.

Change-Id: If9286f5d5787280814daca9fbc8f5191ff26a839
2018-08-31 10:37:08 -05:00
bigbiff bigbiff
38b83c1da4 ADB Backup: fix md5 check on restore.
Add debug capability.
Fix backup of images after tarred partitions with too much padding
Add more md5 logging.
Skip digest check if selected.
Change ADB Backup version to 3 for new fixes to image padding.
Change-Id: I0f76c0733c523717e4797d1a14c3ae47d046fc8c
2018-05-25 18:42:16 +02:00
nkk71
98fc399c26 Use /persist as Qualcomm time fix source during early boot
* /persist can be mounted early while TWRP is parsing the fstab so
  as soon as the partition is parsed, mount and adjust the time
  accordingly.

* Store a backup settings file on /persist. Having a 2nd copy of
  the settings file in the /persist partition allows for early
  reading of the file and adjust timezone and brightness to user
  preference while still on TWRP splash.

* Add the qcom ats time offset in TWRP settings file and use it
  if no better ats file is found. This will also allow devices
  with a persist partition, but no ats files in it, to adjust
  the time offset during early boot.

* Use /persist/time/ as Qualcomm time fix source, based on
  Xuefer <xuefer@gmail.com> patch:
  https://gerrit.omnirom.org/c/27265/
  https://gerrit.omnirom.org/c/24384/

Change-Id: I6c21538eec58d87edfb639d9ce3871f33b886c1d
2018-01-17 20:42:17 +01:00
Ethan Yonker
fefe5915b0 FBE for Pixel 2
Includes various minor fixes for building in Android 8 trees with r23+ tag

Update FBE extended header in libtar to version 2 and include the entire
ext4_encryption_policy structure now after translating the policy.

See this post for more details:
https://plus.google.com/u/1/+DeesTroy/posts/i33ygUi7tiu

Change-Id: I2af981e51f459b17fcd895fb8c2d3f6c8200e24b
2017-11-28 16:03:41 -06:00
Ethan Yonker
6e8c27a52b Support v2 fstab format
Auto detect and support both the v1 and v2 fstab formats
Support putting TWRP style flags in a separate /etc/twrp.flags file

twrp.flags format is the same as twrp.fstab (v1 with TWRP flags)

Support using a wildcard in a block device and find all partitions:
/usb-otg vfat /dev/block/sda*

Support using sysfs entries (voldmanaged) and read uevents and scan for
wildcard partitions from uevent data. (twvold?)

May not be complete for some of the newer flags found in fstabs in newer
build trees and there is a slim chance of a crash if the user removes a
removable device while TWRP is performing actions. May need to add some
kind of mutex to prevent the 2 threads from causing this crash. We need
to start somewhere though and this change is pretty innocuous when not
using a v2 fstab.

Change-Id: I617d97c7db332cbe671a9d2b8ad98b3d9c4f03cc
2017-11-28 00:20:51 +01:00
bigbiff bigbiff
19fb79c722 ADB Backup: add ability for TWRP GUI to restore
Restore adb backup files that TWRP made to your PC.
Put files in your backup directory to see them.

e.g. /sdcard/TWRP/BACKUPS/<sn>

Change-Id: I2c57970d77b64c39a302159041456e761c185259
2017-11-27 09:32:30 -06:00
Ethan Yonker
8373cfe28c Update to AOSP 8.0 base
Change-Id: I29fe722b4eb9718765327902779046840a01433e
2017-09-08 07:14:59 -05:00
nkk71
9efbe769c3 Fix incorrect 'unlink' return value check
Change-Id: I430f6bb21a5fd87e0422420463e8bb96c4a612e1
2017-06-17 14:21:47 +02:00
bigbiff bigbiff
56cf564658 twrpDigest refactor
This patch is to refactor twrpDigest using polymorphism
and inheritance to use the same call patterns for creating and
reading a digest. Now a library.
Use SHA2 from libcrypto. SHA2 is default if device has libcrypto.

Change string MD5 everywhere to use digest or Digest instead. Updated
string tags to digest. Translation will be required.

Switch out digest code into a driver class from partitionmanager.

SHA2 is better for digest creation due to decreased collision space
compared to MD5 and SHA1.

See https://en.wikipedia.org/wiki/SHA-2

Change-Id: I74b5546789990b12aa4ce2e389d25f80a3fe213f
2017-06-17 07:05:45 -05:00
Ethan Yonker
6355b56c93 Adopted Storage: backup keys but do not wipe them
Change-Id: I545a32848ee686ecfacd13604ae3f18f5d206dfc
2017-05-01 09:42:17 -05:00
bigbiff bigbiff
b5ecaad27a ADB Backup: fix adb restore issues
Set Backup_FileName on adb backup to fix restore.
Set read_from_adb after EOF to return properly
from newer adb client prompt.
Create setter and getter for Backup_FileName
for openrecoveryscript.cpp which is not a
friend class.
Fix condition for twrpTar::Get_Size() and adb backup.
Change-Id: I7eb8168fa3416366b996e220cecbc0e1bcec5e8e
2017-04-23 14:37:22 -04:00
Matt Mower
a8e6d83155 Do not unconditionally remove MTP storage on unmount
* It is not necessary to Remove_MTP_Storage() for a partition if an
  MTP_Storage_ID has not been assigned.
* The hack to force-set tw_mtp_enabled=1 should no longer be necessary
  now that we're checking whether MTP really needs to be disabled for
  a volume before running Disable_MTP().

Change-Id: I1b7233eedd9da7c6be0c67fc60243f3837105173
2017-02-23 19:42:48 +01:00
Ethan Yonker
01f4e035aa Improve backup display names with emulated storage
-Change backup display name to say that we are excluding storage
-Add warning message during backup of any partition with data media
-Also eliminate unused variable from twrpTar class

Maybe this will make the people in issue 276 happy, but probably not because
they already lost their data, or because the warning text is yellow instead of
red.
https://github.com/TeamWin/Team-Win-Recovery-Project/issues/276

Change-Id: I98303fe7f6b7a25fea029637c90145258d41ee46
2017-02-07 21:30:01 -06:00
Matt Mower
06543e35e0 Add missing file descriptor closes
Change-Id: I7154a022833a5e092facd7c5df776719b9fcc929
2017-01-18 13:04:35 -06:00
Matt Mower
874136434a SELinux can be assumed for Android 4.4+
Change-Id: I7410a0c8e439eec90a955ee9201efd9a92bb9635
2017-01-18 12:40:26 -06:00
Matt Mower
a0cd91d317 Restore file system type logline on restore
Change-Id: I2b961a75f500c657ff7a82698957060f85e95ab8
2017-01-18 17:50:55 +01:00
Matt Mower
23d8aaef29 Unused variable cleanup
Change-Id: I2397d0bd221dcf5c9d0f971ba157519bcf014a70
2017-01-18 17:50:05 +01:00
Matt Mower
029a82db6c Very minor code cleanup
Change-Id: Ie0b97da2cce7bb93307ed49b1138bc2f36df34d0
2017-01-18 17:49:23 +01:00
Matt Mower
a8a89d1961 Whitespace cleanup
Change-Id: I93c65973679894bb8587da4b38b410d38036b8bd
2017-01-18 17:41:17 +01:00
nailyk
a083dc68c6 ADBbackups: Fix wrong owner on binary backups.
- Set the correct owner on binary backup files to flash storage.

Solve https://github.com/TeamWin/Team-Win-Recovery-Project/issues/749

Change-Id: I5526494c77232f524cf02a482de070b44248c4a0
2017-01-18 17:02:56 +01:00
Ethan Yonker
79f88bdf8d Support backup/restore of FBE policies
Change-Id: Iba8ef20f57b0fb57bb9406c53148a806441d0b59
2016-12-13 14:25:04 -06:00
Ethan Yonker
bd7492de28 Support File Based Encryption
Change-Id: Ib688ddd0c32d3999590cacd86b6d9b18eac336e9
2016-12-13 21:16:42 +01:00
Ethan Yonker
1b190166eb Add boot slot support
Change-Id: I7eaf80e327985f53791f90fbdebad022a9650d31
2016-12-13 14:04:48 -06:00
Ethan Yonker
3fdcda4662 Improve backup & wipe exclusion handling
Rename twrpDU.* to exclude.*
Remove global variable for du and replace with partition specific
variables.
Use separate exclusion lists for backups and wiping.
Clean up some includes
Fix some parenthesis in twrp.cpp that I messed up.

Note: twrpTarMain command line utility compiles but probably does
not work correctly yet due to not properly setting part_settings

Change-Id: Idec9c3e6a8782ba53f3420fa79ba33394f4f85fb
2016-11-30 13:19:08 -06:00
Ethan Yonker
93ac7a0bb1 Check if mount point is dir during startup
7.0 trees tend to create a /vendor symlink in the root of the
ramdisk. TWRP needs to delete the symlink and mkdir to be able to
mount the partition properly.

Change-Id: Ia338739e07ca16ccd2492ea1fec2f5e99cfc08eb
2016-11-30 16:46:01 +01:00
James Christopher Adduono
79ae093c82 MD5 verification sanity
We can use switches and enums to make things more understandable
and work with results in a more sensible manner.

PS2: Move file MD5 verification and error handling into
     a separate function to reduce code.

PS3: Default to false in Check_Restore_File_MD5 function

Change-Id: Id3ee0bb444cf13be67bb5dec2c43f7c26a86b954
(cherry picked from commit 5c3950716e5c7c6279efd5f3f338d6d22e5215e2)
2016-11-30 16:30:22 +01:00
Ethan Yonker
e080c1f8fb Fix image flashing
PS2: full_filename is not a dir

PS3: use a consistent format of always assuming directory
     is missing the trailing / + fix whitespace alignment

Change-Id: Ib963473ae10571b3d069b326d024ca04c7224dda
(cherry picked from commit fa4ff144374474c541351d153549ad11d4396614)
2016-11-30 16:27:07 +01:00
Ethan Yonker
dcf2b674c4 Clean up PartitionSettings
The PartitionSettings struct contains some data elements that are duplicates
of data elements in the TWPartition class that is contained within the
PartitionsSettings.Part element. We will eliminate this duplication to help
reduce the chances for programming bugs.

Specifically, this fixes problems where the current file system does not
match the backed up file system.

Change-Id: I02f236e72093362050556a2e53a09d1dbb9a269d
2016-09-13 14:53:37 -05:00
bigbiff bigbiff
8fd4b096c4 MD5 checking: fix issues introduced with adb backup patchset
This patchset will fix issues with creating and checking
md5 checksums with single partitions and subpartitions.

Change-Id: Iddfaf46412e95635af958094726cf9e3eb5a4cc8
2016-08-30 20:52:02 -04:00
Kjell Braden
3126a113e7 wait for cryptfs device node to come up
this is to prevent a race condition to occur when mounting an adopted
storage volume just after it was decrypted. After setting up the
decrypted volume using cryptfs_setup_ext_volume(), Decrypt_Adopted()
immediately calls Mount(), which will call Check_FS_Type(), which will
fail in blkid_new_probe_from_filename, as the device node was not
created yet.

Change-Id: Ic5a274c2066ab278c9b7f1c8b83b820e552ca344
2016-08-22 16:51:30 +02:00
bigbiff
ce8f83c48d 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 <filename> --twrp <options> 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 <filename> --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 <filename>

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
2016-07-31 22:20:18 -05:00
Matt Mower
72c87ce347 Wait to mount until after fstab processed
The necessity to process fstab twice stems from mounting partitions
while still processing. Instead, wait to finish setup of /data, /cache
and storage parameters until after fstab has been processed (once).

Change-Id: Id77e1edbab5eb68a7cd4a1f34953d819a043d47a
2016-05-03 14:39:12 -05:00
Matt Mower
2b2dd15cbd Remove char/string conversions in fstab processing
There a few char->string conversions between functions which handle
different parts of fstab line processing, but there are no uses of
string functions. Pass char arrays/pointers around instead.

Change-Id: I976a9a54ee8dcfb6194cadcac6a34e467602003b
2016-05-03 18:48:38 +01:00
Matt Mower
4ab42b1831 Rewrite FS fstab flag processing
* If 'ro' fsflag detected, set Mount_Read_Only = true
* Only output human readable Mount_Options to log
* Match fsflags identically (not just first n chars) since there are
  no fs_flags which take arguments
* Match new processing method introduced in TW fstab flag processing

Change-Id: Iefdb76016be90a131b0d627d0cd3f18d2eb1a008
2016-05-03 18:21:43 +01:00
Matt Mower
2416a50b5a Rewrite TWRP fstab flag processing
* Do not flip/flop between std::string and char* when no std::string
  specific functions are applied.
* Remove the need to manually count flag string lengths
* Move checks for Display_Name, Storage_Name, and Backup_Display_Name
  out of flag processing

Change-Id: I24d432c222124012b2a98d27598e42d0944f7da2
2016-05-03 18:20:57 +01:00
Gordon Freeman
5da130284e Partition: Fix parsing of several twrp fstab flags
fix parsing when using storagename=, backupname= and userdataencryptbackup= in twrp.fstab
also split encryptable= and forceencrypt= into seperate blocks
and make storage=Y working

Change-Id: I674f7ffe7f9e4ff121c4dccf79096360e044535c
2016-04-28 16:45:58 +01:00
Ethan Yonker
472f506817 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
2016-03-31 15:44:24 +01:00
Ethan Yonker
fe91611cb1 DataManager Updates
The goal of this change is to make DataManager use InfoManager to reduce
code duplication.

Change-Id: Ia4f4c4324453a192995e0f442db0a03628c13e46
2016-03-31 15:43:53 +01:00
James Christopher Adduono
d6f94acc9a Allow restoring to read-only file system
This allows the restoration of firmware or modems on read-only
mounted file systems. If the user is able to make a backup of
these partitions, it would only make sense they be allowed to
restore that backup. The current handling is dangerous in that
it happily wipes, but refuses to restore. :)

Note that it would be preferable to use the backup=emmc flag
instead in most cases, added by change:
https://gerrit.omnirom.org/#/c/17183

Change-Id: I32d47c8928dee61595c15a9db16d3c5b9a6d7183
2016-03-29 19:38:02 +01:00
Ethan Yonker
c2dafbbba6 Change to dd for wiping crypto partitions
flash_image was spitting an error. We are also specifying a size
so that we do not risk writing beyond the partition.

Change-Id: Ie3a0d77db96e54357238595934c3df0e3b680823
2016-03-17 21:55:41 +01:00
Ethan Yonker
fcf3f24856 Fix adopted storage when andsec flag is present
Change-Id: If903d838abc920f952f243482338188c15bb1dbf
2016-02-18 11:38:33 -06:00
Matt Mower
209c963575 partitions: Mount storage for MTP after wipe
Conditionally run Add_MTP_Storage() after wipe if:
1) is wiped successfully
2) is storage (already implemented)
3) mount succeeds

Previous to this commit, Add_MTP_Storage() was called before mounting
storage, which fails. Mounting storage right after wipe should not be
a problem since Update_System_Details() does it anyways (and doesn't
complain if already mounted).

Change-Id: I8a5a78d5ac9181f3a9464dfe6b77284458f9868b
2016-02-05 11:47:56 -06:00
HashBang
ed974bb87a allow flashing sparse images
if the image has the right magic bytes to be a sparse image,
use simg2img to flash the image

create a rule to make a fully dynamic simg2img which results in a
much smaller increase in gzip ramdisk size (2KB vs 40KB)

Change-Id: I1b0f6bc127da46103888b1154a9bddd8ac02c01d
2016-02-03 16:05:56 -06:00
that
f54e539b9c partition.cpp: fix build, add missing include
Change-Id: I5b4c3b90d579573536e9de2df5127160cdc9a10f
2016-01-29 22:04:43 +01:00
Ethan Yonker
b5fab76bea Replace fix permissions with fix contexts for emulated storage
Fix permissions rarely fixed anything on more recent versions of
Android and usually made things worse. Instead we will replace it
with a more dumbed down option that should fix contexts on
/data/media with a few improvements to ensure that contexts get
fixed for multiple users and on adopted storage.

Change-Id: If5523781936a0b04196e2ad871cae767ebae2583
2016-01-29 21:58:33 +01:00
Greg Wallace
558aef791b Reduce format f2fs time
Secure block discard/trim was fixed by:
6b39b93d83

Once fixed, formatting using discard/trim takes a LONG time.  Other TWRP
formatting methods are already insecure.  It doesn't make sense for this
one type of partition to have secure wipe when none of the others do.

Change-Id: Ib5ad5a722895b0e0c7aa4e3af98b705e2574b762
2016-01-29 17:55:46 +01:00
Ethan Yonker
66a1949df9 Adopted Storage support
-Detects, decrypts, and mounts an adopted SD card if a
  secondary block device is defined (usually mmcblk1)
 -Handles unified storage
 -Displays the adopted storage in MTP along with internal
 -Factory Reset - wiped just like a data media device, we
  retain the keys folder and the storage.xml during a
  factory reset
 -Backup / Restore
 -Disable mass storage when adopted storage is present
 -Read storage nickname from storage.xml and apply it to
  display names in the GUI
 -Read storage.xml and determine what storage location is in
  use for /sdcard and remap accordingly

libgpt_twrp is source code mostly kanged from an efimanager
project. It is GPL v2 or higher, so we will opt for GPL v3.

Change-Id: Ieda0030bec5155ba8d2b9167dc0016cebbf39d55
2016-01-25 23:59:17 +01:00
Matt Mower
3c36697b2d Fix a bunch of messages
* Find and rename/remove duplicate string variable names
* Add missing string variables to en language file
* Fix display of some strings missing @ in front of variable name
* Fix several %s --> {1}
* Be consistent in usage of cancelled vs. canceled (both spellings
  acceptable)

Tip for finding strings missing from language files:

1) Find all messages:
egrep -hr "gui_msg.+=" > /tmp/msgs.txt

2) Regex replace to trim them down
WHAT: ^\s+gui_msg(?:[^"]+)"([a-zA-Z0-9_]+)=([^"]+).+
WITH: $1
Note that $2 can be used to retain the message

3) Find missing strings:
for i in $(cat /tmp/msgs.txt); do
    if ! grep -q $i gui/theme/common/languages/en.xml; then
        echo $i;
    fi
done

Change-Id: Ic193162e4b5468bf027472928a370be39840ea1d
2016-01-22 05:29:04 +01:00
Ethan Yonker
483e9f45b7 Improve sdcard partitioning process
-Improve code for partitioning sdcards
-Allow user to select a device for partitioning (must be removable)
-Use sgdisk to partition sdcards
-Set default sizes for ext and swap to 0
-Change increments for ext to 256MB and swap to 64MB

Note: sgdisk is included in 6.0. I have included a static prebuilt
sgdisk for trees that do not have sgdisk, however the prebuilt
sgdisk is a decent bit larger than the old parted binary. The old
parted binary is quite old at this point and we only have it for
armv7a. sgdisk should be maintained by AOSP and can be built from
source so it should work across architectures.

Change-Id: Ib80882d9b5776e5e9358b11340fba392e6f1ae09
2016-01-14 17:40:43 +01:00