mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
do not throw exceptions from native code: this does not work on some devices
This commit is contained in:
parent
64de74460d
commit
ebe5fc182c
5 changed files with 14 additions and 47 deletions
|
@ -32,11 +32,7 @@
|
||||||
|
|
||||||
static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
|
static shared_ptr<FormatPlugin> findCppPlugin(jobject base) {
|
||||||
const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base);
|
const std::string fileType = AndroidUtil::Method_NativeFormatPlugin_supportedFileType->callForCppString(base);
|
||||||
shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().pluginByType(fileType);
|
return PluginCollection::Instance().pluginByType(fileType);
|
||||||
if (plugin.isNull()) {
|
|
||||||
AndroidUtil::throwRuntimeException("Native FormatPlugin instance is NULL for type " + fileType);
|
|
||||||
}
|
|
||||||
return plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillUids(JNIEnv* env, jobject javaBook, Book &book) {
|
static void fillUids(JNIEnv* env, jobject javaBook, Book &book) {
|
||||||
|
@ -287,7 +283,6 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if (!model->flush()) {
|
if (!model->flush()) {
|
||||||
AndroidUtil::throwCachedCharStorageException("Cannot write file from native code");
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,8 +128,6 @@ shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_addImage;
|
||||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontFamilyList;
|
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontFamilyList;
|
||||||
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontEntry;
|
shared_ptr<VoidMethod> AndroidUtil::Method_NativeBookModel_registerFontEntry;
|
||||||
|
|
||||||
//shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_BookReadingException_throwForFile;
|
|
||||||
|
|
||||||
JNIEnv *AndroidUtil::getEnv() {
|
JNIEnv *AndroidUtil::getEnv() {
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
ourJavaVM->GetEnv((void **)&env, JNI_VERSION_1_2);
|
ourJavaVM->GetEnv((void **)&env, JNI_VERSION_1_2);
|
||||||
|
@ -212,11 +210,6 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
Method_NativeBookModel_registerFontFamilyList = new VoidMethod(Class_NativeBookModel, "registerFontFamilyList", "([Ljava/lang/String;)");
|
Method_NativeBookModel_registerFontFamilyList = new VoidMethod(Class_NativeBookModel, "registerFontFamilyList", "([Ljava/lang/String;)");
|
||||||
Method_NativeBookModel_registerFontEntry = new VoidMethod(Class_NativeBookModel, "registerFontEntry", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;)");
|
Method_NativeBookModel_registerFontEntry = new VoidMethod(Class_NativeBookModel, "registerFontEntry", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;Lorg/geometerplus/zlibrary/core/fonts/FileInfo;)");
|
||||||
|
|
||||||
/*
|
|
||||||
Class_BookReadingException = new JavaClass(env, "org/geometerplus/fbreader/bookmodel/BookReadingException");
|
|
||||||
StaticMethod_BookReadingException_throwForFile = new StaticVoidMethod(Class_BookReadingException, "throwForFile", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;)V") );
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,24 +323,3 @@ jbyteArray AndroidUtil::createJavaByteArray(JNIEnv *env, const std::vector<jbyte
|
||||||
env->SetByteArrayRegion(array, 0, size, &data.front());
|
env->SetByteArrayRegion(array, 0, size, &data.front());
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidUtil::throwRuntimeException(const std::string &message) {
|
|
||||||
getEnv()->ThrowNew(Class_java_lang_RuntimeException.j(), message.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void AndroidUtil::throwCachedCharStorageException(const std::string &message) {
|
|
||||||
getEnv()->ThrowNew(Class_CachedCharStorageException.j(), message.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
void AndroidUtil::throwBookReadingException(const std::string &resourceId, const ZLFile &file) {
|
|
||||||
JNIEnv *env = getEnv();
|
|
||||||
env->CallStaticVoidMethod(
|
|
||||||
StaticMethod_BookReadingException_throwForFile,
|
|
||||||
AndroidUtil::createJavaString(env, resourceId),
|
|
||||||
AndroidUtil::createJavaFile(env, file.path())
|
|
||||||
);
|
|
||||||
// TODO: possible memory leak
|
|
||||||
// TODO: clear ZLFile object reference
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -166,8 +166,6 @@ public:
|
||||||
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontFamilyList;
|
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontFamilyList;
|
||||||
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontEntry;
|
static shared_ptr<VoidMethod> Method_NativeBookModel_registerFontEntry;
|
||||||
|
|
||||||
//static shared_ptr<StaticObjectMethod> StaticMethod_BookReadingException_throwForFile;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool init(JavaVM* jvm);
|
static bool init(JavaVM* jvm);
|
||||||
static JNIEnv *getEnv();
|
static JNIEnv *getEnv();
|
||||||
|
@ -182,10 +180,6 @@ public:
|
||||||
|
|
||||||
static jintArray createJavaIntArray(JNIEnv *env, const std::vector<jint> &data);
|
static jintArray createJavaIntArray(JNIEnv *env, const std::vector<jint> &data);
|
||||||
static jbyteArray createJavaByteArray(JNIEnv *env, const std::vector<jbyte> &data);
|
static jbyteArray createJavaByteArray(JNIEnv *env, const std::vector<jbyte> &data);
|
||||||
|
|
||||||
static void throwRuntimeException(const std::string &message);
|
|
||||||
static void throwCachedCharStorageException(const std::string &message);
|
|
||||||
//static void throwBookReadingException(const std::string &resourceId, const ZLFile &file);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline jstring JString::j() { return myJ; }
|
inline jstring JString::j() { return myJ; }
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.image.*;
|
import org.geometerplus.zlibrary.core.image.*;
|
||||||
|
import org.geometerplus.zlibrary.text.model.CachedCharStorageException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.book.Book;
|
import org.geometerplus.fbreader.book.Book;
|
||||||
import org.geometerplus.fbreader.book.BookUtil;
|
import org.geometerplus.fbreader.book.BookUtil;
|
||||||
|
@ -93,12 +94,17 @@ public class NativeFormatPlugin extends FormatPlugin {
|
||||||
@Override
|
@Override
|
||||||
synchronized public void readModel(BookModel model) throws BookReadingException {
|
synchronized public void readModel(BookModel model) throws BookReadingException {
|
||||||
final int code = readModelNative(model);
|
final int code = readModelNative(model);
|
||||||
if (code != 0) {
|
switch (code) {
|
||||||
throw new BookReadingException(
|
case 0:
|
||||||
"nativeCodeFailure",
|
return;
|
||||||
model.Book.File,
|
case 3:
|
||||||
new String[] { String.valueOf(code), model.Book.File.getPath() }
|
throw new CachedCharStorageException("Cannot write file from native code");
|
||||||
);
|
default:
|
||||||
|
throw new BookReadingException(
|
||||||
|
"nativeCodeFailure",
|
||||||
|
model.Book.File,
|
||||||
|
new String[] { String.valueOf(code), model.Book.File.getPath() }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.text.model;
|
package org.geometerplus.zlibrary.text.model;
|
||||||
|
|
||||||
final class CachedCharStorageException extends RuntimeException {
|
public final class CachedCharStorageException extends RuntimeException {
|
||||||
private static final long serialVersionUID = -6373408730045821053L;
|
private static final long serialVersionUID = -6373408730045821053L;
|
||||||
|
|
||||||
public CachedCharStorageException(String message) {
|
public CachedCharStorageException(String message) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue