Merge "Frameworks/base: Consistency in core/jni"

This commit is contained in:
Andreas Gampe
2014-11-21 18:18:35 +00:00
committed by Gerrit Code Review
104 changed files with 884 additions and 1193 deletions

View File

@@ -265,6 +265,10 @@ LOCAL_MODULE:= libandroid_runtime
# off a GCC warning that Clang doesn't know. # off a GCC warning that Clang doesn't know.
LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code -Wno-unknown-pragmas LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code -Wno-unknown-pragmas
# -Wno-c++11-extensions: Clang warns about Skia using the C++11 override keyword, but this project
# is not being compiled with that level. Remove once this has changed.
LOCAL_CFLAGS += -Wno-c++11-extensions
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
include $(call all-makefiles-under,$(LOCAL_PATH)) include $(call all-makefiles-under,$(LOCAL_PATH))

View File

@@ -1,5 +1,5 @@
#ifndef AutoDecodeCancel_DEFINED #ifndef _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_
#define AutoDecodeCancel_DEFINED #define _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_
#include <jni.h> #include <jni.h>
#include "SkImageDecoder.h" #include "SkImageDecoder.h"
@@ -24,4 +24,4 @@ private:
#endif #endif
}; };
#endif #endif // _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_

View File

@@ -15,16 +15,12 @@
#include "android_nio_utils.h" #include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h" #include "CreateJavaOutputStreamAdaptor.h"
#include "core_jni_helpers.h"
#include <jni.h> #include <jni.h>
#include <Caches.h> #include <Caches.h>
#if 0
#define TRACE_BITMAP(code) code
#else
#define TRACE_BITMAP(code)
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Conversions to/from SkColor, for get/setPixels, and the create method, which // Conversions to/from SkColor, for get/setPixels, and the create method, which
// is basically like setPixels // is basically like setPixels
@@ -876,8 +872,6 @@ static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapHandle) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h>
static JNINativeMethod gBitmapMethods[] = { static JNINativeMethod gBitmapMethods[] = {
{ "nativeCreate", "([IIIIIIZ)Landroid/graphics/Bitmap;", { "nativeCreate", "([IIIIIIZ)Landroid/graphics/Bitmap;",
(void*)Bitmap_creator }, (void*)Bitmap_creator },
@@ -917,10 +911,8 @@ static JNINativeMethod gBitmapMethods[] = {
{ "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw },
}; };
#define kClassPathName "android/graphics/Bitmap"
int register_android_graphics_Bitmap(JNIEnv* env) int register_android_graphics_Bitmap(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, return android::RegisterMethodsOrDie(env, "android/graphics/Bitmap", gBitmapMethods,
gBitmapMethods, SK_ARRAY_COUNT(gBitmapMethods)); NELEM(gBitmapMethods));
} }

View File

@@ -15,7 +15,7 @@
#include "JNIHelp.h" #include "JNIHelp.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <androidfw/Asset.h> #include <androidfw/Asset.h>
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
#include <cutils/compiler.h> #include <cutils/compiler.h>
@@ -573,52 +573,40 @@ static JNINativeMethod gOptionsMethods[] = {
{ "requestCancel", "()V", (void*)nativeRequestCancel } { "requestCancel", "()V", (void*)nativeRequestCancel }
}; };
static jfieldID getFieldIDCheck(JNIEnv* env, jclass clazz,
const char fieldname[], const char type[]) {
jfieldID id = env->GetFieldID(clazz, fieldname, type);
SkASSERT(id);
return id;
}
int register_android_graphics_BitmapFactory(JNIEnv* env) { int register_android_graphics_BitmapFactory(JNIEnv* env) {
jclass options_class = env->FindClass("android/graphics/BitmapFactory$Options"); jclass options_class = FindClassOrDie(env, "android/graphics/BitmapFactory$Options");
SkASSERT(options_class); gOptions_bitmapFieldID = GetFieldIDOrDie(env, options_class, "inBitmap",
gOptions_bitmapFieldID = getFieldIDCheck(env, options_class, "inBitmap",
"Landroid/graphics/Bitmap;"); "Landroid/graphics/Bitmap;");
gOptions_justBoundsFieldID = getFieldIDCheck(env, options_class, "inJustDecodeBounds", "Z"); gOptions_justBoundsFieldID = GetFieldIDOrDie(env, options_class, "inJustDecodeBounds", "Z");
gOptions_sampleSizeFieldID = getFieldIDCheck(env, options_class, "inSampleSize", "I"); gOptions_sampleSizeFieldID = GetFieldIDOrDie(env, options_class, "inSampleSize", "I");
gOptions_configFieldID = getFieldIDCheck(env, options_class, "inPreferredConfig", gOptions_configFieldID = GetFieldIDOrDie(env, options_class, "inPreferredConfig",
"Landroid/graphics/Bitmap$Config;"); "Landroid/graphics/Bitmap$Config;");
gOptions_premultipliedFieldID = getFieldIDCheck(env, options_class, "inPremultiplied", "Z"); gOptions_premultipliedFieldID = GetFieldIDOrDie(env, options_class, "inPremultiplied", "Z");
gOptions_mutableFieldID = getFieldIDCheck(env, options_class, "inMutable", "Z"); gOptions_mutableFieldID = GetFieldIDOrDie(env, options_class, "inMutable", "Z");
gOptions_ditherFieldID = getFieldIDCheck(env, options_class, "inDither", "Z"); gOptions_ditherFieldID = GetFieldIDOrDie(env, options_class, "inDither", "Z");
gOptions_preferQualityOverSpeedFieldID = getFieldIDCheck(env, options_class, gOptions_preferQualityOverSpeedFieldID = GetFieldIDOrDie(env, options_class,
"inPreferQualityOverSpeed", "Z"); "inPreferQualityOverSpeed", "Z");
gOptions_scaledFieldID = getFieldIDCheck(env, options_class, "inScaled", "Z"); gOptions_scaledFieldID = GetFieldIDOrDie(env, options_class, "inScaled", "Z");
gOptions_densityFieldID = getFieldIDCheck(env, options_class, "inDensity", "I"); gOptions_densityFieldID = GetFieldIDOrDie(env, options_class, "inDensity", "I");
gOptions_screenDensityFieldID = getFieldIDCheck(env, options_class, "inScreenDensity", "I"); gOptions_screenDensityFieldID = GetFieldIDOrDie(env, options_class, "inScreenDensity", "I");
gOptions_targetDensityFieldID = getFieldIDCheck(env, options_class, "inTargetDensity", "I"); gOptions_targetDensityFieldID = GetFieldIDOrDie(env, options_class, "inTargetDensity", "I");
gOptions_widthFieldID = getFieldIDCheck(env, options_class, "outWidth", "I"); gOptions_widthFieldID = GetFieldIDOrDie(env, options_class, "outWidth", "I");
gOptions_heightFieldID = getFieldIDCheck(env, options_class, "outHeight", "I"); gOptions_heightFieldID = GetFieldIDOrDie(env, options_class, "outHeight", "I");
gOptions_mimeFieldID = getFieldIDCheck(env, options_class, "outMimeType", "Ljava/lang/String;"); gOptions_mimeFieldID = GetFieldIDOrDie(env, options_class, "outMimeType", "Ljava/lang/String;");
gOptions_mCancelID = getFieldIDCheck(env, options_class, "mCancel", "Z"); gOptions_mCancelID = GetFieldIDOrDie(env, options_class, "mCancel", "Z");
jclass bitmap_class = env->FindClass("android/graphics/Bitmap"); jclass bitmap_class = FindClassOrDie(env, "android/graphics/Bitmap");
SkASSERT(bitmap_class); gBitmap_nativeBitmapFieldID = GetFieldIDOrDie(env, bitmap_class, "mNativeBitmap", "J");
gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "J"); gBitmap_ninePatchInsetsFieldID = GetFieldIDOrDie(env, bitmap_class, "mNinePatchInsets",
gBitmap_ninePatchInsetsFieldID = getFieldIDCheck(env, bitmap_class, "mNinePatchInsets",
"Landroid/graphics/NinePatch$InsetStruct;"); "Landroid/graphics/NinePatch$InsetStruct;");
gInsetStruct_class = (jclass) env->NewGlobalRef(env->FindClass("android/graphics/NinePatch$InsetStruct")); gInsetStruct_class = MakeGlobalRefOrDie(env, FindClassOrDie(env,
gInsetStruct_constructorMethodID = env->GetMethodID(gInsetStruct_class, "<init>", "(IIIIIIIIFIF)V"); "android/graphics/NinePatch$InsetStruct"));
gInsetStruct_constructorMethodID = GetMethodIDOrDie(env, gInsetStruct_class, "<init>",
"(IIIIIIIIFIF)V");
int ret = AndroidRuntime::registerNativeMethods(env, android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory$Options",
"android/graphics/BitmapFactory$Options", gOptionsMethods, NELEM(gOptionsMethods));
gOptionsMethods, return android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory",
SK_ARRAY_COUNT(gOptionsMethods)); gMethods, NELEM(gMethods));
if (ret) {
return ret;
}
return android::AndroidRuntime::registerNativeMethods(env, "android/graphics/BitmapFactory",
gMethods, SK_ARRAY_COUNT(gMethods));
} }

View File

@@ -1,5 +1,5 @@
#ifndef BitmapFactory_DEFINE #ifndef _ANDROID_GRAPHICS_BITMAP_FACTORY_H_
#define BitmapFactory_DEFINE #define _ANDROID_GRAPHICS_BITMAP_FACTORY_H_
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
@@ -21,4 +21,4 @@ extern jfieldID gOptions_bitmapFieldID;
jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format); jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format);
#endif #endif // _ANDROID_GRAPHICS_BITMAP_FACTORY_H_

View File

@@ -30,7 +30,7 @@
#include "Utils.h" #include "Utils.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "android_util_Binder.h" #include "android_util_Binder.h"
#include "android_nio_utils.h" #include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h" #include "CreateJavaOutputStreamAdaptor.h"
@@ -40,12 +40,6 @@
#include <androidfw/Asset.h> #include <androidfw/Asset.h>
#include <sys/stat.h> #include <sys/stat.h>
#if 0
#define TRACE_BITMAP(code) code
#else
#define TRACE_BITMAP(code)
#endif
using namespace android; using namespace android;
class SkBitmapRegionDecoder { class SkBitmapRegionDecoder {
@@ -273,8 +267,6 @@ static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h>
static JNINativeMethod gBitmapRegionDecoderMethods[] = { static JNINativeMethod gBitmapRegionDecoderMethods[] = {
{ "nativeDecodeRegion", { "nativeDecodeRegion",
"(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;", "(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
@@ -307,10 +299,8 @@ static JNINativeMethod gBitmapRegionDecoderMethods[] = {
}, },
}; };
#define kClassPathName "android/graphics/BitmapRegionDecoder"
int register_android_graphics_BitmapRegionDecoder(JNIEnv* env) int register_android_graphics_BitmapRegionDecoder(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, return android::RegisterMethodsOrDie(env, "android/graphics/BitmapRegionDecoder",
gBitmapRegionDecoderMethods, SK_ARRAY_COUNT(gBitmapRegionDecoderMethods)); gBitmapRegionDecoderMethods, NELEM(gBitmapRegionDecoderMethods));
} }

View File

@@ -1,5 +1,5 @@
#include "jni.h" #include "jni.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "SkCamera.h" #include "SkCamera.h"
@@ -137,16 +137,8 @@ static JNINativeMethod gCameraMethods[] = {
}; };
int register_android_graphics_Camera(JNIEnv* env) { int register_android_graphics_Camera(JNIEnv* env) {
jclass clazz = env->FindClass("android/graphics/Camera"); jclass clazz = android::FindClassOrDie(env, "android/graphics/Camera");
if (clazz == 0) { gNativeInstanceFieldID = android::GetFieldIDOrDie(env, clazz, "native_instance", "J");
return -1; return android::RegisterMethodsOrDie(env, "android/graphics/Camera", gCameraMethods,
} NELEM(gCameraMethods));
gNativeInstanceFieldID = env->GetFieldID(clazz, "native_instance", "J");
if (gNativeInstanceFieldID == 0) {
return -1;
}
return android::AndroidRuntime::registerNativeMethods(env,
"android/graphics/Camera",
gCameraMethods,
SK_ARRAY_COUNT(gCameraMethods));
} }

View File

@@ -17,16 +17,20 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include "Paint.h" #include "Paint.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include <utils/RefBase.h> #include <utils/RefBase.h>
#include <CanvasProperty.h> #include <CanvasProperty.h>
namespace android { namespace android {
using namespace uirenderer;
#ifdef USE_OPENGL_RENDERER #ifdef USE_OPENGL_RENDERER
static const bool kUseOpenGLRenderer = true;
#else
static const bool kUseOpenGLRenderer = false;
#endif
using namespace uirenderer;
static jlong createFloat(JNIEnv* env, jobject clazz, jfloat initialValue) { static jlong createFloat(JNIEnv* env, jobject clazz, jfloat initialValue) {
return reinterpret_cast<jlong>(new CanvasPropertyPrimitive(initialValue)); return reinterpret_cast<jlong>(new CanvasPropertyPrimitive(initialValue));
@@ -37,23 +41,21 @@ static jlong createPaint(JNIEnv* env, jobject clazz, jlong paintPtr) {
return reinterpret_cast<jlong>(new CanvasPropertyPaint(*paint)); return reinterpret_cast<jlong>(new CanvasPropertyPaint(*paint));
} }
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// JNI Glue // JNI Glue
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
const char* const kClassPathName = "android/graphics/CanvasProperty";
static JNINativeMethod gMethods[] = { static JNINativeMethod gMethods[] = {
#ifdef USE_OPENGL_RENDERER
{ "nCreateFloat", "(F)J", (void*) createFloat }, { "nCreateFloat", "(F)J", (void*) createFloat },
{ "nCreatePaint", "(J)J", (void*) createPaint }, { "nCreatePaint", "(J)J", (void*) createPaint },
#endif
}; };
int register_android_graphics_CanvasProperty(JNIEnv* env) { int register_android_graphics_CanvasProperty(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); if (kUseOpenGLRenderer) {
return RegisterMethodsOrDie(env, "android/graphics/CanvasProperty", gMethods,
NELEM(gMethods));
}
return 0;
} }
}; // namespace android }; // namespace android

View File

@@ -17,7 +17,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "SkColorFilter.h" #include "SkColorFilter.h"
#include "SkColorMatrixFilter.h" #include "SkColorMatrixFilter.h"
@@ -74,18 +74,15 @@ static JNINativeMethod colormatrix_methods[] = {
{ "nativeColorMatrixFilter", "([F)J", (void*) SkColorFilterGlue::CreateColorMatrixFilter }, { "nativeColorMatrixFilter", "([F)J", (void*) SkColorFilterGlue::CreateColorMatrixFilter },
}; };
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_ColorFilter(JNIEnv* env) { int register_android_graphics_ColorFilter(JNIEnv* env) {
int result; android::RegisterMethodsOrDie(env, "android/graphics/ColorFilter", colorfilter_methods,
NELEM(colorfilter_methods));
REG(env, "android/graphics/ColorFilter", colorfilter_methods); android::RegisterMethodsOrDie(env, "android/graphics/PorterDuffColorFilter", porterduff_methods,
REG(env, "android/graphics/PorterDuffColorFilter", porterduff_methods); NELEM(porterduff_methods));
REG(env, "android/graphics/LightingColorFilter", lighting_methods); android::RegisterMethodsOrDie(env, "android/graphics/LightingColorFilter", lighting_methods,
REG(env, "android/graphics/ColorMatrixColorFilter", colormatrix_methods); NELEM(lighting_methods));
android::RegisterMethodsOrDie(env, "android/graphics/ColorMatrixColorFilter",
colormatrix_methods, NELEM(colormatrix_methods));
return 0; return 0;
} }

View File

@@ -1,5 +1,5 @@
#ifndef CreateJavaOutputStream_DEFINED #ifndef _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_
#define CreateJavaOutputStream_DEFINED #define _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_
//#include <android_runtime/AndroidRuntime.h> //#include <android_runtime/AndroidRuntime.h>
#include "jni.h" #include "jni.h"
@@ -38,4 +38,5 @@ SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream,
SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream, SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream,
jbyteArray storage); jbyteArray storage);
#endif
#endif // _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_

View File

@@ -24,6 +24,8 @@
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
#include "core_jni_helpers.h"
#include "SkDrawFilter.h" #include "SkDrawFilter.h"
#include "SkPaintFlagsDrawFilter.h" #include "SkPaintFlagsDrawFilter.h"
#include "SkPaint.h" #include "SkPaint.h"
@@ -103,16 +105,11 @@ static JNINativeMethod paintflags_methods[] = {
{"nativeConstructor","(II)J", (void*) SkDrawFilterGlue::CreatePaintFlagsDF} {"nativeConstructor","(II)J", (void*) SkDrawFilterGlue::CreatePaintFlagsDF}
}; };
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_DrawFilter(JNIEnv* env) { int register_android_graphics_DrawFilter(JNIEnv* env) {
int result; int result = RegisterMethodsOrDie(env, "android/graphics/DrawFilter", drawfilter_methods,
NELEM(drawfilter_methods));
REG(env, "android/graphics/DrawFilter", drawfilter_methods); result |= RegisterMethodsOrDie(env, "android/graphics/PaintFlagsDrawFilter", paintflags_methods,
REG(env, "android/graphics/PaintFlagsDrawFilter", paintflags_methods); NELEM(paintflags_methods));
return 0; return 0;
} }

View File

@@ -17,7 +17,7 @@
#define LOG_TAG "Minikin" #define LOG_TAG "Minikin"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include "SkTypeface.h" #include "SkTypeface.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
@@ -125,9 +125,8 @@ static JNINativeMethod gFontFamilyMethods[] = {
int register_android_graphics_FontFamily(JNIEnv* env) int register_android_graphics_FontFamily(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/graphics/FontFamily", gFontFamilyMethods,
"android/graphics/FontFamily", NELEM(gFontFamilyMethods));
gFontFamilyMethods, NELEM(gFontFamilyMethods));
} }
} }

View File

@@ -1,5 +1,5 @@
#ifndef GraphicsJNI_DEFINED #ifndef _ANDROID_GRAPHICS_GRAPHICS_JNI_H_
#define GraphicsJNI_DEFINED #define _ANDROID_GRAPHICS_GRAPHICS_JNI_H_
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-parameter"
@@ -292,4 +292,4 @@ void doThrowIOE(JNIEnv* env, const char* msg = NULL); // IO Exception
#define NPE_CHECK_RETURN_VOID(env, object) \ #define NPE_CHECK_RETURN_VOID(env, object) \
do { if (NULL == (object)) { doThrowNPE(env); return; } } while (0) do { if (NULL == (object)) { doThrowNPE(env); return; } } while (0)
#endif #endif // _ANDROID_GRAPHICS_GRAPHICS_JNI_H_

View File

@@ -44,6 +44,8 @@
namespace android { namespace android {
static const bool kDebugGlyphs = false;
// Our implementation of the callbacks which Harfbuzz requires by using Skia // Our implementation of the callbacks which Harfbuzz requires by using Skia
// calls. See the Harfbuzz source for references about what these callbacks do. // calls. See the Harfbuzz source for references about what these callbacks do.
@@ -62,9 +64,9 @@ static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
uint16_t glyph = codepoint; uint16_t glyph = codepoint;
paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds); paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds);
#if DEBUG_GLYPHS if (kDebugGlyphs) {
ALOGD("returned glyph for %i: width = %f", codepoint, skWidth); ALOGD("returned glyph for %i: width = %f", codepoint, skWidth);
#endif }
if (width) if (width)
*width = SkScalarToHBFixed(skWidth); *width = SkScalarToHBFixed(skWidth);
if (extents) { if (extents) {

View File

@@ -24,8 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef HarfBuzzNGFaceSkia_h #ifndef _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_
#define HarfBuzzNGFaceSkia_h #define _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_
#include <SkScalar.h> #include <SkScalar.h>
#include <SkPaint.h> #include <SkPaint.h>
@@ -56,4 +56,4 @@ hb_font_t* createFont(hb_face_t* face, SkPaint* paint, float sizeX, float sizeY)
} // namespace android } // namespace android
#endif #endif // _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_

View File

@@ -1,5 +1,5 @@
#include "jni.h" #include "jni.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include "SkInterpolator.h" #include "SkInterpolator.h"
@@ -83,8 +83,6 @@ static JNINativeMethod gInterpolatorMethods[] = {
int register_android_graphics_Interpolator(JNIEnv* env) int register_android_graphics_Interpolator(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator",
"android/graphics/Interpolator", gInterpolatorMethods, NELEM(gInterpolatorMethods));
gInterpolatorMethods,
SK_ARRAY_COUNT(gInterpolatorMethods));
} }

View File

