Made the android platform channel benchmarks comparable to iOS (#83110)

This commit is contained in:
gaaclarke
2021-05-24 10:45:49 -07:00
committed by GitHub
parent c500a0629e
commit ade6e1f96d
3 changed files with 26 additions and 4 deletions

View File

@@ -12,15 +12,24 @@ import io.flutter.plugin.common.StandardMessageCodec
import java.nio.ByteBuffer
class MainActivity: FlutterActivity() {
// We allow for the caching of a response in the binary channel case since
// the reply requires a direct buffer, but the input is not a direct buffer.
// We can't directly send the input back to the reply currently.
private var byteBufferCache : ByteBuffer? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
val reset = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.reset", StandardMessageCodec.INSTANCE)
reset.setMessageHandler { message, reply -> run {
byteBufferCache = null
} }
val basicStandard = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.standard", StandardMessageCodec.INSTANCE)
basicStandard.setMessageHandler { message, reply -> reply.reply(message) }
val basicBinary = BasicMessageChannel(flutterEngine.dartExecutor, "dev.flutter.echo.basic.binary", BinaryCodec.INSTANCE)
basicBinary.setMessageHandler { message, reply -> run {
val result = ByteBuffer.allocateDirect(message!!.capacity())
result.put(message)
reply.reply(result)
if (byteBufferCache == null) {
byteBufferCache = ByteBuffer.allocateDirect(message!!.capacity())
byteBufferCache!!.put(message)
}
reply.reply(byteBufferCache)
} }
super.configureFlutterEngine(flutterEngine)
}