diff options
author | Andreas Gampe <agampe@google.com> | 2014-11-21 10:36:14 -0800 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2014-11-21 10:36:14 -0800 |
commit | 7d13d9db1ef90063cb542ccd6554042a6a3263b7 (patch) | |
tree | 087eaefffcd35f9c4968408ea80080cda39e22ac /core | |
parent | 935fd8d0b1c7953e6e6610aea0c2d09d0fa8ba97 (diff) | |
parent | 3fc5e3cabfd9787e722b7720eabbcbba49984a94 (diff) | |
download | frameworks_base-7d13d9db1ef90063cb542ccd6554042a6a3263b7.zip frameworks_base-7d13d9db1ef90063cb542ccd6554042a6a3263b7.tar.gz frameworks_base-7d13d9db1ef90063cb542ccd6554042a6a3263b7.tar.bz2 |
resolved conflicts for merge of 3fc5e3ca to lmp-mr1-dev-plus-aosp
Change-Id: Id8286e5a4381315a6060251a8055b0f1d1a96019
Diffstat (limited to 'core')
104 files changed, 926 insertions, 1235 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk index d53a5b8..97e0fd3c 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -265,6 +265,10 @@ LOCAL_MODULE:= libandroid_runtime # off a GCC warning that Clang doesn't know. 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 $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/jni/android/graphics/AutoDecodeCancel.h b/core/jni/android/graphics/AutoDecodeCancel.h index 37b86f9..dd6a0d4 100644 --- a/core/jni/android/graphics/AutoDecodeCancel.h +++ b/core/jni/android/graphics/AutoDecodeCancel.h @@ -1,5 +1,5 @@ -#ifndef AutoDecodeCancel_DEFINED -#define AutoDecodeCancel_DEFINED +#ifndef _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_ +#define _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_ #include <jni.h> #include "SkImageDecoder.h" @@ -24,4 +24,4 @@ private: #endif }; -#endif +#endif // _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_ diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 61a34e5..ceec0e3 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -15,16 +15,12 @@ #include "android_nio_utils.h" #include "CreateJavaOutputStreamAdaptor.h" +#include "core_jni_helpers.h" + #include <jni.h> #include <ResourceCache.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 // 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[] = { { "nativeCreate", "([IIIIIIZ)Landroid/graphics/Bitmap;", (void*)Bitmap_creator }, @@ -917,10 +911,8 @@ static JNINativeMethod gBitmapMethods[] = { { "nativePrepareToDraw", "(J)V", (void*)Bitmap_prepareToDraw }, }; -#define kClassPathName "android/graphics/Bitmap" - int register_android_graphics_Bitmap(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, - gBitmapMethods, SK_ARRAY_COUNT(gBitmapMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/Bitmap", gBitmapMethods, + NELEM(gBitmapMethods)); } diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 0e08a8d..099f1b0 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -15,7 +15,7 @@ #include "JNIHelp.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <androidfw/Asset.h> #include <androidfw/ResourceTypes.h> #include <cutils/compiler.h> @@ -574,52 +574,40 @@ static JNINativeMethod gOptionsMethods[] = { { "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) { - jclass options_class = env->FindClass("android/graphics/BitmapFactory$Options"); - SkASSERT(options_class); - gOptions_bitmapFieldID = getFieldIDCheck(env, options_class, "inBitmap", + jclass options_class = FindClassOrDie(env, "android/graphics/BitmapFactory$Options"); + gOptions_bitmapFieldID = GetFieldIDOrDie(env, options_class, "inBitmap", "Landroid/graphics/Bitmap;"); - gOptions_justBoundsFieldID = getFieldIDCheck(env, options_class, "inJustDecodeBounds", "Z"); - gOptions_sampleSizeFieldID = getFieldIDCheck(env, options_class, "inSampleSize", "I"); - gOptions_configFieldID = getFieldIDCheck(env, options_class, "inPreferredConfig", + gOptions_justBoundsFieldID = GetFieldIDOrDie(env, options_class, "inJustDecodeBounds", "Z"); + gOptions_sampleSizeFieldID = GetFieldIDOrDie(env, options_class, "inSampleSize", "I"); + gOptions_configFieldID = GetFieldIDOrDie(env, options_class, "inPreferredConfig", "Landroid/graphics/Bitmap$Config;"); - gOptions_premultipliedFieldID = getFieldIDCheck(env, options_class, "inPremultiplied", "Z"); - gOptions_mutableFieldID = getFieldIDCheck(env, options_class, "inMutable", "Z"); - gOptions_ditherFieldID = getFieldIDCheck(env, options_class, "inDither", "Z"); - gOptions_preferQualityOverSpeedFieldID = getFieldIDCheck(env, options_class, + gOptions_premultipliedFieldID = GetFieldIDOrDie(env, options_class, "inPremultiplied", "Z"); + gOptions_mutableFieldID = GetFieldIDOrDie(env, options_class, "inMutable", "Z"); + gOptions_ditherFieldID = GetFieldIDOrDie(env, options_class, "inDither", "Z"); + gOptions_preferQualityOverSpeedFieldID = GetFieldIDOrDie(env, options_class, "inPreferQualityOverSpeed", "Z"); - gOptions_scaledFieldID = getFieldIDCheck(env, options_class, "inScaled", "Z"); - gOptions_densityFieldID = getFieldIDCheck(env, options_class, "inDensity", "I"); - gOptions_screenDensityFieldID = getFieldIDCheck(env, options_class, "inScreenDensity", "I"); - gOptions_targetDensityFieldID = getFieldIDCheck(env, options_class, "inTargetDensity", "I"); - gOptions_widthFieldID = getFieldIDCheck(env, options_class, "outWidth", "I"); - gOptions_heightFieldID = getFieldIDCheck(env, options_class, "outHeight", "I"); - gOptions_mimeFieldID = getFieldIDCheck(env, options_class, "outMimeType", "Ljava/lang/String;"); - gOptions_mCancelID = getFieldIDCheck(env, options_class, "mCancel", "Z"); - - jclass bitmap_class = env->FindClass("android/graphics/Bitmap"); - SkASSERT(bitmap_class); - gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "J"); - gBitmap_ninePatchInsetsFieldID = getFieldIDCheck(env, bitmap_class, "mNinePatchInsets", + gOptions_scaledFieldID = GetFieldIDOrDie(env, options_class, "inScaled", "Z"); + gOptions_densityFieldID = GetFieldIDOrDie(env, options_class, "inDensity", "I"); + gOptions_screenDensityFieldID = GetFieldIDOrDie(env, options_class, "inScreenDensity", "I"); + gOptions_targetDensityFieldID = GetFieldIDOrDie(env, options_class, "inTargetDensity", "I"); + gOptions_widthFieldID = GetFieldIDOrDie(env, options_class, "outWidth", "I"); + gOptions_heightFieldID = GetFieldIDOrDie(env, options_class, "outHeight", "I"); + gOptions_mimeFieldID = GetFieldIDOrDie(env, options_class, "outMimeType", "Ljava/lang/String;"); + gOptions_mCancelID = GetFieldIDOrDie(env, options_class, "mCancel", "Z"); + + jclass bitmap_class = FindClassOrDie(env, "android/graphics/Bitmap"); + gBitmap_nativeBitmapFieldID = GetFieldIDOrDie(env, bitmap_class, "mNativeBitmap", "J"); + gBitmap_ninePatchInsetsFieldID = GetFieldIDOrDie(env, bitmap_class, "mNinePatchInsets", "Landroid/graphics/NinePatch$InsetStruct;"); - gInsetStruct_class = (jclass) env->NewGlobalRef(env->FindClass("android/graphics/NinePatch$InsetStruct")); - gInsetStruct_constructorMethodID = env->GetMethodID(gInsetStruct_class, "<init>", "(IIIIIIIIFIF)V"); + gInsetStruct_class = MakeGlobalRefOrDie(env, FindClassOrDie(env, + "android/graphics/NinePatch$InsetStruct")); + gInsetStruct_constructorMethodID = GetMethodIDOrDie(env, gInsetStruct_class, "<init>", + "(IIIIIIIIFIF)V"); - int ret = AndroidRuntime::registerNativeMethods(env, - "android/graphics/BitmapFactory$Options", - gOptionsMethods, - SK_ARRAY_COUNT(gOptionsMethods)); - if (ret) { - return ret; - } - return android::AndroidRuntime::registerNativeMethods(env, "android/graphics/BitmapFactory", - gMethods, SK_ARRAY_COUNT(gMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory$Options", + gOptionsMethods, NELEM(gOptionsMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/BitmapFactory", + gMethods, NELEM(gMethods)); } diff --git a/core/jni/android/graphics/BitmapFactory.h b/core/jni/android/graphics/BitmapFactory.h index 97dcc6d..a54da43 100644 --- a/core/jni/android/graphics/BitmapFactory.h +++ b/core/jni/android/graphics/BitmapFactory.h @@ -1,5 +1,5 @@ -#ifndef BitmapFactory_DEFINE -#define BitmapFactory_DEFINE +#ifndef _ANDROID_GRAPHICS_BITMAP_FACTORY_H_ +#define _ANDROID_GRAPHICS_BITMAP_FACTORY_H_ #include "GraphicsJNI.h" @@ -21,4 +21,4 @@ extern jfieldID gOptions_bitmapFieldID; jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format); -#endif +#endif // _ANDROID_GRAPHICS_BITMAP_FACTORY_H_ diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp index 91efc8c..3537bcb 100644 --- a/core/jni/android/graphics/BitmapRegionDecoder.cpp +++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp @@ -30,7 +30,7 @@ #include "Utils.h" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "android_util_Binder.h" #include "android_nio_utils.h" #include "CreateJavaOutputStreamAdaptor.h" @@ -40,12 +40,6 @@ #include <androidfw/Asset.h> #include <sys/stat.h> -#if 0 - #define TRACE_BITMAP(code) code -#else - #define TRACE_BITMAP(code) -#endif - using namespace android; class SkBitmapRegionDecoder { @@ -273,8 +267,6 @@ static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) { /////////////////////////////////////////////////////////////////////////////// -#include <android_runtime/AndroidRuntime.h> - static JNINativeMethod gBitmapRegionDecoderMethods[] = { { "nativeDecodeRegion", "(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) { - return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, - gBitmapRegionDecoderMethods, SK_ARRAY_COUNT(gBitmapRegionDecoderMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/BitmapRegionDecoder", + gBitmapRegionDecoderMethods, NELEM(gBitmapRegionDecoderMethods)); } diff --git a/core/jni/android/graphics/Camera.cpp b/core/jni/android/graphics/Camera.cpp index 9f832b0..b572604 100644 --- a/core/jni/android/graphics/Camera.cpp +++ b/core/jni/android/graphics/Camera.cpp @@ -1,5 +1,5 @@ #include "jni.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "SkCamera.h" @@ -137,16 +137,8 @@ static JNINativeMethod gCameraMethods[] = { }; int register_android_graphics_Camera(JNIEnv* env) { - jclass clazz = env->FindClass("android/graphics/Camera"); - if (clazz == 0) { - return -1; - } - 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)); + jclass clazz = android::FindClassOrDie(env, "android/graphics/Camera"); + gNativeInstanceFieldID = android::GetFieldIDOrDie(env, clazz, "native_instance", "J"); + return android::RegisterMethodsOrDie(env, "android/graphics/Camera", gCameraMethods, + NELEM(gCameraMethods)); } diff --git a/core/jni/android/graphics/CanvasProperty.cpp b/core/jni/android/graphics/CanvasProperty.cpp index e63c5fa..a69a457 100644 --- a/core/jni/android/graphics/CanvasProperty.cpp +++ b/core/jni/android/graphics/CanvasProperty.cpp @@ -17,16 +17,20 @@ #include "jni.h" #include "GraphicsJNI.h" #include "Paint.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include <utils/RefBase.h> #include <CanvasProperty.h> namespace android { -using namespace uirenderer; - #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) { 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)); } -#endif - // ---------------------------------------------------------------------------- // JNI Glue // ---------------------------------------------------------------------------- -const char* const kClassPathName = "android/graphics/CanvasProperty"; - static JNINativeMethod gMethods[] = { -#ifdef USE_OPENGL_RENDERER { "nCreateFloat", "(F)J", (void*) createFloat }, { "nCreatePaint", "(J)J", (void*) createPaint }, -#endif }; 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 diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp index c66c844..026cbee 100644 --- a/core/jni/android/graphics/ColorFilter.cpp +++ b/core/jni/android/graphics/ColorFilter.cpp @@ -17,7 +17,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "SkColorFilter.h" #include "SkColorMatrixFilter.h" @@ -74,18 +74,15 @@ static JNINativeMethod colormatrix_methods[] = { { "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 result; - - REG(env, "android/graphics/ColorFilter", colorfilter_methods); - REG(env, "android/graphics/PorterDuffColorFilter", porterduff_methods); - REG(env, "android/graphics/LightingColorFilter", lighting_methods); - REG(env, "android/graphics/ColorMatrixColorFilter", colormatrix_methods); + android::RegisterMethodsOrDie(env, "android/graphics/ColorFilter", colorfilter_methods, + NELEM(colorfilter_methods)); + android::RegisterMethodsOrDie(env, "android/graphics/PorterDuffColorFilter", porterduff_methods, + NELEM(porterduff_methods)); + android::RegisterMethodsOrDie(env, "android/graphics/LightingColorFilter", lighting_methods, + NELEM(lighting_methods)); + android::RegisterMethodsOrDie(env, "android/graphics/ColorMatrixColorFilter", + colormatrix_methods, NELEM(colormatrix_methods)); return 0; } diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.h b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.h index ecd270f..56cba51 100644 --- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.h +++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.h @@ -1,5 +1,5 @@ -#ifndef CreateJavaOutputStream_DEFINED -#define CreateJavaOutputStream_DEFINED +#ifndef _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_ +#define _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_ //#include <android_runtime/AndroidRuntime.h> #include "jni.h" @@ -38,4 +38,5 @@ SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream, SkWStream* CreateJavaOutputStreamAdaptor(JNIEnv* env, jobject stream, jbyteArray storage); -#endif + +#endif // _ANDROID_GRAPHICS_CREATE_JAVA_OUTPUT_STREAM_ADAPTOR_H_ diff --git a/core/jni/android/graphics/DrawFilter.cpp b/core/jni/android/graphics/DrawFilter.cpp index 3275875..bac124f 100644 --- a/core/jni/android/graphics/DrawFilter.cpp +++ b/core/jni/android/graphics/DrawFilter.cpp @@ -24,6 +24,8 @@ #include "GraphicsJNI.h" #include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" + #include "SkDrawFilter.h" #include "SkPaintFlagsDrawFilter.h" #include "SkPaint.h" @@ -103,16 +105,11 @@ static JNINativeMethod paintflags_methods[] = { {"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 result; - - REG(env, "android/graphics/DrawFilter", drawfilter_methods); - REG(env, "android/graphics/PaintFlagsDrawFilter", paintflags_methods); + int result = RegisterMethodsOrDie(env, "android/graphics/DrawFilter", drawfilter_methods, + NELEM(drawfilter_methods)); + result |= RegisterMethodsOrDie(env, "android/graphics/PaintFlagsDrawFilter", paintflags_methods, + NELEM(paintflags_methods)); return 0; } diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp index bfb30b7..8a85d62 100644 --- a/core/jni/android/graphics/FontFamily.cpp +++ b/core/jni/android/graphics/FontFamily.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "Minikin" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include "SkTypeface.h" #include "GraphicsJNI.h" @@ -125,9 +125,8 @@ static JNINativeMethod gFontFamilyMethods[] = { int register_android_graphics_FontFamily(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, - "android/graphics/FontFamily", - gFontFamilyMethods, NELEM(gFontFamilyMethods)); + return RegisterMethodsOrDie(env, "android/graphics/FontFamily", gFontFamilyMethods, + NELEM(gFontFamilyMethods)); } } diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h index 8ef56cf..45b31c0 100644 --- a/core/jni/android/graphics/GraphicsJNI.h +++ b/core/jni/android/graphics/GraphicsJNI.h @@ -1,5 +1,5 @@ -#ifndef GraphicsJNI_DEFINED -#define GraphicsJNI_DEFINED +#ifndef _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ +#define _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ #pragma GCC diagnostic push #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) \ do { if (NULL == (object)) { doThrowNPE(env); return; } } while (0) -#endif +#endif // _ANDROID_GRAPHICS_GRAPHICS_JNI_H_ diff --git a/core/jni/android/graphics/HarfBuzzNGFaceSkia.cpp b/core/jni/android/graphics/HarfBuzzNGFaceSkia.cpp index a75efcf..ca3a42f 100644 --- a/core/jni/android/graphics/HarfBuzzNGFaceSkia.cpp +++ b/core/jni/android/graphics/HarfBuzzNGFaceSkia.cpp @@ -44,6 +44,8 @@ namespace android { +static const bool kDebugGlyphs = false; + // Our implementation of the callbacks which Harfbuzz requires by using Skia // 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; paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds); -#if DEBUG_GLYPHS - ALOGD("returned glyph for %i: width = %f", codepoint, skWidth); -#endif + if (kDebugGlyphs) { + ALOGD("returned glyph for %i: width = %f", codepoint, skWidth); + } if (width) *width = SkScalarToHBFixed(skWidth); if (extents) { diff --git a/core/jni/android/graphics/HarfBuzzNGFaceSkia.h b/core/jni/android/graphics/HarfBuzzNGFaceSkia.h index 7b71ecc..3308d5d 100644 --- a/core/jni/android/graphics/HarfBuzzNGFaceSkia.h +++ b/core/jni/android/graphics/HarfBuzzNGFaceSkia.h @@ -24,8 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HarfBuzzNGFaceSkia_h -#define HarfBuzzNGFaceSkia_h +#ifndef _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_ +#define _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_ #include <SkScalar.h> #include <SkPaint.h> @@ -56,4 +56,4 @@ hb_font_t* createFont(hb_face_t* face, SkPaint* paint, float sizeX, float sizeY) } // namespace android -#endif +#endif // _ANDROID_GRAPHICS_HARF_BUZZ_NG_FACE_SKIA_H_ diff --git a/core/jni/android/graphics/Interpolator.cpp b/core/jni/android/graphics/Interpolator.cpp index 455f867..f7f3511 100644 --- a/core/jni/android/graphics/Interpolator.cpp +++ b/core/jni/android/graphics/Interpolator.cpp @@ -1,5 +1,5 @@ #include "jni.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "GraphicsJNI.h" #include "SkInterpolator.h" @@ -83,8 +83,6 @@ static JNINativeMethod gInterpolatorMethods[] = { int register_android_graphics_Interpolator(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, - "android/graphics/Interpolator", - gInterpolatorMethods, - SK_ARRAY_COUNT(gInterpolatorMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/Interpolator", + gInterpolatorMethods, NELEM(gInterpolatorMethods)); } diff --git a/core/jni/android/graphics/MaskFilter.cpp b/core/jni/android/graphics/MaskFilter.cpp index b394905..d658643 100644 --- a/core/jni/android/graphics/MaskFilter.cpp +++ b/core/jni/android/graphics/MaskFilter.cpp @@ -4,6 +4,8 @@ #include "SkBlurMaskFilter.h" #include "SkTableMaskFilter.h" +#include "core_jni_helpers.h" + #include <jni.h> static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) { @@ -77,20 +79,16 @@ static JNINativeMethod gTableMaskFilterMethods[] = { { "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 result; - - REG(env, "android/graphics/MaskFilter", gMaskFilterMethods); - REG(env, "android/graphics/BlurMaskFilter", gBlurMaskFilterMethods); - REG(env, "android/graphics/EmbossMaskFilter", gEmbossMaskFilterMethods); - REG(env, "android/graphics/TableMaskFilter", gTableMaskFilterMethods); + android::RegisterMethodsOrDie(env, "android/graphics/MaskFilter", gMaskFilterMethods, + NELEM(gMaskFilterMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/BlurMaskFilter", gBlurMaskFilterMethods, + NELEM(gBlurMaskFilterMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/EmbossMaskFilter", + gEmbossMaskFilterMethods, NELEM(gEmbossMaskFilterMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/TableMaskFilter", gTableMaskFilterMethods, + NELEM(gTableMaskFilterMethods)); return 0; } diff --git a/core/jni/android/graphics/Matrix.cpp b/core/jni/android/graphics/Matrix.cpp index 01ab699..0ff7c78 100644 --- a/core/jni/android/graphics/Matrix.cpp +++ b/core/jni/android/graphics/Matrix.cpp @@ -17,7 +17,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include "SkMatrix.h" #include "SkTemplates.h" @@ -354,11 +354,10 @@ static JNINativeMethod methods[] = { static jfieldID sNativeInstanceField; int register_android_graphics_Matrix(JNIEnv* env) { - int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Matrix", methods, - sizeof(methods) / sizeof(methods[0])); + int result = RegisterMethodsOrDie(env, "android/graphics/Matrix", methods, NELEM(methods)); - jclass clazz = env->FindClass("android/graphics/Matrix"); - sNativeInstanceField = env->GetFieldID(clazz, "native_instance", "J"); + jclass clazz = FindClassOrDie(env, "android/graphics/Matrix"); + sNativeInstanceField = GetFieldIDOrDie(env, clazz, "native_instance", "J"); return result; } diff --git a/core/jni/android/graphics/Matrix.h b/core/jni/android/graphics/Matrix.h index 31edf88..11c9e72 100644 --- a/core/jni/android/graphics/Matrix.h +++ b/core/jni/android/graphics/Matrix.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _ANDROID_GRAPHICS_MATRIX_H -#define _ANDROID_GRAPHICS_MATRIX_H +#ifndef _ANDROID_GRAPHICS_MATRIX_H_ +#define _ANDROID_GRAPHICS_MATRIX_H_ #include "jni.h" #include "SkMatrix.h" @@ -27,4 +27,4 @@ extern SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrix } // namespace android -#endif // _ANDROID_GRAPHICS_MATRIX_H +#endif // _ANDROID_GRAPHICS_MATRIX_H_ diff --git a/core/jni/android/graphics/MinikinSkia.h b/core/jni/android/graphics/MinikinSkia.h index 255617e..a06428d 100644 --- a/core/jni/android/graphics/MinikinSkia.h +++ b/core/jni/android/graphics/MinikinSkia.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_MINIKIN_SKIA_H -#define ANDROID_MINIKIN_SKIA_H +#ifndef _ANDROID_GRAPHICS_MINIKIN_SKIA_H_ +#define _ANDROID_GRAPHICS_MINIKIN_SKIA_H_ #include <minikin/MinikinFont.h> @@ -54,4 +54,4 @@ private: } // namespace android -#endif // ANDROID_MINIKIN_SKIA_H
\ No newline at end of file +#endif // _ANDROID_GRAPHICS_MINIKIN_SKIA_H_
\ No newline at end of file diff --git a/core/jni/android/graphics/MinikinUtils.h b/core/jni/android/graphics/MinikinUtils.h index 3646c1a..236f1fd 100644 --- a/core/jni/android/graphics/MinikinUtils.h +++ b/core/jni/android/graphics/MinikinUtils.h @@ -21,8 +21,8 @@ // TODO: does this really need to be separate from MinikinSkia? -#ifndef ANDROID_MINIKIN_UTILS_H -#define ANDROID_MINIKIN_UTILS_H +#ifndef _ANDROID_GRAPHICS_MINIKIN_UTILS_H_ +#define _ANDROID_GRAPHICS_MINIKIN_UTILS_H_ #include <minikin/Layout.h> #include "Paint.h" @@ -81,4 +81,4 @@ public: } // namespace android -#endif // ANDROID_MINIKIN_UTILS_H +#endif // _ANDROID_GRAPHICS_MINIKIN_UTILS_H_ diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp index 226f83e..b25fa84 100644 --- a/core/jni/android/graphics/Movie.cpp +++ b/core/jni/android/graphics/Movie.cpp @@ -13,11 +13,7 @@ #include <androidfw/ResourceTypes.h> #include <netinet/in.h> -#if 0 - #define TRACE_BITMAP(code) code -#else - #define TRACE_BITMAP(code) -#endif +#include "core_jni_helpers.h" static jclass gMovie_class; 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[] = { { "width", "()I", (void*)movie_width }, { "height", "()I", (void*)movie_height }, @@ -157,22 +151,14 @@ static JNINativeMethod gMethods[] = { (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) { - gMovie_class = env->FindClass(kClassPathName); - RETURN_ERR_IF_NULL(gMovie_class); - gMovie_class = (jclass)env->NewGlobalRef(gMovie_class); + gMovie_class = android::FindClassOrDie(env, "android/graphics/Movie"); + gMovie_class = android::MakeGlobalRefOrDie(env, gMovie_class); - gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(J)V"); - RETURN_ERR_IF_NULL(gMovie_constructorMethodID); + gMovie_constructorMethodID = android::GetMethodIDOrDie(env, gMovie_class, "<init>", "(J)V"); - gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "J"); - RETURN_ERR_IF_NULL(gMovie_nativeInstanceID); + gMovie_nativeInstanceID = android::GetFieldIDOrDie(env, gMovie_class, "mNativeMovie", "J"); - return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, - gMethods, SK_ARRAY_COUNT(gMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/Movie", gMethods, NELEM(gMethods)); } diff --git a/core/jni/android/graphics/NinePatch.cpp b/core/jni/android/graphics/NinePatch.cpp index be62fdd..d868f28 100644 --- a/core/jni/android/graphics/NinePatch.cpp +++ b/core/jni/android/graphics/NinePatch.cpp @@ -30,6 +30,7 @@ #include "GraphicsJNI.h" #include "JNIHelp.h" +#include "core_jni_helpers.h" extern void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, const SkBitmap& bitmap, const android::Res_png_9patch& chunk, const SkPaint* paint, SkRegion** outRegion); @@ -176,8 +177,6 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// -#include <android_runtime/AndroidRuntime.h> - static JNINativeMethod gNinePatchMethods[] = { { "isNinePatchChunk", "([B)Z", (void*) SkNinePatchGlue::isNinePatchChunk }, { "validateNinePatchChunk", "(J[B)J", (void*) SkNinePatchGlue::validateNinePatchChunk }, @@ -189,6 +188,6 @@ static JNINativeMethod gNinePatchMethods[] = { }; int register_android_graphics_NinePatch(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, - "android/graphics/NinePatch", gNinePatchMethods, SK_ARRAY_COUNT(gNinePatchMethods)); + return android::RegisterMethodsOrDie(env, + "android/graphics/NinePatch", gNinePatchMethods, NELEM(gNinePatchMethods)); } diff --git a/core/jni/android/graphics/NinePatchImpl.cpp b/core/jni/android/graphics/NinePatchImpl.cpp index 39a9554..4c589b7 100644 --- a/core/jni/android/graphics/NinePatchImpl.cpp +++ b/core/jni/android/graphics/NinePatchImpl.cpp @@ -23,20 +23,16 @@ #include "SkBitmap.h" #include "SkCanvas.h" +#include "SkColorPriv.h" #include "SkNinePatch.h" #include "SkPaint.h" #include "SkUnPreMultiply.h" -#define USE_TRACE - -#ifdef USE_TRACE - static bool gTrace; -#endif - -#include "SkColorPriv.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) { switch (bitmap.colorType()) { case kN32_SkColorType: @@ -128,37 +124,34 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, return; } -#ifdef USE_TRACE - gTrace = true; -#endif + if (kUseTrace) { + gTrace = true; + } SkASSERT(canvas || outRegion); -#ifdef USE_TRACE - if (canvas) { - const SkMatrix& m = canvas->getTotalMatrix(); - ALOGV("ninepatch [%g %g %g] [%g %g %g]\n", - SkScalarToFloat(m[0]), SkScalarToFloat(m[1]), SkScalarToFloat(m[2]), - SkScalarToFloat(m[3]), SkScalarToFloat(m[4]), SkScalarToFloat(m[5])); - } -#endif + if (kUseTrace) { + if (canvas) { + const SkMatrix& m = canvas->getTotalMatrix(); + ALOGV("ninepatch [%g %g %g] [%g %g %g]\n", + SkScalarToFloat(m[0]), SkScalarToFloat(m[1]), SkScalarToFloat(m[2]), + SkScalarToFloat(m[3]), SkScalarToFloat(m[4]), SkScalarToFloat(m[5])); + } -#ifdef USE_TRACE - if (gTrace) { - ALOGV("======== ninepatch bounds [%g %g]\n", SkScalarToFloat(bounds.width()), 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 xDivs [%d,%d]\n", xDivs[0], xDivs[1]); ALOGV("======== ninepatch yDivs [%d,%d]\n", yDivs[0], yDivs[1]); } -#endif if (bounds.isEmpty() || bitmap.width() == 0 || bitmap.height() == 0 || (paint && paint->getXfermode() == NULL && paint->getAlpha() == 0)) { -#ifdef USE_TRACE - if (gTrace) ALOGV("======== abort ninepatch draw\n"); -#endif + if (kUseTrace) { + ALOGV("======== abort ninepatch draw\n"); + } return; } @@ -202,13 +195,13 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, } int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining; -#ifdef USE_TRACE - ALOGV("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n", - bitmap.width(), bitmap.height(), - SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop), - SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()), - numXDivs, numYDivs); -#endif + if (kUseTrace) { + ALOGV("NinePatch [%d %d] bounds [%g %g %g %g] divs [%d %d]\n", + bitmap.width(), bitmap.height(), + SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop), + SkScalarToFloat(bounds.width()), SkScalarToFloat(bounds.height()), + numXDivs, numYDivs); + } src.fTop = 0; dst.fTop = bounds.fTop; @@ -307,15 +300,15 @@ void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, goto nextDiv; } if (canvas) { -#ifdef USE_TRACE - ALOGV("-- src [%d %d %d %d] dst [%g %g %g %g]\n", - src.fLeft, src.fTop, src.width(), src.height(), - SkScalarToFloat(dst.fLeft), SkScalarToFloat(dst.fTop), - SkScalarToFloat(dst.width()), SkScalarToFloat(dst.height())); - if (2 == src.width() && SkIntToScalar(5) == dst.width()) { - ALOGV("--- skip patch\n"); + if (kUseTrace) { + ALOGV("-- src [%d %d %d %d] dst [%g %g %g %g]\n", + src.fLeft, src.fTop, src.width(), src.height(), + SkScalarToFloat(dst.fLeft), SkScalarToFloat(dst.fTop), + SkScalarToFloat(dst.width()), SkScalarToFloat(dst.height())); + if (2 == src.width() && SkIntToScalar(5) == dst.width()) { + ALOGV("--- skip patch\n"); + } } -#endif drawStretchyPatch(canvas, src, dst, bitmap, *paint, initColor, color, hasXfer); } diff --git a/core/jni/android/graphics/NinePatchPeeker.h b/core/jni/android/graphics/NinePatchPeeker.h index 7c18b2d..2d49b38 100644 --- a/core/jni/android/graphics/NinePatchPeeker.h +++ b/core/jni/android/graphics/NinePatchPeeker.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef NinePatchPeeker_h -#define NinePatchPeeker_h +#ifndef _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_ +#define _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_ #include "SkImageDecoder.h" #include <androidfw/ResourceTypes.h> @@ -53,4 +53,4 @@ public: uint8_t mOutlineAlpha; }; -#endif // NinePatchPeeker_h +#endif // _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_ diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 6b02326..2cd2db7 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -21,7 +21,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <ScopedUtfChars.h> #include "SkBlurDrawLooper.h" @@ -1021,35 +1021,26 @@ static JNINativeMethod methods[] = { {"native_hasShadowLayer", "!(J)Z", (void*)PaintGlue::hasShadowLayer} }; -static jfieldID req_fieldID(jfieldID id) { - SkASSERT(id); - return id; -} - int register_android_graphics_Paint(JNIEnv* env) { - gFontMetrics_class = env->FindClass("android/graphics/Paint$FontMetrics"); - SkASSERT(gFontMetrics_class); - gFontMetrics_class = (jclass)env->NewGlobalRef(gFontMetrics_class); - - gFontMetrics_fieldID.top = req_fieldID(env->GetFieldID(gFontMetrics_class, "top", "F")); - gFontMetrics_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetrics_class, "ascent", "F")); - gFontMetrics_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetrics_class, "descent", "F")); - gFontMetrics_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetrics_class, "bottom", "F")); - gFontMetrics_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetrics_class, "leading", "F")); - - gFontMetricsInt_class = env->FindClass("android/graphics/Paint$FontMetricsInt"); - SkASSERT(gFontMetricsInt_class); - gFontMetricsInt_class = (jclass)env->NewGlobalRef(gFontMetricsInt_class); - - gFontMetricsInt_fieldID.top = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "top", "I")); - gFontMetricsInt_fieldID.ascent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "ascent", "I")); - gFontMetricsInt_fieldID.descent = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "descent", "I")); - gFontMetricsInt_fieldID.bottom = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "bottom", "I")); - gFontMetricsInt_fieldID.leading = req_fieldID(env->GetFieldID(gFontMetricsInt_class, "leading", "I")); - - int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Paint", methods, - sizeof(methods) / sizeof(methods[0])); - return result; + gFontMetrics_class = FindClassOrDie(env, "android/graphics/Paint$FontMetrics"); + gFontMetrics_class = MakeGlobalRefOrDie(env, gFontMetrics_class); + + gFontMetrics_fieldID.top = GetFieldIDOrDie(env, gFontMetrics_class, "top", "F"); + gFontMetrics_fieldID.ascent = GetFieldIDOrDie(env, gFontMetrics_class, "ascent", "F"); + gFontMetrics_fieldID.descent = GetFieldIDOrDie(env, gFontMetrics_class, "descent", "F"); + gFontMetrics_fieldID.bottom = GetFieldIDOrDie(env, gFontMetrics_class, "bottom", "F"); + gFontMetrics_fieldID.leading = GetFieldIDOrDie(env, gFontMetrics_class, "leading", "F"); + + gFontMetricsInt_class = FindClassOrDie(env, "android/graphics/Paint$FontMetricsInt"); + gFontMetricsInt_class = MakeGlobalRefOrDie(env, gFontMetricsInt_class); + + gFontMetricsInt_fieldID.top = GetFieldIDOrDie(env, gFontMetricsInt_class, "top", "I"); + gFontMetricsInt_fieldID.ascent = GetFieldIDOrDie(env, gFontMetricsInt_class, "ascent", "I"); + gFontMetricsInt_fieldID.descent = GetFieldIDOrDie(env, gFontMetricsInt_class, "descent", "I"); + gFontMetricsInt_fieldID.bottom = GetFieldIDOrDie(env, gFontMetricsInt_class, "bottom", "I"); + gFontMetricsInt_fieldID.leading = GetFieldIDOrDie(env, gFontMetricsInt_class, "leading", "I"); + + return RegisterMethodsOrDie(env, "android/graphics/Paint", methods, NELEM(methods)); } } diff --git a/core/jni/android/graphics/Paint.h b/core/jni/android/graphics/Paint.h index a20bb4b..fa539f5 100644 --- a/core/jni/android/graphics/Paint.h +++ b/core/jni/android/graphics/Paint.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_GRAPHICS_PAINT_H -#define ANDROID_GRAPHICS_PAINT_H +#ifndef ANDROID_GRAPHICS_PAINT_H_ +#define ANDROID_GRAPHICS_PAINT_H_ #include <SkPaint.h> #include <string> @@ -78,4 +78,4 @@ private: } // namespace android -#endif // ANDROID_GRAPHICS_PAINT_H +#endif // ANDROID_GRAPHICS_PAINT_H_ diff --git a/core/jni/android/graphics/Path.cpp b/core/jni/android/graphics/Path.cpp index 30ce58d..1e4eb75 100644 --- a/core/jni/android/graphics/Path.cpp +++ b/core/jni/android/graphics/Path.cpp @@ -22,7 +22,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "SkPath.h" #include "SkPathOps.h" @@ -520,9 +520,7 @@ static JNINativeMethod methods[] = { }; int register_android_graphics_Path(JNIEnv* env) { - int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Path", methods, - sizeof(methods) / sizeof(methods[0])); - return result; + return RegisterMethodsOrDie(env, "android/graphics/Path", methods, NELEM(methods)); } } diff --git a/core/jni/android/graphics/PathEffect.cpp b/core/jni/android/graphics/PathEffect.cpp index 28d881d..9d0f0ad 100644 --- a/core/jni/android/graphics/PathEffect.cpp +++ b/core/jni/android/graphics/PathEffect.cpp @@ -1,6 +1,8 @@ #include <jni.h> #include "GraphicsJNI.h" +#include "core_jni_helpers.h" + #include "SkPathEffect.h" #include "SkCornerPathEffect.h" #include "SkDashPathEffect.h" @@ -97,24 +99,22 @@ static JNINativeMethod gDiscretePathEffectMethods[] = { { "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 result; - - REG(env, "android/graphics/PathEffect", gPathEffectMethods); - REG(env, "android/graphics/ComposePathEffect", gComposePathEffectMethods); - REG(env, "android/graphics/SumPathEffect", gSumPathEffectMethods); - REG(env, "android/graphics/DashPathEffect", gDashPathEffectMethods); - REG(env, "android/graphics/PathDashPathEffect", gPathDashPathEffectMethods); - REG(env, "android/graphics/CornerPathEffect", gCornerPathEffectMethods); - REG(env, "android/graphics/DiscretePathEffect", gDiscretePathEffectMethods); + android::RegisterMethodsOrDie(env, "android/graphics/PathEffect", gPathEffectMethods, + NELEM(gPathEffectMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/ComposePathEffect", + gComposePathEffectMethods, NELEM(gComposePathEffectMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/SumPathEffect", gSumPathEffectMethods, + NELEM(gSumPathEffectMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/DashPathEffect", gDashPathEffectMethods, + NELEM(gDashPathEffectMethods)); + 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; } diff --git a/core/jni/android/graphics/PathMeasure.cpp b/core/jni/android/graphics/PathMeasure.cpp index 13f68a9..fec5d9d 100644 --- a/core/jni/android/graphics/PathMeasure.cpp +++ b/core/jni/android/graphics/PathMeasure.cpp @@ -17,7 +17,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include "SkPathMeasure.h" @@ -156,9 +156,7 @@ static JNINativeMethod methods[] = { }; int register_android_graphics_PathMeasure(JNIEnv* env) { - int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/PathMeasure", methods, - sizeof(methods) / sizeof(methods[0])); - return result; + return RegisterMethodsOrDie(env, "android/graphics/PathMeasure", methods, NELEM(methods)); } } diff --git a/core/jni/android/graphics/Picture.h b/core/jni/android/graphics/Picture.h index a2e5d4a..4db923d 100644 --- a/core/jni/android/graphics/Picture.h +++ b/core/jni/android/graphics/Picture.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_GRAPHICS_PICTURE_H -#define ANDROID_GRAPHICS_PICTURE_H +#ifndef ANDROID_GRAPHICS_PICTURE_H_ +#define ANDROID_GRAPHICS_PICTURE_H_ #include "SkPicture.h" #include "SkPictureRecorder.h" @@ -63,4 +63,4 @@ private: }; }; // namespace android -#endif // ANDROID_GRAPHICS_PICTURE_H +#endif // ANDROID_GRAPHICS_PICTURE_H_ diff --git a/core/jni/android/graphics/PorterDuff.cpp b/core/jni/android/graphics/PorterDuff.cpp index 8a49eb5..73b1691 100644 --- a/core/jni/android/graphics/PorterDuff.cpp +++ b/core/jni/android/graphics/PorterDuff.cpp @@ -22,7 +22,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "SkPorterDuff.h" @@ -43,10 +43,7 @@ static JNINativeMethod methods[] = { }; int register_android_graphics_PorterDuff(JNIEnv* env) { - int result = AndroidRuntime::registerNativeMethods(env, - "android/graphics/PorterDuffXfermode", methods, - sizeof(methods) / sizeof(methods[0])); - return result; + return RegisterMethodsOrDie(env, "android/graphics/PorterDuffXfermode", methods, NELEM(methods)); } } diff --git a/core/jni/android/graphics/Rasterizer.cpp b/core/jni/android/graphics/Rasterizer.cpp index 2b1aca1..cfc23ac8 100644 --- a/core/jni/android/graphics/Rasterizer.cpp +++ b/core/jni/android/graphics/Rasterizer.cpp @@ -24,7 +24,7 @@ #include "GraphicsJNI.h" #include "Paint.h" #include "SkLayerRasterizer.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" // Rasterizer.java holds a pointer (jlong) to this guy class NativeRasterizer { @@ -59,7 +59,6 @@ public: static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { delete reinterpret_cast<NativeRasterizer *>(objHandle); } - }; static JNINativeMethod gRasterizerMethods[] = { @@ -67,9 +66,8 @@ static JNINativeMethod gRasterizerMethods[] = { }; int register_android_graphics_Rasterizer(JNIEnv* env) { - int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Rasterizer", gRasterizerMethods, - sizeof(gRasterizerMethods) / sizeof(gRasterizerMethods[0])); - return result; + return RegisterMethodsOrDie(env, "android/graphics/Rasterizer", gRasterizerMethods, + NELEM(gRasterizerMethods)); } class SkLayerRasterizerGlue { @@ -94,10 +92,8 @@ static JNINativeMethod gLayerRasterizerMethods[] = { int register_android_graphics_LayerRasterizer(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, - "android/graphics/LayerRasterizer", - gLayerRasterizerMethods, - SK_ARRAY_COUNT(gLayerRasterizerMethods)); + return RegisterMethodsOrDie(env, "android/graphics/LayerRasterizer", + gLayerRasterizerMethods, NELEM(gLayerRasterizerMethods)); } } diff --git a/core/jni/android/graphics/Region.cpp b/core/jni/android/graphics/Region.cpp index 912968a..90a020e 100644 --- a/core/jni/android/graphics/Region.cpp +++ b/core/jni/android/graphics/Region.cpp @@ -23,7 +23,7 @@ #include "android_util_Binder.h" #include <jni.h> -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> namespace android { @@ -325,19 +325,13 @@ static JNINativeMethod gRegionMethods[] = { int register_android_graphics_Region(JNIEnv* env) { - jclass clazz = env->FindClass("android/graphics/Region"); - SkASSERT(clazz); + jclass clazz = FindClassOrDie(env, "android/graphics/Region"); - gRegion_nativeInstanceFieldID = env->GetFieldID(clazz, "mNativeRegion", "J"); - SkASSERT(gRegion_nativeInstanceFieldID); + gRegion_nativeInstanceFieldID = GetFieldIDOrDie(env, clazz, "mNativeRegion", "J"); - int result = android::AndroidRuntime::registerNativeMethods(env, "android/graphics/Region", - gRegionMethods, SK_ARRAY_COUNT(gRegionMethods)); - if (result < 0) - return result; - - return android::AndroidRuntime::registerNativeMethods(env, "android/graphics/RegionIterator", - gRegionIterMethods, SK_ARRAY_COUNT(gRegionIterMethods)); + RegisterMethodsOrDie(env, "android/graphics/Region", gRegionMethods, NELEM(gRegionMethods)); + return RegisterMethodsOrDie(env, "android/graphics/RegionIterator", gRegionIterMethods, + NELEM(gRegionIterMethods)); } SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj) { diff --git a/core/jni/android/graphics/Region.h b/core/jni/android/graphics/Region.h index c15f06e..2e8e109 100644 --- a/core/jni/android/graphics/Region.h +++ b/core/jni/android/graphics/Region.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _ANDROID_GRAPHICS_REGION_H -#define _ANDROID_GRAPHICS_REGION_H +#ifndef _ANDROID_GRAPHICS_REGION_H_ +#define _ANDROID_GRAPHICS_REGION_H_ #include "jni.h" #include "SkRegion.h" @@ -27,4 +27,4 @@ extern SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject region } // namespace android -#endif // _ANDROID_GRAPHICS_REGION_H +#endif // _ANDROID_GRAPHICS_REGION_H_ diff --git a/core/jni/android/graphics/RtlProperties.h b/core/jni/android/graphics/RtlProperties.h index d43745f..907dd59 100644 --- a/core/jni/android/graphics/RtlProperties.h +++ b/core/jni/android/graphics/RtlProperties.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ANDROID_RTL_PROPERTIES_H -#define ANDROID_RTL_PROPERTIES_H +#ifndef _ANDROID_GRAPHICS_RTL_PROPERTIES_H_ +#define _ANDROID_GRAPHICS_RTL_PROPERTIES_H_ #include <cutils/properties.h> #include <stdlib.h> @@ -45,11 +45,5 @@ static RtlDebugLevel readRtlDebugLevel() { 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 -#endif // ANDROID_RTL_PROPERTIES_H +#endif // _ANDROID_GRAPHICS_RTL_PROPERTIES_H_ diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp index 70a2fe5..9ec9c58 100644 --- a/core/jni/android/graphics/Shader.cpp +++ b/core/jni/android/graphics/Shader.cpp @@ -11,6 +11,8 @@ #include <SkiaShader.h> #include <Caches.h> +#include "core_jni_helpers.h" + using namespace android::uirenderer; static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) { @@ -260,23 +262,22 @@ static JNINativeMethod gComposeShaderMethods[] = { { "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 result; - - REG(env, "android/graphics/Color", gColorMethods); - 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; + 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)); + + return 0; } diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index eaca6d2..35d69fe 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -24,7 +24,7 @@ #include <gui/GLConsumer.h> #include <gui/Surface.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/Log.h> #include <utils/misc.h> @@ -359,10 +359,8 @@ static JNINativeMethod gSurfaceTextureMethods[] = { int register_android_graphics_SurfaceTexture(JNIEnv* env) { - int err = 0; - err = AndroidRuntime::registerNativeMethods(env, kSurfaceTextureClassPathName, - gSurfaceTextureMethods, NELEM(gSurfaceTextureMethods)); - return err; + return RegisterMethodsOrDie(env, kSurfaceTextureClassPathName, gSurfaceTextureMethods, + NELEM(gSurfaceTextureMethods)); } } // namespace android diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp index 2029658..808ae2c 100644 --- a/core/jni/android/graphics/Typeface.cpp +++ b/core/jni/android/graphics/Typeface.cpp @@ -15,7 +15,7 @@ */ #include "jni.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "GraphicsJNI.h" #include <ScopedPrimitiveArray.h> @@ -81,8 +81,6 @@ static JNINativeMethod gTypefaceMethods[] = { int register_android_graphics_Typeface(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, - "android/graphics/Typeface", - gTypefaceMethods, - SK_ARRAY_COUNT(gTypefaceMethods)); + return RegisterMethodsOrDie(env, "android/graphics/Typeface", gTypefaceMethods, + NELEM(gTypefaceMethods)); } diff --git a/core/jni/android/graphics/TypefaceImpl.h b/core/jni/android/graphics/TypefaceImpl.h index d129f62..d36f83a 100644 --- a/core/jni/android/graphics/TypefaceImpl.h +++ b/core/jni/android/graphics/TypefaceImpl.h @@ -15,8 +15,8 @@ */ -#ifndef ANDROID_TYPEFACE_IMPL_H -#define ANDROID_TYPEFACE_IMPL_H +#ifndef _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_ +#define _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_ #include "jni.h" // for jlong, eventually remove #include "SkTypeface.h" @@ -62,4 +62,4 @@ void TypefaceImpl_setDefault(TypefaceImpl* face); } -#endif // ANDROID_TYPEFACE_IMPL_H
\ No newline at end of file +#endif // _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_
\ No newline at end of file diff --git a/core/jni/android/graphics/Utils.h b/core/jni/android/graphics/Utils.h index b90593c..bde87f0 100644 --- a/core/jni/android/graphics/Utils.h +++ b/core/jni/android/graphics/Utils.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef UTILS_DEFINED -#define UTILS_DEFINED +#ifndef _ANDROID_GRAPHICS_UTILS_H_ +#define _ANDROID_GRAPHICS_UTILS_H_ #include "SkStream.h" @@ -89,4 +89,4 @@ jobject nullObjectReturn(const char msg[]); }; // namespace android -#endif +#endif // _ANDROID_GRAPHICS_UTILS_H_ diff --git a/core/jni/android/graphics/Xfermode.cpp b/core/jni/android/graphics/Xfermode.cpp index 6bf6f8a..5a3883a 100644 --- a/core/jni/android/graphics/Xfermode.cpp +++ b/core/jni/android/graphics/Xfermode.cpp @@ -16,7 +16,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "SkAvoidXfermode.h" #include "SkPixelXorXfermode.h" @@ -59,19 +59,15 @@ static JNINativeMethod gPixelXorMethods[] = { {"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 result; - - REG(env, "android/graphics/Xfermode", gXfermodeMethods); - REG(env, "android/graphics/AvoidXfermode", gAvoidMethods); - REG(env, "android/graphics/PixelXorXfermode", gPixelXorMethods); + android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods, + NELEM(gXfermodeMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods, + NELEM(gXfermodeMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/AvoidXfermode", gAvoidMethods, + NELEM(gAvoidMethods)); + android::RegisterMethodsOrDie(env, "android/graphics/PixelXorXfermode", gPixelXorMethods, + NELEM(gPixelXorMethods)); return 0; } diff --git a/core/jni/android/graphics/YuvToJpegEncoder.cpp b/core/jni/android/graphics/YuvToJpegEncoder.cpp index 9b2e4b5..5eede2a 100644 --- a/core/jni/android/graphics/YuvToJpegEncoder.cpp +++ b/core/jni/android/graphics/YuvToJpegEncoder.cpp @@ -4,6 +4,8 @@ #include <ui/PixelFormat.h> #include <hardware/hardware.h> +#include "core_jni_helpers.h" + #include <jni.h> 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[] = { { "nativeCompressToJpeg", "([BIII[I[IILjava/io/OutputStream;[B)Z", (void*)YuvImage_compressToJpeg } }; -#define kClassPathName "android/graphics/YuvImage" - int register_android_graphics_YuvImage(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, - gYuvImageMethods, SK_ARRAY_COUNT(gYuvImageMethods)); + return android::RegisterMethodsOrDie(env, "android/graphics/YuvImage", gYuvImageMethods, + NELEM(gYuvImageMethods)); } diff --git a/core/jni/android/graphics/YuvToJpegEncoder.h b/core/jni/android/graphics/YuvToJpegEncoder.h index 0d418ed..1ea844a 100644 --- a/core/jni/android/graphics/YuvToJpegEncoder.h +++ b/core/jni/android/graphics/YuvToJpegEncoder.h @@ -1,5 +1,5 @@ -#ifndef YuvToJpegEncoder_DEFINED -#define YuvToJpegEncoder_DEFINED +#ifndef _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_ +#define _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_ #include "SkTypes.h" #include "SkStream.h" @@ -47,16 +47,16 @@ protected: class Yuv420SpToJpegEncoder : public YuvToJpegEncoder { public: - Yuv420SpToJpegEncoder(int* strides); - virtual ~Yuv420SpToJpegEncoder() {} + Yuv420SpToJpegEncoder(int* strides); + virtual ~Yuv420SpToJpegEncoder() {} private: - void configSamplingFactors(jpeg_compress_struct* cinfo); - void deinterleaveYuv(uint8_t* yuv, int width, int height, + void configSamplingFactors(jpeg_compress_struct* cinfo); + void deinterleaveYuv(uint8_t* yuv, int width, int height, uint8_t*& yPlanar, uint8_t*& uPlanar, uint8_t*& vPlanar); - void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows, - int rowIndex, int width, int height); - void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); + void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows, + int rowIndex, int width, int height); + void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); }; class Yuv422IToJpegEncoder : public YuvToJpegEncoder { @@ -71,4 +71,4 @@ private: uint8_t* vRows, int rowIndex, int width, int height); }; -#endif +#endif // _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_ diff --git a/core/jni/android/graphics/pdf/PdfDocument.cpp b/core/jni/android/graphics/pdf/PdfDocument.cpp index 9436a47..be90612 100644 --- a/core/jni/android/graphics/pdf/PdfDocument.cpp +++ b/core/jni/android/graphics/pdf/PdfDocument.cpp @@ -16,7 +16,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <vector> #include "Canvas.h" @@ -164,10 +164,9 @@ static JNINativeMethod gPdfDocument_Methods[] = { }; int register_android_graphics_pdf_PdfDocument(JNIEnv* env) { - int result = android::AndroidRuntime::registerNativeMethods( + return RegisterMethodsOrDie( env, "android/graphics/pdf/PdfDocument", gPdfDocument_Methods, NELEM(gPdfDocument_Methods)); - return result; } }; diff --git a/core/jni/android/graphics/pdf/PdfEditor.cpp b/core/jni/android/graphics/pdf/PdfEditor.cpp index 17090b7..cb228f2 100644 --- a/core/jni/android/graphics/pdf/PdfEditor.cpp +++ b/core/jni/android/graphics/pdf/PdfEditor.cpp @@ -28,7 +28,7 @@ #include "SkMatrix.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include <vector> #include <utils/Log.h> #include <unistd.h> @@ -355,19 +355,19 @@ static JNINativeMethod gPdfEditor_Methods[] = { }; int register_android_graphics_pdf_PdfEditor(JNIEnv* env) { - const int result = android::AndroidRuntime::registerNativeMethods( + const int result = RegisterMethodsOrDie( env, "android/graphics/pdf/PdfEditor", gPdfEditor_Methods, NELEM(gPdfEditor_Methods)); - jclass pointClass = env->FindClass("android/graphics/Point"); - gPointClassInfo.x = env->GetFieldID(pointClass, "x", "I"); - gPointClassInfo.y = env->GetFieldID(pointClass, "y", "I"); + jclass pointClass = FindClassOrDie(env, "android/graphics/Point"); + gPointClassInfo.x = GetFieldIDOrDie(env, pointClass, "x", "I"); + gPointClassInfo.y = GetFieldIDOrDie(env, pointClass, "y", "I"); - jclass rectClass = env->FindClass("android/graphics/Rect"); - gRectClassInfo.left = env->GetFieldID(rectClass, "left", "I"); - gRectClassInfo.top = env->GetFieldID(rectClass, "top", "I"); - gRectClassInfo.right = env->GetFieldID(rectClass, "right", "I"); - gRectClassInfo.bottom = env->GetFieldID(rectClass, "bottom", "I"); + jclass rectClass = FindClassOrDie(env, "android/graphics/Rect"); + gRectClassInfo.left = GetFieldIDOrDie(env, rectClass, "left", "I"); + gRectClassInfo.top = GetFieldIDOrDie(env, rectClass, "top", "I"); + gRectClassInfo.right = GetFieldIDOrDie(env, rectClass, "right", "I"); + gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClass, "bottom", "I"); return result; }; diff --git a/core/jni/android/graphics/pdf/PdfRenderer.cpp b/core/jni/android/graphics/pdf/PdfRenderer.cpp index 3319578..ae23cb4 100644 --- a/core/jni/android/graphics/pdf/PdfRenderer.cpp +++ b/core/jni/android/graphics/pdf/PdfRenderer.cpp @@ -26,7 +26,7 @@ #include "fsdk_rendercontext.h" #pragma GCC diagnostic pop -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <vector> #include <utils/Log.h> #include <unistd.h> @@ -282,13 +282,13 @@ static JNINativeMethod gPdfRenderer_Methods[] = { }; int register_android_graphics_pdf_PdfRenderer(JNIEnv* env) { - int result = android::AndroidRuntime::registerNativeMethods( + int result = RegisterMethodsOrDie( env, "android/graphics/pdf/PdfRenderer", gPdfRenderer_Methods, NELEM(gPdfRenderer_Methods)); - jclass clazz = env->FindClass("android/graphics/Point"); - gPointClassInfo.x = env->GetFieldID(clazz, "x", "I"); - gPointClassInfo.y = env->GetFieldID(clazz, "y", "I"); + jclass clazz = FindClassOrDie(env, "android/graphics/Point"); + gPointClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "I"); + gPointClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "I"); return result; }; diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index f60a154..da30044 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -29,7 +29,7 @@ #include <SkBitmap.h> -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #undef LOG_TAG #define LOG_TAG "OpenGLUtil" @@ -732,24 +732,22 @@ static jfieldID elementSizeShiftID; /* Cache method IDs each time the class is loaded. */ static void -nativeClassInitBuffer(JNIEnv *_env) +nativeClassInitBuffer(JNIEnv *env) { - jclass nioAccessClassLocal = _env->FindClass("java/nio/NIOAccess"); - nioAccessClass = (jclass) _env->NewGlobalRef(nioAccessClassLocal); - - jclass bufferClassLocal = _env->FindClass("java/nio/Buffer"); - bufferClass = (jclass) _env->NewGlobalRef(bufferClassLocal); - - getBasePointerID = _env->GetStaticMethodID(nioAccessClass, + jclass nioAccessClassLocal = FindClassOrDie(env, "java/nio/NIOAccess"); + nioAccessClass = MakeGlobalRefOrDie(env, nioAccessClassLocal); + getBasePointerID = GetStaticMethodIDOrDie(env, nioAccessClass, "getBasePointer", "(Ljava/nio/Buffer;)J"); - getBaseArrayID = _env->GetStaticMethodID(nioAccessClass, + getBaseArrayID = GetStaticMethodIDOrDie(env, nioAccessClass, "getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;"); - getBaseArrayOffsetID = _env->GetStaticMethodID(nioAccessClass, + getBaseArrayOffsetID = GetStaticMethodIDOrDie(env, nioAccessClass, "getBaseArrayOffset", "(Ljava/nio/Buffer;)I"); - positionID = _env->GetFieldID(bufferClass, "position", "I"); - limitID = _env->GetFieldID(bufferClass, "limit", "I"); - elementSizeShiftID = - _env->GetFieldID(bufferClass, "_elementSizeShift", "I"); + + jclass bufferClassLocal = FindClassOrDie(env, "java/nio/Buffer"); + bufferClass = MakeGlobalRefOrDie(env, bufferClassLocal); + positionID = GetFieldIDOrDie(env, bufferClass, "position", "I"); + limitID = GetFieldIDOrDie(env, bufferClass, "limit", "I"); + elementSizeShiftID = GetFieldIDOrDie(env, bufferClass, "_elementSizeShift", "I"); } static void * @@ -1056,12 +1054,7 @@ int register_android_opengl_classes(JNIEnv* env) int result = 0; for (int i = 0; i < NELEM(gClasses); i++) { ClassRegistrationInfo* cri = &gClasses[i]; - result = AndroidRuntime::registerNativeMethods(env, - cri->classPath, cri->methods, cri->methodCount); - if (result < 0) { - ALOGE("Failed to register %s: %d", cri->classPath, result); - break; - } + result = RegisterMethodsOrDie(env, cri->classPath, cri->methods, cri->methodCount); } return result; } diff --git a/core/jni/android_animation_PropertyValuesHolder.cpp b/core/jni/android_animation_PropertyValuesHolder.cpp index ef1c4ed..d117741 100644 --- a/core/jni/android_animation_PropertyValuesHolder.cpp +++ b/core/jni/android_animation_PropertyValuesHolder.cpp @@ -18,7 +18,7 @@ #include <assert.h> #include "jni.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/misc.h> // ---------------------------------------------------------------------------- @@ -168,8 +168,7 @@ static JNINativeMethod gMethods[] = { int register_android_animation_PropertyValuesHolder(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, - kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } }; diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp index a65b690..95be3f2 100644 --- a/core/jni/android_app_NativeActivity.cpp +++ b/core/jni/android_app_NativeActivity.cpp @@ -42,12 +42,15 @@ #include "core_jni_helpers.h" + #define LOG_TRACE(...) //#define LOG_TRACE(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__) namespace android { +static const bool kLogTrace = false; + static struct { jmethodID finish; jmethodID setWindowFlags; @@ -77,8 +80,10 @@ static void write_work(int fd, int32_t cmd, int32_t arg1=0, int32_t arg2=0) { work.cmd = cmd; work.arg1 = arg1; work.arg2 = arg2; - - LOG_TRACE("write_work: cmd=%d", cmd); + + if (kLogTrace) { + ALOGD("write_work: cmd=%d", cmd); + } restart: int res = write(fd, &work, sizeof(work)); @@ -208,7 +213,9 @@ static int mainWorkCallback(int fd, int events, void* data) { return 1; } - LOG_TRACE("mainWorkCallback: cmd=%d", work.cmd); + if (kLogTrace) { + ALOGD("mainWorkCallback: cmd=%d", work.cmd); + } switch (work.cmd) { case CMD_FINISH: { @@ -251,7 +258,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName jstring externalDataDir, jint sdkVersion, jobject jAssetMgr, jbyteArray savedState) { - LOG_TRACE("loadNativeCode_native"); + if (kLogTrace) { + ALOGD("loadNativeCode_native"); + } const char* pathStr = env->GetStringUTFChars(path, NULL); NativeCode* code = NULL; @@ -360,7 +369,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName static void unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("unloadNativeCode_native"); + if (kLogTrace) { + ALOGD("unloadNativeCode_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; delete code; @@ -370,7 +381,9 @@ unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle) static void onStart_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onStart_native"); + if (kLogTrace) { + ALOGD("onStart_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onStart != NULL) { @@ -382,7 +395,9 @@ onStart_native(JNIEnv* env, jobject clazz, jlong handle) static void onResume_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onResume_native"); + if (kLogTrace) { + ALOGD("onResume_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onResume != NULL) { @@ -394,7 +409,9 @@ onResume_native(JNIEnv* env, jobject clazz, jlong handle) static jbyteArray onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onSaveInstanceState_native"); + if (kLogTrace) { + ALOGD("onSaveInstanceState_native"); + } jbyteArray array = NULL; @@ -421,7 +438,9 @@ onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle) static void onPause_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onPause_native"); + if (kLogTrace) { + ALOGD("onPause_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onPause != NULL) { @@ -433,7 +452,9 @@ onPause_native(JNIEnv* env, jobject clazz, jlong handle) static void onStop_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onStop_native"); + if (kLogTrace) { + ALOGD("onStop_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onStop != NULL) { @@ -445,7 +466,9 @@ onStop_native(JNIEnv* env, jobject clazz, jlong handle) static void onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onConfigurationChanged_native"); + if (kLogTrace) { + ALOGD("onConfigurationChanged_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onConfigurationChanged != NULL) { @@ -457,7 +480,9 @@ onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle) static void onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onLowMemory_native"); + if (kLogTrace) { + ALOGD("onLowMemory_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onLowMemory != NULL) { @@ -469,7 +494,9 @@ onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle) static void onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean focused) { - LOG_TRACE("onWindowFocusChanged_native"); + if (kLogTrace) { + ALOGD("onWindowFocusChanged_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onWindowFocusChanged != NULL) { @@ -481,7 +508,9 @@ onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean f static void onSurfaceCreated_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface) { - LOG_TRACE("onSurfaceCreated_native"); + if (kLogTrace) { + ALOGD("onSurfaceCreated_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; code->setSurface(surface); @@ -502,7 +531,9 @@ static void onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface, jint format, jint width, jint height) { - LOG_TRACE("onSurfaceChanged_native"); + if (kLogTrace) { + ALOGD("onSurfaceChanged_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; sp<ANativeWindow> oldNativeWindow = code->nativeWindow; @@ -542,7 +573,9 @@ onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surfac static void onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle) { - LOG_TRACE("onSurfaceRedrawNeeded_native"); + if (kLogTrace) { + ALOGD("onSurfaceRedrawNeeded_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->nativeWindow != NULL && code->callbacks.onNativeWindowRedrawNeeded != NULL) { @@ -554,7 +587,9 @@ onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle) static void onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface) { - LOG_TRACE("onSurfaceDestroyed_native"); + if (kLogTrace) { + ALOGD("onSurfaceDestroyed_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->nativeWindow != NULL && code->callbacks.onNativeWindowDestroyed != NULL) { @@ -568,7 +603,9 @@ onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surf static void onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr) { - LOG_TRACE("onInputChannelCreated_native"); + if (kLogTrace) { + ALOGD("onInputChannelCreated_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onInputQueueCreated != NULL) { @@ -581,7 +618,9 @@ onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queue static void onInputQueueDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr) { - LOG_TRACE("onInputChannelDestroyed_native"); + if (kLogTrace) { + ALOGD("onInputChannelDestroyed_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onInputQueueDestroyed != NULL) { @@ -595,7 +634,9 @@ static void onContentRectChanged_native(JNIEnv* env, jobject clazz, jlong handle, jint x, jint y, jint w, jint h) { - LOG_TRACE("onContentRectChanged_native"); + if (kLogTrace) { + ALOGD("onContentRectChanged_native"); + } if (handle != 0) { NativeCode* code = (NativeCode*)handle; if (code->callbacks.onContentRectChanged != NULL) { diff --git a/core/jni/android_backup_BackupDataOutput.cpp b/core/jni/android_backup_BackupDataOutput.cpp index 81f9ff4..a7894f4 100644 --- a/core/jni/android_backup_BackupDataOutput.cpp +++ b/core/jni/android_backup_BackupDataOutput.cpp @@ -18,7 +18,7 @@ #include <utils/Log.h> #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <androidfw/BackupHelpers.h> @@ -106,7 +106,7 @@ static const JNINativeMethod g_methods[] = { int register_android_backup_BackupDataOutput(JNIEnv* env) { //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)); } diff --git a/core/jni/android_backup_FileBackupHelperBase.cpp b/core/jni/android_backup_FileBackupHelperBase.cpp index 66e3e9d..6d6ac1b 100644 --- a/core/jni/android_backup_FileBackupHelperBase.cpp +++ b/core/jni/android_backup_FileBackupHelperBase.cpp @@ -18,7 +18,7 @@ #include <utils/Log.h> #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <androidfw/BackupHelpers.h> @@ -118,7 +118,7 @@ static const JNINativeMethod g_methods[] = { 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)); } diff --git a/core/jni/android_database_SQLiteGlobal.cpp b/core/jni/android_database_SQLiteGlobal.cpp index 89d64fa..d0c592e 100644 --- a/core/jni/android_database_SQLiteGlobal.cpp +++ b/core/jni/android_database_SQLiteGlobal.cpp @@ -18,7 +18,7 @@ #include <jni.h> #include <JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <sqlite3.h> #include <sqlite3_android.h> @@ -74,15 +74,14 @@ static jint nativeReleaseMemory(JNIEnv* env, jclass clazz) { static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ - { "nativeReleaseMemory", "()I", - (void*)nativeReleaseMemory }, + { "nativeReleaseMemory", "()I", (void*)nativeReleaseMemory }, }; int register_android_database_SQLiteGlobal(JNIEnv *env) { sqliteInitialize(); - return AndroidRuntime::registerNativeMethods(env, "android/database/sqlite/SQLiteGlobal", + return RegisterMethodsOrDie(env, "android/database/sqlite/SQLiteGlobal", sMethods, NELEM(sMethods)); } diff --git a/core/jni/android_ddm_DdmHandleNativeHeap.cpp b/core/jni/android_ddm_DdmHandleNativeHeap.cpp index 0938396..ae96936 100644 --- a/core/jni/android_ddm_DdmHandleNativeHeap.cpp +++ b/core/jni/android_ddm_DdmHandleNativeHeap.cpp @@ -20,7 +20,7 @@ #include <JNIHelp.h> #include <jni.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/Log.h> #include <utils/String8.h> @@ -110,7 +110,8 @@ static JNINativeMethod method_table[] = { }; 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)); } }; diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index 507c165..19aad61 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -16,7 +16,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "Canvas.h" #include "SkDrawFilter.h" @@ -700,7 +700,7 @@ static JNINativeMethod gMethods[] = { }; 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 diff --git a/core/jni/android_graphics_Picture.cpp b/core/jni/android_graphics_Picture.cpp index eb8f6dd..308ee20 100644 --- a/core/jni/android_graphics_Picture.cpp +++ b/core/jni/android_graphics_Picture.cpp @@ -16,7 +16,7 @@ #include "jni.h" #include "GraphicsJNI.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "Picture.h" @@ -106,7 +106,7 @@ static JNINativeMethod gMethods[] = { }; 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 diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index 4d191a31..7a0f511 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -21,7 +21,7 @@ #include "jni.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_view_Surface.h> @@ -1033,26 +1033,14 @@ struct field { 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++) { field *f = &fields[i]; - jclass clazz = env->FindClass(f->class_name); - if (clazz == NULL) { - 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; - } - + jclass clazz = FindClassOrDie(env, f->class_name); + jfieldID field = GetFieldIDOrDie(env, clazz, f->field_name, f->field_type); *(f->jfield) = field; } - - return 0; } // Get all the required offsets in java class and register native functions @@ -1078,30 +1066,17 @@ int register_android_hardware_Camera(JNIEnv *env) { "android/graphics/Point", "y", "I", &fields.point_y}, }; - if (find_fields(env, fields_to_find, NELEM(fields_to_find)) < 0) - return -1; + find_fields(env, fields_to_find, NELEM(fields_to_find)); - jclass clazz = env->FindClass("android/hardware/Camera"); - fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", + jclass clazz = FindClassOrDie(env, "android/hardware/Camera"); + fields.post_event = GetStaticMethodIDOrDie(env, clazz, "postEventFromNative", "(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"); - fields.rect_constructor = env->GetMethodID(clazz, "<init>", "()V"); - if (fields.rect_constructor == NULL) { - ALOGE("Can't find android/graphics/Rect.Rect()"); - return -1; - } + clazz = FindClassOrDie(env, "android/graphics/Rect"); + fields.rect_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V"); - clazz = env->FindClass("android/hardware/Camera$Face"); - fields.face_constructor = env->GetMethodID(clazz, "<init>", "()V"); - if (fields.face_constructor == NULL) { - ALOGE("Can't find android/hardware/Camera$Face.Face()"); - return -1; - } + clazz = FindClassOrDie(env, "android/hardware/Camera$Face"); + fields.face_constructor = GetMethodIDOrDie(env, clazz, "<init>", "()V"); clazz = env->FindClass("android/graphics/Point"); fields.point_constructor = env->GetMethodID(clazz, "<init>", "()V"); @@ -1111,6 +1086,5 @@ int register_android_hardware_Camera(JNIEnv *env) } // Register native functions - return AndroidRuntime::registerNativeMethods(env, "android/hardware/Camera", - camMethods, NELEM(camMethods)); + return RegisterMethodsOrDie(env, "android/hardware/Camera", camMethods, NELEM(camMethods)); } diff --git a/core/jni/android_hardware_SerialPort.cpp b/core/jni/android_hardware_SerialPort.cpp index 7f40a5c..2d2ff4d 100644 --- a/core/jni/android_hardware_SerialPort.cpp +++ b/core/jni/android_hardware_SerialPort.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <stdio.h> #include <sys/types.h> @@ -260,17 +260,9 @@ static JNINativeMethod method_table[] = { int register_android_hardware_SerialPort(JNIEnv *env) { - jclass clazz = env->FindClass("android/hardware/SerialPort"); - if (clazz == NULL) { - 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; - } + jclass clazz = FindClassOrDie(env, "android/hardware/SerialPort"); + field_context = GetFieldIDOrDie(env, clazz, "mNativeContext", "I"); - return AndroidRuntime::registerNativeMethods(env, "android/hardware/SerialPort", + return RegisterMethodsOrDie(env, "android/hardware/SerialPort", method_table, NELEM(method_table)); } diff --git a/core/jni/android_hardware_SoundTrigger.cpp b/core/jni/android_hardware_SoundTrigger.cpp index 2a8e6d6..28e5030 100644 --- a/core/jni/android_hardware_SoundTrigger.cpp +++ b/core/jni/android_hardware_SoundTrigger.cpp @@ -21,7 +21,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <system/sound_trigger.h> #include <soundtrigger/SoundTriggerCallback.h> #include <soundtrigger/SoundTrigger.h> @@ -801,112 +801,102 @@ static JNINativeMethod gModuleMethods[] = { int register_android_hardware_SoundTrigger(JNIEnv *env) { - jclass arrayListClass = env->FindClass("java/util/ArrayList"); - gArrayListClass = (jclass) env->NewGlobalRef(arrayListClass); - gArrayListMethods.add = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); - - jclass uuidClass = env->FindClass("java/util/UUID"); - gUUIDClass = (jclass) env->NewGlobalRef(uuidClass); - gUUIDMethods.toString = env->GetMethodID(uuidClass, "toString", "()Ljava/lang/String;"); - - jclass lClass = env->FindClass(kSoundTriggerClassPathName); - gSoundTriggerClass = (jclass) env->NewGlobalRef(lClass); - - jclass moduleClass = env->FindClass(kModuleClassPathName); - gModuleClass = (jclass) env->NewGlobalRef(moduleClass); - gPostEventFromNative = env->GetStaticMethodID(moduleClass, "postEventFromNative", - "(Ljava/lang/Object;IIILjava/lang/Object;)V"); - gModuleFields.mNativeContext = env->GetFieldID(moduleClass, "mNativeContext", "J"); - gModuleFields.mId = env->GetFieldID(moduleClass, "mId", "I"); - - - jclass modulePropertiesClass = env->FindClass(kModulePropertiesClassPathName); - gModulePropertiesClass = (jclass) env->NewGlobalRef(modulePropertiesClass); - gModulePropertiesCstor = env->GetMethodID(modulePropertiesClass, "<init>", - "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIIIZIZIZ)V"); - - jclass soundModelClass = env->FindClass(kSoundModelClassPathName); - gSoundModelClass = (jclass) env->NewGlobalRef(soundModelClass); - gSoundModelFields.uuid = env->GetFieldID(soundModelClass, "uuid", "Ljava/util/UUID;"); - gSoundModelFields.vendorUuid = env->GetFieldID(soundModelClass, "vendorUuid", "Ljava/util/UUID;"); - gSoundModelFields.data = env->GetFieldID(soundModelClass, "data", "[B"); - - jclass keyphraseClass = env->FindClass(kKeyphraseClassPathName); - gKeyphraseClass = (jclass) env->NewGlobalRef(keyphraseClass); - gKeyphraseFields.id = env->GetFieldID(keyphraseClass, "id", "I"); - 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, + jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList"); + gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass); + gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z"); + + jclass uuidClass = FindClassOrDie(env, "java/util/UUID"); + gUUIDClass = MakeGlobalRefOrDie(env, uuidClass); + gUUIDMethods.toString = GetMethodIDOrDie(env, uuidClass, "toString", "()Ljava/lang/String;"); + + jclass lClass = FindClassOrDie(env, kSoundTriggerClassPathName); + gSoundTriggerClass = MakeGlobalRefOrDie(env, lClass); + + jclass moduleClass = FindClassOrDie(env, kModuleClassPathName); + gModuleClass = MakeGlobalRefOrDie(env, moduleClass); + gPostEventFromNative = GetStaticMethodIDOrDie(env, moduleClass, "postEventFromNative", + "(Ljava/lang/Object;IIILjava/lang/Object;)V"); + gModuleFields.mNativeContext = GetFieldIDOrDie(env, moduleClass, "mNativeContext", "J"); + 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 soundModelClass = FindClassOrDie(env, kSoundModelClassPathName); + gSoundModelClass = MakeGlobalRefOrDie(env, soundModelClass); + gSoundModelFields.uuid = GetFieldIDOrDie(env, soundModelClass, "uuid", "Ljava/util/UUID;"); + gSoundModelFields.vendorUuid = GetFieldIDOrDie(env, soundModelClass, "vendorUuid", + "Ljava/util/UUID;"); + gSoundModelFields.data = GetFieldIDOrDie(env, soundModelClass, "data", "[B"); + + jclass keyphraseClass = FindClassOrDie(env, kKeyphraseClassPathName); + gKeyphraseClass = MakeGlobalRefOrDie(env, keyphraseClass); + gKeyphraseFields.id = GetFieldIDOrDie(env, keyphraseClass, "id", "I"); + gKeyphraseFields.recognitionModes = GetFieldIDOrDie(env, keyphraseClass, "recognitionModes", + "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 keyphraseSoundModelClass = FindClassOrDie(env, kKeyphraseSoundModelClassPathName); + gKeyphraseSoundModelClass = MakeGlobalRefOrDie(env, keyphraseSoundModelClass); + gKeyphraseSoundModelFields.keyphrases = GetFieldIDOrDie(env, keyphraseSoundModelClass, "keyphrases", "[Landroid/hardware/soundtrigger/SoundTrigger$Keyphrase;"); - - jclass recognitionEventClass = env->FindClass(kRecognitionEventClassPathName); - gRecognitionEventClass = (jclass) env->NewGlobalRef(recognitionEventClass); - gRecognitionEventCstor = env->GetMethodID(recognitionEventClass, "<init>", + jclass recognitionEventClass = FindClassOrDie(env, kRecognitionEventClassPathName); + gRecognitionEventClass = MakeGlobalRefOrDie(env, recognitionEventClass); + gRecognitionEventCstor = GetMethodIDOrDie(env, recognitionEventClass, "<init>", "(IIZIIIZLandroid/media/AudioFormat;[B)V"); - jclass keyphraseRecognitionEventClass = env->FindClass(kKeyphraseRecognitionEventClassPathName); - gKeyphraseRecognitionEventClass = (jclass) env->NewGlobalRef(keyphraseRecognitionEventClass); - gKeyphraseRecognitionEventCstor = env->GetMethodID(keyphraseRecognitionEventClass, "<init>", + jclass keyphraseRecognitionEventClass = FindClassOrDie(env, + kKeyphraseRecognitionEventClassPathName); + gKeyphraseRecognitionEventClass = MakeGlobalRefOrDie(env, keyphraseRecognitionEventClass); + gKeyphraseRecognitionEventCstor = GetMethodIDOrDie(env, keyphraseRecognitionEventClass, "<init>", "(IIZIIIZLandroid/media/AudioFormat;[B[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;)V"); - jclass keyRecognitionConfigClass = env->FindClass(kRecognitionConfigClassPathName); - gRecognitionConfigClass = (jclass) env->NewGlobalRef(keyRecognitionConfigClass); - gRecognitionConfigFields.captureRequested = env->GetFieldID(keyRecognitionConfigClass, - "captureRequested", - "Z"); - gRecognitionConfigFields.keyphrases = env->GetFieldID(keyRecognitionConfigClass, - "keyphrases", - "[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;"); - gRecognitionConfigFields.data = env->GetFieldID(keyRecognitionConfigClass, - "data", - "[B"); - - jclass keyphraseRecognitionExtraClass = env->FindClass(kKeyphraseRecognitionExtraClassPathName); - gKeyphraseRecognitionExtraClass = (jclass) env->NewGlobalRef(keyphraseRecognitionExtraClass); - gKeyphraseRecognitionExtraCstor = env->GetMethodID(keyphraseRecognitionExtraClass, "<init>", - "(III[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;)V"); - gKeyphraseRecognitionExtraFields.id = env->GetFieldID(gKeyphraseRecognitionExtraClass, "id", "I"); - gKeyphraseRecognitionExtraFields.recognitionModes = env->GetFieldID(gKeyphraseRecognitionExtraClass, - "recognitionModes", "I"); - gKeyphraseRecognitionExtraFields.coarseConfidenceLevel = env->GetFieldID(gKeyphraseRecognitionExtraClass, - "coarseConfidenceLevel", "I"); - gKeyphraseRecognitionExtraFields.confidenceLevels = env->GetFieldID(gKeyphraseRecognitionExtraClass, - "confidenceLevels", - "[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;"); - - jclass confidenceLevelClass = env->FindClass(kConfidenceLevelClassPathName); - gConfidenceLevelClass = (jclass) env->NewGlobalRef(confidenceLevelClass); - gConfidenceLevelCstor = env->GetMethodID(confidenceLevelClass, "<init>", "(II)V"); - gConfidenceLevelFields.userId = env->GetFieldID(confidenceLevelClass, "userId", "I"); - gConfidenceLevelFields.confidenceLevel = env->GetFieldID(confidenceLevelClass, + jclass keyRecognitionConfigClass = FindClassOrDie(env, kRecognitionConfigClassPathName); + gRecognitionConfigClass = MakeGlobalRefOrDie(env, keyRecognitionConfigClass); + gRecognitionConfigFields.captureRequested = GetFieldIDOrDie(env, keyRecognitionConfigClass, + "captureRequested", "Z"); + gRecognitionConfigFields.keyphrases = GetFieldIDOrDie(env, keyRecognitionConfigClass, + "keyphrases", "[Landroid/hardware/soundtrigger/SoundTrigger$KeyphraseRecognitionExtra;"); + gRecognitionConfigFields.data = GetFieldIDOrDie(env, keyRecognitionConfigClass, "data", "[B"); + + jclass keyphraseRecognitionExtraClass = FindClassOrDie(env, + kKeyphraseRecognitionExtraClassPathName); + gKeyphraseRecognitionExtraClass = MakeGlobalRefOrDie(env, keyphraseRecognitionExtraClass); + gKeyphraseRecognitionExtraCstor = GetMethodIDOrDie(env, keyphraseRecognitionExtraClass, + "<init>", "(III[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;)V"); + gKeyphraseRecognitionExtraFields.id = GetFieldIDOrDie(env, gKeyphraseRecognitionExtraClass, + "id", "I"); + gKeyphraseRecognitionExtraFields.recognitionModes = GetFieldIDOrDie(env, + gKeyphraseRecognitionExtraClass, "recognitionModes", "I"); + gKeyphraseRecognitionExtraFields.coarseConfidenceLevel = GetFieldIDOrDie(env, + gKeyphraseRecognitionExtraClass, "coarseConfidenceLevel", "I"); + gKeyphraseRecognitionExtraFields.confidenceLevels = GetFieldIDOrDie(env, + gKeyphraseRecognitionExtraClass, "confidenceLevels", + "[Landroid/hardware/soundtrigger/SoundTrigger$ConfidenceLevel;"); + + jclass confidenceLevelClass = FindClassOrDie(env, kConfidenceLevelClassPathName); + gConfidenceLevelClass = MakeGlobalRefOrDie(env, confidenceLevelClass); + gConfidenceLevelCstor = GetMethodIDOrDie(env, confidenceLevelClass, "<init>", "(II)V"); + gConfidenceLevelFields.userId = GetFieldIDOrDie(env, confidenceLevelClass, "userId", "I"); + gConfidenceLevelFields.confidenceLevel = GetFieldIDOrDie(env, confidenceLevelClass, "confidenceLevel", "I"); - jclass audioFormatClass = env->FindClass(kAudioFormatClassPathName); - gAudioFormatClass = (jclass) env->NewGlobalRef(audioFormatClass); - gAudioFormatCstor = env->GetMethodID(audioFormatClass, "<init>", "(III)V"); - - jclass soundModelEventClass = env->FindClass(kSoundModelEventClassPathName); - gSoundModelEventClass = (jclass) env->NewGlobalRef(soundModelEventClass); - gSoundModelEventCstor = env->GetMethodID(soundModelEventClass, "<init>", - "(II[B)V"); - + jclass audioFormatClass = FindClassOrDie(env, kAudioFormatClassPathName); + gAudioFormatClass = MakeGlobalRefOrDie(env, audioFormatClass); + gAudioFormatCstor = GetMethodIDOrDie(env, audioFormatClass, "<init>", "(III)V"); - int status = AndroidRuntime::registerNativeMethods(env, - kSoundTriggerClassPathName, gMethods, NELEM(gMethods)); - - if (status == 0) { - status = AndroidRuntime::registerNativeMethods(env, - kModuleClassPathName, gModuleMethods, NELEM(gModuleMethods)); - } + jclass soundModelEventClass = FindClassOrDie(env, kSoundModelEventClassPathName); + gSoundModelEventClass = MakeGlobalRefOrDie(env, soundModelEventClass); + gSoundModelEventCstor = GetMethodIDOrDie(env, soundModelEventClass, "<init>", "(II[B)V"); - return status; + RegisterMethodsOrDie(env, kSoundTriggerClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kModuleClassPathName, gModuleMethods, NELEM(gModuleMethods)); } diff --git a/core/jni/android_hardware_UsbDevice.cpp b/core/jni/android_hardware_UsbDevice.cpp index 25f901b..ef3b646 100644 --- a/core/jni/android_hardware_UsbDevice.cpp +++ b/core/jni/android_hardware_UsbDevice.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <usbhost/usbhost.h> @@ -54,6 +54,6 @@ static JNINativeMethod method_table[] = { 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)); } diff --git a/core/jni/android_hardware_UsbDeviceConnection.cpp b/core/jni/android_hardware_UsbDeviceConnection.cpp index 467a9a1..e0cae6f 100644 --- a/core/jni/android_hardware_UsbDeviceConnection.cpp +++ b/core/jni/android_hardware_UsbDeviceConnection.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <usbhost/usbhost.h> @@ -268,17 +268,9 @@ static JNINativeMethod method_table[] = { int register_android_hardware_UsbDeviceConnection(JNIEnv *env) { - jclass clazz = env->FindClass("android/hardware/usb/UsbDeviceConnection"); - if (clazz == NULL) { - 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; - } + jclass clazz = FindClassOrDie(env, "android/hardware/usb/UsbDeviceConnection"); + field_context = GetFieldIDOrDie(env, clazz, "mNativeContext", "J"); - return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbDeviceConnection", + return RegisterMethodsOrDie(env, "android/hardware/usb/UsbDeviceConnection", method_table, NELEM(method_table)); } diff --git a/core/jni/android_hardware_UsbRequest.cpp b/core/jni/android_hardware_UsbRequest.cpp index a3c7b0a..ce99e15 100644 --- a/core/jni/android_hardware_UsbRequest.cpp +++ b/core/jni/android_hardware_UsbRequest.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <usbhost/usbhost.h> @@ -215,7 +215,7 @@ int register_android_hardware_UsbRequest(JNIEnv *env) return -1; } - return AndroidRuntime::registerNativeMethods(env, "android/hardware/usb/UsbRequest", + return RegisterMethodsOrDie(env, "android/hardware/usb/UsbRequest", method_table, NELEM(method_table)); } diff --git a/core/jni/android_hardware_camera2_CameraMetadata.cpp b/core/jni/android_hardware_camera2_CameraMetadata.cpp index 9132690..7c8769d 100644 --- a/core/jni/android_hardware_camera2_CameraMetadata.cpp +++ b/core/jni/android_hardware_camera2_CameraMetadata.cpp @@ -16,7 +16,6 @@ */ // #define LOG_NDEBUG 0 -// #define LOG_NNDEBUG 0 #define LOG_TAG "CameraMetadata-JNI" #include <utils/Errors.h> #include <utils/Log.h> @@ -29,7 +28,7 @@ #include "jni.h" #include "JNIHelp.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 <binder/IServiceManager.h> @@ -42,13 +41,7 @@ #include <sys/types.h> // for socketpair #include <sys/socket.h> // for socketpair -#if defined(LOG_NNDEBUG) -#if !LOG_NNDEBUG -#define ALOGVV ALOGV -#endif -#else -#define ALOGVV(...) -#endif +static const bool kIsDebug = false; // fully-qualified class name #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) { // Register native functions - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, CAMERA_METADATA_CLASS_NAME, 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] : vendorSections[i - ANDROID_SECTION_COUNT].string(); - ALOGVV("%s: Trying to match against section '%s'", - __FUNCTION__, str); + if (kIsDebug) { + ALOGV("%s: Trying to match against section '%s'", __FUNCTION__, str); + } if (strstr(key, str) == key) { // key begins with the section name 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 if (section == NULL || sectionLength < strLength) { @@ -663,7 +659,9 @@ static jint CameraMetadata_getTagFromKey(JNIEnv *env, jobject thiz, jstring keyN sectionIndex = i; sectionLength = strLength; - ALOGVV("%s: Found new best section (%s)", __FUNCTION__, section); + if (kIsDebug) { + ALOGV("%s: Found new best section (%s)", __FUNCTION__, section); + } } } } diff --git a/core/jni/android_hardware_camera2_DngCreator.cpp b/core/jni/android_hardware_camera2_DngCreator.cpp index d542419..bb8de28 100644 --- a/core/jni/android_hardware_camera2_DngCreator.cpp +++ b/core/jni/android_hardware_camera2_DngCreator.cpp @@ -36,7 +36,7 @@ #include <img_utils/Input.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 <jni.h> @@ -803,29 +803,20 @@ static TiffWriter* DngCreator_getCreator(JNIEnv* env, jobject thiz) { static void DngCreator_nativeClassInit(JNIEnv* env, jclass clazz) { ALOGV("%s:", __FUNCTION__); - gDngCreatorClassInfo.mNativeContext = env->GetFieldID(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"); - LOG_ALWAYS_FATAL_IF(outputStreamClazz == NULL, "Can't find java/io/OutputStream class"); - gOutputStreamClassInfo.mWriteMethod = env->GetMethodID(outputStreamClazz, "write", "([BII)V"); - LOG_ALWAYS_FATAL_IF(gOutputStreamClassInfo.mWriteMethod == NULL, "Can't find write method"); - - jclass inputStreamClazz = env->FindClass("java/io/InputStream"); - LOG_ALWAYS_FATAL_IF(inputStreamClazz == NULL, "Can't find java/io/InputStream class"); - gInputStreamClassInfo.mReadMethod = env->GetMethodID(inputStreamClazz, "read", "([BII)I"); - 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"); - LOG_ALWAYS_FATAL_IF(inputBufferClazz == NULL, "Can't find java/nio/ByteBuffer class"); - gInputByteBufferClassInfo.mGetMethod = env->GetMethodID(inputBufferClazz, "get", - "([BII)Ljava/nio/ByteBuffer;"); - LOG_ALWAYS_FATAL_IF(gInputByteBufferClassInfo.mGetMethod == NULL, "Can't find get method"); + gDngCreatorClassInfo.mNativeContext = GetFieldIDOrDie(env, + clazz, ANDROID_DNGCREATOR_CTX_JNI_ID, "J"); + + jclass outputStreamClazz = FindClassOrDie(env, "java/io/OutputStream"); + gOutputStreamClassInfo.mWriteMethod = GetMethodIDOrDie(env, + outputStreamClazz, "write", "([BII)V"); + + jclass inputStreamClazz = FindClassOrDie(env, "java/io/InputStream"); + gInputStreamClassInfo.mReadMethod = GetMethodIDOrDie(env, inputStreamClazz, "read", "([BII)I"); + gInputStreamClassInfo.mSkipMethod = GetMethodIDOrDie(env, inputStreamClazz, "skip", "(J)J"); + + jclass inputBufferClazz = FindClassOrDie(env, "java/nio/ByteBuffer"); + gInputByteBufferClassInfo.mGetMethod = GetMethodIDOrDie(env, + inputBufferClazz, "get", "([BII)Ljava/nio/ByteBuffer;"); } 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) { - return AndroidRuntime::registerNativeMethods(env, - "android/hardware/camera2/DngCreator", gDngCreatorMethods, - NELEM(gDngCreatorMethods)); + return RegisterMethodsOrDie(env, + "android/hardware/camera2/DngCreator", gDngCreatorMethods, NELEM(gDngCreatorMethods)); } diff --git a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp index 7dafb1b..f75ab17 100644 --- a/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp +++ b/core/jni/android_hardware_camera2_legacy_LegacyCameraDevice.cpp @@ -23,7 +23,7 @@ #include "jni.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_graphics_SurfaceTexture.h" @@ -719,7 +719,7 @@ static JNINativeMethod gCameraDeviceMethods[] = { int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv* env) { // Register native functions - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, CAMERA_DEVICE_CLASS_NAME, gCameraDeviceMethods, NELEM(gCameraDeviceMethods)); diff --git a/core/jni/android_hardware_camera2_legacy_PerfMeasurement.cpp b/core/jni/android_hardware_camera2_legacy_PerfMeasurement.cpp index 93473a5..7257597 100644 --- a/core/jni/android_hardware_camera2_legacy_PerfMeasurement.cpp +++ b/core/jni/android_hardware_camera2_legacy_PerfMeasurement.cpp @@ -22,7 +22,7 @@ #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <ui/GraphicBuffer.h> #include <system/window.h> @@ -328,7 +328,7 @@ static JNINativeMethod gPerfMeasurementMethods[] = { int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv* env) { // Register native functions - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, PERF_MEASUREMENT_CLASS_NAME, gPerfMeasurementMethods, NELEM(gPerfMeasurementMethods)); diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp index d2eb8dd..044c359 100644 --- a/core/jni/android_media_AudioRecord.cpp +++ b/core/jni/android_media_AudioRecord.cpp @@ -21,7 +21,7 @@ #include <inttypes.h> #include <jni.h> #include <JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/Log.h> #include <media/AudioRecord.h> @@ -605,59 +605,28 @@ int register_android_media_AudioRecord(JNIEnv *env) // Get the AudioRecord class - jclass audioRecordClass = env->FindClass(kClassPathName); - if (audioRecordClass == NULL) { - ALOGE("Can't find %s", kClassPathName); - return -1; - } + jclass audioRecordClass = FindClassOrDie(env, kClassPathName); // Get the postEvent method - javaAudioRecordFields.postNativeEventInJava = env->GetStaticMethodID( - audioRecordClass, - JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V"); - if (javaAudioRecordFields.postNativeEventInJava == NULL) { - ALOGE("Can't find AudioRecord.%s", JAVA_POSTEVENT_CALLBACK_NAME); - return -1; - } + javaAudioRecordFields.postNativeEventInJava = GetStaticMethodIDOrDie(env, + audioRecordClass, JAVA_POSTEVENT_CALLBACK_NAME, + "(Ljava/lang/Object;IIILjava/lang/Object;)V"); // Get the variables // mNativeRecorderInJavaObj - javaAudioRecordFields.nativeRecorderInJavaObj = - env->GetFieldID(audioRecordClass, - JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J"); - if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) { - ALOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME); - return -1; - } + javaAudioRecordFields.nativeRecorderInJavaObj = GetFieldIDOrDie(env, + audioRecordClass, JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J"); // mNativeCallbackCookie - javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID( - audioRecordClass, - JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J"); - if (javaAudioRecordFields.nativeCallbackCookie == NULL) { - ALOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME); - return -1; - } + javaAudioRecordFields.nativeCallbackCookie = GetFieldIDOrDie(env, + audioRecordClass, JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J"); // Get the AudioAttributes class and fields - jclass audioAttrClass = env->FindClass(kAudioAttributesClassPathName); - if (audioAttrClass == NULL) { - ALOGE("Can't find %s", kAudioAttributesClassPathName); - return -1; - } - 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; - } + jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName); + javaAudioAttrFields.fieldRecSource = GetFieldIDOrDie(env, audioAttrClass, "mSource", "I"); + javaAudioAttrFields.fieldFlags = GetFieldIDOrDie(env, audioAttrClass, "mFlags", "I"); + javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env, + audioAttrClass, "mFormattedTags", "Ljava/lang/String;"); - return AndroidRuntime::registerNativeMethods(env, - kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } // ---------------------------------------------------------------------------- diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp index 378a700..87688ba 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -22,7 +22,7 @@ #include <jni.h> #include <JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <media/AudioSystem.h> @@ -1380,99 +1380,94 @@ static JNINativeMethod gEventHandlerMethods[] = { int register_android_media_AudioSystem(JNIEnv *env) { - - jclass arrayListClass = env->FindClass("java/util/ArrayList"); - gArrayListClass = (jclass) env->NewGlobalRef(arrayListClass); - gArrayListMethods.add = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z"); - - jclass audioHandleClass = env->FindClass("android/media/AudioHandle"); - gAudioHandleClass = (jclass) env->NewGlobalRef(audioHandleClass); - gAudioHandleCstor = env->GetMethodID(audioHandleClass, "<init>", "(I)V"); - gAudioHandleFields.mId = env->GetFieldID(audioHandleClass, "mId", "I"); - - 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", + jclass arrayListClass = FindClassOrDie(env, "java/util/ArrayList"); + gArrayListClass = MakeGlobalRefOrDie(env, arrayListClass); + gArrayListMethods.add = GetMethodIDOrDie(env, arrayListClass, "add", "(Ljava/lang/Object;)Z"); + + jclass audioHandleClass = FindClassOrDie(env, "android/media/AudioHandle"); + gAudioHandleClass = MakeGlobalRefOrDie(env, audioHandleClass); + gAudioHandleCstor = GetMethodIDOrDie(env, audioHandleClass, "<init>", "(I)V"); + gAudioHandleFields.mId = GetFieldIDOrDie(env, audioHandleClass, "mId", "I"); + + jclass audioPortClass = FindClassOrDie(env, "android/media/AudioPort"); + gAudioPortClass = MakeGlobalRefOrDie(env, audioPortClass); + gAudioPortCstor = GetMethodIDOrDie(env, audioPortClass, "<init>", + "(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V"); + gAudioPortFields.mHandle = GetFieldIDOrDie(env, audioPortClass, "mHandle", "Landroid/media/AudioHandle;"); - gAudioPortFields.mRole = env->GetFieldID(audioPortClass, "mRole", "I"); - gAudioPortFields.mGains = env->GetFieldID(audioPortClass, "mGains", + gAudioPortFields.mRole = GetFieldIDOrDie(env, audioPortClass, "mRole", "I"); + gAudioPortFields.mGains = GetFieldIDOrDie(env, audioPortClass, "mGains", "[Landroid/media/AudioGain;"); - gAudioPortFields.mActiveConfig = env->GetFieldID(audioPortClass, "mActiveConfig", - "Landroid/media/AudioPortConfig;"); - - jclass audioPortConfigClass = env->FindClass("android/media/AudioPortConfig"); - gAudioPortConfigClass = (jclass) env->NewGlobalRef(audioPortConfigClass); - gAudioPortConfigCstor = env->GetMethodID(audioPortConfigClass, "<init>", - "(Landroid/media/AudioPort;IIILandroid/media/AudioGainConfig;)V"); - gAudioPortConfigFields.mPort = env->GetFieldID(audioPortConfigClass, "mPort", + gAudioPortFields.mActiveConfig = GetFieldIDOrDie(env, audioPortClass, "mActiveConfig", + "Landroid/media/AudioPortConfig;"); + + jclass audioPortConfigClass = FindClassOrDie(env, "android/media/AudioPortConfig"); + gAudioPortConfigClass = MakeGlobalRefOrDie(env, audioPortConfigClass); + gAudioPortConfigCstor = GetMethodIDOrDie(env, audioPortConfigClass, "<init>", + "(Landroid/media/AudioPort;IIILandroid/media/AudioGainConfig;)V"); + gAudioPortConfigFields.mPort = GetFieldIDOrDie(env, audioPortConfigClass, "mPort", "Landroid/media/AudioPort;"); - gAudioPortConfigFields.mSamplingRate = env->GetFieldID(audioPortConfigClass, + gAudioPortConfigFields.mSamplingRate = GetFieldIDOrDie(env, audioPortConfigClass, "mSamplingRate", "I"); - gAudioPortConfigFields.mChannelMask = env->GetFieldID(audioPortConfigClass, + gAudioPortConfigFields.mChannelMask = GetFieldIDOrDie(env, audioPortConfigClass, "mChannelMask", "I"); - gAudioPortConfigFields.mFormat = env->GetFieldID(audioPortConfigClass, "mFormat", "I"); - gAudioPortConfigFields.mGain = env->GetFieldID(audioPortConfigClass, "mGain", + gAudioPortConfigFields.mFormat = GetFieldIDOrDie(env, audioPortConfigClass, "mFormat", "I"); + gAudioPortConfigFields.mGain = GetFieldIDOrDie(env, audioPortConfigClass, "mGain", "Landroid/media/AudioGainConfig;"); - gAudioPortConfigFields.mConfigMask = env->GetFieldID(audioPortConfigClass, "mConfigMask", "I"); - - jclass audioDevicePortConfigClass = env->FindClass("android/media/AudioDevicePortConfig"); - gAudioDevicePortConfigClass = (jclass) env->NewGlobalRef(audioDevicePortConfigClass); - gAudioDevicePortConfigCstor = env->GetMethodID(audioDevicePortConfigClass, "<init>", - "(Landroid/media/AudioDevicePort;IIILandroid/media/AudioGainConfig;)V"); - - jclass audioMixPortConfigClass = env->FindClass("android/media/AudioMixPortConfig"); - gAudioMixPortConfigClass = (jclass) env->NewGlobalRef(audioMixPortConfigClass); - gAudioMixPortConfigCstor = env->GetMethodID(audioMixPortConfigClass, "<init>", - "(Landroid/media/AudioMixPort;IIILandroid/media/AudioGainConfig;)V"); - - jclass audioDevicePortClass = env->FindClass("android/media/AudioDevicePort"); - gAudioDevicePortClass = (jclass) env->NewGlobalRef(audioDevicePortClass); - gAudioDevicePortCstor = env->GetMethodID(audioDevicePortClass, "<init>", - "(Landroid/media/AudioHandle;[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V"); - - jclass audioMixPortClass = env->FindClass("android/media/AudioMixPort"); - gAudioMixPortClass = (jclass) env->NewGlobalRef(audioMixPortClass); - gAudioMixPortCstor = env->GetMethodID(audioMixPortClass, "<init>", - "(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V"); - - jclass audioGainClass = env->FindClass("android/media/AudioGain"); - gAudioGainClass = (jclass) env->NewGlobalRef(audioGainClass); - gAudioGainCstor = env->GetMethodID(audioGainClass, "<init>", "(IIIIIIIII)V"); - - jclass audioGainConfigClass = env->FindClass("android/media/AudioGainConfig"); - gAudioGainConfigClass = (jclass) env->NewGlobalRef(audioGainConfigClass); - gAudioGainConfigCstor = env->GetMethodID(audioGainConfigClass, "<init>", + gAudioPortConfigFields.mConfigMask = GetFieldIDOrDie(env, audioPortConfigClass, "mConfigMask", + "I"); + + jclass audioDevicePortConfigClass = FindClassOrDie(env, "android/media/AudioDevicePortConfig"); + gAudioDevicePortConfigClass = MakeGlobalRefOrDie(env, audioDevicePortConfigClass); + gAudioDevicePortConfigCstor = GetMethodIDOrDie(env, audioDevicePortConfigClass, "<init>", + "(Landroid/media/AudioDevicePort;IIILandroid/media/AudioGainConfig;)V"); + + jclass audioMixPortConfigClass = FindClassOrDie(env, "android/media/AudioMixPortConfig"); + gAudioMixPortConfigClass = MakeGlobalRefOrDie(env, audioMixPortConfigClass); + gAudioMixPortConfigCstor = GetMethodIDOrDie(env, audioMixPortConfigClass, "<init>", + "(Landroid/media/AudioMixPort;IIILandroid/media/AudioGainConfig;)V"); + + jclass audioDevicePortClass = FindClassOrDie(env, "android/media/AudioDevicePort"); + gAudioDevicePortClass = MakeGlobalRefOrDie(env, audioDevicePortClass); + gAudioDevicePortCstor = GetMethodIDOrDie(env, audioDevicePortClass, "<init>", + "(Landroid/media/AudioHandle;[I[I[I[Landroid/media/AudioGain;ILjava/lang/String;)V"); + + jclass audioMixPortClass = FindClassOrDie(env, "android/media/AudioMixPort"); + gAudioMixPortClass = MakeGlobalRefOrDie(env, audioMixPortClass); + gAudioMixPortCstor = GetMethodIDOrDie(env, audioMixPortClass, "<init>", + "(Landroid/media/AudioHandle;I[I[I[I[Landroid/media/AudioGain;)V"); + + jclass audioGainClass = FindClassOrDie(env, "android/media/AudioGain"); + gAudioGainClass = MakeGlobalRefOrDie(env, audioGainClass); + gAudioGainCstor = GetMethodIDOrDie(env, audioGainClass, "<init>", "(IIIIIIIII)V"); + + jclass audioGainConfigClass = FindClassOrDie(env, "android/media/AudioGainConfig"); + gAudioGainConfigClass = MakeGlobalRefOrDie(env, audioGainConfigClass); + gAudioGainConfigCstor = GetMethodIDOrDie(env, audioGainConfigClass, "<init>", "(ILandroid/media/AudioGain;II[II)V"); - gAudioGainConfigFields.mIndex = env->GetFieldID(gAudioGainConfigClass, "mIndex", "I"); - gAudioGainConfigFields.mMode = env->GetFieldID(audioGainConfigClass, "mMode", "I"); - gAudioGainConfigFields.mChannelMask = env->GetFieldID(audioGainConfigClass, "mChannelMask", + gAudioGainConfigFields.mIndex = GetFieldIDOrDie(env, gAudioGainConfigClass, "mIndex", "I"); + gAudioGainConfigFields.mMode = GetFieldIDOrDie(env, audioGainConfigClass, "mMode", "I"); + gAudioGainConfigFields.mChannelMask = GetFieldIDOrDie(env, audioGainConfigClass, "mChannelMask", "I"); - gAudioGainConfigFields.mValues = env->GetFieldID(audioGainConfigClass, "mValues", "[I"); - gAudioGainConfigFields.mRampDurationMs = env->GetFieldID(audioGainConfigClass, + gAudioGainConfigFields.mValues = GetFieldIDOrDie(env, audioGainConfigClass, "mValues", "[I"); + gAudioGainConfigFields.mRampDurationMs = GetFieldIDOrDie(env, audioGainConfigClass, "mRampDurationMs", "I"); - jclass audioPatchClass = env->FindClass("android/media/AudioPatch"); - gAudioPatchClass = (jclass) env->NewGlobalRef(audioPatchClass); - gAudioPatchCstor = env->GetMethodID(audioPatchClass, "<init>", + jclass audioPatchClass = FindClassOrDie(env, "android/media/AudioPatch"); + gAudioPatchClass = MakeGlobalRefOrDie(env, audioPatchClass); + gAudioPatchCstor = GetMethodIDOrDie(env, audioPatchClass, "<init>", "(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;"); - jclass eventHandlerClass = env->FindClass(kEventHandlerClassPathName); - gPostEventFromNative = env->GetStaticMethodID(eventHandlerClass, "postEventFromNative", - "(Ljava/lang/Object;IIILjava/lang/Object;)V"); + jclass eventHandlerClass = FindClassOrDie(env, kEventHandlerClassPathName); + gPostEventFromNative = GetStaticMethodIDOrDie(env, eventHandlerClass, "postEventFromNative", + "(Ljava/lang/Object;IIILjava/lang/Object;)V"); AudioSystem::setErrorCallback(android_media_AudioSystem_error_callback); - int status = AndroidRuntime::registerNativeMethods(env, - kClassPathName, gMethods, NELEM(gMethods)); - - if (status == 0) { - status = AndroidRuntime::registerNativeMethods(env, - kEventHandlerClassPathName, gEventHandlerMethods, NELEM(gEventHandlerMethods)); - } - return status; + RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kEventHandlerClassPathName, gEventHandlerMethods, + NELEM(gEventHandlerMethods)); } diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp index ab38864..c6f4199 100644 --- a/core/jni/android_media_AudioTrack.cpp +++ b/core/jni/android_media_AudioTrack.cpp @@ -19,7 +19,7 @@ #include <JNIHelp.h> #include <JniConstants.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "ScopedBytes.h" @@ -1062,68 +1062,34 @@ int register_android_media_AudioTrack(JNIEnv *env) javaAudioTrackFields.postNativeEventInJava = NULL; // Get the AudioTrack class - jclass audioTrackClass = env->FindClass(kClassPathName); - if (audioTrackClass == NULL) { - ALOGE("Can't find %s", kClassPathName); - return -1; - } + jclass audioTrackClass = FindClassOrDie(env, kClassPathName); // Get the postEvent method - javaAudioTrackFields.postNativeEventInJava = env->GetStaticMethodID( - audioTrackClass, - JAVA_POSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;IIILjava/lang/Object;)V"); - if (javaAudioTrackFields.postNativeEventInJava == NULL) { - ALOGE("Can't find AudioTrack.%s", JAVA_POSTEVENT_CALLBACK_NAME); - return -1; - } + javaAudioTrackFields.postNativeEventInJava = GetStaticMethodIDOrDie(env, + audioTrackClass, JAVA_POSTEVENT_CALLBACK_NAME, + "(Ljava/lang/Object;IIILjava/lang/Object;)V"); // Get the variables fields // nativeTrackInJavaObj - javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID( - audioTrackClass, - JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J"); - if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) { - ALOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME); - return -1; - } + javaAudioTrackFields.nativeTrackInJavaObj = GetFieldIDOrDie(env, + audioTrackClass, JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J"); // jniData - javaAudioTrackFields.jniData = env->GetFieldID( - audioTrackClass, - JAVA_JNIDATA_FIELD_NAME, "J"); - if (javaAudioTrackFields.jniData == NULL) { - ALOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME); - return -1; - } + javaAudioTrackFields.jniData = GetFieldIDOrDie(env, + audioTrackClass, JAVA_JNIDATA_FIELD_NAME, "J"); // fieldStreamType - javaAudioTrackFields.fieldStreamType = env->GetFieldID(audioTrackClass, - JAVA_STREAMTYPE_FIELD_NAME, "I"); - if (javaAudioTrackFields.fieldStreamType == NULL) { - ALOGE("Can't find AudioTrack.%s", JAVA_STREAMTYPE_FIELD_NAME); - return -1; - } + javaAudioTrackFields.fieldStreamType = GetFieldIDOrDie(env, + audioTrackClass, JAVA_STREAMTYPE_FIELD_NAME, "I"); // Get the AudioAttributes class and fields - jclass audioAttrClass = env->FindClass(kAudioAttributesClassPathName); - if (audioAttrClass == NULL) { - ALOGE("Can't find %s", kAudioAttributesClassPathName); - return -1; - } - jclass audioAttributesClassRef = (jclass)env->NewGlobalRef(audioAttrClass); - javaAudioAttrFields.fieldUsage = env->GetFieldID(audioAttributesClassRef, "mUsage", "I"); - 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)); + jclass audioAttrClass = FindClassOrDie(env, kAudioAttributesClassPathName); + javaAudioAttrFields.fieldUsage = GetFieldIDOrDie(env, audioAttrClass, "mUsage", "I"); + javaAudioAttrFields.fieldContentType = GetFieldIDOrDie(env, + audioAttrClass, "mContentType", "I"); + javaAudioAttrFields.fieldFlags = GetFieldIDOrDie(env, audioAttrClass, "mFlags", "I"); + javaAudioAttrFields.fieldFormattedTags = GetFieldIDOrDie(env, + audioAttrClass, "mFormattedTags", "Ljava/lang/String;"); + + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_media_JetPlayer.cpp b/core/jni/android_media_JetPlayer.cpp index 69f5711..d441f10 100644 --- a/core/jni/android_media_JetPlayer.cpp +++ b/core/jni/android_media_JetPlayer.cpp @@ -24,7 +24,7 @@ #include <jni.h> #include <JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/Log.h> #include <media/JetPlayer.h> @@ -517,36 +517,22 @@ static JNINativeMethod gMethods[] = { int register_android_media_JetPlayer(JNIEnv *env) { - jclass jetPlayerClass = NULL; javaJetPlayerFields.jetClass = NULL; javaJetPlayerFields.postNativeEventInJava = NULL; javaJetPlayerFields.nativePlayerInJavaObj = NULL; // Get the JetPlayer java class - jetPlayerClass = env->FindClass(kClassPathName); - if (jetPlayerClass == NULL) { - ALOGE("Can't find %s", kClassPathName); - return -1; - } - javaJetPlayerFields.jetClass = (jclass)env->NewGlobalRef(jetPlayerClass); + jclass jetPlayerClass = FindClassOrDie(env, kClassPathName); + javaJetPlayerFields.jetClass = MakeGlobalRefOrDie(env, jetPlayerClass); // Get the mNativePlayerInJavaObj variable field - javaJetPlayerFields.nativePlayerInJavaObj = env->GetFieldID( - jetPlayerClass, - JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J"); - if (javaJetPlayerFields.nativePlayerInJavaObj == NULL) { - ALOGE("Can't find JetPlayer.%s", JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME); - return -1; - } + javaJetPlayerFields.nativePlayerInJavaObj = GetFieldIDOrDie(env, + jetPlayerClass, JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J"); // Get the callback to post events from this native code to Java - javaJetPlayerFields.postNativeEventInJava = env->GetStaticMethodID(javaJetPlayerFields.jetClass, - JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME, "(Ljava/lang/Object;III)V"); - if (javaJetPlayerFields.postNativeEventInJava == NULL) { - ALOGE("Can't find Jet.%s", JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME); - return -1; - } + javaJetPlayerFields.postNativeEventInJava = GetStaticMethodIDOrDie(env, + javaJetPlayerFields.jetClass, JAVA_NATIVEJETPOSTEVENT_CALLBACK_NAME, + "(Ljava/lang/Object;III)V"); - return AndroidRuntime::registerNativeMethods(env, - kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_media_RemoteDisplay.cpp b/core/jni/android_media_RemoteDisplay.cpp index 1cd3fbb..e2bba30 100644 --- a/core/jni/android_media_RemoteDisplay.cpp +++ b/core/jni/android_media_RemoteDisplay.cpp @@ -22,7 +22,7 @@ #include "android_os_Parcel.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/Log.h> @@ -188,17 +188,15 @@ static JNINativeMethod gMethods[] = { int register_android_media_RemoteDisplay(JNIEnv* env) { - int err = AndroidRuntime::registerNativeMethods(env, "android/media/RemoteDisplay", - gMethods, NELEM(gMethods)); - - jclass clazz = env->FindClass("android/media/RemoteDisplay"); - gRemoteDisplayClassInfo.notifyDisplayConnected = - env->GetMethodID(clazz, "notifyDisplayConnected", - "(Landroid/view/Surface;IIII)V"); - gRemoteDisplayClassInfo.notifyDisplayDisconnected = - env->GetMethodID(clazz, "notifyDisplayDisconnected", "()V"); - gRemoteDisplayClassInfo.notifyDisplayError = - env->GetMethodID(clazz, "notifyDisplayError", "(I)V"); + int err = RegisterMethodsOrDie(env, "android/media/RemoteDisplay", gMethods, NELEM(gMethods)); + + jclass clazz = FindClassOrDie(env, "android/media/RemoteDisplay"); + gRemoteDisplayClassInfo.notifyDisplayConnected = GetMethodIDOrDie(env, + clazz, "notifyDisplayConnected", "(Landroid/view/Surface;IIII)V"); + gRemoteDisplayClassInfo.notifyDisplayDisconnected = GetMethodIDOrDie(env, + clazz, "notifyDisplayDisconnected", "()V"); + gRemoteDisplayClassInfo.notifyDisplayError = GetMethodIDOrDie(env, + clazz, "notifyDisplayError", "(I)V"); return err; } diff --git a/core/jni/android_media_ToneGenerator.cpp b/core/jni/android_media_ToneGenerator.cpp index ca00709..243f040 100644 --- a/core/jni/android_media_ToneGenerator.cpp +++ b/core/jni/android_media_ToneGenerator.cpp @@ -23,7 +23,7 @@ #include <jni.h> #include <JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <utils/Log.h> #include <media/AudioSystem.h> @@ -134,21 +134,10 @@ static JNINativeMethod gMethods[] = { int register_android_media_ToneGenerator(JNIEnv *env) { - jclass clazz; + jclass clazz = FindClassOrDie(env, "android/media/ToneGenerator"); - clazz = env->FindClass("android/media/ToneGenerator"); - 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; - } + fields.context = GetFieldIDOrDie(env, clazz, "mNativeContext", "J"); ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context); - return AndroidRuntime::registerNativeMethods(env, - "android/media/ToneGenerator", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/media/ToneGenerator", gMethods, NELEM(gMethods)); } diff --git a/core/jni/android_net_TrafficStats.cpp b/core/jni/android_net_TrafficStats.cpp index 031637f..7354417 100644 --- a/core/jni/android_net_TrafficStats.cpp +++ b/core/jni/android_net_TrafficStats.cpp @@ -23,7 +23,7 @@ #include <sys/stat.h> #include <sys/types.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <jni.h> #include <ScopedUtfChars.h> #include <utils/misc.h> @@ -192,8 +192,7 @@ static JNINativeMethod gMethods[] = { }; int register_android_net_TrafficStats(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, "android/net/TrafficStats", - gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/net/TrafficStats", gMethods, NELEM(gMethods)); } } diff --git a/core/jni/android_nio_utils.h b/core/jni/android_nio_utils.h index 5ada287..bd5f20a 100644 --- a/core/jni/android_nio_utils.h +++ b/core/jni/android_nio_utils.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef android_nio_utils_DEFINED -#define android_nio_utils_DEFINED +#ifndef _ANDROID_NIO_UTILS_H_ +#define _ANDROID_NIO_UTILS_H_ #include <android_runtime/AndroidRuntime.h> @@ -70,4 +70,4 @@ private: } /* namespace android */ -#endif +#endif // _ANDROID_NIO_UTILS_H_ diff --git a/core/jni/android_os_MemoryFile.cpp b/core/jni/android_os_MemoryFile.cpp index 27b29bc..c198a73 100644 --- a/core/jni/android_os_MemoryFile.cpp +++ b/core/jni/android_os_MemoryFile.cpp @@ -18,7 +18,7 @@ #include <utils/Log.h> #include <cutils/ashmem.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "JNIHelp.h" #include <unistd.h> #include <sys/mman.h> @@ -151,9 +151,7 @@ static const JNINativeMethod methods[] = { int register_android_os_MemoryFile(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods( - env, "android/os/MemoryFile", - methods, NELEM(methods)); + return RegisterMethodsOrDie(env, "android/os/MemoryFile", methods, NELEM(methods)); } } diff --git a/core/jni/android_os_SELinux.cpp b/core/jni/android_os_SELinux.cpp index c282549..136e758 100644 --- a/core/jni/android_os_SELinux.cpp +++ b/core/jni/android_os_SELinux.cpp @@ -19,7 +19,7 @@ #include "JNIHelp.h" #include "jni.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include "selinux/selinux.h" #include "selinux/android.h" #include <errno.h> @@ -469,8 +469,7 @@ int register_android_os_SELinux(JNIEnv *env) { isSELinuxDisabled = (is_selinux_enabled() != 1) ? true : false; - return AndroidRuntime::registerNativeMethods(env, "android/os/SELinux", method_table, - NELEM(method_table)); + return RegisterMethodsOrDie(env, "android/os/SELinux", method_table, NELEM(method_table)); } } diff --git a/core/jni/android_os_SystemClock.cpp b/core/jni/android_os_SystemClock.cpp index 6247844..1d45605 100644 --- a/core/jni/android_os_SystemClock.cpp +++ b/core/jni/android_os_SystemClock.cpp @@ -27,7 +27,7 @@ #include "JNIHelp.h" #include "jni.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <sys/time.h> #include <time.h> @@ -135,8 +135,7 @@ static JNINativeMethod gMethods[] = { }; int register_android_os_SystemClock(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, - "android/os/SystemClock", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/os/SystemClock", gMethods, NELEM(gMethods)); } }; // namespace android diff --git a/core/jni/android_os_SystemProperties.cpp b/core/jni/android_os_SystemProperties.cpp index 677396d1..554d304 100644 --- a/core/jni/android_os_SystemProperties.cpp +++ b/core/jni/android_os_SystemProperties.cpp @@ -21,7 +21,7 @@ #include "utils/misc.h" #include <utils/Log.h> #include "jni.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <nativehelper/JNIHelp.h> namespace android @@ -239,9 +239,8 @@ static JNINativeMethod method_table[] = { int register_android_os_SystemProperties(JNIEnv *env) { - return AndroidRuntime::registerNativeMethods( - env, "android/os/SystemProperties", - method_table, NELEM(method_table)); + return RegisterMethodsOrDie(env, "android/os/SystemProperties", method_table, + NELEM(method_table)); } }; diff --git a/core/jni/android_os_UEventObserver.cpp b/core/jni/android_os_UEventObserver.cpp index 3f7c7d2..eb36f85 100644 --- a/core/jni/android_os_UEventObserver.cpp +++ b/core/jni/android_os_UEventObserver.cpp @@ -22,7 +22,7 @@ #include "hardware_legacy/uevent.h" #include "jni.h" #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <utils/Mutex.h> #include <utils/Vector.h> @@ -117,16 +117,9 @@ static JNINativeMethod gMethods[] = { int register_android_os_UEventObserver(JNIEnv *env) { - jclass clazz; + FindClassOrDie(env, "android/os/UEventObserver"); - clazz = env->FindClass("android/os/UEventObserver"); - if (clazz == NULL) { - ALOGE("Can't find android/os/UEventObserver"); - return -1; - } - - return AndroidRuntime::registerNativeMethods(env, - "android/os/UEventObserver", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/os/UEventObserver", gMethods, NELEM(gMethods)); } } // namespace android diff --git a/core/jni/android_server_Watchdog.cpp b/core/jni/android_server_Watchdog.cpp index 6726c14..d1f9434 100644 --- a/core/jni/android_server_Watchdog.cpp +++ b/core/jni/android_server_Watchdog.cpp @@ -26,7 +26,7 @@ #include "jni.h" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" static void dumpOneStack(int tid, int outFd) { char buf[64]; @@ -106,8 +106,7 @@ static const JNINativeMethod g_methods[] = { }; int register_android_server_Watchdog(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, "com/android/server/Watchdog", - g_methods, NELEM(g_methods)); + return RegisterMethodsOrDie(env, "com/android/server/Watchdog", g_methods, NELEM(g_methods)); } } diff --git a/core/jni/android_text_AndroidBidi.cpp b/core/jni/android_text_AndroidBidi.cpp index 6f7ee49..3285429 100644 --- a/core/jni/android_text_AndroidBidi.cpp +++ b/core/jni/android_text_AndroidBidi.cpp @@ -18,7 +18,7 @@ #define LOG_TAG "AndroidUnicode" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "utils/misc.h" #include "utils/Log.h" #include "unicode/ubidi.h" @@ -57,14 +57,12 @@ static jint runBidi(JNIEnv* env, jobject obj, jint dir, jcharArray chsArray, } static JNINativeMethod gMethods[] = { - { "runBidi", "(I[C[BIZ)I", - (void*) runBidi } + { "runBidi", "(I[C[BIZ)I", (void*) runBidi } }; int register_android_text_AndroidBidi(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, "android/text/AndroidBidi", - gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/text/AndroidBidi", gMethods, NELEM(gMethods)); } } diff --git a/core/jni/android_text_AndroidCharacter.cpp b/core/jni/android_text_AndroidCharacter.cpp index 94bd40f..9258248 100644 --- a/core/jni/android_text_AndroidCharacter.cpp +++ b/core/jni/android_text_AndroidCharacter.cpp @@ -19,7 +19,7 @@ #include "JNIHelp.h" #include "ScopedPrimitiveArray.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "utils/misc.h" #include "utils/Log.h" #include "unicode/uchar.h" @@ -193,8 +193,7 @@ static JNINativeMethod gMethods[] = { int register_android_text_AndroidCharacter(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, "android/text/AndroidCharacter", - gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/text/AndroidCharacter", gMethods, NELEM(gMethods)); } } diff --git a/core/jni/android_text_StaticLayout.cpp b/core/jni/android_text_StaticLayout.cpp index 9e20d18..0c2ebf4 100644 --- a/core/jni/android_text_StaticLayout.cpp +++ b/core/jni/android_text_StaticLayout.cpp @@ -23,7 +23,7 @@ #include "utils/Log.h" #include "ScopedPrimitiveArray.h" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <vector> namespace android { @@ -103,8 +103,7 @@ static JNINativeMethod gMethods[] = { int register_android_text_StaticLayout(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, "android/text/StaticLayout", - gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/text/StaticLayout", gMethods, NELEM(gMethods)); } } diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp index 0752c7e..5f42c3d 100644 --- a/core/jni/android_util_Binder.cpp +++ b/core/jni/android_util_Binder.cpp @@ -46,8 +46,6 @@ #include <ScopedUtfChars.h> #include <ScopedLocalRef.h> -#include <android_runtime/AndroidRuntime.h> - #include "core_jni_helpers.h" //#undef ALOGV @@ -834,7 +832,7 @@ static int int_register_android_os_Binder(JNIEnv* env) gBinderOffsets.mExecTransact = GetMethodIDOrDie(env, clazz, "execTransact", "(IJJI)Z"); gBinderOffsets.mObject = GetFieldIDOrDie(env, clazz, "mObject", "J"); - return AndroidRuntime::registerNativeMethods( + return RegisterMethodsOrDie( env, kBinderPathName, gBinderMethods, NELEM(gBinderMethods)); } @@ -909,7 +907,7 @@ static int int_register_android_os_BinderInternal(JNIEnv* env) gBinderInternalOffsets.mClass = MakeGlobalRefOrDie(env, clazz); gBinderInternalOffsets.mForceGc = GetStaticMethodIDOrDie(env, clazz, "forceBinderGc", "()V"); - return AndroidRuntime::registerNativeMethods( + return RegisterMethodsOrDie( env, kBinderInternalPathName, gBinderInternalMethods, NELEM(gBinderInternalMethods)); } @@ -1240,7 +1238,7 @@ static int int_register_android_os_BinderProxy(JNIEnv* env) clazz = FindClassOrDie(env, "java/lang/Class"); gClassOffsets.mGetName = GetMethodIDOrDie(env, clazz, "getName", "()Ljava/lang/String;"); - return AndroidRuntime::registerNativeMethods( + return RegisterMethodsOrDie( env, kBinderProxyPathName, gBinderProxyMethods, NELEM(gBinderProxyMethods)); } diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp index 8a0eaa2..2df13b7 100644 --- a/core/jni/android_util_EventLog.cpp +++ b/core/jni/android_util_EventLog.cpp @@ -17,7 +17,7 @@ #include <fcntl.h> #include "JNIHelp.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include "jni.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) { for (int i = 0; i < NELEM(gClasses); ++i) { - jclass clazz = env->FindClass(gClasses[i].name); - if (clazz == NULL) { - ALOGE("Can't find class: %s\n", gClasses[i].name); - return -1; - } - *gClasses[i].clazz = (jclass) env->NewGlobalRef(clazz); + jclass clazz = FindClassOrDie(env, gClasses[i].name); + *gClasses[i].clazz = MakeGlobalRefOrDie(env, clazz); } 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); - 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) { - *gMethods[i].id = env->GetMethodID( + *gMethods[i].id = GetMethodIDOrDie(env, *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, "android/util/EventLog", gRegisterMethods, NELEM(gRegisterMethods)); diff --git a/core/jni/android_util_FileObserver.cpp b/core/jni/android_util_FileObserver.cpp index b906cfd..067d298 100644 --- a/core/jni/android_util_FileObserver.cpp +++ b/core/jni/android_util_FileObserver.cpp @@ -19,7 +19,7 @@ #include "jni.h" #include "utils/Log.h" #include "utils/misc.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <stdio.h> #include <stdlib.h> @@ -138,24 +138,12 @@ static JNINativeMethod sMethods[] = { 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) - { - 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)); + return RegisterMethodsOrDie(env, "android/os/FileObserver$ObserverThread", sMethods, + NELEM(sMethods)); } } /* namespace android */ diff --git a/core/jni/android_util_Log.cpp b/core/jni/android_util_Log.cpp index 93dcbef..9a80f1d 100644 --- a/core/jni/android_util_Log.cpp +++ b/core/jni/android_util_Log.cpp @@ -26,11 +26,9 @@ #include "jni.h" #include "JNIHelp.h" #include "utils/misc.h" -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include "android_util_Log.h" -#define MIN(a,b) ((a<b)?a:b) - namespace android { struct levels_t { @@ -145,21 +143,16 @@ static JNINativeMethod gMethods[] = { int register_android_util_Log(JNIEnv* env) { - jclass clazz = env->FindClass("android/util/Log"); - - if (clazz == NULL) { - ALOGE("Can't find android/util/Log"); - return -1; - } + jclass clazz = FindClassOrDie(env, "android/util/Log"); - levels.verbose = env->GetStaticIntField(clazz, env->GetStaticFieldID(clazz, "VERBOSE", "I")); - 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")); + levels.verbose = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "VERBOSE", "I")); + levels.debug = env->GetStaticIntField(clazz, GetStaticFieldIDOrDie(env, clazz, "DEBUG", "I")); + 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")); - return AndroidRuntime::registerNativeMethods(env, "android/util/Log", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "android/util/Log", gMethods, NELEM(gMethods)); } }; // namespace android diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index 1d70909..2830724 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -26,7 +26,7 @@ #include <utils/Vector.h> #include <processgroup/processgroup.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include "android_util_Binder.h" #include "JNIHelp.h" @@ -1054,11 +1054,7 @@ static const JNINativeMethod methods[] = { {"removeAllProcessGroups", "()V", (void*)android_os_Process_removeAllProcessGroups}, }; -const char* const kProcessPathName = "android/os/Process"; - int register_android_os_Process(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods( - env, kProcessPathName, - methods, NELEM(methods)); + return RegisterMethodsOrDie(env, "android/os/Process", methods, NELEM(methods)); } diff --git a/core/jni/android_util_StringBlock.cpp b/core/jni/android_util_StringBlock.cpp index f29250f..f83eaec 100644 --- a/core/jni/android_util_StringBlock.cpp +++ b/core/jni/android_util_StringBlock.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include "JNIHelp.h" #include <utils/misc.h> -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include <utils/Log.h> #include <androidfw/ResourceTypes.h> @@ -171,7 +171,7 @@ static JNINativeMethod gStringBlockMethods[] = { int register_android_content_StringBlock(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, "android/content/res/StringBlock", gStringBlockMethods, NELEM(gStringBlockMethods)); } diff --git a/core/jni/android_util_XmlBlock.cpp b/core/jni/android_util_XmlBlock.cpp index 57afc2b..375710e 100644 --- a/core/jni/android_util_XmlBlock.cpp +++ b/core/jni/android_util_XmlBlock.cpp @@ -19,7 +19,7 @@ #include "jni.h" #include "JNIHelp.h" -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include <androidfw/AssetManager.h> #include <androidfw/ResourceTypes.h> #include <utils/Log.h> @@ -412,7 +412,7 @@ static JNINativeMethod gXmlBlockMethods[] = { int register_android_content_XmlBlock(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods)); } diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 95c6d33..4d60601 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -53,6 +53,10 @@ namespace android { using namespace uirenderer; +static struct { + jmethodID set; +} gRectClassInfo; + /** * Note: DisplayListRenderer JNI layer is generated and compiled only on supported * devices. This means all the logic must be compiled only when the @@ -64,21 +68,7 @@ using namespace uirenderer; // Defines // ---------------------------------------------------------------------------- -// Debug -#define DEBUG_RENDERER 0 - -// Debug -#if DEBUG_RENDERER - #define RENDERER_LOGD(...) ALOGD(__VA_ARGS__) -#else - #define RENDERER_LOGD(...) -#endif - -// ---------------------------------------------------------------------------- - -static struct { - jmethodID set; -} gRectClassInfo; +static const bool kDebugRenderer = false; // ---------------------------------------------------------------------------- // Constructors @@ -87,7 +77,9 @@ static struct { static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz, jlong rendererPtr) { DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererPtr); - RENDERER_LOGD("Destroy DisplayListRenderer"); + if (kDebugRenderer) { + ALOGD("Destroy DisplayListRenderer"); + } delete renderer; } @@ -842,24 +834,30 @@ static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz, #endif // USE_OPENGL_RENDERER +#ifdef USE_OPENGL_RENDERER +static const bool kUseOpenGLRenderer = true; +#else +static const bool kUseOpenGLRenderer = false; +#endif + // ---------------------------------------------------------------------------- // Common // ---------------------------------------------------------------------------- static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) { -#ifdef USE_OPENGL_RENDERER - char prop[PROPERTY_VALUE_MAX]; - if (property_get("ro.kernel.qemu", prop, NULL) == 0) { - // not in the emulator - return JNI_TRUE; + if (kUseOpenGLRenderer) { + char prop[PROPERTY_VALUE_MAX]; + if (property_get("ro.kernel.qemu", prop, NULL) == 0) { + // not in the emulator + 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 } // ---------------------------------------------------------------------------- @@ -868,10 +866,10 @@ static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz static void android_app_ActivityThread_dumpGraphics(JNIEnv* env, jobject clazz, jobject javaFileDescriptor) { -#ifdef USE_OPENGL_RENDERER - int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); - android::uirenderer::renderthread::RenderProxy::outputLogBuffer(fd); -#endif // USE_OPENGL_RENDERER + if (kUseOpenGLRenderer) { + int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor); + android::uirenderer::renderthread::RenderProxy::outputLogBuffer(fd); + } } // ---------------------------------------------------------------------------- @@ -983,18 +981,16 @@ static JNINativeMethod gActivityThreadMethods[] = { }; int register_android_view_GLES20Canvas(JNIEnv* env) { -#ifdef USE_OPENGL_RENDERER - jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); - gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); -#endif + if (kUseOpenGLRenderer) { + jclass clazz = FindClassOrDie(env, "android/graphics/Rect"); + gRectClassInfo.set = GetMethodIDOrDie(env, clazz, "set", "(IIII)V"); + } return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } -const char* const kActivityThreadPathName = "android/app/ActivityThread"; - int register_android_app_ActivityThread(JNIEnv* env) { - return RegisterMethodsOrDie(env, kActivityThreadPathName, + return RegisterMethodsOrDie(env, "android/app/ActivityThread", gActivityThreadMethods, NELEM(gActivityThreadMethods)); } diff --git a/core/jni/android_view_GraphicBuffer.cpp b/core/jni/android_view_GraphicBuffer.cpp index 7f1af49..a12629f 100644 --- a/core/jni/android_view_GraphicBuffer.cpp +++ b/core/jni/android_view_GraphicBuffer.cpp @@ -47,16 +47,7 @@ namespace android { // ---------------------------------------------------------------------------- // Debug -#define DEBUG_GRAPHIC_BUFFER 0 - -// 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 +static const bool kDebugGraphicBuffer = false; #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<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc()); if (alloc == NULL) { - GB_LOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()"); + if (kDebugGraphicBuffer) { + ALOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()"); + } return NULL; } status_t error; sp<GraphicBuffer> buffer(alloc->createGraphicBuffer(width, height, format, usage, &error)); if (buffer == NULL) { - GB_LOGW("createGraphicBuffer() failed in GraphicBuffer.create()"); + if (kDebugGraphicBuffer) { + ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()"); + } return NULL; } diff --git a/core/jni/android_view_HardwareLayer.cpp b/core/jni/android_view_HardwareLayer.cpp index 1ffff03..cefb3da 100644 --- a/core/jni/android_view_HardwareLayer.cpp +++ b/core/jni/android_view_HardwareLayer.cpp @@ -20,7 +20,7 @@ #include "GraphicsJNI.h" #include <nativehelper/JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <android_runtime/android_graphics_SurfaceTexture.h> #include <gui/GLConsumer.h> @@ -110,7 +110,7 @@ static JNINativeMethod gMethods[] = { }; int register_android_view_HardwareLayer(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } }; diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp index 76d626c..37f5062 100644 --- a/core/jni/android_view_InputEventReceiver.cpp +++ b/core/jni/android_view_InputEventReceiver.cpp @@ -18,10 +18,6 @@ //#define LOG_NDEBUG 0 -// Log debug messages about the dispatch cycle. -#define DEBUG_DISPATCH_CYCLE 0 - - #include "JNIHelp.h" #include <android_runtime/AndroidRuntime.h> @@ -41,6 +37,8 @@ namespace android { +static const bool kDebugDispatchCycle = false; + static struct { jclass clazz; @@ -94,9 +92,9 @@ NativeInputEventReceiver::NativeInputEventReceiver(JNIEnv* env, mReceiverWeakGlobal(env->NewGlobalRef(receiverWeak)), mInputConsumer(inputChannel), mMessageQueue(messageQueue), mBatchedInputEventPending(false), mFdEvents(0) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName()); + } } NativeInputEventReceiver::~NativeInputEventReceiver() { @@ -110,25 +108,25 @@ status_t NativeInputEventReceiver::initialize() { } void NativeInputEventReceiver::dispose() { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Disposing input event receiver.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Disposing input event receiver.", getInputChannelName()); + } setFdEvents(0); } status_t NativeInputEventReceiver::finishInputEvent(uint32_t seq, bool handled) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Finished input event.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Finished input event.", getInputChannelName()); + } status_t status = mInputConsumer.sendFinishedSignal(seq, handled); if (status) { if (status == WOULD_BLOCK) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Could not send finished signal immediately. " - "Enqueued for later.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Could not send finished signal immediately. " + "Enqueued for later.", getInputChannelName()); + } Finish finish; finish.seq = seq; finish.handled = handled; @@ -158,13 +156,13 @@ void NativeInputEventReceiver::setFdEvents(int events) { int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data) { if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) { -#if DEBUG_DISPATCH_CYCLE // 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 // the consumer will soon be disposed as well. - ALOGD("channel '%s' ~ Publisher closed input channel or an error occurred. " - "events=0x%x", getInputChannelName(), events); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Publisher closed input channel or an error occurred. " + "events=0x%x", getInputChannelName(), events); + } return 0; // remove the callback } @@ -183,10 +181,10 @@ int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data) mFinishQueue.removeItemsAt(0, i); if (status == WOULD_BLOCK) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Sent %u queued finish events; %u left.", - getInputChannelName(), i, mFinishQueue.size()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Sent %u queued finish events; %u left.", + getInputChannelName(), i, mFinishQueue.size()); + } 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 } } -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Sent %u queued finish events; none left.", - getInputChannelName(), mFinishQueue.size()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Sent %u queued finish events; none left.", + getInputChannelName(), mFinishQueue.size()); + } mFinishQueue.clear(); setFdEvents(ALOOPER_EVENT_INPUT); return 1; @@ -218,10 +216,10 @@ int NativeInputEventReceiver::handleEvent(int receiveFd, int events, void* data) status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, bool consumeBatches, nsecs_t frameTime, bool* outConsumedBatch) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s, frameTime=%lld.", - getInputChannelName(), consumeBatches ? "true" : "false", frameTime); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s, frameTime=%lld.", + getInputChannelName(), consumeBatches ? "true" : "false", frameTime); + } if (consumeBatches) { mBatchedInputEventPending = false; @@ -252,10 +250,10 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, } mBatchedInputEventPending = true; -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Dispatching batched input event pending notification.", - getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Dispatching batched input event pending notification.", + getInputChannelName()); + } env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.dispatchBatchedInputEventPending); if (env->ExceptionCheck()) { @@ -284,17 +282,17 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, jobject inputEventObj; switch (inputEvent->getType()) { case AINPUT_EVENT_TYPE_KEY: -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Received key event.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received key event.", getInputChannelName()); + } inputEventObj = android_view_KeyEvent_fromNative(env, static_cast<KeyEvent*>(inputEvent)); break; case AINPUT_EVENT_TYPE_MOTION: { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Received motion event.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received motion event.", getInputChannelName()); + } MotionEvent* motionEvent = static_cast<MotionEvent*>(inputEvent); if ((motionEvent->getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) { *outConsumedBatch = true; @@ -309,9 +307,9 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, } if (inputEventObj) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Dispatching input event.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Dispatching input event.", getInputChannelName()); + } env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.dispatchInputEvent, seq, inputEventObj); if (env->ExceptionCheck()) { diff --git a/core/jni/android_view_InputEventSender.cpp b/core/jni/android_view_InputEventSender.cpp index de65d0d..e7388cf 100644 --- a/core/jni/android_view_InputEventSender.cpp +++ b/core/jni/android_view_InputEventSender.cpp @@ -18,10 +18,6 @@ //#define LOG_NDEBUG 0 -// Log debug messages about the dispatch cycle. -#define DEBUG_DISPATCH_CYCLE 0 - - #include "JNIHelp.h" #include <android_runtime/AndroidRuntime.h> @@ -41,6 +37,9 @@ namespace android { +// Log debug messages about the dispatch cycle. +static const bool kDebugDispatchCycle = false; + static struct { jclass clazz; @@ -84,9 +83,9 @@ NativeInputEventSender::NativeInputEventSender(JNIEnv* env, mSenderWeakGlobal(env->NewGlobalRef(senderWeak)), mInputPublisher(inputChannel), mMessageQueue(messageQueue), mNextPublishedSeq(1) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Initializing input event sender.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Initializing input event sender.", getInputChannelName()); + } } NativeInputEventSender::~NativeInputEventSender() { @@ -101,17 +100,17 @@ status_t NativeInputEventSender::initialize() { } void NativeInputEventSender::dispose() { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Disposing input event sender.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Disposing input event sender.", getInputChannelName()); + } mMessageQueue->getLooper()->removeFd(mInputPublisher.getChannel()->getFd()); } status_t NativeInputEventSender::sendKeyEvent(uint32_t seq, const KeyEvent* event) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Sending key event, seq=%u.", getInputChannelName(), seq); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Sending key event, seq=%u.", getInputChannelName(), seq); + } uint32_t publishedSeq = mNextPublishedSeq++; 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) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Sending motion event, seq=%u.", getInputChannelName(), seq); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Sending motion event, seq=%u.", getInputChannelName(), seq); + } uint32_t publishedSeq; 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) { if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) { -#if DEBUG_DISPATCH_CYCLE // 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 // soon be disposed as well. - ALOGD("channel '%s' ~ Consumer closed input channel or an error occurred. " - "events=0x%x", getInputChannelName(), events); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Consumer closed input channel or an error occurred. " + "events=0x%x", getInputChannelName(), events); + } + return 0; // remove the callback } @@ -178,9 +178,9 @@ int NativeInputEventSender::handleEvent(int receiveFd, int events, void* data) { } status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) { -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Receiving finished signals.", getInputChannelName()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Receiving finished signals.", getInputChannelName()); + } ScopedLocalRef<jobject> senderObj(env, NULL); bool skipCallbacks = false; @@ -202,12 +202,12 @@ status_t NativeInputEventSender::receiveFinishedSignals(JNIEnv* env) { uint32_t seq = mPublishedSeqMap.valueAt(index); mPublishedSeqMap.removeItemsAt(index); -#if DEBUG_DISPATCH_CYCLE - ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, " - "pendingEvents=%u.", - getInputChannelName(), seq, handled ? "true" : "false", - mPublishedSeqMap.size()); -#endif + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received finished signal, seq=%u, handled=%s, " + "pendingEvents=%u.", + getInputChannelName(), seq, handled ? "true" : "false", + mPublishedSeqMap.size()); + } if (!skipCallbacks) { if (!senderObj.get()) { diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index b3a9b05..7f6c50f 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -23,7 +23,7 @@ #include "android_os_Parcel.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_graphics_SurfaceTexture.h> #include <android_runtime/Log.h> @@ -454,26 +454,26 @@ static JNINativeMethod gSurfaceMethods[] = { 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)); - jclass clazz = env->FindClass("android/view/Surface"); - gSurfaceClassInfo.clazz = jclass(env->NewGlobalRef(clazz)); - gSurfaceClassInfo.mNativeObject = - env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "J"); - gSurfaceClassInfo.mLock = - env->GetFieldID(gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;"); - gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(J)V"); - - clazz = env->FindClass("android/graphics/Canvas"); - gCanvasClassInfo.mSurfaceFormat = env->GetFieldID(clazz, "mSurfaceFormat", "I"); - gCanvasClassInfo.setNativeBitmap = env->GetMethodID(clazz, "setNativeBitmap", "(J)V"); - - clazz = env->FindClass("android/graphics/Rect"); - gRectClassInfo.left = env->GetFieldID(clazz, "left", "I"); - gRectClassInfo.top = env->GetFieldID(clazz, "top", "I"); - gRectClassInfo.right = env->GetFieldID(clazz, "right", "I"); - gRectClassInfo.bottom = env->GetFieldID(clazz, "bottom", "I"); + jclass clazz = FindClassOrDie(env, "android/view/Surface"); + gSurfaceClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); + gSurfaceClassInfo.mNativeObject = GetFieldIDOrDie(env, + gSurfaceClassInfo.clazz, "mNativeObject", "J"); + gSurfaceClassInfo.mLock = GetFieldIDOrDie(env, + gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;"); + gSurfaceClassInfo.ctor = GetMethodIDOrDie(env, gSurfaceClassInfo.clazz, "<init>", "(J)V"); + + clazz = FindClassOrDie(env, "android/graphics/Canvas"); + gCanvasClassInfo.mSurfaceFormat = GetFieldIDOrDie(env, clazz, "mSurfaceFormat", "I"); + gCanvasClassInfo.setNativeBitmap = GetMethodIDOrDie(env, clazz, "setNativeBitmap", "(J)V"); + + clazz = FindClassOrDie(env, "android/graphics/Rect"); + gRectClassInfo.left = GetFieldIDOrDie(env, clazz, "left", "I"); + gRectClassInfo.top = GetFieldIDOrDie(env, clazz, "top", "I"); + gRectClassInfo.right = GetFieldIDOrDie(env, clazz, "right", "I"); + gRectClassInfo.bottom = GetFieldIDOrDie(env, clazz, "bottom", "I"); return err; } diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index adfcdb0..13c373f 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -26,7 +26,7 @@ #include "android/graphics/GraphicsJNI.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_SurfaceSession.h> @@ -647,41 +647,44 @@ static JNINativeMethod sSurfaceControlMethods[] = { 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)); - jclass clazz = env->FindClass("android/view/SurfaceControl$PhysicalDisplayInfo"); - gPhysicalDisplayInfoClassInfo.clazz = static_cast<jclass>(env->NewGlobalRef(clazz)); - gPhysicalDisplayInfoClassInfo.ctor = env->GetMethodID(gPhysicalDisplayInfoClassInfo.clazz, - "<init>", "()V"); - gPhysicalDisplayInfoClassInfo.width = env->GetFieldID(clazz, "width", "I"); - gPhysicalDisplayInfoClassInfo.height = env->GetFieldID(clazz, "height", "I"); - gPhysicalDisplayInfoClassInfo.refreshRate = env->GetFieldID(clazz, "refreshRate", "F"); - gPhysicalDisplayInfoClassInfo.density = env->GetFieldID(clazz, "density", "F"); - gPhysicalDisplayInfoClassInfo.xDpi = env->GetFieldID(clazz, "xDpi", "F"); - gPhysicalDisplayInfoClassInfo.yDpi = env->GetFieldID(clazz, "yDpi", "F"); - gPhysicalDisplayInfoClassInfo.secure = env->GetFieldID(clazz, "secure", "Z"); - gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = env->GetFieldID(clazz, - "appVsyncOffsetNanos", "J"); - gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = env->GetFieldID(clazz, - "presentationDeadlineNanos", "J"); - - jclass rectClazz = env->FindClass("android/graphics/Rect"); - gRectClassInfo.bottom = env->GetFieldID(rectClazz, "bottom", "I"); - gRectClassInfo.left = env->GetFieldID(rectClazz, "left", "I"); - gRectClassInfo.right = env->GetFieldID(rectClazz, "right", "I"); - gRectClassInfo.top = env->GetFieldID(rectClazz, "top", "I"); - - jclass frameStatsClazz = env->FindClass("android/view/FrameStats"); - jfieldID undefined_time_nano_field = env->GetStaticFieldID(frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); + jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo"); + gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); + gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env, + gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V"); + gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I"); + gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I"); + gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F"); + gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F"); + gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F"); + gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F"); + gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z"); + gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env, + clazz, "appVsyncOffsetNanos", "J"); + gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env, + clazz, "presentationDeadlineNanos", "J"); + + jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect"); + gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I"); + gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I"); + gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I"); + gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I"); + + jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats"); + jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env, + frameStatsClazz, "UNDEFINED_TIME_NANO", "J"); nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field); - jclass contFrameStatsClazz = env->FindClass("android/view/WindowContentFrameStats"); - gWindowContentFrameStatsClassInfo.init = env->GetMethodID(contFrameStatsClazz, "init", "(J[J[J[J)V"); + jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats"); + gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env, + contFrameStatsClazz, "init", "(J[J[J[J)V"); gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; - jclass animFrameStatsClazz = env->FindClass("android/view/WindowAnimationFrameStats"); - gWindowAnimationFrameStatsClassInfo.init = env->GetMethodID(animFrameStatsClazz, "init", "(J[J)V"); + jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats"); + gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env, + animFrameStatsClazz, "init", "(J[J)V"); gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano; return err; diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 6219956..499ff16 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -20,7 +20,7 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <EGL/egl.h> #include <EGL/eglext.h> @@ -454,7 +454,7 @@ static JNINativeMethod gMethods[] = { }; int register_android_view_ThreadedRenderer(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } }; // namespace android diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp index 545cb3e..3c1993e 100644 --- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp +++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "NativeLibraryHelper" //#define LOG_NDEBUG 0 -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <ScopedUtfChars.h> #include <UniquePtr.h> @@ -563,8 +563,8 @@ static JNINativeMethod gMethods[] = { int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env) { - return AndroidRuntime::registerNativeMethods(env, - "com/android/internal/content/NativeLibraryHelper", gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, + "com/android/internal/content/NativeLibraryHelper", gMethods, NELEM(gMethods)); } }; diff --git a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp index 1fbe016..6c0b756 100644 --- a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp +++ b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp @@ -21,7 +21,7 @@ #include <sys/stat.h> #include <sys/types.h> -#include <android_runtime/AndroidRuntime.h> +#include <core_jni_helpers.h> #include <jni.h> #include <ScopedUtfChars.h> @@ -284,16 +284,6 @@ static int readNetworkStatsDetail(JNIEnv* env, jclass clazz, jobject stats, 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[] = { { "nativeReadNetworkStatsDetail", "(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 err = AndroidRuntime::registerNativeMethods(env, + int err = RegisterMethodsOrDie(env, "com/android/internal/net/NetworkStatsFactory", gMethods, NELEM(gMethods)); - gStringClass = findClass(env, "java/lang/String"); - - jclass clazz = env->FindClass("android/net/NetworkStats"); - gNetworkStatsClassInfo.size = env->GetFieldID(clazz, "size", "I"); - gNetworkStatsClassInfo.capacity = env->GetFieldID(clazz, "capacity", "I"); - gNetworkStatsClassInfo.iface = env->GetFieldID(clazz, "iface", "[Ljava/lang/String;"); - gNetworkStatsClassInfo.uid = env->GetFieldID(clazz, "uid", "[I"); - gNetworkStatsClassInfo.set = env->GetFieldID(clazz, "set", "[I"); - gNetworkStatsClassInfo.tag = env->GetFieldID(clazz, "tag", "[I"); - gNetworkStatsClassInfo.rxBytes = env->GetFieldID(clazz, "rxBytes", "[J"); - gNetworkStatsClassInfo.rxPackets = env->GetFieldID(clazz, "rxPackets", "[J"); - gNetworkStatsClassInfo.txBytes = env->GetFieldID(clazz, "txBytes", "[J"); - gNetworkStatsClassInfo.txPackets = env->GetFieldID(clazz, "txPackets", "[J"); - gNetworkStatsClassInfo.operations = env->GetFieldID(clazz, "operations", "[J"); + gStringClass = FindClassOrDie(env, "java/lang/String"); + gStringClass = MakeGlobalRefOrDie(env, gStringClass); + + jclass clazz = FindClassOrDie(env, "android/net/NetworkStats"); + gNetworkStatsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "I"); + gNetworkStatsClassInfo.capacity = GetFieldIDOrDie(env, clazz, "capacity", "I"); + gNetworkStatsClassInfo.iface = GetFieldIDOrDie(env, clazz, "iface", "[Ljava/lang/String;"); + gNetworkStatsClassInfo.uid = GetFieldIDOrDie(env, clazz, "uid", "[I"); + gNetworkStatsClassInfo.set = GetFieldIDOrDie(env, clazz, "set", "[I"); + gNetworkStatsClassInfo.tag = GetFieldIDOrDie(env, clazz, "tag", "[I"); + gNetworkStatsClassInfo.rxBytes = GetFieldIDOrDie(env, clazz, "rxBytes", "[J"); + gNetworkStatsClassInfo.rxPackets = GetFieldIDOrDie(env, clazz, "rxPackets", "[J"); + gNetworkStatsClassInfo.txBytes = GetFieldIDOrDie(env, clazz, "txBytes", "[J"); + gNetworkStatsClassInfo.txPackets = GetFieldIDOrDie(env, clazz, "txPackets", "[J"); + gNetworkStatsClassInfo.operations = GetFieldIDOrDie(env, clazz, "operations", "[J"); return err; } diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp index c645e30..2bfeadb 100644 --- a/core/jni/com_android_internal_os_Zygote.cpp +++ b/core/jni/com_android_internal_os_Zygote.cpp @@ -44,7 +44,7 @@ #include <selinux/android.h> #include <processgroup/processgroup.h> -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include "JNIHelp.h" #include "ScopedLocalRef.h" #include "ScopedPrimitiveArray.h" @@ -613,15 +613,11 @@ static JNINativeMethod gMethods[] = { }; int register_com_android_internal_os_Zygote(JNIEnv* env) { - gZygoteClass = (jclass) env->NewGlobalRef(env->FindClass(kZygoteClassName)); - if (gZygoteClass == NULL) { - RuntimeAbort(env); - } - gCallPostForkChildHooks = env->GetStaticMethodID(gZygoteClass, "callPostForkChildHooks", + gZygoteClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteClassName)); + gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks", "(ILjava/lang/String;)V"); - return AndroidRuntime::registerNativeMethods(env, "com/android/internal/os/Zygote", - gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods)); } } // namespace android diff --git a/core/jni/com_android_internal_os_ZygoteInit.cpp b/core/jni/com_android_internal_os_ZygoteInit.cpp index 10c6e2ce..496f569 100644 --- a/core/jni/com_android_internal_os_ZygoteInit.cpp +++ b/core/jni/com_android_internal_os_ZygoteInit.cpp @@ -25,7 +25,7 @@ #include "jni.h" #include <JNIHelp.h> -#include "android_runtime/AndroidRuntime.h" +#include "core_jni_helpers.h" #include <sys/capability.h> #include <sys/prctl.h> @@ -258,7 +258,7 @@ static JNINativeMethod gMethods[] = { }; int register_com_android_internal_os_ZygoteInit(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, + return RegisterMethodsOrDie(env, "com/android/internal/os/ZygoteInit", gMethods, NELEM(gMethods)); } diff --git a/core/jni/com_android_internal_util_VirtualRefBasePtr.cpp b/core/jni/com_android_internal_util_VirtualRefBasePtr.cpp index ce6f207..7a18c2d 100644 --- a/core/jni/com_android_internal_util_VirtualRefBasePtr.cpp +++ b/core/jni/com_android_internal_util_VirtualRefBasePtr.cpp @@ -16,7 +16,7 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" namespace android { @@ -42,7 +42,7 @@ static JNINativeMethod gMethods[] = { }; int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } diff --git a/core/jni/com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp b/core/jni/com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp index 704e1be..c5c2e9d 100644 --- a/core/jni/com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp +++ b/core/jni/com_android_internal_view_animation_NativeInterpolatorFactoryHelper.cpp @@ -18,7 +18,7 @@ #include "jni.h" #include <nativehelper/JNIHelp.h> -#include <android_runtime/AndroidRuntime.h> +#include "core_jni_helpers.h" #include <Interpolator.h> @@ -98,7 +98,7 @@ static JNINativeMethod gMethods[] = { }; int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv* env) { - return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); + return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); } |