Loading media/mtp/IMtpDatabase.h +3 −1 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public: int64_t& outFileLength, MtpObjectFormat& outFormat) = 0; virtual int openFilePath(const char* path, bool transcode) = 0; virtual MtpResponseCode beginDeleteObject(MtpObjectHandle handle) = 0; virtual void endDeleteObject(MtpObjectHandle handle, bool succeeded) = 0; Loading media/mtp/MtpServer.cpp +27 −7 Original line number Diff line number Diff line Loading @@ -791,10 +791,33 @@ MtpResponseCode MtpServer::doGetObject() { const char* filePath = (const char *)pathBuf; mtp_file_range mfr; 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); // 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) { fstat(mfr.fd, &sstat); finalsize = sstat.st_size; fileLength = finalsize; } else { ALOGW("Mtp open with no transcoding 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; } fstat(mfr.fd, &sstat); finalsize = sstat.st_size; } mfr.offset = 0; mfr.length = fileLength; mfr.command = mRequest.getOperationCode(); Loading @@ -815,9 +838,6 @@ MtpResponseCode MtpServer::doGetObject() { auto end = std::chrono::steady_clock::now(); std::chrono::duration<double> diff = end - start; struct stat sstat; fstat(mfr.fd, &sstat); uint64_t finalsize = sstat.st_size; ALOGV("Sent a file over MTP. Time: %f s, Size: %" PRIu64 ", Rate: %f bytes/s", diff.count(), finalsize, ((double) finalsize) / diff.count()); closeObjFd(mfr.fd, filePath); Loading media/mtp/tests/MtpFuzzer/MtpMockDatabase.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,11 @@ MtpResponseCode MtpMockDatabase::getObjectFilePath(MtpObjectHandle handle, return MTP_RESPONSE_OK; } int MtpMockDatabase::openFilePath(const char* path, bool transcode) { ALOGD("MockDatabase %s: filePath=%s transcode=%d\n", __func__, path, transcode); return 0; } MtpResponseCode MtpMockDatabase::beginDeleteObject(MtpObjectHandle handle) { ALOGD("MockDatabase %s: ohandle=%u\n", __func__, handle); return MTP_RESPONSE_OK; Loading media/mtp/tests/MtpFuzzer/MtpMockDatabase.h +2 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,8 @@ public: MtpResponseCode getObjectFilePath(MtpObjectHandle handle, MtpStringBuffer& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); int openFilePath(const char* path, bool transcode); MtpResponseCode beginDeleteObject(MtpObjectHandle handle); void endDeleteObject(MtpObjectHandle handle, bool succeeded); Loading Loading
media/mtp/IMtpDatabase.h +3 −1 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public: int64_t& outFileLength, MtpObjectFormat& outFormat) = 0; virtual int openFilePath(const char* path, bool transcode) = 0; virtual MtpResponseCode beginDeleteObject(MtpObjectHandle handle) = 0; virtual void endDeleteObject(MtpObjectHandle handle, bool succeeded) = 0; Loading
media/mtp/MtpServer.cpp +27 −7 Original line number Diff line number Diff line Loading @@ -791,10 +791,33 @@ MtpResponseCode MtpServer::doGetObject() { const char* filePath = (const char *)pathBuf; mtp_file_range mfr; 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); // 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) { fstat(mfr.fd, &sstat); finalsize = sstat.st_size; fileLength = finalsize; } else { ALOGW("Mtp open with no transcoding 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; } fstat(mfr.fd, &sstat); finalsize = sstat.st_size; } mfr.offset = 0; mfr.length = fileLength; mfr.command = mRequest.getOperationCode(); Loading @@ -815,9 +838,6 @@ MtpResponseCode MtpServer::doGetObject() { auto end = std::chrono::steady_clock::now(); std::chrono::duration<double> diff = end - start; struct stat sstat; fstat(mfr.fd, &sstat); uint64_t finalsize = sstat.st_size; ALOGV("Sent a file over MTP. Time: %f s, Size: %" PRIu64 ", Rate: %f bytes/s", diff.count(), finalsize, ((double) finalsize) / diff.count()); closeObjFd(mfr.fd, filePath); Loading
media/mtp/tests/MtpFuzzer/MtpMockDatabase.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,11 @@ MtpResponseCode MtpMockDatabase::getObjectFilePath(MtpObjectHandle handle, return MTP_RESPONSE_OK; } int MtpMockDatabase::openFilePath(const char* path, bool transcode) { ALOGD("MockDatabase %s: filePath=%s transcode=%d\n", __func__, path, transcode); return 0; } MtpResponseCode MtpMockDatabase::beginDeleteObject(MtpObjectHandle handle) { ALOGD("MockDatabase %s: ohandle=%u\n", __func__, handle); return MTP_RESPONSE_OK; Loading
media/mtp/tests/MtpFuzzer/MtpMockDatabase.h +2 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,8 @@ public: MtpResponseCode getObjectFilePath(MtpObjectHandle handle, MtpStringBuffer& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); int openFilePath(const char* path, bool transcode); MtpResponseCode beginDeleteObject(MtpObjectHandle handle); void endDeleteObject(MtpObjectHandle handle, bool succeeded); Loading