static void CameraMetadata_writeValues(JNIEnv *env, jobject thiz, jint tag, jbyteArray src) { ALOGV("%s (tag = %d)", __FUNCTION__, tag); CameraMetadata* metadata = CameraMetadata_getPointerThrow(env, thiz); if (metadata == NULL) return; int tagType = get_camera_metadata_tag_type(tag); if (tagType == -1) { jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Tag (%d) did not have a type", tag); return; } status_t res; if (src == NULL) { // If array is NULL, delete the entry if (metadata->exists(tag)) { res = metadata->erase(tag); ALOGV("%s: Erase values (res = %d)", __FUNCTION__, res); } else { res = OK; ALOGV("%s: Don't need to erase", __FUNCTION__); } } else { // Copy from java array into native array ScopedByteArrayRO arrayReader(env, src); if (arrayReader.get() == NULL) return; res = Helpers::updateAny(metadata, static_cast<uint32_t>(tag), tagType, arrayReader.get(), arrayReader.size()); ALOGV("%s: Update values (res = %d)", __FUNCTION__, res); } if (res == OK) { return; } else if (res == BAD_VALUE) { jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Src byte array was poorly formed"); } else if (res == INVALID_OPERATION) { jniThrowExceptionFmt(env, "java/lang/IllegalStateException", "Internal error while trying to update metadata"); } else { jniThrowExceptionFmt(env, "java/lang/IllegalStateException", "Unknown error (%d) while trying to update " "metadata", res); } }
static jbyteArray CameraMetadata_readValues(JNIEnv *env, jobject thiz, jint tag) { ALOGV("%s (tag = %d)", __FUNCTION__, tag); CameraMetadata* metadata = CameraMetadata_getPointerThrow(env, thiz); if (metadata == NULL) return NULL; int tagType = get_camera_metadata_tag_type(tag); if (tagType == -1) { jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException", "Tag (%d) did not have a type", tag); return NULL; } size_t tagSize = Helpers::getTypeSize(tagType); camera_metadata_entry entry = metadata->find(tag); if (entry.count == 0) { if (!metadata->exists(tag)) { ALOGV("%s: Tag %d does not have any entries", __FUNCTION__, tag); return NULL; } else { // OK: we will return a 0-sized array. ALOGV("%s: Tag %d had an entry, but it had 0 data", __FUNCTION__, tag); } } jsize byteCount = entry.count * tagSize; jbyteArray byteArray = env->NewByteArray(byteCount); if (env->ExceptionCheck()) return NULL; // Copy into java array from native array ScopedByteArrayRW arrayWriter(env, byteArray); memcpy(arrayWriter.get(), entry.data.u8, byteCount); return byteArray; }