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();
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);
}
MtpStorage* mStorage;
Mutex mMutex;
bool mUsePtp;
+ bool mLocked;
int mFd;
public:
: mDatabase(database),
mServer(NULL),
mStorage(storage),
+ mUsePtp(false),
+ mLocked(false),
mFd(-1)
{
}
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);
(mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
- mServer->addStorage(mStorage);
+ if (!mLocked)
+ mServer->addStorage(mStorage);
mMutex.unlock();
mServer->run();
#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[] = {
{"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";