@@ -4,6 +4,8 @@
#include "SkBlurMaskFilter.h" #include "SkBlurMaskFilter.h"
#include "SkTableMaskFilter.h" #include "SkTableMaskFilter.h"
#include "core_jni_helpers.h"
#include <jni.h> #include <jni.h>
static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) { static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) {
@@ -77,20 +79,16 @@ static JNINativeMethod gTableMaskFilterMethods[] = {
{ "nativeNewGamma", "(F)J", (void*)SkMaskFilterGlue::createGammaTable } { "nativeNewGamma", "(F)J", (void*)SkMaskFilterGlue::createGammaTable }
}; };
#include <android_runtime/AndroidRuntime.h>
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_MaskFilter(JNIEnv* env) int register_android_graphics_MaskFilter(JNIEnv* env)
{ {
int result; android::RegisterMethodsOrDie(env, "android/graphics/MaskFilter", gMaskFilterMethods,
NELEM(gMaskFilterMethods));
REG(env, "android/graphics/MaskFilter", gMaskFilterMethods); android::RegisterMethodsOrDie(env, "android/graphics/BlurMaskFilter", gBlurMaskFilterMethods,
REG(env, "android/graphics/BlurMaskFilter", gBlurMaskFilterMethods); NELEM(gBlurMaskFilterMethods));
REG(env, "android/graphics/EmbossMaskFilter", gEmbossMaskFilterMethods); android::RegisterMethodsOrDie(env, "android/graphics/EmbossMaskFilter",
REG(env, "android/graphics/TableMaskFilter", gTableMaskFilterMethods); gEmbossMaskFilterMethods, NELEM(gEmbossMaskFilterMethods));
android::RegisterMethodsOrDie(env, "android/graphics/TableMaskFilter", gTableMaskFilterMethods,
NELEM(gTableMaskFilterMethods));
return 0; return 0;
} }

View File

@@ -17,7 +17,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include "SkMatrix.h" #include "SkMatrix.h"
#include "SkTemplates.h" #include "SkTemplates.h"
@@ -353,11 +353,10 @@ static JNINativeMethod methods[] = {
static jfieldID sNativeInstanceField; static jfieldID sNativeInstanceField;
int register_android_graphics_Matrix(JNIEnv* env) { int register_android_graphics_Matrix(JNIEnv* env) {
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Matrix", methods, int result = RegisterMethodsOrDie(env, "android/graphics/Matrix", methods, NELEM(methods));
sizeof(methods) / sizeof(methods[0]));
jclass clazz = env->FindClass("android/graphics/Matrix"); jclass clazz = FindClassOrDie(env, "android/graphics/Matrix");
sNativeInstanceField = env->GetFieldID(clazz, "native_instance", "J"); sNativeInstanceField = GetFieldIDOrDie(env, clazz, "native_instance", "J");
return result; return result;
} }

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _ANDROID_GRAPHICS_MATRIX_H #ifndef _ANDROID_GRAPHICS_MATRIX_H_
#define _ANDROID_GRAPHICS_MATRIX_H #define _ANDROID_GRAPHICS_MATRIX_H_
#include "jni.h" #include "jni.h"
#include "SkMatrix.h" #include "SkMatrix.h"
@@ -27,4 +27,4 @@ extern SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrix
} // namespace android } // namespace android
#endif // _ANDROID_GRAPHICS_MATRIX_H #endif // _ANDROID_GRAPHICS_MATRIX_H_

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef ANDROID_MINIKIN_SKIA_H #ifndef _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
#define ANDROID_MINIKIN_SKIA_H #define _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
#include <minikin/MinikinFont.h> #include <minikin/MinikinFont.h>
@@ -54,4 +54,4 @@ private:
} // namespace android } // namespace android
#endif // ANDROID_MINIKIN_SKIA_H #endif // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_

View File

@@ -21,8 +21,8 @@
// TODO: does this really need to be separate from MinikinSkia? // TODO: does this really need to be separate from MinikinSkia?
#ifndef ANDROID_MINIKIN_UTILS_H #ifndef _ANDROID_GRAPHICS_MINIKIN_UTILS_H_
#define ANDROID_MINIKIN_UTILS_H #define _ANDROID_GRAPHICS_MINIKIN_UTILS_H_
#include <minikin/Layout.h> #include <minikin/Layout.h>
#include "Paint.h" #include "Paint.h"
@@ -81,4 +81,4 @@ public:
} // namespace android } // namespace android
#endif // ANDROID_MINIKIN_UTILS_H #endif // _ANDROID_GRAPHICS_MINIKIN_UTILS_H_

View File

@@ -13,11 +13,7 @@
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
#include <netinet/in.h> #include <netinet/in.h>
#if 0 #include "core_jni_helpers.h"
#define TRACE_BITMAP(code) code
#else
#define TRACE_BITMAP(code)
#endif
static jclass gMovie_class; static jclass gMovie_class;
static jmethodID gMovie_constructorMethodID; static jmethodID gMovie_constructorMethodID;
@@ -138,8 +134,6 @@ static void movie_destructor(JNIEnv* env, jobject, jlong movieHandle) {
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h>
static JNINativeMethod gMethods[] = { static JNINativeMethod gMethods[] = {
{ "width", "()I", (void*)movie_width }, { "width", "()I", (void*)movie_width },
{ "height", "()I", (void*)movie_height }, { "height", "()I", (void*)movie_height },
@@ -157,22 +151,14 @@ static JNINativeMethod gMethods[] = {
(void*)movie_decodeByteArray }, (void*)movie_decodeByteArray },
}; };
#define kClassPathName "android/graphics/Movie"
#define RETURN_ERR_IF_NULL(value) do { if (!(value)) { assert(0); return -1; } } while (false)
int register_android_graphics_Movie(JNIEnv* env) int register_android_graphics_Movie(JNIEnv* env)
{ {
gMovie_class = env->FindClass(kClassPathName); gMovie_class = android::FindClassOrDie(env, "android/graphics/Movie");
RETURN_ERR_IF_NULL(gMovie_class); gMovie_class = android::MakeGlobalRefOrDie(env, gMovie_class);
gMovie_class = (jclass)env->NewGlobalRef(gMovie_class);
gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(J)V"); gMovie_constructorMethodID = android::GetMethodIDOrDie(env, gMovie_class, "<init>", "(J)V");
RETURN_ERR_IF_NULL(gMovie_constructorMethodID);
gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "J"); gMovie_nativeInstanceID = android::GetFieldIDOrDie(env, gMovie_class, "mNativeMovie", "J");
RETURN_ERR_IF_NULL(gMovie_nativeInstanceID);
return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, return android::RegisterMethodsOrDie(env, "android/graphics/Movie", gMethods, NELEM(gMethods));
gMethods, SK_ARRAY_COUNT(gMethods));
} }

View File

@@ -30,6 +30,7 @@
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "core_jni_helpers.h"
extern void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, const SkBitmap& bitmap, extern void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, const SkBitmap& bitmap,
const android::Res_png_9patch& chunk, const SkPaint* paint, SkRegion** outRegion); const android::Res_png_9patch& chunk, const SkPaint* paint, SkRegion** outRegion);
@@ -176,8 +177,6 @@ public:
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h>
static JNINativeMethod gNinePatchMethods[] = { static JNINativeMethod gNinePatchMethods[] = {
{ "isNinePatchChunk", "([B)Z", (void*) SkNinePatchGlue::isNinePatchChunk }, { "isNinePatchChunk", "([B)Z", (void*) SkNinePatchGlue::isNinePatchChunk },
{ "validateNinePatchChunk", "(J[B)J", (void*) SkNinePatchGlue::validateNinePatchChunk }, { "validateNinePatchChunk", "(J[B)J", (void*) SkNinePatchGlue::validateNinePatchChunk },
@@ -189,6 +188,6 @@ static JNINativeMethod gNinePatchMethods[] = {
}; };
int register_android_graphics_NinePatch(JNIEnv* env) { int register_android_graphics_NinePatch(JNIEnv* env) {
return android::AndroidRuntime::registerNativeMethods(env, return android::RegisterMethodsOrDie(env,
"android/graphics/NinePatch", gNinePatchMethods, SK_ARRAY_COUNT(gNinePatchMethods)); "android/graphics/NinePatch", gNinePatchMethods, NELEM(gNinePatchMethods));
} }

View File

@@ -23,20 +23,16 @@
#include "SkBitmap.h" #include "SkBitmap.h"
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkColorPriv.h"
#include "SkNinePatch.h" #include "SkNinePatch.h"
#include "SkPaint.h" #include "SkPaint.h"
#include "SkUnPreMultiply.h" #include "SkUnPreMultiply.h"
#define USE_TRACE
#ifdef USE_TRACE
static bool gTrace;
#endif
#include "SkColorPriv.h"
#include <utils/Log.h> #include <utils/Log.h>
static const bool kUseTrace = true;
static bool gTrace = false;
static bool getColor(const SkBitmap& bitmap, int x, int y, SkColor* c) { static bool getColor(const SkBitmap& bitmap, int x, int y, SkColor* c) {
switch (bitmap.colorType()) { switch (bitmap.colorType()) {
case kN32_SkColorType: case kN32_SkColorType:
@@ -128,37 +124,34 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
return; return;
} }
#ifdef USE_TRACE if (kUseTrace) {
gTrace = true; gTrace = true;
#endif }
SkASSERT(canvas || outRegion); SkASSERT(canvas || outRegion);
#ifdef USE_TRACE if (kUseTrace) {
if (canvas) { if (canvas) {
const SkMatrix& m = canvas->getTotalMatrix(); const SkMatrix& m = canvas->getTotalMatrix();
ALOGV("ninepatch [%g %g %g] [%g %g %g]\n", ALOGV("ninepatch [%g %g %g] [%g %g %g]\n",
SkScalarToFloat(m[0]), SkScalarToFloat(m[1]), SkScalarToFloat(m[2]), SkScalarToFloat(m[0]), SkScalarToFloat(m[1]), SkScalarToFloat(m[2]),
SkScalarToFloat(m[3]), SkScalarToFloat(m[4]), SkScalarToFloat(m[5])); SkScalarToFloat(m[3]), SkScalarToFloat(m[4]), SkScalarToFloat(m[5]));
} }
#endif
#ifdef USE_TRACE ALOGV("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()),
if (gTrace) { SkScalarToFloat(bounds.height()));
ALOGV("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()));
ALOGV("======== ninepatch paint bm [%d,%d]\n", bitmap.width(), bitmap.height()); ALOGV("======== ninepatch paint bm [%d,%d]\n", bitmap.width(), bitmap.height());
ALOGV("======== ninepatch xDivs [%d,%d]\n", xDivs[0], xDivs[1]); ALOGV("======== ninepatch xDivs [%d,%d]\n", xDivs[0], xDivs[1]);
ALOGV("======== ninepatch yDivs [%d,%d]\n", yDivs[0], yDivs[1]); ALOGV("======== ninepatch yDivs [%d,%d]\n", yDivs[0], yDivs[1]);
} }
#endif
if (bounds.isEmpty() || if (bounds.isEmpty() ||
bitmap.width() == 0 || bitmap.height() == 0 || bitmap.width() == 0 || bitmap.height() == 0 ||
(paint && paint->getXfermode() == NULL && paint->getAlpha() == 0)) (paint && paint->getXfermode() == NULL && paint->getAlpha() == 0))
{ {
#ifdef USE_TRACE if (kUseTrace) {
if (gTrace) ALOGV("======== abort ninepatch draw\n"); ALOGV("======== abort ninepatch draw\n");
#endif }
return; return;
} }
@@ -202,13 +195,13 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
} }
int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining; int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining;
#ifdef USE_TRACE if (kUseTrace) {
ALOGV("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n", ALOGV("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n",
bitmap.width(), bitmap.height(), bitmap.width(), bitmap.height(),
SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop), SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()), SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()),
numXDivs, numYDivs); numXDivs, numYDivs);
#endif }
src.fTop = 0; src.fTop = 0;
dst.fTop = bounds.fTop; dst.fTop = bounds.fTop;
@@ -307,15 +300,15 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
goto nextDiv; goto nextDiv;
} }
if (canvas) { if (canvas) {
#ifdef USE_TRACE if (kUseTrace) {
ALOGV("-- src [%d %d %d %d] dst [%g %g %g %g]\n", ALOGV("-- src [%d %d %d %d] dst [%g %g %g %g]\n",
src.fLeft, src.fTop, src.width(), src.height(), src.fLeft, src.fTop, src.width(), src.height(),
SkScalarToFloat(dst.fLeft), SkScalarToFloat(dst.fTop), SkScalarToFloat(dst.fLeft), SkScalarToFloat(dst.fTop),
SkScalarToFloat(dst.width()), SkScalarToFloat(dst.height())); SkScalarToFloat(dst.width()), SkScalarToFloat(dst.height()));
if (2 == src.width() && SkIntToScalar(5) == dst.width()) { if (2 == src.width() && SkIntToScalar(5) == dst.width()) {
ALOGV("--- skip patch\n"); ALOGV("--- skip patch\n");
}
} }
#endif
drawStretchyPatch(canvas, src, dst, bitmap, *paint, initColor, drawStretchyPatch(canvas, src, dst, bitmap, *paint, initColor,
color, hasXfer); color, hasXfer);
} }

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef NinePatchPeeker_h #ifndef _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_
#define NinePatchPeeker_h #define _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_
#include "SkImageDecoder.h" #include "SkImageDecoder.h"
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
@@ -53,4 +53,4 @@ public:
uint8_t mOutlineAlpha; uint8_t mOutlineAlpha;
}; };
#endif // NinePatchPeeker_h #endif // _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_

View File

@@ -21,7 +21,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <ScopedUtfChars.h> #include <ScopedUtfChars.h>
#include "SkBlurDrawLooper.h" #include "SkBlurDrawLooper.h"
@@ -1018,35 +1018,26 @@ static JNINativeMethod methods[] = {
{"native_hasShadowLayer", "(J)Z", (void*)PaintGlue::hasShadowLayer} {"native_hasShadowLayer", "(J)Z", (void*)PaintGlue::hasShadowLayer}
}; };
static jfieldID req_fieldID(jfieldID id) {
SkASSERT(id);
return id;
}
int register_android_graphics_Paint(JNIEnv* env) { int register_android_graphics_Paint(JNIEnv* env) {
gFontMetrics_class = env->FindClass("android/graphics/Paint$FontMetrics"); gFontMetrics_class = FindClassOrDie(env, "android/graphics/Paint$FontMetrics");
SkASSERT(gFontMetrics_class); gFontMetrics_class = MakeGlobalRefOrDie(env, gFontMetrics_class);
gFontMetrics_class = (jclass)env->NewGlobalRef(gFontMetrics_class);
gFontMetrics_fieldID.top = req_fieldID(env->GetFieldID(gFontMetrics_class, "top", "F")); gFontMetrics_fieldID.top = GetFieldIDOrDie(env, gFontMetrics_class, "top", "F");
gFontMetrics_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetrics_class, "ascent", "F")); gFontMetrics_fieldID.ascent = GetFieldIDOrDie(env, gFontMetrics_class, "ascent", "F");
gFontMetrics_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetrics_class, "descent", "F")); gFontMetrics_fieldID.descent = GetFieldIDOrDie(env, gFontMetrics_class, "descent", "F");
gFontMetrics_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetrics_class, "bottom", "F")); gFontMetrics_fieldID.bottom = GetFieldIDOrDie(env, gFontMetrics_class, "bottom", "F");
gFontMetrics_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetrics_class, "leading", "F")); gFontMetrics_fieldID.leading = GetFieldIDOrDie(env, gFontMetrics_class, "leading", "F");
gFontMetricsInt_class = env->FindClass("android/graphics/Paint$FontMetricsInt"); gFontMetricsInt_class = FindClassOrDie(env, "android/graphics/Paint$FontMetricsInt");
SkASSERT(gFontMetricsInt_class); gFontMetricsInt_class = MakeGlobalRefOrDie(env, gFontMetricsInt_class);
gFontMetricsInt_class = (jclass)env->NewGlobalRef(gFontMetricsInt_class);
gFontMetricsInt_fieldID.top = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "top", "I")); gFontMetricsInt_fieldID.top = GetFieldIDOrDie(env, gFontMetricsInt_class, "top", "I");
gFontMetricsInt_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "ascent", "I")); gFontMetricsInt_fieldID.ascent = GetFieldIDOrDie(env, gFontMetricsInt_class, "ascent", "I");
gFontMetricsInt_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "descent", "I")); gFontMetricsInt_fieldID.descent = GetFieldIDOrDie(env, gFontMetricsInt_class, "descent", "I");
gFontMetricsInt_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "bottom", "I")); gFontMetricsInt_fieldID.bottom = GetFieldIDOrDie(env, gFontMetricsInt_class, "bottom", "I");
gFontMetricsInt_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "leading", "I")); gFontMetricsInt_fieldID.leading = GetFieldIDOrDie(env, gFontMetricsInt_class, "leading", "I");
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Paint", methods, return RegisterMethodsOrDie(env, "android/graphics/Paint", methods, NELEM(methods));
sizeof(methods) / sizeof(methods[0]));
return result;
} }
} }

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef ANDROID_GRAPHICS_PAINT_H #ifndef ANDROID_GRAPHICS_PAINT_H_
#define ANDROID_GRAPHICS_PAINT_H #define ANDROID_GRAPHICS_PAINT_H_
#include <SkPaint.h> #include <SkPaint.h>
#include <string> #include <string>
@@ -78,4 +78,4 @@ private:
} // namespace android } // namespace android
#endif // ANDROID_GRAPHICS_PAINT_H #endif // ANDROID_GRAPHICS_PAINT_H_

View File

@@ -22,7 +22,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "SkPath.h" #include "SkPath.h"
#include "SkPathOps.h" #include "SkPathOps.h"
@@ -520,9 +520,7 @@ static JNINativeMethod methods[] = {
}; };
int register_android_graphics_Path(JNIEnv* env) { int register_android_graphics_Path(JNIEnv* env) {
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Path", methods, return RegisterMethodsOrDie(env, "android/graphics/Path", methods, NELEM(methods));
sizeof(methods) / sizeof(methods[0]));
return result;
} }
} }

View File

@@ -1,6 +1,8 @@
#include <jni.h> #include <jni.h>
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include "core_jni_helpers.h"
#include "SkPathEffect.h" #include "SkPathEffect.h"
#include "SkCornerPathEffect.h" #include "SkCornerPathEffect.h"
#include "SkDashPathEffect.h" #include "SkDashPathEffect.h"
@@ -97,24 +99,22 @@ static JNINativeMethod gDiscretePathEffectMethods[] = {
{ "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor } { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
}; };
#include <android_runtime/AndroidRuntime.h>
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_PathEffect(JNIEnv* env) int register_android_graphics_PathEffect(JNIEnv* env)
{ {
int result; android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods,
NELEM(gPathEffectMethods));
REG(env, "android/graphics/PathEffect", gPathEffectMethods); android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect",
REG(env, "android/graphics/ComposePathEffect", gComposePathEffectMethods); gComposePathEffectMethods, NELEM(gComposePathEffectMethods));
REG(env, "android/graphics/SumPathEffect", gSumPathEffectMethods); android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods,
REG(env, "android/graphics/DashPathEffect", gDashPathEffectMethods); NELEM(gSumPathEffectMethods));
REG(env, "android/graphics/PathDashPathEffect", gPathDashPathEffectMethods); android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods,
REG(env, "android/graphics/CornerPathEffect", gCornerPathEffectMethods); NELEM(gDashPathEffectMethods));
REG(env, "android/graphics/DiscretePathEffect", gDiscretePathEffectMethods); android::RegisterMethodsOrDie(env, "android/graphics/PathDashPathEffect",
gPathDashPathEffectMethods, NELEM(gPathDashPathEffectMethods));
android::RegisterMethodsOrDie(env, "android/graphics/CornerPathEffect",
gCornerPathEffectMethods, NELEM(gCornerPathEffectMethods));
android::RegisterMethodsOrDie(env, "android/graphics/DiscretePathEffect",
gDiscretePathEffectMethods, NELEM(gDiscretePathEffectMethods));
return 0; return 0;
} }

View File

@@ -17,7 +17,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include "SkPathMeasure.h" #include "SkPathMeasure.h"
@@ -156,9 +156,7 @@ static JNINativeMethod methods[] = {
}; };
int register_android_graphics_PathMeasure(JNIEnv* env) { int register_android_graphics_PathMeasure(JNIEnv* env) {
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/PathMeasure", methods, return RegisterMethodsOrDie(env, "android/graphics/PathMeasure", methods, NELEM(methods));
sizeof(methods) / sizeof(methods[0]));
return result;
} }
} }

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef ANDROID_GRAPHICS_PICTURE_H #ifndef ANDROID_GRAPHICS_PICTURE_H_
#define ANDROID_GRAPHICS_PICTURE_H #define ANDROID_GRAPHICS_PICTURE_H_
#include "SkPicture.h" #include "SkPicture.h"
#include "SkPictureRecorder.h" #include "SkPictureRecorder.h"
@@ -63,4 +63,4 @@ private:
}; };
}; // namespace android }; // namespace android
#endif // ANDROID_GRAPHICS_PICTURE_H #endif // ANDROID_GRAPHICS_PICTURE_H_

View File

@@ -22,7 +22,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "SkPorterDuff.h" #include "SkPorterDuff.h"
@@ -43,10 +43,7 @@ static JNINativeMethod methods[] = {
}; };
int register_android_graphics_PorterDuff(JNIEnv* env) { int register_android_graphics_PorterDuff(JNIEnv* env) {
int result = AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/graphics/PorterDuffXfermode", methods, NELEM(methods));
"android/graphics/PorterDuffXfermode", methods,
sizeof(methods) / sizeof(methods[0]));
return result;
} }
} }

View File

