@@ -35,13 +35,6 @@ void PlatformMessageResponseAndroid::Complete(std::vector<uint8_t> data) {
35
35
return ;
36
36
}
37
37
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
-
45
38
// Convert the vector to a Java byte array.
46
39
fml::jni::ScopedJavaLocalRef<jbyteArray> data_array (
47
40
env, env->NewByteArray (data.size ()));
@@ -56,7 +49,23 @@ void PlatformMessageResponseAndroid::Complete(std::vector<uint8_t> data) {
56
49
57
50
// |blink::PlatformMessageResponse|
58
51
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);
61
60
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
+ }
62
71
} // namespace shell
0 commit comments