Loading media/jni/android_media_MtpServer.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include "private/android_filesystem_config.h" #include "MtpServer.h" Loading Loading @@ -65,7 +66,7 @@ public: return false; } MtpServer* server = new MtpServer(fd, mDatabasePath); MtpServer* server = new MtpServer(fd, mDatabasePath, AID_SDCARD_RW, 0664, 0775); server->addStorage(mStoragePath); // temporary Loading media/mtp/MtpServer.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -113,10 +113,14 @@ static const MtpObjectFormat kSupportedPlaybackFormats[] = { // MTP_FORMAT_PLS_PLAYLIST, }; MtpServer::MtpServer(int fd, const char* databasePath) MtpServer::MtpServer(int fd, const char* databasePath, int fileGroup, int filePerm, int directoryPerm) : mFD(fd), mDatabasePath(databasePath), mDatabase(NULL), mFileGroup(fileGroup), mFilePermission(filePerm), mDirectoryPermission(directoryPerm), mSessionID(0), mSessionOpen(false), mSendObjectHandle(kInvalidObjectHandle), Loading Loading @@ -536,10 +540,11 @@ MtpResponseCode MtpServer::doSendObjectInfo() { if (format == MTP_FORMAT_ASSOCIATION) { mode_t mask = umask(0); int ret = mkdir((const char *)path, S_IRWXU | S_IRWXG | S_IRWXO); int ret = mkdir((const char *)path, mDirectoryPermission); umask(mask); if (ret && ret != -EEXIST) return MTP_RESPONSE_GENERAL_ERROR; chown((const char *)path, getuid(), mFileGroup); } else { mSendObjectFilePath = path; // save the handle for the SendObject call, which should follow Loading Loading @@ -571,12 +576,19 @@ MtpResponseCode MtpServer::doSendObject() { if (mfr.fd < 0) { return MTP_RESPONSE_GENERAL_ERROR; } fchown(mfr.fd, getuid(), mFileGroup); // set permissions mode_t mask = umask(0); fchmod(mfr.fd, mFilePermission); umask(mask); mfr.offset = 0; mfr.length = mSendObjectFileSize; // transfer the file ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr); close(mfr.fd); // FIXME - we need to delete mSendObjectHandle from the database if this fails. LOGV("MTP_RECEIVE_FILE returned %d", ret); mSendObjectHandle = kInvalidObjectHandle; Loading media/mtp/MtpServer.h +8 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,12 @@ private: MtpSqliteDatabase* mDatabase; // group to own new files and folders int mFileGroup; // permissions for new files and directories int mFilePermission; int mDirectoryPermission; // current session ID MtpSessionID mSessionID; // true if we have an open session and mSessionID is valid Loading @@ -61,7 +67,8 @@ private: size_t mSendObjectFileSize; public: MtpServer(int fd, const char* databasePath); MtpServer(int fd, const char* databasePath, int fileGroup, int filePerm, int directoryPerm); virtual ~MtpServer(); void addStorage(const char* filePath); Loading media/mtp/mtptest.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "MtpServer.h" #include "MtpStorage.h" #include "f_mtp.h" #include "private/android_filesystem_config.h" using namespace android; Loading Loading @@ -76,7 +77,7 @@ int main(int argc, char* argv[]) { enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); MtpServer server(fd, "/data/data/mtp/mtp.db"); MtpServer server(fd, "/data/data/mtp/mtp.db", AID_SDCARD_RW, 0664, 0775); server.addStorage(storagePath); server.scanStorage(); server.run(); Loading Loading
media/jni/android_media_MtpServer.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" #include "private/android_filesystem_config.h" #include "MtpServer.h" Loading Loading @@ -65,7 +66,7 @@ public: return false; } MtpServer* server = new MtpServer(fd, mDatabasePath); MtpServer* server = new MtpServer(fd, mDatabasePath, AID_SDCARD_RW, 0664, 0775); server->addStorage(mStoragePath); // temporary Loading
media/mtp/MtpServer.cpp +14 −2 Original line number Diff line number Diff line Loading @@ -113,10 +113,14 @@ static const MtpObjectFormat kSupportedPlaybackFormats[] = { // MTP_FORMAT_PLS_PLAYLIST, }; MtpServer::MtpServer(int fd, const char* databasePath) MtpServer::MtpServer(int fd, const char* databasePath, int fileGroup, int filePerm, int directoryPerm) : mFD(fd), mDatabasePath(databasePath), mDatabase(NULL), mFileGroup(fileGroup), mFilePermission(filePerm), mDirectoryPermission(directoryPerm), mSessionID(0), mSessionOpen(false), mSendObjectHandle(kInvalidObjectHandle), Loading Loading @@ -536,10 +540,11 @@ MtpResponseCode MtpServer::doSendObjectInfo() { if (format == MTP_FORMAT_ASSOCIATION) { mode_t mask = umask(0); int ret = mkdir((const char *)path, S_IRWXU | S_IRWXG | S_IRWXO); int ret = mkdir((const char *)path, mDirectoryPermission); umask(mask); if (ret && ret != -EEXIST) return MTP_RESPONSE_GENERAL_ERROR; chown((const char *)path, getuid(), mFileGroup); } else { mSendObjectFilePath = path; // save the handle for the SendObject call, which should follow Loading Loading @@ -571,12 +576,19 @@ MtpResponseCode MtpServer::doSendObject() { if (mfr.fd < 0) { return MTP_RESPONSE_GENERAL_ERROR; } fchown(mfr.fd, getuid(), mFileGroup); // set permissions mode_t mask = umask(0); fchmod(mfr.fd, mFilePermission); umask(mask); mfr.offset = 0; mfr.length = mSendObjectFileSize; // transfer the file ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr); close(mfr.fd); // FIXME - we need to delete mSendObjectHandle from the database if this fails. LOGV("MTP_RECEIVE_FILE returned %d", ret); mSendObjectHandle = kInvalidObjectHandle; Loading
media/mtp/MtpServer.h +8 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,12 @@ private: MtpSqliteDatabase* mDatabase; // group to own new files and folders int mFileGroup; // permissions for new files and directories int mFilePermission; int mDirectoryPermission; // current session ID MtpSessionID mSessionID; // true if we have an open session and mSessionID is valid Loading @@ -61,7 +67,8 @@ private: size_t mSendObjectFileSize; public: MtpServer(int fd, const char* databasePath); MtpServer(int fd, const char* databasePath, int fileGroup, int filePerm, int directoryPerm); virtual ~MtpServer(); void addStorage(const char* filePath); Loading
media/mtp/mtptest.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include "MtpServer.h" #include "MtpStorage.h" #include "f_mtp.h" #include "private/android_filesystem_config.h" using namespace android; Loading Loading @@ -76,7 +77,7 @@ int main(int argc, char* argv[]) { enable_usb_function("usb_mass_storage", false); enable_usb_function("mtp", true); MtpServer server(fd, "/data/data/mtp/mtp.db"); MtpServer server(fd, "/data/data/mtp/mtp.db", AID_SDCARD_RW, 0664, 0775); server.addStorage(storagePath); server.scanStorage(); server.run(); Loading