Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3393c17

Browse files
authored
Fix Android platform channels (#5025)
1 parent 1bc0e1b commit 3393c17

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

shell/platform/android/platform_message_response_android.cc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ void PlatformMessageResponseAndroid::Complete(std::vector<uint8_t> data) {
3535
return;
3636
}
3737

38-
if (data.size() == 0) {
39-
// If the data is empty, there is no reason to create a Java byte
40-
// array. Make the response now with a nullptr now.
41-
FlutterViewHandlePlatformMessageResponse(env, java_object.obj(),
42-
response, nullptr);
43-
}
44-
4538
// Convert the vector to a Java byte array.
4639
fml::jni::ScopedJavaLocalRef<jbyteArray> data_array(
4740
env, env->NewByteArray(data.size()));
@@ -56,7 +49,23 @@ void PlatformMessageResponseAndroid::Complete(std::vector<uint8_t> data) {
5649

5750
// |blink::PlatformMessageResponse|
5851
void PlatformMessageResponseAndroid::CompleteEmpty() {
59-
Complete(std::vector<uint8_t>{});
60-
}
52+
platform_task_runner_->PostTask(
53+
fxl::MakeCopyable([response = response_id_, //
54+
weak_java_object = weak_java_object_ //
55+
]() {
56+
// We are on the platform thread. Attempt to get the strong reference to
57+
// the Java object.
58+
auto env = fml::jni::AttachCurrentThread();
59+
auto java_object = weak_java_object.get(env);
6160

61+
if (java_object.is_null()) {
62+
// The Java object was collected before this message response got to
63+
// it. Drop the response on the floor.
64+
return;
65+
}
66+
// Make the response call into Java.
67+
FlutterViewHandlePlatformMessageResponse(env, java_object.obj(),
68+
response, nullptr);
69+
}));
70+
}
6271
} // namespace shell

0 commit comments

Comments
 (0)