unify java
This commit is contained in:
76
packages/myddas/sqlite3/Android/jni/sqlite/ALog-priv.h
Normal file
76
packages/myddas/sqlite3/Android/jni/sqlite/ALog-priv.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
#ifndef NATIVEHELPER_ALOGPRIV_H_
|
||||
#define NATIVEHELPER_ALOGPRIV_H_
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#ifndef LOG_NDEBUG
|
||||
#ifdef NDEBUG
|
||||
#define LOG_NDEBUG 1
|
||||
#else
|
||||
#define LOG_NDEBUG 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Basic log message macros intended to emulate the behavior of log/log.h
|
||||
* in system core. This should be dependent only on ndk exposed logging
|
||||
* functionality.
|
||||
*/
|
||||
|
||||
#ifndef ALOG
|
||||
#define ALOG(priority, tag, fmt...) \
|
||||
__android_log_print(ANDROID_##priority, tag, fmt)
|
||||
#endif
|
||||
|
||||
#ifndef ALOGV
|
||||
#if LOG_NDEBUG
|
||||
#define ALOGV(...) ((void)0)
|
||||
#else
|
||||
#define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ALOGD
|
||||
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGI
|
||||
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGW
|
||||
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
#ifndef ALOGE
|
||||
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Not quite the same as the core android LOG_FATAL_IF (which also
|
||||
** sends a SIGTRAP), but close enough.
|
||||
*/
|
||||
#define LOG_FATAL_IF(bCond, zErr) if( bCond ) ALOGE(zErr);
|
||||
|
||||
#endif
|
44
packages/myddas/sqlite3/Android/jni/sqlite/Android.mk
Normal file
44
packages/myddas/sqlite3/Android/jni/sqlite/Android.mk
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# If using SEE, uncomment the following:
|
||||
# LOCAL_CFLAGS += -DSQLITE_HAS_CODEC
|
||||
|
||||
# This is important - it causes SQLite to use memory for temp files. Since
|
||||
# Android has no globally writable temp directory, if this is not defined the
|
||||
# application throws an exception when it tries to create a temp file.
|
||||
#
|
||||
LOCAL_CFLAGS += -DSQLITE_TEMP_STORE=3
|
||||
|
||||
LOCAL_CFLAGS += -DHAVE_CONFIG_H -DKHTML_NO_EXCEPTIONS -DGKWQ_NO_JAVA
|
||||
LOCAL_CFLAGS += -DNO_SUPPORT_JS_BINDING -DQT_NO_WHEELEVENT -DKHTML_NO_XBL
|
||||
LOCAL_CFLAGS += -U__APPLE__
|
||||
LOCAL_CFLAGS += -DHAVE_STRCHRNUL=0
|
||||
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-int-to-pointer-cast
|
||||
LOCAL_CFLAGS += -Wno-maybe-uninitialized -Wno-parentheses
|
||||
LOCAL_CPPFLAGS += -Wno-conversion-null
|
||||
|
||||
|
||||
ifeq ($(TARGET_ARCH), arm)
|
||||
LOCAL_CFLAGS += -DPACKED="__attribute__ ((packed))"
|
||||
else
|
||||
LOCAL_CFLAGS += -DPACKED=""
|
||||
endif
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
android_database_SQLiteCommon.cpp \
|
||||
android_database_SQLiteConnection.cpp \
|
||||
android_database_SQLiteGlobal.cpp \
|
||||
android_database_SQLiteDebug.cpp \
|
||||
JNIHelp.cpp JniConstants.cpp
|
||||
|
||||
LOCAL_SRC_FILES += sqlite3.c
|
||||
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH) $(LOCAL_PATH)/nativehelper/
|
||||
|
||||
LOCAL_MODULE:= libsqliteX
|
||||
LOCAL_LDLIBS += -ldl -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
341
packages/myddas/sqlite3/Android/jni/sqlite/JNIHelp.cpp
Normal file
341
packages/myddas/sqlite3/Android/jni/sqlite/JNIHelp.cpp
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (C) 2006 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "JNIHelp"
|
||||
|
||||
#include "JniConstants.h"
|
||||
#include "JNIHelp.h"
|
||||
#include "ALog-priv.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* Equivalent to ScopedLocalRef, but for C_JNIEnv instead. (And slightly more powerful.)
|
||||
*/
|
||||
template<typename T>
|
||||
class scoped_local_ref {
|
||||
public:
|
||||
scoped_local_ref(C_JNIEnv* env, T localRef = NULL)
|
||||
: mEnv(env), mLocalRef(localRef)
|
||||
{
|
||||
}
|
||||
|
||||
~scoped_local_ref() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset(T localRef = NULL) {
|
||||
if (mLocalRef != NULL) {
|
||||
(*mEnv)->DeleteLocalRef(reinterpret_cast<JNIEnv*>(mEnv), mLocalRef);
|
||||
mLocalRef = localRef;
|
||||
}
|
||||
}
|
||||
|
||||
T get() const {
|
||||
return mLocalRef;
|
||||
}
|
||||
|
||||
private:
|
||||
C_JNIEnv* mEnv;
|
||||
T mLocalRef;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
scoped_local_ref(const scoped_local_ref&);
|
||||
void operator=(const scoped_local_ref&);
|
||||
};
|
||||
|
||||
static jclass findClass(C_JNIEnv* env, const char* className) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
return (*env)->FindClass(e, className);
|
||||
}
|
||||
|
||||
extern "C" int jniRegisterNativeMethods(C_JNIEnv* env, const char* className,
|
||||
const JNINativeMethod* gMethods, int numMethods)
|
||||
{
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
|
||||
ALOGV("Registering %s's %d native methods...", className, numMethods);
|
||||
|
||||
scoped_local_ref<jclass> c(env, findClass(env, className));
|
||||
if (c.get() == NULL) {
|
||||
char* msg;
|
||||
asprintf(&msg, "Native registration unable to find class '%s'; aborting...", className);
|
||||
e->FatalError(msg);
|
||||
}
|
||||
|
||||
if ((*env)->RegisterNatives(e, c.get(), gMethods, numMethods) < 0) {
|
||||
char* msg;
|
||||
asprintf(&msg, "RegisterNatives failed for '%s'; aborting...", className);
|
||||
e->FatalError(msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a human-readable summary of an exception object. The buffer will
|
||||
* be populated with the "binary" class name and, if present, the
|
||||
* exception message.
|
||||
*/
|
||||
static bool getExceptionSummary(C_JNIEnv* env, jthrowable exception, std::string& result) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
|
||||
/* get the name of the exception's class */
|
||||
scoped_local_ref<jclass> exceptionClass(env, (*env)->GetObjectClass(e, exception)); // can't fail
|
||||
scoped_local_ref<jclass> classClass(env,
|
||||
(*env)->GetObjectClass(e, exceptionClass.get())); // java.lang.Class, can't fail
|
||||
jmethodID classGetNameMethod =
|
||||
(*env)->GetMethodID(e, classClass.get(), "getName", "()Ljava/lang/String;");
|
||||
scoped_local_ref<jstring> classNameStr(env,
|
||||
(jstring) (*env)->CallObjectMethod(e, exceptionClass.get(), classGetNameMethod));
|
||||
if (classNameStr.get() == NULL) {
|
||||
(*env)->ExceptionClear(e);
|
||||
result = "<error getting class name>";
|
||||
return false;
|
||||
}
|
||||
const char* classNameChars = (*env)->GetStringUTFChars(e, classNameStr.get(), NULL);
|
||||
if (classNameChars == NULL) {
|
||||
(*env)->ExceptionClear(e);
|
||||
result = "<error getting class name UTF-8>";
|
||||
return false;
|
||||
}
|
||||
result += classNameChars;
|
||||
(*env)->ReleaseStringUTFChars(e, classNameStr.get(), classNameChars);
|
||||
|
||||
/* if the exception has a detail message, get that */
|
||||
jmethodID getMessage =
|
||||
(*env)->GetMethodID(e, exceptionClass.get(), "getMessage", "()Ljava/lang/String;");
|
||||
scoped_local_ref<jstring> messageStr(env,
|
||||
(jstring) (*env)->CallObjectMethod(e, exception, getMessage));
|
||||
if (messageStr.get() == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
result += ": ";
|
||||
|
||||
const char* messageChars = (*env)->GetStringUTFChars(e, messageStr.get(), NULL);
|
||||
if (messageChars != NULL) {
|
||||
result += messageChars;
|
||||
(*env)->ReleaseStringUTFChars(e, messageStr.get(), messageChars);
|
||||
} else {
|
||||
result += "<error getting message>";
|
||||
(*env)->ExceptionClear(e); // clear OOM
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an exception (with stack trace) as a string.
|
||||
*/
|
||||
static bool getStackTrace(C_JNIEnv* env, jthrowable exception, std::string& result) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
|
||||
scoped_local_ref<jclass> stringWriterClass(env, findClass(env, "java/io/StringWriter"));
|
||||
if (stringWriterClass.get() == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jmethodID stringWriterCtor = (*env)->GetMethodID(e, stringWriterClass.get(), "<init>", "()V");
|
||||
jmethodID stringWriterToStringMethod =
|
||||
(*env)->GetMethodID(e, stringWriterClass.get(), "toString", "()Ljava/lang/String;");
|
||||
|
||||
scoped_local_ref<jclass> printWriterClass(env, findClass(env, "java/io/PrintWriter"));
|
||||
if (printWriterClass.get() == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jmethodID printWriterCtor =
|
||||
(*env)->GetMethodID(e, printWriterClass.get(), "<init>", "(Ljava/io/Writer;)V");
|
||||
|
||||
scoped_local_ref<jobject> stringWriter(env,
|
||||
(*env)->NewObject(e, stringWriterClass.get(), stringWriterCtor));
|
||||
if (stringWriter.get() == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
jobject printWriter =
|
||||
(*env)->NewObject(e, printWriterClass.get(), printWriterCtor, stringWriter.get());
|
||||
if (printWriter == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
scoped_local_ref<jclass> exceptionClass(env, (*env)->GetObjectClass(e, exception)); // can't fail
|
||||
jmethodID printStackTraceMethod =
|
||||
(*env)->GetMethodID(e, exceptionClass.get(), "printStackTrace", "(Ljava/io/PrintWriter;)V");
|
||||
(*env)->CallVoidMethod(e, exception, printStackTraceMethod, printWriter);
|
||||
|
||||
if ((*env)->ExceptionCheck(e)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
scoped_local_ref<jstring> messageStr(env,
|
||||
(jstring) (*env)->CallObjectMethod(e, stringWriter.get(), stringWriterToStringMethod));
|
||||
if (messageStr.get() == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* utfChars = (*env)->GetStringUTFChars(e, messageStr.get(), NULL);
|
||||
if (utfChars == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result = utfChars;
|
||||
|
||||
(*env)->ReleaseStringUTFChars(e, messageStr.get(), utfChars);
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" int jniThrowException(C_JNIEnv* env, const char* className, const char* msg) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
|
||||
if ((*env)->ExceptionCheck(e)) {
|
||||
/* TODO: consider creating the new exception with this as "cause" */
|
||||
scoped_local_ref<jthrowable> exception(env, (*env)->ExceptionOccurred(e));
|
||||
(*env)->ExceptionClear(e);
|
||||
|
||||
if (exception.get() != NULL) {
|
||||
std::string text;
|
||||
getExceptionSummary(env, exception.get(), text);
|
||||
ALOGW("Discarding pending exception (%s) to throw %s", text.c_str(), className);
|
||||
}
|
||||
}
|
||||
|
||||
scoped_local_ref<jclass> exceptionClass(env, findClass(env, className));
|
||||
if (exceptionClass.get() == NULL) {
|
||||
ALOGE("Unable to find exception class %s", className);
|
||||
/* ClassNotFoundException now pending */
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*env)->ThrowNew(e, exceptionClass.get(), msg) != JNI_OK) {
|
||||
ALOGE("Failed throwing '%s' '%s'", className, msg);
|
||||
/* an exception, most likely OOM, will now be pending */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args) {
|
||||
char msgBuf[512];
|
||||
vsnprintf(msgBuf, sizeof(msgBuf), fmt, args);
|
||||
return jniThrowException(env, className, msgBuf);
|
||||
}
|
||||
|
||||
int jniThrowNullPointerException(C_JNIEnv* env, const char* msg) {
|
||||
return jniThrowException(env, "java/lang/NullPointerException", msg);
|
||||
}
|
||||
|
||||
int jniThrowRuntimeException(C_JNIEnv* env, const char* msg) {
|
||||
return jniThrowException(env, "java/lang/RuntimeException", msg);
|
||||
}
|
||||
|
||||
int jniThrowIOException(C_JNIEnv* env, int errnum) {
|
||||
char buffer[80];
|
||||
const char* message = jniStrError(errnum, buffer, sizeof(buffer));
|
||||
return jniThrowException(env, "java/io/IOException", message);
|
||||
}
|
||||
|
||||
static std::string jniGetStackTrace(C_JNIEnv* env, jthrowable exception) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
|
||||
scoped_local_ref<jthrowable> currentException(env, (*env)->ExceptionOccurred(e));
|
||||
if (exception == NULL) {
|
||||
exception = currentException.get();
|
||||
if (exception == NULL) {
|
||||
return "<no pending exception>";
|
||||
}
|
||||
}
|
||||
|
||||
if (currentException.get() != NULL) {
|
||||
(*env)->ExceptionClear(e);
|
||||
}
|
||||
|
||||
std::string trace;
|
||||
if (!getStackTrace(env, exception, trace)) {
|
||||
(*env)->ExceptionClear(e);
|
||||
getExceptionSummary(env, exception, trace);
|
||||
}
|
||||
|
||||
if (currentException.get() != NULL) {
|
||||
(*env)->Throw(e, currentException.get()); // rethrow
|
||||
}
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
||||
void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception) {
|
||||
std::string trace(jniGetStackTrace(env, exception));
|
||||
__android_log_write(priority, tag, trace.c_str());
|
||||
}
|
||||
|
||||
const char* jniStrError(int errnum, char* buf, size_t buflen) {
|
||||
#if __GLIBC__
|
||||
// Note: glibc has a nonstandard strerror_r that returns char* rather than POSIX's int.
|
||||
// char *strerror_r(int errnum, char *buf, size_t n);
|
||||
return strerror_r(errnum, buf, buflen);
|
||||
#else
|
||||
int rc = strerror_r(errnum, buf, buflen);
|
||||
if (rc != 0) {
|
||||
// (POSIX only guarantees a value other than 0. The safest
|
||||
// way to implement this function is to use C++ and overload on the
|
||||
// type of strerror_r to accurately distinguish GNU from POSIX.)
|
||||
snprintf(buf, buflen, "errno %d", errnum);
|
||||
}
|
||||
return buf;
|
||||
#endif
|
||||
}
|
||||
|
||||
jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
static jmethodID ctor = e->GetMethodID(JniConstants::fileDescriptorClass, "<init>", "()V");
|
||||
jobject fileDescriptor = (*env)->NewObject(e, JniConstants::fileDescriptorClass, ctor);
|
||||
// NOTE: NewObject ensures that an OutOfMemoryError will be seen by the Java
|
||||
// caller if the alloc fails, so we just return NULL when that happens.
|
||||
if (fileDescriptor != NULL) {
|
||||
jniSetFileDescriptorOfFD(env, fileDescriptor, fd);
|
||||
}
|
||||
return fileDescriptor;
|
||||
}
|
||||
|
||||
int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
static jfieldID fid = e->GetFieldID(JniConstants::fileDescriptorClass, "descriptor", "I");
|
||||
if (fileDescriptor != NULL) {
|
||||
return (*env)->GetIntField(e, fileDescriptor, fid);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
static jfieldID fid = e->GetFieldID(JniConstants::fileDescriptorClass, "descriptor", "I");
|
||||
(*env)->SetIntField(e, fileDescriptor, fid, value);
|
||||
}
|
||||
|
||||
jobject jniGetReferent(C_JNIEnv* env, jobject ref) {
|
||||
JNIEnv* e = reinterpret_cast<JNIEnv*>(env);
|
||||
static jmethodID get = e->GetMethodID(JniConstants::referenceClass, "get", "()Ljava/lang/Object;");
|
||||
return (*env)->CallObjectMethod(e, ref, get);
|
||||
}
|
||||
|
139
packages/myddas/sqlite3/Android/jni/sqlite/JniConstants.cpp
Normal file
139
packages/myddas/sqlite3/Android/jni/sqlite/JniConstants.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "JniConstants"
|
||||
|
||||
#include "ALog-priv.h"
|
||||
#include "JniConstants.h"
|
||||
#include "ScopedLocalRef.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
jclass JniConstants::bidiRunClass;
|
||||
jclass JniConstants::bigDecimalClass;
|
||||
jclass JniConstants::booleanClass;
|
||||
jclass JniConstants::byteArrayClass;
|
||||
jclass JniConstants::byteClass;
|
||||
jclass JniConstants::calendarClass;
|
||||
jclass JniConstants::characterClass;
|
||||
jclass JniConstants::charsetICUClass;
|
||||
jclass JniConstants::constructorClass;
|
||||
jclass JniConstants::deflaterClass;
|
||||
jclass JniConstants::doubleClass;
|
||||
jclass JniConstants::errnoExceptionClass;
|
||||
jclass JniConstants::fieldClass;
|
||||
jclass JniConstants::fieldPositionIteratorClass;
|
||||
jclass JniConstants::fileDescriptorClass;
|
||||
jclass JniConstants::floatClass;
|
||||
jclass JniConstants::gaiExceptionClass;
|
||||
jclass JniConstants::inet6AddressClass;
|
||||
jclass JniConstants::inetAddressClass;
|
||||
jclass JniConstants::inetSocketAddressClass;
|
||||
jclass JniConstants::inetUnixAddressClass;
|
||||
jclass JniConstants::inflaterClass;
|
||||
jclass JniConstants::inputStreamClass;
|
||||
jclass JniConstants::integerClass;
|
||||
jclass JniConstants::localeDataClass;
|
||||
jclass JniConstants::longClass;
|
||||
jclass JniConstants::methodClass;
|
||||
jclass JniConstants::mutableIntClass;
|
||||
jclass JniConstants::mutableLongClass;
|
||||
jclass JniConstants::objectClass;
|
||||
jclass JniConstants::objectArrayClass;
|
||||
jclass JniConstants::outputStreamClass;
|
||||
jclass JniConstants::parsePositionClass;
|
||||
jclass JniConstants::patternSyntaxExceptionClass;
|
||||
jclass JniConstants::realToStringClass;
|
||||
jclass JniConstants::referenceClass;
|
||||
jclass JniConstants::shortClass;
|
||||
jclass JniConstants::socketClass;
|
||||
jclass JniConstants::socketImplClass;
|
||||
jclass JniConstants::stringClass;
|
||||
jclass JniConstants::structAddrinfoClass;
|
||||
jclass JniConstants::structFlockClass;
|
||||
jclass JniConstants::structGroupReqClass;
|
||||
jclass JniConstants::structLingerClass;
|
||||
jclass JniConstants::structPasswdClass;
|
||||
jclass JniConstants::structPollfdClass;
|
||||
jclass JniConstants::structStatClass;
|
||||
jclass JniConstants::structStatVfsClass;
|
||||
jclass JniConstants::structTimevalClass;
|
||||
jclass JniConstants::structUcredClass;
|
||||
jclass JniConstants::structUtsnameClass;
|
||||
|
||||
static jclass findClass(JNIEnv* env, const char* name) {
|
||||
ScopedLocalRef<jclass> localClass(env, env->FindClass(name));
|
||||
jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(localClass.get()));
|
||||
if (result == NULL) {
|
||||
ALOGE("failed to find class '%s'", name);
|
||||
abort();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void JniConstants::init(JNIEnv* env) {
|
||||
bidiRunClass = findClass(env, "java/text/Bidi$Run");
|
||||
bigDecimalClass = findClass(env, "java/math/BigDecimal");
|
||||
booleanClass = findClass(env, "java/lang/Boolean");
|
||||
byteClass = findClass(env, "java/lang/Byte");
|
||||
byteArrayClass = findClass(env, "[B");
|
||||
calendarClass = findClass(env, "java/util/Calendar");
|
||||
characterClass = findClass(env, "java/lang/Character");
|
||||
charsetICUClass = findClass(env, "java/nio/charset/CharsetICU");
|
||||
constructorClass = findClass(env, "java/lang/reflect/Constructor");
|
||||
floatClass = findClass(env, "java/lang/Float");
|
||||
deflaterClass = findClass(env, "java/util/zip/Deflater");
|
||||
doubleClass = findClass(env, "java/lang/Double");
|
||||
errnoExceptionClass = findClass(env, "libcore/io/ErrnoException");
|
||||
fieldClass = findClass(env, "java/lang/reflect/Field");
|
||||
fieldPositionIteratorClass = findClass(env, "libcore/icu/NativeDecimalFormat$FieldPositionIterator");
|
||||
fileDescriptorClass = findClass(env, "java/io/FileDescriptor");
|
||||
gaiExceptionClass = findClass(env, "libcore/io/GaiException");
|
||||
inet6AddressClass = findClass(env, "java/net/Inet6Address");
|
||||
inetAddressClass = findClass(env, "java/net/InetAddress");
|
||||
inetSocketAddressClass = findClass(env, "java/net/InetSocketAddress");
|
||||
inetUnixAddressClass = findClass(env, "java/net/InetUnixAddress");
|
||||
inflaterClass = findClass(env, "java/util/zip/Inflater");
|
||||
inputStreamClass = findClass(env, "java/io/InputStream");
|
||||
integerClass = findClass(env, "java/lang/Integer");
|
||||
localeDataClass = findClass(env, "libcore/icu/LocaleData");
|
||||
longClass = findClass(env, "java/lang/Long");
|
||||
methodClass = findClass(env, "java/lang/reflect/Method");
|
||||
mutableIntClass = findClass(env, "libcore/util/MutableInt");
|
||||
mutableLongClass = findClass(env, "libcore/util/MutableLong");
|
||||
objectClass = findClass(env, "java/lang/Object");
|
||||
objectArrayClass = findClass(env, "[Ljava/lang/Object;");
|
||||
outputStreamClass = findClass(env, "java/io/OutputStream");
|
||||
parsePositionClass = findClass(env, "java/text/ParsePosition");
|
||||
patternSyntaxExceptionClass = findClass(env, "java/util/regex/PatternSyntaxException");
|
||||
realToStringClass = findClass(env, "java/lang/RealToString");
|
||||
referenceClass = findClass(env, "java/lang/ref/Reference");
|
||||
shortClass = findClass(env, "java/lang/Short");
|
||||
socketClass = findClass(env, "java/net/Socket");
|
||||
socketImplClass = findClass(env, "java/net/SocketImpl");
|
||||
stringClass = findClass(env, "java/lang/String");
|
||||
structAddrinfoClass = findClass(env, "libcore/io/StructAddrinfo");
|
||||
structFlockClass = findClass(env, "libcore/io/StructFlock");
|
||||
structGroupReqClass = findClass(env, "libcore/io/StructGroupReq");
|
||||
structLingerClass = findClass(env, "libcore/io/StructLinger");
|
||||
structPasswdClass = findClass(env, "libcore/io/StructPasswd");
|
||||
structPollfdClass = findClass(env, "libcore/io/StructPollfd");
|
||||
structStatClass = findClass(env, "libcore/io/StructStat");
|
||||
structStatVfsClass = findClass(env, "libcore/io/StructStatVfs");
|
||||
structTimevalClass = findClass(env, "libcore/io/StructTimeval");
|
||||
structUcredClass = findClass(env, "libcore/io/StructUcred");
|
||||
structUtsnameClass = findClass(env, "libcore/io/StructUtsname");
|
||||
}
|
40
packages/myddas/sqlite3/Android/jni/sqlite/README
Normal file
40
packages/myddas/sqlite3/Android/jni/sqlite/README
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
All the files in this directory are copied from stock android. The following
|
||||
files:
|
||||
|
||||
JniConstants.cpp
|
||||
JNIHelp.cpp
|
||||
ALog-priv.h
|
||||
|
||||
are copied in from Android's libnativehelper module (altogether less than 1000
|
||||
lines of code). The remainder are from the core framework (directory
|
||||
/frameworks/base/core/jni).
|
||||
|
||||
Notes on changes:
|
||||
|
||||
The ashmem_XXX() interfaces are used for the various "xxxForBlobDescriptor()"
|
||||
API functions. The code in libcutils for this seems to be platform
|
||||
dependent - some platforms have kernel support, others have a user space
|
||||
implementation. So these functions are not supported for now.
|
||||
|
||||
The original SQLiteConnection.cpp uses AndroidRuntime::genJNIEnv() to obtain a
|
||||
pointer to the current threads environment. Changed to store a pointer to the
|
||||
process JavaVM (Android allows only one) as a global variable. Then retrieve
|
||||
the JNIEnv as needed using GetEnv().
|
||||
|
||||
Replaced uses of class String8 with std::string in SQLiteConnection.cpp and a
|
||||
few other places.
|
||||
|
||||
The stock Android code to populate CursorWindow containers with the results of
|
||||
a SELECT statement uses a C++ interface that is not available to NDK builds. So
|
||||
this code is rewritten to call the CursorWindow java interface via JNI methods.
|
||||
This is the largest source code change. See function
|
||||
nativeExecuteForCursorWindow() in file android_database_SQLiteConnection.cpp
|
||||
for details.
|
||||
|
||||
The "LOCALIZED" collation and some miscellaneous user-functions added by the
|
||||
sqlite3_android.cpp module are not included. A collation called LOCALIZED
|
||||
that is equivalent to BINARY is added instead to keep various things working.
|
||||
This should not cause serious problems - class SQLiteConnection always
|
||||
runs "REINDEX LOCALIZED" immediately after opening a connection.
|
||||
|
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
#include "android_database_SQLiteCommon.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
/* throw a SQLiteException with a message appropriate for the error in handle */
|
||||
void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle) {
|
||||
throw_sqlite3_exception(env, handle, NULL);
|
||||
}
|
||||
|
||||
/* throw a SQLiteException with the given message */
|
||||
void throw_sqlite3_exception(JNIEnv* env, const char* message) {
|
||||
throw_sqlite3_exception(env, NULL, message);
|
||||
}
|
||||
|
||||
/* throw a SQLiteException with a message appropriate for the error in handle
|
||||
concatenated with the given message
|
||||
*/
|
||||
void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message) {
|
||||
if (handle) {
|
||||
// get the error code and message from the SQLite connection
|
||||
// the error message may contain more information than the error code
|
||||
// because it is based on the extended error code rather than the simplified
|
||||
// error code that SQLite normally returns.
|
||||
throw_sqlite3_exception(env, sqlite3_extended_errcode(handle),
|
||||
sqlite3_errmsg(handle), message);
|
||||
} else {
|
||||
// we use SQLITE_OK so that a generic SQLiteException is thrown;
|
||||
// any code not specified in the switch statement below would do.
|
||||
throw_sqlite3_exception(env, SQLITE_OK, "unknown error", message);
|
||||
}
|
||||
}
|
||||
|
||||
/* throw a SQLiteException for a given error code
|
||||
* should only be used when the database connection is not available because the
|
||||
* error information will not be quite as rich */
|
||||
void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* message) {
|
||||
throw_sqlite3_exception(env, errcode, "unknown error", message);
|
||||
}
|
||||
|
||||
/* throw a SQLiteException for a given error code, sqlite3message, and
|
||||
user message
|
||||
*/
|
||||
void throw_sqlite3_exception(JNIEnv* env, int errcode,
|
||||
const char* sqlite3Message, const char* message) {
|
||||
const char* exceptionClass;
|
||||
switch (errcode & 0xff) { /* mask off extended error code */
|
||||
case SQLITE_IOERR:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteDiskIOException";
|
||||
break;
|
||||
case SQLITE_CORRUPT:
|
||||
case SQLITE_NOTADB: // treat "unsupported file format" error as corruption also
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteDatabaseCorruptException";
|
||||
break;
|
||||
case SQLITE_CONSTRAINT:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteConstraintException";
|
||||
break;
|
||||
case SQLITE_ABORT:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteAbortException";
|
||||
break;
|
||||
case SQLITE_DONE:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteDoneException";
|
||||
sqlite3Message = NULL; // SQLite error message is irrelevant in this case
|
||||
break;
|
||||
case SQLITE_FULL:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteFullException";
|
||||
break;
|
||||
case SQLITE_MISUSE:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteMisuseException";
|
||||
break;
|
||||
case SQLITE_PERM:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteAccessPermException";
|
||||
break;
|
||||
case SQLITE_BUSY:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteDatabaseLockedException";
|
||||
break;
|
||||
case SQLITE_LOCKED:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteTableLockedException";
|
||||
break;
|
||||
case SQLITE_READONLY:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteReadOnlyDatabaseException";
|
||||
break;
|
||||
case SQLITE_CANTOPEN:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteCantOpenDatabaseException";
|
||||
break;
|
||||
case SQLITE_TOOBIG:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteBlobTooBigException";
|
||||
break;
|
||||
case SQLITE_RANGE:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException";
|
||||
break;
|
||||
case SQLITE_NOMEM:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteOutOfMemoryException";
|
||||
break;
|
||||
case SQLITE_MISMATCH:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteDatatypeMismatchException";
|
||||
break;
|
||||
case SQLITE_INTERRUPT:
|
||||
exceptionClass = "android/os/OperationCanceledException";
|
||||
break;
|
||||
default:
|
||||
exceptionClass = "org/sqlite/database/sqlite/SQLiteException";
|
||||
break;
|
||||
}
|
||||
|
||||
if (sqlite3Message) {
|
||||
char *zFullmsg = sqlite3_mprintf(
|
||||
"%s (code %d)%s%s", sqlite3Message, errcode,
|
||||
(message ? ": " : ""), (message ? message : "")
|
||||
);
|
||||
jniThrowException(env, exceptionClass, zFullmsg);
|
||||
sqlite3_free(zFullmsg);
|
||||
} else {
|
||||
jniThrowException(env, exceptionClass, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace android
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_DATABASE_SQLITE_COMMON_H
|
||||
#define _ANDROID_DATABASE_SQLITE_COMMON_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <JNIHelp.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
// Special log tags defined in SQLiteDebug.java.
|
||||
#define SQLITE_LOG_TAG "SQLiteLog"
|
||||
#define SQLITE_TRACE_TAG "SQLiteStatements"
|
||||
#define SQLITE_PROFILE_TAG "SQLiteTime"
|
||||
|
||||
namespace android {
|
||||
|
||||
/* throw a SQLiteException with a message appropriate for the error in handle */
|
||||
void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle);
|
||||
|
||||
/* throw a SQLiteException with the given message */
|
||||
void throw_sqlite3_exception(JNIEnv* env, const char* message);
|
||||
|
||||
/* throw a SQLiteException with a message appropriate for the error in handle
|
||||
concatenated with the given message
|
||||
*/
|
||||
void throw_sqlite3_exception(JNIEnv* env, sqlite3* handle, const char* message);
|
||||
|
||||
/* throw a SQLiteException for a given error code */
|
||||
void throw_sqlite3_exception_errcode(JNIEnv* env, int errcode, const char* message);
|
||||
|
||||
void throw_sqlite3_exception(JNIEnv* env, int errcode,
|
||||
const char* sqlite3Message, const char* message);
|
||||
|
||||
}
|
||||
|
||||
#endif // _ANDROID_DATABASE_SQLITE_COMMON_H
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "SQLiteDebug"
|
||||
|
||||
#include <jni.h>
|
||||
#include <JNIHelp.h>
|
||||
#include <ALog-priv.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
static struct {
|
||||
jfieldID memoryUsed;
|
||||
jfieldID pageCacheOverflow;
|
||||
jfieldID largestMemAlloc;
|
||||
} gSQLiteDebugPagerStatsClassInfo;
|
||||
|
||||
static void nativeGetPagerStats(JNIEnv *env, jobject clazz, jobject statsObj)
|
||||
{
|
||||
int memoryUsed;
|
||||
int pageCacheOverflow;
|
||||
int largestMemAlloc;
|
||||
int unused;
|
||||
|
||||
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0);
|
||||
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0);
|
||||
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0);
|
||||
env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.memoryUsed, memoryUsed);
|
||||
env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow,
|
||||
pageCacheOverflow);
|
||||
env->SetIntField(statsObj, gSQLiteDebugPagerStatsClassInfo.largestMemAlloc, largestMemAlloc);
|
||||
}
|
||||
|
||||
/*
|
||||
* JNI registration.
|
||||
*/
|
||||
|
||||
static JNINativeMethod gMethods[] =
|
||||
{
|
||||
{ "nativeGetPagerStats", "(Lorg/sqlite/database/sqlite/SQLiteDebug$PagerStats;)V",
|
||||
(void*) nativeGetPagerStats },
|
||||
};
|
||||
|
||||
#define FIND_CLASS(var, className) \
|
||||
var = env->FindClass(className); \
|
||||
LOG_FATAL_IF(! var, "Unable to find class " className);
|
||||
|
||||
#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
|
||||
var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
|
||||
LOG_FATAL_IF(! var, "Unable to find field " fieldName);
|
||||
|
||||
int register_android_database_SQLiteDebug(JNIEnv *env)
|
||||
{
|
||||
jclass clazz;
|
||||
FIND_CLASS(clazz, "org/sqlite/database/sqlite/SQLiteDebug$PagerStats");
|
||||
|
||||
GET_FIELD_ID(gSQLiteDebugPagerStatsClassInfo.memoryUsed, clazz,
|
||||
"memoryUsed", "I");
|
||||
GET_FIELD_ID(gSQLiteDebugPagerStatsClassInfo.largestMemAlloc, clazz,
|
||||
"largestMemAlloc", "I");
|
||||
GET_FIELD_ID(gSQLiteDebugPagerStatsClassInfo.pageCacheOverflow, clazz,
|
||||
"pageCacheOverflow", "I");
|
||||
|
||||
return jniRegisterNativeMethods(env, "org/sqlite/database/sqlite/SQLiteDebug",
|
||||
gMethods, NELEM(gMethods));
|
||||
}
|
||||
|
||||
} // namespace android
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "SQLiteGlobal"
|
||||
|
||||
#include <jni.h>
|
||||
#include <JNIHelp.h>
|
||||
#include "ALog-priv.h"
|
||||
|
||||
|
||||
#include <sqlite3.h>
|
||||
#if 0
|
||||
#include <sqlite3_android.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "android_database_SQLiteCommon.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
// Limit heap to 8MB for now. This is 4 times the maximum cursor window
|
||||
// size, as has been used by the original code in SQLiteDatabase for
|
||||
// a long time.
|
||||
static const int SOFT_HEAP_LIMIT = 8 * 1024 * 1024;
|
||||
|
||||
|
||||
// Called each time a message is logged.
|
||||
static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) {
|
||||
bool verboseLog = !!data;
|
||||
if (iErrCode == 0 || iErrCode == SQLITE_CONSTRAINT || iErrCode == SQLITE_SCHEMA) {
|
||||
if (verboseLog) {
|
||||
ALOG(LOG_VERBOSE, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg);
|
||||
}
|
||||
} else {
|
||||
ALOG(LOG_ERROR, SQLITE_LOG_TAG, "(%d) %s\n", iErrCode, zMsg);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the global SQLite configuration.
|
||||
// This must be called before any other SQLite functions are called.
|
||||
static void sqliteInitialize() {
|
||||
// Enable multi-threaded mode. In this mode, SQLite is safe to use by multiple
|
||||
// threads as long as no two threads use the same database connection at the same
|
||||
// time (which we guarantee in the SQLite database wrappers).
|
||||
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
|
||||
|
||||
// Redirect SQLite log messages to the Android log.
|
||||
#if 0
|
||||
bool verboseLog = android_util_Log_isVerboseLogEnabled(SQLITE_LOG_TAG);
|
||||
#endif
|
||||
bool verboseLog = false;
|
||||
sqlite3_config(SQLITE_CONFIG_LOG, &sqliteLogCallback, verboseLog ? (void*)1 : NULL);
|
||||
|
||||
// The soft heap limit prevents the page cache allocations from growing
|
||||
// beyond the given limit, no matter what the max page cache sizes are
|
||||
// set to. The limit does not, as of 3.5.0, affect any other allocations.
|
||||
sqlite3_soft_heap_limit(SOFT_HEAP_LIMIT);
|
||||
|
||||
// Initialize SQLite.
|
||||
sqlite3_initialize();
|
||||
}
|
||||
|
||||
static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) {
|
||||
return sqlite3_release_memory(SOFT_HEAP_LIMIT);
|
||||
}
|
||||
|
||||
static JNINativeMethod sMethods[] =
|
||||
{
|
||||
/* name, signature, funcPtr */
|
||||
{ "nativeReleaseMemory", "()I",
|
||||
(void*)nativeReleaseMemory },
|
||||
};
|
||||
|
||||
int register_android_database_SQLiteGlobal(JNIEnv *env)
|
||||
{
|
||||
sqliteInitialize();
|
||||
|
||||
return jniRegisterNativeMethods(env, "org/sqlite/database/sqlite/SQLiteGlobal",
|
||||
sMethods, NELEM(sMethods));
|
||||
}
|
||||
|
||||
} // namespace android
|
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* JNI helper functions.
|
||||
*
|
||||
* This file may be included by C or C++ code, which is trouble because jni.h
|
||||
* uses different typedefs for JNIEnv in each language.
|
||||
*
|
||||
* TODO: remove C support.
|
||||
*/
|
||||
#ifndef NATIVEHELPER_JNIHELP_H_
|
||||
#define NATIVEHELPER_JNIHELP_H_
|
||||
|
||||
#include "jni.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef NELEM
|
||||
# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Register one or more native methods with a particular class.
|
||||
* "className" looks like "java/lang/String". Aborts on failure.
|
||||
* TODO: fix all callers and change the return type to void.
|
||||
*/
|
||||
int jniRegisterNativeMethods(C_JNIEnv* env, const char* className, const JNINativeMethod* gMethods, int numMethods);
|
||||
|
||||
/*
|
||||
* Throw an exception with the specified class and an optional message.
|
||||
*
|
||||
* The "className" argument will be passed directly to FindClass, which
|
||||
* takes strings with slashes (e.g. "java/lang/Object").
|
||||
*
|
||||
* If an exception is currently pending, we log a warning message and
|
||||
* clear it.
|
||||
*
|
||||
* Returns 0 on success, nonzero if something failed (e.g. the exception
|
||||
* class couldn't be found, so *an* exception will still be pending).
|
||||
*
|
||||
* Currently aborts the VM if it can't throw the exception.
|
||||
*/
|
||||
int jniThrowException(C_JNIEnv* env, const char* className, const char* msg);
|
||||
|
||||
/*
|
||||
* Throw a java.lang.NullPointerException, with an optional message.
|
||||
*/
|
||||
int jniThrowNullPointerException(C_JNIEnv* env, const char* msg);
|
||||
|
||||
/*
|
||||
* Throw a java.lang.RuntimeException, with an optional message.
|
||||
*/
|
||||
int jniThrowRuntimeException(C_JNIEnv* env, const char* msg);
|
||||
|
||||
/*
|
||||
* Throw a java.io.IOException, generating the message from errno.
|
||||
*/
|
||||
int jniThrowIOException(C_JNIEnv* env, int errnum);
|
||||
|
||||
/*
|
||||
* Return a pointer to a locale-dependent error string explaining errno
|
||||
* value 'errnum'. The returned pointer may or may not be equal to 'buf'.
|
||||
* This function is thread-safe (unlike strerror) and portable (unlike
|
||||
* strerror_r).
|
||||
*/
|
||||
const char* jniStrError(int errnum, char* buf, size_t buflen);
|
||||
|
||||
/*
|
||||
* Returns a new java.io.FileDescriptor for the given int fd.
|
||||
*/
|
||||
jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd);
|
||||
|
||||
/*
|
||||
* Returns the int fd from a java.io.FileDescriptor.
|
||||
*/
|
||||
int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor);
|
||||
|
||||
/*
|
||||
* Sets the int fd in a java.io.FileDescriptor.
|
||||
*/
|
||||
void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value);
|
||||
|
||||
/*
|
||||
* Returns the reference from a java.lang.ref.Reference.
|
||||
*/
|
||||
jobject jniGetReferent(C_JNIEnv* env, jobject ref);
|
||||
|
||||
/*
|
||||
* Log a message and an exception.
|
||||
* If exception is NULL, logs the current exception in the JNI environment.
|
||||
*/
|
||||
void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* For C++ code, we provide inlines that map to the C functions. g++ always
|
||||
* inlines these, even on non-optimized builds.
|
||||
*/
|
||||
#if defined(__cplusplus)
|
||||
inline int jniRegisterNativeMethods(JNIEnv* env, const char* className, const JNINativeMethod* gMethods, int numMethods) {
|
||||
return jniRegisterNativeMethods(&env->functions, className, gMethods, numMethods);
|
||||
}
|
||||
|
||||
inline int jniThrowException(JNIEnv* env, const char* className, const char* msg) {
|
||||
return jniThrowException(&env->functions, className, msg);
|
||||
}
|
||||
|
||||
extern "C" int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args);
|
||||
|
||||
/*
|
||||
* Equivalent to jniThrowException but with a printf-like format string and
|
||||
* variable-length argument list. This is only available in C++.
|
||||
*/
|
||||
inline int jniThrowExceptionFmt(JNIEnv* env, const char* className, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
return jniThrowExceptionFmt(&env->functions, className, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
inline int jniThrowNullPointerException(JNIEnv* env, const char* msg) {
|
||||
return jniThrowNullPointerException(&env->functions, msg);
|
||||
}
|
||||
|
||||
inline int jniThrowRuntimeException(JNIEnv* env, const char* msg) {
|
||||
return jniThrowRuntimeException(&env->functions, msg);
|
||||
}
|
||||
|
||||
inline int jniThrowIOException(JNIEnv* env, int errnum) {
|
||||
return jniThrowIOException(&env->functions, errnum);
|
||||
}
|
||||
|
||||
inline jobject jniCreateFileDescriptor(JNIEnv* env, int fd) {
|
||||
return jniCreateFileDescriptor(&env->functions, fd);
|
||||
}
|
||||
|
||||
inline int jniGetFDFromFileDescriptor(JNIEnv* env, jobject fileDescriptor) {
|
||||
return jniGetFDFromFileDescriptor(&env->functions, fileDescriptor);
|
||||
}
|
||||
|
||||
inline void jniSetFileDescriptorOfFD(JNIEnv* env, jobject fileDescriptor, int value) {
|
||||
jniSetFileDescriptorOfFD(&env->functions, fileDescriptor, value);
|
||||
}
|
||||
|
||||
inline jobject jniGetReferent(JNIEnv* env, jobject ref) {
|
||||
return jniGetReferent(&env->functions, ref);
|
||||
}
|
||||
|
||||
inline void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowable exception = NULL) {
|
||||
jniLogException(&env->functions, priority, tag, exception);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TEMP_FAILURE_RETRY is defined by some, but not all, versions of
|
||||
* <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
|
||||
* not already defined, then define it here.
|
||||
*/
|
||||
#ifndef TEMP_FAILURE_RETRY
|
||||
/* Used to retry syscalls that can return EINTR. */
|
||||
#define TEMP_FAILURE_RETRY(exp) ({ \
|
||||
typeof (exp) _rc; \
|
||||
do { \
|
||||
_rc = (exp); \
|
||||
} while (_rc == -1 && errno == EINTR); \
|
||||
_rc; })
|
||||
#endif
|
||||
|
||||
#endif /* NATIVEHELPER_JNIHELP_H_ */
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef JNI_CONSTANTS_H_included
|
||||
#define JNI_CONSTANTS_H_included
|
||||
|
||||
#include "JNIHelp.h"
|
||||
|
||||
/**
|
||||
* A cache to avoid calling FindClass at runtime.
|
||||
*
|
||||
* Class lookup is relatively expensive (2.5us on passion-eng at the time of writing), so we do
|
||||
* all such lookups eagerly at startup. This means that code that never uses, say,
|
||||
* java.util.zip.Deflater still has to pay for the lookup, but it means that on a device the cost
|
||||
* is definitely paid during boot and amortized. A central cache also removes the temptation to
|
||||
* dynamically call FindClass rather than add a small cache to each file that needs one. Another
|
||||
* cost is that each class cached here requires a global reference, though in practice we save
|
||||
* enough by not having a global reference for each file that uses a class such as java.lang.String
|
||||
* which is used in several files.
|
||||
*
|
||||
* FindClass is still called in a couple of situations: when throwing exceptions, and in some of
|
||||
* the serialization code. The former is clearly not a performance case, and we're currently
|
||||
* assuming that neither is the latter.
|
||||
*
|
||||
* TODO: similar arguments hold for field and method IDs; we should cache them centrally too.
|
||||
*/
|
||||
struct JniConstants {
|
||||
static void init(JNIEnv* env);
|
||||
|
||||
static jclass bidiRunClass;
|
||||
static jclass bigDecimalClass;
|
||||
static jclass booleanClass;
|
||||
static jclass byteArrayClass;
|
||||
static jclass byteClass;
|
||||
static jclass calendarClass;
|
||||
static jclass characterClass;
|
||||
static jclass charsetICUClass;
|
||||
static jclass constructorClass;
|
||||
static jclass deflaterClass;
|
||||
static jclass doubleClass;
|
||||
static jclass errnoExceptionClass;
|
||||
static jclass fieldClass;
|
||||
static jclass fieldPositionIteratorClass;
|
||||
static jclass fileDescriptorClass;
|
||||
static jclass floatClass;
|
||||
static jclass gaiExceptionClass;
|
||||
static jclass inet6AddressClass;
|
||||
static jclass inetAddressClass;
|
||||
static jclass inetSocketAddressClass;
|
||||
static jclass inetUnixAddressClass;
|
||||
static jclass inflaterClass;
|
||||
static jclass inputStreamClass;
|
||||
static jclass integerClass;
|
||||
static jclass localeDataClass;
|
||||
static jclass longClass;
|
||||
static jclass methodClass;
|
||||
static jclass mutableIntClass;
|
||||
static jclass mutableLongClass;
|
||||
static jclass objectClass;
|
||||
static jclass objectArrayClass;
|
||||
static jclass outputStreamClass;
|
||||
static jclass parsePositionClass;
|
||||
static jclass patternSyntaxExceptionClass;
|
||||
static jclass realToStringClass;
|
||||
static jclass referenceClass;
|
||||
static jclass shortClass;
|
||||
static jclass socketClass;
|
||||
static jclass socketImplClass;
|
||||
static jclass stringClass;
|
||||
static jclass structAddrinfoClass;
|
||||
static jclass structFlockClass;
|
||||
static jclass structGroupReqClass;
|
||||
static jclass structLingerClass;
|
||||
static jclass structPasswdClass;
|
||||
static jclass structPollfdClass;
|
||||
static jclass structStatClass;
|
||||
static jclass structStatVfsClass;
|
||||
static jclass structTimevalClass;
|
||||
static jclass structUcredClass;
|
||||
static jclass structUtsnameClass;
|
||||
};
|
||||
|
||||
#define NATIVE_METHOD(className, functionName, signature) \
|
||||
{ #functionName, signature, reinterpret_cast<void*>(className ## _ ## functionName) }
|
||||
|
||||
#endif // JNI_CONSTANTS_H_included
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SCOPED_LOCAL_REF_H_included
|
||||
#define SCOPED_LOCAL_REF_H_included
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// A smart pointer that deletes a JNI local reference when it goes out of scope.
|
||||
template<typename T>
|
||||
class ScopedLocalRef {
|
||||
public:
|
||||
ScopedLocalRef(JNIEnv* env, T localRef) : mEnv(env), mLocalRef(localRef) {
|
||||
}
|
||||
|
||||
~ScopedLocalRef() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset(T ptr = NULL) {
|
||||
if (ptr != mLocalRef) {
|
||||
if (mLocalRef != NULL) {
|
||||
mEnv->DeleteLocalRef(mLocalRef);
|
||||
}
|
||||
mLocalRef = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
T release() __attribute__((warn_unused_result)) {
|
||||
T localRef = mLocalRef;
|
||||
mLocalRef = NULL;
|
||||
return localRef;
|
||||
}
|
||||
|
||||
T get() const {
|
||||
return mLocalRef;
|
||||
}
|
||||
|
||||
private:
|
||||
JNIEnv* mEnv;
|
||||
T mLocalRef;
|
||||
|
||||
// Disallow copy and assignment.
|
||||
ScopedLocalRef(const ScopedLocalRef&);
|
||||
void operator=(const ScopedLocalRef&);
|
||||
};
|
||||
|
||||
#endif // SCOPED_LOCAL_REF_H_included
|
1141
packages/myddas/sqlite3/Android/jni/sqlite/nativehelper/jni.h
Normal file
1141
packages/myddas/sqlite3/Android/jni/sqlite/nativehelper/jni.h
Normal file
File diff suppressed because it is too large
Load Diff
8733
packages/myddas/sqlite3/sqlite3.h
Normal file
8733
packages/myddas/sqlite3/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user