@@ -24,7 +24,7 @@
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include "Paint.h" #include "Paint.h"
#include "SkLayerRasterizer.h" #include "SkLayerRasterizer.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
// Rasterizer.java holds a pointer (jlong) to this guy // Rasterizer.java holds a pointer (jlong) to this guy
class NativeRasterizer { class NativeRasterizer {
@@ -59,7 +59,6 @@ public:
static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
delete reinterpret_cast<NativeRasterizer *>(objHandle); delete reinterpret_cast<NativeRasterizer *>(objHandle);
} }
}; };
static JNINativeMethod gRasterizerMethods[] = { static JNINativeMethod gRasterizerMethods[] = {
@@ -67,9 +66,8 @@ static JNINativeMethod gRasterizerMethods[] = {
}; };
int register_android_graphics_Rasterizer(JNIEnv* env) { int register_android_graphics_Rasterizer(JNIEnv* env) {
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Rasterizer", gRasterizerMethods, return RegisterMethodsOrDie(env, "android/graphics/Rasterizer", gRasterizerMethods,
sizeof(gRasterizerMethods) / sizeof(gRasterizerMethods[0])); NELEM(gRasterizerMethods));
return result;
} }
class SkLayerRasterizerGlue { class SkLayerRasterizerGlue {
@@ -94,10 +92,8 @@ static JNINativeMethod gLayerRasterizerMethods[] = {
int register_android_graphics_LayerRasterizer(JNIEnv* env) int register_android_graphics_LayerRasterizer(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/graphics/LayerRasterizer",
"android/graphics/LayerRasterizer", gLayerRasterizerMethods, NELEM(gLayerRasterizerMethods));
gLayerRasterizerMethods,
SK_ARRAY_COUNT(gLayerRasterizerMethods));
} }
} }

View File

@@ -23,7 +23,7 @@
#include "android_util_Binder.h" #include "android_util_Binder.h"
#include <jni.h> #include <jni.h>
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
namespace android { namespace android {
@@ -325,19 +325,13 @@ static JNINativeMethod gRegionMethods[] = {
int register_android_graphics_Region(JNIEnv* env) int register_android_graphics_Region(JNIEnv* env)
{ {
jclass clazz = env->FindClass("android/graphics/Region"); jclass clazz = FindClassOrDie(env, "android/graphics/Region");
SkASSERT(clazz);
gRegion_nativeInstanceFieldID = env->GetFieldID(clazz, "mNativeRegion", "J"); gRegion_nativeInstanceFieldID = GetFieldIDOrDie(env, clazz, "mNativeRegion", "J");
SkASSERT(gRegion_nativeInstanceFieldID);
int result = android::AndroidRuntime::registerNativeMethods(env, "android/graphics/Region", RegisterMethodsOrDie(env, "android/graphics/Region", gRegionMethods, NELEM(gRegionMethods));
gRegionMethods, SK_ARRAY_COUNT(gRegionMethods)); return RegisterMethodsOrDie(env, "android/graphics/RegionIterator", gRegionIterMethods,
if (result < 0) NELEM(gRegionIterMethods));
return result;
return android::AndroidRuntime::registerNativeMethods(env, "android/graphics/RegionIterator",
gRegionIterMethods, SK_ARRAY_COUNT(gRegionIterMethods));
} }
SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj) { SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj) {

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _ANDROID_GRAPHICS_REGION_H #ifndef _ANDROID_GRAPHICS_REGION_H_
#define _ANDROID_GRAPHICS_REGION_H #define _ANDROID_GRAPHICS_REGION_H_
#include "jni.h" #include "jni.h"
#include "SkRegion.h" #include "SkRegion.h"
@@ -27,4 +27,4 @@ extern SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject region
} // namespace android } // namespace android
#endif // _ANDROID_GRAPHICS_REGION_H #endif // _ANDROID_GRAPHICS_REGION_H_

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef ANDROID_RTL_PROPERTIES_H #ifndef _ANDROID_GRAPHICS_RTL_PROPERTIES_H_
#define ANDROID_RTL_PROPERTIES_H #define _ANDROID_GRAPHICS_RTL_PROPERTIES_H_
#include <cutils/properties.h> #include <cutils/properties.h>
#include <stdlib.h> #include <stdlib.h>
@@ -45,11 +45,5 @@ static RtlDebugLevel readRtlDebugLevel() {
return kRtlDebugDisabled; return kRtlDebugDisabled;
} }
// Define if we want (1) to have Advances debug values or not (0)
#define DEBUG_ADVANCES 0
// Define if we want (1) to have Glyphs debug values or not (0)
#define DEBUG_GLYPHS 0
} // namespace android } // namespace android
#endif // ANDROID_RTL_PROPERTIES_H #endif // _ANDROID_GRAPHICS_RTL_PROPERTIES_H_

View File

@@ -11,6 +11,8 @@
#include <SkiaShader.h> #include <SkiaShader.h>
#include <Caches.h> #include <Caches.h>
#include "core_jni_helpers.h"
using namespace android::uirenderer; using namespace android::uirenderer;
static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) { static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) {
@@ -260,23 +262,22 @@ static JNINativeMethod gComposeShaderMethods[] = {
{ "nativeCreate2", "(JJI)J", (void*)ComposeShader_create2 }, { "nativeCreate2", "(JJI)J", (void*)ComposeShader_create2 },
}; };
#include <android_runtime/AndroidRuntime.h>
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_Shader(JNIEnv* env) int register_android_graphics_Shader(JNIEnv* env)
{ {
int result; android::RegisterMethodsOrDie(env, "android/graphics/Color", gColorMethods,
NELEM(gColorMethods));
android::RegisterMethodsOrDie(env, "android/graphics/Shader", gShaderMethods,
NELEM(gShaderMethods));
android::RegisterMethodsOrDie(env, "android/graphics/BitmapShader", gBitmapShaderMethods,
NELEM(gBitmapShaderMethods));
android::RegisterMethodsOrDie(env, "android/graphics/LinearGradient", gLinearGradientMethods,
NELEM(gLinearGradientMethods));
android::RegisterMethodsOrDie(env, "android/graphics/RadialGradient", gRadialGradientMethods,
NELEM(gRadialGradientMethods));
android::RegisterMethodsOrDie(env, "android/graphics/SweepGradient", gSweepGradientMethods,
NELEM(gSweepGradientMethods));
android::RegisterMethodsOrDie(env, "android/graphics/ComposeShader", gComposeShaderMethods,
NELEM(gComposeShaderMethods));
REG(env, "android/graphics/Color", gColorMethods); return 0;
REG(env, "android/graphics/Shader", gShaderMethods);
REG(env, "android/graphics/BitmapShader", gBitmapShaderMethods);
REG(env, "android/graphics/LinearGradient", gLinearGradientMethods);
REG(env, "android/graphics/RadialGradient", gRadialGradientMethods);
REG(env, "android/graphics/SweepGradient", gSweepGradientMethods);
REG(env, "android/graphics/ComposeShader", gComposeShaderMethods);
return result;
} }

View File

@@ -24,7 +24,7 @@
#include <gui/GLConsumer.h> #include <gui/GLConsumer.h>
#include <gui/Surface.h> #include <gui/Surface.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/Log.h> #include <utils/Log.h>
#include <utils/misc.h> #include <utils/misc.h>
@@ -359,10 +359,8 @@ static JNINativeMethod gSurfaceTextureMethods[] = {
int register_android_graphics_SurfaceTexture(JNIEnv* env) int register_android_graphics_SurfaceTexture(JNIEnv* env)
{ {
int err = 0; return RegisterMethodsOrDie(env, kSurfaceTextureClassPathName, gSurfaceTextureMethods,
err = AndroidRuntime::registerNativeMethods(env, kSurfaceTextureClassPathName, NELEM(gSurfaceTextureMethods));
gSurfaceTextureMethods, NELEM(gSurfaceTextureMethods));
return err;
} }
} // namespace android } // namespace android

View File

@@ -15,7 +15,7 @@
*/ */
#include "jni.h" #include "jni.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <ScopedPrimitiveArray.h> #include <ScopedPrimitiveArray.h>
@@ -81,8 +81,6 @@ static JNINativeMethod gTypefaceMethods[] = {
int register_android_graphics_Typeface(JNIEnv* env) int register_android_graphics_Typeface(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/graphics/Typeface", gTypefaceMethods,
"android/graphics/Typeface", NELEM(gTypefaceMethods));
gTypefaceMethods,
SK_ARRAY_COUNT(gTypefaceMethods));
} }

View File

@@ -15,8 +15,8 @@
*/ */
#ifndef ANDROID_TYPEFACE_IMPL_H #ifndef _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
#define ANDROID_TYPEFACE_IMPL_H #define _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
#include "jni.h" // for jlong, eventually remove #include "jni.h" // for jlong, eventually remove
#include "SkTypeface.h" #include "SkTypeface.h"
@@ -62,4 +62,4 @@ void TypefaceImpl_setDefault(TypefaceImpl* face);
} }
#endif // ANDROID_TYPEFACE_IMPL_H #endif // _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef UTILS_DEFINED #ifndef _ANDROID_GRAPHICS_UTILS_H_
#define UTILS_DEFINED #define _ANDROID_GRAPHICS_UTILS_H_
#include "SkStream.h" #include "SkStream.h"
@@ -89,4 +89,4 @@ jobject nullObjectReturn(const char msg[]);
}; // namespace android }; // namespace android
#endif #endif // _ANDROID_GRAPHICS_UTILS_H_

View File

@@ -16,7 +16,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "SkAvoidXfermode.h" #include "SkAvoidXfermode.h"
#include "SkPixelXorXfermode.h" #include "SkPixelXorXfermode.h"
@@ -59,19 +59,15 @@ static JNINativeMethod gPixelXorMethods[] = {
{"nativeCreate", "(I)J", (void*) SkXfermodeGlue::pixelxor_create} {"nativeCreate", "(I)J", (void*) SkXfermodeGlue::pixelxor_create}
}; };
#include <android_runtime/AndroidRuntime.h>
#define REG(env, name, array) \
result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
SK_ARRAY_COUNT(array)); \
if (result < 0) return result
int register_android_graphics_Xfermode(JNIEnv* env) { int register_android_graphics_Xfermode(JNIEnv* env) {
int result; android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods,
NELEM(gXfermodeMethods));
REG(env, "android/graphics/Xfermode", gXfermodeMethods); android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods,
REG(env, "android/graphics/AvoidXfermode", gAvoidMethods); NELEM(gXfermodeMethods));
REG(env, "android/graphics/PixelXorXfermode", gPixelXorMethods); android::RegisterMethodsOrDie(env, "android/graphics/AvoidXfermode", gAvoidMethods,
NELEM(gAvoidMethods));
android::RegisterMethodsOrDie(env, "android/graphics/PixelXorXfermode", gPixelXorMethods,
NELEM(gPixelXorMethods));
return 0; return 0;
} }

View File

@@ -4,6 +4,8 @@
#include <ui/PixelFormat.h> #include <ui/PixelFormat.h>
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include "core_jni_helpers.h"
#include <jni.h> #include <jni.h>
YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) { YuvToJpegEncoder* YuvToJpegEncoder::create(int format, int* strides) {
@@ -241,17 +243,13 @@ static jboolean YuvImage_compressToJpeg(JNIEnv* env, jobject, jbyteArray inYuv,
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h>
static JNINativeMethod gYuvImageMethods[] = { static JNINativeMethod gYuvImageMethods[] = {
{ "nativeCompressToJpeg", "([BIII[I[IILjava/io/OutputStream;[B)Z", { "nativeCompressToJpeg", "([BIII[I[IILjava/io/OutputStream;[B)Z",
(void*)YuvImage_compressToJpeg } (void*)YuvImage_compressToJpeg }
}; };
#define kClassPathName "android/graphics/YuvImage"
int register_android_graphics_YuvImage(JNIEnv* env) int register_android_graphics_YuvImage(JNIEnv* env)
{ {
return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, return android::RegisterMethodsOrDie(env, "android/graphics/YuvImage", gYuvImageMethods,
gYuvImageMethods, SK_ARRAY_COUNT(gYuvImageMethods)); NELEM(gYuvImageMethods));
} }

View File

@@ -1,5 +1,5 @@
#ifndef YuvToJpegEncoder_DEFINED #ifndef _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_
#define YuvToJpegEncoder_DEFINED #define _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_
#include "SkTypes.h" #include "SkTypes.h"
#include "SkStream.h" #include "SkStream.h"
@@ -47,16 +47,16 @@ protected:
class Yuv420SpToJpegEncoder : public YuvToJpegEncoder { class Yuv420SpToJpegEncoder : public YuvToJpegEncoder {
public: public:
Yuv420SpToJpegEncoder(int* strides); Yuv420SpToJpegEncoder(int* strides);
virtual ~Yuv420SpToJpegEncoder() {} virtual ~Yuv420SpToJpegEncoder() {}
private: private:
void configSamplingFactors(jpeg_compress_struct* cinfo); void configSamplingFactors(jpeg_compress_struct* cinfo);
void deinterleaveYuv(uint8_t* yuv, int width, int height, void deinterleaveYuv(uint8_t* yuv, int width, int height,
uint8_t*& yPlanar, uint8_t*& uPlanar, uint8_t*& vPlanar); uint8_t*& yPlanar, uint8_t*& uPlanar, uint8_t*& vPlanar);
void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows, void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows,
int rowIndex, int width, int height); int rowIndex, int width, int height);
void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets);
}; };
class Yuv422IToJpegEncoder : public YuvToJpegEncoder { class Yuv422IToJpegEncoder : public YuvToJpegEncoder {
@@ -71,4 +71,4 @@ private:
uint8_t* vRows, int rowIndex, int width, int height); uint8_t* vRows, int rowIndex, int width, int height);
}; };
#endif #endif // _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_

View File

@@ -16,7 +16,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <vector> #include <vector>
#include "Canvas.h" #include "Canvas.h"
@@ -164,10 +164,9 @@ static JNINativeMethod gPdfDocument_Methods[] = {
}; };
int register_android_graphics_pdf_PdfDocument(JNIEnv* env) { int register_android_graphics_pdf_PdfDocument(JNIEnv* env) {
int result = android::AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(
env, "android/graphics/pdf/PdfDocument", gPdfDocument_Methods, env, "android/graphics/pdf/PdfDocument", gPdfDocument_Methods,
NELEM(gPdfDocument_Methods)); NELEM(gPdfDocument_Methods));
return result;
} }
}; };

View File

@@ -20,7 +20,7 @@
#include "fpdfedit.h" #include "fpdfedit.h"
#include "fpdfsave.h" #include "fpdfsave.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include <vector> #include <vector>
#include <utils/Log.h> #include <utils/Log.h>
#include <unistd.h> #include <unistd.h>
@@ -153,7 +153,7 @@ static JNINativeMethod gPdfEditor_Methods[] = {
}; };
int register_android_graphics_pdf_PdfEditor(JNIEnv* env) { int register_android_graphics_pdf_PdfEditor(JNIEnv* env) {
return android::AndroidRuntime::registerNativeMethods( return android::RegisterMethodsOrDie(
env, "android/graphics/pdf/PdfEditor", gPdfEditor_Methods, env, "android/graphics/pdf/PdfEditor", gPdfEditor_Methods,
NELEM(gPdfEditor_Methods)); NELEM(gPdfEditor_Methods));
}; };

View File

@@ -26,7 +26,7 @@
#include "fsdk_rendercontext.h" #include "fsdk_rendercontext.h"
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <vector> #include <vector>
#include <utils/Log.h> #include <utils/Log.h>
#include <unistd.h> #include <unistd.h>
@@ -273,13 +273,13 @@ static JNINativeMethod gPdfRenderer_Methods[] = {
}; };
int register_android_graphics_pdf_PdfRenderer(JNIEnv* env) { int register_android_graphics_pdf_PdfRenderer(JNIEnv* env) {
int result = android::AndroidRuntime::registerNativeMethods( int result = RegisterMethodsOrDie(
env, "android/graphics/pdf/PdfRenderer", gPdfRenderer_Methods, env, "android/graphics/pdf/PdfRenderer", gPdfRenderer_Methods,
NELEM(gPdfRenderer_Methods)); NELEM(gPdfRenderer_Methods));
jclass clazz = env->FindClass("android/graphics/Point"); jclass clazz = FindClassOrDie(env, "android/graphics/Point");
gPointClassInfo.x = env->GetFieldID(clazz, "x", "I"); gPointClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "I");
gPointClassInfo.y = env->GetFieldID(clazz, "y", "I"); gPointClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "I");
return result; return result;
}; };

View File

@@ -29,7 +29,7 @@
#include <SkBitmap.h> #include <SkBitmap.h>
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#undef LOG_TAG #undef LOG_TAG
#define LOG_TAG "OpenGLUtil" #define LOG_TAG "OpenGLUtil"
@@ -732,24 +732,22 @@ static jfieldID elementSizeShiftID;
/* Cache method IDs each time the class is loaded. */ /* Cache method IDs each time the class is loaded. */
static void static void
nativeClassInitBuffer(JNIEnv *_env) nativeClassInitBuffer(JNIEnv *env)
{ {
jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); jclass nioAccessClassLocal = FindClassOrDie(env, "java/nio/NIOAccess");
nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); nioAccessClass = MakeGlobalRefOrDie(env, nioAccessClassLocal);
getBasePointerID = GetStaticMethodIDOrDie(env, nioAccessClass,
jclass bufferClassLocal = _env->FindClass("java/nio/Buffer");
bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal);
getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
"getBasePointer", "(Ljava/nio/Buffer;)J"); "getBasePointer", "(Ljava/nio/Buffer;)J");
getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, getBaseArrayID = GetStaticMethodIDOrDie(env, nioAccessClass,
"getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, getBaseArrayOffsetID = GetStaticMethodIDOrDie(env, nioAccessClass,
"getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); "getBaseArrayOffset", "(Ljava/nio/Buffer;)I");
positionID = _env->GetFieldID(bufferClass, "position", "I");
limitID = _env->GetFieldID(bufferClass, "limit", "I"); jclass bufferClassLocal = FindClassOrDie(env, "java/nio/Buffer");
elementSizeShiftID = bufferClass = MakeGlobalRefOrDie(env, bufferClassLocal);
_env->GetFieldID(bufferClass, "_elementSizeShift", "I"); positionID = GetFieldIDOrDie(env, bufferClass, "position", "I");
limitID = GetFieldIDOrDie(env, bufferClass, "limit", "I");
elementSizeShiftID = GetFieldIDOrDie(env, bufferClass, "_elementSizeShift", "I");
} }
static void * static void *
@@ -1056,12 +1054,7 @@ int register_android_opengl_classes(JNIEnv* env)
int result = 0; int result = 0;
for (int i = 0; i < NELEM(gClasses); i++) { for (int i = 0; i < NELEM(gClasses); i++) {
ClassRegistrationInfo* cri = &gClasses[i]; ClassRegistrationInfo* cri = &gClasses[i];
result = AndroidRuntime::registerNativeMethods(env, result = RegisterMethodsOrDie(env, cri->classPath, cri->methods, cri->methodCount);
cri->classPath, cri->methods, cri->methodCount);
if (result < 0) {
ALOGE("Failed to register %s: %d", cri->classPath, result);
break;
}
} }
return result; return result;
} }

View File

@@ -18,7 +18,7 @@
#include <assert.h> #include <assert.h>
#include "jni.h" #include "jni.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/misc.h> #include <utils/misc.h>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -168,8 +168,7 @@ static JNINativeMethod gMethods[] = {
int register_android_animation_PropertyValuesHolder(JNIEnv* env) int register_android_animation_PropertyValuesHolder(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
kClassPathName, gMethods, NELEM(gMethods));
} }
}; };

View File

