blob: e5b72caf279242ba5dad250d2f9cef6cde8f0f3a [file] [log] [blame]
Andreas Huber9266f992016-08-25 11:21:21 -07001/*
2 * Copyright (C) 2016 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//#define LOG_NDEBUG 0
18#define LOG_TAG "android_os_HwBlob"
19#include <android-base/logging.h>
20
21#include "android_os_HwBlob.h"
22
23#include "android_os_HwParcel.h"
Nirav Atre9850dd92018-07-24 17:03:44 -070024#include "android_os_NativeHandle.h"
Andreas Huber9266f992016-08-25 11:21:21 -070025
Steven Moreland2279b252017-07-19 09:50:45 -070026#include <nativehelper/JNIHelp.h>
Andreas Huber9266f992016-08-25 11:21:21 -070027#include <android_runtime/AndroidRuntime.h>
Martijn Coenenaa2c32f2016-09-01 01:37:05 +020028#include <hidl/Status.h>
Andreas Huber9266f992016-08-25 11:21:21 -070029#include <nativehelper/ScopedLocalRef.h>
Andreas Huber2631df72017-11-01 10:19:44 -070030#include <nativehelper/ScopedPrimitiveArray.h>
Andreas Huber9266f992016-08-25 11:21:21 -070031
32#include "core_jni_helpers.h"
33
34using android::AndroidRuntime;
Nirav Atre9850dd92018-07-24 17:03:44 -070035using android::hardware::hidl_handle;
Andreas Huber9266f992016-08-25 11:21:21 -070036using android::hardware::hidl_string;
37
38#define PACKAGE_PATH "android/os"
39#define CLASS_NAME "HwBlob"
40#define CLASS_PATH PACKAGE_PATH "/" CLASS_NAME
41
42namespace android {
43
44static struct fields_t {
45 jfieldID contextID;
46 jmethodID constructID;
47
48} gFields;
49
50// static
51void JHwBlob::InitClass(JNIEnv *env) {
52 ScopedLocalRef<jclass> clazz(
53 env, FindClassOrDie(env, CLASS_PATH));
54
55 gFields.contextID =
56 GetFieldIDOrDie(env, clazz.get(), "mNativeContext", "J");
57
58 gFields.constructID = GetMethodIDOrDie(env, clazz.get(), "<init>", "(I)V");
59}
60
61// static
62sp<JHwBlob> JHwBlob::SetNativeContext(
63 JNIEnv *env, jobject thiz, const sp<JHwBlob> &context) {
64 sp<JHwBlob> old = (JHwBlob *)env->GetLongField(thiz, gFields.contextID);
65
Andreas Huber0eb37e02017-10-31 11:51:50 -070066 if (context != nullptr) {
67 context->incStrong(nullptr /* id */);
Andreas Huber9266f992016-08-25 11:21:21 -070068 }
69
Andreas Huber0eb37e02017-10-31 11:51:50 -070070 if (old != nullptr) {
71 old->decStrong(nullptr /* id */);
Andreas Huber9266f992016-08-25 11:21:21 -070072 }
73
74 env->SetLongField(thiz, gFields.contextID, (long)context.get());
75
76 return old;
77}
78
79// static
80sp<JHwBlob> JHwBlob::GetNativeContext(JNIEnv *env, jobject thiz) {
81 return (JHwBlob *)env->GetLongField(thiz, gFields.contextID);
82}
83
84JHwBlob::JHwBlob(JNIEnv *env, jobject thiz, size_t size)
85 : mBuffer(nullptr),
86 mSize(size),
Nirav Atre9850dd92018-07-24 17:03:44 -070087 mType(BlobType::GENERIC),
Andreas Huber9266f992016-08-25 11:21:21 -070088 mOwnsBuffer(true),
89 mHandle(0) {
Andreas Huber9266f992016-08-25 11:21:21 -070090 if (size > 0) {
Steven Moreland45ec7bb2019-04-18 16:32:42 -070091 mBuffer = calloc(size, 1);
Andreas Huber9266f992016-08-25 11:21:21 -070092 }
93}
94
95JHwBlob::~JHwBlob() {
96 if (mOwnsBuffer) {
97 free(mBuffer);
98 mBuffer = nullptr;
99 }
Andreas Huber9266f992016-08-25 11:21:21 -0700100}
101
102void JHwBlob::setTo(const void *ptr, size_t handle) {
103 CHECK_EQ(mSize, 0u);
104 CHECK(mBuffer == nullptr);
105
106 mBuffer = const_cast<void *>(ptr);
107 mSize = SIZE_MAX; // XXX
108 mOwnsBuffer = false;
109 mHandle = handle;
110}
111
112status_t JHwBlob::getHandle(size_t *handle) const {
113 if (mOwnsBuffer) {
114 return INVALID_OPERATION;
115 }
116
117 *handle = mHandle;
118
119 return OK;
120}
121
122status_t JHwBlob::read(size_t offset, void *data, size_t size) const {
123 if (offset + size > mSize) {
124 return -ERANGE;
125 }
126
127 memcpy(data, (const uint8_t *)mBuffer + offset, size);
128
129 return OK;
130}
131
132status_t JHwBlob::write(size_t offset, const void *data, size_t size) {
133 if (offset + size > mSize) {
134 return -ERANGE;
135 }
136
137 memcpy((uint8_t *)mBuffer + offset, data, size);
138
139 return OK;
140}
141
142status_t JHwBlob::getString(size_t offset, const hidl_string **s) const {
143 if ((offset + sizeof(hidl_string)) > mSize) {
144 return -ERANGE;
145 }
146
147 *s = reinterpret_cast<const hidl_string *>(
148 (const uint8_t *)mBuffer + offset);
149
150 return OK;
151}
152
153const void *JHwBlob::data() const {
154 return mBuffer;
155}
156
Andreas Huber0eb37e02017-10-31 11:51:50 -0700157void *JHwBlob::data() {
158 return mBuffer;
159}
160
Andreas Huber9266f992016-08-25 11:21:21 -0700161size_t JHwBlob::size() const {
162 return mSize;
163}
164
Nirav Atre9850dd92018-07-24 17:03:44 -0700165void JHwBlob::specializeBlobTo(BlobType type) {
166 CHECK_EQ(static_cast<int>(mType), static_cast<int>(BlobType::GENERIC));
167 mType = type;
168}
169
170JHwBlob::BlobType JHwBlob::type() const {
171 return mType;
172}
173
Andreas Huber9266f992016-08-25 11:21:21 -0700174status_t JHwBlob::putBlob(size_t offset, const sp<JHwBlob> &blob) {
175 size_t index = mSubBlobs.add();
176 BlobInfo *info = &mSubBlobs.editItemAt(index);
177
178 info->mOffset = offset;
179 info->mBlob = blob;
180
181 const void *data = blob->data();
182
183 return write(offset, &data, sizeof(data));
184}
185
186status_t JHwBlob::writeToParcel(hardware::Parcel *parcel) const {
Nirav Atre9850dd92018-07-24 17:03:44 -0700187 CHECK_EQ(static_cast<int>(mType), static_cast<int>(BlobType::GENERIC));
188
189 size_t handle = 0;
Andreas Huber9266f992016-08-25 11:21:21 -0700190 status_t err = parcel->writeBuffer(data(), size(), &handle);
191
192 if (err != OK) {
193 return err;
194 }
195
Nirav Atre9850dd92018-07-24 17:03:44 -0700196 return writeSubBlobsToParcel(parcel, handle);
Andreas Huber9266f992016-08-25 11:21:21 -0700197}
198
199status_t JHwBlob::writeEmbeddedToParcel(
200 hardware::Parcel *parcel,
201 size_t parentHandle,
202 size_t parentOffset) const {
Nirav Atre9850dd92018-07-24 17:03:44 -0700203 size_t handle = 0;
204 status_t err = OK;
205
206 switch (mType) {
207 case BlobType::GENERIC: {
208 err = parcel->writeEmbeddedBuffer(data(), size(), &handle, parentHandle, parentOffset);
209 break;
210 }
211 case BlobType::NATIVE_HANDLE: {
212 err = parcel->writeEmbeddedNativeHandle(
213 static_cast<const native_handle *>(data()), parentHandle, parentOffset);
214
215 CHECK(mSubBlobs.empty());
216 break;
217 }
218 default: { err = INVALID_OPERATION; }
219 }
Andreas Huber9266f992016-08-25 11:21:21 -0700220
221 if (err != OK) {
222 return err;
223 }
224
Nirav Atre9850dd92018-07-24 17:03:44 -0700225 return writeSubBlobsToParcel(parcel, handle);
226}
227
228status_t JHwBlob::writeSubBlobsToParcel(hardware::Parcel *parcel,
229 size_t parentHandle) const {
Andreas Huber9266f992016-08-25 11:21:21 -0700230 for (size_t i = 0; i < mSubBlobs.size(); ++i) {
231 const BlobInfo &info = mSubBlobs[i];
Nirav Atre9850dd92018-07-24 17:03:44 -0700232 status_t err = info.mBlob->writeEmbeddedToParcel(parcel, parentHandle, info.mOffset);
Andreas Huber9266f992016-08-25 11:21:21 -0700233
234 if (err != OK) {
235 return err;
236 }
237 }
238
239 return OK;
240}
241
242// static
243jobject JHwBlob::NewObject(JNIEnv *env, const void *ptr, size_t handle) {
244 jobject obj = JHwBlob::NewObject(env, 0 /* size */);
245 JHwBlob::GetNativeContext(env, obj)->setTo(ptr, handle);
246
247 return obj;
248}
249
250// static
251jobject JHwBlob::NewObject(JNIEnv *env, size_t size) {
252 ScopedLocalRef<jclass> clazz(env, FindClassOrDie(env, CLASS_PATH));
253
254 jmethodID constructID =
255 GetMethodIDOrDie(env, clazz.get(), "<init>", "(I)V");
256
257 // XXX Again cannot refer to gFields.constructID because InitClass may
258 // not have been called yet.
259
260 return env->NewObject(clazz.get(), constructID, size);
261}
262
263} // namespace android
264
265////////////////////////////////////////////////////////////////////////////////
266
267using namespace android;
268
269static void releaseNativeContext(void *nativeContext) {
270 sp<JHwBlob> parcel = (JHwBlob *)nativeContext;
271
Andreas Huber0eb37e02017-10-31 11:51:50 -0700272 if (parcel != nullptr) {
273 parcel->decStrong(nullptr /* id */);
Andreas Huber9266f992016-08-25 11:21:21 -0700274 }
275}
276
Nirav Atre9850dd92018-07-24 17:03:44 -0700277static jlong JHwBlob_native_init(JNIEnv *env, jclass /*clazz*/) {
Andreas Huber9266f992016-08-25 11:21:21 -0700278 JHwBlob::InitClass(env);
279
280 return reinterpret_cast<jlong>(&releaseNativeContext);
281}
282
283static void JHwBlob_native_setup(
284 JNIEnv *env, jobject thiz, jint size) {
285 sp<JHwBlob> context = new JHwBlob(env, thiz, size);
286
287 JHwBlob::SetNativeContext(env, thiz, context);
288}
289
290#define DEFINE_BLOB_GETTER(Suffix,Type) \
291static Type JHwBlob_native_get ## Suffix( \
292 JNIEnv *env, jobject thiz, jlong offset) { \
293 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz); \
294 \
295 Type x; \
296 status_t err = blob->read(offset, &x, sizeof(x)); \
297 \
298 if (err != OK) { \
299 signalExceptionForError(env, err); \
300 return 0; \
301 } \
302 \
303 return x; \
304}
305
306DEFINE_BLOB_GETTER(Int8,jbyte)
307DEFINE_BLOB_GETTER(Int16,jshort)
308DEFINE_BLOB_GETTER(Int32,jint)
309DEFINE_BLOB_GETTER(Int64,jlong)
310DEFINE_BLOB_GETTER(Float,jfloat)
311DEFINE_BLOB_GETTER(Double,jdouble)
312
313static jboolean JHwBlob_native_getBool(
314 JNIEnv *env, jobject thiz, jlong offset) {
315 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
316
317 bool x;
318 status_t err = blob->read(offset, &x, sizeof(x));
319
320 if (err != OK) {
321 signalExceptionForError(env, err);
322 return 0;
323 }
324
325 return (jboolean)x;
326}
327
328static jstring JHwBlob_native_getString(
329 JNIEnv *env, jobject thiz, jlong offset) {
330 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
331
332 const hidl_string *s;
333 status_t err = blob->getString(offset, &s);
334
335 if (err != OK) {
336 signalExceptionForError(env, err);
337 return nullptr;
338 }
339
340 return env->NewStringUTF(s->c_str());
341}
342
Andreas Huber0eb37e02017-10-31 11:51:50 -0700343#define DEFINE_BLOB_ARRAY_COPIER(Suffix,Type,NewType) \
344static void JHwBlob_native_copyTo ## Suffix ## Array( \
345 JNIEnv *env, \
346 jobject thiz, \
347 jlong offset, \
348 Type ## Array array, \
349 jint size) { \
350 if (array == nullptr) { \
351 jniThrowException(env, "java/lang/NullPointerException", nullptr); \
352 return; \
353 } \
354 \
355 if (env->GetArrayLength(array) < size) { \
356 signalExceptionForError(env, BAD_VALUE); \
357 return; \
358 } \
359 \
360 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz); \
361 \
362 if ((offset + size * sizeof(Type)) > blob->size()) { \
363 signalExceptionForError(env, -ERANGE); \
364 return; \
365 } \
366 \
367 env->Set ## NewType ## ArrayRegion( \
368 array, \
369 0 /* start */, \
370 size, \
371 reinterpret_cast<const Type *>( \
372 static_cast<const uint8_t *>(blob->data()) + offset)); \
373}
374
Andreas Huber2631df72017-11-01 10:19:44 -0700375DEFINE_BLOB_ARRAY_COPIER(Int8,jbyte,Byte)
376DEFINE_BLOB_ARRAY_COPIER(Int16,jshort,Short)
377DEFINE_BLOB_ARRAY_COPIER(Int32,jint,Int)
378DEFINE_BLOB_ARRAY_COPIER(Int64,jlong,Long)
379DEFINE_BLOB_ARRAY_COPIER(Float,jfloat,Float)
380DEFINE_BLOB_ARRAY_COPIER(Double,jdouble,Double)
381
Andreas Huber0eb37e02017-10-31 11:51:50 -0700382static void JHwBlob_native_copyToBoolArray(
383 JNIEnv *env,
384 jobject thiz,
385 jlong offset,
386 jbooleanArray array,
387 jint size) {
388 if (array == nullptr) {
389 jniThrowException(env, "java/lang/NullPointerException", nullptr);
390 return;
391 }
392
393 if (env->GetArrayLength(array) < size) {
394 signalExceptionForError(env, BAD_VALUE);
395 return;
396 }
397
398 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
399
400 if ((offset + size * sizeof(bool)) > blob->size()) {
401 signalExceptionForError(env, -ERANGE);
402 return;
403 }
404
405 const bool *src =
406 reinterpret_cast<const bool *>(
407 static_cast<const uint8_t *>(blob->data()) + offset);
408
409 jboolean *dst = env->GetBooleanArrayElements(array, nullptr /* isCopy */);
410
411 for (jint i = 0; i < size; ++i) {
412 dst[i] = src[i];
413 }
414
415 env->ReleaseBooleanArrayElements(array, dst, 0 /* mode */);
416 dst = nullptr;
417}
418
Andreas Huber9266f992016-08-25 11:21:21 -0700419#define DEFINE_BLOB_PUTTER(Suffix,Type) \
420static void JHwBlob_native_put ## Suffix( \
421 JNIEnv *env, jobject thiz, jlong offset, Type x) { \
422 \
423 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz); \
424 \
425 status_t err = blob->write(offset, &x, sizeof(x)); \
426 \
427 if (err != OK) { \
428 signalExceptionForError(env, err); \
429 } \
430}
431
432DEFINE_BLOB_PUTTER(Int8,jbyte)
433DEFINE_BLOB_PUTTER(Int16,jshort)
434DEFINE_BLOB_PUTTER(Int32,jint)
435DEFINE_BLOB_PUTTER(Int64,jlong)
436DEFINE_BLOB_PUTTER(Float,jfloat)
437DEFINE_BLOB_PUTTER(Double,jdouble)
438
439static void JHwBlob_native_putBool(
440 JNIEnv *env, jobject thiz, jlong offset, jboolean x) {
441
442 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
443
444 bool b = (bool)x;
445 status_t err = blob->write(offset, &b, sizeof(b));
446
447 if (err != OK) {
448 signalExceptionForError(env, err);
449 }
450}
451
452static void JHwBlob_native_putString(
453 JNIEnv *env, jobject thiz, jlong offset, jstring stringObj) {
454 if (stringObj == nullptr) {
455 jniThrowException(env, "java/lang/NullPointerException", nullptr);
456 return;
457 }
458
459 const char *s = env->GetStringUTFChars(stringObj, nullptr);
460
461 if (s == nullptr) {
462 return;
463 }
464
465 size_t size = strlen(s) + 1;
466 ScopedLocalRef<jobject> subBlobObj(env, JHwBlob::NewObject(env, size));
467 sp<JHwBlob> subBlob = JHwBlob::GetNativeContext(env, subBlobObj.get());
468 subBlob->write(0 /* offset */, s, size);
469
470 env->ReleaseStringUTFChars(stringObj, s);
471 s = nullptr;
472
473 hidl_string tmp;
Andreas Huber7e603112017-02-06 11:49:26 -0800474 tmp.setToExternal(static_cast<const char *>(subBlob->data()), size - 1);
Andreas Huber9266f992016-08-25 11:21:21 -0700475
476 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
477 blob->write(offset, &tmp, sizeof(tmp));
478 blob->putBlob(offset + hidl_string::kOffsetOfBuffer, subBlob);
479}
480
Nirav Atre9850dd92018-07-24 17:03:44 -0700481static void JHwBlob_native_putNativeHandle(JNIEnv *env, jobject thiz,
482 jlong offset, jobject jHandle) {
483 std::unique_ptr<native_handle_t, int(*)(native_handle_t*)> nativeHandle(
484 JNativeHandle::MakeCppNativeHandle(env, jHandle, nullptr /* storage */),
485 native_handle_delete);
486
487 size_t size = 0;
488 if (nativeHandle != nullptr) {
489 size = sizeof(native_handle_t) + nativeHandle->numFds * sizeof(int)
490 + nativeHandle->numInts * sizeof(int);
491 }
492
493 ScopedLocalRef<jobject> subBlobObj(env, JHwBlob::NewObject(env, size));
494 sp<JHwBlob> subBlob = JHwBlob::GetNativeContext(env, subBlobObj.get());
495 subBlob->specializeBlobTo(JHwBlob::BlobType::NATIVE_HANDLE);
496 subBlob->write(0 /* offset */, nativeHandle.get(), size);
497
498 hidl_handle cppHandle;
499 cppHandle.setTo(static_cast<native_handle_t *>(subBlob->data()), false /* shouldOwn */);
500
501 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
502 blob->write(offset, &cppHandle, sizeof(cppHandle));
503 blob->putBlob(offset + hidl_handle::kOffsetOfNativeHandle, subBlob);
504}
505
Andreas Huber0eb37e02017-10-31 11:51:50 -0700506#define DEFINE_BLOB_ARRAY_PUTTER(Suffix,Type,NewType) \
507static void JHwBlob_native_put ## Suffix ## Array( \
508 JNIEnv *env, jobject thiz, jlong offset, Type ## Array array) { \
Andreas Huber2631df72017-11-01 10:19:44 -0700509 Scoped ## NewType ## ArrayRO autoArray(env, array); \
Andreas Huber0eb37e02017-10-31 11:51:50 -0700510 \
511 if (array == nullptr) { \
Andreas Huber2631df72017-11-01 10:19:44 -0700512 /* NullpointerException already pending */ \
Andreas Huber0eb37e02017-10-31 11:51:50 -0700513 return; \
514 } \
515 \
516 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz); \
517 \
Andreas Huber2631df72017-11-01 10:19:44 -0700518 status_t err = blob->write( \
519 offset, autoArray.get(), autoArray.size() * sizeof(Type)); \
Andreas Huber0eb37e02017-10-31 11:51:50 -0700520 \
521 if (err != OK) { \
522 signalExceptionForError(env, err); \
523 } \
524}
525
526DEFINE_BLOB_ARRAY_PUTTER(Int8,jbyte,Byte)
527DEFINE_BLOB_ARRAY_PUTTER(Int16,jshort,Short)
528DEFINE_BLOB_ARRAY_PUTTER(Int32,jint,Int)
529DEFINE_BLOB_ARRAY_PUTTER(Int64,jlong,Long)
530DEFINE_BLOB_ARRAY_PUTTER(Float,jfloat,Float)
531DEFINE_BLOB_ARRAY_PUTTER(Double,jdouble,Double)
532
533static void JHwBlob_native_putBoolArray(
534 JNIEnv *env, jobject thiz, jlong offset, jbooleanArray array) {
Andreas Huber2631df72017-11-01 10:19:44 -0700535 ScopedBooleanArrayRO autoArray(env, array);
Andreas Huber0eb37e02017-10-31 11:51:50 -0700536
537 if (array == nullptr) {
Andreas Huber2631df72017-11-01 10:19:44 -0700538 /* NullpointerException already pending */
Andreas Huber0eb37e02017-10-31 11:51:50 -0700539 return;
540 }
541
542 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
543
Andreas Huber2631df72017-11-01 10:19:44 -0700544 if ((offset + autoArray.size() * sizeof(bool)) > blob->size()) {
Andreas Huber0eb37e02017-10-31 11:51:50 -0700545 signalExceptionForError(env, -ERANGE);
546 return;
547 }
548
Andreas Huber2631df72017-11-01 10:19:44 -0700549 const jboolean *src = autoArray.get();
Andreas Huber0eb37e02017-10-31 11:51:50 -0700550
551 bool *dst = reinterpret_cast<bool *>(
552 static_cast<uint8_t *>(blob->data()) + offset);
553
Andreas Huber2631df72017-11-01 10:19:44 -0700554 for (size_t i = 0; i < autoArray.size(); ++i) {
Andreas Huber0eb37e02017-10-31 11:51:50 -0700555 dst[i] = src[i];
556 }
Andreas Huber0eb37e02017-10-31 11:51:50 -0700557}
558
Andreas Huber9266f992016-08-25 11:21:21 -0700559static void JHwBlob_native_putBlob(
560 JNIEnv *env, jobject thiz, jlong offset, jobject blobObj) {
561 if (blobObj == nullptr) {
562 jniThrowException(env, "java/lang/NullPointerException", nullptr);
563 return;
564 }
565
566 sp<JHwBlob> blob = JHwBlob::GetNativeContext(env, thiz);
567 sp<JHwBlob> subBlob = JHwBlob::GetNativeContext(env, blobObj);
568
569 blob->putBlob(offset, subBlob);
570}
571
572static jlong JHwBlob_native_handle(JNIEnv *env, jobject thiz) {
573 size_t handle;
574 status_t err = JHwBlob::GetNativeContext(env, thiz)->getHandle(&handle);
575
576 if (err != OK) {
577 signalExceptionForError(env, err);
578 return 0;
579 }
580
581 return handle;
582}
583
584static JNINativeMethod gMethods[] = {
585 { "native_init", "()J", (void *)JHwBlob_native_init },
586 { "native_setup", "(I)V", (void *)JHwBlob_native_setup },
587
588 { "getBool", "(J)Z", (void *)JHwBlob_native_getBool },
589 { "getInt8", "(J)B", (void *)JHwBlob_native_getInt8 },
590 { "getInt16", "(J)S", (void *)JHwBlob_native_getInt16 },
591 { "getInt32", "(J)I", (void *)JHwBlob_native_getInt32 },
592 { "getInt64", "(J)J", (void *)JHwBlob_native_getInt64 },
593 { "getFloat", "(J)F", (void *)JHwBlob_native_getFloat },
594 { "getDouble", "(J)D", (void *)JHwBlob_native_getDouble },
595 { "getString", "(J)Ljava/lang/String;", (void *)JHwBlob_native_getString },
596
Andreas Huber0eb37e02017-10-31 11:51:50 -0700597 { "copyToBoolArray", "(J[ZI)V", (void *)JHwBlob_native_copyToBoolArray },
598 { "copyToInt8Array", "(J[BI)V", (void *)JHwBlob_native_copyToInt8Array },
599 { "copyToInt16Array", "(J[SI)V", (void *)JHwBlob_native_copyToInt16Array },
600 { "copyToInt32Array", "(J[II)V", (void *)JHwBlob_native_copyToInt32Array },
601 { "copyToInt64Array", "(J[JI)V", (void *)JHwBlob_native_copyToInt64Array },
602 { "copyToFloatArray", "(J[FI)V", (void *)JHwBlob_native_copyToFloatArray },
603 { "copyToDoubleArray", "(J[DI)V", (void *)JHwBlob_native_copyToDoubleArray },
604
Andreas Huber9266f992016-08-25 11:21:21 -0700605 { "putBool", "(JZ)V", (void *)JHwBlob_native_putBool },
606 { "putInt8", "(JB)V", (void *)JHwBlob_native_putInt8 },
607 { "putInt16", "(JS)V", (void *)JHwBlob_native_putInt16 },
608 { "putInt32", "(JI)V", (void *)JHwBlob_native_putInt32 },
609 { "putInt64", "(JJ)V", (void *)JHwBlob_native_putInt64 },
610 { "putFloat", "(JF)V", (void *)JHwBlob_native_putFloat },
611 { "putDouble", "(JD)V", (void *)JHwBlob_native_putDouble },
612 { "putString", "(JLjava/lang/String;)V", (void *)JHwBlob_native_putString },
Nirav Atre9850dd92018-07-24 17:03:44 -0700613 { "putNativeHandle", "(JL" PACKAGE_PATH "/NativeHandle;)V",
614 (void*)JHwBlob_native_putNativeHandle },
Andreas Huber9266f992016-08-25 11:21:21 -0700615
Andreas Huber0eb37e02017-10-31 11:51:50 -0700616 { "putBoolArray", "(J[Z)V", (void *)JHwBlob_native_putBoolArray },
617 { "putInt8Array", "(J[B)V", (void *)JHwBlob_native_putInt8Array },
618 { "putInt16Array", "(J[S)V", (void *)JHwBlob_native_putInt16Array },
619 { "putInt32Array", "(J[I)V", (void *)JHwBlob_native_putInt32Array },
620 { "putInt64Array", "(J[J)V", (void *)JHwBlob_native_putInt64Array },
621 { "putFloatArray", "(J[F)V", (void *)JHwBlob_native_putFloatArray },
622 { "putDoubleArray", "(J[D)V", (void *)JHwBlob_native_putDoubleArray },
623
Andreas Huber9266f992016-08-25 11:21:21 -0700624 { "putBlob", "(JL" PACKAGE_PATH "/HwBlob;)V",
625 (void *)JHwBlob_native_putBlob },
626
627 { "handle", "()J", (void *)JHwBlob_native_handle },
628};
629
630namespace android {
631
632int register_android_os_HwBlob(JNIEnv *env) {
633 return RegisterMethodsOrDie(env, CLASS_PATH, gMethods, NELEM(gMethods));
634}
635
636} // namespace android
637