Loading core/res/res/values/config.xml +10 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,16 @@ removable. --> <bool name="config_externalStorageRemovable" product="default">true</bool> <!-- Number of megabytes of space to leave unallocated by MTP. MTP will subtract this value from the free space it reports back to the host via GetStorageInfo, and will not allow new files to be added via MTP if there is less than this amount left free in the storage. If MTP has dedicated storage this value should be zero, but if MTP is sharing storage with the rest of the system, set this to a positive value to ensure that MTP activity does not result in the storage being too close to full. --> <integer name="config_mtpReserveSpaceMegabytes">0</integer> <!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION. Please don't copy them, copy anything else. --> Loading media/java/android/media/MtpServer.java +4 −3 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ public class MtpServer { System.loadLibrary("media_jni"); } public MtpServer(MtpDatabase database, String storagePath) { native_setup(database, storagePath); public MtpServer(MtpDatabase database, String storagePath, long reserveSpace) { native_setup(database, storagePath, reserveSpace); } @Override Loading Loading @@ -66,7 +66,8 @@ public class MtpServer { // used by the JNI code private int mNativeContext; private native final void native_setup(MtpDatabase database, String storagePath); private native final void native_setup(MtpDatabase database, String storagePath, long reserveSpace); private native final void native_finalize(); private native final void native_start(); private native final void native_stop(); Loading media/jni/android_media_MtpServer.cpp +10 −5 Original line number Diff line number Diff line Loading @@ -60,14 +60,17 @@ private: MtpDatabase* mDatabase; MtpServer* mServer; String8 mStoragePath; uint64_t mReserveSpace; jobject mJavaServer; int mFd; public: MtpThread(MtpDatabase* database, const char* storagePath, jobject javaServer) MtpThread(MtpDatabase* database, const char* storagePath, uint64_t reserveSpace, jobject javaServer) : mDatabase(database), mServer(NULL), mStoragePath(storagePath), mReserveSpace(reserveSpace), mJavaServer(javaServer), mFd(-1) { Loading Loading @@ -100,7 +103,7 @@ public: } mServer = new MtpServer(mFd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer->addStorage(mStoragePath); mServer->addStorage(mStoragePath, mReserveSpace); sMutex.unlock(); LOGD("MtpThread mServer->run"); Loading Loading @@ -139,7 +142,8 @@ public: #endif // HAVE_ANDROID_OS static void android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath) android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath, jlong reserveSpace) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); Loading @@ -147,7 +151,8 @@ android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, j MtpDatabase* database = getMtpDatabase(env, javaDatabase); const char *storagePathStr = env->GetStringUTFChars(storagePath, NULL); MtpThread* thread = new MtpThread(database, storagePathStr, env->NewGlobalRef(thiz)); MtpThread* thread = new MtpThread(database, storagePathStr, reserveSpace, env->NewGlobalRef(thiz)); env->SetIntField(thiz, field_context, (int)thread); env->ReleaseStringUTFChars(storagePath, storagePathStr); Loading Loading @@ -213,7 +218,7 @@ android_media_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { {"native_setup", "(Landroid/media/MtpDatabase;Ljava/lang/String;)V", {"native_setup", "(Landroid/media/MtpDatabase;Ljava/lang/String;J)V", (void *)android_media_MtpServer_setup}, {"native_finalize", "()V", (void *)android_media_MtpServer_finalize}, {"native_start", "()V", (void *)android_media_MtpServer_start}, Loading media/mtp/MtpServer.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -104,10 +104,10 @@ MtpServer::MtpServer(int fd, MtpDatabase* database, MtpServer::~MtpServer() { } void MtpServer::addStorage(const char* filePath) { void MtpServer::addStorage(const char* filePath, uint64_t reserveSpace) { int index = mStorages.size() + 1; index |= index << 16; // set high and low part to our index MtpStorage* storage = new MtpStorage(index, filePath, mDatabase); MtpStorage* storage = new MtpStorage(index, filePath, reserveSpace); addStorage(storage); } Loading Loading @@ -687,6 +687,10 @@ MtpResponseCode MtpServer::doSendObjectInfo() { if (access(path, R_OK) == 0) return MTP_RESPONSE_GENERAL_ERROR; // check space first if (mSendObjectFileSize > storage->getFreeSpace()) return MTP_RESPONSE_STORAGE_FULL; MtpObjectHandle handle = mDatabase->beginSendObject((const char*)path, format, parent, storageID, mSendObjectFileSize, modifiedTime); if (handle == kInvalidObjectHandle) { Loading media/mtp/MtpServer.h +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public: int fileGroup, int filePerm, int directoryPerm); virtual ~MtpServer(); void addStorage(const char* filePath); void addStorage(const char* filePath, uint64_t reserveSpace); inline void addStorage(MtpStorage* storage) { mStorages.push(storage); } MtpStorage* getStorage(MtpStorageID id); void run(); Loading Loading
core/res/res/values/config.xml +10 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,16 @@ removable. --> <bool name="config_externalStorageRemovable" product="default">true</bool> <!-- Number of megabytes of space to leave unallocated by MTP. MTP will subtract this value from the free space it reports back to the host via GetStorageInfo, and will not allow new files to be added via MTP if there is less than this amount left free in the storage. If MTP has dedicated storage this value should be zero, but if MTP is sharing storage with the rest of the system, set this to a positive value to ensure that MTP activity does not result in the storage being too close to full. --> <integer name="config_mtpReserveSpaceMegabytes">0</integer> <!-- XXXXX NOTE THE FOLLOWING RESOURCES USE THE WRONG NAMING CONVENTION. Please don't copy them, copy anything else. --> Loading
media/java/android/media/MtpServer.java +4 −3 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ public class MtpServer { System.loadLibrary("media_jni"); } public MtpServer(MtpDatabase database, String storagePath) { native_setup(database, storagePath); public MtpServer(MtpDatabase database, String storagePath, long reserveSpace) { native_setup(database, storagePath, reserveSpace); } @Override Loading Loading @@ -66,7 +66,8 @@ public class MtpServer { // used by the JNI code private int mNativeContext; private native final void native_setup(MtpDatabase database, String storagePath); private native final void native_setup(MtpDatabase database, String storagePath, long reserveSpace); private native final void native_finalize(); private native final void native_start(); private native final void native_stop(); Loading
media/jni/android_media_MtpServer.cpp +10 −5 Original line number Diff line number Diff line Loading @@ -60,14 +60,17 @@ private: MtpDatabase* mDatabase; MtpServer* mServer; String8 mStoragePath; uint64_t mReserveSpace; jobject mJavaServer; int mFd; public: MtpThread(MtpDatabase* database, const char* storagePath, jobject javaServer) MtpThread(MtpDatabase* database, const char* storagePath, uint64_t reserveSpace, jobject javaServer) : mDatabase(database), mServer(NULL), mStoragePath(storagePath), mReserveSpace(reserveSpace), mJavaServer(javaServer), mFd(-1) { Loading Loading @@ -100,7 +103,7 @@ public: } mServer = new MtpServer(mFd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer->addStorage(mStoragePath); mServer->addStorage(mStoragePath, mReserveSpace); sMutex.unlock(); LOGD("MtpThread mServer->run"); Loading Loading @@ -139,7 +142,8 @@ public: #endif // HAVE_ANDROID_OS static void android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath) android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jstring storagePath, jlong reserveSpace) { #ifdef HAVE_ANDROID_OS LOGD("setup\n"); Loading @@ -147,7 +151,8 @@ android_media_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, j MtpDatabase* database = getMtpDatabase(env, javaDatabase); const char *storagePathStr = env->GetStringUTFChars(storagePath, NULL); MtpThread* thread = new MtpThread(database, storagePathStr, env->NewGlobalRef(thiz)); MtpThread* thread = new MtpThread(database, storagePathStr, reserveSpace, env->NewGlobalRef(thiz)); env->SetIntField(thiz, field_context, (int)thread); env->ReleaseStringUTFChars(storagePath, storagePathStr); Loading Loading @@ -213,7 +218,7 @@ android_media_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { {"native_setup", "(Landroid/media/MtpDatabase;Ljava/lang/String;)V", {"native_setup", "(Landroid/media/MtpDatabase;Ljava/lang/String;J)V", (void *)android_media_MtpServer_setup}, {"native_finalize", "()V", (void *)android_media_MtpServer_finalize}, {"native_start", "()V", (void *)android_media_MtpServer_start}, Loading
media/mtp/MtpServer.cpp +6 −2 Original line number Diff line number Diff line Loading @@ -104,10 +104,10 @@ MtpServer::MtpServer(int fd, MtpDatabase* database, MtpServer::~MtpServer() { } void MtpServer::addStorage(const char* filePath) { void MtpServer::addStorage(const char* filePath, uint64_t reserveSpace) { int index = mStorages.size() + 1; index |= index << 16; // set high and low part to our index MtpStorage* storage = new MtpStorage(index, filePath, mDatabase); MtpStorage* storage = new MtpStorage(index, filePath, reserveSpace); addStorage(storage); } Loading Loading @@ -687,6 +687,10 @@ MtpResponseCode MtpServer::doSendObjectInfo() { if (access(path, R_OK) == 0) return MTP_RESPONSE_GENERAL_ERROR; // check space first if (mSendObjectFileSize > storage->getFreeSpace()) return MTP_RESPONSE_STORAGE_FULL; MtpObjectHandle handle = mDatabase->beginSendObject((const char*)path, format, parent, storageID, mSendObjectFileSize, modifiedTime); if (handle == kInvalidObjectHandle) { Loading
media/mtp/MtpServer.h +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public: int fileGroup, int filePerm, int directoryPerm); virtual ~MtpServer(); void addStorage(const char* filePath); void addStorage(const char* filePath, uint64_t reserveSpace); inline void addStorage(MtpStorage* storage) { mStorages.push(storage); } MtpStorage* getStorage(MtpStorageID id); void run(); Loading