diff options
author | Jerry Zhang <zhangjerry@google.com> | 2017-12-06 16:03:57 -0800 |
---|---|---|
committer | Jerry Zhang <zhangjerry@google.com> | 2018-03-22 11:35:19 -0700 |
commit | 6d319b8aaa961862afac48010d96d03afb11fa1c (patch) | |
tree | a90ec1e5d307de422619e6102060df871e222f54 /media/jni/android_mtp_MtpServer.cpp | |
parent | c7f6eadffc0a243618ce09ee8d6bb8235738135d (diff) |
Write descriptors for Mtp in UsbService
The current model for setting up a functionfs
function is:
UsbDeviceManager#setCurrentFunctions() ->
intent is sent to MtpReceiver to write the descriptors ->
init/hal waits for descriptors to write, then pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer
The main downside of this is a lack of reliability because
the Mtp process could be killed at any point. Normally, a
gadget is unbound if its control endpoint is closed. no_disconnect
works around this, but is still a little janky. In addition, the
extra intent delays the startup of the gadget.
With the new model, UsbDeviceManager writes the descriptors
on initialization. Since it is a system service, it won't be killed.
UsbDeviceManager#setCurrentFunctions() ->
init/hal pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer
MtpServer calls UsbManager#getControlFd to get a dup of the control
endpoint.
Also modify permissions so system server can access mtp files.
Bug: 72877174
Test: Change usb configurations to ptp/mtp
Change-Id: Id17d2b5930f4e1f37ec1b4f00add9d594174ad49
Diffstat (limited to 'media/jni/android_mtp_MtpServer.cpp')
-rw-r--r-- | media/jni/android_mtp_MtpServer.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp index c76cebebc730..8730e0622200 100644 --- a/media/jni/android_mtp_MtpServer.cpp +++ b/media/jni/android_mtp_MtpServer.cpp @@ -55,22 +55,17 @@ static inline MtpServer* getMtpServer(JNIEnv *env, jobject thiz) { return (MtpServer*)env->GetLongField(thiz, field_MtpServer_nativeContext); } -static void android_mtp_configure(JNIEnv *, jobject, jboolean usePtp) { - MtpServer::configure(usePtp); -} - static void -android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp, - jstring deviceInfoManufacturer, - jstring deviceInfoModel, - jstring deviceInfoDeviceVersion, - jstring deviceInfoSerialNumber) +android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jobject jControlFd, + jboolean usePtp, jstring deviceInfoManufacturer, jstring deviceInfoModel, + jstring deviceInfoDeviceVersion, jstring deviceInfoSerialNumber) { const char *deviceInfoManufacturerStr = env->GetStringUTFChars(deviceInfoManufacturer, NULL); const char *deviceInfoModelStr = env->GetStringUTFChars(deviceInfoModel, NULL); const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL); const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL); - MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase), + int controlFd = dup(jniGetFDFromFileDescriptor(env, jControlFd)); + MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase), controlFd, usePtp, MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""), MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""), @@ -201,8 +196,7 @@ android_mtp_MtpServer_remove_storage(JNIEnv *env, jobject thiz, jint storageId) // ---------------------------------------------------------------------------- static const JNINativeMethod gMethods[] = { - {"native_configure", "(Z)V", (void *)android_mtp_configure}, - {"native_setup", "(Landroid/mtp/MtpDatabase;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", + {"native_setup", "(Landroid/mtp/MtpDatabase;Ljava/io/FileDescriptor;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", (void *)android_mtp_MtpServer_setup}, {"native_run", "()V", (void *)android_mtp_MtpServer_run}, {"native_cleanup", "()V", (void *)android_mtp_MtpServer_cleanup}, |