Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 933ea68a authored by Alex Klyubin's avatar Alex Klyubin Committed by Gerrit Code Review
Browse files

Merge "Make users of MtpServer fill in DeviceInfo field values"

parents 5e055b6a abdc2b47
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -29,9 +29,21 @@ public class MtpServer implements Runnable {
        System.loadLibrary("media_jni");
    }

    public MtpServer(MtpDatabase database, boolean usePtp) {
    public MtpServer(
            MtpDatabase database,
            boolean usePtp,
            String deviceInfoManufacturer,
            String deviceInfoModel,
            String deviceInfoDeviceVersion,
            String deviceInfoSerialNumber) {
        mDatabase = database;
        native_setup(database, usePtp);
        native_setup(
                database,
                usePtp,
                deviceInfoManufacturer,
                deviceInfoModel,
                deviceInfoDeviceVersion,
                deviceInfoSerialNumber);
        database.setServer(this);
    }

@@ -72,7 +84,13 @@ public class MtpServer implements Runnable {
    }

    public static native final void native_configure(boolean usePtp);
    private native final void native_setup(MtpDatabase database, boolean usePtp);
    private native final void native_setup(
            MtpDatabase database,
            boolean usePtp,
            String deviceInfoManufacturer,
            String deviceInfoModel,
            String deviceInfoDeviceVersion,
            String deviceInfoSerialNumber);
    private native final void native_run();
    private native final void native_cleanup();
    private native final void native_send_object_added(int handle);
+27 −3
Original line number Diff line number Diff line
@@ -61,10 +61,34 @@ static void android_mtp_configure(JNIEnv *, jobject, jboolean usePtp) {
}

static void
android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp)
android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, 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),
            usePtp, AID_MEDIA_RW, 0664, 0775);
            usePtp, AID_MEDIA_RW, 0664, 0775,
            MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""),
            MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""),
            MtpString((deviceInfoDeviceVersionStr != NULL) ? deviceInfoDeviceVersionStr : ""),
            MtpString((deviceInfoSerialNumberStr != NULL) ? deviceInfoSerialNumberStr : ""));
    if (deviceInfoManufacturerStr != NULL) {
        env->ReleaseStringUTFChars(deviceInfoManufacturer, deviceInfoManufacturerStr);
    }
    if (deviceInfoModelStr != NULL) {
        env->ReleaseStringUTFChars(deviceInfoModel, deviceInfoModelStr);
    }
    if (deviceInfoDeviceVersionStr != NULL) {
        env->ReleaseStringUTFChars(deviceInfoDeviceVersion, deviceInfoDeviceVersionStr);
    }
    if (deviceInfoSerialNumberStr != NULL) {
        env->ReleaseStringUTFChars(deviceInfoSerialNumber, deviceInfoSerialNumberStr);
    }
    env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
}

@@ -180,7 +204,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;Z)V",
    {"native_setup",                "(Landroid/mtp/MtpDatabase;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},