Loading core/java/android/provider/Settings.java +8 −1 Original line number Diff line number Diff line Loading @@ -1685,6 +1685,12 @@ public final class Settings { */ public static final String UNLOCK_SOUND = "unlock_sound"; /** * True if we should appear as a PTP device instead of MTP. * @hide */ public static final String USE_PTP_INTERFACE = "use_ptp_interface"; /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. Loading Loading @@ -1745,7 +1751,8 @@ public final class Settings { DOCK_SOUNDS_ENABLED, LOCKSCREEN_SOUNDS_ENABLED, SHOW_WEB_SUGGESTIONS, NOTIFICATION_LIGHT_PULSE NOTIFICATION_LIGHT_PULSE, USE_PTP_INTERFACE, }; // Settings moved to Settings.Secure Loading media/java/android/media/MtpServer.java +5 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,10 @@ public class MtpServer { native_send_object_removed(handle); } public void setPtpMode(boolean usePtp) { native_set_ptp_mode(usePtp); } // used by the JNI code private int mNativeContext; Loading @@ -68,4 +72,5 @@ public class MtpServer { private native final void native_stop(); 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); } media/jni/android_media_MtpServer.cpp +43 −8 Original line number Diff line number Diff line Loading @@ -22,8 +22,11 @@ #include <limits.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <utils/threads.h> #include <linux/usb/f_mtp.h> #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" Loading Loading @@ -56,34 +59,54 @@ private: MtpServer* mServer; String8 mStoragePath; jobject mJavaServer; int mFd; public: MtpThread(MtpDatabase* database, const char* storagePath, jobject javaServer) : mDatabase(database), mServer(NULL), mStoragePath(storagePath), mJavaServer(javaServer) mJavaServer(javaServer), mFd(-1) { } virtual bool threadLoop() { void setPtpMode(bool usePtp) { sMutex.lock(); if (mFd >= 0) { ioctl(mFd, MTP_SET_INTERFACE_MODE, (usePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); } else { int fd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", fd); if (fd < 0) { if (fd >= 0) { ioctl(fd, MTP_SET_INTERFACE_MODE, (usePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); close(fd); } } sMutex.unlock(); } virtual bool threadLoop() { sMutex.lock(); mFd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", mFd); if (mFd < 0) { LOGE("could not open MTP driver\n"); sMutex.unlock(); return false; } sMutex.lock(); mServer = new MtpServer(fd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer = new MtpServer(mFd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer->addStorage(mStoragePath); sMutex.unlock(); LOGD("MtpThread mServer->run"); mServer->run(); close(fd); sMutex.lock(); close(mFd); mFd = -1; delete mServer; mServer = NULL; Loading Loading @@ -184,6 +207,17 @@ android_media_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint hand #endif } static void android_media_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) { #ifdef HAVE_ANDROID_OS LOGD("set_ptp_mode\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->setPtpMode(usePtp); #endif } // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { Loading @@ -194,6 +228,7 @@ static JNINativeMethod gMethods[] = { {"native_stop", "()V", (void *)android_media_MtpServer_stop}, {"native_send_object_added", "(I)V", (void *)android_media_MtpServer_send_object_added}, {"native_send_object_removed", "(I)V", (void *)android_media_MtpServer_send_object_removed}, {"native_set_ptp_mode", "(Z)V", (void *)android_media_MtpServer_set_ptp_mode}, }; static const char* const kClassPathName = "android/media/MtpServer"; Loading packages/SettingsProvider/res/values/defaults.xml +2 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,6 @@ <!-- Default for Settings.System.VIBRATE_IN_SILENT --> <bool name="def_vibrate_in_silent">true</bool> <bool name="def_use_ptp_interface">false</bool> </resources> packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -1047,6 +1047,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, R.bool.def_vibrate_in_silent); loadBooleanSetting(stmt, Settings.System.USE_PTP_INTERFACE, R.bool.def_use_ptp_interface); } finally { if (stmt != null) stmt.close(); } Loading Loading
core/java/android/provider/Settings.java +8 −1 Original line number Diff line number Diff line Loading @@ -1685,6 +1685,12 @@ public final class Settings { */ public static final String UNLOCK_SOUND = "unlock_sound"; /** * True if we should appear as a PTP device instead of MTP. * @hide */ public static final String USE_PTP_INTERFACE = "use_ptp_interface"; /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. Loading Loading @@ -1745,7 +1751,8 @@ public final class Settings { DOCK_SOUNDS_ENABLED, LOCKSCREEN_SOUNDS_ENABLED, SHOW_WEB_SUGGESTIONS, NOTIFICATION_LIGHT_PULSE NOTIFICATION_LIGHT_PULSE, USE_PTP_INTERFACE, }; // Settings moved to Settings.Secure Loading
media/java/android/media/MtpServer.java +5 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,10 @@ public class MtpServer { native_send_object_removed(handle); } public void setPtpMode(boolean usePtp) { native_set_ptp_mode(usePtp); } // used by the JNI code private int mNativeContext; Loading @@ -68,4 +72,5 @@ public class MtpServer { private native final void native_stop(); 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); }
media/jni/android_media_MtpServer.cpp +43 −8 Original line number Diff line number Diff line Loading @@ -22,8 +22,11 @@ #include <limits.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <utils/threads.h> #include <linux/usb/f_mtp.h> #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" Loading Loading @@ -56,34 +59,54 @@ private: MtpServer* mServer; String8 mStoragePath; jobject mJavaServer; int mFd; public: MtpThread(MtpDatabase* database, const char* storagePath, jobject javaServer) : mDatabase(database), mServer(NULL), mStoragePath(storagePath), mJavaServer(javaServer) mJavaServer(javaServer), mFd(-1) { } virtual bool threadLoop() { void setPtpMode(bool usePtp) { sMutex.lock(); if (mFd >= 0) { ioctl(mFd, MTP_SET_INTERFACE_MODE, (usePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); } else { int fd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", fd); if (fd < 0) { if (fd >= 0) { ioctl(fd, MTP_SET_INTERFACE_MODE, (usePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP)); close(fd); } } sMutex.unlock(); } virtual bool threadLoop() { sMutex.lock(); mFd = open("/dev/mtp_usb", O_RDWR); printf("open returned %d\n", mFd); if (mFd < 0) { LOGE("could not open MTP driver\n"); sMutex.unlock(); return false; } sMutex.lock(); mServer = new MtpServer(fd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer = new MtpServer(mFd, mDatabase, AID_SDCARD_RW, 0664, 0775); mServer->addStorage(mStoragePath); sMutex.unlock(); LOGD("MtpThread mServer->run"); mServer->run(); close(fd); sMutex.lock(); close(mFd); mFd = -1; delete mServer; mServer = NULL; Loading Loading @@ -184,6 +207,17 @@ android_media_MtpServer_send_object_removed(JNIEnv *env, jobject thiz, jint hand #endif } static void android_media_MtpServer_set_ptp_mode(JNIEnv *env, jobject thiz, jboolean usePtp) { #ifdef HAVE_ANDROID_OS LOGD("set_ptp_mode\n"); MtpThread *thread = (MtpThread *)env->GetIntField(thiz, field_context); if (thread) thread->setPtpMode(usePtp); #endif } // ---------------------------------------------------------------------------- static JNINativeMethod gMethods[] = { Loading @@ -194,6 +228,7 @@ static JNINativeMethod gMethods[] = { {"native_stop", "()V", (void *)android_media_MtpServer_stop}, {"native_send_object_added", "(I)V", (void *)android_media_MtpServer_send_object_added}, {"native_send_object_removed", "(I)V", (void *)android_media_MtpServer_send_object_removed}, {"native_set_ptp_mode", "(Z)V", (void *)android_media_MtpServer_set_ptp_mode}, }; static const char* const kClassPathName = "android/media/MtpServer"; Loading
packages/SettingsProvider/res/values/defaults.xml +2 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,6 @@ <!-- Default for Settings.System.VIBRATE_IN_SILENT --> <bool name="def_vibrate_in_silent">true</bool> <bool name="def_use_ptp_interface">false</bool> </resources>
packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -1047,6 +1047,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT, R.bool.def_vibrate_in_silent); loadBooleanSetting(stmt, Settings.System.USE_PTP_INTERFACE, R.bool.def_use_ptp_interface); } finally { if (stmt != null) stmt.close(); } Loading