Skip to content

Commit 5442c0a

Browse files
authored
Revert "Updated background execution implementation for Android" (flutter#5949)
This reverts commit bc885f3.
1 parent a5215ce commit 5442c0a

14 files changed

+115
-330
lines changed

shell/platform/android/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ java_library("flutter_shell_java") {
133133
"io/flutter/util/PathUtils.java",
134134
"io/flutter/util/Preconditions.java",
135135
"io/flutter/view/AccessibilityBridge.java",
136-
"io/flutter/view/FlutterCallbackInformation.java",
137136
"io/flutter/view/FlutterMain.java",
138137
"io/flutter/view/FlutterNativeView.java",
139-
"io/flutter/view/FlutterRunArguments.java",
140138
"io/flutter/view/FlutterView.java",
141139
"io/flutter/view/ResourceCleaner.java",
142140
"io/flutter/view/ResourceExtractor.java",

shell/platform/android/android_shell_holder.cc

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,34 @@ namespace shell {
2323

2424
AndroidShellHolder::AndroidShellHolder(
2525
blink::Settings settings,
26-
fml::jni::JavaObjectWeakGlobalRef java_object,
27-
bool is_background_view)
26+
fml::jni::JavaObjectWeakGlobalRef java_object)
2827
: settings_(std::move(settings)), java_object_(java_object) {
2928
static size_t shell_count = 1;
3029
auto thread_label = std::to_string(shell_count++);
3130

3231
FML_CHECK(pthread_key_create(&thread_destruct_key_, ThreadDestructCallback) ==
3332
0);
3433

35-
if (is_background_view) {
36-
thread_host_ = {thread_label, ThreadHost::Type::UI};
37-
} else {
38-
thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU |
39-
ThreadHost::Type::IO};
40-
}
34+
thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU |
35+
ThreadHost::Type::IO};
4136

4237
// Detach from JNI when the UI and GPU threads exit.
4338
auto jni_exit_task([key = thread_destruct_key_]() {
4439
FML_CHECK(pthread_setspecific(key, reinterpret_cast<void*>(1)) == 0);
4540
});
4641
thread_host_.ui_thread->GetTaskRunner()->PostTask(jni_exit_task);
47-
if (!is_background_view) {
48-
thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task);
49-
}
42+
thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task);
5043