@@ -42,12 +42,15 @@
#include "core_jni_helpers.h" #include "core_jni_helpers.h"
#define LOG_TRACE(...) #define LOG_TRACE(...)
//#define LOG_TRACE(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__) //#define LOG_TRACE(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)
namespace android namespace android
{ {
static const bool kLogTrace = false;
static struct { static struct {
jmethodID finish; jmethodID finish;
jmethodID setWindowFlags; jmethodID setWindowFlags;
@@ -78,7 +81,9 @@ static void write_work(int fd, int32_t cmd, int32_t arg1=0, int32_t arg2=0) {
work.arg1 = arg1; work.arg1 = arg1;
work.arg2 = arg2; work.arg2 = arg2;
LOG_TRACE("write_work: cmd=%d", cmd); if (kLogTrace) {
ALOGD("write_work: cmd=%d", cmd);
}
restart: restart:
int res = write(fd, &work, sizeof(work)); int res = write(fd, &work, sizeof(work));
@@ -208,7 +213,9 @@ static int mainWorkCallback(int fd, int events, void* data) {
return 1; return 1;
} }
LOG_TRACE("mainWorkCallback: cmd=%d", work.cmd); if (kLogTrace) {
ALOGD("mainWorkCallback: cmd=%d", work.cmd);
}
switch (work.cmd) { switch (work.cmd) {
case CMD_FINISH: { case CMD_FINISH: {
@@ -251,7 +258,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
jstring externalDataDir, jint sdkVersion, jstring externalDataDir, jint sdkVersion,
jobject jAssetMgr, jbyteArray savedState) jobject jAssetMgr, jbyteArray savedState)
{ {
LOG_TRACE("loadNativeCode_native"); if (kLogTrace) {
ALOGD("loadNativeCode_native");
}
const char* pathStr = env->GetStringUTFChars(path, NULL); const char* pathStr = env->GetStringUTFChars(path, NULL);
NativeCode* code = NULL; NativeCode* code = NULL;
@@ -360,7 +369,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName
static void static void
unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle) unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("unloadNativeCode_native"); if (kLogTrace) {
ALOGD("unloadNativeCode_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
delete code; delete code;
@@ -370,7 +381,9 @@ unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onStart_native(JNIEnv* env, jobject clazz, jlong handle) onStart_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onStart_native"); if (kLogTrace) {
ALOGD("onStart_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onStart != NULL) { if (code->callbacks.onStart != NULL) {
@@ -382,7 +395,9 @@ onStart_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onResume_native(JNIEnv* env, jobject clazz, jlong handle) onResume_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onResume_native"); if (kLogTrace) {
ALOGD("onResume_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onResume != NULL) { if (code->callbacks.onResume != NULL) {
@@ -394,7 +409,9 @@ onResume_native(JNIEnv* env, jobject clazz, jlong handle)
static jbyteArray static jbyteArray
onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle) onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onSaveInstanceState_native"); if (kLogTrace) {
ALOGD("onSaveInstanceState_native");
}
jbyteArray array = NULL; jbyteArray array = NULL;
@@ -421,7 +438,9 @@ onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onPause_native(JNIEnv* env, jobject clazz, jlong handle) onPause_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onPause_native"); if (kLogTrace) {
ALOGD("onPause_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onPause != NULL) { if (code->callbacks.onPause != NULL) {
@@ -433,7 +452,9 @@ onPause_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onStop_native(JNIEnv* env, jobject clazz, jlong handle) onStop_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onStop_native"); if (kLogTrace) {
ALOGD("onStop_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onStop != NULL) { if (code->callbacks.onStop != NULL) {
@@ -445,7 +466,9 @@ onStop_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle) onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onConfigurationChanged_native"); if (kLogTrace) {
ALOGD("onConfigurationChanged_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onConfigurationChanged != NULL) { if (code->callbacks.onConfigurationChanged != NULL) {
@@ -457,7 +480,9 @@ onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle) onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onLowMemory_native"); if (kLogTrace) {
ALOGD("onLowMemory_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onLowMemory != NULL) { if (code->callbacks.onLowMemory != NULL) {
@@ -469,7 +494,9 @@ onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean focused) onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean focused)
{ {
LOG_TRACE("onWindowFocusChanged_native"); if (kLogTrace) {
ALOGD("onWindowFocusChanged_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onWindowFocusChanged != NULL) { if (code->callbacks.onWindowFocusChanged != NULL) {
@@ -481,7 +508,9 @@ onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean f
static void static void
onSurfaceCreated_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface) onSurfaceCreated_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
{ {
LOG_TRACE("onSurfaceCreated_native"); if (kLogTrace) {
ALOGD("onSurfaceCreated_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
code->setSurface(surface); code->setSurface(surface);
@@ -502,7 +531,9 @@ static void
onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface, onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface,
jint format, jint width, jint height) jint format, jint width, jint height)
{ {
LOG_TRACE("onSurfaceChanged_native"); if (kLogTrace) {
ALOGD("onSurfaceChanged_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
sp<ANativeWindow> oldNativeWindow = code->nativeWindow; sp<ANativeWindow> oldNativeWindow = code->nativeWindow;
@@ -542,7 +573,9 @@ onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surfac
static void static void
onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle) onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle)
{ {
LOG_TRACE("onSurfaceRedrawNeeded_native"); if (kLogTrace) {
ALOGD("onSurfaceRedrawNeeded_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) { if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) {
@@ -554,7 +587,9 @@ onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle)
static void static void
onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface) onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
{ {
LOG_TRACE("onSurfaceDestroyed_native"); if (kLogTrace) {
ALOGD("onSurfaceDestroyed_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->nativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) { if (code->nativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) {
@@ -568,7 +603,9 @@ onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surf
static void static void
onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr) onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
{ {
LOG_TRACE("onInputChannelCreated_native"); if (kLogTrace) {
ALOGD("onInputChannelCreated_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onInputQueueCreated != NULL) { if (code->callbacks.onInputQueueCreated != NULL) {
@@ -581,7 +618,9 @@ onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queue
static void static void
onInputQueueDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr) onInputQueueDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
{ {
LOG_TRACE("onInputChannelDestroyed_native"); if (kLogTrace) {
ALOGD("onInputChannelDestroyed_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onInputQueueDestroyed != NULL) { if (code->callbacks.onInputQueueDestroyed != NULL) {
@@ -595,7 +634,9 @@ static void
onContentRectChanged_native(JNIEnv* env, jobject clazz, jlong handle, onContentRectChanged_native(JNIEnv* env, jobject clazz, jlong handle,
jint x, jint y, jint w, jint h) jint x, jint y, jint w, jint h)
{ {
LOG_TRACE("onContentRectChanged_native"); if (kLogTrace) {
ALOGD("onContentRectChanged_native");
}
if (handle != 0) { if (handle != 0) {
NativeCode* code = (NativeCode*)handle; NativeCode* code = (NativeCode*)handle;
if (code->callbacks.onContentRectChanged != NULL) { if (code->callbacks.onContentRectChanged != NULL) {

View File

@@ -18,7 +18,7 @@
#include <utils/Log.h> #include <utils/Log.h>
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <androidfw/BackupHelpers.h> #include <androidfw/BackupHelpers.h>
@@ -106,7 +106,7 @@ static const JNINativeMethod g_methods[] = {
int register_android_backup_BackupDataOutput(JNIEnv* env) int register_android_backup_BackupDataOutput(JNIEnv* env)
{ {
//ALOGD("register_android_backup_BackupDataOutput"); //ALOGD("register_android_backup_BackupDataOutput");
return AndroidRuntime::registerNativeMethods(env, "android/app/backup/BackupDataOutput", return RegisterMethodsOrDie(env, "android/app/backup/BackupDataOutput",
g_methods, NELEM(g_methods)); g_methods, NELEM(g_methods));
} }

View File

@@ -18,7 +18,7 @@
#include <utils/Log.h> #include <utils/Log.h>
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <androidfw/BackupHelpers.h> #include <androidfw/BackupHelpers.h>
@@ -118,7 +118,7 @@ static const JNINativeMethod g_methods[] = {
int register_android_backup_FileBackupHelperBase(JNIEnv* env) int register_android_backup_FileBackupHelperBase(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, "android/app/backup/FileBackupHelperBase", return RegisterMethodsOrDie(env, "android/app/backup/FileBackupHelperBase",
g_methods, NELEM(g_methods)); g_methods, NELEM(g_methods));
} }

View File

@@ -18,7 +18,7 @@
#include <jni.h> #include <jni.h>
#include <JNIHelp.h> #include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <sqlite3.h> #include <sqlite3.h>
#include <sqlite3_android.h> #include <sqlite3_android.h>
@@ -74,15 +74,14 @@ static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) {
static JNINativeMethod sMethods[] = static JNINativeMethod sMethods[] =
{ {
/* name, signature, funcPtr */ /* name, signature, funcPtr */
{ "nativeReleaseMemory", "()I", { "nativeReleaseMemory", "()I", (void*)nativeReleaseMemory },
(void*)nativeReleaseMemory },
}; };
int register_android_database_SQLiteGlobal(JNIEnv *env) int register_android_database_SQLiteGlobal(JNIEnv *env)
{ {
sqliteInitialize(); sqliteInitialize();
return AndroidRuntime::registerNativeMethods(env, "android/database/sqlite/SQLiteGlobal", return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteGlobal",
sMethods, NELEM(sMethods)); sMethods, NELEM(sMethods));
} }

View File

@@ -20,7 +20,7 @@
#include <JNIHelp.h> #include <JNIHelp.h>
#include <jni.h> #include <jni.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/Log.h> #include <utils/Log.h>
#include <utils/String8.h> #include <utils/String8.h>
@@ -110,7 +110,8 @@ static JNINativeMethod method_table[] = {
}; };
int register_android_ddm_DdmHandleNativeHeap(JNIEnv* env) { int register_android_ddm_DdmHandleNativeHeap(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, "android/ddm/DdmHandleNativeHeap", method_table, NELEM(method_table)); return RegisterMethodsOrDie(env, "android/ddm/DdmHandleNativeHeap", method_table,
NELEM(method_table));
} }
}; };

View File

@@ -16,7 +16,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "Canvas.h" #include "Canvas.h"
#include "SkDrawFilter.h" #include "SkDrawFilter.h"
@@ -700,7 +700,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_graphics_Canvas(JNIEnv* env) { int register_android_graphics_Canvas(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, "android/graphics/Canvas", gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, "android/graphics/Canvas", gMethods, NELEM(gMethods));
} }
}; // namespace android }; // namespace android

View File

@@ -16,7 +16,7 @@
#include "jni.h" #include "jni.h"
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "Picture.h" #include "Picture.h"
@@ -106,7 +106,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_graphics_Picture(JNIEnv* env) { int register_android_graphics_Picture(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, "android/graphics/Picture", gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, "android/graphics/Picture", gMethods, NELEM(gMethods));
} }
}; // namespace android }; // namespace android

View File

@@ -21,7 +21,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <android_runtime/android_graphics_SurfaceTexture.h> #include <android_runtime/android_graphics_SurfaceTexture.h>
#include <android_runtime/android_view_Surface.h> #include <android_runtime/android_view_Surface.h>
@@ -991,26 +991,14 @@ struct field {
jfieldID *jfield; jfieldID *jfield;
}; };
static int find_fields(JNIEnv *env, field *fields, int count) static void find_fields(JNIEnv *env, field *fields, int count)
{ {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
field *f = &fields[i]; field *f = &fields[i];
jclass clazz = env->FindClass(f->class_name); jclass clazz = FindClassOrDie(env, f->class_name);
if (clazz == NULL) { jfieldID field = GetFieldIDOrDie(env, clazz, f->field_name, f->field_type);
ALOGE("Can't find %s", f->class_name);
return -1;
}
jfieldID field = env->GetFieldID(clazz, f->field_name, f->field_type);
if (field == NULL) {
ALOGE("Can't find %s.%s", f->class_name, f->field_name);
return -1;
}
*(f->jfield) = field; *(f->jfield) = field;
} }
return 0;
} }
// Get all the required offsets in java class and register native functions // Get all the required offsets in java class and register native functions
@@ -1030,32 +1018,18 @@ int register_android_hardware_Camera(JNIEnv *env)
{ "android/graphics/Rect", "bottom", "I", &fields.rect_bottom }, { "android/graphics/Rect", "bottom", "I", &fields.rect_bottom },
}; };
if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0) find_fields(env, fields_to_find, NELEM(fields_to_find));
return -1;
jclass clazz = env->FindClass("android/hardware/Camera"); jclass clazz = FindClassOrDie(env, "android/hardware/Camera");
fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", fields.post_event = GetStaticMethodIDOrDie(env, clazz, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V"); "(Ljava/lang/Object;IIILjava/lang/Object;)V");
if (fields.post_event == NULL) {
ALOGE("Can't find android/hardware/Camera.postEventFromNative");
return -1;
}
clazz = env->FindClass("android/graphics/Rect"); clazz = FindClassOrDie(env, "android/graphics/Rect");
fields.rect_constructor = env->GetMethodID(clazz, "<init>", "()V"); fields.rect_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
if (fields.rect_constructor == NULL) {
ALOGE("Can't find android/graphics/Rect.Rect()");
return -1;
}
clazz = env->FindClass("android/hardware/Camera$Face"); clazz = FindClassOrDie(env, "android/hardware/Camera$Face");
fields.face_constructor = env->GetMethodID(clazz, "<init>", "()V"); fields.face_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V");
if (fields.face_constructor == NULL) {
ALOGE("Can't find android/hardware/Camera$Face.Face()");
return -1;
}
// Register native functions // Register native functions
return AndroidRuntime::registerNativeMethods(env, "android/hardware/Camera", return RegisterMethodsOrDie(env, "android/hardware/Camera", camMethods, NELEM(camMethods));
camMethods, NELEM(camMethods));
} }

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
@@ -260,17 +260,9 @@ static JNINativeMethod method_table[] = {
int register_android_hardware_SerialPort(JNIEnv *env) int register_android_hardware_SerialPort(JNIEnv *env)
{ {
jclass clazz = env->FindClass("android/hardware/SerialPort"); jclass clazz = FindClassOrDie(env, "android/hardware/SerialPort");
if (clazz == NULL) { field_context = GetFieldIDOrDie(env, clazz, "mNativeContext", "I");
ALOGE("Can't find android/hardware/SerialPort");
return -1;
}
field_context = env->GetFieldID(clazz, "mNativeContext", "I");
if (field_context == NULL) {
ALOGE("Can't find SerialPort.mNativeContext");
return -1;
}
return AndroidRuntime::registerNativeMethods(env, "android/hardware/SerialPort", return RegisterMethodsOrDie(env, "android/hardware/SerialPort",
method_table, NELEM(method_table)); method_table, NELEM(method_table));
} }

View File

@@ -21,7 +21,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <system/sound_trigger.h> #include <system/sound_trigger.h>
#include <soundtrigger/SoundTriggerCallback.h> #include <soundtrigger/SoundTriggerCallback.h>
#include <soundtrigger/SoundTrigger.h> #include <soundtrigger/SoundTrigger.h>
@@ -798,112 +798,102 @@ static JNINativeMethod gModuleMethods[] = {
int register_android_hardware_SoundTrigger(JNIEnv *env) int register_android_hardware_SoundTrigger(JNIEnv *env)
{ {
jclass arrayListClass = env->FindClass("java/util/ArrayList"); jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList");
gArrayListClass = (jclass) env->NewGlobalRef(arrayListClass); gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass);
gArrayListMethods.add = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
jclass uuidClass = env->FindClass("java/util/UUID"); jclass uuidClass = FindClassOrDie(env, "java/util/UUID");
gUUIDClass = (jclass) env->NewGlobalRef(uuidClass); gUUIDClass = MakeGlobalRefOrDie(env, uuidClass);
gUUIDMethods.toString = env->GetMethodID(uuidClass, "toString", "()Ljava/lang/String;"); gUUIDMethods.toString = GetMethodIDOrDie(env, uuidClass, "toString", "()Ljava/lang/String;");
jclass lClass = env->FindClass(kSoundTriggerClassPathName); jclass lClass = FindClassOrDie(env, kSoundTriggerClassPathName);
gSoundTriggerClass = (jclass) env->NewGlobalRef(lClass); gSoundTriggerClass = MakeGlobalRefOrDie(env, lClass);
jclass moduleClass = env->FindClass(kModuleClassPathName); jclass moduleClass = FindClassOrDie(env, kModuleClassPathName);
gModuleClass = (jclass) env->NewGlobalRef(moduleClass); gModuleClass = MakeGlobalRefOrDie(env, moduleClass);
gPostEventFromNative = env->GetStaticMethodID(moduleClass, "postEventFromNative", gPostEventFromNative = GetStaticMethodIDOrDie(env, moduleClass, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V"); "(Ljava/lang/Object;IIILjava/lang/Object;)V");
gModuleFields.mNativeContext = env->GetFieldID(moduleClass, "mNativeContext", "J"); gModuleFields.mNativeContext = GetFieldIDOrDie(env, moduleClass, "mNativeContext", "J");
gModuleFields.mId = env->GetFieldID(moduleClass, "mId", "I"); gModuleFields.mId = GetFieldIDOrDie(env, moduleClass, "mId", "I");
jclass modulePropertiesClass = FindClassOrDie(env, kModulePropertiesClassPathName);
gModulePropertiesClass = MakeGlobalRefOrDie(env, modulePropertiesClass);
gModulePropertiesCstor = GetMethodIDOrDie(env, modulePropertiesClass, "<init>",
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIIZIZIZ)V");
jclass modulePropertiesClass = env->FindClass(kModulePropertiesClassPathName); jclass soundModelClass = FindClassOrDie(env, kSoundModelClassPathName);
gModulePropertiesClass = (jclass) env->NewGlobalRef(modulePropertiesClass); gSoundModelClass = MakeGlobalRefOrDie(env, soundModelClass);
gModulePropertiesCstor = env->GetMethodID(modulePropertiesClass, "<init>", gSoundModelFields.uuid = GetFieldIDOrDie(env, soundModelClass, "uuid", "Ljava/util/UUID;");
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIIZIZIZ)V"); gSoundModelFields.vendorUuid = GetFieldIDOrDie(env, soundModelClass, "vendorUuid",
"Ljava/util/UUID;");
gSoundModelFields.data = GetFieldIDOrDie(env, soundModelClass, "data", "[B");
jclass soundModelClass = env->FindClass(kSoundModelClassPathName); jclass keyphraseClass = FindClassOrDie(env, kKeyphraseClassPathName);
gSoundModelClass = (jclass) env->NewGlobalRef(soundModelClass); gKeyphraseClass = MakeGlobalRefOrDie(env, keyphraseClass);
gSoundModelFields.uuid = env->GetFieldID(soundModelClass, "uuid", "Ljava/util/UUID;"); gKeyphraseFields.id = GetFieldIDOrDie(env, keyphraseClass, "id", "I");
gSoundModelFields.vendorUuid = env->GetFieldID(soundModelClass, "vendorUuid", "Ljava/util/UUID;"); gKeyphraseFields.recognitionModes = GetFieldIDOrDie(env, keyphraseClass, "recognitionModes",
gSoundModelFields.data = env->GetFieldID(soundModelClass, "data", "[B"); "I");
gKeyphraseFields.locale = GetFieldIDOrDie(env, keyphraseClass, "locale", "Ljava/lang/String;");
gKeyphraseFields.text = GetFieldIDOrDie(env, keyphraseClass, "text", "Ljava/lang/String;");
gKeyphraseFields.users = GetFieldIDOrDie(env, keyphraseClass, "users", "[I");
jclass keyphraseClass = env->FindClass(kKeyphraseClassPathName); jclass keyphraseSoundModelClass = FindClassOrDie(env, kKeyphraseSoundModelClassPathName);
gKeyphraseClass = (jclass) env->NewGlobalRef(keyphraseClass); gKeyphraseSoundModelClass = MakeGlobalRefOrDie(env, keyphraseSoundModelClass);
gKeyphraseFields.id = env->GetFieldID(keyphraseClass, "id", "I"); gKeyphraseSoundModelFields.keyphrases = GetFieldIDOrDie(env, keyphraseSoundModelClass,
gKeyphraseFields.recognitionModes = env->GetFieldID(keyphraseClass, "recognitionModes", "I");
gKeyphraseFields.locale = env->GetFieldID(keyphraseClass, "locale", "Ljava/lang/String;");
gKeyphraseFields.text = env->GetFieldID(keyphraseClass, "text", "Ljava/lang/String;");
gKeyphraseFields.users = env->GetFieldID(keyphraseClass, "users", "[I");
jclass keyphraseSoundModelClass = env->FindClass(kKeyphraseSoundModelClassPathName);
gKeyphraseSoundModelClass = (jclass) env->NewGlobalRef(keyphraseSoundModelClass);
gKeyphraseSoundModelFields.keyphrases = env->GetFieldID(keyphraseSoundModelClass,
"keyphrases", "keyphrases",
"[Landroid/hardware/soundtrigger/SoundTrigger$Keyphrase;"); "[Landroid/hardware/soundtrigger/SoundTrigger$Keyphrase;");
jclass recognitionEventClass = FindClassOrDie(env, kRecognitionEventClassPathName);
jclass recognitionEventClass = env->FindClass(kRecognitionEventClassPathName); gRecognitionEventClass = MakeGlobalRefOrDie(env, recognitionEventClass);
gRecognitionEventClass = (jclass) env->NewGlobalRef(recognitionEventClass); gRecognitionEventCstor = GetMethodIDOrDie(env, recognitionEventClass, "<init>",
gRecognitionEventCstor = env->GetMethodID(recognitionEventClass, "<init>",
"(IIZIIIZLandroid/media/AudioFormat;[B)V"); "(IIZIIIZLandroid/media/AudioFormat;[B)V");
jclass keyphraseRecognitionEventClass = env->FindClass(kKeyphraseRecognitionEventClassPathName); jclass keyphraseRecognitionEventClass = FindClassOrDie(env,
gKeyphraseRecognitionEventClass = (jclass) env->NewGlobalRef(keyphraseRecognitionEventClass); kKeyphraseRecognitionEventClassPathName);
gKeyphraseRecognitionEventCstor = env->GetMethodID(keyphraseRecognitionEventClass, "<init>", gKeyphraseRecognitionEventClass = MakeGlobalRefOrDie(env, keyphraseRecognitionEventClass);
gKeyphraseRecognitionEventCstor = GetMethodIDOrDie(env, keyphraseRecognitionEventClass, "<init>",
"(IIZIIIZLandroid/media/AudioFormat;[B[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;)V"); "(IIZIIIZLandroid/media/AudioFormat;[B[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;)V");
jclass keyRecognitionConfigClass = env->FindClass(kRecognitionConfigClassPathName); jclass keyRecognitionConfigClass = FindClassOrDie(env, kRecognitionConfigClassPathName);
gRecognitionConfigClass = (jclass) env->NewGlobalRef(keyRecognitionConfigClass); gRecognitionConfigClass = MakeGlobalRefOrDie(env, keyRecognitionConfigClass);
gRecognitionConfigFields.captureRequested = env->GetFieldID(keyRecognitionConfigClass, gRecognitionConfigFields.captureRequested = GetFieldIDOrDie(env, keyRecognitionConfigClass,
"captureRequested", "captureRequested", "Z");
"Z"); gRecognitionConfigFields.keyphrases = GetFieldIDOrDie(env, keyRecognitionConfigClass,
gRecognitionConfigFields.keyphrases = env->GetFieldID(keyRecognitionConfigClass, "keyphrases", "[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;");
"keyphrases", gRecognitionConfigFields.data = GetFieldIDOrDie(env, keyRecognitionConfigClass, "data", "[B");
"[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;");
gRecognitionConfigFields.data = env->GetFieldID(keyRecognitionConfigClass,
"data",
"[B");
jclass keyphraseRecognitionExtraClass = env->FindClass(kKeyphraseRecognitionExtraClassPathName); jclass keyphraseRecognitionExtraClass = FindClassOrDie(env,
gKeyphraseRecognitionExtraClass = (jclass) env->NewGlobalRef(keyphraseRecognitionExtraClass); kKeyphraseRecognitionExtraClassPathName);
gKeyphraseRecognitionExtraCstor = env->GetMethodID(keyphraseRecognitionExtraClass, "<init>", gKeyphraseRecognitionExtraClass = MakeGlobalRefOrDie(env, keyphraseRecognitionExtraClass);
"(III[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;)V"); gKeyphraseRecognitionExtraCstor = GetMethodIDOrDie(env, keyphraseRecognitionExtraClass,
gKeyphraseRecognitionExtraFields.id = env->GetFieldID(gKeyphraseRecognitionExtraClass, "id", "I"); "<init>", "(III[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;)V");
gKeyphraseRecognitionExtraFields.recognitionModes = env->GetFieldID(gKeyphraseRecognitionExtraClass, gKeyphraseRecognitionExtraFields.id = GetFieldIDOrDie(env, gKeyphraseRecognitionExtraClass,
"recognitionModes", "I"); "id", "I");
gKeyphraseRecognitionExtraFields.coarseConfidenceLevel = env->GetFieldID(gKeyphraseRecognitionExtraClass, gKeyphraseRecognitionExtraFields.recognitionModes = GetFieldIDOrDie(env,
"coarseConfidenceLevel", "I"); gKeyphraseRecognitionExtraClass, "recognitionModes", "I");
gKeyphraseRecognitionExtraFields.confidenceLevels = env->GetFieldID(gKeyphraseRecognitionExtraClass, gKeyphraseRecognitionExtraFields.coarseConfidenceLevel = GetFieldIDOrDie(env,
"confidenceLevels", gKeyphraseRecognitionExtraClass, "coarseConfidenceLevel", "I");
"[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;"); gKeyphraseRecognitionExtraFields.confidenceLevels = GetFieldIDOrDie(env,
gKeyphraseRecognitionExtraClass, "confidenceLevels",
"[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;");
jclass confidenceLevelClass = env->FindClass(kConfidenceLevelClassPathName); jclass confidenceLevelClass = FindClassOrDie(env, kConfidenceLevelClassPathName);
gConfidenceLevelClass = (jclass) env->NewGlobalRef(confidenceLevelClass); gConfidenceLevelClass = MakeGlobalRefOrDie(env, confidenceLevelClass);
gConfidenceLevelCstor = env->GetMethodID(confidenceLevelClass, "<init>", "(II)V"); gConfidenceLevelCstor = GetMethodIDOrDie(env, confidenceLevelClass, "<init>", "(II)V");
gConfidenceLevelFields.userId = env->GetFieldID(confidenceLevelClass, "userId", "I"); gConfidenceLevelFields.userId = GetFieldIDOrDie(env, confidenceLevelClass, "userId", "I");
gConfidenceLevelFields.confidenceLevel = env->GetFieldID(confidenceLevelClass, gConfidenceLevelFields.confidenceLevel = GetFieldIDOrDie(env, confidenceLevelClass,
"confidenceLevel", "I"); "confidenceLevel", "I");
jclass audioFormatClass = env->FindClass(kAudioFormatClassPathName); jclass audioFormatClass = FindClassOrDie(env, kAudioFormatClassPathName);
gAudioFormatClass = (jclass) env->NewGlobalRef(audioFormatClass); gAudioFormatClass = MakeGlobalRefOrDie(env, audioFormatClass);
gAudioFormatCstor = env->GetMethodID(audioFormatClass, "<init>", "(III)V"); gAudioFormatCstor = GetMethodIDOrDie(env, audioFormatClass, "<init>", "(III)V");
jclass soundModelEventClass = env->FindClass(kSoundModelEventClassPathName); jclass soundModelEventClass = FindClassOrDie(env, kSoundModelEventClassPathName);
gSoundModelEventClass = (jclass) env->NewGlobalRef(soundModelEventClass); gSoundModelEventClass = MakeGlobalRefOrDie(env, soundModelEventClass);
gSoundModelEventCstor = env->GetMethodID(soundModelEventClass, "<init>", gSoundModelEventCstor = GetMethodIDOrDie(env, soundModelEventClass, "<init>", "(II[B)V");
"(II[B)V");
int status = AndroidRuntime::registerNativeMethods(env, RegisterMethodsOrDie(env, kSoundTriggerClassPathName, gMethods, NELEM(gMethods));
kSoundTriggerClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kModuleClassPathName, gModuleMethods, NELEM(gModuleMethods));
if (status == 0) {
status = AndroidRuntime::registerNativeMethods(env,
kModuleClassPathName, gModuleMethods, NELEM(gModuleMethods));
}
return status;
} }

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <usbhost/usbhost.h> #include <usbhost/usbhost.h>
@@ -54,6 +54,6 @@ static JNINativeMethod method_table[] = {
int register_android_hardware_UsbDevice(JNIEnv *env) int register_android_hardware_UsbDevice(JNIEnv *env)
{ {
return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbDevice", return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDevice",
method_table, NELEM(method_table)); method_table, NELEM(method_table));
} }

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <usbhost/usbhost.h> #include <usbhost/usbhost.h>
@@ -268,17 +268,9 @@ static JNINativeMethod method_table[] = {
int register_android_hardware_UsbDeviceConnection(JNIEnv *env) int register_android_hardware_UsbDeviceConnection(JNIEnv *env)
{ {
jclass clazz = env->FindClass("android/hardware/usb/UsbDeviceConnection"); jclass clazz = FindClassOrDie(env, "android/hardware/usb/UsbDeviceConnection");
if (clazz == NULL) { field_context = GetFieldIDOrDie(env, clazz, "mNativeContext", "J");
ALOGE("Can't find android/hardware/usb/UsbDeviceConnection");
return -1;
}
field_context = env->GetFieldID(clazz, "mNativeContext", "J");
if (field_context == NULL) {
ALOGE("Can't find UsbDeviceConnection.mNativeContext");
return -1;
}
return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbDeviceConnection", return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDeviceConnection",
method_table, NELEM(method_table)); method_table, NELEM(method_table));
} }

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <usbhost/usbhost.h> #include <usbhost/usbhost.h>
@@ -215,7 +215,7 @@ int register_android_hardware_UsbRequest(JNIEnv *env)
return -1; return -1;
} }
return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbRequest", return RegisterMethodsOrDie(env, "android/hardware/usb/UsbRequest",
method_table, NELEM(method_table)); method_table, NELEM(method_table));
} }

View File

@@ -16,7 +16,6 @@
*/ */
// #define LOG_NDEBUG 0 // #define LOG_NDEBUG 0
// #define LOG_NNDEBUG 0
#define LOG_TAG "CameraMetadata-JNI" #define LOG_TAG "CameraMetadata-JNI"
#include <utils/Errors.h> #include <utils/Errors.h>
#include <utils/Log.h> #include <utils/Log.h>
@@ -29,7 +28,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_os_Parcel.h" #include "android_os_Parcel.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "android_runtime/android_hardware_camera2_CameraMetadata.h" #include "android_runtime/android_hardware_camera2_CameraMetadata.h"
#include <binder/IServiceManager.h> #include <binder/IServiceManager.h>
@@ -42,13 +41,7 @@
#include <sys/types.h> // for socketpair #include <sys/types.h> // for socketpair
#include <sys/socket.h> // for socketpair #include <sys/socket.h> // for socketpair
#if defined(LOG_NNDEBUG) static const bool kIsDebug = false;
#if !LOG_NNDEBUG
#define ALOGVV ALOGV
#endif
#else
#define ALOGVV(...)
#endif
// fully-qualified class name // fully-qualified class name
#define CAMERA_METADATA_CLASS_NAME "android/hardware/camera2/impl/CameraMetadataNative" #define CAMERA_METADATA_CLASS_NAME "android/hardware/camera2/impl/CameraMetadataNative"
@@ -596,7 +589,7 @@ static int find_fields(JNIEnv *env, field *fields, int count)
int register_android_hardware_camera2_CameraMetadata(JNIEnv *env) int register_android_hardware_camera2_CameraMetadata(JNIEnv *env)
{ {
// Register native functions // Register native functions
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
CAMERA_METADATA_CLASS_NAME, CAMERA_METADATA_CLASS_NAME,
gCameraMetadataMethods, gCameraMetadataMethods,
NELEM(gCameraMetadataMethods)); NELEM(gCameraMetadataMethods));
@@ -650,12 +643,15 @@ static jint CameraMetadata_getTagFromKey(JNIEnv *env, jobject thiz, jstring keyN
const char *str = (i < ANDROID_SECTION_COUNT) ? camera_metadata_section_names[i] : const char *str = (i < ANDROID_SECTION_COUNT) ? camera_metadata_section_names[i] :
vendorSections[i - ANDROID_SECTION_COUNT].string(); vendorSections[i - ANDROID_SECTION_COUNT].string();
ALOGVV("%s: Trying to match against section '%s'", if (kIsDebug) {
__FUNCTION__, str); ALOGV("%s: Trying to match against section '%s'", __FUNCTION__, str);
}
if (strstr(key, str) == key) { // key begins with the section name if (strstr(key, str) == key) { // key begins with the section name
size_t strLength = strlen(str); size_t strLength = strlen(str);
ALOGVV("%s: Key begins with section name", __FUNCTION__); if (kIsDebug) {
ALOGV("%s: Key begins with section name", __FUNCTION__);
}
// section name is the longest we've found so far // section name is the longest we've found so far
if (section == NULL || sectionLength < strLength) { if (section == NULL || sectionLength < strLength) {
@@ -663,7 +659,9 @@ static jint CameraMetadata_getTagFromKey(JNIEnv *env, jobject thiz, jstring keyN
sectionIndex = i; sectionIndex = i;
sectionLength = strLength; sectionLength = strLength;
ALOGVV("%s: Found new best section (%s)", __FUNCTION__, section); if (kIsDebug) {
ALOGV("%s: Found new best section (%s)", __FUNCTION__, section);
}
} }
} }
} }

View File

@@ -36,7 +36,7 @@
#include <img_utils/Input.h> #include <img_utils/Input.h>
#include <img_utils/StripSource.h> #include <img_utils/StripSource.h>
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "android_runtime/android_hardware_camera2_CameraMetadata.h" #include "android_runtime/android_hardware_camera2_CameraMetadata.h"
#include <jni.h> #include <jni.h>
@@ -803,29 +803,20 @@ static TiffWriter* DngCreator_getCreator(JNIEnv* env, jobject thiz) {
static void DngCreator_nativeClassInit(JNIEnv* env, jclass clazz) { static void DngCreator_nativeClassInit(JNIEnv* env, jclass clazz) {
ALOGV("%s:", __FUNCTION__); ALOGV("%s:", __FUNCTION__);
gDngCreatorClassInfo.mNativeContext = env->GetFieldID(clazz, gDngCreatorClassInfo.mNativeContext = GetFieldIDOrDie(env,
ANDROID_DNGCREATOR_CTX_JNI_ID, "J"); clazz, ANDROID_DNGCREATOR_CTX_JNI_ID, "J");
LOG_ALWAYS_FATAL_IF(gDngCreatorClassInfo.mNativeContext == NULL,
"can't find android/hardware/camera2/DngCreator.%s",
ANDROID_DNGCREATOR_CTX_JNI_ID);
jclass outputStreamClazz = env->FindClass("java/io/OutputStream"); jclass outputStreamClazz = FindClassOrDie(env, "java/io/OutputStream");
LOG_ALWAYS_FATAL_IF(outputStreamClazz == NULL, "Can't find java/io/OutputStream class"); gOutputStreamClassInfo.mWriteMethod = GetMethodIDOrDie(env,
gOutputStreamClassInfo.mWriteMethod = env->GetMethodID(outputStreamClazz, "write", "([BII)V"); outputStreamClazz, "write", "([BII)V");
LOG_ALWAYS_FATAL_IF(gOutputStreamClassInfo.mWriteMethod == NULL, "Can't find write method");
jclass inputStreamClazz = env->FindClass("java/io/InputStream"); jclass inputStreamClazz = FindClassOrDie(env, "java/io/InputStream");
LOG_ALWAYS_FATAL_IF(inputStreamClazz == NULL, "Can't find java/io/InputStream class"); gInputStreamClassInfo.mReadMethod = GetMethodIDOrDie(env, inputStreamClazz, "read", "([BII)I");
gInputStreamClassInfo.mReadMethod = env->GetMethodID(inputStreamClazz, "read", "([BII)I"); gInputStreamClassInfo.mSkipMethod = GetMethodIDOrDie(env, inputStreamClazz, "skip", "(J)J");
LOG_ALWAYS_FATAL_IF(gInputStreamClassInfo.mReadMethod == NULL, "Can't find read method");
gInputStreamClassInfo.mSkipMethod = env->GetMethodID(inputStreamClazz, "skip", "(J)J");
LOG_ALWAYS_FATAL_IF(gInputStreamClassInfo.mSkipMethod == NULL, "Can't find skip method");
jclass inputBufferClazz = env->FindClass("java/nio/ByteBuffer"); jclass inputBufferClazz = FindClassOrDie(env, "java/nio/ByteBuffer");
LOG_ALWAYS_FATAL_IF(inputBufferClazz == NULL, "Can't find java/nio/ByteBuffer class"); gInputByteBufferClassInfo.mGetMethod = GetMethodIDOrDie(env,
gInputByteBufferClassInfo.mGetMethod = env->GetMethodID(inputBufferClazz, "get", inputBufferClazz, "get", "([BII)Ljava/nio/ByteBuffer;");
"([BII)Ljava/nio/ByteBuffer;");
LOG_ALWAYS_FATAL_IF(gInputByteBufferClassInfo.mGetMethod == NULL, "Can't find get method");
} }
static void DngCreator_init(JNIEnv* env, jobject thiz, jobject characteristicsPtr, static void DngCreator_init(JNIEnv* env, jobject thiz, jobject characteristicsPtr,
@@ -1985,7 +1976,6 @@ static JNINativeMethod gDngCreatorMethods[] = {
}; };
int register_android_hardware_camera2_DngCreator(JNIEnv *env) { int register_android_hardware_camera2_DngCreator(JNIEnv *env) {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
"android/hardware/camera2/DngCreator", gDngCreatorMethods, "android/hardware/camera2/DngCreator", gDngCreatorMethods, NELEM(gDngCreatorMethods));
NELEM(gDngCreatorMethods));
} }

View File

@@ -23,7 +23,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "android_runtime/android_view_Surface.h" #include "android_runtime/android_view_Surface.h"
#include "android_runtime/android_graphics_SurfaceTexture.h" #include "android_runtime/android_graphics_SurfaceTexture.h"
@@ -719,7 +719,7 @@ static JNINativeMethod gCameraDeviceMethods[] = {
int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv* env) int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv* env)
{ {
// Register native functions // Register native functions
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
CAMERA_DEVICE_CLASS_NAME, CAMERA_DEVICE_CLASS_NAME,
gCameraDeviceMethods, gCameraDeviceMethods,
NELEM(gCameraDeviceMethods)); NELEM(gCameraDeviceMethods));

View File

@@ -22,7 +22,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <ui/GraphicBuffer.h> #include <ui/GraphicBuffer.h>
#include <system/window.h> #include <system/window.h>
@@ -328,7 +328,7 @@ static JNINativeMethod gPerfMeasurementMethods[] = {
int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv* env) int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv* env)
{ {
// Register native functions // Register native functions
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
PERF_MEASUREMENT_CLASS_NAME, PERF_MEASUREMENT_CLASS_NAME,
gPerfMeasurementMethods, gPerfMeasurementMethods,
NELEM(gPerfMeasurementMethods)); NELEM(gPerfMeasurementMethods));

View File

@@ -21,7 +21,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <jni.h> #include <jni.h>
#include <JNIHelp.h> #include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/Log.h> #include <utils/Log.h>
#include <media/AudioRecord.h> #include <media/AudioRecord.h>
@@ -605,59 +605,28 @@ int register_android_media_AudioRecord(JNIEnv *env)
// Get the AudioRecord class // Get the AudioRecord class
jclass audioRecordClass = env->FindClass(kClassPathName); jclass audioRecordClass = FindClassOrDie(env, kClassPathName);
if (audioRecordClass == NULL) {
ALOGE("Can't find %s", kClassPathName);
return -1;
}
// Get the postEvent method // Get the postEvent method
javaAudioRecordFields.postNativeEventInJava = env->GetStaticMethodID( javaAudioRecordFields.postNativeEventInJava = GetStaticMethodIDOrDie(env,
audioRecordClass, audioRecordClass, JAVA_POSTEVENT_CALLBACK_NAME,
JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V"); "(Ljava/lang/Object;IIILjava/lang/Object;)V");
if (javaAudioRecordFields.postNativeEventInJava == NULL) {
ALOGE("Can't find AudioRecord.%s", JAVA_POSTEVENT_CALLBACK_NAME);
return -1;
}
// Get the variables // Get the variables
// mNativeRecorderInJavaObj // mNativeRecorderInJavaObj
javaAudioRecordFields.nativeRecorderInJavaObj = javaAudioRecordFields.nativeRecorderInJavaObj = GetFieldIDOrDie(env,
env->GetFieldID(audioRecordClass, audioRecordClass, JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J");
JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J");
if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
ALOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
return -1;
}
// mNativeCallbackCookie // mNativeCallbackCookie
javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID( javaAudioRecordFields.nativeCallbackCookie = GetFieldIDOrDie(env,
audioRecordClass, audioRecordClass, JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J");
JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J");
if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
ALOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
return -1;
}
// Get the AudioAttributes class and fields // Get the AudioAttributes class and fields
jclass audioAttrClass = env->FindClass(kAudioAttributesClassPathName); jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName);
if (audioAttrClass == NULL) { javaAudioAttrFields.fieldRecSource = GetFieldIDOrDie(env, audioAttrClass, "mSource", "I");
ALOGE("Can't find %s", kAudioAttributesClassPathName); javaAudioAttrFields.fieldFlags = GetFieldIDOrDie(env, audioAttrClass, "mFlags", "I");
return -1; javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env,
} audioAttrClass, "mFormattedTags", "Ljava/lang/String;");
jclass audioAttributesClassRef = (jclass)env->NewGlobalRef(audioAttrClass);
javaAudioAttrFields.fieldRecSource = env->GetFieldID(audioAttributesClassRef, "mSource", "I");
javaAudioAttrFields.fieldFlags = env->GetFieldID(audioAttributesClassRef, "mFlags", "I");
javaAudioAttrFields.fieldFormattedTags =
env->GetFieldID(audioAttributesClassRef, "mFormattedTags", "Ljava/lang/String;");
env->DeleteGlobalRef(audioAttributesClassRef);
if (javaAudioAttrFields.fieldRecSource == NULL
|| javaAudioAttrFields.fieldFlags == NULL
|| javaAudioAttrFields.fieldFormattedTags == NULL) {
ALOGE("Can't initialize AudioAttributes fields");
return -1;
}
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
kClassPathName, gMethods, NELEM(gMethods));
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -22,7 +22,7 @@
#include <jni.h> #include <jni.h>
#include <JNIHelp.h> #include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <media/AudioSystem.h> #include <media/AudioSystem.h>
@@ -1357,99 +1357,94 @@ static JNINativeMethod gEventHandlerMethods[] = {
int register_android_media_AudioSystem(JNIEnv *env) int register_android_media_AudioSystem(JNIEnv *env)
{ {
jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList");
gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass);
gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
jclass arrayListClass = env->FindClass("java/util/ArrayList"); jclass audioHandleClass = FindClassOrDie(env, "android/media/AudioHandle");
gArrayListClass = (jclass) env->NewGlobalRef(arrayListClass); gAudioHandleClass = MakeGlobalRefOrDie(env, audioHandleClass);
gArrayListMethods.add = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); gAudioHandleCstor = GetMethodIDOrDie(env, audioHandleClass, "<init>", "(I)V");
gAudioHandleFields.mId = GetFieldIDOrDie(env, audioHandleClass, "mId", "I");
jclass audioHandleClass = env->FindClass("android/media/AudioHandle"); jclass audioPortClass = FindClassOrDie(env, "android/media/AudioPort");
gAudioHandleClass = (jclass) env->NewGlobalRef(audioHandleClass); gAudioPortClass = MakeGlobalRefOrDie(env, audioPortClass);
gAudioHandleCstor = env->GetMethodID(audioHandleClass, "<init>", "(I)V"); gAudioPortCstor = GetMethodIDOrDie(env, audioPortClass, "<init>",
gAudioHandleFields.mId = env->GetFieldID(audioHandleClass, "mId", "I"); "(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V");
gAudioPortFields.mHandle = GetFieldIDOrDie(env, audioPortClass, "mHandle",
jclass audioPortClass = env->FindClass("android/media/AudioPort");
gAudioPortClass = (jclass) env->NewGlobalRef(audioPortClass);
gAudioPortCstor = env->GetMethodID(audioPortClass, "<init>",
"(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V");
gAudioPortFields.mHandle = env->GetFieldID(audioPortClass, "mHandle",
"Landroid/media/AudioHandle;"); "Landroid/media/AudioHandle;");
gAudioPortFields.mRole = env->GetFieldID(audioPortClass, "mRole", "I"); gAudioPortFields.mRole = GetFieldIDOrDie(env, audioPortClass, "mRole", "I");
gAudioPortFields.mGains = env->GetFieldID(audioPortClass, "mGains", gAudioPortFields.mGains = GetFieldIDOrDie(env, audioPortClass, "mGains",
"[Landroid/media/AudioGain;"); "[Landroid/media/AudioGain;");
gAudioPortFields.mActiveConfig = env->GetFieldID(audioPortClass, "mActiveConfig", gAudioPortFields.mActiveConfig = GetFieldIDOrDie(env, audioPortClass, "mActiveConfig",
"Landroid/media/AudioPortConfig;"); "Landroid/media/AudioPortConfig;");
jclass audioPortConfigClass = env->FindClass("android/media/AudioPortConfig"); jclass audioPortConfigClass = FindClassOrDie(env, "android/media/AudioPortConfig");
gAudioPortConfigClass = (jclass) env->NewGlobalRef(audioPortConfigClass); gAudioPortConfigClass = MakeGlobalRefOrDie(env, audioPortConfigClass);
gAudioPortConfigCstor = env->GetMethodID(audioPortConfigClass, "<init>", gAudioPortConfigCstor = GetMethodIDOrDie(env, audioPortConfigClass, "<init>",
"(Landroid/media/AudioPort;IIILandroid/media/AudioGainConfig;)V"); "(Landroid/media/AudioPort;IIILandroid/media/AudioGainConfig;)V");
gAudioPortConfigFields.mPort = env->GetFieldID(audioPortConfigClass, "mPort", gAudioPortConfigFields.mPort = GetFieldIDOrDie(env, audioPortConfigClass, "mPort",
"Landroid/media/AudioPort;"); "Landroid/media/AudioPort;");
gAudioPortConfigFields.mSamplingRate = env->GetFieldID(audioPortConfigClass, gAudioPortConfigFields.mSamplingRate = GetFieldIDOrDie(env, audioPortConfigClass,
"mSamplingRate", "I"); "mSamplingRate", "I");
gAudioPortConfigFields.mChannelMask = env->GetFieldID(audioPortConfigClass, gAudioPortConfigFields.mChannelMask = GetFieldIDOrDie(env, audioPortConfigClass,
"mChannelMask", "I"); "mChannelMask", "I");
gAudioPortConfigFields.mFormat = env->GetFieldID(audioPortConfigClass, "mFormat", "I"); gAudioPortConfigFields.mFormat = GetFieldIDOrDie(env, audioPortConfigClass, "mFormat", "I");
gAudioPortConfigFields.mGain = env->GetFieldID(audioPortConfigClass, "mGain", gAudioPortConfigFields.mGain = GetFieldIDOrDie(env, audioPortConfigClass, "mGain",
"Landroid/media/AudioGainConfig;"); "Landroid/media/AudioGainConfig;");
gAudioPortConfigFields.mConfigMask = env->GetFieldID(audioPortConfigClass, "mConfigMask", "I"); gAudioPortConfigFields.mConfigMask = GetFieldIDOrDie(env, audioPortConfigClass, "mConfigMask",
"I");
jclass audioDevicePortConfigClass = env->FindClass("android/media/AudioDevicePortConfig"); jclass audioDevicePortConfigClass = FindClassOrDie(env, "android/media/AudioDevicePortConfig");
gAudioDevicePortConfigClass = (jclass) env->NewGlobalRef(audioDevicePortConfigClass); gAudioDevicePortConfigClass = MakeGlobalRefOrDie(env, audioDevicePortConfigClass);
gAudioDevicePortConfigCstor = env->GetMethodID(audioDevicePortConfigClass, "<init>", gAudioDevicePortConfigCstor = GetMethodIDOrDie(env, audioDevicePortConfigClass, "<init>",
"(Landroid/media/AudioDevicePort;IIILandroid/media/AudioGainConfig;)V"); "(Landroid/media/AudioDevicePort;IIILandroid/media/AudioGainConfig;)V");
jclass audioMixPortConfigClass = env->FindClass("android/media/AudioMixPortConfig"); jclass audioMixPortConfigClass = FindClassOrDie(env, "android/media/AudioMixPortConfig");
gAudioMixPortConfigClass = (jclass) env->NewGlobalRef(audioMixPortConfigClass); gAudioMixPortConfigClass = MakeGlobalRefOrDie(env, audioMixPortConfigClass);
gAudioMixPortConfigCstor = env->GetMethodID(audioMixPortConfigClass, "<init>", gAudioMixPortConfigCstor = GetMethodIDOrDie(env, audioMixPortConfigClass, "<init>",
"(Landroid/media/AudioMixPort;IIILandroid/media/AudioGainConfig;)V"); "(Landroid/media/AudioMixPort;IIILandroid/media/AudioGainConfig;)V");
jclass audioDevicePortClass = env->FindClass("android/media/AudioDevicePort"); jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort");
gAudioDevicePortClass = (jclass) env->NewGlobalRef(audioDevicePortClass); gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass);
gAudioDevicePortCstor = env->GetMethodID(audioDevicePortClass, "<init>", gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>",
"(Landroid/media/AudioHandle;[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V"); "(Landroid/media/AudioHandle;[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V");
jclass audioMixPortClass = env->FindClass("android/media/AudioMixPort"); jclass audioMixPortClass = FindClassOrDie(env, "android/media/AudioMixPort");
gAudioMixPortClass = (jclass) env->NewGlobalRef(audioMixPortClass); gAudioMixPortClass = MakeGlobalRefOrDie(env, audioMixPortClass);
gAudioMixPortCstor = env->GetMethodID(audioMixPortClass, "<init>", gAudioMixPortCstor = GetMethodIDOrDie(env, audioMixPortClass, "<init>",
"(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V"); "(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V");
jclass audioGainClass = env->FindClass("android/media/AudioGain"); jclass audioGainClass = FindClassOrDie(env, "android/media/AudioGain");
gAudioGainClass = (jclass) env->NewGlobalRef(audioGainClass); gAudioGainClass = MakeGlobalRefOrDie(env, audioGainClass);
gAudioGainCstor = env->GetMethodID(audioGainClass, "<init>", "(IIIIIIIII)V"); gAudioGainCstor = GetMethodIDOrDie(env, audioGainClass, "<init>", "(IIIIIIIII)V");
jclass audioGainConfigClass = env->FindClass("android/media/AudioGainConfig"); jclass audioGainConfigClass = FindClassOrDie(env, "android/media/AudioGainConfig");
gAudioGainConfigClass = (jclass) env->NewGlobalRef(audioGainConfigClass); gAudioGainConfigClass = MakeGlobalRefOrDie(env, audioGainConfigClass);
gAudioGainConfigCstor = env->GetMethodID(audioGainConfigClass, "<init>", gAudioGainConfigCstor = GetMethodIDOrDie(env, audioGainConfigClass, "<init>",
"(ILandroid/media/AudioGain;II[II)V"); "(ILandroid/media/AudioGain;II[II)V");
gAudioGainConfigFields.mIndex = env->GetFieldID(gAudioGainConfigClass, "mIndex", "I"); gAudioGainConfigFields.mIndex = GetFieldIDOrDie(env, gAudioGainConfigClass, "mIndex", "I");
gAudioGainConfigFields.mMode = env->GetFieldID(audioGainConfigClass, "mMode", "I"); gAudioGainConfigFields.mMode = GetFieldIDOrDie(env, audioGainConfigClass, "mMode", "I");
gAudioGainConfigFields.mChannelMask = env->GetFieldID(audioGainConfigClass, "mChannelMask", gAudioGainConfigFields.mChannelMask = GetFieldIDOrDie(env, audioGainConfigClass, "mChannelMask",
"I"); "I");
gAudioGainConfigFields.mValues = env->GetFieldID(audioGainConfigClass, "mValues", "[I"); gAudioGainConfigFields.mValues = GetFieldIDOrDie(env, audioGainConfigClass, "mValues", "[I");
gAudioGainConfigFields.mRampDurationMs = env->GetFieldID(audioGainConfigClass, gAudioGainConfigFields.mRampDurationMs = GetFieldIDOrDie(env, audioGainConfigClass,
"mRampDurationMs", "I"); "mRampDurationMs", "I");
jclass audioPatchClass = env->FindClass("android/media/AudioPatch"); jclass audioPatchClass = FindClassOrDie(env, "android/media/AudioPatch");
gAudioPatchClass = (jclass) env->NewGlobalRef(audioPatchClass); gAudioPatchClass = MakeGlobalRefOrDie(env, audioPatchClass);
gAudioPatchCstor = env->GetMethodID(audioPatchClass, "<init>", gAudioPatchCstor = GetMethodIDOrDie(env, audioPatchClass, "<init>",
"(Landroid/media/AudioHandle;[Landroid/media/AudioPortConfig;[Landroid/media/AudioPortConfig;)V"); "(Landroid/media/AudioHandle;[Landroid/media/AudioPortConfig;[Landroid/media/AudioPortConfig;)V");
gAudioPatchFields.mHandle = env->GetFieldID(audioPatchClass, "mHandle", gAudioPatchFields.mHandle = GetFieldIDOrDie(env, audioPatchClass, "mHandle",
"Landroid/media/AudioHandle;"); "Landroid/media/AudioHandle;");
jclass eventHandlerClass = env->FindClass(kEventHandlerClassPathName); jclass eventHandlerClass = FindClassOrDie(env, kEventHandlerClassPathName);
gPostEventFromNative = env->GetStaticMethodID(eventHandlerClass, "postEventFromNative", gPostEventFromNative = GetStaticMethodIDOrDie(env, eventHandlerClass, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V"); "(Ljava/lang/Object;IIILjava/lang/Object;)V");
AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback); AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback);
int status = AndroidRuntime::registerNativeMethods(env, RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
kClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kEventHandlerClassPathName, gEventHandlerMethods,
NELEM(gEventHandlerMethods));
if (status == 0) {
status = AndroidRuntime::registerNativeMethods(env,
kEventHandlerClassPathName, gEventHandlerMethods, NELEM(gEventHandlerMethods));
}
return status;
} }

View File

@@ -19,7 +19,7 @@
#include <JNIHelp.h> #include <JNIHelp.h>
#include <JniConstants.h> #include <JniConstants.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "ScopedBytes.h" #include "ScopedBytes.h"
@@ -1062,68 +1062,34 @@ int register_android_media_AudioTrack(JNIEnv *env)
javaAudioTrackFields.postNativeEventInJava = NULL; javaAudioTrackFields.postNativeEventInJava = NULL;
// Get the AudioTrack class // Get the AudioTrack class
jclass audioTrackClass = env->FindClass(kClassPathName); jclass audioTrackClass = FindClassOrDie(env, kClassPathName);
if (audioTrackClass == NULL) {
ALOGE("Can't find %s", kClassPathName);
return -1;
}
// Get the postEvent method // Get the postEvent method
javaAudioTrackFields.postNativeEventInJava = env->GetStaticMethodID( javaAudioTrackFields.postNativeEventInJava = GetStaticMethodIDOrDie(env,
audioTrackClass, audioTrackClass, JAVA_POSTEVENT_CALLBACK_NAME,
JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V"); "(Ljava/lang/Object;IIILjava/lang/Object;)V");
if (javaAudioTrackFields.postNativeEventInJava == NULL) {
ALOGE("Can't find AudioTrack.%s", JAVA_POSTEVENT_CALLBACK_NAME);
return -1;
}
// Get the variables fields // Get the variables fields
// nativeTrackInJavaObj // nativeTrackInJavaObj
javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID( javaAudioTrackFields.nativeTrackInJavaObj = GetFieldIDOrDie(env,
audioTrackClass, audioTrackClass, JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J");
JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J");
if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
ALOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
return -1;
}
// jniData // jniData
javaAudioTrackFields.jniData = env->GetFieldID( javaAudioTrackFields.jniData = GetFieldIDOrDie(env,
audioTrackClass, audioTrackClass, JAVA_JNIDATA_FIELD_NAME, "J");
JAVA_JNIDATA_FIELD_NAME, "J");
if (javaAudioTrackFields.jniData == NULL) {
ALOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
return -1;
}
// fieldStreamType // fieldStreamType
javaAudioTrackFields.fieldStreamType = env->GetFieldID(audioTrackClass, javaAudioTrackFields.fieldStreamType = GetFieldIDOrDie(env,
JAVA_STREAMTYPE_FIELD_NAME, "I"); audioTrackClass, JAVA_STREAMTYPE_FIELD_NAME, "I");
if (javaAudioTrackFields.fieldStreamType == NULL) {
ALOGE("Can't find AudioTrack.%s", JAVA_STREAMTYPE_FIELD_NAME);
return -1;
}
// Get the AudioAttributes class and fields // Get the AudioAttributes class and fields
jclass audioAttrClass = env->FindClass(kAudioAttributesClassPathName); jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName);
if (audioAttrClass == NULL) { javaAudioAttrFields.fieldUsage = GetFieldIDOrDie(env, audioAttrClass, "mUsage", "I");
ALOGE("Can't find %s", kAudioAttributesClassPathName); javaAudioAttrFields.fieldContentType = GetFieldIDOrDie(env,
return -1; audioAttrClass, "mContentType", "I");
} javaAudioAttrFields.fieldFlags = GetFieldIDOrDie(env, audioAttrClass, "mFlags", "I");
jclass audioAttributesClassRef = (jclass)env->NewGlobalRef(audioAttrClass); javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env,
javaAudioAttrFields.fieldUsage = env->GetFieldID(audioAttributesClassRef, "mUsage", "I"); audioAttrClass, "mFormattedTags", "Ljava/lang/String;");
javaAudioAttrFields.fieldContentType
= env->GetFieldID(audioAttributesClassRef, "mContentType", "I");
javaAudioAttrFields.fieldFlags = env->GetFieldID(audioAttributesClassRef, "mFlags", "I");
javaAudioAttrFields.fieldFormattedTags =
env->GetFieldID(audioAttributesClassRef, "mFormattedTags", "Ljava/lang/String;");
env->DeleteGlobalRef(audioAttributesClassRef);
if (javaAudioAttrFields.fieldUsage == NULL || javaAudioAttrFields.fieldContentType == NULL
|| javaAudioAttrFields.fieldFlags == NULL
|| javaAudioAttrFields.fieldFormattedTags == NULL) {
ALOGE("Can't initialize AudioAttributes fields");
return -1;
}
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
} }

View File

@@ -24,7 +24,7 @@
#include <jni.h> #include <jni.h>
#include <JNIHelp.h> #include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/Log.h> #include <utils/Log.h>
#include <media/JetPlayer.h> #include <media/JetPlayer.h>
@@ -517,36 +517,22 @@ static JNINativeMethod gMethods[] = {
int register_android_media_JetPlayer(JNIEnv *env) int register_android_media_JetPlayer(JNIEnv *env)
{ {
jclass jetPlayerClass = NULL;
javaJetPlayerFields.jetClass = NULL; javaJetPlayerFields.jetClass = NULL;
javaJetPlayerFields.postNativeEventInJava = NULL; javaJetPlayerFields.postNativeEventInJava = NULL;
javaJetPlayerFields.nativePlayerInJavaObj = NULL; javaJetPlayerFields.nativePlayerInJavaObj = NULL;
// Get the JetPlayer java class // Get the JetPlayer java class
jetPlayerClass = env->FindClass(kClassPathName); jclass jetPlayerClass = FindClassOrDie(env, kClassPathName);
if (jetPlayerClass == NULL) { javaJetPlayerFields.jetClass = MakeGlobalRefOrDie(env, jetPlayerClass);
ALOGE("Can't find %s", kClassPathName);
return -1;
}
javaJetPlayerFields.jetClass = (jclass)env->NewGlobalRef(jetPlayerClass);
// Get the mNativePlayerInJavaObj variable field // Get the mNativePlayerInJavaObj variable field
javaJetPlayerFields.nativePlayerInJavaObj = env->GetFieldID( javaJetPlayerFields.nativePlayerInJavaObj = GetFieldIDOrDie(env,
jetPlayerClass, jetPlayerClass, JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J");
JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J");
if (javaJetPlayerFields.nativePlayerInJavaObj == NULL) {
ALOGE("Can't find JetPlayer.%s", JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME);
return -1;
}
// Get the callback to post events from this native code to Java // Get the callback to post events from this native code to Java
javaJetPlayerFields.postNativeEventInJava = env->GetStaticMethodID(javaJetPlayerFields.jetClass, javaJetPlayerFields.postNativeEventInJava = GetStaticMethodIDOrDie(env,
JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;III)V"); javaJetPlayerFields.jetClass, JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME,
if (javaJetPlayerFields.postNativeEventInJava == NULL) { "(Ljava/lang/Object;III)V");
ALOGE("Can't find Jet.%s", JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME);
return -1;
}
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
kClassPathName, gMethods, NELEM(gMethods));
} }

View File

@@ -22,7 +22,7 @@
#include "android_os_Parcel.h" #include "android_os_Parcel.h"
#include "android_util_Binder.h" #include "android_util_Binder.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <android_runtime/android_view_Surface.h> #include <android_runtime/android_view_Surface.h>
#include <android_runtime/Log.h> #include <android_runtime/Log.h>
@@ -188,17 +188,15 @@ static JNINativeMethod gMethods[] = {
int register_android_media_RemoteDisplay(JNIEnv* env) int register_android_media_RemoteDisplay(JNIEnv* env)
{ {
int err = AndroidRuntime::registerNativeMethods(env, "android/media/RemoteDisplay", int err = RegisterMethodsOrDie(env, "android/media/RemoteDisplay", gMethods, NELEM(gMethods));
gMethods, NELEM(gMethods));
jclass clazz = env->FindClass("android/media/RemoteDisplay"); jclass clazz = FindClassOrDie(env, "android/media/RemoteDisplay");
gRemoteDisplayClassInfo.notifyDisplayConnected = gRemoteDisplayClassInfo.notifyDisplayConnected = GetMethodIDOrDie(env,
env->GetMethodID(clazz, "notifyDisplayConnected", clazz, "notifyDisplayConnected", "(Landroid/view/Surface;IIII)V");
"(Landroid/view/Surface;IIII)V"); gRemoteDisplayClassInfo.notifyDisplayDisconnected = GetMethodIDOrDie(env,
gRemoteDisplayClassInfo.notifyDisplayDisconnected = clazz, "notifyDisplayDisconnected", "()V");
env->GetMethodID(clazz, "notifyDisplayDisconnected", "()V"); gRemoteDisplayClassInfo.notifyDisplayError = GetMethodIDOrDie(env,
gRemoteDisplayClassInfo.notifyDisplayError = clazz, "notifyDisplayError", "(I)V");
env->GetMethodID(clazz, "notifyDisplayError", "(I)V");
return err; return err;
} }

View File

@@ -23,7 +23,7 @@
#include <jni.h> #include <jni.h>
#include <JNIHelp.h> #include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <utils/Log.h> #include <utils/Log.h>
#include <media/AudioSystem.h> #include <media/AudioSystem.h>
@@ -134,21 +134,10 @@ static JNINativeMethod gMethods[] = {
int register_android_media_ToneGenerator(JNIEnv *env) { int register_android_media_ToneGenerator(JNIEnv *env) {
jclass clazz; jclass clazz = FindClassOrDie(env, "android/media/ToneGenerator");
clazz = env->FindClass("android/media/ToneGenerator"); fields.context = GetFieldIDOrDie(env, clazz, "mNativeContext", "J");
if (clazz == NULL) {
ALOGE("Can't find %s", "android/media/ToneGenerator");
return -1;
}
fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
if (fields.context == NULL) {
ALOGE("Can't find ToneGenerator.mNativeContext");
return -1;
}
ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context); ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context);
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/media/ToneGenerator", gMethods, NELEM(gMethods));
"android/media/ToneGenerator", gMethods, NELEM(gMethods));
} }

View File

@@ -23,7 +23,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <jni.h> #include <jni.h>
#include <ScopedUtfChars.h> #include <ScopedUtfChars.h>
#include <utils/misc.h> #include <utils/misc.h>
@@ -192,8 +192,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_net_TrafficStats(JNIEnv* env) { int register_android_net_TrafficStats(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, "android/net/TrafficStats", return RegisterMethodsOrDie(env, "android/net/TrafficStats", gMethods, NELEM(gMethods));
gMethods, NELEM(gMethods));
} }
} }

View File

@@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef android_nio_utils_DEFINED #ifndef _ANDROID_NIO_UTILS_H_
#define android_nio_utils_DEFINED #define _ANDROID_NIO_UTILS_H_
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
@@ -70,4 +70,4 @@ private:
} /* namespace android */ } /* namespace android */
#endif #endif // _ANDROID_NIO_UTILS_H_

