Skip to content

Commit

Permalink
Revert "Updated background execution implementation for Android" (#5949)
Browse files Browse the repository at this point in the history
This reverts commit bc885f3.
  • Loading branch information
alexmarkov authored Aug 6, 2018
1 parent a5215ce commit 5442c0a
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 330 deletions.
2 changes: 0 additions & 2 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ 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/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",
Expand Down
78 changes: 23 additions & 55 deletions shell/platform/android/android_shell_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,34 @@ namespace shell {

AndroidShellHolder::AndroidShellHolder(
blink::Settings settings,
fml::jni::JavaObjectWeakGlobalRef java_object,
bool is_background_view)
fml::jni::JavaObjectWeakGlobalRef java_object)
: settings_(std::move(settings)), java_object_(java_object) {
static size_t shell_count = 1;
auto thread_label = std::to_string(shell_count++);

FML_CHECK(pthread_key_create(&thread_destruct_key_, ThreadDestructCallback) ==
0);

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};
}
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_]() {
FML_CHECK(pthread_setspecific(key, reinterpret_cast<void*>(1)) == 0);
});
thread_host_.ui_thread->GetTaskRunner()->PostTask(jni_exit_task);
if (!is_background_view) {
thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task);
}
thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task);

fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
Shell::CreateCallback<PlatformView> on_create_platform_view =
[is_background_view, java_object, &weak_platform_view](Shell& shell) {
std::unique_ptr<PlatformViewAndroid> platform_view_android;
if (is_background_view) {
platform_view_android = std::make_unique<PlatformViewAndroid>(
shell, // delegate
shell.GetTaskRunners(), // task runners
java_object // java object handle for JNI interop
);

} else {
platform_view_android = std::make_unique<PlatformViewAndroid>(
shell, // delegate
shell.GetTaskRunners(), // task runners
java_object, // java object handle for JNI interop
shell.GetSettings()
.enable_software_rendering // use software rendering
);
}
[java_object, &weak_platform_view](Shell& shell) {
auto platform_view_android = std::make_unique<PlatformViewAndroid>(
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;
};
Expand All @@ -79,26 +62,13 @@ AndroidShellHolder::AndroidShellHolder(
// The current thread will be used as the platform thread. Ensure that the
// message loop is initialized.
fml::MessageLoop::EnsureInitializedForCurrentThread();
fml::RefPtr<fml::TaskRunner> gpu_runner;
fml::RefPtr<fml::TaskRunner> ui_runner;
fml::RefPtr<fml::TaskRunner> io_runner;
fml::RefPtr<fml::TaskRunner> platform_runner =
fml::MessageLoop::GetCurrent().GetTaskRunner();
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
platform_runner, // platform
gpu_runner, // gpu
ui_runner, // ui
io_runner // io

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
);

shell_ =
Expand Down Expand Up @@ -161,12 +131,10 @@ void AndroidShellHolder::Launch(RunConfiguration config) {
fml::MakeCopyable([engine = shell_->GetEngine(), //
config = std::move(config) //
]() mutable {
FML_LOG(INFO) << "Attempting to launch engine configuration...";
if (!engine || !engine->Run(std::move(config))) {
FML_LOG(ERROR) << "Could not launch engine in configuration.";
} else {
FML_LOG(INFO) << "Isolate for engine configuration successfully "
"started and run.";
if (engine) {
if (!engine->Run(std::move(config))) {
FML_LOG(ERROR) << "Could not launch engine in configuration.";
}
}
}));
}
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/android/android_shell_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace shell {
class AndroidShellHolder {
public:
AndroidShellHolder(blink::Settings settings,
fml::jni::JavaObjectWeakGlobalRef java_object,
bool is_background_view);
fml::jni::JavaObjectWeakGlobalRef java_object);

~AndroidShellHolder();

Expand Down
24 changes: 14 additions & 10 deletions shell/platform/android/io/flutter/app/FlutterActivityDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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;
Expand Down Expand Up @@ -163,16 +162,19 @@ public void onCreate(Bundle savedInstanceState) {
}
}

if (loadIntent(activity.getIntent())) {
// 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)) {
return;
}
if (!flutterView.getFlutterNativeView().isApplicationRunning()) {
String appBundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext());
if (appBundlePath != null) {
FlutterRunArguments arguments = new FlutterRunArguments();
arguments.bundlePath = appBundlePath;
arguments.entrypoint = "main";
flutterView.runFromBundle(arguments);
flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate);
}
}
}
Expand Down Expand Up @@ -323,6 +325,11 @@ 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");
Expand All @@ -336,10 +343,7 @@ private boolean loadIntent(Intent intent) {
flutterView.setInitialRoute(route);
}
if (!flutterView.getFlutterNativeView().isApplicationRunning()) {
FlutterRunArguments args = new FlutterRunArguments();
args.bundlePath = appBundlePath;
args.entrypoint = "main";
flutterView.runFromBundle(args);
flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate);
}
return true;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 5442c0a

Please sign in to comment.