The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "CursorWindow" |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 19 | #define LOG_NDEBUG 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 21 | #include <inttypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <jni.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 23 | #include <nativehelper/JNIHelp.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <android_runtime/AndroidRuntime.h> |
| 25 | |
| 26 | #include <utils/Log.h> |
| 27 | #include <utils/String8.h> |
| 28 | #include <utils/String16.h> |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 29 | #include <utils/Unicode.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <unistd.h> |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 34 | #include <sys/types.h> |
| 35 | #include <dirent.h> |
| 36 | |
| 37 | #undef LOG_NDEBUG |
| 38 | #define LOG_NDEBUG 1 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Mathias Agopian | 49d2b18 | 2012-02-27 18:11:20 -0800 | [diff] [blame] | 40 | #include <androidfw/CursorWindow.h> |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 41 | #include "android_os_Parcel.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | #include "android_util_Binder.h" |
Jeff Brown | e5360fb | 2011-10-31 17:48:13 -0700 | [diff] [blame] | 43 | #include "android_database_SQLiteCommon.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 45 | #include "core_jni_helpers.h" |
| 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | namespace android { |
| 48 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 49 | static struct { |
| 50 | jfieldID data; |
| 51 | jfieldID sizeCopied; |
| 52 | } gCharArrayBufferClassInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 54 | static jstring gEmptyString; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 56 | static void throwExceptionWithRowCol(JNIEnv* env, jint row, jint column) { |
| 57 | String8 msg; |
| 58 | msg.appendFormat("Couldn't read row %d, col %d from CursorWindow. " |
| 59 | "Make sure the Cursor is initialized correctly before accessing data from it.", |
| 60 | row, column); |
| 61 | jniThrowException(env, "java/lang/IllegalStateException", msg.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 64 | static void throwUnknownTypeException(JNIEnv * env, jint type) { |
| 65 | String8 msg; |
| 66 | msg.appendFormat("UNKNOWN type %d", type); |
| 67 | jniThrowException(env, "java/lang/IllegalStateException", msg.string()); |
| 68 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 70 | static int getFdCount() { |
| 71 | char fdpath[PATH_MAX]; |
| 72 | int count = 0; |
| 73 | snprintf(fdpath, PATH_MAX, "/proc/%d/fd", getpid()); |
| 74 | DIR *dir = opendir(fdpath); |
| 75 | if (dir != NULL) { |
| 76 | struct dirent *dirent; |
| 77 | while ((dirent = readdir(dir))) { |
| 78 | count++; |
| 79 | } |
| 80 | count -= 2; // discount "." and ".." |
| 81 | closedir(dir); |
| 82 | } |
| 83 | return count; |
| 84 | } |
| 85 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 86 | static jlong nativeCreate(JNIEnv* env, jclass clazz, jstring nameObj, jint cursorWindowSize) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 87 | String8 name; |
Jeff Brown | 5a05c23 | 2012-01-12 12:04:22 -0800 | [diff] [blame] | 88 | const char* nameStr = env->GetStringUTFChars(nameObj, NULL); |
| 89 | name.setTo(nameStr); |
| 90 | env->ReleaseStringUTFChars(nameObj, nameStr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 91 | |
| 92 | CursorWindow* window; |
Jeff Brown | 5e5d6d8 | 2011-10-12 15:41:34 -0700 | [diff] [blame] | 93 | status_t status = CursorWindow::create(name, cursorWindowSize, &window); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 94 | if (status || !window) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 95 | ALOGE("Could not allocate CursorWindow '%s' of size %d due to error %d.", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 96 | name.string(), cursorWindowSize, status); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 97 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 100 | LOG_WINDOW("nativeInitializeEmpty: window = %p", window); |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 101 | return reinterpret_cast<jlong>(window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 104 | static jlong nativeCreateFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 105 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 107 | CursorWindow* window; |
| 108 | status_t status = CursorWindow::createFromParcel(parcel, &window); |
| 109 | if (status || !window) { |
Amith Yamasani | 0903ec5 | 2016-08-26 09:22:36 -0700 | [diff] [blame] | 110 | ALOGE("Could not create CursorWindow from Parcel due to error %d, process fd count=%d", |
| 111 | status, getFdCount()); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 112 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 115 | LOG_WINDOW("nativeInitializeFromBinder: numRows = %d, numColumns = %d, window = %p", |
| 116 | window->getNumRows(), window->getNumColumns(), window); |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 117 | return reinterpret_cast<jlong>(window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 120 | static void nativeDispose(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 121 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 122 | if (window) { |
| 123 | LOG_WINDOW("Closing window %p", window); |
| 124 | delete window; |
| 125 | } |
| 126 | } |
| 127 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 128 | static jstring nativeGetName(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 650de3d | 2011-10-27 14:52:28 -0700 | [diff] [blame] | 129 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 130 | return env->NewStringUTF(window->name().string()); |
| 131 | } |
| 132 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 133 | static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jlong windowPtr, |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 134 | jobject parcelObj) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 135 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 136 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 137 | |
| 138 | status_t status = window->writeToParcel(parcel); |
| 139 | if (status) { |
| 140 | String8 msg; |
| 141 | msg.appendFormat("Could not write CursorWindow to Parcel due to error %d.", status); |
| 142 | jniThrowRuntimeException(env, msg.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 146 | static void nativeClear(JNIEnv * env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 147 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 148 | LOG_WINDOW("Clearing window %p", window); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 149 | status_t status = window->clear(); |
| 150 | if (status) { |
| 151 | LOG_WINDOW("Could not clear window. error=%d", status); |
| 152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 155 | static jint nativeGetNumRows(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 156 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 157 | return window->getNumRows(); |
| 158 | } |
| 159 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 160 | static jboolean nativeSetNumColumns(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 161 | jint columnNum) { |
| 162 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 163 | status_t status = window->setNumColumns(columnNum); |
| 164 | return status == OK; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 167 | static jboolean nativeAllocRow(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 168 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 169 | status_t status = window->allocRow(); |
| 170 | return status == OK; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 173 | static void nativeFreeLastRow(JNIEnv* env, jclass clazz, jlong windowPtr) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 174 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 175 | window->freeLastRow(); |
| 176 | } |
| 177 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 178 | static jint nativeGetType(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 179 | jint row, jint column) { |
| 180 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 181 | LOG_WINDOW("returning column type affinity for %d,%d from %p", row, column, window); |
| 182 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 183 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 184 | if (!fieldSlot) { |
Jeff Brown | aa32c30 | 2011-10-07 13:15:59 -0700 | [diff] [blame] | 185 | // FIXME: This is really broken but we have CTS tests that depend |
| 186 | // on this legacy behavior. |
| 187 | //throwExceptionWithRowCol(env, row, column); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 188 | return CursorWindow::FIELD_TYPE_NULL; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 189 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 190 | return window->getFieldSlotType(fieldSlot); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 193 | static jbyteArray nativeGetBlob(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 194 | jint row, jint column) { |
| 195 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 196 | LOG_WINDOW("Getting blob for %d,%d from %p", row, column, window); |
| 197 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 198 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 199 | if (!fieldSlot) { |
| 200 | throwExceptionWithRowCol(env, row, column); |
| 201 | return NULL; |
| 202 | } |
| 203 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 204 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 205 | if (type == CursorWindow::FIELD_TYPE_BLOB || type == CursorWindow::FIELD_TYPE_STRING) { |
| 206 | size_t size; |
| 207 | const void* value = window->getFieldSlotValueBlob(fieldSlot, &size); |
Fyodor Kupolov | eb6de6f | 2017-02-22 14:12:50 -0800 | [diff] [blame] | 208 | if (!value) { |
| 209 | throw_sqlite3_exception(env, "Native could not read blob slot"); |
| 210 | return NULL; |
| 211 | } |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 212 | jbyteArray byteArray = env->NewByteArray(size); |
| 213 | if (!byteArray) { |
| 214 | env->ExceptionClear(); |
| 215 | throw_sqlite3_exception(env, "Native could not create new byte[]"); |
| 216 | return NULL; |
| 217 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 218 | env->SetByteArrayRegion(byteArray, 0, size, static_cast<const jbyte*>(value)); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 219 | return byteArray; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 220 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 221 | throw_sqlite3_exception(env, "INTEGER data in nativeGetBlob "); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 222 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 223 | throw_sqlite3_exception(env, "FLOAT data in nativeGetBlob "); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 224 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 225 | // do nothing |
| 226 | } else { |
| 227 | throwUnknownTypeException(env, type); |
| 228 | } |
| 229 | return NULL; |
| 230 | } |
| 231 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 232 | static jstring nativeGetString(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 233 | jint row, jint column) { |
| 234 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 235 | LOG_WINDOW("Getting string for %d,%d from %p", row, column, window); |
| 236 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 237 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 238 | if (!fieldSlot) { |
| 239 | throwExceptionWithRowCol(env, row, column); |
| 240 | return NULL; |
| 241 | } |
| 242 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 243 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 244 | if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 245 | size_t sizeIncludingNull; |
| 246 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
Fyodor Kupolov | eb6de6f | 2017-02-22 14:12:50 -0800 | [diff] [blame] | 247 | if (!value) { |
| 248 | throw_sqlite3_exception(env, "Native could not read string slot"); |
| 249 | return NULL; |
| 250 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 251 | if (sizeIncludingNull <= 1) { |
Jeff Brown | 715311f | 2011-10-07 14:17:09 -0700 | [diff] [blame] | 252 | return gEmptyString; |
| 253 | } |
| 254 | // Convert to UTF-16 here instead of calling NewStringUTF. NewStringUTF |
| 255 | // doesn't like UTF-8 strings with high codepoints. It actually expects |
| 256 | // Modified UTF-8 with encoded surrogate pairs. |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 257 | String16 utf16(value, sizeIncludingNull - 1); |
Jeff Brown | 715311f | 2011-10-07 14:17:09 -0700 | [diff] [blame] | 258 | return env->NewString(reinterpret_cast<const jchar*>(utf16.string()), utf16.size()); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 259 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 260 | int64_t value = window->getFieldSlotValueLong(fieldSlot); |
| 261 | char buf[32]; |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 262 | snprintf(buf, sizeof(buf), "%" PRId64, value); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 263 | return env->NewStringUTF(buf); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 264 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 265 | double value = window->getFieldSlotValueDouble(fieldSlot); |
| 266 | char buf[32]; |
| 267 | snprintf(buf, sizeof(buf), "%g", value); |
| 268 | return env->NewStringUTF(buf); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 269 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 270 | return NULL; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 271 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 272 | throw_sqlite3_exception(env, "Unable to convert BLOB to string"); |
| 273 | return NULL; |
| 274 | } else { |
| 275 | throwUnknownTypeException(env, type); |
| 276 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 280 | static jcharArray allocCharArrayBuffer(JNIEnv* env, jobject bufferObj, size_t size) { |
| 281 | jcharArray dataObj = jcharArray(env->GetObjectField(bufferObj, |
| 282 | gCharArrayBufferClassInfo.data)); |
| 283 | if (dataObj && size) { |
| 284 | jsize capacity = env->GetArrayLength(dataObj); |
| 285 | if (size_t(capacity) < size) { |
| 286 | env->DeleteLocalRef(dataObj); |
| 287 | dataObj = NULL; |
| 288 | } |
| 289 | } |
| 290 | if (!dataObj) { |
| 291 | jsize capacity = size; |
| 292 | if (capacity < 64) { |
| 293 | capacity = 64; |
| 294 | } |
| 295 | dataObj = env->NewCharArray(capacity); // might throw OOM |
| 296 | if (dataObj) { |
| 297 | env->SetObjectField(bufferObj, gCharArrayBufferClassInfo.data, dataObj); |
| 298 | } |
| 299 | } |
| 300 | return dataObj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 303 | static void fillCharArrayBufferUTF(JNIEnv* env, jobject bufferObj, |
| 304 | const char* str, size_t len) { |
| 305 | ssize_t size = utf8_to_utf16_length(reinterpret_cast<const uint8_t*>(str), len); |
| 306 | if (size < 0) { |
| 307 | size = 0; // invalid UTF8 string |
| 308 | } |
| 309 | jcharArray dataObj = allocCharArrayBuffer(env, bufferObj, size); |
| 310 | if (dataObj) { |
| 311 | if (size) { |
| 312 | jchar* data = static_cast<jchar*>(env->GetPrimitiveArrayCritical(dataObj, NULL)); |
Jeff Brown | d0ff68d | 2011-10-07 13:28:18 -0700 | [diff] [blame] | 313 | utf8_to_utf16_no_null_terminator(reinterpret_cast<const uint8_t*>(str), len, |
Sergio Giro | 8f7b8a1 | 2016-07-21 14:44:07 +0100 | [diff] [blame] | 314 | reinterpret_cast<char16_t*>(data), (size_t) size); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 315 | env->ReleasePrimitiveArrayCritical(dataObj, data, 0); |
| 316 | } |
| 317 | env->SetIntField(bufferObj, gCharArrayBufferClassInfo.sizeCopied, size); |
| 318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | } |
| 320 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 321 | static void clearCharArrayBuffer(JNIEnv* env, jobject bufferObj) { |
| 322 | jcharArray dataObj = allocCharArrayBuffer(env, bufferObj, 0); |
| 323 | if (dataObj) { |
| 324 | env->SetIntField(bufferObj, gCharArrayBufferClassInfo.sizeCopied, 0); |
| 325 | } |
| 326 | } |
| 327 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 328 | static void nativeCopyStringToBuffer(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 329 | jint row, jint column, jobject bufferObj) { |
| 330 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 331 | LOG_WINDOW("Copying string for %d,%d from %p", row, column, window); |
| 332 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 333 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 334 | if (!fieldSlot) { |
| 335 | throwExceptionWithRowCol(env, row, column); |
| 336 | return; |
| 337 | } |
| 338 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 339 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 340 | if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 341 | size_t sizeIncludingNull; |
| 342 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 343 | if (sizeIncludingNull > 1) { |
| 344 | fillCharArrayBufferUTF(env, bufferObj, value, sizeIncludingNull - 1); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 345 | } else { |
| 346 | clearCharArrayBuffer(env, bufferObj); |
| 347 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 348 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 349 | int64_t value = window->getFieldSlotValueLong(fieldSlot); |
| 350 | char buf[32]; |
Mark Salyzyn | 8539403 | 2014-04-16 10:28:37 -0700 | [diff] [blame] | 351 | snprintf(buf, sizeof(buf), "%" PRId64, value); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 352 | fillCharArrayBufferUTF(env, bufferObj, buf, strlen(buf)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 353 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 354 | double value = window->getFieldSlotValueDouble(fieldSlot); |
| 355 | char buf[32]; |
| 356 | snprintf(buf, sizeof(buf), "%g", value); |
| 357 | fillCharArrayBufferUTF(env, bufferObj, buf, strlen(buf)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 358 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 359 | clearCharArrayBuffer(env, bufferObj); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 360 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 361 | throw_sqlite3_exception(env, "Unable to convert BLOB to string"); |
| 362 | } else { |
| 363 | throwUnknownTypeException(env, type); |
| 364 | } |
| 365 | } |
| 366 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 367 | static jlong nativeGetLong(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 368 | jint row, jint column) { |
| 369 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 370 | LOG_WINDOW("Getting long for %d,%d from %p", row, column, window); |
| 371 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 372 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 373 | if (!fieldSlot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | throwExceptionWithRowCol(env, row, column); |
| 375 | return 0; |
| 376 | } |
| 377 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 378 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 379 | if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 380 | return window->getFieldSlotValueLong(fieldSlot); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 381 | } else if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 382 | size_t sizeIncludingNull; |
| 383 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 384 | return sizeIncludingNull > 1 ? strtoll(value, NULL, 0) : 0L; |
| 385 | } else if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 386 | return jlong(window->getFieldSlotValueDouble(fieldSlot)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 387 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | return 0; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 389 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | throw_sqlite3_exception(env, "Unable to convert BLOB to long"); |
| 391 | return 0; |
| 392 | } else { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 393 | throwUnknownTypeException(env, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | } |
| 397 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 398 | static jdouble nativeGetDouble(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 399 | jint row, jint column) { |
| 400 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
| 401 | LOG_WINDOW("Getting double for %d,%d from %p", row, column, window); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 403 | CursorWindow::FieldSlot* fieldSlot = window->getFieldSlot(row, column); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 404 | if (!fieldSlot) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | throwExceptionWithRowCol(env, row, column); |
| 406 | return 0.0; |
| 407 | } |
| 408 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 409 | int32_t type = window->getFieldSlotType(fieldSlot); |
| 410 | if (type == CursorWindow::FIELD_TYPE_FLOAT) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 411 | return window->getFieldSlotValueDouble(fieldSlot); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 412 | } else if (type == CursorWindow::FIELD_TYPE_STRING) { |
| 413 | size_t sizeIncludingNull; |
| 414 | const char* value = window->getFieldSlotValueString(fieldSlot, &sizeIncludingNull); |
| 415 | return sizeIncludingNull > 1 ? strtod(value, NULL) : 0.0; |
| 416 | } else if (type == CursorWindow::FIELD_TYPE_INTEGER) { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 417 | return jdouble(window->getFieldSlotValueLong(fieldSlot)); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 418 | } else if (type == CursorWindow::FIELD_TYPE_NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | return 0.0; |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 420 | } else if (type == CursorWindow::FIELD_TYPE_BLOB) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | throw_sqlite3_exception(env, "Unable to convert BLOB to double"); |
| 422 | return 0.0; |
| 423 | } else { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 424 | throwUnknownTypeException(env, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | return 0.0; |
| 426 | } |
| 427 | } |
| 428 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 429 | static jboolean nativePutBlob(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 430 | jbyteArray valueObj, jint row, jint column) { |
| 431 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 432 | jsize len = env->GetArrayLength(valueObj); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 434 | void* value = env->GetPrimitiveArrayCritical(valueObj, NULL); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 435 | status_t status = window->putBlob(row, column, value, len); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 436 | env->ReleasePrimitiveArrayCritical(valueObj, value, JNI_ABORT); |
| 437 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 438 | if (status) { |
| 439 | LOG_WINDOW("Failed to put blob. error=%d", status); |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | LOG_WINDOW("%d,%d is BLOB with %u bytes", row, column, len); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | return true; |
| 445 | } |
| 446 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 447 | static jboolean nativePutString(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 448 | jstring valueObj, jint row, jint column) { |
| 449 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 451 | size_t sizeIncludingNull = env->GetStringUTFLength(valueObj) + 1; |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 452 | const char* valueStr = env->GetStringUTFChars(valueObj, NULL); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 453 | if (!valueStr) { |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 454 | LOG_WINDOW("value can't be transferred to UTFChars"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | return false; |
| 456 | } |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 457 | status_t status = window->putString(row, column, valueStr, sizeIncludingNull); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 458 | env->ReleaseStringUTFChars(valueObj, valueStr); |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 459 | |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 460 | if (status) { |
| 461 | LOG_WINDOW("Failed to put string. error=%d", status); |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | LOG_WINDOW("%d,%d is TEXT with %u bytes", row, column, sizeIncludingNull); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | return true; |
| 467 | } |
| 468 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 469 | static jboolean nativePutLong(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 470 | jlong value, jint row, jint column) { |
| 471 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 472 | status_t status = window->putLong(row, column, value); |
| 473 | |
| 474 | if (status) { |
| 475 | LOG_WINDOW("Failed to put long. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | return false; |
| 477 | } |
| 478 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 479 | LOG_WINDOW("%d,%d is INTEGER 0x%016llx", row, column, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | return true; |
| 481 | } |
| 482 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 483 | static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 484 | jdouble value, jint row, jint column) { |
| 485 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 486 | status_t status = window->putDouble(row, column, value); |
| 487 | |
| 488 | if (status) { |
| 489 | LOG_WINDOW("Failed to put double. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | return false; |
| 491 | } |
| 492 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 493 | LOG_WINDOW("%d,%d is FLOAT %lf", row, column, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 497 | static jboolean nativePutNull(JNIEnv* env, jclass clazz, jlong windowPtr, |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 498 | jint row, jint column) { |
| 499 | CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr); |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 500 | status_t status = window->putNull(row, column); |
| 501 | |
| 502 | if (status) { |
| 503 | LOG_WINDOW("Failed to put null. error=%d", status); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | return false; |
| 505 | } |
| 506 | |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 507 | LOG_WINDOW("%d,%d is NULL", row, column); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | return true; |
| 509 | } |
| 510 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 511 | static const JNINativeMethod sMethods[] = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | { |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 513 | /* name, signature, funcPtr */ |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 514 | { "nativeCreate", "(Ljava/lang/String;I)J", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 515 | (void*)nativeCreate }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 516 | { "nativeCreateFromParcel", "(Landroid/os/Parcel;)J", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 517 | (void*)nativeCreateFromParcel }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 518 | { "nativeDispose", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 519 | (void*)nativeDispose }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 520 | { "nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
Jeff Brown | 0cde89f | 2011-10-10 14:50:10 -0700 | [diff] [blame] | 521 | (void*)nativeWriteToParcel }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 522 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 523 | { "nativeGetName", "(J)Ljava/lang/String;", |
Jeff Brown | 650de3d | 2011-10-27 14:52:28 -0700 | [diff] [blame] | 524 | (void*)nativeGetName }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 525 | { "nativeGetBlob", "(JII)[B", |
| 526 | (void*)nativeGetBlob }, |
| 527 | { "nativeGetString", "(JII)Ljava/lang/String;", |
| 528 | (void*)nativeGetString }, |
| 529 | { "nativeCopyStringToBuffer", "(JIILandroid/database/CharArrayBuffer;)V", |
| 530 | (void*)nativeCopyStringToBuffer }, |
| 531 | { "nativePutBlob", "(J[BII)Z", |
| 532 | (void*)nativePutBlob }, |
| 533 | { "nativePutString", "(JLjava/lang/String;II)Z", |
| 534 | (void*)nativePutString }, |
| 535 | |
| 536 | // ------- @FastNative below here ---------------------- |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 537 | { "nativeClear", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 538 | (void*)nativeClear }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 539 | { "nativeGetNumRows", "(J)I", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 540 | (void*)nativeGetNumRows }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 541 | { "nativeSetNumColumns", "(JI)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 542 | (void*)nativeSetNumColumns }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 543 | { "nativeAllocRow", "(J)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 544 | (void*)nativeAllocRow }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 545 | { "nativeFreeLastRow", "(J)V", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 546 | (void*)nativeFreeLastRow }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 547 | { "nativeGetType", "(JII)I", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 548 | (void*)nativeGetType }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 549 | { "nativeGetLong", "(JII)J", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 550 | (void*)nativeGetLong }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 551 | { "nativeGetDouble", "(JII)D", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 552 | (void*)nativeGetDouble }, |
Chris Craik | 0834e35 | 2017-06-16 10:34:11 -0700 | [diff] [blame] | 553 | |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 554 | { "nativePutLong", "(JJII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 555 | (void*)nativePutLong }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 556 | { "nativePutDouble", "(JDII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 557 | (void*)nativePutDouble }, |
Ashok Bhat | 738702d | 2014-01-02 13:42:56 +0000 | [diff] [blame] | 558 | { "nativePutNull", "(JII)Z", |
Jeff Brown | 3bc6bbc | 2011-10-06 13:11:04 -0700 | [diff] [blame] | 559 | (void*)nativePutNull }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | }; |
| 561 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 562 | int register_android_database_CursorWindow(JNIEnv* env) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 564 | jclass clazz = FindClassOrDie(env, "android/database/CharArrayBuffer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 566 | gCharArrayBufferClassInfo.data = GetFieldIDOrDie(env, clazz, "data", "[C"); |
| 567 | gCharArrayBufferClassInfo.sizeCopied = GetFieldIDOrDie(env, clazz, "sizeCopied", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 569 | gEmptyString = MakeGlobalRefOrDie(env, env->NewStringUTF("")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 571 | return RegisterMethodsOrDie(env, "android/database/CursorWindow", sMethods, NELEM(sMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | } // namespace android |