Always increment response_id for Android platform messages (flutter/engine#29090)
This commit is contained in:
@@ -61,9 +61,8 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
|
||||
@Nullable ByteBuffer message,
|
||||
@Nullable BinaryMessenger.BinaryReply callback) {
|
||||
Log.v(TAG, "Sending message with callback over channel '" + channel + "'");
|
||||
int replyId = 0;
|
||||
int replyId = nextReplyId++;
|
||||
if (callback != null) {
|
||||
replyId = nextReplyId++;
|
||||
pendingReplies.put(replyId, callback);
|
||||
}
|
||||
if (message == null) {
|
||||
|
||||
@@ -227,9 +227,8 @@ void PlatformViewAndroid::InvokePlatformMessageEmptyResponseCallback(
|
||||
// |PlatformView|
|
||||
void PlatformViewAndroid::HandlePlatformMessage(
|
||||
std::unique_ptr<flutter::PlatformMessage> message) {
|
||||
int response_id = 0;
|
||||
int response_id = next_response_id_++;
|
||||
if (auto response = message->response()) {
|
||||
response_id = next_response_id_++;
|
||||
pending_responses_[response_id] = response;
|
||||
}
|
||||
// This call can re-enter in InvokePlatformMessageXxxResponseCallback.
|
||||
|
||||
@@ -4,7 +4,10 @@ import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import io.flutter.embedding.engine.FlutterJNI;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
@@ -124,4 +127,16 @@ public class DartMessengerTest {
|
||||
messenger.handlePlatformMessageResponse(1, message);
|
||||
assertEquals(0, byteBuffers[0].limit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replyIdIncrementsOnNullReply() {
|
||||
/// Setup test.
|
||||
final FlutterJNI fakeFlutterJni = mock(FlutterJNI.class);
|
||||
final DartMessenger messenger = new DartMessenger(fakeFlutterJni);
|
||||
final String channel = "foobar";
|
||||
messenger.send(channel, null, null);
|
||||
verify(fakeFlutterJni, times(1)).dispatchEmptyPlatformMessage(eq("foobar"), eq(1));
|
||||
messenger.send(channel, null, null);
|
||||
verify(fakeFlutterJni, times(1)).dispatchEmptyPlatformMessage(eq("foobar"), eq(2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user