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

Commit ebabd09a authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Handle the failure from GetStringUTFChars()"

parents 68344047 3977472d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -427,6 +427,9 @@ MtpResponseCode MyMtpDatabase::getObjectPropertyValue(MtpObjectHandle handle,
                jstring stringValue = (jstring)env->GetObjectArrayElement(stringValuesArray, 0);
                if (stringValue) {
                    const char* str = env->GetStringUTFChars(stringValue, NULL);
                    if (str == NULL) {
                        return MTP_RESPONSE_GENERAL_ERROR;
                    }
                    packet.putString(str);
                    env->ReleaseStringUTFChars(stringValue, str);
                } else {
+9 −1
Original line number Diff line number Diff line
@@ -110,6 +110,10 @@ android_mtp_MtpDevice_open(JNIEnv *env, jobject thiz, jstring deviceName, jint f
#ifdef HAVE_ANDROID_OS
    LOGD("open\n");
    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
    if (deviceNameStr == NULL) {
        return false;
    }

    MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
    env->ReleaseStringUTFChars(deviceName, deviceNameStr);

@@ -426,12 +430,16 @@ android_mtp_MtpDevice_import_file(JNIEnv *env, jobject thiz, jint object_id, jst
    MtpDevice* device = get_device_from_object(env, thiz);
    if (device) {
        const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
        if (destPathStr == NULL) {
            return false;
        }

        bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
        env->ReleaseStringUTFChars(dest_path, destPathStr);
        return result;
    }
#endif
    return NULL;
    return false;
}

// ----------------------------------------------------------------------------
+13 −9
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public:
    void removeStorage(MtpStorageID id) {
        MtpStorage* storage = mServer->getStorage(id);
        if (storage) {
            for (int i = 0; i < mStorageList.size(); i++) {
            for (size_t i = 0; i < mStorageList.size(); i++) {
                if (mStorageList[i] == storage) {
                    mStorageList.removeAt(i);
                    break;
@@ -122,7 +122,7 @@ public:
                    (mUsePtp ? MTP_INTERFACE_MODE_PTP : MTP_INTERFACE_MODE_MTP));

            mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
            for (int i = 0; i < mStorageList.size(); i++) {
            for (size_t i = 0; i < mStorageList.size(); i++) {
                mServer->addStorage(mStorageList[i]);
            }
        } else {
@@ -247,13 +247,17 @@ android_mtp_MtpServer_add_storage(JNIEnv *env, jobject thiz, jobject jstorage)
        jlong reserveSpace = env->GetLongField(jstorage, field_MtpStorage_reserveSpace);

        const char *pathStr = env->GetStringUTFChars(path, NULL);
        if (pathStr != NULL) {
            const char *descriptionStr = env->GetStringUTFChars(description, NULL);

            if (descriptionStr != NULL) {
                MtpStorage* storage = new MtpStorage(storageID, pathStr, descriptionStr, reserveSpace);
                thread->addStorage(storage);

                env->ReleaseStringUTFChars(path, pathStr);
                env->ReleaseStringUTFChars(description, descriptionStr);
            } else {
                env->ReleaseStringUTFChars(path, pathStr);
            }
        }
    } else {
        LOGE("MtpThread is null in add_storage");
    }