View File

@@ -18,7 +18,7 @@
#include <utils/Log.h> #include <utils/Log.h>
#include <cutils/ashmem.h> #include <cutils/ashmem.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
@@ -151,9 +151,7 @@ static const JNINativeMethod methods[] = {
int register_android_os_MemoryFile(JNIEnv* env) int register_android_os_MemoryFile(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(env, "android/os/MemoryFile", methods, NELEM(methods));
env, "android/os/MemoryFile",
methods, NELEM(methods));
} }
} }

View File

@@ -19,7 +19,7 @@
#include "JNIHelp.h" #include "JNIHelp.h"
#include "jni.h" #include "jni.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "selinux/selinux.h" #include "selinux/selinux.h"
#include "selinux/android.h" #include "selinux/android.h"
#include <errno.h> #include <errno.h>
@@ -469,8 +469,7 @@ int register_android_os_SELinux(JNIEnv *env) {
isSELinuxDisabled = (is_selinux_enabled() != 1) ? true : false; isSELinuxDisabled = (is_selinux_enabled() != 1) ? true : false;
return AndroidRuntime::registerNativeMethods(env, "android/os/SELinux", method_table, return RegisterMethodsOrDie(env, "android/os/SELinux", method_table, NELEM(method_table));
NELEM(method_table));
} }
} }

