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

Commit ef99738

Browse files
authored
Added a DartExecutor API for querying # of pending channel callbacks (#10021)
1 parent a0ec528 commit ef99738

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ public void send(@NonNull String channel, @Nullable ByteBuffer message, @Nullabl
196196
public void setMessageHandler(@NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler) {
197197
messenger.setMessageHandler(channel, handler);
198198
}
199+
200+
/**
201+
* Returns the number of pending channel callback replies.
202+
*
203+
* <p>When sending messages to the Flutter application using {@link BinaryMessenger#send(String,
204+
* ByteBuffer, io.flutter.plugin.common.BinaryMessenger.BinaryReply)}, developers can optionally
205+
* specify a reply callback if they expect a reply from the Flutter application.
206+
*
207+
* <p>This method tracks all the pending callbacks that are waiting for response, and is supposed
208+
* to be called from the main thread (as other methods). Calling from a different thread could
209+
* possibly capture an indeterministic internal state, so don't do it.
210+
*
211+
* <p>Currently, it's mainly useful for a testing framework like Espresso to determine whether all
212+
* the async channel callbacks are handled and the app is idle.
213+
*/
214+
@UiThread
215+
public int getPendingChannelResponseCount() {
216+
return messenger.getPendingChannelResponseCount();
217+
}
218+
199219
//------ END BinaryMessenger -----
200220

201221
/**

shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ public void handlePlatformMessageResponse(int replyId, @Nullable byte[] reply) {
118118
}
119119
}
120120

121+
/**
122+
* Returns the number of pending channel callback replies.
123+
*
124+
* <p>When sending messages to the Flutter application using {@link BinaryMessenger#send(String,
125+
* ByteBuffer, io.flutter.plugin.common.BinaryMessenger.BinaryReply)}, developers can optionally
126+
* specify a reply callback if they expect a reply from the Flutter application.
127+
*
128+
* <p>This method tracks all the pending callbacks that are waiting for response, and is supposed
129+
* to be called from the main thread (as other methods). Calling from a different thread could
130+
* possibly capture an indeterministic internal state, so don't do it.
131+
*/
132+
@UiThread
133+
public int getPendingChannelResponseCount() {
134+
return pendingReplies.size();
135+
}
136+
121137
private static class Reply implements BinaryMessenger.BinaryReply {
122138
@NonNull
123139
private final FlutterJNI flutterJNI;
@@ -141,4 +157,4 @@ public void reply(@Nullable ByteBuffer reply) {
141157
}
142158
}
143159
}
144-
}
160+
}

0 commit comments

Comments
 (0)