what-the-bank/sources/io/flutter/plugin/common/MethodChannel.java

137 lines
5.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.flutter.plugin.common;
import io.flutter.Log;
import io.flutter.plugin.common.BinaryMessenger;
import java.nio.ByteBuffer;
/* loaded from: classes.dex */
public class MethodChannel {
private static final String TAG = "MethodChannel#";
private final MethodCodec codec;
private final BinaryMessenger messenger;
private final String name;
private final BinaryMessenger.TaskQueue taskQueue;
/* loaded from: classes.dex */
public interface MethodCallHandler {
void onMethodCall(MethodCall methodCall, Result result);
}
/* loaded from: classes.dex */
public interface Result {
void error(String str, String str2, Object obj);
void notImplemented();
void success(Object obj);
}
public MethodChannel(BinaryMessenger binaryMessenger, String str) {
this(binaryMessenger, str, StandardMethodCodec.INSTANCE);
}
public MethodChannel(BinaryMessenger binaryMessenger, String str, MethodCodec methodCodec) {
this(binaryMessenger, str, methodCodec, null);
}
public MethodChannel(BinaryMessenger binaryMessenger, String str, MethodCodec methodCodec, BinaryMessenger.TaskQueue taskQueue) {
this.messenger = binaryMessenger;
this.name = str;
this.codec = methodCodec;
this.taskQueue = taskQueue;
}
public void invokeMethod(String str, Object obj) {
invokeMethod(str, obj, null);
}
public void invokeMethod(String str, Object obj, Result result) {
this.messenger.send(this.name, this.codec.encodeMethodCall(new MethodCall(str, obj)), result == null ? null : new IncomingResultHandler(this, result));
}
public void setMethodCallHandler(MethodCallHandler methodCallHandler) {
if (this.taskQueue != null) {
this.messenger.setMessageHandler(this.name, methodCallHandler != null ? new IncomingMethodCallHandler(this, methodCallHandler) : null, this.taskQueue);
} else {
this.messenger.setMessageHandler(this.name, methodCallHandler != null ? new IncomingMethodCallHandler(this, methodCallHandler) : null);
}
}
public void resizeChannelBuffer(int i) {
BasicMessageChannel.resizeChannelBuffer(this.messenger, this.name, i);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class IncomingResultHandler implements BinaryMessenger.BinaryReply {
private final Result callback;
final MethodChannel this$0;
IncomingResultHandler(MethodChannel methodChannel, Result result) {
this.this$0 = methodChannel;
this.callback = result;
}
@Override // io.flutter.plugin.common.BinaryMessenger.BinaryReply
public final void reply(ByteBuffer byteBuffer) {
try {
if (byteBuffer != null) {
try {
this.callback.success(this.this$0.codec.decodeEnvelope(byteBuffer));
} catch (FlutterException e) {
this.callback.error(e.code, e.getMessage(), e.details);
}
} else {
this.callback.notImplemented();
}
} catch (RuntimeException e2) {
Log.e(MethodChannel.TAG + this.this$0.name, "Failed to handle method call result", e2);
}
}
}
/* loaded from: classes.dex */
final class IncomingMethodCallHandler implements BinaryMessenger.BinaryMessageHandler {
private final MethodCallHandler handler;
final MethodChannel this$0;
IncomingMethodCallHandler(MethodChannel methodChannel, MethodCallHandler methodCallHandler) {
this.this$0 = methodChannel;
this.handler = methodCallHandler;
}
@Override // io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler
public final void onMessage(ByteBuffer byteBuffer, BinaryMessenger.BinaryReply binaryReply) {
try {
this.handler.onMethodCall(this.this$0.codec.decodeMethodCall(byteBuffer), new Result(this, binaryReply) { // from class: io.flutter.plugin.common.MethodChannel.IncomingMethodCallHandler.1
final IncomingMethodCallHandler this$1;
final BinaryMessenger.BinaryReply val$reply;
{
this.this$1 = this;
this.val$reply = binaryReply;
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void success(Object obj) {
this.val$reply.reply(this.this$1.this$0.codec.encodeSuccessEnvelope(obj));
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void error(String str, String str2, Object obj) {
this.val$reply.reply(this.this$1.this$0.codec.encodeErrorEnvelope(str, str2, obj));
}
@Override // io.flutter.plugin.common.MethodChannel.Result
public void notImplemented() {
this.val$reply.reply(null);
}
});
} catch (RuntimeException e) {
Log.e(MethodChannel.TAG + this.this$0.name, "Failed to handle method call", e);
binaryReply.reply(this.this$0.codec.encodeErrorEnvelopeWithStacktrace("error", e.getMessage(), null, Log.getStackTraceString(e)));
}
}
}
}