View File

@@ -27,7 +27,7 @@
#include "JNIHelp.h" #include "JNIHelp.h"
#include "jni.h" #include "jni.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
@@ -135,8 +135,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_os_SystemClock(JNIEnv* env) int register_android_os_SystemClock(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env, "android/os/SystemClock", gMethods, NELEM(gMethods));
"android/os/SystemClock", gMethods, NELEM(gMethods));
} }
}; // namespace android }; // namespace android

View File

@@ -21,7 +21,7 @@
#include "utils/misc.h" #include "utils/misc.h"
#include <utils/Log.h> #include <utils/Log.h>
#include "jni.h" #include "jni.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <nativehelper/JNIHelp.h> #include <nativehelper/JNIHelp.h>
namespace android namespace android
@@ -239,9 +239,8 @@ static JNINativeMethod method_table[] = {
int register_android_os_SystemProperties(JNIEnv *env) int register_android_os_SystemProperties(JNIEnv *env)
{ {
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(env, "android/os/SystemProperties", method_table,
env, "android/os/SystemProperties", NELEM(method_table));
method_table, NELEM(method_table));
} }
}; };

View File

@@ -22,7 +22,7 @@
#include "hardware_legacy/uevent.h" #include "hardware_legacy/uevent.h"
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <utils/Mutex.h> #include <utils/Mutex.h>
#include <utils/Vector.h> #include <utils/Vector.h>
@@ -117,16 +117,9 @@ static JNINativeMethod gMethods[] = {
int register_android_os_UEventObserver(JNIEnv *env) int register_android_os_UEventObserver(JNIEnv *env)
{ {
jclass clazz; FindClassOrDie(env, "android/os/UEventObserver");
clazz = env->FindClass("android/os/UEventObserver"); return RegisterMethodsOrDie(env, "android/os/UEventObserver", gMethods, NELEM(gMethods));
if (clazz == NULL) {
ALOGE("Can't find android/os/UEventObserver");
return -1;
}
return AndroidRuntime::registerNativeMethods(env,
"android/os/UEventObserver", gMethods, NELEM(gMethods));
} }
} // namespace android } // namespace android

