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

556 lines
20 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package io.flutter.plugins.camera;
import android.app.Activity;
import android.hardware.camera2.CameraAccessException;
import android.os.Handler;
import android.os.Looper;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.camera.CameraPermissions;
import io.flutter.plugins.camera.features.CameraFeatureFactoryImpl;
import io.flutter.plugins.camera.features.Point;
import io.flutter.plugins.camera.features.autofocus.FocusMode;
import io.flutter.plugins.camera.features.exposurelock.ExposureMode;
import io.flutter.plugins.camera.features.flash.FlashMode;
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
import io.flutter.view.TextureRegistry;
import java.util.HashMap;
import java.util.Objects;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public final class MethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
static final boolean $assertionsDisabled = false;
private final Activity activity;
private Camera camera;
private final CameraPermissions cameraPermissions;
private final EventChannel imageStreamChannel;
private final BinaryMessenger messenger;
private final MethodChannel methodChannel;
private final CameraPermissions.PermissionsRegistry permissionsRegistry;
private final TextureRegistry textureRegistry;
/* JADX INFO: Access modifiers changed from: package-private */
public MethodCallHandlerImpl(Activity activity, BinaryMessenger binaryMessenger, CameraPermissions cameraPermissions, CameraPermissions.PermissionsRegistry permissionsRegistry, TextureRegistry textureRegistry) {
this.activity = activity;
this.messenger = binaryMessenger;
this.cameraPermissions = cameraPermissions;
this.permissionsRegistry = permissionsRegistry;
this.textureRegistry = textureRegistry;
MethodChannel methodChannel = new MethodChannel(binaryMessenger, "plugins.flutter.io/camera_android");
this.methodChannel = methodChannel;
this.imageStreamChannel = new EventChannel(binaryMessenger, "plugins.flutter.io/camera_android/imageStream");
methodChannel.setMethodCallHandler(this);
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
@Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
public final void onMethodCall(final MethodCall methodCall, final MethodChannel.Result result) {
char c;
Double d;
Double d2;
String str = methodCall.method;
str.hashCode();
switch (str.hashCode()) {
case -2037208347:
if (str.equals("availableCameras")) {
c = 0;
break;
}
c = 65535;
break;
case -1982465099:
if (str.equals("getMinZoomLevel")) {
c = 1;
break;
}
c = 65535;
break;
case -1849130371:
if (str.equals("getExposureOffsetStepSize")) {
c = 2;
break;
}
c = 65535;
break;
case -1783353674:
if (str.equals("getMinExposureOffset")) {
c = 3;
break;
}
c = 65535;
break;
case -1352294148:
if (str.equals("create")) {
c = 4;
break;
}
c = 65535;
break;
case -1313121483:
if (str.equals("lockCaptureOrientation")) {
c = 5;
break;
}
c = 65535;
break;
case -1157944680:
if (str.equals("prepareForVideoRecording")) {
c = 6;
break;
}
c = 65535;
break;
case -1151868548:
if (str.equals("setExposureOffset")) {
c = 7;
break;
}
c = 65535;
break;
case -1127151527:
if (str.equals("setFocusMode")) {
c = '\b';
break;
}
c = 65535;
break;
case -1120721617:
if (str.equals("setZoomLevel")) {
c = '\t';
break;
}
c = 65535;
break;
case -1077837554:
if (str.equals("unlockCaptureOrientation")) {
c = '\n';
break;
}
c = 65535;
break;
case -579183206:
if (str.equals("setFocusPoint")) {
c = 11;
break;
}
c = 65535;
break;
case 109225283:
if (str.equals("resumeVideoRecording")) {
c = '\f';
break;
}
c = 65535;
break;
case 186649688:
if (str.equals("stopVideoRecording")) {
c = '\r';
break;
}
c = 65535;
break;
case 196568648:
if (str.equals("getMaxExposureOffset")) {
c = 14;
break;
}
c = 65535;
break;
case 391927665:
if (str.equals("setFlashMode")) {
c = 15;
break;
}
c = 65535;
break;
case 770486092:
if (str.equals("pauseVideoRecording")) {
c = 16;
break;
}
c = 65535;
break;
case 871091088:
if (str.equals("initialize")) {
c = 17;
break;
}
c = 65535;
break;
case 888134860:
if (str.equals("setExposureMode")) {
c = 18;
break;
}
c = 65535;
break;
case 888641243:
if (str.equals("resumePreview")) {
c = 19;
break;
}
c = 65535;
break;
case 954656505:
if (str.equals("startImageStream")) {
c = 20;
break;
}
c = 65535;
break;
case 1018096247:
if (str.equals("takePicture")) {
c = 21;
break;
}
c = 65535;
break;
case 1120116920:
if (str.equals("startVideoRecording")) {
c = 22;
break;
}
c = 65535;
break;
case 1422316786:
if (str.equals("pausePreview")) {
c = 23;
break;
}
c = 65535;
break;
case 1671767583:
if (str.equals("dispose")) {
c = 24;
break;
}
c = 65535;
break;
case 1672159065:
if (str.equals("stopImageStream")) {
c = 25;
break;
}
c = 65535;
break;
case 1765152647:
if (str.equals("setExposurePoint")) {
c = 26;
break;
}
c = 65535;
break;
case 1838076131:
if (str.equals("getMaxZoomLevel")) {
c = 27;
break;
}
c = 65535;
break;
default:
c = 65535;
break;
}
Double d3 = null;
Double d4 = null;
switch (c) {
case 0:
try {
result.success(CameraUtils.getAvailableCameras(this.activity));
return;
} catch (Exception e) {
handleException(e, result);
return;
}
case 1:
try {
result.success(Float.valueOf(this.camera.getMinZoomLevel()));
return;
} catch (Exception e2) {
handleException(e2, result);
return;
}
case 2:
try {
result.success(Double.valueOf(this.camera.getExposureOffsetStepSize()));
return;
} catch (Exception e3) {
handleException(e3, result);
return;
}
case 3:
try {
result.success(Double.valueOf(this.camera.getMinExposureOffset()));
return;
} catch (Exception e4) {
handleException(e4, result);
return;
}
case 4:
Camera camera = this.camera;
if (camera != null) {
camera.close();
}
this.cameraPermissions.requestPermissions(this.activity, this.permissionsRegistry, ((Boolean) methodCall.argument("enableAudio")).booleanValue(), new CameraPermissions.ResultCallback(this, methodCall, result) { // from class: io.flutter.plugins.camera.MethodCallHandlerImpl$$ExternalSyntheticLambda0
public final MethodCallHandlerImpl f$0;
public final MethodCall f$1;
public final MethodChannel.Result f$2;
@Override // io.flutter.plugins.camera.CameraPermissions.ResultCallback
public final void onResult(String str2, String str3) {
this.f$0.m348x71af31cb(this.f$1, this.f$2, str2, str3);
}
{
this.f$0 = this;
this.f$1 = methodCall;
this.f$2 = result;
}
});
return;
case 5:
try {
this.camera.lockCaptureOrientation(CameraUtils.deserializeDeviceOrientation((String) methodCall.argument("orientation")));
result.success(null);
return;
} catch (Exception e5) {
handleException(e5, result);
return;
}
case 6:
result.success(null);
return;
case 7:
try {
this.camera.setExposureOffset(result, ((Double) methodCall.argument("offset")).doubleValue());
return;
} catch (Exception e6) {
handleException(e6, result);
return;
}
case '\b':
String str2 = (String) methodCall.argument("mode");
FocusMode valueForString = FocusMode.getValueForString(str2);
if (valueForString == null) {
result.error("setFocusModeFailed", "Unknown focus mode ".concat(String.valueOf(str2)), null);
return;
}
try {
this.camera.setFocusMode(result, valueForString);
return;
} catch (Exception e7) {
handleException(e7, result);
return;
}
case '\t':
Double d5 = (Double) methodCall.argument("zoom");
if (d5 == null) {
result.error("ZOOM_ERROR", "setZoomLevel is called without specifying a zoom level.", null);
return;
}
try {
this.camera.setZoomLevel(result, d5.floatValue());
return;
} catch (Exception e8) {
handleException(e8, result);
return;
}
case '\n':
try {
this.camera.unlockCaptureOrientation();
result.success(null);
return;
} catch (Exception e9) {
handleException(e9, result);
return;
}
case 11:
Boolean bool = (Boolean) methodCall.argument("reset");
if (bool == null || !bool.booleanValue()) {
d3 = (Double) methodCall.argument("x");
d = (Double) methodCall.argument("y");
} else {
d = null;
}
try {
this.camera.setFocusPoint(result, new Point(d3, d));
return;
} catch (Exception e10) {
handleException(e10, result);
return;
}
case '\f':
this.camera.resumeVideoRecording(result);
return;
case '\r':
this.camera.stopVideoRecording(result);
return;
case 14:
try {
result.success(Double.valueOf(this.camera.getMaxExposureOffset()));
return;
} catch (Exception e11) {
handleException(e11, result);
return;
}
case 15:
String str3 = (String) methodCall.argument("mode");
FlashMode valueForString2 = FlashMode.getValueForString(str3);
if (valueForString2 == null) {
result.error("setFlashModeFailed", "Unknown flash mode ".concat(String.valueOf(str3)), null);
return;
}
try {
this.camera.setFlashMode(result, valueForString2);
return;
} catch (Exception e12) {
handleException(e12, result);
return;
}
case 16:
this.camera.pauseVideoRecording(result);
return;
case 17:
Camera camera2 = this.camera;
if (camera2 != null) {
try {
camera2.open((String) methodCall.argument("imageFormatGroup"));
result.success(null);
return;
} catch (Exception e13) {
handleException(e13, result);
return;
}
}
result.error("cameraNotFound", "Camera not found. Please call the 'create' method before calling 'initialize'.", null);
return;
case 18:
String str4 = (String) methodCall.argument("mode");
ExposureMode valueForString3 = ExposureMode.getValueForString(str4);
if (valueForString3 == null) {
result.error("setExposureModeFailed", "Unknown exposure mode ".concat(String.valueOf(str4)), null);
return;
}
try {
this.camera.setExposureMode(result, valueForString3);
return;
} catch (Exception e14) {
handleException(e14, result);
return;
}
case 19:
this.camera.resumePreview();
result.success(null);
return;
case 20:
try {
this.camera.startPreviewWithImageStream(this.imageStreamChannel);
result.success(null);
return;
} catch (Exception e15) {
handleException(e15, result);
return;
}
case 21:
this.camera.takePicture(result);
return;
case 22:
this.camera.startVideoRecording(result, Objects.equals(methodCall.argument("enableStream"), Boolean.TRUE) ? this.imageStreamChannel : null);
return;
case 23:
try {
this.camera.pausePreview();
result.success(null);
return;
} catch (Exception e16) {
handleException(e16, result);
return;
}
case 24:
Camera camera3 = this.camera;
if (camera3 != null) {
camera3.dispose();
}
result.success(null);
return;
case 25:
try {
this.camera.startPreview();
result.success(null);
return;
} catch (Exception e17) {
handleException(e17, result);
return;
}
case 26:
Boolean bool2 = (Boolean) methodCall.argument("reset");
if (bool2 == null || !bool2.booleanValue()) {
d4 = (Double) methodCall.argument("x");
d2 = (Double) methodCall.argument("y");
} else {
d2 = null;
}
try {
this.camera.setExposurePoint(result, new Point(d4, d2));
return;
} catch (Exception e18) {
handleException(e18, result);
return;
}
case 27:
try {
result.success(Float.valueOf(this.camera.getMaxZoomLevel()));
return;
} catch (Exception e19) {
handleException(e19, result);
return;
}
default:
result.notImplemented();
return;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: lambda$onMethodCall$0$io-flutter-plugins-camera-MethodCallHandlerImpl, reason: not valid java name */
public final /* synthetic */ void m348x71af31cb(MethodCall methodCall, MethodChannel.Result result, String str, String str2) {
if (str == null) {
try {
instantiateCamera(methodCall, result);
return;
} catch (Exception e) {
handleException(e, result);
return;
}
}
result.error(str, str2, null);
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void stopListening() {
this.methodChannel.setMethodCallHandler(null);
}
private void instantiateCamera(MethodCall methodCall, MethodChannel.Result result) throws CameraAccessException {
String str = (String) methodCall.argument("cameraName");
String str2 = (String) methodCall.argument("resolutionPreset");
boolean booleanValue = ((Boolean) methodCall.argument("enableAudio")).booleanValue();
TextureRegistry.SurfaceTextureEntry createSurfaceTexture = this.textureRegistry.createSurfaceTexture();
this.camera = new Camera(this.activity, createSurfaceTexture, new CameraFeatureFactoryImpl(), new DartMessenger(this.messenger, createSurfaceTexture.id(), new Handler(Looper.getMainLooper())), new CameraPropertiesImpl(str, CameraUtils.getCameraManager(this.activity)), ResolutionPreset.valueOf(str2), booleanValue);
HashMap hashMap = new HashMap();
hashMap.put("cameraId", Long.valueOf(createSurfaceTexture.id()));
result.success(hashMap);
}
private void handleException(Exception exc, MethodChannel.Result result) {
if (exc instanceof CameraAccessException) {
result.error("CameraAccess", exc.getMessage(), null);
return;
}
throw ((RuntimeException) exc);
}
}