diff options
author | Jeff Brown <jeffbrown@google.com> | 2012-01-20 14:07:59 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-01-20 14:07:59 -0800 |
commit | 1bf599a01e7ad720150d8cc12416ba67bebd74c9 (patch) | |
tree | db2d5edc57a18a125f1576987b1daf119862d142 /core/jni | |
parent | 2f9510ca50b0fd2925bc7e349f76136ed403a386 (diff) | |
parent | 4b57553e693c9705e8363d3e0e9d881261b3e6fa (diff) | |
download | frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.zip frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.tar.gz frameworks_base-1bf599a01e7ad720150d8cc12416ba67bebd74c9.tar.bz2 |
Merge "Initialize SQLite as part of the android runtime."
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_database_SQLiteGlobal.cpp | 27 | ||||
-rw-r--r-- | core/jni/android_util_Log.cpp | 39 | ||||
-rw-r--r-- | core/jni/android_util_Log.h | 30 |
3 files changed, 73 insertions, 23 deletions
diff --git a/core/jni/android_database_SQLiteGlobal.cpp b/core/jni/android_database_SQLiteGlobal.cpp index 82cae5a..9301183 100644 --- a/core/jni/android_database_SQLiteGlobal.cpp +++ b/core/jni/android_database_SQLiteGlobal.cpp @@ -24,9 +24,16 @@ #include <sqlite3_android.h> #include "android_database_SQLiteCommon.h" +#include "android_util_Log.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; @@ -40,37 +47,41 @@ static void sqliteLogCallback(void* data, int iErrCode, const char* zMsg) { } // Sets the global SQLite configuration. -// This must be called before any other SQLite functions are called. */ -static void nativeConfig(JNIEnv* env, jclass clazz, jboolean verboseLog, jint softHeapLimit) { +// 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. + bool verboseLog = android_util_Log_isVerboseLogEnabled(SQLITE_LOG_TAG); 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(softHeapLimit); + sqlite3_soft_heap_limit(SOFT_HEAP_LIMIT); + + // Initialize SQLite. + sqlite3_initialize(); } -static jint nativeReleaseMemory(JNIEnv* env, jclass clazz, jint bytesToFree) { - return sqlite3_release_memory(bytesToFree); +static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) { + return sqlite3_release_memory(SOFT_HEAP_LIMIT); } static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ - { "nativeConfig", "(ZI)V", - (void*)nativeConfig }, - { "nativeReleaseMemory", "(I)I", + { "nativeReleaseMemory", "()I", (void*)nativeReleaseMemory }, }; int register_android_database_SQLiteGlobal(JNIEnv *env) { + sqliteInitialize(); + return AndroidRuntime::registerNativeMethods(env, "android/database/sqlite/SQLiteGlobal", sMethods, NELEM(sMethods)); } diff --git a/core/jni/android_util_Log.cpp b/core/jni/android_util_Log.cpp index a57aad7..2895171 100644 --- a/core/jni/android_util_Log.cpp +++ b/core/jni/android_util_Log.cpp @@ -27,6 +27,7 @@ #include "JNIHelp.h" #include "utils/misc.h" #include "android_runtime/AndroidRuntime.h" +#include "android_util_Log.h" #define MIN(a,b) ((a<b)?a:b) @@ -56,40 +57,48 @@ static int toLevel(const char* value) return levels.info; } -static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) -{ - int len; - char key[PROPERTY_KEY_MAX]; +static jboolean isLoggable(const char* tag, jint level) { + String8 key; + key.append(LOG_NAMESPACE); + key.append(tag); + char buf[PROPERTY_VALUE_MAX]; + if (property_get(key.string(), buf, "") <= 0) { + return false; + } + int logLevel = toLevel(buf); + return logLevel >= 0 && level >= logLevel; +} + +static jboolean android_util_Log_isLoggable(JNIEnv* env, jobject clazz, jstring tag, jint level) +{ if (tag == NULL) { return false; } - jboolean result = false; - const char* chars = env->GetStringUTFChars(tag, NULL); + if (!chars) { + return false; + } + jboolean result = false; if ((strlen(chars)+sizeof(LOG_NAMESPACE)) > PROPERTY_KEY_MAX) { char buf2[200]; snprintf(buf2, sizeof(buf2), "Log tag \"%s\" exceeds limit of %d characters\n", chars, PROPERTY_KEY_MAX - sizeof(LOG_NAMESPACE)); - // release the chars! - env->ReleaseStringUTFChars(tag, chars); - jniThrowException(env, "java/lang/IllegalArgumentException", buf2); - return false; } else { - strncpy(key, LOG_NAMESPACE, sizeof(LOG_NAMESPACE)-1); - strcpy(key + sizeof(LOG_NAMESPACE) - 1, chars); + result = isLoggable(chars, level); } env->ReleaseStringUTFChars(tag, chars); + return result; +} - len = property_get(key, buf, ""); - int logLevel = toLevel(buf); - return (logLevel >= 0 && level >= logLevel) ? true : false; +bool android_util_Log_isVerboseLogEnabled(const char* tag) { + return isLoggable(tag, levels.verbose); } /* diff --git a/core/jni/android_util_Log.h b/core/jni/android_util_Log.h new file mode 100644 index 0000000..4804a85 --- /dev/null +++ b/core/jni/android_util_Log.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2012 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 _ANDROID_UTIL_LOG_H +#define _ANDROID_UTIL_LOG_H + +#include <jni.h> +#include <JNIHelp.h> + + +namespace android { + +bool android_util_Log_isVerboseLogEnabled(const char* tag); + +} + +#endif // _ANDROID_UTIL_LOG_H |