View File

@@ -26,7 +26,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
static void dumpOneStack(int tid, int outFd) { static void dumpOneStack(int tid, int outFd) {
char buf[64]; char buf[64];
@@ -106,8 +106,7 @@ static const JNINativeMethod g_methods[] = {
}; };
int register_android_server_Watchdog(JNIEnv* env) { int register_android_server_Watchdog(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, "com/android/server/Watchdog", return RegisterMethodsOrDie(env, "com/android/server/Watchdog", g_methods, NELEM(g_methods));
g_methods, NELEM(g_methods));
} }
} }

View File

@@ -18,7 +18,7 @@
#define LOG_TAG "AndroidUnicode" #define LOG_TAG "AndroidUnicode"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "utils/misc.h" #include "utils/misc.h"
#include "utils/Log.h" #include "utils/Log.h"
#include "unicode/ubidi.h" #include "unicode/ubidi.h"
@@ -57,14 +57,12 @@ static jint runBidi(JNIEnv* env, jobject obj, jint dir, jcharArray chsArray,
} }
static JNINativeMethod gMethods[] = { static JNINativeMethod gMethods[] = {
{ "runBidi", "(I[C[BIZ)I", { "runBidi", "(I[C[BIZ)I", (void*) runBidi }
(void*) runBidi }
}; };
int register_android_text_AndroidBidi(JNIEnv* env) int register_android_text_AndroidBidi(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, "android/text/AndroidBidi", return RegisterMethodsOrDie(env, "android/text/AndroidBidi", gMethods, NELEM(gMethods));
gMethods, NELEM(gMethods));
} }
} }

View File

@@ -19,7 +19,7 @@
#include "JNIHelp.h" #include "JNIHelp.h"
#include "ScopedPrimitiveArray.h" #include "ScopedPrimitiveArray.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "utils/misc.h" #include "utils/misc.h"
#include "utils/Log.h" #include "utils/Log.h"
#include "unicode/uchar.h" #include "unicode/uchar.h"
@@ -193,8 +193,7 @@ static JNINativeMethod gMethods[] = {
int register_android_text_AndroidCharacter(JNIEnv* env) int register_android_text_AndroidCharacter(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, "android/text/AndroidCharacter", return RegisterMethodsOrDie(env, "android/text/AndroidCharacter", gMethods, NELEM(gMethods));
gMethods, NELEM(gMethods));
} }
} }

View File

@@ -23,7 +23,7 @@
#include "utils/Log.h" #include "utils/Log.h"
#include "ScopedPrimitiveArray.h" #include "ScopedPrimitiveArray.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <vector> #include <vector>
namespace android { namespace android {
@@ -103,8 +103,7 @@ static JNINativeMethod gMethods[] = {
int register_android_text_StaticLayout(JNIEnv* env) int register_android_text_StaticLayout(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, "android/text/StaticLayout", return RegisterMethodsOrDie(env, "android/text/StaticLayout", gMethods, NELEM(gMethods));
gMethods, NELEM(gMethods));
} }
} }

View File

@@ -46,8 +46,6 @@
#include <ScopedUtfChars.h> #include <ScopedUtfChars.h>
#include <ScopedLocalRef.h> #include <ScopedLocalRef.h>
#include <android_runtime/AndroidRuntime.h>
#include "core_jni_helpers.h" #include "core_jni_helpers.h"
//#undef ALOGV //#undef ALOGV
@@ -834,7 +832,7 @@ static int int_register_android_os_Binder(JNIEnv* env)
gBinderOffsets.mExecTransact = GetMethodIDOrDie(env, clazz, "execTransact", "(IJJI)Z"); gBinderOffsets.mExecTransact = GetMethodIDOrDie(env, clazz, "execTransact", "(IJJI)Z");
gBinderOffsets.mObject = GetFieldIDOrDie(env, clazz, "mObject", "J"); gBinderOffsets.mObject = GetFieldIDOrDie(env, clazz, "mObject", "J");
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(
env, kBinderPathName, env, kBinderPathName,
gBinderMethods, NELEM(gBinderMethods)); gBinderMethods, NELEM(gBinderMethods));
} }
@@ -909,7 +907,7 @@ static int int_register_android_os_BinderInternal(JNIEnv* env)
gBinderInternalOffsets.mClass = MakeGlobalRefOrDie(env, clazz); gBinderInternalOffsets.mClass = MakeGlobalRefOrDie(env, clazz);
gBinderInternalOffsets.mForceGc = GetStaticMethodIDOrDie(env, clazz, "forceBinderGc", "()V"); gBinderInternalOffsets.mForceGc = GetStaticMethodIDOrDie(env, clazz, "forceBinderGc", "()V");
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(
env, kBinderInternalPathName, env, kBinderInternalPathName,
gBinderInternalMethods, NELEM(gBinderInternalMethods)); gBinderInternalMethods, NELEM(gBinderInternalMethods));
} }
@@ -1240,7 +1238,7 @@ static int int_register_android_os_BinderProxy(JNIEnv* env)
clazz = FindClassOrDie(env, "java/lang/Class"); clazz = FindClassOrDie(env, "java/lang/Class");
gClassOffsets.mGetName = GetMethodIDOrDie(env, clazz, "getName", "()Ljava/lang/String;"); gClassOffsets.mGetName = GetMethodIDOrDie(env, clazz, "getName", "()Ljava/lang/String;");
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(
env, kBinderProxyPathName, env, kBinderProxyPathName,
gBinderProxyMethods, NELEM(gBinderProxyMethods)); gBinderProxyMethods, NELEM(gBinderProxyMethods));
} }

View File

@@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#include "JNIHelp.h" #include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "jni.h" #include "jni.h"
#include "log/logger.h" #include "log/logger.h"
@@ -263,33 +263,21 @@ static struct { jclass *c; const char *name, *mt; jmethodID *id; } gMethods[] =
int register_android_util_EventLog(JNIEnv* env) { int register_android_util_EventLog(JNIEnv* env) {
for (int i = 0; i < NELEM(gClasses); ++i) { for (int i = 0; i < NELEM(gClasses); ++i) {
jclass clazz = env->FindClass(gClasses[i].name); jclass clazz = FindClassOrDie(env, gClasses[i].name);
if (clazz == NULL) { *gClasses[i].clazz = MakeGlobalRefOrDie(env, clazz);
ALOGE("Can't find class: %s\n", gClasses[i].name);
return -1;
}
*gClasses[i].clazz = (jclass) env->NewGlobalRef(clazz);
} }
for (int i = 0; i < NELEM(gFields); ++i) { for (int i = 0; i < NELEM(gFields); ++i) {
*gFields[i].id = env->GetFieldID( *gFields[i].id = GetFieldIDOrDie(env,
*gFields[i].c, gFields[i].name, gFields[i].ft); *gFields[i].c, gFields[i].name, gFields[i].ft);
if (*gFields[i].id == NULL) {
ALOGE("Can't find field: %s\n", gFields[i].name);
return -1;
}
} }
for (int i = 0; i < NELEM(gMethods); ++i) { for (int i = 0; i < NELEM(gMethods); ++i) {
*gMethods[i].id = env->GetMethodID( *gMethods[i].id = GetMethodIDOrDie(env,
*gMethods[i].c, gMethods[i].name, gMethods[i].mt); *gMethods[i].c, gMethods[i].name, gMethods[i].mt);
if (*gMethods[i].id == NULL) {
ALOGE("Can't find method: %s\n", gMethods[i].name);
return -1;
}
} }
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(
env, env,
"android/util/EventLog", "android/util/EventLog",
gRegisterMethods, NELEM(gRegisterMethods)); gRegisterMethods, NELEM(gRegisterMethods));

View File

@@ -19,7 +19,7 @@
#include "jni.h" #include "jni.h"
#include "utils/Log.h" #include "utils/Log.h"
#include "utils/misc.h" #include "utils/misc.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -138,24 +138,12 @@ static JNINativeMethod sMethods[] = {
int register_android_os_FileObserver(JNIEnv* env) int register_android_os_FileObserver(JNIEnv* env)
{ {
jclass clazz; jclass clazz = FindClassOrDie(env, "android/os/FileObserver$ObserverThread");
clazz = env->FindClass("android/os/FileObserver$ObserverThread"); method_onEvent = GetMethodIDOrDie(env, clazz, "onEvent", "(IILjava/lang/String;)V");
if (clazz == NULL) return RegisterMethodsOrDie(env, "android/os/FileObserver$ObserverThread", sMethods,
{ NELEM(sMethods));
ALOGE("Can't find android/os/FileObserver$ObserverThread");
return -1;
}
method_onEvent = env->GetMethodID(clazz, "onEvent", "(IILjava/lang/String;)V");
if (method_onEvent == NULL)
{
ALOGE("Can't find FileObserver.onEvent(int, int, String)");
return -1;
}
return AndroidRuntime::registerNativeMethods(env, "android/os/FileObserver$ObserverThread", sMethods, NELEM(sMethods));
} }
} /* namespace android */ } /* namespace android */

View File

@@ -26,11 +26,9 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include "utils/misc.h" #include "utils/misc.h"
#include "android_runtime/AndroidRuntime.h" #include "core_jni_helpers.h"
#include "android_util_Log.h" #include "android_util_Log.h"
#define MIN(a,b) ((a<b)?a:b)
namespace android { namespace android {
struct levels_t { struct levels_t {
@@ -145,21 +143,16 @@ static JNINativeMethod gMethods[] = {
int register_android_util_Log(JNIEnv* env) int register_android_util_Log(JNIEnv* env)
{ {
jclass clazz = env->FindClass("android/util/Log"); jclass clazz = FindClassOrDie(env, "android/util/Log");
if (clazz == NULL) { levels.verbose = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "VERBOSE", "I"));
ALOGE("Can't find android/util/Log"); levels.debug = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "DEBUG", "I"));
return -1; levels.info = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "INFO", "I"));
} levels.warn = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "WARN", "I"));
levels.error = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "ERROR", "I"));
levels.assert = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "ASSERT", "I"));
levels.verbose = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "VERBOSE", "I")); return RegisterMethodsOrDie(env, "android/util/Log", gMethods, NELEM(gMethods));
levels.debug = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "DEBUG", "I"));
levels.info = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "INFO", "I"));
levels.warn = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "WARN", "I"));
levels.error = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "ERROR", "I"));
levels.assert = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "ASSERT", "I"));
return AndroidRuntime::registerNativeMethods(env, "android/util/Log", gMethods, NELEM(gMethods));
} }
}; // namespace android }; // namespace android

View File

@@ -26,7 +26,7 @@
#include <utils/Vector.h> #include <utils/Vector.h>
#include <processgroup/processgroup.h> #include <processgroup/processgroup.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include "android_util_Binder.h" #include "android_util_Binder.h"
#include "JNIHelp.h" #include "JNIHelp.h"
@@ -1054,11 +1054,7 @@ static const JNINativeMethod methods[] = {
{"removeAllProcessGroups", "()V", (void*)android_os_Process_removeAllProcessGroups}, {"removeAllProcessGroups", "()V", (void*)android_os_Process_removeAllProcessGroups},
}; };
const char* const kProcessPathName = "android/os/Process";
int register_android_os_Process(JNIEnv* env) int register_android_os_Process(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods( return RegisterMethodsOrDie(env, "android/os/Process", methods, NELEM(methods));
env, kProcessPathName,
methods, NELEM(methods));
} }

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <utils/misc.h> #include <utils/misc.h>
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include <utils/Log.h> #include <utils/Log.h>
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
@@ -171,7 +171,7 @@ static JNINativeMethod gStringBlockMethods[] = {
int register_android_content_StringBlock(JNIEnv* env) int register_android_content_StringBlock(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
"android/content/res/StringBlock", gStringBlockMethods, NELEM(gStringBlockMethods)); "android/content/res/StringBlock", gStringBlockMethods, NELEM(gStringBlockMethods));
} }

View File

@@ -19,7 +19,7 @@
#include "jni.h" #include "jni.h"
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include <androidfw/AssetManager.h> #include <androidfw/AssetManager.h>
#include <androidfw/ResourceTypes.h> #include <androidfw/ResourceTypes.h>
#include <utils/Log.h> #include <utils/Log.h>
@@ -412,7 +412,7 @@ static JNINativeMethod gXmlBlockMethods[] = {
int register_android_content_XmlBlock(JNIEnv* env) int register_android_content_XmlBlock(JNIEnv* env)
{ {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
"android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods)); "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods));
} }

View File

