crypto: Use system's vold for decryption

  If TWRP crypto fails to decrypt partition, mount the system
  partition and use system's own vold to attempt decryption.
  This provides a fallback for proprietary OEM encryption as well as
  encryption methods which TWRP hasn't been updated for.

  Requirements in device tree:
  * fstab.{ro.hardware} in device/recovery/root
    The fstab does not need to be complete, but it does need the
    data partition and the encryption entries.

  * 'TW_CRYPTO_USE_SYSTEM_VOLD := true' in BoardConfig
  or
  * 'TW_CRYPTO_USE_SYSTEM_VOLD := <list of services>'

  Notes:
  * Setting the flag to 'true' will just use system's vdc+vold
    or
  * Setting the flag with additional services, will also start them
    prior to attempting vdc+vold decryption, eg: for qualcomm based
    devices you usually need 'TW_CRYPTO_USE_SYSTEM_VOLD := qseecomd'

  * For each service listed an additional import will be automatically
    added to the vold_decrypt.rc file in the form of
    init.recovery.vold_decrypt.{service}.rc
    You will need to add any not already existing .rc files in
    your device/recovery/root folder.

  * The service names specified in the vold_decrypt.{service}.rc files
    have to be named 'sys_{service}'
    eg: 'service sys_qseecomd /system/bin/qseecomd'

  * Any service already existing in TWRP as {service} or sbin{service} will
    be stopped and restarted as needed.

  * You can override the default init.recovery.vold_decrypt.rc file(s)
    by placing same named ones in your device/recovery/root folder.
    If you do, you'll need to manually add the needed imports.

  * If /vendor and /firmware folders are temporarily moved and symlinked
    to the folders and files in the system partition, the properties
    'vold_decrypt.symlinked_vendor' and 'vold_decrypt.symlinked_firmware'
    will be set to 1.
    This allows for additional control in the .rc files for any extra
    actions (symlinks, cp files, etc) that may be needed for decryption
    by using: on property:vold_decrypt.symlinked_vendor=1 and/or
    on property:vold_decrypt.symlinked_firmware=1 triggers.

  Debug mode: 'TW_CRYPTO_SYSTEM_VOLD_DEBUG := true' in BoardConfig
  * Specifying this flag, will enable strace on init and vdc, which will
    create separate log files in /tmp for every process created, allowing
    for detailed analysis of which services and files are being accessed.
  * Note that enabling strace will expose the password in the logs!!
  * You need to manually add strace to your build.

Thanks to @Captain_Throwback for co-authoring and testing.

Tested successfully on HTC devices:
M8 (KK through MM), M9 (MM and N), A9 (N), 10 (N), Bolt (N),
Desire 626s (MM), U Ultra (N)

HTC One X9 (MTK device)

And by Nikolay Jeliazkov on: Xiaomi Mi Max

Change-Id: I4d22ab55baf6a2a50adde2e4c1c510c142714227
8 files changed
tree: 788c81abdeb80f028754935f825538284cce550e
  1. adbbu/
  2. applypatch/
  3. attr/
  4. bmlutils/
  5. bootloader_message/
  6. crypto/
  7. digest/
  8. dosfstools/
  9. edify/
  10. etc/
  11. exfat/
  12. fb2png/
  13. flashutils/
  14. fonts/
  15. fuse/
  16. gpt/
  17. gui/
  18. htcdumlock/
  19. injecttwrp/
  20. libblkid/
  21. libcrecovery/
  22. libmincrypt/
  23. libpixelflinger/
  24. libtar/
  25. minadbd/
  26. minadbd.old/
  27. minui/
  28. minui.old/
  29. minuitwrp/
  30. minzip/
  31. mmcutils/
  32. mtdutils/
  33. mtp/
  34. openaes/
  35. orscmd/
  36. otafault/
  37. pigz/
  38. prebuilt/
  39. res/
  40. res-hdpi/
  41. res-mdpi/
  42. res-xhdpi/
  43. res-xxhdpi/
  44. res-xxxhdpi/
  45. scripts/
  46. sepolicy/
  47. simg2img/
  48. tests/
  49. toolbox/
  50. tools/
  51. toybox/
  52. twrpTarMain/
  53. uncrypt/
  54. update_verifier/
  55. updater/
  56. verifier24/
  57. .gitignore
  58. adb_install.cpp
  59. adb_install.h
  60. Android.mk
  61. asn1_decoder.cpp
  62. asn1_decoder.h
  63. bootloader.h
  64. CleanSpec.mk
  65. common.h
  66. data.cpp
  67. data.hpp
  68. default_device.cpp
  69. device.cpp
  70. device.h
  71. error_code.h
  72. exclude.cpp
  73. exclude.hpp
  74. find_file.cpp
  75. find_file.hpp
  76. fixContexts.cpp
  77. fixContexts.hpp
  78. fuse.h
  79. fuse_sdcard_provider.cpp
  80. fuse_sdcard_provider.h
  81. fuse_sideload.cpp
  82. fuse_sideload.h
  83. infomanager.cpp
  84. infomanager.hpp
  85. install.cpp
  86. install.h
  87. installcommand.cpp
  88. installcommand.h
  89. interlace-frames.py
  90. legacy_properties.h
  91. legacy_property_service.cpp
  92. legacy_property_service.h
  93. mounts.c
  94. mounts.h
  95. NOTICE
  96. openrecoveryscript.cpp
  97. openrecoveryscript.hpp
  98. partition.cpp
  99. partitionmanager.cpp
  100. partitions.hpp
  101. print_sha1.h
  102. progresstracking.cpp
  103. progresstracking.hpp
  104. README.md
  105. recovery-persist.cpp
  106. recovery-persist.rc
  107. recovery-refresh.cpp
  108. recovery-refresh.rc
  109. recovery.cpp
  110. recovery_ui.h
  111. roots.cpp
  112. roots.h
  113. screen_ui.cpp
  114. screen_ui.h
  115. set_metadata.cpp
  116. set_metadata.h
  117. tarWrite.c
  118. tarWrite.h
  119. tw_atomic.cpp
  120. tw_atomic.hpp
  121. twcommon.h
  122. twinstall.cpp
  123. twinstall.h
  124. twrp-functions.cpp
  125. twrp-functions.hpp
  126. twrp.cpp
  127. twrpDigest.cpp
  128. twrpDigest.hpp
  129. twrpTar.cpp
  130. twrpTar.h
  131. twrpTar.hpp
  132. ui.cpp
  133. ui.h
  134. unique_fd.h
  135. variables.h
  136. verifier.cpp
  137. verifier.h
  138. wear_touch.cpp
  139. wear_touch.h
  140. wear_ui.cpp
  141. wear_ui.h
README.md

Team Win Recovery Project (TWRP)

You can find a compiling guide here.