what-the-bank/sources/io/flutter/plugins/urllauncher/MethodCallHandlerImpl.java

109 lines
4.0 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package io.flutter.plugins.urllauncher;
import android.os.Bundle;
import com.google.android.gms.common.internal.ImagesContract;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.urllauncher.UrlLauncher;
import java.util.Map;
/* loaded from: classes6.dex */
final class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
private static final String TAG = "MethodCallHandlerImpl";
private MethodChannel channel;
private final UrlLauncher urlLauncher;
/* JADX INFO: Access modifiers changed from: package-private */
public MethodCallHandlerImpl(UrlLauncher urlLauncher) {
this.urlLauncher = urlLauncher;
}
@Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
public final void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
char c;
String str = (String) methodCall.argument(ImagesContract.URL);
String str2 = methodCall.method;
str2.hashCode();
int hashCode = str2.hashCode();
if (hashCode == -1109843021) {
if (str2.equals("launch")) {
c = 0;
}
c = 65535;
} else if (hashCode != -185306205) {
if (hashCode == -121617663 && str2.equals("closeWebView")) {
c = 2;
}
c = 65535;
} else {
if (str2.equals("canLaunch")) {
c = 1;
}
c = 65535;
}
if (c == 0) {
onLaunch(methodCall, result, str);
return;
}
if (c == 1) {
onCanLaunch(result, str);
} else if (c == 2) {
onCloseWebView(result);
} else {
result.notImplemented();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void startListening(BinaryMessenger binaryMessenger) {
if (this.channel != null) {
stopListening();
}
MethodChannel methodChannel = new MethodChannel(binaryMessenger, "plugins.flutter.io/url_launcher_android");
this.channel = methodChannel;
methodChannel.setMethodCallHandler(this);
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void stopListening() {
MethodChannel methodChannel = this.channel;
if (methodChannel == null) {
return;
}
methodChannel.setMethodCallHandler(null);
this.channel = null;
}
private void onCanLaunch(MethodChannel.Result result, String str) {
result.success(Boolean.valueOf(this.urlLauncher.canLaunch(str)));
}
private void onLaunch(MethodCall methodCall, MethodChannel.Result result, String str) {
boolean booleanValue = ((Boolean) methodCall.argument("useWebView")).booleanValue();
boolean booleanValue2 = ((Boolean) methodCall.argument("enableJavaScript")).booleanValue();
boolean booleanValue3 = ((Boolean) methodCall.argument("enableDomStorage")).booleanValue();
UrlLauncher.LaunchStatus launch = this.urlLauncher.launch(str, extractBundle((Map) methodCall.argument("headers")), booleanValue, booleanValue2, booleanValue3);
if (launch == UrlLauncher.LaunchStatus.NO_ACTIVITY) {
result.error("NO_ACTIVITY", "Launching a URL requires a foreground activity.", null);
} else if (launch == UrlLauncher.LaunchStatus.ACTIVITY_NOT_FOUND) {
result.error("ACTIVITY_NOT_FOUND", String.format("No Activity found to handle intent { %s }", str), null);
} else {
result.success(Boolean.TRUE);
}
}
private void onCloseWebView(MethodChannel.Result result) {
this.urlLauncher.closeWebView();
result.success(null);
}
private static Bundle extractBundle(Map<String, String> map) {
Bundle bundle = new Bundle();
for (String str : map.keySet()) {
bundle.putString(str, map.get(str));
}
return bundle;
}
}