MTP add/remove storage instead of disabling MTP

Implement a pipe between TWRP and MTP to allow TWRP to tell MTP
to remove storage partitions as they become unavailable (e.g.
during a wipe, unmount, etc) instead of disabling MTP completely.
This includes some fixes and improvements in destructors to
properly remove / delete various items. This also means that we
will not be toggling adb off and on quite as often.

I do not like that we had to add another thread, but we were
unable to use select() on the mtp_usb character device because
this device does not support polling. Select always returned
indicating that the mtp file descriptor was ready to be read and
the resulting read would block. The read block prevented us from
being able to include reading of the pipe between TWRP and MTP in
the main MTP thread.

We might want to add a return pipe letting TWRP know if the
removal of the storage device was successful, but I am not sure
how we want to implement this. It would invovle timeouts in both
TWRP and MTP to ensure that we returned a failure indicator in a
timely manner to TWRP and prevent deleting the storage device in
the case of a failure. Right now we make no attempt to ensure that
an MTP operation is underway like a large file transfer, but we
were not doing anything like this in the past. In some respects we
have limited control over what happens. If the user installs a
zip that unmounts a storage partition, we will not know about the
change in storage status anyway. Regular Android does not have
these troubles because partitions rarely get unmounted like in
recovery. At some point, we have to hold the user accountable for
performing actions that may remove a storage partition while they
are using MTP anyway.

Ideally we do not want to toggle the USB IDs and thus toggle adb
off and on during early boot, but I am not sure what the best way
to handle that at this time.

Change-Id: I9343e5396bf6023d3b994de1bf01ed91d129bc14
18 files changed
tree: 5f0275dfed9c51b255e73feaeba609cd7a762da1
  1. applypatch/
  2. bmlutils/
  3. crypto/
  4. digest/
  5. dosfstools/
  6. edify/
  7. etc/
  8. exfat/
  9. fb2png/
  10. flashutils/
  11. fonts/
  12. fuse/
  13. gui/
  14. htcdumlock/
  15. injecttwrp/
  16. libblkid/
  17. libcrecovery/
  18. libmincrypt/
  19. libtar/
  20. minadbd/
  21. minui/
  22. minuitwrp/
  23. minzip/
  24. mmcutils/
  25. mtdutils/
  26. mtp/
  27. openaes/
  28. orscmd/
  29. pigz/
  30. prebuilt/
  31. res/
  32. res-hdpi/
  33. res-mdpi/
  34. res-xhdpi/
  35. res-xxhdpi/
  36. res-xxxhdpi/
  37. testdata/
  38. tests/
  39. toolbox/
  40. tools/
  41. twrpTarMain/
  42. uncrypt/
  43. updater/
  44. .gitignore
  45. adb_install.cpp
  46. adb_install.h
  47. Android.mk
  48. asn1_decoder.cpp
  49. asn1_decoder.h
  50. bootloader.cpp
  51. bootloader.h
  52. CleanSpec.mk
  53. common.h
  54. data.cpp
  55. data.h
  56. data.hpp
  57. default_device.cpp
  58. device.h
  59. find_file.cpp
  60. find_file.hpp
  61. fixPermissions.cpp
  62. fixPermissions.hpp
  63. fuse.h
  64. fuse_sdcard_provider.c
  65. fuse_sdcard_provider.h
  66. fuse_sideload.c
  67. fuse_sideload.h
  68. infomanager.cpp
  69. infomanager.hpp
  70. install.cpp
  71. install.h
  72. interlace-frames.py
  73. legacy_properties.h
  74. legacy_property_service.c
  75. legacy_property_service.h
  76. mounts.c
  77. mounts.h
  78. NOTICE
  79. openrecoveryscript.cpp
  80. openrecoveryscript.hpp
  81. partition.cpp
  82. partitionmanager.cpp
  83. partitions.hpp
  84. README.md
  85. recovery.cpp
  86. recovery_ui.h
  87. roots.cpp
  88. roots.h
  89. screen_ui.cpp
  90. screen_ui.h
  91. set_metadata.c
  92. set_metadata.h
  93. tarWrite.c
  94. tarWrite.h
  95. twcommon.h
  96. twinstall.cpp
  97. twinstall.h
  98. twrp-functions.cpp
  99. twrp-functions.hpp
  100. twrp.cpp
  101. twrpDigest.cpp
  102. twrpDigest.hpp
  103. twrpDU.cpp
  104. twrpDU.hpp
  105. twrpTar.cpp
  106. twrpTar.h
  107. twrpTar.hpp
  108. ui.cpp
  109. ui.h
  110. variables.h
  111. verifier.cpp
  112. verifier.h
  113. verifier_test.cpp
  114. verifier_test.sh
README.md

Team Win Recovery Project (TWRP)

The goal of this branch is to rebase TWRP onto AOSP while maintaining as much of the original AOSP code as possible. This goal should allow us to apply updates to the AOSP code going forward with little to no extra work. With this goal in mind, we will carefully consider any changes needed to the AOSP code before allowing them. In most cases, instead of changing the AOSP code, we'll create our own functions instead. The only changes that should be made to AOSP code should be those affecting startup of the recovery and some of the make files.

If there are changes that need to be merged from AOSP, we will pull the change directly from AOSP instead of creating a new patch in order to prevent merge conflicts with AOSP.

This branch is under final testing and will be used shortly for public builds, but has not officially been released.

You can find a compiling guide here.

More information about the project.

If you have code changes to submit those should be pushed to our gerrit instance. A guide can be found here.