From 1be3595cfd32e58a516cdf01f2937e3bc41c55dd Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 28 Jun 2018 16:09:31 -0700 Subject: [PATCH 01/11] Updated background execution implementation for Android --- shell/platform/android/BUILD.gn | 1 + .../platform/android/android_shell_holder.cc | 77 +++++-- shell/platform/android/android_shell_holder.h | 3 +- .../view/FlutterIsolateStartedEvent.java | 6 + .../io/flutter/view/FlutterNativeView.java | 112 +++++---- .../android/io/flutter/view/FlutterView.java | 212 ++++++++---------- .../platform/android/platform_view_android.cc | 37 ++- .../platform/android/platform_view_android.h | 9 + .../android/platform_view_android_jni.cc | 42 +++- .../android/platform_view_android_jni.h | 2 + 10 files changed, 301 insertions(+), 200 deletions(-) create mode 100644 shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 817c1c29250f8..822f2d53558ca 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -132,6 +132,7 @@ java_library("flutter_shell_java") { "io/flutter/util/PathUtils.java", "io/flutter/util/Preconditions.java", "io/flutter/view/AccessibilityBridge.java", + "io/flutter/view/FlutterIsolateStartedEvent.java", "io/flutter/view/FlutterMain.java", "io/flutter/view/FlutterNativeView.java", "io/flutter/view/FlutterView.java", diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 248949535d06f..47f95dfde3a53 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -23,7 +23,8 @@ namespace shell { AndroidShellHolder::AndroidShellHolder( blink::Settings settings, - fml::jni::JavaObjectWeakGlobalRef java_object) + fml::jni::JavaObjectWeakGlobalRef java_object, + bool is_background_view) : settings_(std::move(settings)), java_object_(java_object) { static size_t shell_count = 1; auto thread_label = std::to_string(shell_count++); @@ -31,26 +32,42 @@ AndroidShellHolder::AndroidShellHolder( FXL_CHECK(pthread_key_create(&thread_destruct_key_, ThreadDestructCallback) == 0); - thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU | - ThreadHost::Type::IO}; + if (is_background_view) { + thread_host_ = {thread_label, ThreadHost::Type::UI}; + } else { + thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU | + ThreadHost::Type::IO}; + } // Detach from JNI when the UI and GPU threads exit. auto jni_exit_task([key = thread_destruct_key_]() { FXL_CHECK(pthread_setspecific(key, reinterpret_cast(1)) == 0); }); thread_host_.ui_thread->GetTaskRunner()->PostTask(jni_exit_task); - thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task); + if (!is_background_view) { + thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task); + } fml::WeakPtr weak_platform_view; Shell::CreateCallback on_create_platform_view = - [java_object, &weak_platform_view](Shell& shell) { - auto platform_view_android = std::make_unique( - shell, // delegate - shell.GetTaskRunners(), // task runners - java_object, // java object handle for JNI interop - shell.GetSettings() - .enable_software_rendering // use software rendering - ); + [is_background_view, java_object, &weak_platform_view](Shell& shell) { + std::unique_ptr platform_view_android; + if (is_background_view) { + platform_view_android = std::make_unique( + shell, // delegate + shell.GetTaskRunners(), // task runners + java_object // java object handle for JNI interop + ); + + } else { + platform_view_android = std::make_unique( + shell, // delegate + shell.GetTaskRunners(), // task runners + java_object, // java object handle for JNI interop + shell.GetSettings() + .enable_software_rendering // use software rendering + ); + } weak_platform_view = platform_view_android->GetWeakPtr(); return platform_view_android; }; @@ -62,13 +79,25 @@ AndroidShellHolder::AndroidShellHolder( // The current thread will be used as the platform thread. Ensure that the // message loop is initialized. fml::MessageLoop::EnsureInitializedForCurrentThread(); - + fxl::RefPtr gpu_runner; + fxl::RefPtr ui_runner; + fxl::RefPtr io_runner; + if (!is_background_view) { + gpu_runner = thread_host_.gpu_thread->GetTaskRunner(); + ui_runner = thread_host_.ui_thread->GetTaskRunner(); + io_runner = thread_host_.io_thread->GetTaskRunner(); + } else { + auto single_task_runner = thread_host_.ui_thread->GetTaskRunner(); + gpu_runner = single_task_runner; + ui_runner = single_task_runner; + io_runner = single_task_runner; + } blink::TaskRunners task_runners( thread_label, // label fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform - thread_host_.gpu_thread->GetTaskRunner(), // gpu - thread_host_.ui_thread->GetTaskRunner(), // ui - thread_host_.io_thread->GetTaskRunner() // io + gpu_runner, // gpu + ui_runner, // ui + io_runner // io ); shell_ = @@ -129,13 +158,19 @@ void AndroidShellHolder::Launch(RunConfiguration config) { shell_->GetTaskRunners().GetUITaskRunner()->PostTask( fxl::MakeCopyable([engine = shell_->GetEngine(), // - config = std::move(config) // + config = std::move(config), // + view = platform_view_.get() // ]() mutable { - if (engine) { - if (!engine->Run(std::move(config))) { - FXL_LOG(ERROR) << "Could not launch engine in configuration."; - } + bool success = false; + FXL_LOG(INFO) << "Attempting to launch engine configuration..."; + if (!engine || !engine->Run(std::move(config))) { + FXL_LOG(ERROR) << "Could not launch engine in configuration."; + } else { + FXL_LOG(INFO) << "Isolate for engine configuration successfully " + "started and run."; + success = true; } + view->InvokeOnStartedCallback(success); })); } diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index 0163d4bbdc1d0..f16afc5b5b0af 100644 --- a/shell/platform/android/android_shell_holder.h +++ b/shell/platform/android/android_shell_holder.h @@ -21,7 +21,8 @@ namespace shell { class AndroidShellHolder { public: AndroidShellHolder(blink::Settings settings, - fml::jni::JavaObjectWeakGlobalRef java_object); + fml::jni::JavaObjectWeakGlobalRef java_object, + bool is_background_view); ~AndroidShellHolder(); diff --git a/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java b/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java new file mode 100644 index 0000000000000..444124f187cce --- /dev/null +++ b/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java @@ -0,0 +1,6 @@ +package io.flutter.view; + +/** + * + */ +public interface FlutterIsolateStartedEvent { public void onStarted(boolean success); } diff --git a/shell/platform/android/io/flutter/view/FlutterNativeView.java b/shell/platform/android/io/flutter/view/FlutterNativeView.java index 46d8f5cb0d0d7..33c6a1a57bbc0 100644 --- a/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -27,11 +27,16 @@ public class FlutterNativeView implements BinaryMessenger { private FlutterView mFlutterView; private final Context mContext; private boolean applicationIsRunning; + private FlutterIsolateStartedEvent startedEvent; public FlutterNativeView(Context context) { + this(context, false); + } + + public FlutterNativeView(Context context, boolean isBackgroundView) { mContext = context; mPluginRegistry = new FlutterPluginRegistry(this, context); - attach(this); + attach(this, isBackgroundView); assertAttached(); mMessageHandlers = new HashMap<>(); } @@ -68,22 +73,30 @@ public long get() { } public void assertAttached() { - if (!isAttached()) - throw new AssertionError("Platform view is not attached"); + if (!isAttached()) throw new AssertionError("Platform view is not attached"); + } + + public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, + boolean reuseRuntimeController) { + runFromBundle(bundlePath, snapshotOverride, entrypoint, null, reuseRuntimeController, null); } - public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) { + public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, + String libraryUrl, boolean reuseRuntimeController, FlutterIsolateStartedEvent event) { assertAttached(); if (applicationIsRunning) - throw new AssertionError("This Flutter engine instance is already running an application"); - - nativeRunBundleAndSnapshot(mNativePlatformView, bundlePath, snapshotOverride, entrypoint, reuseRuntimeController, mContext.getResources().getAssets()); + throw new AssertionError( + "This Flutter engine instance is already running an application"); + startedEvent = event; + nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePath, snapshotOverride, + entrypoint, libraryUrl, reuseRuntimeController, + mContext.getResources().getAssets()); applicationIsRunning = true; } public boolean isApplicationRunning() { - return applicationIsRunning; + return applicationIsRunning; } public static String getObservatoryUri() { @@ -92,7 +105,7 @@ public static String getObservatoryUri() { @Override public void send(String channel, ByteBuffer message) { - send(channel, message, null); + send(channel, message, null); } @Override @@ -110,8 +123,8 @@ public void send(String channel, ByteBuffer message, BinaryReply callback) { if (message == null) { nativeDispatchEmptyPlatformMessage(mNativePlatformView, channel, replyId); } else { - nativeDispatchPlatformMessage(mNativePlatformView, channel, message, - message.position(), replyId); + nativeDispatchPlatformMessage( + mNativePlatformView, channel, message, message.position(), replyId); } } @@ -124,8 +137,8 @@ public void setMessageHandler(String channel, BinaryMessageHandler handler) { } } - private void attach(FlutterNativeView view) { - mNativePlatformView = nativeAttach(view); + private void attach(FlutterNativeView view, boolean isBackgroundView) { + mNativePlatformView = nativeAttach(view, isBackgroundView); } // Called by native to send us a platform message. @@ -135,27 +148,28 @@ private void handlePlatformMessage(final String channel, byte[] message, final i if (handler != null) { try { final ByteBuffer buffer = (message == null ? null : ByteBuffer.wrap(message)); - handler.onMessage(buffer, - new BinaryReply() { - private final AtomicBoolean done = new AtomicBoolean(false); - @Override - public void reply(ByteBuffer reply) { - if (!isAttached()) { - Log.d(TAG, "handlePlatformMessage replying to a detached view, channel=" + channel); - return; - } - if (done.getAndSet(true)) { - throw new IllegalStateException("Reply already submitted"); - } - if (reply == null) { - nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, - replyId); - } else { - nativeInvokePlatformMessageResponseCallback(mNativePlatformView, - replyId, reply, reply.position()); - } + handler.onMessage(buffer, new BinaryReply() { + private final AtomicBoolean done = new AtomicBoolean(false); + @Override + public void reply(ByteBuffer reply) { + if (!isAttached()) { + Log.d(TAG, + "handlePlatformMessage replying to a detached view, channel=" + + channel); + return; + } + if (done.getAndSet(true)) { + throw new IllegalStateException("Reply already submitted"); + } + if (reply == null) { + nativeInvokePlatformMessageEmptyResponseCallback( + mNativePlatformView, replyId); + } else { + nativeInvokePlatformMessageResponseCallback( + mNativePlatformView, replyId, reply, reply.position()); } - }); + } + }); } catch (Exception ex) { Log.e(TAG, "Uncaught exception in binary message listener", ex); nativeInvokePlatformMessageEmptyResponseCallback(mNativePlatformView, replyId); @@ -179,8 +193,7 @@ private void handlePlatformMessageResponse(int replyId, byte[] reply) { // Called by native to update the semantics/accessibility tree. private void updateSemantics(ByteBuffer buffer, String[] strings) { - if (mFlutterView == null) - return; + if (mFlutterView == null) return; mFlutterView.updateSemantics(buffer, strings); } @@ -193,37 +206,38 @@ private void updateCustomAccessibilityActions(ByteBuffer buffer, String[] string // Called by native to notify first Flutter frame rendered. private void onFirstFrame() { - if (mFlutterView == null) - return; + if (mFlutterView == null) return; mFlutterView.onFirstFrame(); } - private static native long nativeAttach(FlutterNativeView view); + private void onStarted(boolean success) { + if (startedEvent == null) return; + startedEvent.onStarted(success); + } + + private static native long nativeAttach(FlutterNativeView view, boolean isBackgroundView); private static native void nativeDestroy(long nativePlatformViewAndroid); private static native void nativeDetach(long nativePlatformViewAndroid); - private static native void nativeRunBundleAndSnapshot(long nativePlatformViewAndroid, - String bundlePath, - String snapshotOverride, - String entrypoint, - boolean reuseRuntimeController, - AssetManager manager); + private static native void nativeRunBundleAndSnapshotFromLibrary(long nativePlatformViewAndroid, + String bundlePath, String snapshotOverride, String entrypoint, String libraryUrl, + boolean reuseRuntimeController, AssetManager manager); private static native String nativeGetObservatoryUri(); // Send an empty platform message to Dart. - private static native void nativeDispatchEmptyPlatformMessage(long nativePlatformViewAndroid, - String channel, int responseId); + private static native void nativeDispatchEmptyPlatformMessage( + long nativePlatformViewAndroid, String channel, int responseId); // Send a data-carrying platform message to Dart. private static native void nativeDispatchPlatformMessage(long nativePlatformViewAndroid, - String channel, ByteBuffer message, int position, int responseId); + String channel, ByteBuffer message, int position, int responseId); // Send an empty response to a platform message received from Dart. private static native void nativeInvokePlatformMessageEmptyResponseCallback( - long nativePlatformViewAndroid, int responseId); + long nativePlatformViewAndroid, int responseId); // Send a data-carrying response to a platform message received from Dart. private static native void nativeInvokePlatformMessageResponseCallback( - long nativePlatformViewAndroid, int responseId, ByteBuffer message, int position); + long nativePlatformViewAndroid, int responseId, ByteBuffer message, int position); } diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 8974a0bec5e10..49eb6ab1d2688 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -41,9 +41,9 @@ /** * An Android view containing a Flutter app. */ -public class FlutterView extends SurfaceView - implements BinaryMessenger, TextureRegistry, AccessibilityManager.AccessibilityStateChangeListener { - +public class FlutterView + extends SurfaceView implements BinaryMessenger, TextureRegistry, + AccessibilityManager.AccessibilityStateChangeListener { /** * Interface for those objects that maintain and expose a reference to a * {@code FlutterView} (such as a full-screen Flutter activity). @@ -129,7 +129,7 @@ public FlutterView(Context context, AttributeSet attrs, FlutterNativeView native TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT - && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { color = typedValue.data; } // TODO(abarth): Consider letting the developer override this color. @@ -156,29 +156,29 @@ public void surfaceDestroyed(SurfaceHolder holder) { }; getHolder().addCallback(mSurfaceCallback); - mAccessibilityManager = (AccessibilityManager) getContext() - .getSystemService(Context.ACCESSIBILITY_SERVICE); + mAccessibilityManager = + (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mActivityLifecycleListeners = new ArrayList<>(); mFirstFrameListeners = new ArrayList<>(); // Configure the platform plugins and flutter channels. - mFlutterLocalizationChannel = new MethodChannel(this, "flutter/localization", - JSONMethodCodec.INSTANCE); - mFlutterNavigationChannel = new MethodChannel(this, "flutter/navigation", - JSONMethodCodec.INSTANCE); - mFlutterKeyEventChannel = new BasicMessageChannel<>(this, "flutter/keyevent", - JSONMessageCodec.INSTANCE); - mFlutterLifecycleChannel = new BasicMessageChannel<>(this, "flutter/lifecycle", - StringCodec.INSTANCE); - mFlutterSystemChannel = new BasicMessageChannel<>(this, "flutter/system", - JSONMessageCodec.INSTANCE); - mFlutterSettingsChannel = new BasicMessageChannel<>(this, "flutter/settings", - JSONMessageCodec.INSTANCE); + mFlutterLocalizationChannel = + new MethodChannel(this, "flutter/localization", JSONMethodCodec.INSTANCE); + mFlutterNavigationChannel = + new MethodChannel(this, "flutter/navigation", JSONMethodCodec.INSTANCE); + mFlutterKeyEventChannel = + new BasicMessageChannel<>(this, "flutter/keyevent", JSONMessageCodec.INSTANCE); + mFlutterLifecycleChannel = + new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE); + mFlutterSystemChannel = + new BasicMessageChannel<>(this, "flutter/system", JSONMessageCodec.INSTANCE); + mFlutterSettingsChannel = + new BasicMessageChannel<>(this, "flutter/settings", JSONMessageCodec.INSTANCE); PlatformPlugin platformPlugin = new PlatformPlugin(activity); - MethodChannel flutterPlatformChannel = new MethodChannel(this, - "flutter/platform", JSONMethodCodec.INSTANCE); + MethodChannel flutterPlatformChannel = + new MethodChannel(this, "flutter/platform", JSONMethodCodec.INSTANCE); flutterPlatformChannel.setMethodCallHandler(platformPlugin); addActivityLifecycleListener(platformPlugin); mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); @@ -310,15 +310,15 @@ public void popRoute() { } private void setUserSettings() { - Map message = new HashMap<>(); - message.put("textScaleFactor", getResources().getConfiguration().fontScale); - message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext())); - mFlutterSettingsChannel.send(message); + Map message = new HashMap<>(); + message.put("textScaleFactor", getResources().getConfiguration().fontScale); + message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext())); + mFlutterSettingsChannel.send(message); } private void setLocale(Locale locale) { - mFlutterLocalizationChannel.invokeMethod("setLocale", - Arrays.asList(locale.getLanguage(), locale.getCountry())); + mFlutterLocalizationChannel.invokeMethod( + "setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry())); } @Override @@ -333,8 +333,7 @@ float getDevicePixelRatio() { } public FlutterNativeView detach() { - if (!isAttached()) - return null; + if (!isAttached()) return null; if (mDiscoveryReceiver != null) { getContext().unregisterReceiver(mDiscoveryReceiver); } @@ -347,8 +346,7 @@ public FlutterNativeView detach() { } public void destroy() { - if (!isAttached()) - return; + if (!isAttached()) return; if (mDiscoveryReceiver != null) { getContext().unregisterReceiver(mDiscoveryReceiver); @@ -425,8 +423,7 @@ private int getPointerDeviceTypeForToolType(int toolType) { } } - private void addPointerForIndex(MotionEvent event, int pointerIndex, - ByteBuffer packet) { + private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet) { int pointerChange = getPointerChangeForAction(event.getActionMasked()); if (pointerChange == -1) { return; @@ -463,8 +460,8 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, packet.putDouble(1.0); // pressure_max if (pointerKind == kPointerDeviceKindStylus) { - packet - .putDouble(event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance + packet.putDouble( + event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance packet.putDouble(0.0); // distance_max } else { packet.putDouble(0.0); // distance @@ -478,7 +475,7 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, packet.putDouble(0.0); // radius_max packet.putDouble( - event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation + event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation if (pointerKind == kPointerDeviceKindStylus) { packet.putDouble(event.getAxisValue(MotionEvent.AXIS_TILT, pointerIndex)); // tilt @@ -508,17 +505,16 @@ public boolean onTouchEvent(MotionEvent event) { int pointerCount = event.getPointerCount(); - ByteBuffer packet = ByteBuffer - .allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField); + ByteBuffer packet = + ByteBuffer.allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField); packet.order(ByteOrder.LITTLE_ENDIAN); int maskedAction = event.getActionMasked(); // ACTION_UP, ACTION_POINTER_UP, ACTION_DOWN, and ACTION_POINTER_DOWN // only apply to a single pointer, other events apply to all pointers. - if (maskedAction == MotionEvent.ACTION_UP - || maskedAction == MotionEvent.ACTION_POINTER_UP - || maskedAction == MotionEvent.ACTION_DOWN - || maskedAction == MotionEvent.ACTION_POINTER_DOWN) { + if (maskedAction == MotionEvent.ACTION_UP || maskedAction == MotionEvent.ACTION_POINTER_UP + || maskedAction == MotionEvent.ACTION_DOWN + || maskedAction == MotionEvent.ACTION_POINTER_DOWN) { addPointerForIndex(event, event.getActionIndex(), packet); } else { // ACTION_MOVE may not actually mean all pointers have moved @@ -600,16 +596,14 @@ private boolean isAttached() { } void assertAttached() { - if (!isAttached()) - throw new AssertionError("Platform view is not attached"); + if (!isAttached()) throw new AssertionError("Platform view is not attached"); } private void preRun() { resetAccessibilityTree(); } - private void postRun() { - } + private void postRun() {} public void runFromBundle(String bundlePath, String snapshotOverride) { runFromBundle(bundlePath, snapshotOverride, "main", false); @@ -619,7 +613,8 @@ public void runFromBundle(String bundlePath, String snapshotOverride, String ent runFromBundle(bundlePath, snapshotOverride, entrypoint, false); } - public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) { + public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, + boolean reuseRuntimeController) { assertAttached(); preRun(); mNativeView.runFromBundle(bundlePath, snapshotOverride, entrypoint, reuseRuntimeController); @@ -636,68 +631,54 @@ public Bitmap getBitmap() { return nativeGetBitmap(mNativeView.get()); } - private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, - Surface surface, - int backgroundColor); + private static native void nativeSurfaceCreated( + long nativePlatformViewAndroid, Surface surface, int backgroundColor); - private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, - int width, - int height); + private static native void nativeSurfaceChanged( + long nativePlatformViewAndroid, int width, int height); private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid); private static native void nativeSetViewportMetrics(long nativePlatformViewAndroid, - float devicePixelRatio, - int physicalWidth, - int physicalHeight, - int physicalPaddingTop, - int physicalPaddingRight, - int physicalPaddingBottom, - int physicalPaddingLeft, - int physicalViewInsetTop, - int physicalViewInsetRight, - int physicalViewInsetBottom, - int physicalViewInsetLeft); + float devicePixelRatio, int physicalWidth, int physicalHeight, int physicalPaddingTop, + int physicalPaddingRight, int physicalPaddingBottom, int physicalPaddingLeft, + int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom, + int physicalViewInsetLeft); private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid); - private static native void nativeDispatchPointerDataPacket(long nativePlatformViewAndroid, - ByteBuffer buffer, int position); + private static native void nativeDispatchPointerDataPacket( + long nativePlatformViewAndroid, ByteBuffer buffer, int position); - private static native void nativeDispatchSemanticsAction(long nativePlatformViewAndroid, int id, - int action, ByteBuffer args, int argsPosition); + private static native void nativeDispatchSemanticsAction( + long nativePlatformViewAndroid, int id, int action, ByteBuffer args, int argsPosition); - private static native void nativeSetSemanticsEnabled(long nativePlatformViewAndroid, - boolean enabled); + private static native void nativeSetSemanticsEnabled( + long nativePlatformViewAndroid, boolean enabled); private static native boolean nativeGetIsSoftwareRenderingEnabled(); - private static native void nativeRegisterTexture(long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture); + private static native void nativeRegisterTexture( + long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture); - private static native void nativeMarkTextureFrameAvailable(long nativePlatformViewAndroid, long textureId); + private static native void nativeMarkTextureFrameAvailable( + long nativePlatformViewAndroid, long textureId); - private static native void nativeUnregisterTexture(long nativePlatformViewAndroid, long textureId); + private static native void nativeUnregisterTexture( + long nativePlatformViewAndroid, long textureId); private void updateViewportMetrics() { - if (!isAttached()) - return; - nativeSetViewportMetrics(mNativeView.get(), - mMetrics.devicePixelRatio, - mMetrics.physicalWidth, - mMetrics.physicalHeight, - mMetrics.physicalPaddingTop, - mMetrics.physicalPaddingRight, - mMetrics.physicalPaddingBottom, - mMetrics.physicalPaddingLeft, - mMetrics.physicalViewInsetTop, - mMetrics.physicalViewInsetRight, - mMetrics.physicalViewInsetBottom, - mMetrics.physicalViewInsetLeft); - - WindowManager wm = (WindowManager) getContext() - .getSystemService(Context.WINDOW_SERVICE); + if (!isAttached()) return; + nativeSetViewportMetrics(mNativeView.get(), mMetrics.devicePixelRatio, + mMetrics.physicalWidth, mMetrics.physicalHeight, mMetrics.physicalPaddingTop, + mMetrics.physicalPaddingRight, mMetrics.physicalPaddingBottom, + mMetrics.physicalPaddingLeft, mMetrics.physicalViewInsetTop, + mMetrics.physicalViewInsetRight, mMetrics.physicalViewInsetBottom, + mMetrics.physicalViewInsetLeft); + + WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); float fps = wm.getDefaultDisplay().getRefreshRate(); - VsyncWaiter.refreshPeriodNanos = (long)(1000000000.0 / fps); + VsyncWaiter.refreshPeriodNanos = (long) (1000000000.0 / fps); } // Called by native to update the semantics/accessibility tree. @@ -743,8 +724,7 @@ protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action } protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action, Object args) { - if (!isAttached()) - return; + if (!isAttached()) return; ByteBuffer encodedArgs = null; int position = 0; if (args != null) { @@ -777,8 +757,8 @@ protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mAccessibilityManager.removeAccessibilityStateChangeListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - mAccessibilityManager - .removeTouchExplorationStateChangeListener(mTouchExplorationListener); + mAccessibilityManager.removeTouchExplorationStateChangeListener( + mTouchExplorationListener); } } @@ -805,8 +785,7 @@ public void onAccessibilityStateChanged(boolean enabled) { } class TouchExplorationListener - implements AccessibilityManager.TouchExplorationStateChangeListener { - + implements AccessibilityManager.TouchExplorationStateChangeListener { @Override public void onTouchExplorationStateChanged(boolean enabled) { if (enabled) { @@ -824,17 +803,16 @@ public void onTouchExplorationStateChanged(boolean enabled) { @Override public AccessibilityNodeProvider getAccessibilityNodeProvider() { - if (mAccessibilityEnabled) - return mAccessibilityNodeProvider; - // TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y tree. + if (mAccessibilityEnabled) return mAccessibilityNodeProvider; + // TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y + // tree. return null; } private AccessibilityBridge mAccessibilityNodeProvider; void ensureAccessibilityEnabled() { - if (!isAttached()) - return; + if (!isAttached()) return; mAccessibilityEnabled = true; if (mAccessibilityNodeProvider == null) { mAccessibilityNodeProvider = new AccessibilityBridge(this); @@ -853,8 +831,8 @@ private boolean handleAccessibilityHoverEvent(MotionEvent event) { if (!mTouchExplorationEnabled) { return false; } - if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER || - event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { + if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER + || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { mAccessibilityNodeProvider.handleTouchExploration(event.getX(), event.getY()); } else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) { mAccessibilityNodeProvider.handleTouchExplorationExit(); @@ -892,7 +870,6 @@ public void setMessageHandler(String channel, BinaryMessageHandler handler) { * and the tool scrapes the log lines for the data. */ private class DiscoveryReceiver extends BroadcastReceiver { - @Override public void onReceive(Context context, Intent intent) { URI observatoryUri = URI.create(FlutterNativeView.getObservatoryUri()); @@ -900,7 +877,8 @@ public void onReceive(Context context, Intent intent) { try { discover.put("id", getContext().getPackageName()); discover.put("observatoryPort", observatoryUri.getPort()); - Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See android_device.dart. + Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See + // android_device.dart. } catch (JSONException e) { } } @@ -909,16 +887,14 @@ public void onReceive(Context context, Intent intent) { /** * Listener will be called on the Android UI thread once when Flutter renders the first frame. */ - public interface FirstFrameListener { - void onFirstFrame(); - } + public interface FirstFrameListener { void onFirstFrame(); } @Override public TextureRegistry.SurfaceTextureEntry createSurfaceTexture() { final SurfaceTexture surfaceTexture = new SurfaceTexture(0); surfaceTexture.detachFromGLContext(); - final SurfaceTextureRegistryEntry entry = new SurfaceTextureRegistryEntry( - nextTextureId.getAndIncrement(), surfaceTexture); + final SurfaceTextureRegistryEntry entry = + new SurfaceTextureRegistryEntry(nextTextureId.getAndIncrement(), surfaceTexture); nativeRegisterTexture(mNativeView.get(), entry.id(), surfaceTexture); return entry; } @@ -931,17 +907,19 @@ final class SurfaceTextureRegistryEntry implements TextureRegistry.SurfaceTextur SurfaceTextureRegistryEntry(long id, SurfaceTexture surfaceTexture) { this.id = id; this.surfaceTexture = surfaceTexture; - this.surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { - @Override - public void onFrameAvailable(SurfaceTexture texture) { - nativeMarkTextureFrameAvailable(mNativeView.get(), SurfaceTextureRegistryEntry.this.id); - } - }); + this.surfaceTexture.setOnFrameAvailableListener( + new SurfaceTexture.OnFrameAvailableListener() { + @Override + public void onFrameAvailable(SurfaceTexture texture) { + nativeMarkTextureFrameAvailable( + mNativeView.get(), SurfaceTextureRegistryEntry.this.id); + } + }); } @Override public SurfaceTexture surfaceTexture() { - return surfaceTexture; + return surfaceTexture; } @Override diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index 422358da27fcb..27fbbdeeec943 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -30,21 +30,36 @@ PlatformViewAndroid::PlatformViewAndroid( "rendering."; } +PlatformViewAndroid::PlatformViewAndroid( + PlatformView::Delegate& delegate, + blink::TaskRunners task_runners, + fml::jni::JavaObjectWeakGlobalRef java_object) + : PlatformView(delegate, std::move(task_runners)), + java_object_(java_object), + android_surface_(nullptr) {} + PlatformViewAndroid::~PlatformViewAndroid() = default; void PlatformViewAndroid::NotifyCreated( fxl::RefPtr native_window) { - InstallFirstFrameCallback(); - android_surface_->SetNativeWindow(native_window); + if (android_surface_) { + InstallFirstFrameCallback(); + android_surface_->SetNativeWindow(native_window); + } PlatformView::NotifyCreated(); } void PlatformViewAndroid::NotifyDestroyed() { PlatformView::NotifyDestroyed(); - android_surface_->TeardownOnScreenContext(); + if (android_surface_) { + android_surface_->TeardownOnScreenContext(); + } } void PlatformViewAndroid::NotifyChanged(const SkISize& size) { + if (!android_surface_) { + return; + } fxl::AutoResetWaitableEvent latch; fml::TaskRunner::RunNowOrPostTask( task_runners_.GetGPUTaskRunner(), // @@ -123,6 +138,16 @@ void PlatformViewAndroid::InvokePlatformMessageEmptyResponseCallback( message_response->CompleteEmpty(); } +void PlatformViewAndroid::InvokeOnStartedCallback(bool success) { + JNIEnv* env = fml::jni::AttachCurrentThread(); + fml::jni::ScopedJavaLocalRef view = java_object_.get(env); + if (view.is_null()) { + // The Java object died. + return; + } + FlutterViewOnStarted(fml::jni::AttachCurrentThread(), view.obj(), success); +} + // |shell::PlatformView| void PlatformViewAndroid::HandlePlatformMessage( fxl::RefPtr message) { @@ -318,11 +343,17 @@ std::unique_ptr PlatformViewAndroid::CreateVSyncWaiter() { // |shell::PlatformView| std::unique_ptr PlatformViewAndroid::CreateRenderingSurface() { + if (!android_surface_) { + return nullptr; + } return android_surface_->CreateGPUSurface(); } // |shell::PlatformView| sk_sp PlatformViewAndroid::CreateResourceContext() const { + if (!android_surface_) { + return nullptr; + } sk_sp resource_context; if (android_surface_->ResourceContextMakeCurrent()) { // TODO(chinmaygarde): Currently, this code depends on the fact that only diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h index b93a9834f3a25..4b17a68d01324 100644 --- a/shell/platform/android/platform_view_android.h +++ b/shell/platform/android/platform_view_android.h @@ -24,6 +24,13 @@ class PlatformViewAndroid final : public PlatformView { public: static bool Register(JNIEnv* env); + // Creates a PlatformViewAndroid with no rendering surface for use with + // background execution. + PlatformViewAndroid(PlatformView::Delegate& delegate, + blink::TaskRunners task_runners, + fml::jni::JavaObjectWeakGlobalRef java_object); + + // Creates a PlatformViewAndroid with a rendering surface. PlatformViewAndroid(PlatformView::Delegate& delegate, blink::TaskRunners task_runners, fml::jni::JavaObjectWeakGlobalRef java_object, @@ -56,6 +63,8 @@ class PlatformViewAndroid final : public PlatformView { void InvokePlatformMessageEmptyResponseCallback(JNIEnv* env, jint response_id); + void InvokeOnStartedCallback(bool success); + void DispatchSemanticsAction(JNIEnv* env, jint id, jint action, diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 0fe2af1c5058e..5b378de805a06 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -95,6 +95,12 @@ void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj) { FXL_CHECK(CheckException(env)); } +static jmethodID g_on_started_method = nullptr; +void FlutterViewOnStarted(JNIEnv* env, jobject obj, jboolean success) { + env->CallVoidMethod(obj, g_on_started_method, success); + FXL_CHECK(CheckException(env)); +} + static jmethodID g_attach_to_gl_context_method = nullptr; void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId) { env->CallVoidMethod(obj, g_attach_to_gl_context_method, textureId); @@ -123,10 +129,13 @@ void SurfaceTextureDetachFromGLContext(JNIEnv* env, jobject obj) { // Called By Java -static jlong Attach(JNIEnv* env, jclass clazz, jobject flutterView) { +static jlong Attach(JNIEnv* env, + jclass clazz, + jobject flutterView, + jboolean is_background_view) { fml::jni::JavaObjectWeakGlobalRef java_object(env, flutterView); auto shell_holder = std::make_unique( - FlutterMain::Get().GetSettings(), java_object); + FlutterMain::Get().GetSettings(), java_object, is_background_view); if (shell_holder->IsValid()) { return reinterpret_cast(shell_holder.release()); } else { @@ -202,13 +211,14 @@ std::unique_ptr CreateIsolateConfiguration( return nullptr; } -static void RunBundleAndSnapshot( +static void RunBundleAndSnapshotFromLibrary( JNIEnv* env, jobject jcaller, jlong shell_holder, jstring jbundlepath, jstring /* snapshot override (unused) */, jstring jEntrypoint, + jstring jLibraryUrl, jboolean /* reuse runtime controller (unused) */, jobject jAssetManager) { auto asset_manager = fml::MakeRefCounted(); @@ -255,7 +265,12 @@ static void RunBundleAndSnapshot( { auto entrypoint = fml::jni::JavaStringToString(env, jEntrypoint); - if (entrypoint.size() > 0) { + auto libraryUrl = fml::jni::JavaStringToString(env, jLibraryUrl); + + if ((entrypoint.size() > 0) && (libraryUrl.size() > 0)) { + config.SetEntrypointAndLibrary(std::move(entrypoint), + std::move(libraryUrl)); + } else if (entrypoint.size() > 0) { config.SetEntrypoint(std::move(entrypoint)); } } @@ -510,7 +525,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { static const JNINativeMethod native_view_methods[] = { { .name = "nativeAttach", - .signature = "(Lio/flutter/view/FlutterNativeView;)J", + .signature = "(Lio/flutter/view/FlutterNativeView;Z)J", .fnPtr = reinterpret_cast(&shell::Attach), }, { @@ -519,10 +534,12 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { .fnPtr = reinterpret_cast(&shell::Destroy), }, { - .name = "nativeRunBundleAndSnapshot", - .signature = "(JLjava/lang/String;Ljava/lang/String;Ljava/lang/" - "String;ZLandroid/content/res/AssetManager;)V", - .fnPtr = reinterpret_cast(&shell::RunBundleAndSnapshot), + .name = "nativeRunBundleAndSnapshotFromLibrary", + .signature = "(JLjava/lang/String;Ljava/lang/String;" + "Ljava/lang/String;Ljava/lang/String;" + "ZLandroid/content/res/AssetManager;)V", + .fnPtr = + reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), }, { .name = "nativeDetach", @@ -672,6 +689,13 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } + g_on_started_method = + env->GetMethodID(g_flutter_native_view_class->obj(), "onStarted", "(Z)V"); + + if (g_on_started_method == nullptr) { + return false; + } + g_attach_to_gl_context_method = env->GetMethodID( g_surface_texture_class->obj(), "attachToGLContext", "(I)V"); diff --git a/shell/platform/android/platform_view_android_jni.h b/shell/platform/android/platform_view_android_jni.h index 1a03d1303a7ec..bec5959be25ca 100644 --- a/shell/platform/android/platform_view_android_jni.h +++ b/shell/platform/android/platform_view_android_jni.h @@ -34,6 +34,8 @@ void FlutterViewUpdateCustomAccessibilityActions(JNIEnv* env, void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj); +void FlutterViewOnStarted(JNIEnv* env, jobject obj, jboolean success); + void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId); void SurfaceTextureUpdateTexImage(JNIEnv* env, jobject obj); From ca823d915299fa57badd45e1fea5232d081b2bc2 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 29 Jun 2018 10:30:13 -0700 Subject: [PATCH 02/11] Reverted formatting on FlutterView.java --- .../android/io/flutter/view/FlutterView.java | 212 ++++++++++-------- 1 file changed, 117 insertions(+), 95 deletions(-) diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 49eb6ab1d2688..8974a0bec5e10 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -41,9 +41,9 @@ /** * An Android view containing a Flutter app. */ -public class FlutterView - extends SurfaceView implements BinaryMessenger, TextureRegistry, - AccessibilityManager.AccessibilityStateChangeListener { +public class FlutterView extends SurfaceView + implements BinaryMessenger, TextureRegistry, AccessibilityManager.AccessibilityStateChangeListener { + /** * Interface for those objects that maintain and expose a reference to a * {@code FlutterView} (such as a full-screen Flutter activity). @@ -129,7 +129,7 @@ public FlutterView(Context context, AttributeSet attrs, FlutterNativeView native TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true); if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT - && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { color = typedValue.data; } // TODO(abarth): Consider letting the developer override this color. @@ -156,29 +156,29 @@ public void surfaceDestroyed(SurfaceHolder holder) { }; getHolder().addCallback(mSurfaceCallback); - mAccessibilityManager = - (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); + mAccessibilityManager = (AccessibilityManager) getContext() + .getSystemService(Context.ACCESSIBILITY_SERVICE); mActivityLifecycleListeners = new ArrayList<>(); mFirstFrameListeners = new ArrayList<>(); // Configure the platform plugins and flutter channels. - mFlutterLocalizationChannel = - new MethodChannel(this, "flutter/localization", JSONMethodCodec.INSTANCE); - mFlutterNavigationChannel = - new MethodChannel(this, "flutter/navigation", JSONMethodCodec.INSTANCE); - mFlutterKeyEventChannel = - new BasicMessageChannel<>(this, "flutter/keyevent", JSONMessageCodec.INSTANCE); - mFlutterLifecycleChannel = - new BasicMessageChannel<>(this, "flutter/lifecycle", StringCodec.INSTANCE); - mFlutterSystemChannel = - new BasicMessageChannel<>(this, "flutter/system", JSONMessageCodec.INSTANCE); - mFlutterSettingsChannel = - new BasicMessageChannel<>(this, "flutter/settings", JSONMessageCodec.INSTANCE); + mFlutterLocalizationChannel = new MethodChannel(this, "flutter/localization", + JSONMethodCodec.INSTANCE); + mFlutterNavigationChannel = new MethodChannel(this, "flutter/navigation", + JSONMethodCodec.INSTANCE); + mFlutterKeyEventChannel = new BasicMessageChannel<>(this, "flutter/keyevent", + JSONMessageCodec.INSTANCE); + mFlutterLifecycleChannel = new BasicMessageChannel<>(this, "flutter/lifecycle", + StringCodec.INSTANCE); + mFlutterSystemChannel = new BasicMessageChannel<>(this, "flutter/system", + JSONMessageCodec.INSTANCE); + mFlutterSettingsChannel = new BasicMessageChannel<>(this, "flutter/settings", + JSONMessageCodec.INSTANCE); PlatformPlugin platformPlugin = new PlatformPlugin(activity); - MethodChannel flutterPlatformChannel = - new MethodChannel(this, "flutter/platform", JSONMethodCodec.INSTANCE); + MethodChannel flutterPlatformChannel = new MethodChannel(this, + "flutter/platform", JSONMethodCodec.INSTANCE); flutterPlatformChannel.setMethodCallHandler(platformPlugin); addActivityLifecycleListener(platformPlugin); mImm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); @@ -310,15 +310,15 @@ public void popRoute() { } private void setUserSettings() { - Map message = new HashMap<>(); - message.put("textScaleFactor", getResources().getConfiguration().fontScale); - message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext())); - mFlutterSettingsChannel.send(message); + Map message = new HashMap<>(); + message.put("textScaleFactor", getResources().getConfiguration().fontScale); + message.put("alwaysUse24HourFormat", DateFormat.is24HourFormat(getContext())); + mFlutterSettingsChannel.send(message); } private void setLocale(Locale locale) { - mFlutterLocalizationChannel.invokeMethod( - "setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry())); + mFlutterLocalizationChannel.invokeMethod("setLocale", + Arrays.asList(locale.getLanguage(), locale.getCountry())); } @Override @@ -333,7 +333,8 @@ float getDevicePixelRatio() { } public FlutterNativeView detach() { - if (!isAttached()) return null; + if (!isAttached()) + return null; if (mDiscoveryReceiver != null) { getContext().unregisterReceiver(mDiscoveryReceiver); } @@ -346,7 +347,8 @@ public FlutterNativeView detach() { } public void destroy() { - if (!isAttached()) return; + if (!isAttached()) + return; if (mDiscoveryReceiver != null) { getContext().unregisterReceiver(mDiscoveryReceiver); @@ -423,7 +425,8 @@ private int getPointerDeviceTypeForToolType(int toolType) { } } - private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet) { + private void addPointerForIndex(MotionEvent event, int pointerIndex, + ByteBuffer packet) { int pointerChange = getPointerChangeForAction(event.getActionMasked()); if (pointerChange == -1) { return; @@ -460,8 +463,8 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet.putDouble(1.0); // pressure_max if (pointerKind == kPointerDeviceKindStylus) { - packet.putDouble( - event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance + packet + .putDouble(event.getAxisValue(MotionEvent.AXIS_DISTANCE, pointerIndex)); // distance packet.putDouble(0.0); // distance_max } else { packet.putDouble(0.0); // distance @@ -475,7 +478,7 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer packet.putDouble(0.0); // radius_max packet.putDouble( - event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation + event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation if (pointerKind == kPointerDeviceKindStylus) { packet.putDouble(event.getAxisValue(MotionEvent.AXIS_TILT, pointerIndex)); // tilt @@ -505,16 +508,17 @@ public boolean onTouchEvent(MotionEvent event) { int pointerCount = event.getPointerCount(); - ByteBuffer packet = - ByteBuffer.allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField); + ByteBuffer packet = ByteBuffer + .allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField); packet.order(ByteOrder.LITTLE_ENDIAN); int maskedAction = event.getActionMasked(); // ACTION_UP, ACTION_POINTER_UP, ACTION_DOWN, and ACTION_POINTER_DOWN // only apply to a single pointer, other events apply to all pointers. - if (maskedAction == MotionEvent.ACTION_UP || maskedAction == MotionEvent.ACTION_POINTER_UP - || maskedAction == MotionEvent.ACTION_DOWN - || maskedAction == MotionEvent.ACTION_POINTER_DOWN) { + if (maskedAction == MotionEvent.ACTION_UP + || maskedAction == MotionEvent.ACTION_POINTER_UP + || maskedAction == MotionEvent.ACTION_DOWN + || maskedAction == MotionEvent.ACTION_POINTER_DOWN) { addPointerForIndex(event, event.getActionIndex(), packet); } else { // ACTION_MOVE may not actually mean all pointers have moved @@ -596,14 +600,16 @@ private boolean isAttached() { } void assertAttached() { - if (!isAttached()) throw new AssertionError("Platform view is not attached"); + if (!isAttached()) + throw new AssertionError("Platform view is not attached"); } private void preRun() { resetAccessibilityTree(); } - private void postRun() {} + private void postRun() { + } public void runFromBundle(String bundlePath, String snapshotOverride) { runFromBundle(bundlePath, snapshotOverride, "main", false); @@ -613,8 +619,7 @@ public void runFromBundle(String bundlePath, String snapshotOverride, String ent runFromBundle(bundlePath, snapshotOverride, entrypoint, false); } - public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, - boolean reuseRuntimeController) { + public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) { assertAttached(); preRun(); mNativeView.runFromBundle(bundlePath, snapshotOverride, entrypoint, reuseRuntimeController); @@ -631,54 +636,68 @@ public Bitmap getBitmap() { return nativeGetBitmap(mNativeView.get()); } - private static native void nativeSurfaceCreated( - long nativePlatformViewAndroid, Surface surface, int backgroundColor); + private static native void nativeSurfaceCreated(long nativePlatformViewAndroid, + Surface surface, + int backgroundColor); - private static native void nativeSurfaceChanged( - long nativePlatformViewAndroid, int width, int height); + private static native void nativeSurfaceChanged(long nativePlatformViewAndroid, + int width, + int height); private static native void nativeSurfaceDestroyed(long nativePlatformViewAndroid); private static native void nativeSetViewportMetrics(long nativePlatformViewAndroid, - float devicePixelRatio, int physicalWidth, int physicalHeight, int physicalPaddingTop, - int physicalPaddingRight, int physicalPaddingBottom, int physicalPaddingLeft, - int physicalViewInsetTop, int physicalViewInsetRight, int physicalViewInsetBottom, - int physicalViewInsetLeft); + float devicePixelRatio, + int physicalWidth, + int physicalHeight, + int physicalPaddingTop, + int physicalPaddingRight, + int physicalPaddingBottom, + int physicalPaddingLeft, + int physicalViewInsetTop, + int physicalViewInsetRight, + int physicalViewInsetBottom, + int physicalViewInsetLeft); private static native Bitmap nativeGetBitmap(long nativePlatformViewAndroid); - private static native void nativeDispatchPointerDataPacket( - long nativePlatformViewAndroid, ByteBuffer buffer, int position); + private static native void nativeDispatchPointerDataPacket(long nativePlatformViewAndroid, + ByteBuffer buffer, int position); - private static native void nativeDispatchSemanticsAction( - long nativePlatformViewAndroid, int id, int action, ByteBuffer args, int argsPosition); + private static native void nativeDispatchSemanticsAction(long nativePlatformViewAndroid, int id, + int action, ByteBuffer args, int argsPosition); - private static native void nativeSetSemanticsEnabled( - long nativePlatformViewAndroid, boolean enabled); + private static native void nativeSetSemanticsEnabled(long nativePlatformViewAndroid, + boolean enabled); private static native boolean nativeGetIsSoftwareRenderingEnabled(); - private static native void nativeRegisterTexture( - long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture); + private static native void nativeRegisterTexture(long nativePlatformViewAndroid, long textureId, SurfaceTexture surfaceTexture); - private static native void nativeMarkTextureFrameAvailable( - long nativePlatformViewAndroid, long textureId); + private static native void nativeMarkTextureFrameAvailable(long nativePlatformViewAndroid, long textureId); - private static native void nativeUnregisterTexture( - long nativePlatformViewAndroid, long textureId); + private static native void nativeUnregisterTexture(long nativePlatformViewAndroid, long textureId); private void updateViewportMetrics() { - if (!isAttached()) return; - nativeSetViewportMetrics(mNativeView.get(), mMetrics.devicePixelRatio, - mMetrics.physicalWidth, mMetrics.physicalHeight, mMetrics.physicalPaddingTop, - mMetrics.physicalPaddingRight, mMetrics.physicalPaddingBottom, - mMetrics.physicalPaddingLeft, mMetrics.physicalViewInsetTop, - mMetrics.physicalViewInsetRight, mMetrics.physicalViewInsetBottom, - mMetrics.physicalViewInsetLeft); - - WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); + if (!isAttached()) + return; + nativeSetViewportMetrics(mNativeView.get(), + mMetrics.devicePixelRatio, + mMetrics.physicalWidth, + mMetrics.physicalHeight, + mMetrics.physicalPaddingTop, + mMetrics.physicalPaddingRight, + mMetrics.physicalPaddingBottom, + mMetrics.physicalPaddingLeft, + mMetrics.physicalViewInsetTop, + mMetrics.physicalViewInsetRight, + mMetrics.physicalViewInsetBottom, + mMetrics.physicalViewInsetLeft); + + WindowManager wm = (WindowManager) getContext() + .getSystemService(Context.WINDOW_SERVICE); float fps = wm.getDefaultDisplay().getRefreshRate(); - VsyncWaiter.refreshPeriodNanos = (long) (1000000000.0 / fps); + VsyncWaiter.refreshPeriodNanos = (long)(1000000000.0 / fps); } // Called by native to update the semantics/accessibility tree. @@ -724,7 +743,8 @@ protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action } protected void dispatchSemanticsAction(int id, AccessibilityBridge.Action action, Object args) { - if (!isAttached()) return; + if (!isAttached()) + return; ByteBuffer encodedArgs = null; int position = 0; if (args != null) { @@ -757,8 +777,8 @@ protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mAccessibilityManager.removeAccessibilityStateChangeListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - mAccessibilityManager.removeTouchExplorationStateChangeListener( - mTouchExplorationListener); + mAccessibilityManager + .removeTouchExplorationStateChangeListener(mTouchExplorationListener); } } @@ -785,7 +805,8 @@ public void onAccessibilityStateChanged(boolean enabled) { } class TouchExplorationListener - implements AccessibilityManager.TouchExplorationStateChangeListener { + implements AccessibilityManager.TouchExplorationStateChangeListener { + @Override public void onTouchExplorationStateChanged(boolean enabled) { if (enabled) { @@ -803,16 +824,17 @@ public void onTouchExplorationStateChanged(boolean enabled) { @Override public AccessibilityNodeProvider getAccessibilityNodeProvider() { - if (mAccessibilityEnabled) return mAccessibilityNodeProvider; - // TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y - // tree. + if (mAccessibilityEnabled) + return mAccessibilityNodeProvider; + // TODO(goderbauer): when a11y is off this should return a one-off snapshot of the a11y tree. return null; } private AccessibilityBridge mAccessibilityNodeProvider; void ensureAccessibilityEnabled() { - if (!isAttached()) return; + if (!isAttached()) + return; mAccessibilityEnabled = true; if (mAccessibilityNodeProvider == null) { mAccessibilityNodeProvider = new AccessibilityBridge(this); @@ -831,8 +853,8 @@ private boolean handleAccessibilityHoverEvent(MotionEvent event) { if (!mTouchExplorationEnabled) { return false; } - if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER - || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { + if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER || + event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { mAccessibilityNodeProvider.handleTouchExploration(event.getX(), event.getY()); } else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) { mAccessibilityNodeProvider.handleTouchExplorationExit(); @@ -870,6 +892,7 @@ public void setMessageHandler(String channel, BinaryMessageHandler handler) { * and the tool scrapes the log lines for the data. */ private class DiscoveryReceiver extends BroadcastReceiver { + @Override public void onReceive(Context context, Intent intent) { URI observatoryUri = URI.create(FlutterNativeView.getObservatoryUri()); @@ -877,8 +900,7 @@ public void onReceive(Context context, Intent intent) { try { discover.put("id", getContext().getPackageName()); discover.put("observatoryPort", observatoryUri.getPort()); - Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See - // android_device.dart. + Log.i(TAG, "DISCOVER: " + discover); // The tool looks for this data. See android_device.dart. } catch (JSONException e) { } } @@ -887,14 +909,16 @@ public void onReceive(Context context, Intent intent) { /** * Listener will be called on the Android UI thread once when Flutter renders the first frame. */ - public interface FirstFrameListener { void onFirstFrame(); } + public interface FirstFrameListener { + void onFirstFrame(); + } @Override public TextureRegistry.SurfaceTextureEntry createSurfaceTexture() { final SurfaceTexture surfaceTexture = new SurfaceTexture(0); surfaceTexture.detachFromGLContext(); - final SurfaceTextureRegistryEntry entry = - new SurfaceTextureRegistryEntry(nextTextureId.getAndIncrement(), surfaceTexture); + final SurfaceTextureRegistryEntry entry = new SurfaceTextureRegistryEntry( + nextTextureId.getAndIncrement(), surfaceTexture); nativeRegisterTexture(mNativeView.get(), entry.id(), surfaceTexture); return entry; } @@ -907,19 +931,17 @@ final class SurfaceTextureRegistryEntry implements TextureRegistry.SurfaceTextur SurfaceTextureRegistryEntry(long id, SurfaceTexture surfaceTexture) { this.id = id; this.surfaceTexture = surfaceTexture; - this.surfaceTexture.setOnFrameAvailableListener( - new SurfaceTexture.OnFrameAvailableListener() { - @Override - public void onFrameAvailable(SurfaceTexture texture) { - nativeMarkTextureFrameAvailable( - mNativeView.get(), SurfaceTextureRegistryEntry.this.id); - } - }); + this.surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { + @Override + public void onFrameAvailable(SurfaceTexture texture) { + nativeMarkTextureFrameAvailable(mNativeView.get(), SurfaceTextureRegistryEntry.this.id); + } + }); } @Override public SurfaceTexture surfaceTexture() { - return surfaceTexture; + return surfaceTexture; } @Override From 1e36a0d005fe1ff458ace630b485dd648a376c12 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 13 Jul 2018 10:41:40 -0700 Subject: [PATCH 03/11] Updated to use DartCallbackCache to lookup callbacks --- shell/platform/android/BUILD.gn | 1 + .../view/FlutterCallbackInformation.java | 23 ++++++++ .../android/platform_view_android_jni.cc | 52 +++++++++++++++++++ travis/licenses_golden/licenses_flutter | 2 + 4 files changed, 78 insertions(+) create mode 100644 shell/platform/android/io/flutter/view/FlutterCallbackInformation.java diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 822f2d53558ca..d9e736c919d4f 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -132,6 +132,7 @@ java_library("flutter_shell_java") { "io/flutter/util/PathUtils.java", "io/flutter/util/Preconditions.java", "io/flutter/view/AccessibilityBridge.java", + "io/flutter/view/FlutterCallbackInformation.java", "io/flutter/view/FlutterIsolateStartedEvent.java", "io/flutter/view/FlutterMain.java", "io/flutter/view/FlutterNativeView.java", diff --git a/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java b/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java new file mode 100644 index 0000000000000..ef78a0a35bfeb --- /dev/null +++ b/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java @@ -0,0 +1,23 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.view; + +public final class FlutterCallbackInformation { + final public String callbackName; + final public String callbackClassName; + final public String callbackLibraryPath; + + public static FlutterCallbackInformation lookupCallbackInformation(long handle) { + return nativeLookupCallbackInformation(handle); + } + + private FlutterCallbackInformation(String callbackName, String callbackClassName, String callbackLibraryPath) { + this.callbackName = callbackName; + this.callbackClassName = callbackClassName; + this.callbackLibraryPath = callbackLibraryPath; + } + + private static native FlutterCallbackInformation nativeLookupCallbackInformation(long handle); +} diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 5b378de805a06..7e644573985b3 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -15,6 +15,7 @@ #include "flutter/fml/platform/android/jni_util.h" #include "flutter/fml/platform/android/jni_weak_ref.h" #include "flutter/fml/platform/android/scoped_java_ref.h" +#include "flutter/lib/ui/plugins/callback_cache.h" #include "flutter/runtime/dart_service_isolate.h" #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/platform/android/android_external_texture_gl.h" @@ -43,6 +44,8 @@ bool CheckException(JNIEnv* env) { } // anonymous namespace +static fml::jni::ScopedJavaGlobalRef* g_flutter_callback_info_class = + nullptr; static fml::jni::ScopedJavaGlobalRef* g_flutter_view_class = nullptr; static fml::jni::ScopedJavaGlobalRef* g_flutter_native_view_class = nullptr; @@ -50,6 +53,19 @@ static fml::jni::ScopedJavaGlobalRef* g_surface_texture_class = nullptr; // Called By Native +static jmethodID g_flutter_callback_info_constructor = nullptr; +jobject CreateFlutterCallbackInformation( + JNIEnv* env, + const std::string& callbackName, + const std::string& callbackClassName, + const std::string& callbackLibraryPath) { + return env->NewObject(g_flutter_callback_info_class->obj(), + g_flutter_callback_info_constructor, + env->NewStringUTF(callbackName.c_str()), + env->NewStringUTF(callbackClassName.c_str()), + env->NewStringUTF(callbackLibraryPath.c_str())); +} + static jmethodID g_handle_platform_message_method = nullptr; void FlutterViewHandlePlatformMessage(JNIEnv* env, jobject obj, @@ -278,6 +294,15 @@ static void RunBundleAndSnapshotFromLibrary( ANDROID_SHELL_HOLDER->Launch(std::move(config)); } +static jobject LookupCallbackInformation(JNIEnv* env, jlong handle) { + auto cbInfo = blink::DartCallbackCache::GetCallbackInformation(handle); + if (cbInfo == nullptr) { + return nullptr; + } + return CreateFlutterCallbackInformation(env, cbInfo->name, cbInfo->class_name, + cbInfo->library_path); +} + static void SetViewportMetrics(JNIEnv* env, jobject jcaller, jlong shell_holder, @@ -504,6 +529,19 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } + g_flutter_callback_info_class = new fml::jni::ScopedJavaGlobalRef( + env, env->FindClass("io/flutter/view/FlutterCallbackInformation")); + if (g_flutter_callback_info_class->is_null()) { + return false; + } + + g_flutter_callback_info_constructor = env->GetMethodID( + g_flutter_callback_info_class->obj(), "", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); + if (g_flutter_callback_info_constructor == nullptr) { + return false; + } + g_flutter_view_class = new fml::jni::ScopedJavaGlobalRef( env, env->FindClass("io/flutter/view/FlutterView")); if (g_flutter_view_class->is_null()) { @@ -639,6 +677,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { }, }; + static const JNINativeMethod callback_info_methods[] = { + { + .name = "nativeLookupCallbackInformation", + .signature = "(J)Lio/flutter/view/FlutterCallbackInformation;", + .fnPtr = reinterpret_cast(&shell::LookupCallbackInformation), + }, + }; + if (env->RegisterNatives(g_flutter_native_view_class->obj(), native_view_methods, arraysize(native_view_methods)) != 0) { @@ -650,6 +696,12 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } + if (env->RegisterNatives(g_flutter_callback_info_class->obj(), + callback_info_methods, + arraysize(callback_info_methods)) != 0) { + return false; + } + g_handle_platform_message_method = env->GetMethodID(g_flutter_native_view_class->obj(), "handlePlatformMessage", "(Ljava/lang/String;[BI)V"); diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index 29035a43eb7ae..0aa56709efa76 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -202,6 +202,7 @@ FILE: ../../../flutter/lib/ui/window/window.h FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/JSONUtil.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java FILE: ../../../flutter/shell/platform/darwin/desktop/Info.plist FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec FILE: ../../../flutter/shell/platform/darwin/ios/framework/Info.plist @@ -501,6 +502,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm From 67dc24a5f63aa79f8fd05fdb439875536016aee6 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 16 Jul 2018 10:57:35 -0700 Subject: [PATCH 04/11] Updated runFromBundle to take an args object; deprecated old signatures --- shell/platform/android/BUILD.gn | 1 + .../flutter/app/FlutterActivityDelegate.java | 24 ++++++-------- .../view/FlutterCallbackInformation.java | 13 +++++++- .../view/FlutterIsolateStartedEvent.java | 11 +++++-- .../io/flutter/view/FlutterNativeView.java | 32 +++++++++++++------ .../io/flutter/view/FlutterRunArguments.java | 16 ++++++++++ .../android/io/flutter/view/FlutterView.java | 30 ++++++++++++++--- .../android/platform_view_android_jni.cc | 5 +-- 8 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 shell/platform/android/io/flutter/view/FlutterRunArguments.java diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index d9e736c919d4f..2c3415fe08671 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -136,6 +136,7 @@ java_library("flutter_shell_java") { "io/flutter/view/FlutterIsolateStartedEvent.java", "io/flutter/view/FlutterMain.java", "io/flutter/view/FlutterNativeView.java", + "io/flutter/view/FlutterRunArguments.java", "io/flutter/view/FlutterView.java", "io/flutter/view/ResourceCleaner.java", "io/flutter/view/ResourceExtractor.java", diff --git a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 3d06d7f8505b5..5c5c367723272 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -30,6 +30,7 @@ import io.flutter.util.Preconditions; import io.flutter.view.FlutterMain; import io.flutter.view.FlutterNativeView; +import io.flutter.view.FlutterRunArguments; import io.flutter.view.FlutterView; import java.util.ArrayList; @@ -162,19 +163,16 @@ public void onCreate(Bundle savedInstanceState) { } } - // When an activity is created for the first time, we direct the - // FlutterView to re-use a pre-existing Isolate rather than create a new - // one. This is so that an Isolate coming in from the ViewFactory is - // used. - final boolean reuseIsolate = true; - - if (loadIntent(activity.getIntent(), reuseIsolate)) { + if (loadIntent(activity.getIntent())) { return; } if (!flutterView.getFlutterNativeView().isApplicationRunning()) { String appBundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext()); if (appBundlePath != null) { - flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate); + FlutterRunArguments arguments = new FlutterRunArguments(); + arguments.bundlePath = appBundlePath; + arguments.entrypoint = "main"; + flutterView.runFromBundle(arguments); } } } @@ -325,11 +323,6 @@ private static String[] getArgsFromIntent(Intent intent) { } private boolean loadIntent(Intent intent) { - final boolean reuseIsolate = false; - return loadIntent(intent, reuseIsolate); - } - - private boolean loadIntent(Intent intent, boolean reuseIsolate) { String action = intent.getAction(); if (Intent.ACTION_RUN.equals(action)) { String route = intent.getStringExtra("route"); @@ -343,7 +336,10 @@ private boolean loadIntent(Intent intent, boolean reuseIsolate) { flutterView.setInitialRoute(route); } if (!flutterView.getFlutterNativeView().isApplicationRunning()) { - flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate); + FlutterRunArguments args = new FlutterRunArguments(); + args.bundlePath = appBundlePath; + args.entrypoint = "main"; + flutterView.runFromBundle(args); } return true; } diff --git a/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java b/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java index ef78a0a35bfeb..20006dd60547c 100644 --- a/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java +++ b/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java @@ -4,16 +4,27 @@ package io.flutter.view; +/** + * A class representing information for a callback registered using + * `PluginUtilities` from `dart:ui`. + */ public final class FlutterCallbackInformation { final public String callbackName; final public String callbackClassName; final public String callbackLibraryPath; + /** + * Get callback information for a given handle. + * @param handle the handle for the callback, generated by + * `PluginUtilities.getCallbackHandle` in `dart:ui`. + * @return an instance of FlutterCallbackInformation for the provided handle. + */ public static FlutterCallbackInformation lookupCallbackInformation(long handle) { return nativeLookupCallbackInformation(handle); } - private FlutterCallbackInformation(String callbackName, String callbackClassName, String callbackLibraryPath) { + private FlutterCallbackInformation(String callbackName, + String callbackClassName, String callbackLibraryPath) { this.callbackName = callbackName; this.callbackClassName = callbackClassName; this.callbackLibraryPath = callbackLibraryPath; diff --git a/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java b/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java index 444124f187cce..7e63e204b2dd2 100644 --- a/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java +++ b/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java @@ -1,6 +1,13 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + package io.flutter.view; /** - * + * An interface for a callback which is invoked once a new isolate has been + * started by the engine. */ -public interface FlutterIsolateStartedEvent { public void onStarted(boolean success); } +public interface FlutterIsolateStartedEvent { + public void onStarted(boolean success); +} diff --git a/shell/platform/android/io/flutter/view/FlutterNativeView.java b/shell/platform/android/io/flutter/view/FlutterNativeView.java index 33c6a1a57bbc0..136269a619484 100644 --- a/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -76,21 +76,35 @@ public void assertAttached() { if (!isAttached()) throw new AssertionError("Platform view is not attached"); } + public void runFromBundle(FlutterRunArguments args) { + if (args.bundlePath == null) { + throw new AssertionError("A bundlePath must be specified"); + } else if (args.entrypoint == null) { + throw new AssertionError("An entrypoint must be specified"); + } + runFromBundleInternal(args.bundlePath, args.entrypoint, + args.libraryPath, args.onStartedEvent); + } + + /** + * @deprecated + * Please use runFromBundle with `FlutterRunArguments`. Parameters + * `snapshotOverride` and `reuseRuntimeController` have no effect. + */ public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) { - runFromBundle(bundlePath, snapshotOverride, entrypoint, null, reuseRuntimeController, null); + runFromBundleInternal(bundlePath, entrypoint, null, null); } - public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, - String libraryUrl, boolean reuseRuntimeController, FlutterIsolateStartedEvent event) { + private void runFromBundleInternal(String bundlePath, String entrypoint, + String libraryPath, FlutterIsolateStartedEvent event) { assertAttached(); if (applicationIsRunning) throw new AssertionError( "This Flutter engine instance is already running an application"); startedEvent = event; - nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePath, snapshotOverride, - entrypoint, libraryUrl, reuseRuntimeController, - mContext.getResources().getAssets()); + nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePath, + entrypoint, libraryPath, mContext.getResources().getAssets()); applicationIsRunning = true; } @@ -219,9 +233,9 @@ private void onStarted(boolean success) { private static native void nativeDestroy(long nativePlatformViewAndroid); private static native void nativeDetach(long nativePlatformViewAndroid); - private static native void nativeRunBundleAndSnapshotFromLibrary(long nativePlatformViewAndroid, - String bundlePath, String snapshotOverride, String entrypoint, String libraryUrl, - boolean reuseRuntimeController, AssetManager manager); + private static native void nativeRunBundleAndSnapshotFromLibrary( + long nativePlatformViewAndroid, String bundlePath, + String entrypoint, String libraryUrl, AssetManager manager); private static native String nativeGetObservatoryUri(); diff --git a/shell/platform/android/io/flutter/view/FlutterRunArguments.java b/shell/platform/android/io/flutter/view/FlutterRunArguments.java new file mode 100644 index 0000000000000..043325d0d272a --- /dev/null +++ b/shell/platform/android/io/flutter/view/FlutterRunArguments.java @@ -0,0 +1,16 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.view; + +/** + * A class containing arguments for entering a FlutterNativeView's isolate for + * the first time. + */ +public class FlutterRunArguments { + public String bundlePath; + public String entrypoint; + public String libraryPath; + public FlutterIsolateStartedEvent onStartedEvent; +} diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 8974a0bec5e10..8fe28670c123a 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -611,19 +611,41 @@ private void preRun() { private void postRun() { } + public void runFromBundle(FlutterRunArguments args) { + assertAttached(); + preRun(); + mNativeView.runFromBundle(args); + postRun(); + } + + /** + * @deprecated + * Please use runFromBundle with `FlutterRunArguments`. Parameter + * `snapshotOverride` has no effect. + */ public void runFromBundle(String bundlePath, String snapshotOverride) { runFromBundle(bundlePath, snapshotOverride, "main", false); } + /** + * @deprecated + * Please use runFromBundle with `FlutterRunArguments`. Parameter + * `snapshotOverride` has no effect. + */ public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint) { runFromBundle(bundlePath, snapshotOverride, entrypoint, false); } + /** + * @deprecated + * Please use runFromBundle with `FlutterRunArguments`. Parameters + * `snapshotOverride` and `reuseRuntimeController` have no effect. + */ public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, boolean reuseRuntimeController) { - assertAttached(); - preRun(); - mNativeView.runFromBundle(bundlePath, snapshotOverride, entrypoint, reuseRuntimeController); - postRun(); + FlutterRunArguments args = new FlutterRunArguments(); + args.bundlePath = bundlePath; + args.entrypoint = entrypoint; + runFromBundle(args); } /** diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 7e644573985b3..9f9784207d6e9 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -232,10 +232,8 @@ static void RunBundleAndSnapshotFromLibrary( jobject jcaller, jlong shell_holder, jstring jbundlepath, - jstring /* snapshot override (unused) */, jstring jEntrypoint, jstring jLibraryUrl, - jboolean /* reuse runtime controller (unused) */, jobject jAssetManager) { auto asset_manager = fml::MakeRefCounted(); @@ -574,8 +572,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { { .name = "nativeRunBundleAndSnapshotFromLibrary", .signature = "(JLjava/lang/String;Ljava/lang/String;" - "Ljava/lang/String;Ljava/lang/String;" - "ZLandroid/content/res/AssetManager;)V", + "Ljava/lang/String;Landroid/content/res/AssetManager;)V", .fnPtr = reinterpret_cast(&shell::RunBundleAndSnapshotFromLibrary), }, From 2dab42ac43fb88782ec87b22280e634fe0f8c81a Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 16 Jul 2018 12:03:24 -0700 Subject: [PATCH 05/11] whitespace --- .../platform/android/io/flutter/app/FlutterActivityDelegate.java | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 5c5c367723272..79af68ade633b 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -28,6 +28,7 @@ import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.util.Preconditions; + import io.flutter.view.FlutterMain; import io.flutter.view.FlutterNativeView; import io.flutter.view.FlutterRunArguments; From f02d63a03d1a3d1e0f9556ac539e35ca3d96e1df Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 16 Jul 2018 12:03:35 -0700 Subject: [PATCH 06/11] remove whitespace --- .../platform/android/io/flutter/app/FlutterActivityDelegate.java | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 79af68ade633b..5c5c367723272 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -28,7 +28,6 @@ import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.util.Preconditions; - import io.flutter.view.FlutterMain; import io.flutter.view.FlutterNativeView; import io.flutter.view.FlutterRunArguments; From 8cc088084ec170b4b0fb385fc83f00c61b651ec9 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 16 Jul 2018 12:24:29 -0700 Subject: [PATCH 07/11] Updated licenses --- tools/licenses/pubspec.lock | 12 ++++++++++-- travis/licenses.sh | 2 +- travis/licenses_golden/licenses_flutter | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/licenses/pubspec.lock b/tools/licenses/pubspec.lock index 75d0f144fde64..c6c3b579591c0 100644 --- a/tools/licenses/pubspec.lock +++ b/tools/licenses/pubspec.lock @@ -1,53 +1,61 @@ # Generated by pub -# See http://pub.dartlang.org/doc/glossary.html#lockfile +# See https://www.dartlang.org/tools/pub/glossary#lockfile packages: archive: + dependency: "direct main" description: name: archive url: "https://pub.dartlang.org" source: hosted version: "1.0.33" args: + dependency: "direct main" description: name: args url: "https://pub.dartlang.org" source: hosted version: "0.13.7" charcode: + dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted version: "1.1.1" collection: + dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted version: "1.14.5" convert: + dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted version: "2.0.1" crypto: + dependency: "direct main" description: name: crypto url: "https://pub.dartlang.org" source: hosted version: "2.0.2+1" path: + dependency: "direct main" description: name: path url: "https://pub.dartlang.org" source: hosted version: "1.5.1" typed_data: + dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted version: "1.1.5" sdks: - dart: ">=1.21.0 <2.0.0" + dart: ">=1.21.0 <=2.0.0-edge.7f1f54edc2cbe5280217ad3c858dd3df515aa3eb" diff --git a/travis/licenses.sh b/travis/licenses.sh index adc74b5c553bd..a5d38e4d5ab0d 100755 --- a/travis/licenses.sh +++ b/travis/licenses.sh @@ -3,7 +3,7 @@ set -e shopt -s nullglob echo "Verifying license script is still happy..." -(cd flutter/tools/licenses; pub get; dart --checked lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../travis/licenses_golden) +(cd flutter/tools/licenses; pub get; dart --no-preview-dart-2 --checked lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../travis/licenses_golden) for f in out/license_script_output/licenses_*; do if ! cmp -s flutter/travis/licenses_golden/$(basename $f) $f diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index 0aa56709efa76..a30b087bb7ee0 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -202,7 +202,6 @@ FILE: ../../../flutter/lib/ui/window/window.h FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/JSONUtil.java -FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java FILE: ../../../flutter/shell/platform/darwin/desktop/Info.plist FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec FILE: ../../../flutter/shell/platform/darwin/ios/framework/Info.plist @@ -503,6 +502,8 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java +FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm From fcc1c030dd63a1cee390b7c51b126815d9bd4b6d Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 16 Jul 2018 12:36:33 -0700 Subject: [PATCH 08/11] Reverted local changes to licenses.sh --- travis/licenses.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/licenses.sh b/travis/licenses.sh index a5d38e4d5ab0d..adc74b5c553bd 100755 --- a/travis/licenses.sh +++ b/travis/licenses.sh @@ -3,7 +3,7 @@ set -e shopt -s nullglob echo "Verifying license script is still happy..." -(cd flutter/tools/licenses; pub get; dart --no-preview-dart-2 --checked lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../travis/licenses_golden) +(cd flutter/tools/licenses; pub get; dart --checked lib/main.dart --src ../../.. --out ../../../out/license_script_output --golden ../../travis/licenses_golden) for f in out/license_script_output/licenses_*; do if ! cmp -s flutter/travis/licenses_golden/$(basename $f) $f From 2449c41edb0da2e183c981de82ce6f1df2f9d039 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Tue, 17 Jul 2018 17:44:49 -0700 Subject: [PATCH 09/11] Thinking positively --- shell/platform/android/android_shell_holder.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 47f95dfde3a53..dacb8e530d9d8 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -82,15 +82,15 @@ AndroidShellHolder::AndroidShellHolder( fxl::RefPtr gpu_runner; fxl::RefPtr ui_runner; fxl::RefPtr io_runner; - if (!is_background_view) { - gpu_runner = thread_host_.gpu_thread->GetTaskRunner(); - ui_runner = thread_host_.ui_thread->GetTaskRunner(); - io_runner = thread_host_.io_thread->GetTaskRunner(); - } else { + if (is_background_view) { auto single_task_runner = thread_host_.ui_thread->GetTaskRunner(); gpu_runner = single_task_runner; ui_runner = single_task_runner; io_runner = single_task_runner; + } else { + gpu_runner = thread_host_.gpu_thread->GetTaskRunner(); + ui_runner = thread_host_.ui_thread->GetTaskRunner(); + io_runner = thread_host_.io_thread->GetTaskRunner(); } blink::TaskRunners task_runners( thread_label, // label From 8868cdfd3f2bfae95210951bd04c1ff4145ea469 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Wed, 1 Aug 2018 16:34:04 -0700 Subject: [PATCH 10/11] Removed "onStarted" events + hooks --- shell/platform/android/BUILD.gn | 1 - shell/platform/android/android_shell_holder.cc | 16 +++++++--------- .../flutter/view/FlutterIsolateStartedEvent.java | 13 ------------- .../io/flutter/view/FlutterNativeView.java | 11 ++--------- .../io/flutter/view/FlutterRunArguments.java | 2 +- shell/platform/android/platform_view_android.cc | 10 ---------- shell/platform/android/platform_view_android.h | 2 -- .../android/platform_view_android_jni.cc | 15 +-------------- .../platform/android/platform_view_android_jni.h | 2 -- 9 files changed, 11 insertions(+), 61 deletions(-) delete mode 100644 shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 2c3415fe08671..1548cee47cdec 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -133,7 +133,6 @@ java_library("flutter_shell_java") { "io/flutter/util/Preconditions.java", "io/flutter/view/AccessibilityBridge.java", "io/flutter/view/FlutterCallbackInformation.java", - "io/flutter/view/FlutterIsolateStartedEvent.java", "io/flutter/view/FlutterMain.java", "io/flutter/view/FlutterNativeView.java", "io/flutter/view/FlutterRunArguments.java", diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index dacb8e530d9d8..efd239d65ae40 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -82,6 +82,8 @@ AndroidShellHolder::AndroidShellHolder( fxl::RefPtr gpu_runner; fxl::RefPtr ui_runner; fxl::RefPtr io_runner; + fxl::RefPtr platform_runner = + fml::MessageLoop::GetCurrent().GetTaskRunner(); if (is_background_view) { auto single_task_runner = thread_host_.ui_thread->GetTaskRunner(); gpu_runner = single_task_runner; @@ -94,7 +96,7 @@ AndroidShellHolder::AndroidShellHolder( } blink::TaskRunners task_runners( thread_label, // label - fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform + platform_runner, // platform gpu_runner, // gpu ui_runner, // ui io_runner // io @@ -158,19 +160,15 @@ void AndroidShellHolder::Launch(RunConfiguration config) { shell_->GetTaskRunners().GetUITaskRunner()->PostTask( fxl::MakeCopyable([engine = shell_->GetEngine(), // - config = std::move(config), // - view = platform_view_.get() // + config = std::move(config) // ]() mutable { - bool success = false; - FXL_LOG(INFO) << "Attempting to launch engine configuration..."; + FML_LOG(INFO) << "Attempting to launch engine configuration..."; if (!engine || !engine->Run(std::move(config))) { - FXL_LOG(ERROR) << "Could not launch engine in configuration."; + FML_LOG(ERROR) << "Could not launch engine in configuration."; } else { - FXL_LOG(INFO) << "Isolate for engine configuration successfully " + FML_LOG(INFO) << "Isolate for engine configuration successfully " "started and run."; - success = true; } - view->InvokeOnStartedCallback(success); })); } diff --git a/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java b/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java deleted file mode 100644 index 7e63e204b2dd2..0000000000000 --- a/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.view; - -/** - * An interface for a callback which is invoked once a new isolate has been - * started by the engine. - */ -public interface FlutterIsolateStartedEvent { - public void onStarted(boolean success); -} diff --git a/shell/platform/android/io/flutter/view/FlutterNativeView.java b/shell/platform/android/io/flutter/view/FlutterNativeView.java index 136269a619484..706183552fb0f 100644 --- a/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -27,7 +27,6 @@ public class FlutterNativeView implements BinaryMessenger { private FlutterView mFlutterView; private final Context mContext; private boolean applicationIsRunning; - private FlutterIsolateStartedEvent startedEvent; public FlutterNativeView(Context context) { this(context, false); @@ -83,7 +82,7 @@ public void runFromBundle(FlutterRunArguments args) { throw new AssertionError("An entrypoint must be specified"); } runFromBundleInternal(args.bundlePath, args.entrypoint, - args.libraryPath, args.onStartedEvent); + args.libraryPath, null); } /** @@ -97,12 +96,11 @@ public void runFromBundle(String bundlePath, String snapshotOverride, String ent } private void runFromBundleInternal(String bundlePath, String entrypoint, - String libraryPath, FlutterIsolateStartedEvent event) { + String libraryPath, String snapshotOverride) { assertAttached(); if (applicationIsRunning) throw new AssertionError( "This Flutter engine instance is already running an application"); - startedEvent = event; nativeRunBundleAndSnapshotFromLibrary(mNativePlatformView, bundlePath, entrypoint, libraryPath, mContext.getResources().getAssets()); @@ -224,11 +222,6 @@ private void onFirstFrame() { mFlutterView.onFirstFrame(); } - private void onStarted(boolean success) { - if (startedEvent == null) return; - startedEvent.onStarted(success); - } - private static native long nativeAttach(FlutterNativeView view, boolean isBackgroundView); private static native void nativeDestroy(long nativePlatformViewAndroid); private static native void nativeDetach(long nativePlatformViewAndroid); diff --git a/shell/platform/android/io/flutter/view/FlutterRunArguments.java b/shell/platform/android/io/flutter/view/FlutterRunArguments.java index 043325d0d272a..fb1218f57b168 100644 --- a/shell/platform/android/io/flutter/view/FlutterRunArguments.java +++ b/shell/platform/android/io/flutter/view/FlutterRunArguments.java @@ -12,5 +12,5 @@ public class FlutterRunArguments { public String bundlePath; public String entrypoint; public String libraryPath; - public FlutterIsolateStartedEvent onStartedEvent; + public String snapshotOverride; } diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index 27fbbdeeec943..46513a556138d 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -138,16 +138,6 @@ void PlatformViewAndroid::InvokePlatformMessageEmptyResponseCallback( message_response->CompleteEmpty(); } -void PlatformViewAndroid::InvokeOnStartedCallback(bool success) { - JNIEnv* env = fml::jni::AttachCurrentThread(); - fml::jni::ScopedJavaLocalRef view = java_object_.get(env); - if (view.is_null()) { - // The Java object died. - return; - } - FlutterViewOnStarted(fml::jni::AttachCurrentThread(), view.obj(), success); -} - // |shell::PlatformView| void PlatformViewAndroid::HandlePlatformMessage( fxl::RefPtr message) { diff --git a/shell/platform/android/platform_view_android.h b/shell/platform/android/platform_view_android.h index 4b17a68d01324..8633c68388692 100644 --- a/shell/platform/android/platform_view_android.h +++ b/shell/platform/android/platform_view_android.h @@ -63,8 +63,6 @@ class PlatformViewAndroid final : public PlatformView { void InvokePlatformMessageEmptyResponseCallback(JNIEnv* env, jint response_id); - void InvokeOnStartedCallback(bool success); - void DispatchSemanticsAction(JNIEnv* env, jint id, jint action, diff --git a/shell/platform/android/platform_view_android_jni.cc b/shell/platform/android/platform_view_android_jni.cc index 9f9784207d6e9..1b530fb08c466 100644 --- a/shell/platform/android/platform_view_android_jni.cc +++ b/shell/platform/android/platform_view_android_jni.cc @@ -111,12 +111,6 @@ void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj) { FXL_CHECK(CheckException(env)); } -static jmethodID g_on_started_method = nullptr; -void FlutterViewOnStarted(JNIEnv* env, jobject obj, jboolean success) { - env->CallVoidMethod(obj, g_on_started_method, success); - FXL_CHECK(CheckException(env)); -} - static jmethodID g_attach_to_gl_context_method = nullptr; void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId) { env->CallVoidMethod(obj, g_attach_to_gl_context_method, textureId); @@ -292,7 +286,7 @@ static void RunBundleAndSnapshotFromLibrary( ANDROID_SHELL_HOLDER->Launch(std::move(config)); } -static jobject LookupCallbackInformation(JNIEnv* env, jlong handle) { +static jobject LookupCallbackInformation(JNIEnv* env, /* unused */ jobject, jlong handle) { auto cbInfo = blink::DartCallbackCache::GetCallbackInformation(handle); if (cbInfo == nullptr) { return nullptr; @@ -738,13 +732,6 @@ bool PlatformViewAndroid::Register(JNIEnv* env) { return false; } - g_on_started_method = - env->GetMethodID(g_flutter_native_view_class->obj(), "onStarted", "(Z)V"); - - if (g_on_started_method == nullptr) { - return false; - } - g_attach_to_gl_context_method = env->GetMethodID( g_surface_texture_class->obj(), "attachToGLContext", "(I)V"); diff --git a/shell/platform/android/platform_view_android_jni.h b/shell/platform/android/platform_view_android_jni.h index bec5959be25ca..1a03d1303a7ec 100644 --- a/shell/platform/android/platform_view_android_jni.h +++ b/shell/platform/android/platform_view_android_jni.h @@ -34,8 +34,6 @@ void FlutterViewUpdateCustomAccessibilityActions(JNIEnv* env, void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj); -void FlutterViewOnStarted(JNIEnv* env, jobject obj, jboolean success); - void SurfaceTextureAttachToGLContext(JNIEnv* env, jobject obj, jint textureId); void SurfaceTextureUpdateTexImage(JNIEnv* env, jobject obj); From 109b34e1b1425251d882afab572b39c269003b2c Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 2 Aug 2018 09:12:04 -0700 Subject: [PATCH 11/11] Updated licenses --- travis/licenses_golden/licenses_flutter | 1 - 1 file changed, 1 deletion(-) diff --git a/travis/licenses_golden/licenses_flutter b/travis/licenses_golden/licenses_flutter index a30b087bb7ee0..dc4a370f0d3bc 100644 --- a/travis/licenses_golden/licenses_flutter +++ b/travis/licenses_golden/licenses_flutter @@ -502,7 +502,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java -FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterRunArguments.java FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h