Remove configure() from Mtp
Instead of configuring the server each
time the connection happens, UsbService
will now pass in the control fd with the
descriptors already written. Also, PTP
endpoints have been moved to their own
directory at /dev/usb-ffs/ptp rather than
using the same ones as mtp.
Bug: 72877174
Test: Verify PTP and MTP config changes work
Change-Id: I9a0336afd610aa397c9947568c308afb89b27c08
diff --git a/media/mtp/MtpDescriptors.cpp b/media/mtp/MtpDescriptors.cpp
index d9b6060..4a336c8 100644
--- a/media/mtp/MtpDescriptors.cpp
+++ b/media/mtp/MtpDescriptors.cpp
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+#include <android-base/logging.h>
+#include <sys/types.h>
+
#include "MtpDescriptors.h"
namespace android {
@@ -257,4 +260,24 @@
.hs_descs = ptp_hs_descriptors,
};
+bool writeDescriptors(int fd, bool ptp) {
+ ssize_t ret = TEMP_FAILURE_RETRY(write(fd,
+ &(ptp ? ptp_desc_v2 : mtp_desc_v2), sizeof(desc_v2)));
+ if (ret < 0) {
+ PLOG(ERROR) << fd << "Switching to V1 descriptor format";
+ ret = TEMP_FAILURE_RETRY(write(fd,
+ &(ptp ? ptp_desc_v1 : mtp_desc_v1), sizeof(desc_v1)));
+ if (ret < 0) {
+ PLOG(ERROR) << fd << "Writing descriptors failed";
+ return false;
+ }
+ }
+ ret = TEMP_FAILURE_RETRY(write(fd, &mtp_strings, sizeof(mtp_strings)));
+ if (ret < 0) {
+ PLOG(ERROR) << fd << "Writing strings failed";
+ return false;
+ }
+ return true;
+}
+
}; // namespace android