@@ -52,6 +52,10 @@ namespace android {
using namespace uirenderer; using namespace uirenderer;
static struct {
jmethodID set;
} gRectClassInfo;
/** /**
* Note: DisplayListRenderer JNI layer is generated and compiled only on supported * Note: DisplayListRenderer JNI layer is generated and compiled only on supported
* devices. This means all the logic must be compiled only when the * devices. This means all the logic must be compiled only when the
@@ -63,21 +67,7 @@ using namespace uirenderer;
// Defines // Defines
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Debug static const bool kDebugRenderer = false;
#define DEBUG_RENDERER 0
// Debug
#if DEBUG_RENDERER
#define RENDERER_LOGD(...) ALOGD(__VA_ARGS__)
#else
#define RENDERER_LOGD(...)
#endif
// ----------------------------------------------------------------------------
static struct {
jmethodID set;
} gRectClassInfo;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Constructors // Constructors
@@ -86,7 +76,9 @@ static struct {
static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz, static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz,
jlong rendererPtr) { jlong rendererPtr) {
DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr);
RENDERER_LOGD("Destroy DisplayListRenderer"); if (kDebugRenderer) {
ALOGD("Destroy DisplayListRenderer");
}
delete renderer; delete renderer;
} }
@@ -835,24 +827,30 @@ static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz,
#endif // USE_OPENGL_RENDERER #endif // USE_OPENGL_RENDERER
#ifdef USE_OPENGL_RENDERER
static const bool kUseOpenGLRenderer = true;
#else
static const bool kUseOpenGLRenderer = false;
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Common // Common
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) {
#ifdef USE_OPENGL_RENDERER if (kUseOpenGLRenderer) {
char prop[PROPERTY_VALUE_MAX]; char prop[PROPERTY_VALUE_MAX];
if (property_get("ro.kernel.qemu", prop, NULL) == 0) { if (property_get("ro.kernel.qemu", prop, NULL) == 0) {
// not in the emulator // not in the emulator
return JNI_TRUE; return JNI_TRUE;
}
// In the emulator this property will be set to 1 when hardware GLES is
// enabled, 0 otherwise. On old emulator versions it will be undefined.
property_get("ro.kernel.qemu.gles", prop, "0");
return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE;
} else {
return JNI_FALSE;
} }
// In the emulator this property will be set to 1 when hardware GLES is
// enabled, 0 otherwise. On old emulator versions it will be undefined.
property_get("ro.kernel.qemu.gles", prop, "0");
return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE;
#else
return JNI_FALSE;
#endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -861,10 +859,10 @@ static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz
static void static void
android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) {
#ifdef USE_OPENGL_RENDERER if (kUseOpenGLRenderer) {
int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
android::uirenderer::RenderNode::outputLogBuffer(fd); android::uirenderer::RenderNode::outputLogBuffer(fd);
#endif // USE_OPENGL_RENDERER }
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -974,18 +972,16 @@ static JNINativeMethod gActivityThreadMethods[] = {
}; };
int register_android_view_GLES20Canvas(JNIEnv* env) { int register_android_view_GLES20Canvas(JNIEnv* env) {
#ifdef USE_OPENGL_RENDERER if (kUseOpenGLRenderer) {
jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); jclass clazz = FindClassOrDie(env, "android/graphics/Rect");
gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V");
#endif }
return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
} }
const char* const kActivityThreadPathName = "android/app/ActivityThread";
int register_android_app_ActivityThread(JNIEnv* env) { int register_android_app_ActivityThread(JNIEnv* env) {
return RegisterMethodsOrDie(env, kActivityThreadPathName, return RegisterMethodsOrDie(env, "android/app/ActivityThread",
gActivityThreadMethods, NELEM(gActivityThreadMethods)); gActivityThreadMethods, NELEM(gActivityThreadMethods));
} }

View File

@@ -47,16 +47,7 @@ namespace android {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Debug // Debug
#define DEBUG_GRAPHIC_BUFFER 0 static const bool kDebugGraphicBuffer = false;
// Debug
#if DEBUG_GRAPHIC_BUFFER
#define GB_LOGD(...) ALOGD(__VA_ARGS__)
#define GB_LOGW(...) ALOGW(__VA_ARGS__)
#else
#define GB_LOGD(...)
#define GB_LOGW(...)
#endif
#define LOCK_CANVAS_USAGE GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_SW_WRITE_OFTEN #define LOCK_CANVAS_USAGE GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_SW_WRITE_OFTEN
@@ -118,14 +109,18 @@ static jlong android_view_GraphiceBuffer_create(JNIEnv* env, jobject clazz,
sp<ISurfaceComposer> composer(ComposerService::getComposerService()); sp<ISurfaceComposer> composer(ComposerService::getComposerService());
sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc()); sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc());
if (alloc == NULL) { if (alloc == NULL) {
GB_LOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()"); if (kDebugGraphicBuffer) {
ALOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()");
}
return NULL; return NULL;
} }
status_t error; status_t error;
sp<GraphicBuffer> buffer(alloc->createGraphicBuffer(width, height, format, usage, &error)); sp<GraphicBuffer> buffer(alloc->createGraphicBuffer(width, height, format, usage, &error));
if (buffer == NULL) { if (buffer == NULL) {
GB_LOGW("createGraphicBuffer() failed in GraphicBuffer.create()"); if (kDebugGraphicBuffer) {
ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()");
}
return NULL; return NULL;
} }

View File

@@ -20,7 +20,7 @@
#include "GraphicsJNI.h" #include "GraphicsJNI.h"
#include <nativehelper/JNIHelp.h> #include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <android_runtime/android_graphics_SurfaceTexture.h> #include <android_runtime/android_graphics_SurfaceTexture.h>
#include <gui/GLConsumer.h> #include <gui/GLConsumer.h>
@@ -117,7 +117,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_view_HardwareLayer(JNIEnv* env) { int register_android_view_HardwareLayer(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
} }
}; };

View File

@@ -18,10 +18,6 @@
//#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0
// Log debug messages about the dispatch cycle.
#define DEBUG_DISPATCH_CYCLE 0
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
@@ -41,6 +37,8 @@
namespace android { namespace android {
static const bool kDebugDispatchCycle = false;
static struct { static struct {
jclass clazz; jclass clazz;
@@ -94,9 +92,9 @@ NativeInputEventReceiver::NativeInputEventReceiver(JNIEnv* env,
mReceiverWeakGlobal(env->NewGlobalRef(receiverWeak)), mReceiverWeakGlobal(env->NewGlobalRef(receiverWeak)),
mInputConsumer(inputChannel), mMessageQueue(messageQueue), mInputConsumer(inputChannel), mMessageQueue(messageQueue),
mBatchedInputEventPending(false), mFdEvents(0) { mBatchedInputEventPending(false), mFdEvents(0) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName()); ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName());
#endif }
} }
NativeInputEventReceiver::~NativeInputEventReceiver() { NativeInputEventReceiver::~NativeInputEventReceiver() {
@@ -110,25 +108,25 @@ status_t NativeInputEventReceiver::initialize() {
} }
void NativeInputEventReceiver::dispose() { void NativeInputEventReceiver::dispose() {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Disposing input event receiver.", getInputChannelName()); ALOGD("channel '%s' ~ Disposing input event receiver.", getInputChannelName());
#endif }
setFdEvents(0); setFdEvents(0);
} }
status_t NativeInputEventReceiver::finishInputEvent(uint32_t seq, bool handled) { status_t NativeInputEventReceiver::finishInputEvent(uint32_t seq, bool handled) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Finished input event.", getInputChannelName()); ALOGD("channel '%s' ~ Finished input event.", getInputChannelName());
#endif }
status_t status = mInputConsumer.sendFinishedSignal(seq, handled); status_t status = mInputConsumer.sendFinishedSignal(seq, handled);
if (status) { if (status) {
if (status == WOULD_BLOCK) { if (status == WOULD_BLOCK) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Could not send finished signal immediately. " ALOGD("channel '%s' ~ Could not send finished signal immediately. "
"Enqueued for later.", getInputChannelName()); "Enqueued for later.", getInputChannelName());
#endif }
Finish finish; Finish finish;
finish.seq = seq; finish.seq = seq;
finish.handled = handled; finish.handled = handled;
@@ -158,13 +156,13 @@ void NativeInputEventReceiver::setFdEvents(int events) {
int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data) { int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data) {
if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) { if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) {
#if DEBUG_DISPATCH_CYCLE
// This error typically occurs when the publisher has closed the input channel // This error typically occurs when the publisher has closed the input channel
// as part of removing a window or finishing an IME session, in which case // as part of removing a window or finishing an IME session, in which case
// the consumer will soon be disposed as well. // the consumer will soon be disposed as well.
ALOGD("channel '%s' ~ Publisher closed input channel or an error occurred. " if (kDebugDispatchCycle) {
"events=0x%x", getInputChannelName(), events); ALOGD("channel '%s' ~ Publisher closed input channel or an error occurred. "
#endif "events=0x%x", getInputChannelName(), events);
}
return 0; // remove the callback return 0; // remove the callback
} }
@@ -183,10 +181,10 @@ int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data)
mFinishQueue.removeItemsAt(0, i); mFinishQueue.removeItemsAt(0, i);
if (status == WOULD_BLOCK) { if (status == WOULD_BLOCK) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Sent %u queued finish events; %u left.", ALOGD("channel '%s' ~ Sent %u queued finish events; %u left.",
getInputChannelName(), i, mFinishQueue.size()); getInputChannelName(), i, mFinishQueue.size());
#endif }
return 1; // keep the callback, try again later return 1; // keep the callback, try again later
} }
@@ -202,10 +200,10 @@ int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data)
return 0; // remove the callback return 0; // remove the callback
} }
} }
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Sent %u queued finish events; none left.", ALOGD("channel '%s' ~ Sent %u queued finish events; none left.",
getInputChannelName(), mFinishQueue.size()); getInputChannelName(), mFinishQueue.size());
#endif }
mFinishQueue.clear(); mFinishQueue.clear();
setFdEvents(ALOOPER_EVENT_INPUT); setFdEvents(ALOOPER_EVENT_INPUT);
return 1; return 1;
@@ -218,10 +216,10 @@ int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data)
status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
bool consumeBatches, nsecs_t frameTime, bool* outConsumedBatch) { bool consumeBatches, nsecs_t frameTime, bool* outConsumedBatch) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s, frameTime=%lld.", ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s, frameTime=%lld.",
getInputChannelName(), consumeBatches ? "true" : "false", frameTime); getInputChannelName(), consumeBatches ? "true" : "false", frameTime);
#endif }
if (consumeBatches) { if (consumeBatches) {
mBatchedInputEventPending = false; mBatchedInputEventPending = false;
@@ -252,10 +250,10 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
} }
mBatchedInputEventPending = true; mBatchedInputEventPending = true;
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Dispatching batched input event pending notification.", ALOGD("channel '%s' ~ Dispatching batched input event pending notification.",
getInputChannelName()); getInputChannelName());
#endif }
env->CallVoidMethod(receiverObj.get(), env->CallVoidMethod(receiverObj.get(),
gInputEventReceiverClassInfo.dispatchBatchedInputEventPending); gInputEventReceiverClassInfo.dispatchBatchedInputEventPending);
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {
@@ -284,17 +282,17 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
jobject inputEventObj; jobject inputEventObj;
switch (inputEvent->getType()) { switch (inputEvent->getType()) {
case AINPUT_EVENT_TYPE_KEY: case AINPUT_EVENT_TYPE_KEY:
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received key event.", getInputChannelName()); ALOGD("channel '%s' ~ Received key event.", getInputChannelName());
#endif }
inputEventObj = android_view_KeyEvent_fromNative(env, inputEventObj = android_view_KeyEvent_fromNative(env,
static_cast<KeyEvent*>(inputEvent)); static_cast<KeyEvent*>(inputEvent));
break; break;
case AINPUT_EVENT_TYPE_MOTION: { case AINPUT_EVENT_TYPE_MOTION: {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received motion event.", getInputChannelName()); ALOGD("channel '%s' ~ Received motion event.", getInputChannelName());
#endif }
MotionEvent* motionEvent = static_cast<MotionEvent*>(inputEvent); MotionEvent* motionEvent = static_cast<MotionEvent*>(inputEvent);
if ((motionEvent->getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) { if ((motionEvent->getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) {
*outConsumedBatch = true; *outConsumedBatch = true;
@@ -309,9 +307,9 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
} }
if (inputEventObj) { if (inputEventObj) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Dispatching input event.", getInputChannelName()); ALOGD("channel '%s' ~ Dispatching input event.", getInputChannelName());
#endif }
env->CallVoidMethod(receiverObj.get(), env->CallVoidMethod(receiverObj.get(),
gInputEventReceiverClassInfo.dispatchInputEvent, seq, inputEventObj); gInputEventReceiverClassInfo.dispatchInputEvent, seq, inputEventObj);
if (env->ExceptionCheck()) { if (env->ExceptionCheck()) {

View File

@@ -18,10 +18,6 @@
//#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0
// Log debug messages about the dispatch cycle.
#define DEBUG_DISPATCH_CYCLE 0
#include "JNIHelp.h" #include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
@@ -41,6 +37,9 @@
namespace android { namespace android {
// Log debug messages about the dispatch cycle.
static const bool kDebugDispatchCycle = false;
static struct { static struct {
jclass clazz; jclass clazz;
@@ -84,9 +83,9 @@ NativeInputEventSender::NativeInputEventSender(JNIEnv* env,
mSenderWeakGlobal(env->NewGlobalRef(senderWeak)), mSenderWeakGlobal(env->NewGlobalRef(senderWeak)),
mInputPublisher(inputChannel), mMessageQueue(messageQueue), mInputPublisher(inputChannel), mMessageQueue(messageQueue),
mNextPublishedSeq(1) { mNextPublishedSeq(1) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Initializing input event sender.", getInputChannelName()); ALOGD("channel '%s' ~ Initializing input event sender.", getInputChannelName());
#endif }
} }
NativeInputEventSender::~NativeInputEventSender() { NativeInputEventSender::~NativeInputEventSender() {
@@ -101,17 +100,17 @@ status_t NativeInputEventSender::initialize() {
} }
void NativeInputEventSender::dispose() { void NativeInputEventSender::dispose() {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Disposing input event sender.", getInputChannelName()); ALOGD("channel '%s' ~ Disposing input event sender.", getInputChannelName());
#endif }
mMessageQueue->getLooper()->removeFd(mInputPublisher.getChannel()->getFd()); mMessageQueue->getLooper()->removeFd(mInputPublisher.getChannel()->getFd());
} }
status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* event) { status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* event) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Sending key event, seq=%u.", getInputChannelName(), seq); ALOGD("channel '%s' ~ Sending key event, seq=%u.", getInputChannelName(), seq);
#endif }
uint32_t publishedSeq = mNextPublishedSeq++; uint32_t publishedSeq = mNextPublishedSeq++;
status_t status = mInputPublisher.publishKeyEvent(publishedSeq, status_t status = mInputPublisher.publishKeyEvent(publishedSeq,
@@ -128,9 +127,9 @@ status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* even
} }
status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent* event) { status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent* event) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Sending motion event, seq=%u.", getInputChannelName(), seq); ALOGD("channel '%s' ~ Sending motion event, seq=%u.", getInputChannelName(), seq);
#endif }
uint32_t publishedSeq; uint32_t publishedSeq;
for (size_t i = 0; i <= event->getHistorySize(); i++) { for (size_t i = 0; i <= event->getHistorySize(); i++) {
@@ -155,13 +154,14 @@ status_t NativeInputEventSender::sendMotionEvent(uint32_t seq, const MotionEvent
int NativeInputEventSender::handleEvent(int receiveFd, int events, void* data) { int NativeInputEventSender::handleEvent(int receiveFd, int events, void* data) {
if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) { if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) {
#if DEBUG_DISPATCH_CYCLE
// This error typically occurs when the consumer has closed the input channel // This error typically occurs when the consumer has closed the input channel
// as part of finishing an IME session, in which case the publisher will // as part of finishing an IME session, in which case the publisher will
// soon be disposed as well. // soon be disposed as well.
ALOGD("channel '%s' ~ Consumer closed input channel or an error occurred. " if (kDebugDispatchCycle) {
"events=0x%x", getInputChannelName(), events); ALOGD("channel '%s' ~ Consumer closed input channel or an error occurred. "
#endif "events=0x%x", getInputChannelName(), events);
}
return 0; // remove the callback return 0; // remove the callback
} }
@@ -178,9 +178,9 @@ int NativeInputEventSender::handleEvent(int receiveFd, int events, void* data) {
} }
status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) { status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) {
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Receiving finished signals.", getInputChannelName()); ALOGD("channel '%s' ~ Receiving finished signals.", getInputChannelName());
#endif }
ScopedLocalRef<jobject> senderObj(env, NULL); ScopedLocalRef<jobject> senderObj(env, NULL);
bool skipCallbacks = false; bool skipCallbacks = false;
@@ -202,12 +202,12 @@ status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) {
uint32_t seq = mPublishedSeqMap.valueAt(index); uint32_t seq = mPublishedSeqMap.valueAt(index);
mPublishedSeqMap.removeItemsAt(index); mPublishedSeqMap.removeItemsAt(index);
#if DEBUG_DISPATCH_CYCLE if (kDebugDispatchCycle) {
ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, " ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, "
"pendingEvents=%u.", "pendingEvents=%u.",
getInputChannelName(), seq, handled ? "true" : "false", getInputChannelName(), seq, handled ? "true" : "false",
mPublishedSeqMap.size()); mPublishedSeqMap.size());
#endif }
if (!skipCallbacks) { if (!skipCallbacks) {
if (!senderObj.get()) { if (!senderObj.get()) {

View File

@@ -23,7 +23,7 @@
#include "android_os_Parcel.h" #include "android_os_Parcel.h"
#include "android/graphics/GraphicsJNI.h" #include "android/graphics/GraphicsJNI.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <android_runtime/android_view_Surface.h> #include <android_runtime/android_view_Surface.h>
#include <android_runtime/android_graphics_SurfaceTexture.h> #include <android_runtime/android_graphics_SurfaceTexture.h>
#include <android_runtime/Log.h> #include <android_runtime/Log.h>
@@ -379,26 +379,26 @@ static JNINativeMethod gSurfaceMethods[] = {
int register_android_view_Surface(JNIEnv* env) int register_android_view_Surface(JNIEnv* env)
{ {
int err = AndroidRuntime::registerNativeMethods(env, "android/view/Surface", int err = RegisterMethodsOrDie(env, "android/view/Surface",
gSurfaceMethods, NELEM(gSurfaceMethods)); gSurfaceMethods, NELEM(gSurfaceMethods));
jclass clazz = env->FindClass("android/view/Surface"); jclass clazz = FindClassOrDie(env, "android/view/Surface");
gSurfaceClassInfo.clazz = jclass(env->NewGlobalRef(clazz)); gSurfaceClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
gSurfaceClassInfo.mNativeObject = gSurfaceClassInfo.mNativeObject = GetFieldIDOrDie(env,
env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "J"); gSurfaceClassInfo.clazz, "mNativeObject", "J");
gSurfaceClassInfo.mLock = gSurfaceClassInfo.mLock = GetFieldIDOrDie(env,
env->GetFieldID(gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;"); gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;");
gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(J)V"); gSurfaceClassInfo.ctor = GetMethodIDOrDie(env, gSurfaceClassInfo.clazz, "<init>", "(J)V");
clazz = env->FindClass("android/graphics/Canvas"); clazz = FindClassOrDie(env, "android/graphics/Canvas");
gCanvasClassInfo.mSurfaceFormat = env->GetFieldID(clazz, "mSurfaceFormat", "I"); gCanvasClassInfo.mSurfaceFormat = GetFieldIDOrDie(env, clazz, "mSurfaceFormat", "I");
gCanvasClassInfo.setNativeBitmap = env->GetMethodID(clazz, "setNativeBitmap", "(J)V"); gCanvasClassInfo.setNativeBitmap = GetMethodIDOrDie(env, clazz, "setNativeBitmap", "(J)V");
clazz = env->FindClass("android/graphics/Rect"); clazz = FindClassOrDie(env, "android/graphics/Rect");
gRectClassInfo.left = env->GetFieldID(clazz, "left", "I"); gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I");
gRectClassInfo.top = env->GetFieldID(clazz, "top", "I"); gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I");
gRectClassInfo.right = env->GetFieldID(clazz, "right", "I"); gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I");
gRectClassInfo.bottom = env->GetFieldID(clazz, "bottom", "I"); gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I");
return err; return err;
} }

View File

@@ -26,7 +26,7 @@
#include "android/graphics/GraphicsJNI.h" #include "android/graphics/GraphicsJNI.h"
#include "android/graphics/Region.h" #include "android/graphics/Region.h"
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <android_runtime/android_view_Surface.h> #include <android_runtime/android_view_Surface.h>
#include <android_runtime/android_view_SurfaceSession.h> #include <android_runtime/android_view_SurfaceSession.h>
@@ -647,41 +647,44 @@ static JNINativeMethod sSurfaceControlMethods[] = {
int register_android_view_SurfaceControl(JNIEnv* env) int register_android_view_SurfaceControl(JNIEnv* env)
{ {
int err = AndroidRuntime::registerNativeMethods(env, "android/view/SurfaceControl", int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
sSurfaceControlMethods, NELEM(sSurfaceControlMethods)); sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
jclass clazz = env->FindClass("android/view/SurfaceControl$PhysicalDisplayInfo"); jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
gPhysicalDisplayInfoClassInfo.clazz = static_cast<jclass>(env->NewGlobalRef(clazz)); gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
gPhysicalDisplayInfoClassInfo.ctor = env->GetMethodID(gPhysicalDisplayInfoClassInfo.clazz, gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
"<init>", "()V"); gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
gPhysicalDisplayInfoClassInfo.width = env->GetFieldID(clazz, "width", "I"); gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
gPhysicalDisplayInfoClassInfo.height = env->GetFieldID(clazz, "height", "I"); gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
gPhysicalDisplayInfoClassInfo.refreshRate = env->GetFieldID(clazz, "refreshRate", "F"); gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
gPhysicalDisplayInfoClassInfo.density = env->GetFieldID(clazz, "density", "F"); gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
gPhysicalDisplayInfoClassInfo.xDpi = env->GetFieldID(clazz, "xDpi", "F"); gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
gPhysicalDisplayInfoClassInfo.yDpi = env->GetFieldID(clazz, "yDpi", "F"); gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
gPhysicalDisplayInfoClassInfo.secure = env->GetFieldID(clazz, "secure", "Z"); gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = env->GetFieldID(clazz, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
"appVsyncOffsetNanos", "J"); clazz, "appVsyncOffsetNanos", "J");
gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = env->GetFieldID(clazz, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
"presentationDeadlineNanos", "J"); clazz, "presentationDeadlineNanos", "J");
jclass rectClazz = env->FindClass("android/graphics/Rect"); jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
gRectClassInfo.bottom = env->GetFieldID(rectClazz, "bottom", "I"); gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
gRectClassInfo.left = env->GetFieldID(rectClazz, "left", "I"); gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
gRectClassInfo.right = env->GetFieldID(rectClazz, "right", "I"); gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
gRectClassInfo.top = env->GetFieldID(rectClazz, "top", "I"); gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
jclass frameStatsClazz = env->FindClass("android/view/FrameStats"); jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
jfieldID undefined_time_nano_field = env->GetStaticFieldID(frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
jclass contFrameStatsClazz = env->FindClass("android/view/WindowContentFrameStats"); jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
gWindowContentFrameStatsClassInfo.init = env->GetMethodID(contFrameStatsClazz, "init", "(J[J[J[J)V"); gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
contFrameStatsClazz, "init", "(J[J[J[J)V");
gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
jclass animFrameStatsClazz = env->FindClass("android/view/WindowAnimationFrameStats"); jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
gWindowAnimationFrameStatsClassInfo.init = env->GetMethodID(animFrameStatsClazz, "init", "(J[J)V"); gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
animFrameStatsClazz, "init", "(J[J)V");
gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
return err; return err;

View File

@@ -20,7 +20,7 @@
#include "jni.h" #include "jni.h"
#include <nativehelper/JNIHelp.h> #include <nativehelper/JNIHelp.h>
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
@@ -454,7 +454,7 @@ static JNINativeMethod gMethods[] = {
}; };
int register_android_view_ThreadedRenderer(JNIEnv* env) { int register_android_view_ThreadedRenderer(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
} }
}; // namespace android }; // namespace android

View File

@@ -17,7 +17,7 @@
#define LOG_TAG "NativeLibraryHelper" #define LOG_TAG "NativeLibraryHelper"
//#define LOG_NDEBUG 0 //#define LOG_NDEBUG 0
#include <android_runtime/AndroidRuntime.h> #include "core_jni_helpers.h"
#include <ScopedUtfChars.h> #include <ScopedUtfChars.h>
#include <UniquePtr.h> #include <UniquePtr.h>
@@ -563,8 +563,8 @@ static JNINativeMethod gMethods[] = {
int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env) int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env)
{ {
return AndroidRuntime::registerNativeMethods(env, return RegisterMethodsOrDie(env,
"com/android/internal/content/NativeLibraryHelper", gMethods, NELEM(gMethods)); "com/android/internal/content/NativeLibraryHelper", gMethods, NELEM(gMethods));
} }
}; };

View File

@@ -21,7 +21,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <android_runtime/AndroidRuntime.h> #include <core_jni_helpers.h>
#include <jni.h> #include <jni.h>
#include <ScopedUtfChars.h> #include <ScopedUtfChars.h>
@@ -284,16 +284,6 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats,
return 0; return 0;
} }
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;
}
static JNINativeMethod gMethods[] = { static JNINativeMethod gMethods[] = {
{ "nativeReadNetworkStatsDetail", { "nativeReadNetworkStatsDetail",
"(Landroid/net/NetworkStats;Ljava/lang/String;I[Ljava/lang/String;I)I", "(Landroid/net/NetworkStats;Ljava/lang/String;I[Ljava/lang/String;I)I",
@@ -301,24 +291,25 @@ static JNINativeMethod gMethods[] = {
}; };
int register_com_android_internal_net_NetworkStatsFactory(JNIEnv* env) { int register_com_android_internal_net_NetworkStatsFactory(JNIEnv* env) {
int err = AndroidRuntime::registerNativeMethods(env, int err = RegisterMethodsOrDie(env,
"com/android/internal/net/NetworkStatsFactory", gMethods, "com/android/internal/net/NetworkStatsFactory", gMethods,
NELEM(gMethods)); NELEM(gMethods));
gStringClass = findClass(env, "java/lang/String"); gStringClass = FindClassOrDie(env, "java/lang/String");
gStringClass = MakeGlobalRefOrDie(env, gStringClass);
jclass clazz = env->FindClass("android/net/NetworkStats"); jclass clazz = FindClassOrDie(env, "android/net/NetworkStats");
gNetworkStatsClassInfo.size = env->GetFieldID(clazz, "size", "I"); gNetworkStatsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "I");
gNetworkStatsClassInfo.capacity = env->GetFieldID(clazz, "capacity", "I"); gNetworkStatsClassInfo.capacity = GetFieldIDOrDie(env, clazz, "capacity", "I");
gNetworkStatsClassInfo.iface = env->GetFieldID(clazz, "iface", "[Ljava/lang/String;"); gNetworkStatsClassInfo.iface = GetFieldIDOrDie(env, clazz, "iface", "[Ljava/lang/String;");
gNetworkStatsClassInfo.uid = env->GetFieldID(clazz, "uid", "[I"); gNetworkStatsClassInfo.uid = GetFieldIDOrDie(env, clazz, "uid", "[I");
gNetworkStatsClassInfo.set = env->GetFieldID(clazz, "set", "[I"); gNetworkStatsClassInfo.set = GetFieldIDOrDie(env, clazz, "set", "[I");
gNetworkStatsClassInfo.tag = env->GetFieldID(clazz, "tag", "[I"); gNetworkStatsClassInfo.tag = GetFieldIDOrDie(env, clazz, "tag", "[I");
gNetworkStatsClassInfo.rxBytes = env->GetFieldID(clazz, "rxBytes", "[J"); gNetworkStatsClassInfo.rxBytes = GetFieldIDOrDie(env, clazz, "rxBytes", "[J");
gNetworkStatsClassInfo.rxPackets = env->GetFieldID(clazz, "rxPackets", "[J"); gNetworkStatsClassInfo.rxPackets = GetFieldIDOrDie(env, clazz, "rxPackets", "[J");
gNetworkStatsClassInfo.txBytes = env->GetFieldID(clazz, "txBytes", "[J"); gNetworkStatsClassInfo.txBytes = GetFieldIDOrDie(env, clazz, "txBytes", "[J");
gNetworkStatsClassInfo.txPackets = env->GetFieldID(clazz, "txPackets", "[J"); gNetworkStatsClassInfo.txPackets = GetFieldIDOrDie(env, clazz, "txPackets", "[J");
gNetworkStatsClassInfo.operations = env->GetFieldID(clazz, "operations", "[J"); gNetworkStatsClassInfo.operations = GetFieldIDOrDie(env, clazz, "operations", "[J");
return err; return err;
} }

Some files were not shown because too many files have changed in this diff Show More