135 lines
5.6 KiB
Java
135 lines
5.6 KiB
Java
|
package io.flutter.plugin.common;
|
||
|
|
||
|
import io.flutter.Log;
|
||
|
import io.flutter.plugin.common.BinaryMessenger;
|
||
|
import java.nio.ByteBuffer;
|
||
|
import java.nio.charset.Charset;
|
||
|
import java.util.Locale;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public final class BasicMessageChannel<T> {
|
||
|
public static final String CHANNEL_BUFFERS_CHANNEL = "dev.flutter/channel-buffers";
|
||
|
private static final String TAG = "BasicMessageChannel#";
|
||
|
private final MessageCodec<T> codec;
|
||
|
private final BinaryMessenger messenger;
|
||
|
private final String name;
|
||
|
private final BinaryMessenger.TaskQueue taskQueue;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public interface MessageHandler<T> {
|
||
|
void onMessage(T t, Reply<T> reply);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public interface Reply<T> {
|
||
|
void reply(T t);
|
||
|
}
|
||
|
|
||
|
public BasicMessageChannel(BinaryMessenger binaryMessenger, String str, MessageCodec<T> messageCodec) {
|
||
|
this(binaryMessenger, str, messageCodec, null);
|
||
|
}
|
||
|
|
||
|
public BasicMessageChannel(BinaryMessenger binaryMessenger, String str, MessageCodec<T> messageCodec, BinaryMessenger.TaskQueue taskQueue) {
|
||
|
this.messenger = binaryMessenger;
|
||
|
this.name = str;
|
||
|
this.codec = messageCodec;
|
||
|
this.taskQueue = taskQueue;
|
||
|
}
|
||
|
|
||
|
public final void send(T t) {
|
||
|
send(t, null);
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
public final void send(T t, Reply<T> reply) {
|
||
|
BinaryMessenger binaryMessenger = this.messenger;
|
||
|
String str = this.name;
|
||
|
ByteBuffer encodeMessage = this.codec.encodeMessage(t);
|
||
|
BinaryMessenger.BinaryReply binaryReply = null;
|
||
|
Object[] objArr = 0;
|
||
|
if (reply != null) {
|
||
|
binaryReply = new IncomingReplyHandler(reply);
|
||
|
}
|
||
|
binaryMessenger.send(str, encodeMessage, binaryReply);
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
/* JADX WARN: Type inference failed for: r0v1, types: [io.flutter.plugin.common.BinaryMessenger] */
|
||
|
/* JADX WARN: Type inference failed for: r1v0, types: [io.flutter.plugin.common.BasicMessageChannel$1] */
|
||
|
/* JADX WARN: Type inference failed for: r1v1, types: [io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler] */
|
||
|
/* JADX WARN: Type inference failed for: r1v2 */
|
||
|
public final void setMessageHandler(MessageHandler<T> messageHandler) {
|
||
|
if (this.taskQueue != null) {
|
||
|
this.messenger.setMessageHandler(this.name, messageHandler != null ? new IncomingMessageHandler(messageHandler) : null, this.taskQueue);
|
||
|
} else {
|
||
|
this.messenger.setMessageHandler(this.name, messageHandler != null ? new IncomingMessageHandler(messageHandler) : 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void resizeChannelBuffer(int i) {
|
||
|
resizeChannelBuffer(this.messenger, this.name, i);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static void resizeChannelBuffer(BinaryMessenger binaryMessenger, String str, int i) {
|
||
|
binaryMessenger.send(CHANNEL_BUFFERS_CHANNEL, ByteBuffer.wrap(String.format(Locale.US, "resize\r%s\r%d", str, Integer.valueOf(i)).getBytes(Charset.forName("UTF-8"))));
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public final class IncomingReplyHandler implements BinaryMessenger.BinaryReply {
|
||
|
private final Reply<T> callback;
|
||
|
final BasicMessageChannel this$0;
|
||
|
|
||
|
private IncomingReplyHandler(BasicMessageChannel basicMessageChannel, Reply<T> reply) {
|
||
|
this.this$0 = basicMessageChannel;
|
||
|
this.callback = reply;
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // io.flutter.plugin.common.BinaryMessenger.BinaryReply
|
||
|
public final void reply(ByteBuffer byteBuffer) {
|
||
|
try {
|
||
|
this.callback.reply(this.this$0.codec.decodeMessage(byteBuffer));
|
||
|
} catch (RuntimeException e) {
|
||
|
Log.e(BasicMessageChannel.TAG + this.this$0.name, "Failed to handle message reply", e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
final class IncomingMessageHandler implements BinaryMessenger.BinaryMessageHandler {
|
||
|
private final MessageHandler<T> handler;
|
||
|
final BasicMessageChannel this$0;
|
||
|
|
||
|
private IncomingMessageHandler(BasicMessageChannel basicMessageChannel, MessageHandler<T> messageHandler) {
|
||
|
this.this$0 = basicMessageChannel;
|
||
|
this.handler = messageHandler;
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler
|
||
|
public final void onMessage(ByteBuffer byteBuffer, BinaryMessenger.BinaryReply binaryReply) {
|
||
|
try {
|
||
|
this.handler.onMessage(this.this$0.codec.decodeMessage(byteBuffer), new Reply<T>(this, binaryReply) { // from class: io.flutter.plugin.common.BasicMessageChannel.IncomingMessageHandler.1
|
||
|
final IncomingMessageHandler this$1;
|
||
|
final BinaryMessenger.BinaryReply val$callback;
|
||
|
|
||
|
{
|
||
|
this.this$1 = this;
|
||
|
this.val$callback = binaryReply;
|
||
|
}
|
||
|
|
||
|
@Override // io.flutter.plugin.common.BasicMessageChannel.Reply
|
||
|
public void reply(T t) {
|
||
|
this.val$callback.reply(this.this$1.this$0.codec.encodeMessage(t));
|
||
|
}
|
||
|
});
|
||
|
} catch (RuntimeException e) {
|
||
|
Log.e(BasicMessageChannel.TAG + this.this$0.name, "Failed to handle message", e);
|
||
|
binaryReply.reply(null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|