5144
fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
5245
Shell::CreateCallback<PlatformView> on_create_platform_view =
53-
[is_background_view, java_object, &weak_platform_view](Shell& shell) {
54-
std::unique_ptr<PlatformViewAndroid> platform_view_android;
55-
if (is_background_view) {
56-
platform_view_android = std::make_unique<PlatformViewAndroid>(
57-
shell, // delegate
58-
shell.GetTaskRunners(), // task runners
59-
java_object // java object handle for JNI interop
60-
);
61-
62-
} else {
63-
platform_view_android = std::make_unique<PlatformViewAndroid>(
64-
shell, // delegate
65-
shell.GetTaskRunners(), // task runners
66-
java_object, // java object handle for JNI interop
67-
shell.GetSettings()
68-
.enable_software_rendering // use software rendering
69-
);
70-
}
46+
[java_object, &weak_platform_view](Shell& shell) {
47+
auto platform_view_android = std::make_unique<PlatformViewAndroid>(
48+
shell, // delegate
49+
shell.GetTaskRunners(), // task runners
50+
java_object, // java object handle for JNI interop
51+
shell.GetSettings()
52+
.enable_software_rendering // use software rendering
53+
);
7154
weak_platform_view = platform_view_android->GetWeakPtr();
7255
return platform_view_android;
7356
};
@@ -79,26 +62,13 @@ AndroidShellHolder::AndroidShellHolder(
7962
// The current thread will be used as the platform thread. Ensure that the
8063
// message loop is initialized.
8164
fml::MessageLoop::EnsureInitializedForCurrentThread();
82-
fml::RefPtr<fml::TaskRunner> gpu_runner;
83-
fml::RefPtr<fml::TaskRunner> ui_runner;
84-
fml::RefPtr<fml::TaskRunner> io_runner;
85-
fml::RefPtr<fml::TaskRunner> platform_runner =
86-
fml::MessageLoop::GetCurrent().GetTaskRunner();
87-
if (is_background_view) {
88-
auto single_task_runner = thread_host_.ui_thread->GetTaskRunner();
89-
gpu_runner = single_task_runner;
90-
ui_runner = single_task_runner;
91-
io_runner = single_task_runner;
92-
} else {
93-
gpu_runner = thread_host_.gpu_thread->GetTaskRunner();
94-
ui_runner = thread_host_.ui_thread->GetTaskRunner();
95-
io_runner = thread_host_.io_thread->GetTaskRunner();
96-
}
97-
blink::TaskRunners task_runners(thread_label, // label
98-
platform_runner, // platform
99-
gpu_runner, // gpu
100-
ui_runner, // ui
101-
io_runner // io
65+
66+
blink::TaskRunners task_runners(
67+
thread_label, // label
68+
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform
69+
thread_host_.gpu_thread->GetTaskRunner(), // gpu
70+
thread_host_.ui_thread->GetTaskRunner(), // ui
71+
thread_host_.io_thread->GetTaskRunner() // io
10272
);
10373

10474
shell_ =
@@ -161,12 +131,10 @@ void AndroidShellHolder::Launch(RunConfiguration config) {
161131
fml::MakeCopyable([engine = shell_->GetEngine(), //
162132
config = std::move(config) //
163133
]() mutable {
164-
FML_LOG(INFO) << "Attempting to launch engine configuration...";
165-
if (!engine || !engine->Run(std::move(config))) {
166-
FML_LOG(ERROR) << "Could not launch engine in configuration.";
167-
} else {
168-
FML_LOG(INFO) << "Isolate for engine configuration successfully "
169-
"started and run.";
134+
if (engine) {
135+
if (!engine->Run(std::move(config))) {
136+
FML_LOG(ERROR) << "Could not launch engine in configuration.";
137+
}
170138
}
171139
}));
172140
}

shell/platform/android/android_shell_holder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace shell {
2121
class AndroidShellHolder {
2222
public:
2323
AndroidShellHolder(blink::Settings settings,
24-
fml::jni::JavaObjectWeakGlobalRef java_object,
25-
bool is_background_view);
24+
fml::jni::JavaObjectWeakGlobalRef java_object);
2625

2726
~AndroidShellHolder();
2827

shell/platform/android/io/flutter/app/FlutterActivityDelegate.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.flutter.util.Preconditions;
3131
import io.flutter.view.FlutterMain;
3232
import io.flutter.view.FlutterNativeView;
33-
import io.flutter.view.FlutterRunArguments;
3433
import io.flutter.view.FlutterView;
3534

3635
import java.util.ArrayList;
@@ -163,16 +162,19 @@ public void onCreate(Bundle savedInstanceState) {
163162
}
164163
}
165164

166-
if (loadIntent(activity.getIntent())) {
165+
// When an activity is created for the first time, we direct the
166+
// FlutterView to re-use a pre-existing Isolate rather than create a new
167+
// one. This is so that an Isolate coming in from the ViewFactory is
168+
// used.
169+
final boolean reuseIsolate = true;
170+
171+
if (loadIntent(activity.getIntent(), reuseIsolate)) {
167172
return;
168173
}
169174
if (!flutterView.getFlutterNativeView().isApplicationRunning()) {
170175
String appBundlePath = FlutterMain.findAppBundlePath(activity.getApplicationContext());
171176
if (appBundlePath != null) {
172-
FlutterRunArguments arguments = new FlutterRunArguments();
173-
arguments.bundlePath = appBundlePath;
174-
arguments.entrypoint = "main";
175-
flutterView.runFromBundle(arguments);
177+
flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate);
176178
}
177179
}
178180
}
@@ -323,6 +325,11 @@ private static String[] getArgsFromIntent(Intent intent) {
323325
}
324326

325327
private boolean loadIntent(Intent intent) {
328+
final boolean reuseIsolate = false;
329+
return loadIntent(intent, reuseIsolate);
330+
}
331+
332+
private boolean loadIntent(Intent intent, boolean reuseIsolate) {
326333
String action = intent.getAction();
327334
if (Intent.ACTION_RUN.equals(action)) {
328335
String route = intent.getStringExtra("route");
@@ -336,10 +343,7 @@ private boolean loadIntent(Intent intent) {
336343
flutterView.setInitialRoute(route);
337344
}
338345
if (!flutterView.getFlutterNativeView().isApplicationRunning()) {
339-
FlutterRunArguments args = new FlutterRunArguments();
340-
args.bundlePath = appBundlePath;
341-
args.entrypoint = "main";
342-
flutterView.runFromBundle(args);
346+
flutterView.runFromBundle(appBundlePath, null, "main", reuseIsolate);
343347
}
344348
return true;
345349
}

shell/platform/android/io/flutter/view/FlutterCallbackInformation.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)