Loading media/java/android/mtp/MtpServer.java +7 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,12 @@ public class MtpServer { native_set_ptp_mode(usePtp); } // Used to disable MTP by removing all storage units. // This is done to disable access to file transfer when the device is locked. public void setLocked(boolean locked) { native_set_locked(locked); } private native final void native_setup(MtpDatabase database, String storagePath, long reserveSpace); private native final void native_start(); Loading @@ -61,4 +67,5 @@ public class MtpServer { private native final void native_send_object_added(int handle); private native final void native_send_object_removed(int handle); private native final void native_set_ptp_mode(boolean usePtp); private native final void native_set_locked(boolean locked); } media/jni/android_mtp_MtpServer.cpp +30 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ private: MtpStorage* mStorage; Mutex mMutex; bool mUsePtp; bool mLocked; int mFd; public: Loading @@ -67,6 +68,8 @@ public: : mDatabase(database), mServer(NULL), mStorage(storage), mUsePtp(false), mLocked(false), mFd(-1) { } Loading @@ -81,6 +84,20 @@ public: mMutex.unlock(); } void setLocked(bool locked) { mMutex.lock(); if (locked != mLocked) { if (mServer) { if (locked) mServer->removeStorage(mStorage); else mServer->addStorage(mStorage); } mLocked = locked; } mMutex.unlock(); } virtual bool threadLoop() { mMutex.lock(); mFd = open("/dev/mtp_usb", O_RDWR); Loading @@ -89,6 +106,7 @@ public: (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775); if (!mLocked) mServer->addStorage(mStorage); mMutex.unlock(); Loading Loading @@ -199,6 +217,16 @@ android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) #endif } static void android_mtp_MtpServer_set_locked(JNIEnv *env, jobject thiz, jboolean locked) { #ifdef HAVE_ANDROID_OS MtpThread *thread = sThread.get(); if (thread) thread->setLocked(locked); #endif } // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { Loading @@ -209,6 +237,7 @@ static JNINativeMethod gMethods[] = { {"native_send_object_added", "(I)V", (void *)android_mtp_MtpServer_send_object_added}, {"native_send_object_removed", "(I)V", (void *)android_mtp_MtpServer_send_object_removed}, {"native_set_ptp_mode", "(Z)V", (void *)android_mtp_MtpServer_set_ptp_mode}, {"native_set_locked", "(Z)V", (void *)android_mtp_MtpServer_set_locked}, }; static const char* const kClassPathName = "android/mtp/MtpServer"; Loading Loading
media/java/android/mtp/MtpServer.java +7 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,12 @@ public class MtpServer { native_set_ptp_mode(usePtp); } // Used to disable MTP by removing all storage units. // This is done to disable access to file transfer when the device is locked. public void setLocked(boolean locked) { native_set_locked(locked); } private native final void native_setup(MtpDatabase database, String storagePath, long reserveSpace); private native final void native_start(); Loading @@ -61,4 +67,5 @@ public class MtpServer { private native final void native_send_object_added(int handle); private native final void native_send_object_removed(int handle); private native final void native_set_ptp_mode(boolean usePtp); private native final void native_set_locked(boolean locked); }
media/jni/android_mtp_MtpServer.cpp +30 −1 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ private: MtpStorage* mStorage; Mutex mMutex; bool mUsePtp; bool mLocked; int mFd; public: Loading @@ -67,6 +68,8 @@ public: : mDatabase(database), mServer(NULL), mStorage(storage), mUsePtp(false), mLocked(false), mFd(-1) { } Loading @@ -81,6 +84,20 @@ public: mMutex.unlock(); } void setLocked(bool locked) { mMutex.lock(); if (locked != mLocked) { if (mServer) { if (locked) mServer->removeStorage(mStorage); else mServer->addStorage(mStorage); } mLocked = locked; } mMutex.unlock(); } virtual bool threadLoop() { mMutex.lock(); mFd = open("/dev/mtp_usb", O_RDWR); Loading @@ -89,6 +106,7 @@ public: (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775); if (!mLocked) mServer->addStorage(mStorage); mMutex.unlock(); Loading Loading @@ -199,6 +217,16 @@ android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) #endif } static void android_mtp_MtpServer_set_locked(JNIEnv *env, jobject thiz, jboolean locked) { #ifdef HAVE_ANDROID_OS MtpThread *thread = sThread.get(); if (thread) thread->setLocked(locked); #endif } // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { Loading @@ -209,6 +237,7 @@ static JNINativeMethod gMethods[] = { {"native_send_object_added", "(I)V", (void *)android_mtp_MtpServer_send_object_added}, {"native_send_object_removed", "(I)V", (void *)android_mtp_MtpServer_send_object_removed}, {"native_set_ptp_mode", "(Z)V", (void *)android_mtp_MtpServer_set_ptp_mode}, {"native_set_locked", "(Z)V", (void *)android_mtp_MtpServer_set_locked}, }; static const char* const kClassPathName = "android/mtp/MtpServer"; Loading