am 8719c406: DO NOT MERGE: MTP: Disable MTP when the keyguard is locked and secure
* commit '8719c406c3db17842d9350c1f6611f088d105f38': DO NOT MERGE: MTP: Disable MTP when the keyguard is locked and secure
This commit is contained in:
@@ -54,6 +54,12 @@ public class MtpServer {
|
|||||||
native_set_ptp_mode(usePtp);
|
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,
|
private native final void native_setup(MtpDatabase database, String storagePath,
|
||||||
long reserveSpace);
|
long reserveSpace);
|
||||||
private native final void native_start();
|
private native final void native_start();
|
||||||
@@ -61,4 +67,5 @@ public class MtpServer {
|
|||||||
private native final void native_send_object_added(int handle);
|
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_send_object_removed(int handle);
|
||||||
private native final void native_set_ptp_mode(boolean usePtp);
|
private native final void native_set_ptp_mode(boolean usePtp);
|
||||||
|
private native final void native_set_locked(boolean locked);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ private:
|
|||||||
MtpStorage* mStorage;
|
MtpStorage* mStorage;
|
||||||
Mutex mMutex;
|
Mutex mMutex;
|
||||||
bool mUsePtp;
|
bool mUsePtp;
|
||||||
|
bool mLocked;
|
||||||
int mFd;
|
int mFd;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -67,6 +68,8 @@ public:
|
|||||||
: mDatabase(database),
|
: mDatabase(database),
|
||||||
mServer(NULL),
|
mServer(NULL),
|
||||||
mStorage(storage),
|
mStorage(storage),
|
||||||
|
mUsePtp(false),
|
||||||
|
mLocked(false),
|
||||||
mFd(-1)
|
mFd(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -81,6 +84,20 @@ public:
|
|||||||
mMutex.unlock();
|
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() {
|
virtual bool threadLoop() {
|
||||||
mMutex.lock();
|
mMutex.lock();
|
||||||
mFd = open("/dev/mtp_usb", O_RDWR);
|
mFd = open("/dev/mtp_usb", O_RDWR);
|
||||||
@@ -89,7 +106,8 @@ public:
|
|||||||
(mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
|
(mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));
|
||||||
|
|
||||||
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
|
mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
|
||||||
mServer->addStorage(mStorage);
|
if (!mLocked)
|
||||||
|
mServer->addStorage(mStorage);
|
||||||
|
|
||||||
mMutex.unlock();
|
mMutex.unlock();
|
||||||
mServer->run();
|
mServer->run();
|
||||||
@@ -199,6 +217,16 @@ android_mtp_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp)
|
|||||||
#endif
|
#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[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
@@ -209,6 +237,7 @@ static JNINativeMethod gMethods[] = {
|
|||||||
{"native_send_object_added", "(I)V", (void *)android_mtp_MtpServer_send_object_added},
|
{"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_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_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";
|
static const char* const kClassPathName = "android/mtp/MtpServer";
|
||||||
|
|||||||
Reference in New Issue
Block a user