diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index b1560ab7f6b3f..baa7038cef5ec 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -44,15 +44,20 @@ bool CheckException(JNIEnv* env) { } // anonymous namespace -static fml::jni::ScopedJavaGlobalRef* g_flutter_callback_info_class = nullptr; +static fml::jni::ScopedJavaGlobalRef* g_flutter_callback_info_class = + nullptr; -// FlutterView.java, from original embedding API. Not used in 2nd iteration of embedding. +// FlutterView.java, from original embedding API. Not used in 2nd iteration of +// embedding. static fml::jni::ScopedJavaGlobalRef* g_flutter_view_class = nullptr; -// FlutterNativeView.java, from original embedding API. Not used in 2nd iteration of embedding. -static fml::jni::ScopedJavaGlobalRef* g_flutter_native_view_class = nullptr; +// FlutterNativeView.java, from original embedding API. Not used in 2nd +// iteration of embedding. +static fml::jni::ScopedJavaGlobalRef* g_flutter_native_view_class = + nullptr; -// FlutterJNI.java, used in 2nd iteration of embedding to centralize all JNI calls. +// FlutterJNI.java, used in 2nd iteration of embedding to centralize all JNI +// calls. static fml::jni::ScopedJavaGlobalRef* g_flutter_jni_class = nullptr; static fml::jni::ScopedJavaGlobalRef* g_flutter_engine_class = nullptr; @@ -592,130 +597,130 @@ bool RegisterOldApi(JNIEnv* env) { } static const JNINativeMethod native_view_methods[] = { - { - .name = "nativeAttach", - .signature = "(Lio/flutter/view/FlutterNativeView;Z)J", - .fnPtr = reinterpret_cast(&shell::Attach), - }, - { - .name = "nativeDestroy", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::Destroy), - }, - { - .name = "nativeRunBundleAndSnapshotFromLibrary", - .signature = - "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;" - "Ljava/lang/String;Landroid/content/res/AssetManager;)V", - .fnPtr = - reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), - }, - { - .name = "nativeDetach", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::Detach), - }, - { - .name = "nativeGetObservatoryUri", - .signature = "()Ljava/lang/String;", - .fnPtr = reinterpret_cast(&shell::GetObservatoryUri), - }, - { - .name = "nativeDispatchEmptyPlatformMessage", - .signature = "(JLjava/lang/String;I)V", - .fnPtr = - reinterpret_cast(&shell::DispatchEmptyPlatformMessage), - }, - { - .name = "nativeDispatchPlatformMessage", - .signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V", - .fnPtr = reinterpret_cast(&shell::DispatchPlatformMessage), - }, - { - .name = "nativeInvokePlatformMessageResponseCallback", - .signature = "(JILjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast( - &shell::InvokePlatformMessageResponseCallback), - }, - { - .name = "nativeInvokePlatformMessageEmptyResponseCallback", - .signature = "(JI)V", - .fnPtr = reinterpret_cast( - &shell::InvokePlatformMessageEmptyResponseCallback), - }, + { + .name = "nativeAttach", + .signature = "(Lio/flutter/view/FlutterNativeView;Z)J", + .fnPtr = reinterpret_cast(&shell::Attach), + }, + { + .name = "nativeDestroy", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::Destroy), + }, + { + .name = "nativeRunBundleAndSnapshotFromLibrary", + .signature = + "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;" + "Ljava/lang/String;Landroid/content/res/AssetManager;)V", + .fnPtr = + reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), + }, + { + .name = "nativeDetach", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::Detach), + }, + { + .name = "nativeGetObservatoryUri", + .signature = "()Ljava/lang/String;", + .fnPtr = reinterpret_cast(&shell::GetObservatoryUri), + }, + { + .name = "nativeDispatchEmptyPlatformMessage", + .signature = "(JLjava/lang/String;I)V", + .fnPtr = + reinterpret_cast(&shell::DispatchEmptyPlatformMessage), + }, + { + .name = "nativeDispatchPlatformMessage", + .signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V", + .fnPtr = reinterpret_cast(&shell::DispatchPlatformMessage), + }, + { + .name = "nativeInvokePlatformMessageResponseCallback", + .signature = "(JILjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast( + &shell::InvokePlatformMessageResponseCallback), + }, + { + .name = "nativeInvokePlatformMessageEmptyResponseCallback", + .signature = "(JI)V", + .fnPtr = reinterpret_cast( + &shell::InvokePlatformMessageEmptyResponseCallback), + }, }; static const JNINativeMethod view_methods[] = { - { - .name = "nativeSurfaceCreated", - .signature = "(JLandroid/view/Surface;I)V", - .fnPtr = reinterpret_cast(&shell::SurfaceCreated), - }, - { - .name = "nativeSurfaceChanged", - .signature = "(JII)V", - .fnPtr = reinterpret_cast(&shell::SurfaceChanged), - }, - { - .name = "nativeSurfaceDestroyed", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::SurfaceDestroyed), - }, - { - .name = "nativeSetViewportMetrics", - .signature = "(JFIIIIIIIIII)V", - .fnPtr = reinterpret_cast(&shell::SetViewportMetrics), - }, - { - .name = "nativeGetBitmap", - .signature = "(J)Landroid/graphics/Bitmap;", - .fnPtr = reinterpret_cast(&shell::GetBitmap), - }, - { - .name = "nativeDispatchPointerDataPacket", - .signature = "(JLjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast(&shell::DispatchPointerDataPacket), - }, - { - .name = "nativeDispatchSemanticsAction", - .signature = "(JIILjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast(&shell::DispatchSemanticsAction), - }, - { - .name = "nativeSetSemanticsEnabled", - .signature = "(JZ)V", - .fnPtr = reinterpret_cast(&shell::SetSemanticsEnabled), - }, - { - .name = "nativeSetAccessibilityFeatures", - .signature = "(JI)V", - .fnPtr = reinterpret_cast(&shell::SetAccessibilityFeatures), - }, - { - .name = "nativeGetIsSoftwareRenderingEnabled", - .signature = "()Z", - .fnPtr = reinterpret_cast(&shell::GetIsSoftwareRendering), - }, - { - .name = "nativeRegisterTexture", - .signature = "(JJLandroid/graphics/SurfaceTexture;)V", - .fnPtr = reinterpret_cast(&shell::RegisterTexture), - }, - { - .name = "nativeMarkTextureFrameAvailable", - .signature = "(JJ)V", - .fnPtr = reinterpret_cast(&shell::MarkTextureFrameAvailable), - }, - { - .name = "nativeUnregisterTexture", - .signature = "(JJ)V", - .fnPtr = reinterpret_cast(&shell::UnregisterTexture), - }, + { + .name = "nativeSurfaceCreated", + .signature = "(JLandroid/view/Surface;I)V", + .fnPtr = reinterpret_cast(&shell::SurfaceCreated), + }, + { + .name = "nativeSurfaceChanged", + .signature = "(JII)V", + .fnPtr = reinterpret_cast(&shell::SurfaceChanged), + }, + { + .name = "nativeSurfaceDestroyed", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::SurfaceDestroyed), + }, + { + .name = "nativeSetViewportMetrics", + .signature = "(JFIIIIIIIIII)V", + .fnPtr = reinterpret_cast(&shell::SetViewportMetrics), + }, + { + .name = "nativeGetBitmap", + .signature = "(J)Landroid/graphics/Bitmap;", + .fnPtr = reinterpret_cast(&shell::GetBitmap), + }, + { + .name = "nativeDispatchPointerDataPacket", + .signature = "(JLjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast(&shell::DispatchPointerDataPacket), + }, + { + .name = "nativeDispatchSemanticsAction", + .signature = "(JIILjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast(&shell::DispatchSemanticsAction), + }, + { + .name = "nativeSetSemanticsEnabled", + .signature = "(JZ)V", + .fnPtr = reinterpret_cast(&shell::SetSemanticsEnabled), + }, + { + .name = "nativeSetAccessibilityFeatures", + .signature = "(JI)V", + .fnPtr = reinterpret_cast(&shell::SetAccessibilityFeatures), + }, + { + .name = "nativeGetIsSoftwareRenderingEnabled", + .signature = "()Z", + .fnPtr = reinterpret_cast(&shell::GetIsSoftwareRendering), + }, + { + .name = "nativeRegisterTexture", + .signature = "(JJLandroid/graphics/SurfaceTexture;)V", + .fnPtr = reinterpret_cast(&shell::RegisterTexture), + }, + { + .name = "nativeMarkTextureFrameAvailable", + .signature = "(JJ)V", + .fnPtr = reinterpret_cast(&shell::MarkTextureFrameAvailable), + }, + { + .name = "nativeUnregisterTexture", + .signature = "(JJ)V", + .fnPtr = reinterpret_cast(&shell::UnregisterTexture), + }, }; if (env->RegisterNatives(g_flutter_native_view_class->obj(), - native_view_methods, - arraysize(native_view_methods)) != 0) { + native_view_methods, + arraysize(native_view_methods)) != 0) { FML_LOG(ERROR) << "Failed to RegisterNatives with FlutterNativeView."; return false; } @@ -727,8 +732,8 @@ bool RegisterOldApi(JNIEnv* env) { } g_handle_platform_message_method = - env->GetMethodID(g_flutter_native_view_class->obj(), - "handlePlatformMessage", "(Ljava/lang/String;[BI)V"); + env->GetMethodID(g_flutter_native_view_class->obj(), + "handlePlatformMessage", "(Ljava/lang/String;[BI)V"); if (g_handle_platform_message_method == nullptr) { FML_LOG(ERROR) << "Could not locate handlePlatformMessage method"; @@ -736,8 +741,8 @@ bool RegisterOldApi(JNIEnv* env) { } g_handle_platform_message_response_method = - env->GetMethodID(g_flutter_native_view_class->obj(), - "handlePlatformMessageResponse", "(I[B)V"); + env->GetMethodID(g_flutter_native_view_class->obj(), + "handlePlatformMessageResponse", "(I[B)V"); if (g_handle_platform_message_response_method == nullptr) { FML_LOG(ERROR) << "Could not locate handlePlatformMessageResponse method"; @@ -758,7 +763,8 @@ bool RegisterOldApi(JNIEnv* env) { "(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V"); if (g_update_custom_accessibility_actions_method == nullptr) { - FML_LOG(ERROR) << "Could not locate updateCustomAccessibilityActions method"; + FML_LOG(ERROR) + << "Could not locate updateCustomAccessibilityActions method"; return false; } @@ -783,152 +789,151 @@ bool RegisterOldApi(JNIEnv* env) { bool RegisterNewApi(JNIEnv* env) { g_flutter_engine_class = new fml::jni::ScopedJavaGlobalRef( - env, env->FindClass("io/flutter/embedding/FlutterEngine")); + env, env->FindClass("io/flutter/embedding/FlutterEngine")); if (g_flutter_engine_class->is_null()) { FML_LOG(ERROR) << "Failed to find FlutterEngine Class."; return false; } static const JNINativeMethod flutter_jni_methods[] = { - // Start of methods from FlutterNativeView - { - .name = "nativeAttach", - .signature = "(Lio/flutter/embedding/FlutterEngine;Z)J", - .fnPtr = reinterpret_cast(&shell::AttachJNI), - }, - { - .name = "nativeDetach", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::DetachJNI), - }, - { - .name = "nativeDestroy", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::DestroyJNI), - }, - { - .name = "nativeRunBundleAndSnapshotFromLibrary", - .signature = - "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;" - "Ljava/lang/String;Landroid/content/res/AssetManager;)V", - .fnPtr = reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), - }, - { - .name = "nativeGetObservatoryUri", - .signature = "()Ljava/lang/String;", - .fnPtr = reinterpret_cast(&shell::GetObservatoryUri), - }, - { - .name = "nativeDispatchEmptyPlatformMessage", - .signature = "(JLjava/lang/String;I)V", - .fnPtr = - reinterpret_cast(&shell::DispatchEmptyPlatformMessage), - }, - { - .name = "nativeDispatchPlatformMessage", - .signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V", - .fnPtr = reinterpret_cast(&shell::DispatchPlatformMessage), - }, - { - .name = "nativeInvokePlatformMessageResponseCallback", - .signature = "(JILjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast( - &shell::InvokePlatformMessageResponseCallback), - }, - { - .name = "nativeInvokePlatformMessageEmptyResponseCallback", - .signature = "(JI)V", - .fnPtr = reinterpret_cast( - &shell::InvokePlatformMessageEmptyResponseCallback), - }, - - // Start of methods from FlutterView - { - .name = "nativeGetBitmap", - .signature = "(J)Landroid/graphics/Bitmap;", - .fnPtr = reinterpret_cast(&shell::GetBitmap), - }, - { - .name = "nativeSurfaceCreated", - .signature = "(JLandroid/view/Surface;I)V", - .fnPtr = reinterpret_cast(&shell::SurfaceCreated), - }, - { - .name = "nativeSurfaceChanged", - .signature = "(JII)V", - .fnPtr = reinterpret_cast(&shell::SurfaceChanged), - }, - { - .name = "nativeSurfaceDestroyed", - .signature = "(J)V", - .fnPtr = reinterpret_cast(&shell::SurfaceDestroyed), - }, - { - .name = "nativeSetViewportMetrics", - .signature = "(JFIIIIIIIIII)V", - .fnPtr = reinterpret_cast(&shell::SetViewportMetrics), - }, - { - .name = "nativeDispatchPointerDataPacket", - .signature = "(JLjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast(&shell::DispatchPointerDataPacket), - }, - { - .name = "nativeDispatchSemanticsAction", - .signature = "(JIILjava/nio/ByteBuffer;I)V", - .fnPtr = reinterpret_cast(&shell::DispatchSemanticsAction), - }, - { - .name = "nativeSetSemanticsEnabled", - .signature = "(JZ)V", - .fnPtr = reinterpret_cast(&shell::SetSemanticsEnabled), - }, - { - .name = "nativeSetAccessibilityFeatures", - .signature = "(JI)V", - .fnPtr = reinterpret_cast(&shell::SetAccessibilityFeatures), - }, - { - .name = "nativeGetIsSoftwareRenderingEnabled", - .signature = "()Z", - .fnPtr = reinterpret_cast(&shell::GetIsSoftwareRendering), - }, - { - .name = "nativeRegisterTexture", - .signature = "(JJLandroid/graphics/SurfaceTexture;)V", - .fnPtr = reinterpret_cast(&shell::RegisterTexture), - }, - { - .name = "nativeMarkTextureFrameAvailable", - .signature = "(JJ)V", - .fnPtr = reinterpret_cast(&shell::MarkTextureFrameAvailable), - }, - { - .name = "nativeUnregisterTexture", - .signature = "(JJ)V", - .fnPtr = reinterpret_cast(&shell::UnregisterTexture), - }, + // Start of methods from FlutterNativeView + { + .name = "nativeAttach", + .signature = "(Lio/flutter/embedding/FlutterEngine;Z)J", + .fnPtr = reinterpret_cast(&shell::AttachJNI), + }, + { + .name = "nativeDetach", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::DetachJNI), + }, + { + .name = "nativeDestroy", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::DestroyJNI), + }, + { + .name = "nativeRunBundleAndSnapshotFromLibrary", + .signature = + "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;" + "Ljava/lang/String;Landroid/content/res/AssetManager;)V", + .fnPtr = + reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), + }, + { + .name = "nativeGetObservatoryUri", + .signature = "()Ljava/lang/String;", + .fnPtr = reinterpret_cast(&shell::GetObservatoryUri), + }, + { + .name = "nativeDispatchEmptyPlatformMessage", + .signature = "(JLjava/lang/String;I)V", + .fnPtr = + reinterpret_cast(&shell::DispatchEmptyPlatformMessage), + }, + { + .name = "nativeDispatchPlatformMessage", + .signature = "(JLjava/lang/String;Ljava/nio/ByteBuffer;II)V", + .fnPtr = reinterpret_cast(&shell::DispatchPlatformMessage), + }, + { + .name = "nativeInvokePlatformMessageResponseCallback", + .signature = "(JILjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast( + &shell::InvokePlatformMessageResponseCallback), + }, + { + .name = "nativeInvokePlatformMessageEmptyResponseCallback", + .signature = "(JI)V", + .fnPtr = reinterpret_cast( + &shell::InvokePlatformMessageEmptyResponseCallback), + }, + + // Start of methods from FlutterView + { + .name = "nativeGetBitmap", + .signature = "(J)Landroid/graphics/Bitmap;", + .fnPtr = reinterpret_cast(&shell::GetBitmap), + }, + { + .name = "nativeSurfaceCreated", + .signature = "(JLandroid/view/Surface;I)V", + .fnPtr = reinterpret_cast(&shell::SurfaceCreated), + }, + { + .name = "nativeSurfaceChanged", + .signature = "(JII)V", + .fnPtr = reinterpret_cast(&shell::SurfaceChanged), + }, + { + .name = "nativeSurfaceDestroyed", + .signature = "(J)V", + .fnPtr = reinterpret_cast(&shell::SurfaceDestroyed), + }, + { + .name = "nativeSetViewportMetrics", + .signature = "(JFIIIIIIIIII)V", + .fnPtr = reinterpret_cast(&shell::SetViewportMetrics), + }, + { + .name = "nativeDispatchPointerDataPacket", + .signature = "(JLjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast(&shell::DispatchPointerDataPacket), + }, + { + .name = "nativeDispatchSemanticsAction", + .signature = "(JIILjava/nio/ByteBuffer;I)V", + .fnPtr = reinterpret_cast(&shell::DispatchSemanticsAction), + }, + { + .name = "nativeSetSemanticsEnabled", + .signature = "(JZ)V", + .fnPtr = reinterpret_cast(&shell::SetSemanticsEnabled), + }, + { + .name = "nativeSetAccessibilityFeatures", + .signature = "(JI)V", + .fnPtr = reinterpret_cast(&shell::SetAccessibilityFeatures), + }, + { + .name = "nativeGetIsSoftwareRenderingEnabled", + .signature = "()Z", + .fnPtr = reinterpret_cast(&shell::GetIsSoftwareRendering), + }, + { + .name = "nativeRegisterTexture", + .signature = "(JJLandroid/graphics/SurfaceTexture;)V", + .fnPtr = reinterpret_cast(&shell::RegisterTexture), + }, + { + .name = "nativeMarkTextureFrameAvailable", + .signature = "(JJ)V", + .fnPtr = reinterpret_cast(&shell::MarkTextureFrameAvailable), + }, + { + .name = "nativeUnregisterTexture", + .signature = "(JJ)V", + .fnPtr = reinterpret_cast(&shell::UnregisterTexture), + }, }; - if (env->RegisterNatives(g_flutter_jni_class->obj(), - flutter_jni_methods, - arraysize(flutter_jni_methods)) != 0) { + if (env->RegisterNatives(g_flutter_jni_class->obj(), flutter_jni_methods, + arraysize(flutter_jni_methods)) != 0) { FML_LOG(ERROR) << "Failed to RegisterNatives with FlutterJNI"; return false; } g_handle_platform_message_method = - env->GetMethodID(g_flutter_engine_class->obj(), - "handlePlatformMessage", "(Ljava/lang/String;[BI)V"); + env->GetMethodID(g_flutter_engine_class->obj(), "handlePlatformMessage", + "(Ljava/lang/String;[BI)V"); if (g_handle_platform_message_method == nullptr) { FML_LOG(ERROR) << "Could not locate handlePlatformMessage method"; return false; } - g_handle_platform_message_response_method = - env->GetMethodID(g_flutter_engine_class->obj(), - "handlePlatformMessageResponse", "(I[B)V"); + g_handle_platform_message_response_method = env->GetMethodID( + g_flutter_engine_class->obj(), "handlePlatformMessageResponse", "(I[B)V"); if (g_handle_platform_message_response_method == nullptr) { FML_LOG(ERROR) << "Could not locate handlePlatformMessageResponse method"; @@ -949,20 +954,21 @@ bool RegisterNewApi(JNIEnv* env) { "(Ljava/nio/ByteBuffer;[Ljava/lang/String;)V"); if (g_update_custom_accessibility_actions_method == nullptr) { - FML_LOG(ERROR) << "Could not locate updateCustomAccessibilityActions method"; + FML_LOG(ERROR) + << "Could not locate updateCustomAccessibilityActions method"; return false; } - g_on_first_frame_method = env->GetMethodID(g_flutter_engine_class->obj(), - "onFirstFrame", "()V"); + g_on_first_frame_method = + env->GetMethodID(g_flutter_engine_class->obj(), "onFirstFrame", "()V"); if (g_on_first_frame_method == nullptr) { FML_LOG(ERROR) << "Could not locate onFirstFrame method"; return false; } - g_on_engine_restart_method = env->GetMethodID( - g_flutter_engine_class->obj(), "onPreEngineRestart", "()V"); + g_on_engine_restart_method = env->GetMethodID(g_flutter_engine_class->obj(), + "onPreEngineRestart", "()V"); if (g_on_engine_restart_method == nullptr) { FML_LOG(ERROR) << "Could not locate onEngineRestart method"; @@ -994,7 +1000,9 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } - // TODO(mattcarroll): this assumes the use of the new API is based on what we're compiling against but that's not true. Need to support both simultaneously. + // TODO(mattcarroll): this assumes the use of the new API is based on what + // we're compiling against but that's not true. Need to support both + // simultaneously. bool is_using_new_api = false; g_flutter_jni_class = new fml::jni::ScopedJavaGlobalRef( env, env->FindClass("io/flutter/embedding/FlutterJNI")); @@ -1005,7 +1013,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { } g_surface_texture_class = new fml::jni::ScopedJavaGlobalRef( - env, env->FindClass("android/graphics/SurfaceTexture")); + env, env->FindClass("android/graphics/SurfaceTexture")); if (g_surface_texture_class->is_null()) { FML_LOG(ERROR) << "Could not locate SurfaceTexture class"; return false;