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

Commit fd5500ae authored by Manish Singh's avatar Manish Singh
Browse files

Use IMtpDatabase to open file in MTP

We want to first try opening the file in MTP using IMtpDatabase
irrespective of whether we are transcoding or not. This way we won't be
affected by the transcoding default option (A or B) and the decision
will solely rely on what we pass from here.

We can now do this because MtpDatabase now has the ability to pass both
supported and unsupported types to MediaProvider.

BUG=158466651
Test: manual

Change-Id: I20bd260cd11278afa66a9e41db3a5d06bd45a3f6
parent 0e6db8c6
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -794,9 +794,8 @@ MtpResponseCode MtpServer::doGetObject() {
    struct stat sstat;
    uint64_t finalsize;
    bool transcode = android::base::GetBoolProperty("sys.fuse.transcode_mtp", true);
    if (!transcode) {
        ALOGD("Mtp transcode disabled");
        mfr.fd = mDatabase->openFilePath(filePath, false);
    ALOGD("Mtp transcode = %d", transcode);
    mfr.fd = mDatabase->openFilePath(filePath, transcode);
    // Doing this here because we want to update fileLength only for this case and leave the
    // regular path as unchanged as possible.
    if (mfr.fd >= 0) {
@@ -804,12 +803,9 @@ MtpResponseCode MtpServer::doGetObject() {
        finalsize = sstat.st_size;
        fileLength = finalsize;
    } else {
            ALOGW("Mtp open with no transcoding failed for %s. Falling back to the original",
        ALOGW("Mtp open via IMtpDatabase failed for %s. Falling back to the original",
                filePath);
        }
    }

    if (transcode || mfr.fd < 0) {
        mfr.fd = open(filePath, O_RDONLY);
        if (mfr.fd < 0) {
            return MTP_RESPONSE_GENERAL_ERROR;