Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63dac45a authored by Jerry Zhang's avatar Jerry Zhang
Browse files

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
parent b95a5989
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -32,8 +32,7 @@ public:
    virtual int sendEvent(mtp_event me) = 0;

    // Return 0 if operation is successful, or -1 else
    virtual int start() = 0;
    virtual int configure(bool ptp) = 0;
    virtual int start(bool ptp) = 0;

    virtual void close() = 0;

+23 −0
Original line number Diff line number Diff line
@@ -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 @@ const struct desc_v1 ptp_desc_v1 = {
    .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
+12 −0
Original line number Diff line number Diff line
@@ -23,6 +23,16 @@

namespace android {

constexpr char FFS_MTP_EP0[] = "/dev/usb-ffs/mtp/ep0";
constexpr char FFS_MTP_EP_IN[] = "/dev/usb-ffs/mtp/ep1";
constexpr char FFS_MTP_EP_OUT[] = "/dev/usb-ffs/mtp/ep2";
constexpr char FFS_MTP_EP_INTR[] = "/dev/usb-ffs/mtp/ep3";

constexpr char FFS_PTP_EP0[] = "/dev/usb-ffs/ptp/ep0";
constexpr char FFS_PTP_EP_IN[] = "/dev/usb-ffs/ptp/ep1";
constexpr char FFS_PTP_EP_OUT[] = "/dev/usb-ffs/ptp/ep2";
constexpr char FFS_PTP_EP_INTR[] = "/dev/usb-ffs/ptp/ep3";

constexpr int MAX_PACKET_SIZE_FS = 64;
constexpr int MAX_PACKET_SIZE_HS = 512;
constexpr int MAX_PACKET_SIZE_SS = 1024;
@@ -91,6 +101,8 @@ extern const struct desc_v1 mtp_desc_v1;
extern const struct desc_v1 ptp_desc_v1;
extern const struct functionfs_strings mtp_strings;

bool writeDescriptors(int fd, bool ptp);

}; // namespace android

#endif // MTP_DESCRIPTORS_H
+1 −6
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ int MtpDevHandle::sendEvent(mtp_event me) {
    return ioctl(mFd, MTP_SEND_EVENT, reinterpret_cast<unsigned long>(&me));
}

int MtpDevHandle::start() {
int MtpDevHandle::start(bool /* ptp */) {
    mFd.reset(TEMP_FAILURE_RETRY(open(mtp_dev_path, O_RDWR)));
    if (mFd == -1) return -1;
    return 0;
@@ -70,9 +70,4 @@ void MtpDevHandle::close() {
    mFd.reset();
}

int MtpDevHandle::configure(bool) {
    // Nothing to do, driver can configure itself
    return 0;
}

} // namespace android
+1 −3
Original line number Diff line number Diff line
@@ -36,10 +36,8 @@ public:
    int sendFile(mtp_file_range mfr);
    int sendEvent(mtp_event me);

    int start();
    int start(bool ptp);
    void close();

    int configure(bool ptp);
};

} // namespace android
Loading