diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md
index f678aeef8d3..d6bfb8b94c9 100644
--- a/packages/camera/camera_android_camerax/CHANGELOG.md
+++ b/packages/camera/camera_android_camerax/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.6.15
+
+* Updates internal API wrapper to use ProxyApis.
+
## 0.6.14+1
* Updates compileSdk 34 to flutter.compileSdkVersion.
diff --git a/packages/camera/camera_android_camerax/android/build.gradle b/packages/camera/camera_android_camerax/android/build.gradle
index 8685e8481d0..b9970ae697e 100644
--- a/packages/camera/camera_android_camerax/android/build.gradle
+++ b/packages/camera/camera_android_camerax/android/build.gradle
@@ -2,6 +2,7 @@ group 'io.flutter.plugins.camerax'
version '1.0'
buildscript {
+ ext.kotlin_version = '1.9.10'
repositories {
google()
mavenCentral()
@@ -9,6 +10,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:8.5.0'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
@@ -20,6 +22,7 @@ rootProject.allprojects {
}
apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
android {
namespace 'io.flutter.plugins.camerax'
@@ -31,6 +34,11 @@ android {
targetCompatibility JavaVersion.VERSION_11
}
+ kotlinOptions {
+ // This must match the Java version provided in compileOptions.
+ jvmTarget = '11'
+ }
+
defaultConfig {
// Many of the CameraX APIs require API 21.
minSdkVersion 21
@@ -65,7 +73,8 @@ dependencies {
implementation "androidx.camera:camera-video:${camerax_version}"
implementation 'com.google.guava:guava:33.4.0-android'
testImplementation 'junit:junit:4.13.2'
- testImplementation 'org.mockito:mockito-inline:5.0.0'
+ testImplementation "org.mockito:mockito-core:5.15.2"
+ testImplementation 'org.mockito:mockito-inline:5.1.0'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'org.robolectric:robolectric:4.10.3'
}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerFlutterApiImpl.java
deleted file mode 100644
index 7bdb8626469..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerFlutterApiImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.ImageAnalysis;
-import androidx.camera.core.ImageProxy;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AnalyzerFlutterApi;
-import java.util.Objects;
-
-/**
- * Flutter API implementation for {@link ImageAnalysis.Analyzer}.
- *
- *
This class may handle adding native instances that are attached to a Dart instance or passing
- * arguments of callbacks methods to a Dart instance.
- */
-public class AnalyzerFlutterApiImpl {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
- private AnalyzerFlutterApi api;
-
- /**
- * Constructs a {@link AnalyzerFlutterApiImpl}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- */
- public AnalyzerFlutterApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- api = new AnalyzerFlutterApi(binaryMessenger);
- }
-
- /**
- * Stores the {@link ImageAnalysis.Analyzer} instance and notifies Dart to create and store a new
- * {@code Analyzer} instance that is attached to this one. If {@code instance} has already been
- * added, this method does nothing.
- */
- public void create(
- @NonNull ImageAnalysis.Analyzer instance, @NonNull AnalyzerFlutterApi.Reply callback) {
- if (!instanceManager.containsInstance(instance)) {
- api.create(instanceManager.addHostCreatedInstance(instance), callback);
- }
- }
-
- /**
- * Sends a message to Dart to call {@code Analyzer.analyze} on the Dart object representing
- * `instance`.
- */
- public void analyze(
- @NonNull ImageAnalysis.Analyzer analyzerInstance,
- @NonNull ImageProxy imageProxyInstance,
- @NonNull AnalyzerFlutterApi.Reply callback) {
- api.analyze(
- Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(analyzerInstance)),
- Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(imageProxyInstance)),
- callback);
- }
-
- /**
- * Sets the Flutter API used to send messages to Dart.
- *
- * This is only visible for testing.
- */
- @VisibleForTesting
- void setApi(@NonNull AnalyzerFlutterApi api) {
- this.api = api;
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerHostApiImpl.java
deleted file mode 100644
index fa788a244f9..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerHostApiImpl.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.ImageAnalysis;
-import androidx.camera.core.ImageProxy;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AnalyzerHostApi;
-
-/**
- * Host API implementation for {@link ImageAnalysis.Analyzer}.
- *
- *
This class may handle instantiating and adding native object instances that are attached to a
- * Dart instance or handle method calls on the associated native class or an instance of the class.
- */
-public class AnalyzerHostApiImpl implements AnalyzerHostApi {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
- private final AnalyzerProxy proxy;
-
- /** Proxy for constructor of {@link ImageAnalysis.Analyzer}. */
- @VisibleForTesting
- public static class AnalyzerProxy {
-
- /** Creates an instance of {@link AnalyzerImpl}. */
- @NonNull
- public AnalyzerImpl create(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- return new AnalyzerImpl(binaryMessenger, instanceManager);
- }
- }
-
- /**
- * Implementation of {@link ImageAnalysis.Analyzer} that passes arguments of callback methods to
- * Dart.
- */
- public static class AnalyzerImpl implements ImageAnalysis.Analyzer {
- private BinaryMessenger binaryMessenger;
- private InstanceManager instanceManager;
- private AnalyzerFlutterApiImpl api;
-
- @VisibleForTesting @NonNull public ImageProxyFlutterApiImpl imageProxyApi;
-
- /**
- * Constructs an instance of {@link ImageAnalysis.Analyzer} that passes arguments of callbacks
- * methods to Dart.
- */
- public AnalyzerImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- super();
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- api = new AnalyzerFlutterApiImpl(binaryMessenger, instanceManager);
- imageProxyApi = new ImageProxyFlutterApiImpl(binaryMessenger, instanceManager);
- }
-
- @Override
- public void analyze(@NonNull ImageProxy imageProxy) {
- Long imageFormat = Long.valueOf(imageProxy.getFormat());
- Long imageHeight = Long.valueOf(imageProxy.getHeight());
- Long imageWidth = Long.valueOf(imageProxy.getWidth());
- imageProxyApi.create(imageProxy, imageFormat, imageHeight, imageWidth, reply -> {});
-
- api.analyze(this, imageProxy, reply -> {});
- }
-
- /**
- * Flutter API used to send messages back to Dart.
- *
- *
This is only visible for testing.
- */
- @VisibleForTesting
- void setApi(@NonNull AnalyzerFlutterApiImpl api) {
- this.api = api;
- }
- }
-
- /**
- * Constructs a {@link AnalyzerHostApiImpl}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- */
- public AnalyzerHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this(binaryMessenger, instanceManager, new AnalyzerProxy());
- }
-
- /**
- * Constructs a {@link AnalyzerHostApiImpl}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param proxy proxy for constructor of {@link ImageAnalysis.Analyzer}
- */
- @VisibleForTesting
- AnalyzerHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull InstanceManager instanceManager,
- @NonNull AnalyzerProxy proxy) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- this.proxy = proxy;
- }
-
- /**
- * Creates an {@link AnalyzerProxy} that represents an {@link ImageAnalysis.Analyzer} instance
- * with the specified identifier.
- */
- @Override
- public void create(@NonNull Long identifier) {
- instanceManager.addDartCreatedInstance(
- proxy.create(binaryMessenger, instanceManager), identifier);
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerProxyApi.java
new file mode 100644
index 00000000000..61a217393fd
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AnalyzerProxyApi.java
@@ -0,0 +1,64 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.ImageAnalysis.Analyzer;
+import java.util.Objects;
+
+/**
+ * ProxyApi implementation for {@link Analyzer}. This class may handle instantiating native object
+ * instances that are attached to a Dart instance or handle method calls on the associated native
+ * class or an instance of that class.
+ */
+class AnalyzerProxyApi extends PigeonApiAnalyzer {
+ AnalyzerProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public ProxyApiRegistrar getPigeonRegistrar() {
+ return (ProxyApiRegistrar) super.getPigeonRegistrar();
+ }
+
+ /** Implementation of {@link Analyzer} that passes arguments of callback methods to Dart. */
+ static class AnalyzerImpl implements Analyzer {
+ final AnalyzerProxyApi api;
+
+ AnalyzerImpl(@NonNull AnalyzerProxyApi api) {
+ this.api = api;
+ }
+
+ @Override
+ public void analyze(@NonNull androidx.camera.core.ImageProxy image) {
+ api.getPigeonRegistrar()
+ .runOnMainThread(
+ new ProxyApiRegistrar.FlutterMethodRunnable() {
+ @Override
+ public void run() {
+ api.analyze(
+ AnalyzerImpl.this,
+ image,
+ ResultCompat.asCompatCallback(
+ result -> {
+ if (result.isFailure()) {
+ onFailure(
+ "Analyzer.analyze",
+ Objects.requireNonNull(result.exceptionOrNull()));
+ }
+ return null;
+ }));
+ }
+ });
+ }
+ }
+
+ @NonNull
+ @Override
+ public Analyzer pigeon_defaultConstructor() {
+ return new AnalyzerImpl(this);
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java
deleted file mode 100644
index 7775ffe598d..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.resolutionselector.AspectRatioStrategy;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AspectRatioStrategyHostApi;
-
-/**
- * Host API implementation for {@link AspectRatioStrategy}.
- *
- *
This class handles instantiating and adding native object instances that are attached to a
- * Dart instance or handle method calls on the associated native class or an instance of the class.
- */
-public class AspectRatioStrategyHostApiImpl implements AspectRatioStrategyHostApi {
- private final InstanceManager instanceManager;
- private final AspectRatioStrategyProxy proxy;
-
- /** Proxy for constructor of {@link AspectRatioStrategy}. */
- @VisibleForTesting
- public static class AspectRatioStrategyProxy {
- /** Creates an instance of {@link AspectRatioStrategy}. */
- @NonNull
- public AspectRatioStrategy create(
- @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
- return new AspectRatioStrategy(preferredAspectRatio.intValue(), fallbackRule.intValue());
- }
- }
-
- /**
- * Constructs an {@link AspectRatioStrategyHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- */
- public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) {
- this(instanceManager, new AspectRatioStrategyProxy());
- }
-
- /**
- * Constructs an {@link AspectRatioStrategyHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param proxy proxy for constructor of {@link AspectRatioStrategy}
- */
- @VisibleForTesting
- AspectRatioStrategyHostApiImpl(
- @NonNull InstanceManager instanceManager, @NonNull AspectRatioStrategyProxy proxy) {
- this.instanceManager = instanceManager;
- this.proxy = proxy;
- }
-
- /**
- * Creates an {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback
- * rule specified.
- */
- @Override
- public void create(
- @NonNull Long identifier, @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
- instanceManager.addDartCreatedInstance(
- proxy.create(preferredAspectRatio, fallbackRule), identifier);
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyProxyApi.java
new file mode 100644
index 00000000000..942c2682ecb
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyProxyApi.java
@@ -0,0 +1,88 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.resolutionselector.AspectRatioStrategy;
+
+/**
+ * ProxyApi implementation for {@link AspectRatioStrategy}. This class may handle instantiating
+ * native object instances that are attached to a Dart instance or handle method calls on the
+ * associated native class or an instance of that class.
+ */
+class AspectRatioStrategyProxyApi extends PigeonApiAspectRatioStrategy {
+ AspectRatioStrategyProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public AspectRatioStrategy pigeon_defaultConstructor(
+ @NonNull AspectRatio preferredAspectRatio,
+ @NonNull AspectRatioStrategyFallbackRule fallbackRule) {
+ int nativeAspectRatio = -2;
+ switch (preferredAspectRatio) {
+ case RATIO16TO9:
+ nativeAspectRatio = androidx.camera.core.AspectRatio.RATIO_16_9;
+ break;
+ case RATIO4TO3:
+ nativeAspectRatio = androidx.camera.core.AspectRatio.RATIO_4_3;
+ break;
+ case RATIO_DEFAULT:
+ nativeAspectRatio = androidx.camera.core.AspectRatio.RATIO_DEFAULT;
+ }
+ int nativeFallbackRule = -1;
+ switch (fallbackRule) {
+ case AUTO:
+ nativeFallbackRule = AspectRatioStrategy.FALLBACK_RULE_AUTO;
+ break;
+ case NONE:
+ nativeFallbackRule = AspectRatioStrategy.FALLBACK_RULE_NONE;
+ break;
+ }
+ return new AspectRatioStrategy(nativeAspectRatio, nativeFallbackRule);
+ }
+
+ @NonNull
+ @Override
+ public AspectRatioStrategy ratio_16_9FallbackAutoStrategy() {
+ return AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY;
+ }
+
+ @NonNull
+ @Override
+ public AspectRatioStrategy ratio_4_3FallbackAutoStrategy() {
+ return AspectRatioStrategy.RATIO_4_3_FALLBACK_AUTO_STRATEGY;
+ }
+
+ @NonNull
+ @Override
+ public AspectRatioStrategyFallbackRule getFallbackRule(
+ @NonNull AspectRatioStrategy pigeonInstance) {
+ switch (pigeonInstance.getFallbackRule()) {
+ case AspectRatioStrategy.FALLBACK_RULE_AUTO:
+ return AspectRatioStrategyFallbackRule.AUTO;
+ case AspectRatioStrategy.FALLBACK_RULE_NONE:
+ return AspectRatioStrategyFallbackRule.NONE;
+ }
+
+ return AspectRatioStrategyFallbackRule.UNKNOWN;
+ }
+
+ @NonNull
+ @Override
+ public AspectRatio getPreferredAspectRatio(@NonNull AspectRatioStrategy pigeonInstance) {
+ switch (pigeonInstance.getPreferredAspectRatio()) {
+ case androidx.camera.core.AspectRatio.RATIO_16_9:
+ return AspectRatio.RATIO16TO9;
+ case androidx.camera.core.AspectRatio.RATIO_4_3:
+ return AspectRatio.RATIO4TO3;
+ case androidx.camera.core.AspectRatio.RATIO_DEFAULT:
+ return AspectRatio.RATIO_DEFAULT;
+ }
+
+ return AspectRatio.UNKNOWN;
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlHostApiImpl.java
deleted file mode 100644
index 300310d6c9d..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlHostApiImpl.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import android.content.Context;
-import androidx.annotation.NonNull;
-import androidx.annotation.OptIn;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.camera2.interop.Camera2CameraControl;
-import androidx.camera.camera2.interop.CaptureRequestOptions;
-import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
-import androidx.camera.core.CameraControl;
-import androidx.core.content.ContextCompat;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Camera2CameraControlHostApi;
-import java.util.Objects;
-
-/**
- * Host API implementation for {@link Camera2CameraControl}.
- *
- *
This class may handle instantiating and adding native object instances that are attached to a
- * Dart instance or handle method calls on the associated native class or an instance of the class.
- */
-public class Camera2CameraControlHostApiImpl implements Camera2CameraControlHostApi {
- private final InstanceManager instanceManager;
- private final Camera2CameraControlProxy proxy;
-
- /** Proxy for constructor and methods of {@link Camera2CameraControl}. */
- @VisibleForTesting
- public static class Camera2CameraControlProxy {
- Context context;
-
- /**
- * Creates an instance of {@link Camera2CameraControl} derived from specified {@link
- * CameraControl} instance.
- */
- @OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)
- public @NonNull Camera2CameraControl create(@NonNull CameraControl cameraControl) {
- return Camera2CameraControl.from(cameraControl);
- }
-
- /**
- * Adds a {@link CaptureRequestOptions} to update the capture session with the options it
- * contains.
- */
- @OptIn(markerClass = androidx.camera.camera2.interop.ExperimentalCamera2Interop.class)
- public void addCaptureRequestOptions(
- @NonNull Camera2CameraControl camera2CameraControl,
- @NonNull CaptureRequestOptions bundle,
- @NonNull GeneratedCameraXLibrary.Result result) {
- if (context == null) {
- throw new IllegalStateException("Context must be set to add capture request options.");
- }
-
- ListenableFuture addCaptureRequestOptionsFuture =
- camera2CameraControl.addCaptureRequestOptions(bundle);
-
- Futures.addCallback(
- addCaptureRequestOptionsFuture,
- new FutureCallback() {
- public void onSuccess(Void voidResult) {
- result.success(null);
- }
-
- public void onFailure(Throwable t) {
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
- }
-
- /**
- * Constructs a {@link Camera2CameraControlHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param context {@link Context} used to retrieve {@code Executor}
- */
- public Camera2CameraControlHostApiImpl(
- @NonNull InstanceManager instanceManager, @NonNull Context context) {
- this(instanceManager, new Camera2CameraControlProxy(), context);
- }
-
- /**
- * Constructs a {@link Camera2CameraControlHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param proxy proxy for constructor and methods of {@link Camera2CameraControl}
- * @param context {@link Context} used to retrieve {@code Executor}
- */
- @VisibleForTesting
- Camera2CameraControlHostApiImpl(
- @NonNull InstanceManager instanceManager,
- @NonNull Camera2CameraControlProxy proxy,
- @NonNull Context context) {
- this.instanceManager = instanceManager;
- this.proxy = proxy;
- proxy.context = context;
- }
-
- /**
- * Sets the context that the {@code Camera2CameraControl} will use to listen for the result of
- * setting capture request options.
- *
- * If using the camera plugin in an add-to-app context, ensure that this is called anytime that
- * the context changes.
- */
- public void setContext(@NonNull Context context) {
- this.proxy.context = context;
- }
-
- @Override
- public void create(@NonNull Long identifier, @NonNull Long cameraControlIdentifier) {
- instanceManager.addDartCreatedInstance(
- proxy.create(Objects.requireNonNull(instanceManager.getInstance(cameraControlIdentifier))),
- identifier);
- }
-
- @Override
- public void addCaptureRequestOptions(
- @NonNull Long identifier,
- @NonNull Long captureRequestOptionsIdentifier,
- @NonNull GeneratedCameraXLibrary.Result result) {
- proxy.addCaptureRequestOptions(
- getCamera2CameraControlInstance(identifier),
- Objects.requireNonNull(instanceManager.getInstance(captureRequestOptionsIdentifier)),
- result);
- }
-
- /**
- * Retrieves the {@link Camera2CameraControl} instance associated with the specified {@code
- * identifier}.
- */
- @OptIn(markerClass = ExperimentalCamera2Interop.class)
- private Camera2CameraControl getCamera2CameraControlInstance(@NonNull Long identifier) {
- return Objects.requireNonNull(instanceManager.getInstance(identifier));
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlProxyApi.java
new file mode 100644
index 00000000000..4d41de7e4e9
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraControlProxyApi.java
@@ -0,0 +1,65 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.OptIn;
+import androidx.camera.camera2.interop.Camera2CameraControl;
+import androidx.camera.camera2.interop.CaptureRequestOptions;
+import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
+import androidx.camera.core.CameraControl;
+import androidx.core.content.ContextCompat;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import kotlin.Result;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function1;
+
+/**
+ * ProxyApi implementation for {@link Camera2CameraControl}. This class may handle instantiating
+ * native object instances that are attached to a Dart instance or handle method calls on the
+ * associated native class or an instance of that class.
+ */
+@OptIn(markerClass = ExperimentalCamera2Interop.class)
+class Camera2CameraControlProxyApi extends PigeonApiCamera2CameraControl {
+ Camera2CameraControlProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public ProxyApiRegistrar getPigeonRegistrar() {
+ return (ProxyApiRegistrar) super.getPigeonRegistrar();
+ }
+
+ @NonNull
+ @Override
+ public Camera2CameraControl from(@NonNull CameraControl cameraControl) {
+ return Camera2CameraControl.from(cameraControl);
+ }
+
+ @Override
+ public void addCaptureRequestOptions(
+ @NonNull Camera2CameraControl pigeonInstance,
+ @NonNull CaptureRequestOptions bundle,
+ @NonNull Function1 super Result, Unit> callback) {
+ final ListenableFuture addCaptureRequestOptionsFuture =
+ pigeonInstance.addCaptureRequestOptions(bundle);
+
+ Futures.addCallback(
+ addCaptureRequestOptionsFuture,
+ new FutureCallback<>() {
+ public void onSuccess(Void voidResult) {
+ ResultCompat.success(null, callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java
deleted file mode 100644
index 58769ab400f..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoFlutterApiImpl.java
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.OptIn;
-import androidx.camera.camera2.interop.Camera2CameraInfo;
-import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Camera2CameraInfoFlutterApi;
-
-public class Camera2CameraInfoFlutterApiImpl extends Camera2CameraInfoFlutterApi {
- private final InstanceManager instanceManager;
-
- public Camera2CameraInfoFlutterApiImpl(
- @Nullable BinaryMessenger binaryMessenger, @Nullable InstanceManager instanceManager) {
- super(binaryMessenger);
- this.instanceManager = instanceManager;
- }
-
- @OptIn(markerClass = ExperimentalCamera2Interop.class)
- void create(@NonNull Camera2CameraInfo camera2CameraInfo, @Nullable Reply reply) {
- if (!instanceManager.containsInstance(camera2CameraInfo)) {
- create(instanceManager.addHostCreatedInstance(camera2CameraInfo), reply);
- }
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java
deleted file mode 100644
index 983e9e0c674..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoHostApiImpl.java
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import android.content.Context;
-import android.hardware.camera2.CameraCharacteristics;
-import androidx.annotation.NonNull;
-import androidx.annotation.OptIn;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.camera2.interop.Camera2CameraInfo;
-import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
-import androidx.camera.core.CameraInfo;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Camera2CameraInfoHostApi;
-import java.util.Objects;
-
-/**
- * Host API implementation for {@link Camera2CameraInfo}.
- *
- * This class handles instantiating and adding native object instances that are attached to a
- * Dart instance or handle method calls on the associated native class or an instance of the class.
- */
-public class Camera2CameraInfoHostApiImpl implements Camera2CameraInfoHostApi {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
- private final Camera2CameraInfoProxy proxy;
-
- /** Proxy for methods of {@link Camera2CameraInfo}. */
- @VisibleForTesting
- @OptIn(markerClass = ExperimentalCamera2Interop.class)
- public static class Camera2CameraInfoProxy {
-
- @NonNull
- public Camera2CameraInfo createFrom(@NonNull CameraInfo cameraInfo) {
- return Camera2CameraInfo.from(cameraInfo);
- }
-
- @NonNull
- public Integer getSupportedHardwareLevel(@NonNull Camera2CameraInfo camera2CameraInfo) {
- return camera2CameraInfo.getCameraCharacteristic(
- CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
- }
-
- @NonNull
- public String getCameraId(@NonNull Camera2CameraInfo camera2CameraInfo) {
- return camera2CameraInfo.getCameraId();
- }
-
- @NonNull
- public Long getSensorOrientation(@NonNull Camera2CameraInfo camera2CameraInfo) {
- return Long.valueOf(
- camera2CameraInfo.getCameraCharacteristic(CameraCharacteristics.SENSOR_ORIENTATION));
- }
- }
-
- /**
- * Constructs an {@link Camera2CameraInfoHostApiImpl}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param context {@link Context} used to retrieve {@code Executor}
- */
- public Camera2CameraInfoHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this(binaryMessenger, instanceManager, new Camera2CameraInfoProxy());
- }
-
- /**
- * Constructs an {@link Camera2CameraInfoHostApiImpl}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param proxy proxy for methods of {@link Camera2CameraInfo}
- */
- @VisibleForTesting
- Camera2CameraInfoHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull InstanceManager instanceManager,
- @NonNull Camera2CameraInfoProxy proxy) {
- this.instanceManager = instanceManager;
- this.binaryMessenger = binaryMessenger;
- this.proxy = proxy;
- }
-
- @OptIn(markerClass = ExperimentalCamera2Interop.class)
- @Override
- @NonNull
- public Long createFrom(@NonNull Long cameraInfoIdentifier) {
- final CameraInfo cameraInfo =
- Objects.requireNonNull(instanceManager.getInstance(cameraInfoIdentifier));
- final Camera2CameraInfo camera2CameraInfo = proxy.createFrom(cameraInfo);
- final Camera2CameraInfoFlutterApiImpl flutterApi =
- new Camera2CameraInfoFlutterApiImpl(binaryMessenger, instanceManager);
-
- flutterApi.create(camera2CameraInfo, reply -> {});
- return instanceManager.getIdentifierForStrongReference(camera2CameraInfo);
- }
-
- @Override
- @NonNull
- public Long getSupportedHardwareLevel(@NonNull Long identifier) {
- return Long.valueOf(proxy.getSupportedHardwareLevel(getCamera2CameraInfoInstance(identifier)));
- }
-
- @Override
- @NonNull
- public String getCameraId(@NonNull Long identifier) {
- return proxy.getCameraId(getCamera2CameraInfoInstance(identifier));
- }
-
- @Override
- @NonNull
- public Long getSensorOrientation(@NonNull Long identifier) {
- return proxy.getSensorOrientation(getCamera2CameraInfoInstance(identifier));
- }
-
- @OptIn(markerClass = ExperimentalCamera2Interop.class)
- private Camera2CameraInfo getCamera2CameraInfoInstance(@NonNull Long identifier) {
- return Objects.requireNonNull(instanceManager.getInstance(identifier));
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoProxyApi.java
new file mode 100644
index 00000000000..f9ee09c07b8
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/Camera2CameraInfoProxyApi.java
@@ -0,0 +1,65 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import android.hardware.camera2.CameraCharacteristics;
+import android.hardware.camera2.CameraMetadata;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.OptIn;
+import androidx.camera.camera2.interop.Camera2CameraInfo;
+import androidx.camera.camera2.interop.ExperimentalCamera2Interop;
+import androidx.camera.core.CameraInfo;
+
+/**
+ * ProxyApi implementation for {@link Camera2CameraInfo}. This class may handle instantiating native
+ * object instances that are attached to a Dart instance or handle method calls on the associated
+ * native class or an instance of that class.
+ */
+@OptIn(markerClass = ExperimentalCamera2Interop.class)
+class Camera2CameraInfoProxyApi extends PigeonApiCamera2CameraInfo {
+ Camera2CameraInfoProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public Camera2CameraInfo from(@NonNull CameraInfo cameraInfo) {
+ return Camera2CameraInfo.from(cameraInfo);
+ }
+
+ @NonNull
+ @Override
+ public String getCameraId(Camera2CameraInfo pigeonInstance) {
+ return pigeonInstance.getCameraId();
+ }
+
+ @Nullable
+ @Override
+ public Object getCameraCharacteristic(
+ Camera2CameraInfo pigeonInstance, @NonNull CameraCharacteristics.Key> key) {
+ final Object result = pigeonInstance.getCameraCharacteristic(key);
+ if (result == null) {
+ return null;
+ }
+
+ if (key == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) {
+ switch ((Integer) result) {
+ case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_3:
+ return InfoSupportedHardwareLevel.LEVEL3;
+ case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL:
+ return InfoSupportedHardwareLevel.EXTERNAL;
+ case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
+ return InfoSupportedHardwareLevel.FULL;
+ case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
+ return InfoSupportedHardwareLevel.LEGACY;
+ case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
+ return InfoSupportedHardwareLevel.LIMITED;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java
index 42e5df0f32c..b1f5c4f1893 100644
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java
@@ -4,41 +4,17 @@
package io.flutter.plugins.camerax;
-import android.app.Activity;
-import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
-import androidx.lifecycle.LifecycleOwner;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.view.TextureRegistry;
/** Platform implementation of the camera_plugin implemented with the CameraX library. */
public final class CameraAndroidCameraxPlugin implements FlutterPlugin, ActivityAware {
- private InstanceManager instanceManager;
private FlutterPluginBinding pluginBinding;
- @VisibleForTesting @Nullable public PendingRecordingHostApiImpl pendingRecordingHostApiImpl;
- @VisibleForTesting @Nullable public RecorderHostApiImpl recorderHostApiImpl;
- @VisibleForTesting @Nullable public VideoCaptureHostApiImpl videoCaptureHostApiImpl;
- @VisibleForTesting @Nullable public ImageAnalysisHostApiImpl imageAnalysisHostApiImpl;
- @VisibleForTesting @Nullable public ImageCaptureHostApiImpl imageCaptureHostApiImpl;
- @VisibleForTesting @Nullable public CameraControlHostApiImpl cameraControlHostApiImpl;
- @VisibleForTesting @Nullable public SystemServicesHostApiImpl systemServicesHostApiImpl;
- @VisibleForTesting @Nullable public MeteringPointHostApiImpl meteringPointHostApiImpl;
-
- @VisibleForTesting @Nullable
- public Camera2CameraControlHostApiImpl camera2CameraControlHostApiImpl;
-
- @VisibleForTesting
- public @Nullable DeviceOrientationManagerHostApiImpl deviceOrientationManagerHostApiImpl;
-
- @VisibleForTesting
- public @Nullable ProcessCameraProviderHostApiImpl processCameraProviderHostApiImpl;
-
- @VisibleForTesting public @Nullable LiveDataHostApiImpl liveDataHostApiImpl;
+ @VisibleForTesting @Nullable ProxyApiRegistrar proxyApiRegistrar;
/**
* Initialize this within the {@code #configureFlutterEngine} of a Flutter activity or fragment.
@@ -47,108 +23,25 @@ public final class CameraAndroidCameraxPlugin implements FlutterPlugin, Activity
*/
public CameraAndroidCameraxPlugin() {}
- @VisibleForTesting
- public void setUp(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull Context context,
- @NonNull TextureRegistry textureRegistry) {
- // Set up instance manager.
- instanceManager =
- InstanceManager.create(
- identifier -> {
- new GeneratedCameraXLibrary.JavaObjectFlutterApi(binaryMessenger)
- .dispose(identifier, reply -> {});
- });
-
- // Set up Host APIs.
- GeneratedCameraXLibrary.InstanceManagerHostApi.setup(
- binaryMessenger, () -> instanceManager.clear());
- GeneratedCameraXLibrary.CameraHostApi.setup(
- binaryMessenger, new CameraHostApiImpl(binaryMessenger, instanceManager));
- GeneratedCameraXLibrary.CameraInfoHostApi.setup(
- binaryMessenger, new CameraInfoHostApiImpl(binaryMessenger, instanceManager));
- GeneratedCameraXLibrary.CameraSelectorHostApi.setup(
- binaryMessenger, new CameraSelectorHostApiImpl(binaryMessenger, instanceManager));
- GeneratedCameraXLibrary.JavaObjectHostApi.setup(
- binaryMessenger, new JavaObjectHostApiImpl(instanceManager));
- processCameraProviderHostApiImpl =
- new ProcessCameraProviderHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.ProcessCameraProviderHostApi.setup(
- binaryMessenger, processCameraProviderHostApiImpl);
- systemServicesHostApiImpl =
- new SystemServicesHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.SystemServicesHostApi.setup(binaryMessenger, systemServicesHostApiImpl);
- deviceOrientationManagerHostApiImpl =
- new DeviceOrientationManagerHostApiImpl(binaryMessenger, instanceManager);
- GeneratedCameraXLibrary.DeviceOrientationManagerHostApi.setup(
- binaryMessenger, deviceOrientationManagerHostApiImpl);
- GeneratedCameraXLibrary.PreviewHostApi.setup(
- binaryMessenger, new PreviewHostApiImpl(binaryMessenger, instanceManager, textureRegistry));
- imageCaptureHostApiImpl =
- new ImageCaptureHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.ImageCaptureHostApi.setup(binaryMessenger, imageCaptureHostApiImpl);
- GeneratedCameraXLibrary.CameraHostApi.setup(
- binaryMessenger, new CameraHostApiImpl(binaryMessenger, instanceManager));
- liveDataHostApiImpl = new LiveDataHostApiImpl(binaryMessenger, instanceManager);
- GeneratedCameraXLibrary.LiveDataHostApi.setup(binaryMessenger, liveDataHostApiImpl);
- GeneratedCameraXLibrary.ObserverHostApi.setup(
- binaryMessenger, new ObserverHostApiImpl(binaryMessenger, instanceManager));
- imageAnalysisHostApiImpl =
- new ImageAnalysisHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.ImageAnalysisHostApi.setup(binaryMessenger, imageAnalysisHostApiImpl);
- GeneratedCameraXLibrary.AnalyzerHostApi.setup(
- binaryMessenger, new AnalyzerHostApiImpl(binaryMessenger, instanceManager));
- GeneratedCameraXLibrary.ImageProxyHostApi.setup(
- binaryMessenger, new ImageProxyHostApiImpl(binaryMessenger, instanceManager));
- GeneratedCameraXLibrary.RecordingHostApi.setup(
- binaryMessenger, new RecordingHostApiImpl(binaryMessenger, instanceManager));
- recorderHostApiImpl = new RecorderHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.RecorderHostApi.setup(binaryMessenger, recorderHostApiImpl);
- pendingRecordingHostApiImpl =
- new PendingRecordingHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.PendingRecordingHostApi.setup(
- binaryMessenger, pendingRecordingHostApiImpl);
- videoCaptureHostApiImpl = new VideoCaptureHostApiImpl(binaryMessenger, instanceManager);
- GeneratedCameraXLibrary.VideoCaptureHostApi.setup(binaryMessenger, videoCaptureHostApiImpl);
- GeneratedCameraXLibrary.ResolutionSelectorHostApi.setup(
- binaryMessenger, new ResolutionSelectorHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.ResolutionStrategyHostApi.setup(
- binaryMessenger, new ResolutionStrategyHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.AspectRatioStrategyHostApi.setup(
- binaryMessenger, new AspectRatioStrategyHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.FallbackStrategyHostApi.setup(
- binaryMessenger, new FallbackStrategyHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.QualitySelectorHostApi.setup(
- binaryMessenger, new QualitySelectorHostApiImpl(instanceManager));
- cameraControlHostApiImpl =
- new CameraControlHostApiImpl(binaryMessenger, instanceManager, context);
- GeneratedCameraXLibrary.CameraControlHostApi.setup(binaryMessenger, cameraControlHostApiImpl);
- camera2CameraControlHostApiImpl = new Camera2CameraControlHostApiImpl(instanceManager, context);
- GeneratedCameraXLibrary.Camera2CameraControlHostApi.setup(
- binaryMessenger, camera2CameraControlHostApiImpl);
- GeneratedCameraXLibrary.CaptureRequestOptionsHostApi.setup(
- binaryMessenger, new CaptureRequestOptionsHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.FocusMeteringActionHostApi.setup(
- binaryMessenger, new FocusMeteringActionHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.FocusMeteringResultHostApi.setup(
- binaryMessenger, new FocusMeteringResultHostApiImpl(instanceManager));
- meteringPointHostApiImpl = new MeteringPointHostApiImpl(instanceManager);
- GeneratedCameraXLibrary.MeteringPointHostApi.setup(binaryMessenger, meteringPointHostApiImpl);
- GeneratedCameraXLibrary.ResolutionFilterHostApi.setup(
- binaryMessenger, new ResolutionFilterHostApiImpl(instanceManager));
- GeneratedCameraXLibrary.Camera2CameraInfoHostApi.setup(
- binaryMessenger, new Camera2CameraInfoHostApiImpl(binaryMessenger, instanceManager));
- }
-
@Override
- public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
- pluginBinding = flutterPluginBinding;
+ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
+ pluginBinding = binding;
+
+ proxyApiRegistrar =
+ new ProxyApiRegistrar(
+ binding.getBinaryMessenger(),
+ binding.getApplicationContext(),
+ binding.getTextureRegistry());
+ proxyApiRegistrar.setUp();
}
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
- if (instanceManager != null) {
- instanceManager.stopFinalizationListener();
+ if (proxyApiRegistrar != null) {
+ proxyApiRegistrar.setIgnoreCallsToDart(true);
+ proxyApiRegistrar.tearDown();
+ proxyApiRegistrar.getInstanceManager().stopFinalizationListener();
+ proxyApiRegistrar = null;
}
}
@@ -156,112 +49,37 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
@Override
public void onAttachedToActivity(@NonNull ActivityPluginBinding activityPluginBinding) {
- Activity activity = activityPluginBinding.getActivity();
-
- // Set up Host API implementations based on the context that `activity` provides.
- setUp(pluginBinding.getBinaryMessenger(), activity, pluginBinding.getTextureRegistry());
-
- // Set any needed references to `activity` itself.
- updateLifecycleOwner(activity);
- updateActivity(activity);
-
- // Set permissions registry reference.
- systemServicesHostApiImpl.setPermissionsRegistry(
- activityPluginBinding::addRequestPermissionsResultListener);
+ if (proxyApiRegistrar != null) {
+ proxyApiRegistrar.setContext(activityPluginBinding.getActivity());
+ proxyApiRegistrar.setPermissionsRegistry(
+ activityPluginBinding::addRequestPermissionsResultListener);
+ }
}
@Override
public void onDetachedFromActivityForConfigChanges() {
- // Clear any references to previously attached `ActivityPluginBinding`/`Activity`.
- updateContext(pluginBinding.getApplicationContext());
- updateLifecycleOwner(null);
- updateActivity(null);
- systemServicesHostApiImpl.setPermissionsRegistry(null);
+ if (proxyApiRegistrar != null) {
+ proxyApiRegistrar.setContext(pluginBinding.getApplicationContext());
+ proxyApiRegistrar.setPermissionsRegistry(null);
+ }
}
@Override
public void onReattachedToActivityForConfigChanges(
@NonNull ActivityPluginBinding activityPluginBinding) {
- Activity activity = activityPluginBinding.getActivity();
-
- // Set any needed references to `activity` itself or its context.
- updateContext(activity);
- updateLifecycleOwner(activity);
- updateActivity(activity);
-
- // Set permissions registry reference.
- systemServicesHostApiImpl.setPermissionsRegistry(
- activityPluginBinding::addRequestPermissionsResultListener);
+ if (proxyApiRegistrar != null) {
+ proxyApiRegistrar.setContext(activityPluginBinding.getActivity());
+ proxyApiRegistrar.setPermissionsRegistry(
+ activityPluginBinding::addRequestPermissionsResultListener);
+ }
}
@Override
public void onDetachedFromActivity() {
// Clear any references to previously attached `ActivityPluginBinding`/`Activity`.
- updateContext(pluginBinding.getApplicationContext());
- updateLifecycleOwner(null);
- updateActivity(null);
- systemServicesHostApiImpl.setPermissionsRegistry(null);
- }
-
- /**
- * Updates context that is used to fetch the corresponding instance of a {@code
- * ProcessCameraProvider} to each of the relevant camera controls.
- */
- public void updateContext(@NonNull Context context) {
- if (processCameraProviderHostApiImpl != null) {
- processCameraProviderHostApiImpl.setContext(context);
- }
- if (recorderHostApiImpl != null) {
- recorderHostApiImpl.setContext(context);
- }
- if (pendingRecordingHostApiImpl != null) {
- pendingRecordingHostApiImpl.setContext(context);
- }
- if (systemServicesHostApiImpl != null) {
- systemServicesHostApiImpl.setContext(context);
- }
- if (imageCaptureHostApiImpl != null) {
- imageCaptureHostApiImpl.setContext(context);
- }
- if (imageAnalysisHostApiImpl != null) {
- imageAnalysisHostApiImpl.setContext(context);
- }
- if (cameraControlHostApiImpl != null) {
- cameraControlHostApiImpl.setContext(context);
- }
- if (camera2CameraControlHostApiImpl != null) {
- camera2CameraControlHostApiImpl.setContext(context);
- }
- }
-
- /** Sets {@code LifecycleOwner} that is used to control the lifecycle of the camera by CameraX. */
- public void updateLifecycleOwner(@Nullable Activity activity) {
- if (activity == null) {
- processCameraProviderHostApiImpl.setLifecycleOwner(null);
- liveDataHostApiImpl.setLifecycleOwner(null);
- } else if (activity instanceof LifecycleOwner) {
- processCameraProviderHostApiImpl.setLifecycleOwner((LifecycleOwner) activity);
- liveDataHostApiImpl.setLifecycleOwner((LifecycleOwner) activity);
- } else {
- ProxyLifecycleProvider proxyLifecycleProvider = new ProxyLifecycleProvider(activity);
- processCameraProviderHostApiImpl.setLifecycleOwner(proxyLifecycleProvider);
- liveDataHostApiImpl.setLifecycleOwner(proxyLifecycleProvider);
- }
- }
-
- /**
- * Updates {@code Activity} that is used for requesting camera permissions and tracking the
- * orientation of the device.
- */
- public void updateActivity(@Nullable Activity activity) {
- if (systemServicesHostApiImpl != null) {
- systemServicesHostApiImpl.setActivity(activity);
- }
- if (deviceOrientationManagerHostApiImpl != null) {
- deviceOrientationManagerHostApiImpl.setActivity(activity);
- }
- if (meteringPointHostApiImpl != null) {
- meteringPointHostApiImpl.setActivity(activity);
+ if (proxyApiRegistrar != null) {
+ proxyApiRegistrar.setContext(pluginBinding.getApplicationContext());
+ proxyApiRegistrar.setPermissionsRegistry(null);
}
}
}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraCharacteristicsProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraCharacteristicsProxyApi.java
new file mode 100644
index 00000000000..5cab2f35e69
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraCharacteristicsProxyApi.java
@@ -0,0 +1,31 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import android.hardware.camera2.CameraCharacteristics;
+import androidx.annotation.NonNull;
+
+/**
+ * ProxyApi implementation for {@link CameraCharacteristics}. This class may handle instantiating
+ * native object instances that are attached to a Dart instance or handle method calls on the
+ * associated native class or an instance of that class.
+ */
+class CameraCharacteristicsProxyApi extends PigeonApiCameraCharacteristics {
+ CameraCharacteristicsProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public CameraCharacteristics.Key> infoSupportedHardwareLevel() {
+ return CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL;
+ }
+
+ @NonNull
+ @Override
+ public android.hardware.camera2.CameraCharacteristics.Key> sensorOrientation() {
+ return CameraCharacteristics.SENSOR_ORIENTATION;
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlFlutterApiImpl.java
deleted file mode 100644
index 1b616180ec7..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlFlutterApiImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.camera.core.CameraControl;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraControlFlutterApi;
-
-public class CameraControlFlutterApiImpl extends CameraControlFlutterApi {
- private final @NonNull InstanceManager instanceManager;
-
- public CameraControlFlutterApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- super(binaryMessenger);
- this.instanceManager = instanceManager;
- }
-
- /**
- * Creates a {@link CameraControl} instance in Dart. {@code reply} is not used so it can be empty.
- */
- void create(CameraControl cameraControl, Reply reply) {
- if (!instanceManager.containsInstance(cameraControl)) {
- create(instanceManager.addHostCreatedInstance(cameraControl), reply);
- }
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlHostApiImpl.java
deleted file mode 100644
index ba4318a8927..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlHostApiImpl.java
+++ /dev/null
@@ -1,284 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import android.content.Context;
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.CameraControl;
-import androidx.camera.core.FocusMeteringAction;
-import androidx.camera.core.FocusMeteringResult;
-import androidx.core.content.ContextCompat;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraControlHostApi;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.Result;
-import java.util.Objects;
-
-/**
- * Host API implementation for {@link CameraControl}.
- *
- * This class handles instantiating and adding native object instances that are attached to a
- * Dart instance or handle method calls on the associated native class or an instance of the class.
- */
-public class CameraControlHostApiImpl implements CameraControlHostApi {
- private final InstanceManager instanceManager;
- private final CameraControlProxy proxy;
-
- /** Proxy for methods of {@link CameraControl}. */
- @VisibleForTesting
- public static class CameraControlProxy {
- Context context;
- BinaryMessenger binaryMessenger;
- InstanceManager instanceManager;
-
- /** Enables or disables the torch of the specified {@link CameraControl} instance. */
- @NonNull
- public void enableTorch(
- @NonNull CameraControl cameraControl,
- @NonNull Boolean torch,
- @NonNull GeneratedCameraXLibrary.Result result) {
- if (context == null) {
- throw new IllegalStateException("Context must be set to enable the torch.");
- }
-
- ListenableFuture enableTorchFuture = cameraControl.enableTorch(torch);
-
- Futures.addCallback(
- enableTorchFuture,
- new FutureCallback() {
- public void onSuccess(Void voidResult) {
- result.success(null);
- }
-
- public void onFailure(Throwable t) {
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
-
- /** Sets the zoom ratio of the specified {@link CameraControl} instance. */
- @NonNull
- public void setZoomRatio(
- @NonNull CameraControl cameraControl,
- @NonNull Double ratio,
- @NonNull GeneratedCameraXLibrary.Result result) {
- if (context == null) {
- throw new IllegalStateException("Context must be set to set zoom ratio.");
- }
-
- float ratioAsFloat = ratio.floatValue();
- ListenableFuture setZoomRatioFuture = cameraControl.setZoomRatio(ratioAsFloat);
-
- Futures.addCallback(
- setZoomRatioFuture,
- new FutureCallback() {
- public void onSuccess(Void voidResult) {
- result.success(null);
- }
-
- public void onFailure(Throwable t) {
- if (t instanceof CameraControl.OperationCanceledException) {
- // Operation was canceled due to camera being closed or a new request was submitted, which
- // is not actionable and should not block a new value from potentially being submitted.
- result.success(null);
- return;
- }
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
-
- /**
- * Starts a focus and metering action configured by the {@code FocusMeteringAction}.
- *
- * Will trigger an auto focus action and enable auto focus/auto exposure/auto white balance
- * metering regions.
- *
- *
Will send a {@link GeneratedCameraXLibrary.Result} with a null result if operation was
- * canceled.
- */
- public void startFocusAndMetering(
- @NonNull CameraControl cameraControl,
- @NonNull FocusMeteringAction focusMeteringAction,
- @NonNull GeneratedCameraXLibrary.Result result) {
- if (context == null) {
- throw new IllegalStateException("Context must be set to set zoom ratio.");
- }
-
- ListenableFuture focusMeteringResultFuture =
- cameraControl.startFocusAndMetering(focusMeteringAction);
-
- Futures.addCallback(
- focusMeteringResultFuture,
- new FutureCallback() {
- public void onSuccess(FocusMeteringResult focusMeteringResult) {
- final FocusMeteringResultFlutterApiImpl flutterApi =
- new FocusMeteringResultFlutterApiImpl(binaryMessenger, instanceManager);
- flutterApi.create(focusMeteringResult, reply -> {});
- result.success(instanceManager.getIdentifierForStrongReference(focusMeteringResult));
- }
-
- public void onFailure(Throwable t) {
- if (t instanceof CameraControl.OperationCanceledException) {
- // Operation was canceled due to camera being closed or a new request was submitted, which
- // is not actionable and should not block a new value from potentially being submitted.
- result.success(null);
- return;
- }
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
-
- /**
- * Cancels current {@code FocusMeteringAction} and clears auto focus/auto exposure/auto white
- * balance regions.
- */
- public void cancelFocusAndMetering(
- @NonNull CameraControl cameraControl, @NonNull Result result) {
- ListenableFuture cancelFocusAndMeteringFuture = cameraControl.cancelFocusAndMetering();
-
- Futures.addCallback(
- cancelFocusAndMeteringFuture,
- new FutureCallback() {
- public void onSuccess(Void voidResult) {
- result.success(null);
- }
-
- public void onFailure(Throwable t) {
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
-
- /**
- * Sets the exposure compensation index for the specified {@link CameraControl} instance and
- * returns the new target exposure value.
- *
- * The exposure compensation value set on the camera must be within the range of {@code
- * ExposureState#getExposureCompensationRange()} for the current {@code ExposureState} for the
- * call to succeed.
- *
- *
Will send a {@link GeneratedCameraXLibrary.Result} with a null result if operation was
- * canceled.
- */
- public void setExposureCompensationIndex(
- @NonNull CameraControl cameraControl, @NonNull Long index, @NonNull Result result) {
- ListenableFuture setExposureCompensationIndexFuture =
- cameraControl.setExposureCompensationIndex(index.intValue());
-
- Futures.addCallback(
- setExposureCompensationIndexFuture,
- new FutureCallback() {
- public void onSuccess(Integer integerResult) {
- result.success(integerResult.longValue());
- }
-
- public void onFailure(Throwable t) {
- if (t instanceof CameraControl.OperationCanceledException) {
- // Operation was canceled due to camera being closed or a new request was submitted, which
- // is not actionable and should not block a new value from potentially being submitted.
- result.success(null);
- return;
- }
- result.error(t);
- }
- },
- ContextCompat.getMainExecutor(context));
- }
- }
-
- /**
- * Constructs an {@link CameraControlHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param context {@link Context} used to retrieve {@code Executor}
- */
- public CameraControlHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull InstanceManager instanceManager,
- @NonNull Context context) {
- this(binaryMessenger, instanceManager, new CameraControlProxy(), context);
- }
-
- /**
- * Constructs an {@link CameraControlHostApiImpl}.
- *
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- * @param proxy proxy for methods of {@link CameraControl}
- * @param context {@link Context} used to retrieve {@code Executor}
- */
- @VisibleForTesting
- CameraControlHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger,
- @NonNull InstanceManager instanceManager,
- @NonNull CameraControlProxy proxy,
- @NonNull Context context) {
- this.instanceManager = instanceManager;
- this.proxy = proxy;
- proxy.context = context;
- // proxy.startFocusAndMetering needs to access these to create a FocusMeteringResult when it becomes available:
- proxy.instanceManager = instanceManager;
- proxy.binaryMessenger = binaryMessenger;
- }
-
- /**
- * Sets the context that the {@code CameraControl} will use to enable/disable torch mode and set
- * the zoom ratio.
- *
- * If using the camera plugin in an add-to-app context, ensure that this is called anytime that
- * the context changes.
- */
- public void setContext(@NonNull Context context) {
- this.proxy.context = context;
- }
-
- @Override
- public void enableTorch(
- @NonNull Long identifier,
- @NonNull Boolean torch,
- @NonNull GeneratedCameraXLibrary.Result result) {
- proxy.enableTorch(getCameraControlInstance(identifier), torch, result);
- }
-
- @Override
- public void setZoomRatio(
- @NonNull Long identifier,
- @NonNull Double ratio,
- @NonNull GeneratedCameraXLibrary.Result result) {
- proxy.setZoomRatio(getCameraControlInstance(identifier), ratio, result);
- }
-
- @Override
- public void startFocusAndMetering(
- @NonNull Long identifier, @NonNull Long focusMeteringActionId, @NonNull Result result) {
- proxy.startFocusAndMetering(
- getCameraControlInstance(identifier),
- Objects.requireNonNull(instanceManager.getInstance(focusMeteringActionId)),
- result);
- }
-
- @Override
- public void cancelFocusAndMetering(@NonNull Long identifier, @NonNull Result result) {
- proxy.cancelFocusAndMetering(getCameraControlInstance(identifier), result);
- }
-
- @Override
- public void setExposureCompensationIndex(
- @NonNull Long identifier, @NonNull Long index, @NonNull Result result) {
- proxy.setExposureCompensationIndex(getCameraControlInstance(identifier), index, result);
- }
-
- private CameraControl getCameraControlInstance(@NonNull Long identifier) {
- return Objects.requireNonNull(instanceManager.getInstance(identifier));
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlProxyApi.java
new file mode 100644
index 00000000000..cee3178df80
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraControlProxyApi.java
@@ -0,0 +1,161 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.CameraControl;
+import androidx.camera.core.FocusMeteringAction;
+import androidx.camera.core.FocusMeteringResult;
+import androidx.core.content.ContextCompat;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import kotlin.Result;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function1;
+
+/**
+ * ProxyApi implementation for {@link CameraControl}. This class may handle instantiating native
+ * object instances that are attached to a Dart instance or handle method calls on the associated
+ * native class or an instance of that class.
+ */
+class CameraControlProxyApi extends PigeonApiCameraControl {
+ CameraControlProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public ProxyApiRegistrar getPigeonRegistrar() {
+ return (ProxyApiRegistrar) super.getPigeonRegistrar();
+ }
+
+ @Override
+ public void enableTorch(
+ @NonNull CameraControl pigeonInstance,
+ boolean torch,
+ @NonNull Function1 super Result, Unit> callback) {
+ final ListenableFuture enableTorchFuture = pigeonInstance.enableTorch(torch);
+
+ Futures.addCallback(
+ enableTorchFuture,
+ new FutureCallback<>() {
+ public void onSuccess(Void voidResult) {
+ ResultCompat.success(null, callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+
+ @Override
+ public void setZoomRatio(
+ @NonNull CameraControl pigeonInstance,
+ double ratio,
+ @NonNull Function1 super Result, Unit> callback) {
+ float ratioAsFloat = (float) ratio;
+ final ListenableFuture setZoomRatioFuture = pigeonInstance.setZoomRatio(ratioAsFloat);
+
+ Futures.addCallback(
+ setZoomRatioFuture,
+ new FutureCallback<>() {
+ public void onSuccess(Void voidResult) {
+ ResultCompat.success(null, callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ if (t instanceof CameraControl.OperationCanceledException) {
+ // Operation was canceled due to camera being closed or a new request was submitted, which
+ // is not actionable and should not block a new value from potentially being submitted.
+ ResultCompat.success(null, callback);
+ return;
+ }
+
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+
+ @Override
+ public void startFocusAndMetering(
+ @NonNull CameraControl pigeonInstance,
+ @NonNull FocusMeteringAction action,
+ @NonNull Function1 super Result, Unit> callback) {
+ ListenableFuture focusMeteringResultFuture =
+ pigeonInstance.startFocusAndMetering(action);
+
+ Futures.addCallback(
+ focusMeteringResultFuture,
+ new FutureCallback<>() {
+ public void onSuccess(FocusMeteringResult focusMeteringResult) {
+ ResultCompat.success(focusMeteringResult, callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ if (t instanceof CameraControl.OperationCanceledException) {
+ // Operation was canceled due to camera being closed or a new request was submitted, which
+ // is not actionable and should not block a new value from potentially being submitted.
+ ResultCompat.success(null, callback);
+ return;
+ }
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+
+ @Override
+ public void cancelFocusAndMetering(
+ @NonNull CameraControl pigeonInstance,
+ @NonNull Function1 super Result, Unit> callback) {
+ final ListenableFuture cancelFocusAndMeteringFuture =
+ pigeonInstance.cancelFocusAndMetering();
+
+ Futures.addCallback(
+ cancelFocusAndMeteringFuture,
+ new FutureCallback<>() {
+ public void onSuccess(Void voidResult) {
+ ResultCompat.success(null, callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+
+ @Override
+ public void setExposureCompensationIndex(
+ @NonNull CameraControl pigeonInstance,
+ long index,
+ @NonNull Function1 super Result, Unit> callback) {
+ final ListenableFuture setExposureCompensationIndexFuture =
+ pigeonInstance.setExposureCompensationIndex((int) index);
+
+ Futures.addCallback(
+ setExposureCompensationIndexFuture,
+ new FutureCallback<>() {
+ public void onSuccess(Integer integerResult) {
+ ResultCompat.success(integerResult.longValue(), callback);
+ }
+
+ public void onFailure(@NonNull Throwable t) {
+ if (t instanceof CameraControl.OperationCanceledException) {
+ // Operation was canceled due to camera being closed or a new request was submitted, which
+ // is not actionable and should not block a new value from potentially being submitted.
+ ResultCompat.success(null, callback);
+ return;
+ }
+ ResultCompat.failure(t, callback);
+ }
+ },
+ ContextCompat.getMainExecutor(getPigeonRegistrar().getContext()));
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraFlutterApiImpl.java
deleted file mode 100644
index cfc40be1819..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraFlutterApiImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.camera.core.Camera;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraFlutterApi;
-
-public class CameraFlutterApiImpl extends CameraFlutterApi {
- private final @NonNull InstanceManager instanceManager;
-
- public CameraFlutterApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- super(binaryMessenger);
- this.instanceManager = instanceManager;
- }
-
- void create(Camera camera, Reply reply) {
- create(instanceManager.addHostCreatedInstance(camera), reply);
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraHostApiImpl.java
deleted file mode 100644
index 603cc62edf8..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraHostApiImpl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.camera.core.Camera;
-import androidx.camera.core.CameraControl;
-import androidx.camera.core.CameraInfo;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraHostApi;
-import java.util.Objects;
-
-public class CameraHostApiImpl implements CameraHostApi {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
-
- public CameraHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- }
-
- /**
- * Retrieves the {@link CameraInfo} instance that contains information about the {@link Camera}
- * instance with the specified identifier.
- */
- @Override
- @NonNull
- public Long getCameraInfo(@NonNull Long identifier) {
- Camera camera = getCameraInstance(identifier);
- CameraInfo cameraInfo = camera.getCameraInfo();
-
- CameraInfoFlutterApiImpl cameraInfoFlutterApiImpl =
- new CameraInfoFlutterApiImpl(binaryMessenger, instanceManager);
- cameraInfoFlutterApiImpl.create(cameraInfo, reply -> {});
- return instanceManager.getIdentifierForStrongReference(cameraInfo);
- }
-
- /**
- * Retrieves the {@link CameraControl} instance that provides access to asynchronous operations
- * like zoom and focus & metering on the {@link Camera} instance with the specified identifier.
- */
- @Override
- @NonNull
- public Long getCameraControl(@NonNull Long identifier) {
- Camera camera = getCameraInstance(identifier);
- CameraControl cameraControl = camera.getCameraControl();
-
- CameraControlFlutterApiImpl cameraControlFlutterApiImpl =
- new CameraControlFlutterApiImpl(binaryMessenger, instanceManager);
- cameraControlFlutterApiImpl.create(cameraControl, reply -> {});
- return instanceManager.getIdentifierForStrongReference(cameraControl);
- }
-
- /** Retrieives the {@link Camera} instance associated with the specified {@code identifier}. */
- private Camera getCameraInstance(@NonNull Long identifier) {
- return (Camera) Objects.requireNonNull(instanceManager.getInstance(identifier));
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoFlutterApiImpl.java
deleted file mode 100644
index 8b0e1ff6b3e..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoFlutterApiImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.camera.core.CameraInfo;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraInfoFlutterApi;
-
-public class CameraInfoFlutterApiImpl extends CameraInfoFlutterApi {
- private final @NonNull InstanceManager instanceManager;
-
- public CameraInfoFlutterApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- super(binaryMessenger);
- this.instanceManager = instanceManager;
- }
-
- /**
- * Creates a {@link CameraInfo} instance in Dart. {@code reply} is not used so it can be empty.
- */
- void create(CameraInfo cameraInfo, Reply reply) {
- if (!instanceManager.containsInstance(cameraInfo)) {
- create(instanceManager.addHostCreatedInstance(cameraInfo), reply);
- }
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoHostApiImpl.java
deleted file mode 100644
index 83eb359cdb5..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoHostApiImpl.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.CameraInfo;
-import androidx.camera.core.CameraState;
-import androidx.camera.core.ExposureState;
-import androidx.camera.core.ZoomState;
-import androidx.lifecycle.LiveData;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraInfoHostApi;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.LiveDataSupportedType;
-import java.util.Objects;
-
-public class CameraInfoHostApiImpl implements CameraInfoHostApi {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
-
- @VisibleForTesting public @NonNull LiveDataFlutterApiWrapper liveDataFlutterApiWrapper;
-
- public CameraInfoHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- this.liveDataFlutterApiWrapper =
- new LiveDataFlutterApiWrapper(binaryMessenger, instanceManager);
- }
-
- /**
- * Retrieves the sensor rotation degrees of the {@link androidx.camera.core.Camera} that is
- * represented by the {@link CameraInfo} with the specified identifier.
- */
- @Override
- @NonNull
- public Long getSensorRotationDegrees(@NonNull Long identifier) {
- CameraInfo cameraInfo =
- (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier));
- return Long.valueOf(cameraInfo.getSensorRotationDegrees());
- }
-
- /**
- * Retrieves the {@link LiveData} of the {@link CameraState} that is tied to the {@link
- * androidx.camera.core.Camera} that is represented by the {@link CameraInfo} with the specified
- * identifier.
- */
- @Override
- @NonNull
- public Long getCameraState(@NonNull Long identifier) {
- CameraInfo cameraInfo =
- (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier));
- LiveData liveCameraState = cameraInfo.getCameraState();
- liveDataFlutterApiWrapper.create(
- liveCameraState, LiveDataSupportedType.CAMERA_STATE, reply -> {});
- return instanceManager.getIdentifierForStrongReference(liveCameraState);
- }
-
- /**
- * Retrieves the {@link ExposureState} of the {@link CameraInfo} with the specified identifier.
- */
- @Override
- @NonNull
- public Long getExposureState(@NonNull Long identifier) {
- CameraInfo cameraInfo =
- (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier));
- ExposureState exposureState = cameraInfo.getExposureState();
-
- ExposureStateFlutterApiImpl exposureStateFlutterApiImpl =
- new ExposureStateFlutterApiImpl(binaryMessenger, instanceManager);
- exposureStateFlutterApiImpl.create(exposureState, result -> {});
-
- return instanceManager.getIdentifierForStrongReference(exposureState);
- }
-
- /**
- * Retrieves the {@link LiveData} of the {@link ZoomState} of the {@link CameraInfo} with the
- * specified identifier.
- */
- @NonNull
- @Override
- public Long getZoomState(@NonNull Long identifier) {
- CameraInfo cameraInfo =
- (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier));
- LiveData zoomState = cameraInfo.getZoomState();
-
- LiveDataFlutterApiWrapper liveDataFlutterApiWrapper =
- new LiveDataFlutterApiWrapper(binaryMessenger, instanceManager);
- liveDataFlutterApiWrapper.create(zoomState, LiveDataSupportedType.ZOOM_STATE, reply -> {});
-
- return instanceManager.getIdentifierForStrongReference(zoomState);
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoProxyApi.java
new file mode 100644
index 00000000000..9b168dc52fd
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraInfoProxyApi.java
@@ -0,0 +1,45 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.CameraInfo;
+import androidx.camera.core.ExposureState;
+
+/**
+ * ProxyApi implementation for {@link CameraInfo}. This class may handle instantiating native object
+ * instances that are attached to a Dart instance or handle method calls on the associated native
+ * class or an instance of that class.
+ */
+class CameraInfoProxyApi extends PigeonApiCameraInfo {
+ CameraInfoProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @Override
+ public long sensorRotationDegrees(CameraInfo pigeonInstance) {
+ return pigeonInstance.getSensorRotationDegrees();
+ }
+
+ @NonNull
+ @Override
+ public ExposureState exposureState(CameraInfo pigeonInstance) {
+ return pigeonInstance.getExposureState();
+ }
+
+ @NonNull
+ @Override
+ public LiveDataProxyApi.LiveDataWrapper getCameraState(CameraInfo pigeonInstance) {
+ return new LiveDataProxyApi.LiveDataWrapper(
+ pigeonInstance.getCameraState(), LiveDataSupportedType.CAMERA_STATE);
+ }
+
+ @NonNull
+ @Override
+ public LiveDataProxyApi.LiveDataWrapper getZoomState(CameraInfo pigeonInstance) {
+ return new LiveDataProxyApi.LiveDataWrapper(
+ pigeonInstance.getZoomState(), LiveDataSupportedType.ZOOM_STATE);
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraIntegerRangeProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraIntegerRangeProxyApi.java
new file mode 100644
index 00000000000..6ed0428990e
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraIntegerRangeProxyApi.java
@@ -0,0 +1,35 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import android.util.Range;
+import androidx.annotation.NonNull;
+
+/**
+ * ProxyApi implementation for {@link android.util.Range}. This class may handle
+ * instantiating native object instances that are attached to a Dart instance or handle method calls
+ * on the associated native class or an instance of that class.
+ */
+class CameraIntegerRangeProxyApi extends PigeonApiCameraIntegerRange {
+ CameraIntegerRangeProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public Range pigeon_defaultConstructor(long lower, long upper) {
+ return new Range<>((int) lower, (int) upper);
+ }
+
+ @Override
+ public long lower(android.util.Range> pigeonInstance) {
+ return (Integer) pigeonInstance.getLower();
+ }
+
+ @Override
+ public long upper(android.util.Range> pigeonInstance) {
+ return (Integer) pigeonInstance.getUpper();
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsError.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsError.java
new file mode 100644
index 00000000000..09b62227716
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsError.java
@@ -0,0 +1,45 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import java.util.Objects;
+
+/** Contains data when an attempt to retrieve camera permissions fails. */
+public class CameraPermissionsError {
+ private final String errorCode;
+ private final String description;
+
+ public CameraPermissionsError(@NonNull String errorCode, @NonNull String description) {
+ this.errorCode = errorCode;
+ this.description = description;
+ }
+
+ @NonNull
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ @NonNull
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean equals(@Nullable Object obj) {
+ if (obj instanceof CameraPermissionsError) {
+ return Objects.equals(((CameraPermissionsError) obj).errorCode, errorCode)
+ && Objects.equals(((CameraPermissionsError) obj).description, description);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(errorCode, description);
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsErrorProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsErrorProxyApi.java
new file mode 100644
index 00000000000..83d20dae755
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsErrorProxyApi.java
@@ -0,0 +1,31 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+
+/**
+ * ProxyApi implementation for {@link CameraPermissionsError}. This class may handle instantiating
+ * native object instances that are attached to a Dart instance or handle method calls on the
+ * associated native class or an instance of that class.
+ */
+public class CameraPermissionsErrorProxyApi extends PigeonApiCameraPermissionsError {
+ public CameraPermissionsErrorProxyApi(
+ @NonNull CameraXLibraryPigeonProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public String errorCode(@NonNull CameraPermissionsError pigeonInstance) {
+ return pigeonInstance.getErrorCode();
+ }
+
+ @NonNull
+ @Override
+ public String description(@NonNull CameraPermissionsError pigeonInstance) {
+ return pigeonInstance.getDescription();
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsManager.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsManager.java
index 28093ec4371..ed80da9ea2c 100644
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsManager.java
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraPermissionsManager.java
@@ -9,11 +9,12 @@
import android.app.Activity;
import android.content.pm.PackageManager;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
-final class CameraPermissionsManager {
+public final class CameraPermissionsManager {
interface PermissionsRegistry {
@SuppressWarnings("deprecation")
void addListener(
@@ -21,7 +22,7 @@ void addListener(
}
interface ResultCallback {
- void onResult(String errorCode, String errorDescription);
+ void onResult(@Nullable CameraPermissionsError error);
}
/**
@@ -48,15 +49,16 @@ void requestPermissions(
ResultCallback callback) {
if (ongoing) {
callback.onResult(
- CAMERA_PERMISSIONS_REQUEST_ONGOING, CAMERA_PERMISSIONS_REQUEST_ONGOING_MESSAGE);
+ new CameraPermissionsError(
+ CAMERA_PERMISSIONS_REQUEST_ONGOING, CAMERA_PERMISSIONS_REQUEST_ONGOING_MESSAGE));
return;
}
if (!hasCameraPermission(activity) || (enableAudio && !hasAudioPermission(activity))) {
permissionsRegistry.addListener(
new CameraRequestPermissionsListener(
- (String errorCode, String errorDescription) -> {
+ (CameraPermissionsError error) -> {
ongoing = false;
- callback.onResult(errorCode, errorDescription);
+ callback.onResult(error);
}));
ongoing = true;
ActivityCompat.requestPermissions(
@@ -67,7 +69,7 @@ void requestPermissions(
CAMERA_REQUEST_ID);
} else {
// Permissions already exist. Call the callback with success.
- callback.onResult(null, null);
+ callback.onResult(null);
}
}
@@ -110,11 +112,13 @@ public boolean onRequestPermissionsResult(
// grantResults could be empty if the permissions request with the user is interrupted
// https://developer.android.com/reference/android/app/Activity#onRequestPermissionsResult(int,%20java.lang.String[],%20int[])
if (grantResults.length == 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
- callback.onResult(CAMERA_ACCESS_DENIED, CAMERA_ACCESS_DENIED_MESSAGE);
+ callback.onResult(
+ new CameraPermissionsError(CAMERA_ACCESS_DENIED, CAMERA_ACCESS_DENIED_MESSAGE));
} else if (grantResults.length > 1 && grantResults[1] != PackageManager.PERMISSION_GRANTED) {
- callback.onResult(AUDIO_ACCESS_DENIED, AUDIO_ACCESS_DENIED_MESSAGE);
+ callback.onResult(
+ new CameraPermissionsError(AUDIO_ACCESS_DENIED, AUDIO_ACCESS_DENIED_MESSAGE));
} else {
- callback.onResult(null, null);
+ callback.onResult(null);
}
return true;
}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraProxyApi.java
new file mode 100644
index 00000000000..3d9158f7ea1
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraProxyApi.java
@@ -0,0 +1,33 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.Camera;
+import androidx.camera.core.CameraControl;
+import androidx.camera.core.CameraInfo;
+
+/**
+ * ProxyApi implementation for {@link Camera}. This class may handle instantiating native object
+ * instances that are attached to a Dart instance or handle method calls on the associated native
+ * class or an instance of that class.
+ */
+class CameraProxyApi extends PigeonApiCamera {
+ CameraProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public CameraControl cameraControl(Camera pigeonInstance) {
+ return pigeonInstance.getCameraControl();
+ }
+
+ @NonNull
+ @Override
+ public CameraInfo getCameraInfo(Camera pigeonInstance) {
+ return pigeonInstance.getCameraInfo();
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorFlutterApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorFlutterApiImpl.java
deleted file mode 100644
index a0b30fa2541..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorFlutterApiImpl.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.camera.core.CameraSelector;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraSelectorFlutterApi;
-
-public class CameraSelectorFlutterApiImpl extends CameraSelectorFlutterApi {
- private final InstanceManager instanceManager;
-
- public CameraSelectorFlutterApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- super(binaryMessenger);
- this.instanceManager = instanceManager;
- }
-
- void create(CameraSelector cameraSelector, Long lensFacing, Reply reply) {
- create(instanceManager.addHostCreatedInstance(cameraSelector), lensFacing, reply);
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorHostApiImpl.java
deleted file mode 100644
index bbd747342de..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorHostApiImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.CameraInfo;
-import androidx.camera.core.CameraSelector;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraSelectorHostApi;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-public class CameraSelectorHostApiImpl implements CameraSelectorHostApi {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
-
- @VisibleForTesting public @NonNull CameraXProxy cameraXProxy = new CameraXProxy();
-
- public CameraSelectorHostApiImpl(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- }
-
- @Override
- public void create(@NonNull Long identifier, @Nullable Long lensFacing) {
- CameraSelector.Builder cameraSelectorBuilder = cameraXProxy.createCameraSelectorBuilder();
- if (lensFacing != null) {
- cameraSelectorBuilder = cameraSelectorBuilder.requireLensFacing(lensFacing.intValue());
- }
- instanceManager.addDartCreatedInstance(cameraSelectorBuilder.build(), identifier);
- }
-
- @Override
- public @NonNull List filter(@NonNull Long identifier, @NonNull List cameraInfoIds) {
- CameraSelector cameraSelector =
- (CameraSelector) Objects.requireNonNull(instanceManager.getInstance(identifier));
- List cameraInfosForFilter = new ArrayList<>();
-
- for (Number cameraInfoAsNumber : cameraInfoIds) {
- Long cameraInfoId = cameraInfoAsNumber.longValue();
-
- CameraInfo cameraInfo =
- (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(cameraInfoId));
- cameraInfosForFilter.add(cameraInfo);
- }
-
- List filteredCameraInfos = cameraSelector.filter(cameraInfosForFilter);
- List filteredCameraInfosIds = new ArrayList<>();
-
- for (CameraInfo cameraInfo : filteredCameraInfos) {
- Long filteredCameraInfoId = instanceManager.getIdentifierForStrongReference(cameraInfo);
- filteredCameraInfosIds.add(filteredCameraInfoId);
- }
-
- return filteredCameraInfosIds;
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorProxyApi.java
new file mode 100644
index 00000000000..b1eb4121060
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSelectorProxyApi.java
@@ -0,0 +1,68 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.camera.core.CameraInfo;
+import androidx.camera.core.CameraSelector;
+import androidx.camera.core.ExperimentalLensFacing;
+import java.util.List;
+
+/**
+ * ProxyApi implementation for {@link CameraSelector}. This class may handle instantiating native
+ * object instances that are attached to a Dart instance or handle method calls on the associated
+ * native class or an instance of that class.
+ */
+class CameraSelectorProxyApi extends PigeonApiCameraSelector {
+ CameraSelectorProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @ExperimentalLensFacing
+ @NonNull
+ @Override
+ public CameraSelector pigeon_defaultConstructor(@Nullable LensFacing requireLensFacing) {
+ final CameraSelector.Builder builder = new CameraSelector.Builder();
+ if (requireLensFacing != null) {
+ switch (requireLensFacing) {
+ case FRONT:
+ builder.requireLensFacing(CameraSelector.LENS_FACING_FRONT);
+ break;
+ case BACK:
+ builder.requireLensFacing(CameraSelector.LENS_FACING_BACK);
+ break;
+ case EXTERNAL:
+ builder.requireLensFacing(CameraSelector.LENS_FACING_EXTERNAL);
+ break;
+ case UNKNOWN:
+ builder.requireLensFacing(CameraSelector.LENS_FACING_UNKNOWN);
+ break;
+ }
+ }
+ return builder.build();
+ }
+
+ @NonNull
+ @Override
+ public androidx.camera.core.CameraSelector defaultBackCamera() {
+ return CameraSelector.DEFAULT_BACK_CAMERA;
+ }
+
+ @NonNull
+ @Override
+ public androidx.camera.core.CameraSelector defaultFrontCamera() {
+ return CameraSelector.DEFAULT_FRONT_CAMERA;
+ }
+
+ // List extends CameraInfo> can be considered the same as List.
+ @SuppressWarnings("unchecked")
+ @NonNull
+ @Override
+ public List filter(
+ @NonNull CameraSelector pigeonInstance, @NonNull List extends CameraInfo> cameraInfos) {
+ return pigeonInstance.filter((List) cameraInfos);
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSizeProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSizeProxyApi.java
new file mode 100644
index 00000000000..3294467fcd9
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraSizeProxyApi.java
@@ -0,0 +1,35 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import android.util.Size;
+import androidx.annotation.NonNull;
+
+/**
+ * ProxyApi implementation for {@link Size}. This class may handle instantiating native object
+ * instances that are attached to a Dart instance or handle method calls on the associated native
+ * class or an instance of that class.
+ */
+class CameraSizeProxyApi extends PigeonApiCameraSize {
+ CameraSizeProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public Size pigeon_defaultConstructor(long width, long height) {
+ return new Size((int) width, (int) height);
+ }
+
+ @Override
+ public long width(@NonNull Size pigeonInstance) {
+ return pigeonInstance.getWidth();
+ }
+
+ @Override
+ public long height(Size pigeonInstance) {
+ return pigeonInstance.getHeight();
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateErrorFlutterApiWrapper.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateErrorFlutterApiWrapper.java
deleted file mode 100644
index f4c8d6ee4af..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateErrorFlutterApiWrapper.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.CameraState;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraStateErrorFlutterApi;
-
-/**
- * Flutter API implementation for {@link CameraStateError}.
- *
- * This class may handle adding native instances that are attached to a Dart instance or passing
- * arguments of callbacks methods to a Dart instance.
- */
-public class CameraStateErrorFlutterApiWrapper {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
- private CameraStateErrorFlutterApi cameraStateErrorFlutterApi;
-
- /**
- * Constructs a {@link CameraStateErrorFlutterApiWrapper}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- */
- public CameraStateErrorFlutterApiWrapper(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- cameraStateErrorFlutterApi = new CameraStateErrorFlutterApi(binaryMessenger);
- }
-
- /**
- * Stores the {@link CameraStateError} instance and notifies Dart to create and store a new {@link
- * CameraStateError} instance that is attached to this one. If {@code instance} has already been
- * added, this method does nothing.
- */
- public void create(
- @NonNull CameraState.StateError instance,
- @NonNull Long code,
- @NonNull CameraStateErrorFlutterApi.Reply callback) {
- if (!instanceManager.containsInstance(instance)) {
- cameraStateErrorFlutterApi.create(
- instanceManager.addHostCreatedInstance(instance), code, callback);
- }
- }
-
- /** Sets the Flutter API used to send messages to Dart. */
- @VisibleForTesting
- void setApi(@NonNull CameraStateErrorFlutterApi api) {
- this.cameraStateErrorFlutterApi = api;
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateFlutterApiWrapper.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateFlutterApiWrapper.java
deleted file mode 100644
index cb1c30ad424..00000000000
--- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateFlutterApiWrapper.java
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2013 The Flutter Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package io.flutter.plugins.camerax;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
-import androidx.camera.core.CameraState;
-import io.flutter.plugin.common.BinaryMessenger;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraStateFlutterApi;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraStateType;
-import io.flutter.plugins.camerax.GeneratedCameraXLibrary.CameraStateTypeData;
-
-/**
- * Flutter API implementation for {@link CameraState}.
- *
- * This class may handle adding native instances that are attached to a Dart instance or passing
- * arguments of callbacks methods to a Dart instance.
- */
-public class CameraStateFlutterApiWrapper {
- private final BinaryMessenger binaryMessenger;
- private final InstanceManager instanceManager;
- private CameraStateFlutterApi cameraStateFlutterApi;
-
- /**
- * Constructs a {@link CameraStateFlutterApiWrapper}.
- *
- * @param binaryMessenger used to communicate with Dart over asynchronous messages
- * @param instanceManager maintains instances stored to communicate with attached Dart objects
- */
- public CameraStateFlutterApiWrapper(
- @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) {
- this.binaryMessenger = binaryMessenger;
- this.instanceManager = instanceManager;
- cameraStateFlutterApi = new CameraStateFlutterApi(binaryMessenger);
- }
-
- /**
- * Stores the {@link CameraState} instance and notifies Dart to create and store a new {@link
- * CameraState} instance that is attached to this one. If {@code instance} has already been added,
- * this method does nothing.
- */
- public void create(
- @NonNull CameraState instance,
- @NonNull CameraStateType type,
- @Nullable CameraState.StateError error,
- @NonNull CameraStateFlutterApi.Reply callback) {
- if (instanceManager.containsInstance(instance)) {
- return;
- }
-
- if (error != null) {
- // if there is a problem with the current camera state, we need to create a CameraStateError
- // to send to the Dart side.
- new CameraStateErrorFlutterApiWrapper(binaryMessenger, instanceManager)
- .create(error, Long.valueOf(error.getCode()), reply -> {});
- }
-
- cameraStateFlutterApi.create(
- instanceManager.addHostCreatedInstance(instance),
- new CameraStateTypeData.Builder().setValue(type).build(),
- instanceManager.getIdentifierForStrongReference(error),
- callback);
- }
-
- /** Converts CameraX CameraState.Type to CameraStateType that the Dart side understands. */
- @NonNull
- public static CameraStateType getCameraStateType(@NonNull CameraState.Type type) {
- CameraStateType cameraStateType = null;
- switch (type) {
- case CLOSED:
- cameraStateType = CameraStateType.CLOSED;
- break;
- case CLOSING:
- cameraStateType = CameraStateType.CLOSING;
- break;
- case OPEN:
- cameraStateType = CameraStateType.OPEN;
- break;
- case OPENING:
- cameraStateType = CameraStateType.OPENING;
- break;
- case PENDING_OPEN:
- cameraStateType = CameraStateType.PENDING_OPEN;
- break;
- }
-
- if (cameraStateType == null) {
- throw new IllegalArgumentException(
- "The CameraState.Type passed to this method was not recognized.");
- }
- return cameraStateType;
- }
-
- /** Sets the Flutter API used to send messages to Dart. */
- @VisibleForTesting
- void setApi(@NonNull CameraStateFlutterApi api) {
- this.cameraStateFlutterApi = api;
- }
-}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateProxyApi.java
new file mode 100644
index 00000000000..33f164a0193
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateProxyApi.java
@@ -0,0 +1,46 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.camera.core.CameraState;
+import androidx.camera.core.CameraState.StateError;
+
+/**
+ * ProxyApi implementation for {@link CameraState}. This class may handle instantiating native
+ * object instances that are attached to a Dart instance or handle method calls on the associated
+ * native class or an instance of that class.
+ */
+class CameraStateProxyApi extends PigeonApiCameraState {
+ CameraStateProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public CameraStateType type(CameraState pigeonInstance) {
+ switch (pigeonInstance.getType()) {
+ case PENDING_OPEN:
+ return CameraStateType.PENDING_OPEN;
+ case OPENING:
+ return CameraStateType.OPENING;
+ case OPEN:
+ return CameraStateType.OPEN;
+ case CLOSING:
+ return CameraStateType.CLOSING;
+ case CLOSED:
+ return CameraStateType.CLOSED;
+ default:
+ return CameraStateType.UNKNOWN;
+ }
+ }
+
+ @Nullable
+ @Override
+ public StateError error(CameraState pigeonInstance) {
+ return pigeonInstance.getError();
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateStateErrorProxyApi.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateStateErrorProxyApi.java
new file mode 100644
index 00000000000..6864a3dd549
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraStateStateErrorProxyApi.java
@@ -0,0 +1,42 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package io.flutter.plugins.camerax;
+
+import androidx.annotation.NonNull;
+import androidx.camera.core.CameraState;
+
+/**
+ * ProxyApi implementation for {@link CameraState.StateError}. This class may handle instantiating
+ * native object instances that are attached to a Dart instance or handle method calls on the
+ * associated native class or an instance of that class.
+ */
+class CameraStateStateErrorProxyApi extends PigeonApiCameraStateStateError {
+ CameraStateStateErrorProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) {
+ super(pigeonRegistrar);
+ }
+
+ @NonNull
+ @Override
+ public CameraStateErrorCode code(CameraState.StateError pigeonInstance) {
+ switch (pigeonInstance.getCode()) {
+ case CameraState.ERROR_CAMERA_DISABLED:
+ return CameraStateErrorCode.CAMERA_DISABLED;
+ case CameraState.ERROR_CAMERA_FATAL_ERROR:
+ return CameraStateErrorCode.CAMERA_FATAL_ERROR;
+ case CameraState.ERROR_CAMERA_IN_USE:
+ return CameraStateErrorCode.CAMERA_IN_USE;
+ case CameraState.ERROR_DO_NOT_DISTURB_MODE_ENABLED:
+ return CameraStateErrorCode.DO_NOT_DISTURB_MODE_ENABLED;
+ case CameraState.ERROR_MAX_CAMERAS_IN_USE:
+ return CameraStateErrorCode.MAX_CAMERAS_IN_USE;
+ case CameraState.ERROR_OTHER_RECOVERABLE_ERROR:
+ return CameraStateErrorCode.OTHER_RECOVERABLE_ERROR;
+ case CameraState.ERROR_STREAM_CONFIG:
+ return CameraStateErrorCode.STREAM_CONFIG;
+ default:
+ return io.flutter.plugins.camerax.CameraStateErrorCode.UNKNOWN;
+ }
+ }
+}
diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt
new file mode 100644
index 00000000000..ab1ed726680
--- /dev/null
+++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraXLibrary.g.kt
@@ -0,0 +1,7207 @@
+// Copyright 2013 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Autogenerated from Pigeon (v25.2.0), do not edit directly.
+// See also: https://pub.dev/packages/pigeon
+@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "UnsafeOptInUsageError", "SyntheticAccessor")
+
+package io.flutter.plugins.camerax
+
+import android.util.Log
+import io.flutter.plugin.common.BasicMessageChannel
+import io.flutter.plugin.common.BinaryMessenger
+import io.flutter.plugin.common.MessageCodec
+import io.flutter.plugin.common.StandardMessageCodec
+import java.io.ByteArrayOutputStream
+import java.nio.ByteBuffer
+
+private fun wrapResult(result: Any?): List {
+ return listOf(result)
+}
+
+private fun wrapError(exception: Throwable): List {
+ return if (exception is CameraXError) {
+ listOf(exception.code, exception.message, exception.details)
+ } else {
+ listOf(
+ exception.javaClass.simpleName,
+ exception.toString(),
+ "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception))
+ }
+}
+
+private fun createConnectionError(channelName: String): CameraXError {
+ return CameraXError(
+ "channel-error", "Unable to establish connection on channel: '$channelName'.", "")
+}
+
+/**
+ * Error class for passing custom error details to Flutter via a thrown PlatformException.
+ *
+ * @property code The error code.
+ * @property message The error message.
+ * @property details The error details. Must be a datatype supported by the api codec.
+ */
+class CameraXError(
+ val code: String,
+ override val message: String? = null,
+ val details: Any? = null
+) : Throwable()
+/**
+ * Maintains instances used to communicate with the corresponding objects in Dart.
+ *
+ * Objects stored in this container are represented by an object in Dart that is also stored in an
+ * InstanceManager with the same identifier.
+ *
+ * When an instance is added with an identifier, either can be used to retrieve the other.
+ *
+ * Added instances are added as a weak reference and a strong reference. When the strong reference
+ * is removed with [remove] and the weak reference is deallocated, the
+ * `finalizationListener.onFinalize` is called with the instance's identifier. However, if the
+ * strong reference is removed and then the identifier is retrieved with the intention to pass the
+ * identifier to Dart (e.g. calling [getIdentifierForStrongReference]), the strong reference to the
+ * instance is recreated. The strong reference will then need to be removed manually again.
+ */
+@Suppress("UNCHECKED_CAST", "MemberVisibilityCanBePrivate")
+class CameraXLibraryPigeonInstanceManager(
+ private val finalizationListener: PigeonFinalizationListener
+) {
+ /** Interface for listening when a weak reference of an instance is removed from the manager. */
+ interface PigeonFinalizationListener {
+ fun onFinalize(identifier: Long)
+ }
+
+ private val identifiers = java.util.WeakHashMap()
+ private val weakInstances = HashMap>()
+ private val strongInstances = HashMap()
+ private val referenceQueue = java.lang.ref.ReferenceQueue()
+ private val weakReferencesToIdentifiers = HashMap, Long>()
+ private val handler = android.os.Handler(android.os.Looper.getMainLooper())
+ private var nextIdentifier: Long = minHostCreatedIdentifier
+ private var hasFinalizationListenerStopped = false
+
+ /**
+ * Modifies the time interval used to define how often this instance removes garbage collected
+ * weak references to native Android objects that this instance was managing.
+ */
+ var clearFinalizedWeakReferencesInterval: Long = 3000
+ set(value) {
+ handler.removeCallbacks { this.releaseAllFinalizedInstances() }
+ field = value
+ releaseAllFinalizedInstances()
+ }
+
+ init {
+ handler.postDelayed({ releaseAllFinalizedInstances() }, clearFinalizedWeakReferencesInterval)
+ }
+
+ companion object {
+ // Identifiers are locked to a specific range to avoid collisions with objects
+ // created simultaneously from Dart.
+ // Host uses identifiers >= 2^16 and Dart is expected to use values n where,
+ // 0 <= n < 2^16.
+ private const val minHostCreatedIdentifier: Long = 65536
+ private const val tag = "PigeonInstanceManager"
+
+ /**
+ * Instantiate a new manager with a listener for garbage collected weak references.
+ *
+ * When the manager is no longer needed, [stopFinalizationListener] must be called.
+ */
+ fun create(
+ finalizationListener: PigeonFinalizationListener
+ ): CameraXLibraryPigeonInstanceManager {
+ return CameraXLibraryPigeonInstanceManager(finalizationListener)
+ }
+ }
+
+ /**
+ * Removes `identifier` and return its associated strongly referenced instance, if present, from
+ * the manager.
+ */
+ fun remove(identifier: Long): T? {
+ logWarningIfFinalizationListenerHasStopped()
+ return strongInstances.remove(identifier) as T?
+ }
+
+ /**
+ * Retrieves the identifier paired with an instance, if present, otherwise `null`.
+ *
+ * If the manager contains a strong reference to `instance`, it will return the identifier
+ * associated with `instance`. If the manager contains only a weak reference to `instance`, a new
+ * strong reference to `instance` will be added and will need to be removed again with [remove].
+ *
+ * If this method returns a nonnull identifier, this method also expects the Dart
+ * `CameraXLibraryPigeonInstanceManager` to have, or recreate, a weak reference to the Dart
+ * instance the identifier is associated with.
+ */
+ fun getIdentifierForStrongReference(instance: Any?): Long? {
+ logWarningIfFinalizationListenerHasStopped()
+ val identifier = identifiers[instance]
+ if (identifier != null) {
+ strongInstances[identifier] = instance!!
+ }
+ return identifier
+ }
+
+ /**
+ * Adds a new instance that was instantiated from Dart.
+ *
+ * The same instance can be added multiple times, but each identifier must be unique. This allows
+ * two objects that are equivalent (e.g. the `equals` method returns true and their hashcodes are
+ * equal) to both be added.
+ *
+ * [identifier] must be >= 0 and unique.
+ */
+ fun addDartCreatedInstance(instance: Any, identifier: Long) {
+ logWarningIfFinalizationListenerHasStopped()
+ addInstance(instance, identifier)
+ }
+
+ /**
+ * Adds a new unique instance that was instantiated from the host platform.
+ *
+ * [identifier] must be >= 0 and unique.
+ */
+ fun addHostCreatedInstance(instance: Any): Long {
+ logWarningIfFinalizationListenerHasStopped()
+ require(!containsInstance(instance)) {
+ "Instance of ${instance.javaClass} has already been added."
+ }
+ val identifier = nextIdentifier++
+ addInstance(instance, identifier)
+ return identifier
+ }
+
+ /** Retrieves the instance associated with identifier, if present, otherwise `null`. */
+ fun getInstance(identifier: Long): T? {
+ logWarningIfFinalizationListenerHasStopped()
+ val instance = weakInstances[identifier] as java.lang.ref.WeakReference?
+ return instance?.get()
+ }
+
+ /** Returns whether this manager contains the given `instance`. */
+ fun containsInstance(instance: Any?): Boolean {
+ logWarningIfFinalizationListenerHasStopped()
+ return identifiers.containsKey(instance)
+ }
+
+ /**
+ * Stops the periodic run of the [PigeonFinalizationListener] for instances that have been garbage
+ * collected.
+ *
+ * The InstanceManager can continue to be used, but the [PigeonFinalizationListener] will no
+ * longer be called and methods will log a warning.
+ */
+ fun stopFinalizationListener() {
+ handler.removeCallbacks { this.releaseAllFinalizedInstances() }
+ hasFinalizationListenerStopped = true
+ }
+
+ /**
+ * Removes all of the instances from this manager.
+ *
+ * The manager will be empty after this call returns.
+ */
+ fun clear() {
+ identifiers.clear()
+ weakInstances.clear()
+ strongInstances.clear()
+ weakReferencesToIdentifiers.clear()
+ }
+
+ /**
+ * Whether the [PigeonFinalizationListener] is still being called for instances that are garbage
+ * collected.
+ *
+ * See [stopFinalizationListener].
+ */
+ fun hasFinalizationListenerStopped(): Boolean {
+ return hasFinalizationListenerStopped
+ }
+
+ private fun releaseAllFinalizedInstances() {
+ if (hasFinalizationListenerStopped()) {
+ return
+ }
+ var reference: java.lang.ref.WeakReference?
+ while ((referenceQueue.poll() as java.lang.ref.WeakReference?).also { reference = it } !=
+ null) {
+ val identifier = weakReferencesToIdentifiers.remove(reference)
+ if (identifier != null) {
+ weakInstances.remove(identifier)
+ strongInstances.remove(identifier)
+ finalizationListener.onFinalize(identifier)
+ }
+ }
+ handler.postDelayed({ releaseAllFinalizedInstances() }, clearFinalizedWeakReferencesInterval)
+ }
+
+ private fun addInstance(instance: Any, identifier: Long) {
+ require(identifier >= 0) { "Identifier must be >= 0: $identifier" }
+ require(!weakInstances.containsKey(identifier)) {
+ "Identifier has already been added: $identifier"
+ }
+ val weakReference = java.lang.ref.WeakReference(instance, referenceQueue)
+ identifiers[instance] = identifier
+ weakInstances[identifier] = weakReference
+ weakReferencesToIdentifiers[weakReference] = identifier
+ strongInstances[identifier] = instance
+ }
+
+ private fun logWarningIfFinalizationListenerHasStopped() {
+ if (hasFinalizationListenerStopped()) {
+ Log.w(
+ tag,
+ "The manager was used after calls to the PigeonFinalizationListener has been stopped.")
+ }
+ }
+}
+
+/** Generated API for managing the Dart and native `InstanceManager`s. */
+private class CameraXLibraryPigeonInstanceManagerApi(val binaryMessenger: BinaryMessenger) {
+ companion object {
+ /** The codec used by CameraXLibraryPigeonInstanceManagerApi. */
+ val codec: MessageCodec by lazy { CameraXLibraryPigeonCodec() }
+
+ /**
+ * Sets up an instance of `CameraXLibraryPigeonInstanceManagerApi` to handle messages from the
+ * `binaryMessenger`.
+ */
+ fun setUpMessageHandlers(
+ binaryMessenger: BinaryMessenger,
+ instanceManager: CameraXLibraryPigeonInstanceManager?
+ ) {
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.PigeonInternalInstanceManager.removeStrongReference",
+ codec)
+ if (instanceManager != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ instanceManager.remove(identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.PigeonInternalInstanceManager.clear",
+ codec)
+ if (instanceManager != null) {
+ channel.setMessageHandler { _, reply ->
+ val wrapped: List =
+ try {
+ instanceManager.clear()
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ fun removeStrongReference(identifierArg: Long, callback: (Result) -> Unit) {
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.PigeonInternalInstanceManager.removeStrongReference"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+}
+/**
+ * Provides implementations for each ProxyApi implementation and provides access to resources needed
+ * by any implementation.
+ */
+abstract class CameraXLibraryPigeonProxyApiRegistrar(val binaryMessenger: BinaryMessenger) {
+ /** Whether APIs should ignore calling to Dart. */
+ public var ignoreCallsToDart = false
+ val instanceManager: CameraXLibraryPigeonInstanceManager
+ private var _codec: MessageCodec? = null
+ val codec: MessageCodec
+ get() {
+ if (_codec == null) {
+ _codec = CameraXLibraryPigeonProxyApiBaseCodec(this)
+ }
+ return _codec!!
+ }
+
+ init {
+ val api = CameraXLibraryPigeonInstanceManagerApi(binaryMessenger)
+ instanceManager =
+ CameraXLibraryPigeonInstanceManager.create(
+ object : CameraXLibraryPigeonInstanceManager.PigeonFinalizationListener {
+ override fun onFinalize(identifier: Long) {
+ api.removeStrongReference(identifier) {
+ if (it.isFailure) {
+ Log.e(
+ "PigeonProxyApiRegistrar",
+ "Failed to remove Dart strong reference with identifier: $identifier")
+ }
+ }
+ }
+ })
+ }
+ /**
+ * An implementation of [PigeonApiCameraSize] used to add a new Dart instance of `CameraSize` to
+ * the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraSize(): PigeonApiCameraSize
+
+ /**
+ * An implementation of [PigeonApiResolutionInfo] used to add a new Dart instance of
+ * `ResolutionInfo` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiResolutionInfo(): PigeonApiResolutionInfo
+
+ /**
+ * An implementation of [PigeonApiCameraIntegerRange] used to add a new Dart instance of
+ * `CameraIntegerRange` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraIntegerRange(): PigeonApiCameraIntegerRange
+
+ /**
+ * An implementation of [PigeonApiVideoRecordEvent] used to add a new Dart instance of
+ * `VideoRecordEvent` to the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiVideoRecordEvent(): PigeonApiVideoRecordEvent {
+ return PigeonApiVideoRecordEvent(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiVideoRecordEventStart] used to add a new Dart instance of
+ * `VideoRecordEventStart` to the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiVideoRecordEventStart(): PigeonApiVideoRecordEventStart {
+ return PigeonApiVideoRecordEventStart(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiVideoRecordEventFinalize] used to add a new Dart instance of
+ * `VideoRecordEventFinalize` to the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiVideoRecordEventFinalize(): PigeonApiVideoRecordEventFinalize {
+ return PigeonApiVideoRecordEventFinalize(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiMeteringPoint] used to add a new Dart instance of
+ * `MeteringPoint` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiMeteringPoint(): PigeonApiMeteringPoint
+
+ /**
+ * An implementation of [PigeonApiObserver] used to add a new Dart instance of `Observer` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiObserver(): PigeonApiObserver
+
+ /**
+ * An implementation of [PigeonApiCameraInfo] used to add a new Dart instance of `CameraInfo` to
+ * the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraInfo(): PigeonApiCameraInfo
+
+ /**
+ * An implementation of [PigeonApiCameraSelector] used to add a new Dart instance of
+ * `CameraSelector` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraSelector(): PigeonApiCameraSelector
+
+ /**
+ * An implementation of [PigeonApiProcessCameraProvider] used to add a new Dart instance of
+ * `ProcessCameraProvider` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiProcessCameraProvider(): PigeonApiProcessCameraProvider
+
+ /**
+ * An implementation of [PigeonApiUseCase] used to add a new Dart instance of `UseCase` to the
+ * Dart `InstanceManager`.
+ */
+ open fun getPigeonApiUseCase(): PigeonApiUseCase {
+ return PigeonApiUseCase(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiCamera] used to add a new Dart instance of `Camera` to the Dart
+ * `InstanceManager`.
+ */
+ abstract fun getPigeonApiCamera(): PigeonApiCamera
+
+ /**
+ * An implementation of [PigeonApiSystemServicesManager] used to add a new Dart instance of
+ * `SystemServicesManager` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiSystemServicesManager(): PigeonApiSystemServicesManager
+
+ /**
+ * An implementation of [PigeonApiCameraPermissionsError] used to add a new Dart instance of
+ * `CameraPermissionsError` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraPermissionsError(): PigeonApiCameraPermissionsError
+
+ /**
+ * An implementation of [PigeonApiDeviceOrientationManager] used to add a new Dart instance of
+ * `DeviceOrientationManager` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiDeviceOrientationManager(): PigeonApiDeviceOrientationManager
+
+ /**
+ * An implementation of [PigeonApiPreview] used to add a new Dart instance of `Preview` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiPreview(): PigeonApiPreview
+
+ /**
+ * An implementation of [PigeonApiVideoCapture] used to add a new Dart instance of `VideoCapture`
+ * to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiVideoCapture(): PigeonApiVideoCapture
+
+ /**
+ * An implementation of [PigeonApiVideoOutput] used to add a new Dart instance of `VideoOutput` to
+ * the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiVideoOutput(): PigeonApiVideoOutput {
+ return PigeonApiVideoOutput(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiRecorder] used to add a new Dart instance of `Recorder` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiRecorder(): PigeonApiRecorder
+
+ /**
+ * An implementation of [PigeonApiVideoRecordEventListener] used to add a new Dart instance of
+ * `VideoRecordEventListener` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiVideoRecordEventListener(): PigeonApiVideoRecordEventListener
+
+ /**
+ * An implementation of [PigeonApiPendingRecording] used to add a new Dart instance of
+ * `PendingRecording` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiPendingRecording(): PigeonApiPendingRecording
+
+ /**
+ * An implementation of [PigeonApiRecording] used to add a new Dart instance of `Recording` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiRecording(): PigeonApiRecording
+
+ /**
+ * An implementation of [PigeonApiImageCapture] used to add a new Dart instance of `ImageCapture`
+ * to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiImageCapture(): PigeonApiImageCapture
+
+ /**
+ * An implementation of [PigeonApiResolutionStrategy] used to add a new Dart instance of
+ * `ResolutionStrategy` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiResolutionStrategy(): PigeonApiResolutionStrategy
+
+ /**
+ * An implementation of [PigeonApiResolutionSelector] used to add a new Dart instance of
+ * `ResolutionSelector` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiResolutionSelector(): PigeonApiResolutionSelector
+
+ /**
+ * An implementation of [PigeonApiAspectRatioStrategy] used to add a new Dart instance of
+ * `AspectRatioStrategy` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiAspectRatioStrategy(): PigeonApiAspectRatioStrategy
+
+ /**
+ * An implementation of [PigeonApiCameraState] used to add a new Dart instance of `CameraState` to
+ * the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraState(): PigeonApiCameraState
+
+ /**
+ * An implementation of [PigeonApiExposureState] used to add a new Dart instance of
+ * `ExposureState` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiExposureState(): PigeonApiExposureState
+
+ /**
+ * An implementation of [PigeonApiZoomState] used to add a new Dart instance of `ZoomState` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiZoomState(): PigeonApiZoomState
+
+ /**
+ * An implementation of [PigeonApiImageAnalysis] used to add a new Dart instance of
+ * `ImageAnalysis` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiImageAnalysis(): PigeonApiImageAnalysis
+
+ /**
+ * An implementation of [PigeonApiAnalyzer] used to add a new Dart instance of `Analyzer` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiAnalyzer(): PigeonApiAnalyzer
+
+ /**
+ * An implementation of [PigeonApiCameraStateStateError] used to add a new Dart instance of
+ * `CameraStateStateError` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraStateStateError(): PigeonApiCameraStateStateError
+
+ /**
+ * An implementation of [PigeonApiLiveData] used to add a new Dart instance of `LiveData` to the
+ * Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiLiveData(): PigeonApiLiveData
+
+ /**
+ * An implementation of [PigeonApiImageProxy] used to add a new Dart instance of `ImageProxy` to
+ * the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiImageProxy(): PigeonApiImageProxy
+
+ /**
+ * An implementation of [PigeonApiPlaneProxy] used to add a new Dart instance of `PlaneProxy` to
+ * the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiPlaneProxy(): PigeonApiPlaneProxy
+
+ /**
+ * An implementation of [PigeonApiQualitySelector] used to add a new Dart instance of
+ * `QualitySelector` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiQualitySelector(): PigeonApiQualitySelector
+
+ /**
+ * An implementation of [PigeonApiFallbackStrategy] used to add a new Dart instance of
+ * `FallbackStrategy` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiFallbackStrategy(): PigeonApiFallbackStrategy
+
+ /**
+ * An implementation of [PigeonApiCameraControl] used to add a new Dart instance of
+ * `CameraControl` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraControl(): PigeonApiCameraControl
+
+ /**
+ * An implementation of [PigeonApiFocusMeteringActionBuilder] used to add a new Dart instance of
+ * `FocusMeteringActionBuilder` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiFocusMeteringActionBuilder(): PigeonApiFocusMeteringActionBuilder
+
+ /**
+ * An implementation of [PigeonApiFocusMeteringAction] used to add a new Dart instance of
+ * `FocusMeteringAction` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiFocusMeteringAction(): PigeonApiFocusMeteringAction
+
+ /**
+ * An implementation of [PigeonApiFocusMeteringResult] used to add a new Dart instance of
+ * `FocusMeteringResult` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiFocusMeteringResult(): PigeonApiFocusMeteringResult
+
+ /**
+ * An implementation of [PigeonApiCaptureRequest] used to add a new Dart instance of
+ * `CaptureRequest` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCaptureRequest(): PigeonApiCaptureRequest
+
+ /**
+ * An implementation of [PigeonApiCaptureRequestKey] used to add a new Dart instance of
+ * `CaptureRequestKey` to the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiCaptureRequestKey(): PigeonApiCaptureRequestKey {
+ return PigeonApiCaptureRequestKey(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiCaptureRequestOptions] used to add a new Dart instance of
+ * `CaptureRequestOptions` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCaptureRequestOptions(): PigeonApiCaptureRequestOptions
+
+ /**
+ * An implementation of [PigeonApiCamera2CameraControl] used to add a new Dart instance of
+ * `Camera2CameraControl` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCamera2CameraControl(): PigeonApiCamera2CameraControl
+
+ /**
+ * An implementation of [PigeonApiResolutionFilter] used to add a new Dart instance of
+ * `ResolutionFilter` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiResolutionFilter(): PigeonApiResolutionFilter
+
+ /**
+ * An implementation of [PigeonApiCameraCharacteristicsKey] used to add a new Dart instance of
+ * `CameraCharacteristicsKey` to the Dart `InstanceManager`.
+ */
+ open fun getPigeonApiCameraCharacteristicsKey(): PigeonApiCameraCharacteristicsKey {
+ return PigeonApiCameraCharacteristicsKey(this)
+ }
+
+ /**
+ * An implementation of [PigeonApiCameraCharacteristics] used to add a new Dart instance of
+ * `CameraCharacteristics` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCameraCharacteristics(): PigeonApiCameraCharacteristics
+
+ /**
+ * An implementation of [PigeonApiCamera2CameraInfo] used to add a new Dart instance of
+ * `Camera2CameraInfo` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiCamera2CameraInfo(): PigeonApiCamera2CameraInfo
+
+ /**
+ * An implementation of [PigeonApiMeteringPointFactory] used to add a new Dart instance of
+ * `MeteringPointFactory` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiMeteringPointFactory(): PigeonApiMeteringPointFactory
+
+ /**
+ * An implementation of [PigeonApiDisplayOrientedMeteringPointFactory] used to add a new Dart
+ * instance of `DisplayOrientedMeteringPointFactory` to the Dart `InstanceManager`.
+ */
+ abstract fun getPigeonApiDisplayOrientedMeteringPointFactory():
+ PigeonApiDisplayOrientedMeteringPointFactory
+
+ fun setUp() {
+ CameraXLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, instanceManager)
+ PigeonApiCameraSize.setUpMessageHandlers(binaryMessenger, getPigeonApiCameraSize())
+ PigeonApiCameraIntegerRange.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiCameraIntegerRange())
+ PigeonApiMeteringPoint.setUpMessageHandlers(binaryMessenger, getPigeonApiMeteringPoint())
+ PigeonApiObserver.setUpMessageHandlers(binaryMessenger, getPigeonApiObserver())
+ PigeonApiCameraInfo.setUpMessageHandlers(binaryMessenger, getPigeonApiCameraInfo())
+ PigeonApiCameraSelector.setUpMessageHandlers(binaryMessenger, getPigeonApiCameraSelector())
+ PigeonApiProcessCameraProvider.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiProcessCameraProvider())
+ PigeonApiCamera.setUpMessageHandlers(binaryMessenger, getPigeonApiCamera())
+ PigeonApiSystemServicesManager.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiSystemServicesManager())
+ PigeonApiDeviceOrientationManager.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiDeviceOrientationManager())
+ PigeonApiPreview.setUpMessageHandlers(binaryMessenger, getPigeonApiPreview())
+ PigeonApiVideoCapture.setUpMessageHandlers(binaryMessenger, getPigeonApiVideoCapture())
+ PigeonApiRecorder.setUpMessageHandlers(binaryMessenger, getPigeonApiRecorder())
+ PigeonApiVideoRecordEventListener.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiVideoRecordEventListener())
+ PigeonApiPendingRecording.setUpMessageHandlers(binaryMessenger, getPigeonApiPendingRecording())
+ PigeonApiRecording.setUpMessageHandlers(binaryMessenger, getPigeonApiRecording())
+ PigeonApiImageCapture.setUpMessageHandlers(binaryMessenger, getPigeonApiImageCapture())
+ PigeonApiResolutionStrategy.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiResolutionStrategy())
+ PigeonApiResolutionSelector.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiResolutionSelector())
+ PigeonApiAspectRatioStrategy.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiAspectRatioStrategy())
+ PigeonApiImageAnalysis.setUpMessageHandlers(binaryMessenger, getPigeonApiImageAnalysis())
+ PigeonApiAnalyzer.setUpMessageHandlers(binaryMessenger, getPigeonApiAnalyzer())
+ PigeonApiLiveData.setUpMessageHandlers(binaryMessenger, getPigeonApiLiveData())
+ PigeonApiImageProxy.setUpMessageHandlers(binaryMessenger, getPigeonApiImageProxy())
+ PigeonApiQualitySelector.setUpMessageHandlers(binaryMessenger, getPigeonApiQualitySelector())
+ PigeonApiFallbackStrategy.setUpMessageHandlers(binaryMessenger, getPigeonApiFallbackStrategy())
+ PigeonApiCameraControl.setUpMessageHandlers(binaryMessenger, getPigeonApiCameraControl())
+ PigeonApiFocusMeteringActionBuilder.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiFocusMeteringActionBuilder())
+ PigeonApiCaptureRequest.setUpMessageHandlers(binaryMessenger, getPigeonApiCaptureRequest())
+ PigeonApiCaptureRequestOptions.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiCaptureRequestOptions())
+ PigeonApiCamera2CameraControl.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiCamera2CameraControl())
+ PigeonApiResolutionFilter.setUpMessageHandlers(binaryMessenger, getPigeonApiResolutionFilter())
+ PigeonApiCameraCharacteristics.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiCameraCharacteristics())
+ PigeonApiCamera2CameraInfo.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiCamera2CameraInfo())
+ PigeonApiMeteringPointFactory.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiMeteringPointFactory())
+ PigeonApiDisplayOrientedMeteringPointFactory.setUpMessageHandlers(
+ binaryMessenger, getPigeonApiDisplayOrientedMeteringPointFactory())
+ }
+
+ fun tearDown() {
+ CameraXLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraSize.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraIntegerRange.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiMeteringPoint.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiObserver.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraInfo.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraSelector.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiProcessCameraProvider.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCamera.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiSystemServicesManager.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiDeviceOrientationManager.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiPreview.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiVideoCapture.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiRecorder.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiVideoRecordEventListener.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiPendingRecording.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiRecording.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiImageCapture.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiResolutionStrategy.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiResolutionSelector.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiAspectRatioStrategy.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiImageAnalysis.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiAnalyzer.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiLiveData.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiImageProxy.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiQualitySelector.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiFallbackStrategy.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraControl.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiFocusMeteringActionBuilder.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCaptureRequest.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCaptureRequestOptions.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCamera2CameraControl.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiResolutionFilter.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCameraCharacteristics.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiCamera2CameraInfo.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiMeteringPointFactory.setUpMessageHandlers(binaryMessenger, null)
+ PigeonApiDisplayOrientedMeteringPointFactory.setUpMessageHandlers(binaryMessenger, null)
+ }
+}
+
+private class CameraXLibraryPigeonProxyApiBaseCodec(
+ val registrar: CameraXLibraryPigeonProxyApiRegistrar
+) : CameraXLibraryPigeonCodec() {
+ override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
+ return when (type) {
+ 128.toByte() -> {
+ val identifier: Long = readValue(buffer) as Long
+ val instance: Any? = registrar.instanceManager.getInstance(identifier)
+ if (instance == null) {
+ Log.e("PigeonProxyApiBaseCodec", "Failed to find instance with identifier: $identifier")
+ }
+ return instance
+ }
+ else -> super.readValueOfType(type, buffer)
+ }
+ }
+
+ override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
+ if (value is Boolean ||
+ value is ByteArray ||
+ value is Double ||
+ value is DoubleArray ||
+ value is FloatArray ||
+ value is Int ||
+ value is IntArray ||
+ value is List<*> ||
+ value is Long ||
+ value is LongArray ||
+ value is Map<*, *> ||
+ value is String ||
+ value is InfoSupportedHardwareLevel ||
+ value is AspectRatio ||
+ value is CameraStateType ||
+ value is LiveDataSupportedType ||
+ value is VideoQuality ||
+ value is MeteringMode ||
+ value is LensFacing ||
+ value is CameraXFlashMode ||
+ value is ResolutionStrategyFallbackRule ||
+ value is AspectRatioStrategyFallbackRule ||
+ value is CameraStateErrorCode ||
+ value == null) {
+ super.writeValue(stream, value)
+ return
+ }
+
+ if (value is android.util.Size) {
+ registrar.getPigeonApiCameraSize().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ResolutionInfo) {
+ registrar.getPigeonApiResolutionInfo().pigeon_newInstance(value) {}
+ } else if (value is android.util.Range<*>) {
+ registrar.getPigeonApiCameraIntegerRange().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.VideoRecordEvent.Start) {
+ registrar.getPigeonApiVideoRecordEventStart().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.VideoRecordEvent.Finalize) {
+ registrar.getPigeonApiVideoRecordEventFinalize().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.VideoRecordEvent) {
+ registrar.getPigeonApiVideoRecordEvent().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.MeteringPoint) {
+ registrar.getPigeonApiMeteringPoint().pigeon_newInstance(value) {}
+ } else if (value is androidx.lifecycle.Observer<*>) {
+ registrar.getPigeonApiObserver().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.CameraInfo) {
+ registrar.getPigeonApiCameraInfo().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.CameraSelector) {
+ registrar.getPigeonApiCameraSelector().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.lifecycle.ProcessCameraProvider) {
+ registrar.getPigeonApiProcessCameraProvider().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.Camera) {
+ registrar.getPigeonApiCamera().pigeon_newInstance(value) {}
+ } else if (value is SystemServicesManager) {
+ registrar.getPigeonApiSystemServicesManager().pigeon_newInstance(value) {}
+ } else if (value is CameraPermissionsError) {
+ registrar.getPigeonApiCameraPermissionsError().pigeon_newInstance(value) {}
+ } else if (value is DeviceOrientationManager) {
+ registrar.getPigeonApiDeviceOrientationManager().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.Preview) {
+ registrar.getPigeonApiPreview().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.VideoCapture<*>) {
+ registrar.getPigeonApiVideoCapture().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.Recorder) {
+ registrar.getPigeonApiRecorder().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.VideoOutput) {
+ registrar.getPigeonApiVideoOutput().pigeon_newInstance(value) {}
+ } else if (value is VideoRecordEventListener) {
+ registrar.getPigeonApiVideoRecordEventListener().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.PendingRecording) {
+ registrar.getPigeonApiPendingRecording().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.Recording) {
+ registrar.getPigeonApiRecording().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ImageCapture) {
+ registrar.getPigeonApiImageCapture().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.resolutionselector.ResolutionStrategy) {
+ registrar.getPigeonApiResolutionStrategy().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.resolutionselector.ResolutionSelector) {
+ registrar.getPigeonApiResolutionSelector().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.resolutionselector.AspectRatioStrategy) {
+ registrar.getPigeonApiAspectRatioStrategy().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.CameraState) {
+ registrar.getPigeonApiCameraState().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ExposureState) {
+ registrar.getPigeonApiExposureState().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ZoomState) {
+ registrar.getPigeonApiZoomState().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ImageAnalysis) {
+ registrar.getPigeonApiImageAnalysis().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.UseCase) {
+ registrar.getPigeonApiUseCase().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ImageAnalysis.Analyzer) {
+ registrar.getPigeonApiAnalyzer().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.CameraState.StateError) {
+ registrar.getPigeonApiCameraStateStateError().pigeon_newInstance(value) {}
+ } else if (value is io.flutter.plugins.camerax.LiveDataProxyApi.LiveDataWrapper) {
+ registrar.getPigeonApiLiveData().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ImageProxy) {
+ registrar.getPigeonApiImageProxy().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.ImageProxy.PlaneProxy) {
+ registrar.getPigeonApiPlaneProxy().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.QualitySelector) {
+ registrar.getPigeonApiQualitySelector().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.video.FallbackStrategy) {
+ registrar.getPigeonApiFallbackStrategy().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.CameraControl) {
+ registrar.getPigeonApiCameraControl().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.FocusMeteringAction.Builder) {
+ registrar.getPigeonApiFocusMeteringActionBuilder().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.FocusMeteringAction) {
+ registrar.getPigeonApiFocusMeteringAction().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.FocusMeteringResult) {
+ registrar.getPigeonApiFocusMeteringResult().pigeon_newInstance(value) {}
+ } else if (value is android.hardware.camera2.CaptureRequest) {
+ registrar.getPigeonApiCaptureRequest().pigeon_newInstance(value) {}
+ } else if (value is android.hardware.camera2.CaptureRequest.Key<*>) {
+ registrar.getPigeonApiCaptureRequestKey().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.camera2.interop.CaptureRequestOptions) {
+ registrar.getPigeonApiCaptureRequestOptions().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.camera2.interop.Camera2CameraControl) {
+ registrar.getPigeonApiCamera2CameraControl().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.resolutionselector.ResolutionFilter) {
+ registrar.getPigeonApiResolutionFilter().pigeon_newInstance(value) {}
+ } else if (value is android.hardware.camera2.CameraCharacteristics.Key<*>) {
+ registrar.getPigeonApiCameraCharacteristicsKey().pigeon_newInstance(value) {}
+ } else if (value is android.hardware.camera2.CameraCharacteristics) {
+ registrar.getPigeonApiCameraCharacteristics().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.camera2.interop.Camera2CameraInfo) {
+ registrar.getPigeonApiCamera2CameraInfo().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.DisplayOrientedMeteringPointFactory) {
+ registrar.getPigeonApiDisplayOrientedMeteringPointFactory().pigeon_newInstance(value) {}
+ } else if (value is androidx.camera.core.MeteringPointFactory) {
+ registrar.getPigeonApiMeteringPointFactory().pigeon_newInstance(value) {}
+ }
+
+ when {
+ registrar.instanceManager.containsInstance(value) -> {
+ stream.write(128)
+ writeValue(stream, registrar.instanceManager.getIdentifierForStrongReference(value))
+ }
+ else ->
+ throw IllegalArgumentException(
+ "Unsupported value: '$value' of type '${value.javaClass.name}'")
+ }
+ }
+}
+
+/**
+ * Generally classifies the overall set of the camera device functionality.
+ *
+ * See
+ * https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#INFO_SUPPORTED_HARDWARE_LEVEL_3.
+ */
+enum class InfoSupportedHardwareLevel(val raw: Int) {
+ /**
+ * This camera device is capable of YUV reprocessing and RAW data capture, in addition to
+ * FULL-level capabilities.
+ */
+ LEVEL3(0),
+ /** This camera device is backed by an external camera connected to this Android device. */
+ EXTERNAL(1),
+ /** This camera device is capable of supporting advanced imaging applications. */
+ FULL(2),
+ /** This camera device is running in backward compatibility mode. */
+ LEGACY(3),
+ /** This camera device does not have enough capabilities to qualify as a FULL device or better. */
+ LIMITED(4);
+
+ companion object {
+ fun ofRaw(raw: Int): InfoSupportedHardwareLevel? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * The aspect ratio of the use case.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/core/AspectRatio.
+ */
+enum class AspectRatio(val raw: Int) {
+ /** 16:9 standard aspect ratio. */
+ RATIO16TO9(0),
+ /** 4:3 standard aspect ratio. */
+ RATIO4TO3(1),
+ /** The aspect ratio representing no preference for aspect ratio. */
+ RATIO_DEFAULT(2),
+ /** The value is not recognized by the wrapper. */
+ UNKNOWN(3);
+
+ companion object {
+ fun ofRaw(raw: Int): AspectRatio? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * The states the camera can be in.
+ *
+ * See https://developer.android.com/reference/androidx/camera/core/CameraState.Type.
+ */
+enum class CameraStateType(val raw: Int) {
+ /** Represents a state where the camera device is closed. */
+ CLOSED(0),
+ /** Represents a state where the camera device is currently closing. */
+ CLOSING(1),
+ /** Represents a state where the camera device is open. */
+ OPEN(2),
+ /** Represents a state where the camera device is currently opening. */
+ OPENING(3),
+ /**
+ * Represents a state where the camera is waiting for a signal to attempt to open the camera
+ * device.
+ */
+ PENDING_OPEN(4),
+ /** This value is not recognized by this wrapper. */
+ UNKNOWN(5);
+
+ companion object {
+ fun ofRaw(raw: Int): CameraStateType? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/** The types (T) properly wrapped to be used as a LiveData. */
+enum class LiveDataSupportedType(val raw: Int) {
+ CAMERA_STATE(0),
+ ZOOM_STATE(1);
+
+ companion object {
+ fun ofRaw(raw: Int): LiveDataSupportedType? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * Video quality constraints that will be used by a QualitySelector to choose an appropriate video
+ * resolution.
+ *
+ * These are pre-defined quality constants that are universally used for video.
+ *
+ * See https://developer.android.com/reference/androidx/camera/video/Quality.
+ */
+enum class VideoQuality(val raw: Int) {
+ /** Standard Definition (SD) 480p video quality. */
+ SD(0),
+ /** High Definition (HD) 720p video quality. */
+ HD(1),
+ /** Full High Definition (FHD) 1080p video quality. */
+ FHD(2),
+ /** Ultra High Definition (UHD) 2160p video quality. */
+ UHD(3),
+ /** The lowest video quality supported by the video frame producer. */
+ LOWEST(4),
+ /** The highest video quality supported by the video frame producer. */
+ HIGHEST(5);
+
+ companion object {
+ fun ofRaw(raw: Int): VideoQuality? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * A flag used for indicating metering mode regions.
+ *
+ * See
+ * https://developer.android.com/reference/kotlin/androidx/camera/core/FocusMeteringAction#FLAG_AF().
+ */
+enum class MeteringMode(val raw: Int) {
+ /** A flag used in metering mode indicating the AE (Auto Exposure) region is enabled. */
+ AE(0),
+ /** A flag used in metering mode indicating the AF (Auto Focus) region is enabled. */
+ AF(1),
+ /** A flag used in metering mode indicating the AWB (Auto White Balance) region is enabled. */
+ AWB(2);
+
+ companion object {
+ fun ofRaw(raw: Int): MeteringMode? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * Direction of lens of a camera.
+ *
+ * See
+ * https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_BACK().
+ */
+enum class LensFacing(val raw: Int) {
+ /** A camera on the device facing the same direction as the device's screen. */
+ FRONT(0),
+ /** A camera on the device facing the opposite direction as the device's screen. */
+ BACK(1),
+ /** An external camera that has no fixed facing relative to the device's screen. */
+ EXTERNAL(2),
+ /** A camera on the devices that its lens facing is resolved. */
+ UNKNOWN(3);
+
+ companion object {
+ fun ofRaw(raw: Int): LensFacing? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * FlashModes for image capture.
+ *
+ * See
+ * https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture#FLASH_MODE_AUTO().
+ */
+enum class CameraXFlashMode(val raw: Int) {
+ /**
+ * Auto flash.
+ *
+ * The flash will be used according to the camera system's determination when taking a picture.
+ */
+ AUTO(0),
+ /**
+ * No flash.
+ *
+ * The flash will never be used when taking a picture.
+ */
+ OFF(1),
+ /**
+ * Always flash.
+ *
+ * The flash will always be used when taking a picture.
+ */
+ ON(2);
+
+ companion object {
+ fun ofRaw(raw: Int): CameraXFlashMode? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * Fallback rule for choosing an alternate size when the specified bound size is unavailable.
+ *
+ * See
+ * https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/ResolutionStrategy.
+ */
+enum class ResolutionStrategyFallbackRule(val raw: Int) {
+ /**
+ * When the specified bound size is unavailable, CameraX falls back to the closest higher
+ * resolution size.
+ */
+ CLOSEST_HIGHER(0),
+ /**
+ * When the specified bound size is unavailable, CameraX falls back to select the closest higher
+ * resolution size.
+ */
+ CLOSEST_HIGHER_THEN_LOWER(1),
+ /**
+ * When the specified bound size is unavailable, CameraX falls back to the closest lower
+ * resolution size.
+ */
+ CLOSEST_LOWER(2),
+ /**
+ * When the specified bound size is unavailable, CameraX falls back to select the closest lower
+ * resolution size.
+ *
+ * If CameraX still cannot find any available resolution, it will fallback to select other higher
+ * resolutions.
+ */
+ CLOSEST_LOWER_THEN_HIGHER(3),
+ /** CameraX doesn't select an alternate size when the specified bound size is unavailable. */
+ NONE(4),
+ /** The value is not recognized by the wrapper. */
+ UNKNOWN(5);
+
+ companion object {
+ fun ofRaw(raw: Int): ResolutionStrategyFallbackRule? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * Fallback rule for choosing the aspect ratio when the preferred aspect ratio is not available.
+ *
+ * See
+ * https://developer.android.com/reference/kotlin/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO().
+ */
+enum class AspectRatioStrategyFallbackRule(val raw: Int) {
+ /**
+ * CameraX automatically chooses the next best aspect ratio which contains the closest field of
+ * view (FOV) of the camera sensor, from the remaining options.
+ */
+ AUTO(0),
+ /**
+ * CameraX doesn't fall back to select sizes of any other aspect ratio when this fallback rule is
+ * used.
+ */
+ NONE(1),
+ /** The value is not recognized by the wrapper. */
+ UNKNOWN(2);
+
+ companion object {
+ fun ofRaw(raw: Int): AspectRatioStrategyFallbackRule? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+/**
+ * Code for a `CameraState` error.
+ *
+ * https://developer.android.com/reference/androidx/camera/core/CameraState#ERROR_CAMERA_DISABLED()
+ */
+enum class CameraStateErrorCode(val raw: Int) {
+ /** An error indicating that the camera device could not be opened due to a device policy. */
+ CAMERA_DISABLED(0),
+ /** An error indicating that the camera device was closed due to a fatal error. */
+ CAMERA_FATAL_ERROR(1),
+ /** An error indicating that the camera device is already in use. */
+ CAMERA_IN_USE(2),
+ /**
+ * An error indicating that the camera could not be opened because "Do Not Disturb" mode is
+ * enabled on devices affected by a bug in Android 9 (API level 28).
+ */
+ DO_NOT_DISTURB_MODE_ENABLED(3),
+ /**
+ * An error indicating that the limit number of open cameras has been reached, and more cameras
+ * cannot be opened until other instances are closed.
+ */
+ MAX_CAMERAS_IN_USE(4),
+ /** An error indicating that the camera device has encountered a recoverable error. */
+ OTHER_RECOVERABLE_ERROR(5),
+ /** An error indicating that configuring the camera has failed. */
+ STREAM_CONFIG(6),
+ /** The value is not recognized by this wrapper. */
+ UNKNOWN(7);
+
+ companion object {
+ fun ofRaw(raw: Int): CameraStateErrorCode? {
+ return values().firstOrNull { it.raw == raw }
+ }
+ }
+}
+
+private open class CameraXLibraryPigeonCodec : StandardMessageCodec() {
+ override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
+ return when (type) {
+ 129.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { InfoSupportedHardwareLevel.ofRaw(it.toInt()) }
+ }
+ 130.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { AspectRatio.ofRaw(it.toInt()) }
+ }
+ 131.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { CameraStateType.ofRaw(it.toInt()) }
+ }
+ 132.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { LiveDataSupportedType.ofRaw(it.toInt()) }
+ }
+ 133.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { VideoQuality.ofRaw(it.toInt()) }
+ }
+ 134.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { MeteringMode.ofRaw(it.toInt()) }
+ }
+ 135.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { LensFacing.ofRaw(it.toInt()) }
+ }
+ 136.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { CameraXFlashMode.ofRaw(it.toInt()) }
+ }
+ 137.toByte() -> {
+ return (readValue(buffer) as Long?)?.let {
+ ResolutionStrategyFallbackRule.ofRaw(it.toInt())
+ }
+ }
+ 138.toByte() -> {
+ return (readValue(buffer) as Long?)?.let {
+ AspectRatioStrategyFallbackRule.ofRaw(it.toInt())
+ }
+ }
+ 139.toByte() -> {
+ return (readValue(buffer) as Long?)?.let { CameraStateErrorCode.ofRaw(it.toInt()) }
+ }
+ else -> super.readValueOfType(type, buffer)
+ }
+ }
+
+ override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
+ when (value) {
+ is InfoSupportedHardwareLevel -> {
+ stream.write(129)
+ writeValue(stream, value.raw)
+ }
+ is AspectRatio -> {
+ stream.write(130)
+ writeValue(stream, value.raw)
+ }
+ is CameraStateType -> {
+ stream.write(131)
+ writeValue(stream, value.raw)
+ }
+ is LiveDataSupportedType -> {
+ stream.write(132)
+ writeValue(stream, value.raw)
+ }
+ is VideoQuality -> {
+ stream.write(133)
+ writeValue(stream, value.raw)
+ }
+ is MeteringMode -> {
+ stream.write(134)
+ writeValue(stream, value.raw)
+ }
+ is LensFacing -> {
+ stream.write(135)
+ writeValue(stream, value.raw)
+ }
+ is CameraXFlashMode -> {
+ stream.write(136)
+ writeValue(stream, value.raw)
+ }
+ is ResolutionStrategyFallbackRule -> {
+ stream.write(137)
+ writeValue(stream, value.raw)
+ }
+ is AspectRatioStrategyFallbackRule -> {
+ stream.write(138)
+ writeValue(stream, value.raw)
+ }
+ is CameraStateErrorCode -> {
+ stream.write(139)
+ writeValue(stream, value.raw)
+ }
+ else -> super.writeValue(stream, value)
+ }
+ }
+}
+
+/**
+ * Immutable class for describing width and height dimensions in pixels.
+ *
+ * See https://developer.android.com/reference/android/util/Size.html.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCameraSize(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun pigeon_defaultConstructor(width: Long, height: Long): android.util.Size
+
+ /** The width of the size (in pixels). */
+ abstract fun width(pigeon_instance: android.util.Size): Long
+
+ /** The height of the size (in pixels). */
+ abstract fun height(pigeon_instance: android.util.Size): Long
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCameraSize?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraSize.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val widthArg = args[1] as Long
+ val heightArg = args[2] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(widthArg, heightArg), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of CameraSize and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(pigeon_instanceArg: android.util.Size, callback: (Result) -> Unit) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val widthArg = width(pigeon_instanceArg)
+ val heightArg = height(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.CameraSize.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, widthArg, heightArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * A `ResolutionInfo` allows the application to know the resolution information of a specific use
+ * case.
+ *
+ * See https://developer.android.com/reference/androidx/camera/core/ResolutionInfo.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiResolutionInfo(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ /** Returns the output resolution used for the use case. */
+ abstract fun resolution(pigeon_instance: androidx.camera.core.ResolutionInfo): android.util.Size
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of ResolutionInfo and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.ResolutionInfo,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val resolutionArg = resolution(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.ResolutionInfo.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, resolutionArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * Immutable class for describing the range of two integer values.
+ *
+ * This is the equivalent to `android.util.Range`.
+ *
+ * See https://developer.android.com/reference/android/util/Range.html.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCameraIntegerRange(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun pigeon_defaultConstructor(lower: Long, upper: Long): android.util.Range<*>
+
+ /** The lower endpoint. */
+ abstract fun lower(pigeon_instance: android.util.Range<*>): Long
+
+ /** The upper endpoint. */
+ abstract fun upper(pigeon_instance: android.util.Range<*>): Long
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCameraIntegerRange?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraIntegerRange.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val lowerArg = args[1] as Long
+ val upperArg = args[2] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(lowerArg, upperArg), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of CameraIntegerRange and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: android.util.Range<*>,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val lowerArg = lower(pigeon_instanceArg)
+ val upperArg = upper(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.CameraIntegerRange.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, lowerArg, upperArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * VideoRecordEvent is used to report video recording events and status.
+ *
+ * See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.
+ */
+@Suppress("UNCHECKED_CAST")
+open class PigeonApiVideoRecordEvent(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of VideoRecordEvent and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.video.VideoRecordEvent,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.VideoRecordEvent.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * Indicates the start of recording.
+ *
+ * See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start.
+ */
+@Suppress("UNCHECKED_CAST")
+open class PigeonApiVideoRecordEventStart(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of VideoRecordEventStart and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.video.VideoRecordEvent.Start,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.VideoRecordEventStart.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+
+ @Suppress("FunctionName")
+ /** An implementation of [PigeonApiVideoRecordEvent] used to access callback methods */
+ fun pigeon_getPigeonApiVideoRecordEvent(): PigeonApiVideoRecordEvent {
+ return pigeonRegistrar.getPigeonApiVideoRecordEvent()
+ }
+}
+/**
+ * Indicates the finalization of recording.
+ *
+ * See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize.
+ */
+@Suppress("UNCHECKED_CAST")
+open class PigeonApiVideoRecordEventFinalize(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ @Suppress("LocalVariableName", "FunctionName")
+ /**
+ * Creates a Dart instance of VideoRecordEventFinalize and attaches it to [pigeon_instanceArg].
+ */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.video.VideoRecordEvent.Finalize,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.VideoRecordEventFinalize.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+
+ @Suppress("FunctionName")
+ /** An implementation of [PigeonApiVideoRecordEvent] used to access callback methods */
+ fun pigeon_getPigeonApiVideoRecordEvent(): PigeonApiVideoRecordEvent {
+ return pigeonRegistrar.getPigeonApiVideoRecordEvent()
+ }
+}
+/**
+ * A MeteringPoint is used to specify a region which can then be converted to sensor coordinate
+ * system for focus and metering purpose.
+ *
+ * See https://developer.android.com/reference/androidx/camera/core/MeteringPoint.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiMeteringPoint(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ /**
+ * Size of the MeteringPoint width and height (ranging from 0 to 1).
+ *
+ * It is the percentage of the sensor width/height (or crop region width/height if crop region is
+ * set).
+ */
+ abstract fun getSize(pigeon_instance: androidx.camera.core.MeteringPoint): Double
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiMeteringPoint?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.MeteringPoint.getSize",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.MeteringPoint
+ val wrapped: List =
+ try {
+ listOf(api.getSize(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of MeteringPoint and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.MeteringPoint,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.MeteringPoint.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * A simple callback that can receive from LiveData.
+ *
+ * See https://developer.android.com/reference/androidx/lifecycle/Observer.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiObserver(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ abstract fun pigeon_defaultConstructor(): androidx.lifecycle.Observer<*>
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiObserver?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Observer.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of Observer and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.lifecycle.Observer<*>,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ callback(
+ Result.failure(
+ CameraXError(
+ "new-instance-error",
+ "Attempting to create a new Dart instance of Observer, but the class has a nonnull callback method.",
+ "")))
+ }
+ }
+
+ /** Called when the data is changed to value. */
+ fun onChanged(
+ pigeon_instanceArg: androidx.lifecycle.Observer<*>,
+ valueArg: Any,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ return
+ }
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.Observer.onChanged"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_instanceArg, valueArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+}
+/**
+ * An interface for retrieving camera information.
+ *
+ * See https://developer.android.com/reference/androidx/camera/core/CameraInfo.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCameraInfo(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ /**
+ * Returns the sensor rotation in degrees, relative to the device's "natural" (default)
+ * orientation.
+ */
+ abstract fun sensorRotationDegrees(pigeon_instance: androidx.camera.core.CameraInfo): Long
+
+ /** Returns a ExposureState. */
+ abstract fun exposureState(
+ pigeon_instance: androidx.camera.core.CameraInfo
+ ): androidx.camera.core.ExposureState
+
+ /** A LiveData of the camera's state. */
+ abstract fun getCameraState(
+ pigeon_instance: androidx.camera.core.CameraInfo
+ ): io.flutter.plugins.camerax.LiveDataProxyApi.LiveDataWrapper
+
+ /** A LiveData of ZoomState. */
+ abstract fun getZoomState(
+ pigeon_instance: androidx.camera.core.CameraInfo
+ ): io.flutter.plugins.camerax.LiveDataProxyApi.LiveDataWrapper
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCameraInfo?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraInfo.getCameraState",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.CameraInfo
+ val wrapped: List =
+ try {
+ listOf(api.getCameraState(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraInfo.getZoomState",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.CameraInfo
+ val wrapped: List =
+ try {
+ listOf(api.getZoomState(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of CameraInfo and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.CameraInfo,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val sensorRotationDegreesArg = sensorRotationDegrees(pigeon_instanceArg)
+ val exposureStateArg = exposureState(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.CameraInfo.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, sensorRotationDegreesArg, exposureStateArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * A set of requirements and priorities used to select a camera or return a filtered set of cameras.
+ *
+ * See https://developer.android.com/reference/androidx/camera/core/CameraSelector.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCameraSelector(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun pigeon_defaultConstructor(
+ requireLensFacing: LensFacing?
+ ): androidx.camera.core.CameraSelector
+
+ /** A static `CameraSelector` that selects the default back facing camera. */
+ abstract fun defaultBackCamera(): androidx.camera.core.CameraSelector
+
+ /** A static `CameraSelector` that selects the default front facing camera. */
+ abstract fun defaultFrontCamera(): androidx.camera.core.CameraSelector
+
+ /** Filters the input `CameraInfo`s using the `CameraFilter`s assigned to the selector. */
+ abstract fun filter(
+ pigeon_instance: androidx.camera.core.CameraSelector,
+ cameraInfos: List
+ ): List
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCameraSelector?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraSelector.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val requireLensFacingArg = args[1] as LensFacing?
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(requireLensFacingArg), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraSelector.defaultBackCamera",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.defaultBackCamera(), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraSelector.defaultFrontCamera",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.defaultFrontCamera(), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.CameraSelector.filter",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.CameraSelector
+ val cameraInfosArg = args[1] as List
+ val wrapped: List =
+ try {
+ listOf(api.filter(pigeon_instanceArg, cameraInfosArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of CameraSelector and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.CameraSelector,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.CameraSelector.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * A singleton which can be used to bind the lifecycle of cameras to any `LifecycleOwner` within an
+ * application's process.
+ *
+ * See https://developer.android.com/reference/androidx/camera/lifecycle/ProcessCameraProvider.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiProcessCameraProvider(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ /** Retrieves the ProcessCameraProvider associated with the current process. */
+ abstract fun getInstance(
+ callback: (Result) -> Unit
+ )
+
+ /** The `CameraInfo` instances of the available cameras. */
+ abstract fun getAvailableCameraInfos(
+ pigeon_instance: androidx.camera.lifecycle.ProcessCameraProvider
+ ): List
+
+ /** Binds the collection of `UseCase` to a `LifecycleOwner`. */
+ abstract fun bindToLifecycle(
+ pigeon_instance: androidx.camera.lifecycle.ProcessCameraProvider,
+ cameraSelector: androidx.camera.core.CameraSelector,
+ useCases: List
+ ): androidx.camera.core.Camera
+
+ /** Returns true if the `UseCase` is bound to a lifecycle. */
+ abstract fun isBound(
+ pigeon_instance: androidx.camera.lifecycle.ProcessCameraProvider,
+ useCase: androidx.camera.core.UseCase
+ ): Boolean
+
+ /** Unbinds all specified use cases from the lifecycle provider. */
+ abstract fun unbind(
+ pigeon_instance: androidx.camera.lifecycle.ProcessCameraProvider,
+ useCases: List
+ )
+
+ /** Unbinds all use cases from the lifecycle provider and removes them from CameraX. */
+ abstract fun unbindAll(pigeon_instance: androidx.camera.lifecycle.ProcessCameraProvider)
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(
+ binaryMessenger: BinaryMessenger,
+ api: PigeonApiProcessCameraProvider?
+ ) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.getInstance",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { _, reply ->
+ api.getInstance { result: Result ->
+ val error = result.exceptionOrNull()
+ if (error != null) {
+ reply.reply(wrapError(error))
+ } else {
+ val data = result.getOrNull()
+ reply.reply(wrapResult(data))
+ }
+ }
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.getAvailableCameraInfos",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.lifecycle.ProcessCameraProvider
+ val wrapped: List =
+ try {
+ listOf(api.getAvailableCameraInfos(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.bindToLifecycle",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.lifecycle.ProcessCameraProvider
+ val cameraSelectorArg = args[1] as androidx.camera.core.CameraSelector
+ val useCasesArg = args[2] as List
+ val wrapped: List =
+ try {
+ listOf(api.bindToLifecycle(pigeon_instanceArg, cameraSelectorArg, useCasesArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.isBound",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.lifecycle.ProcessCameraProvider
+ val useCaseArg = args[1] as androidx.camera.core.UseCase
+ val wrapped: List =
+ try {
+ listOf(api.isBound(pigeon_instanceArg, useCaseArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.unbind",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.lifecycle.ProcessCameraProvider
+ val useCasesArg = args[1] as List
+ val wrapped: List =
+ try {
+ api.unbind(pigeon_instanceArg, useCasesArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.unbindAll",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.lifecycle.ProcessCameraProvider
+ val wrapped: List =
+ try {
+ api.unbindAll(pigeon_instanceArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of ProcessCameraProvider and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.lifecycle.ProcessCameraProvider,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.ProcessCameraProvider.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * The use case which all other use cases are built on top of.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase.
+ */
+@Suppress("UNCHECKED_CAST")
+open class PigeonApiUseCase(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of UseCase and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.UseCase,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.UseCase.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * The camera interface is used to control the flow of data to use cases, control the camera via the
+ * `CameraControl`, and publish the state of the camera via CameraInfo.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/core/Camera.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCamera(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ /** The `CameraControl` for the Camera. */
+ abstract fun cameraControl(
+ pigeon_instance: androidx.camera.core.Camera
+ ): androidx.camera.core.CameraControl
+
+ /** Returns information about this camera. */
+ abstract fun getCameraInfo(
+ pigeon_instance: androidx.camera.core.Camera
+ ): androidx.camera.core.CameraInfo
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCamera?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Camera.getCameraInfo",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Camera
+ val wrapped: List =
+ try {
+ listOf(api.getCameraInfo(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of Camera and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.Camera,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val cameraControlArg = cameraControl(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.Camera.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, cameraControlArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/** Convenience class for accessing system resources. */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiSystemServicesManager(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun pigeon_defaultConstructor(): SystemServicesManager
+
+ abstract fun requestCameraPermissions(
+ pigeon_instance: SystemServicesManager,
+ enableAudio: Boolean,
+ callback: (Result) -> Unit
+ )
+
+ /** Returns a path to be used to create a temp file in the current cache directory. */
+ abstract fun getTempFilePath(
+ pigeon_instance: SystemServicesManager,
+ prefix: String,
+ suffix: String
+ ): String
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(
+ binaryMessenger: BinaryMessenger,
+ api: PigeonApiSystemServicesManager?
+ ) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.SystemServicesManager.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.SystemServicesManager.requestCameraPermissions",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as SystemServicesManager
+ val enableAudioArg = args[1] as Boolean
+ api.requestCameraPermissions(pigeon_instanceArg, enableAudioArg) {
+ result: Result ->
+ val error = result.exceptionOrNull()
+ if (error != null) {
+ reply.reply(wrapError(error))
+ } else {
+ val data = result.getOrNull()
+ reply.reply(wrapResult(data))
+ }
+ }
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.SystemServicesManager.getTempFilePath",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as SystemServicesManager
+ val prefixArg = args[1] as String
+ val suffixArg = args[2] as String
+ val wrapped: List =
+ try {
+ listOf(api.getTempFilePath(pigeon_instanceArg, prefixArg, suffixArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of SystemServicesManager and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: SystemServicesManager,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ callback(
+ Result.failure(
+ CameraXError(
+ "new-instance-error",
+ "Attempting to create a new Dart instance of SystemServicesManager, but the class has a nonnull callback method.",
+ "")))
+ }
+ }
+
+ fun onCameraError(
+ pigeon_instanceArg: SystemServicesManager,
+ errorDescriptionArg: String,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ return
+ }
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.SystemServicesManager.onCameraError"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_instanceArg, errorDescriptionArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+}
+/** Contains data when an attempt to retrieve camera permissions fails. */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiCameraPermissionsError(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun errorCode(pigeon_instance: CameraPermissionsError): String
+
+ abstract fun description(pigeon_instance: CameraPermissionsError): String
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of CameraPermissionsError and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: CameraPermissionsError,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val errorCodeArg = errorCode(pigeon_instanceArg)
+ val descriptionArg = description(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.CameraPermissionsError.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, errorCodeArg, descriptionArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * Support class to help to determine the media orientation based on the orientation of the device.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiDeviceOrientationManager(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ abstract fun pigeon_defaultConstructor(): DeviceOrientationManager
+
+ abstract fun startListeningForDeviceOrientationChange(pigeon_instance: DeviceOrientationManager)
+
+ abstract fun stopListeningForDeviceOrientationChange(pigeon_instance: DeviceOrientationManager)
+
+ abstract fun getDefaultDisplayRotation(pigeon_instance: DeviceOrientationManager): Long
+
+ abstract fun getUiOrientation(pigeon_instance: DeviceOrientationManager): String
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(
+ binaryMessenger: BinaryMessenger,
+ api: PigeonApiDeviceOrientationManager?
+ ) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.startListeningForDeviceOrientationChange",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as DeviceOrientationManager
+ val wrapped: List =
+ try {
+ api.startListeningForDeviceOrientationChange(pigeon_instanceArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.stopListeningForDeviceOrientationChange",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as DeviceOrientationManager
+ val wrapped: List =
+ try {
+ api.stopListeningForDeviceOrientationChange(pigeon_instanceArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.getDefaultDisplayRotation",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as DeviceOrientationManager
+ val wrapped: List =
+ try {
+ listOf(api.getDefaultDisplayRotation(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.getUiOrientation",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as DeviceOrientationManager
+ val wrapped: List =
+ try {
+ listOf(api.getUiOrientation(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /**
+ * Creates a Dart instance of DeviceOrientationManager and attaches it to [pigeon_instanceArg].
+ */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: DeviceOrientationManager,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ callback(
+ Result.failure(
+ CameraXError(
+ "new-instance-error",
+ "Attempting to create a new Dart instance of DeviceOrientationManager, but the class has a nonnull callback method.",
+ "")))
+ }
+ }
+
+ fun onDeviceOrientationChanged(
+ pigeon_instanceArg: DeviceOrientationManager,
+ orientationArg: String,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ return
+ }
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName =
+ "dev.flutter.pigeon.camera_android_camerax.DeviceOrientationManager.onDeviceOrientationChanged"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_instanceArg, orientationArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+}
+/**
+ * A use case that provides a camera preview stream for displaying on-screen.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/core/Preview.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiPreview(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ abstract fun pigeon_defaultConstructor(
+ resolutionSelector: androidx.camera.core.resolutionselector.ResolutionSelector?,
+ targetRotation: Long?
+ ): androidx.camera.core.Preview
+
+ abstract fun resolutionSelector(
+ pigeon_instance: androidx.camera.core.Preview
+ ): androidx.camera.core.resolutionselector.ResolutionSelector?
+
+ /**
+ * Sets a SurfaceProvider to provide a Surface for Preview.
+ *
+ * This is a convenience function that
+ * 1. Creates a `SurfaceProvider` using the `SurfaceProducer` provided by the Flutter engine.
+ * 2. Sets this method with the created `SurfaceProvider`.
+ * 3. Returns the texture id of the `TextureEntry` that provided the `SurfaceProducer`.
+ */
+ abstract fun setSurfaceProvider(
+ pigeon_instance: androidx.camera.core.Preview,
+ systemServicesManager: SystemServicesManager
+ ): Long
+
+ /** Releases the `SurfaceProducer` created in `setSurfaceProvider` if one was created. */
+ abstract fun releaseSurfaceProvider(pigeon_instance: androidx.camera.core.Preview)
+
+ /** Gets selected resolution information of the `Preview`. */
+ abstract fun getResolutionInfo(
+ pigeon_instance: androidx.camera.core.Preview
+ ): androidx.camera.core.ResolutionInfo?
+
+ /** Sets the target rotation. */
+ abstract fun setTargetRotation(pigeon_instance: androidx.camera.core.Preview, rotation: Long)
+
+ /**
+ * Returns whether or not the preview's surface producer handles correctly rotating the camera
+ * preview automatically.
+ */
+ abstract fun surfaceProducerHandlesCropAndRotation(
+ pigeon_instance: androidx.camera.core.Preview
+ ): Boolean
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiPreview?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val resolutionSelectorArg =
+ args[1] as androidx.camera.core.resolutionselector.ResolutionSelector?
+ val targetRotationArg = args[2] as Long?
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(resolutionSelectorArg, targetRotationArg),
+ pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.setSurfaceProvider",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Preview
+ val systemServicesManagerArg = args[1] as SystemServicesManager
+ val wrapped: List =
+ try {
+ listOf(api.setSurfaceProvider(pigeon_instanceArg, systemServicesManagerArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.releaseSurfaceProvider",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Preview
+ val wrapped: List =
+ try {
+ api.releaseSurfaceProvider(pigeon_instanceArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.getResolutionInfo",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Preview
+ val wrapped: List =
+ try {
+ listOf(api.getResolutionInfo(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.setTargetRotation",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Preview
+ val rotationArg = args[1] as Long
+ val wrapped: List =
+ try {
+ api.setTargetRotation(pigeon_instanceArg, rotationArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Preview.surfaceProducerHandlesCropAndRotation",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.core.Preview
+ val wrapped: List =
+ try {
+ listOf(api.surfaceProducerHandlesCropAndRotation(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of Preview and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.core.Preview,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val resolutionSelectorArg = resolutionSelector(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.Preview.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg, resolutionSelectorArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+
+ @Suppress("FunctionName")
+ /** An implementation of [PigeonApiUseCase] used to access callback methods */
+ fun pigeon_getPigeonApiUseCase(): PigeonApiUseCase {
+ return pigeonRegistrar.getPigeonApiUseCase()
+ }
+}
+/**
+ * A use case that provides camera stream suitable for video application.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiVideoCapture(
+ open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar
+) {
+ /** Create a `VideoCapture` associated with the given `VideoOutput`. */
+ abstract fun withOutput(
+ videoOutput: androidx.camera.video.VideoOutput
+ ): androidx.camera.video.VideoCapture<*>
+
+ /** Gets the VideoOutput associated with this VideoCapture. */
+ abstract fun getOutput(
+ pigeon_instance: androidx.camera.video.VideoCapture<*>
+ ): androidx.camera.video.VideoOutput
+
+ /** Sets the desired rotation of the output video. */
+ abstract fun setTargetRotation(
+ pigeon_instance: androidx.camera.video.VideoCapture<*>,
+ rotation: Long
+ )
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiVideoCapture?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.VideoCapture.withOutput",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val videoOutputArg = args[1] as androidx.camera.video.VideoOutput
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.withOutput(videoOutputArg), pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.VideoCapture.getOutput",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.video.VideoCapture<*>
+ val wrapped: List =
+ try {
+ listOf(api.getOutput(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.VideoCapture.setTargetRotation",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.video.VideoCapture<*>
+ val rotationArg = args[1] as Long
+ val wrapped: List =
+ try {
+ api.setTargetRotation(pigeon_instanceArg, rotationArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ }
+ }
+
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of VideoCapture and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.video.VideoCapture<*>,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.VideoCapture.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+
+ @Suppress("FunctionName")
+ /** An implementation of [PigeonApiUseCase] used to access callback methods */
+ fun pigeon_getPigeonApiUseCase(): PigeonApiUseCase {
+ return pigeonRegistrar.getPigeonApiUseCase()
+ }
+}
+/**
+ * A class that will produce video data from a Surface.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/video/VideoOutput.
+ */
+@Suppress("UNCHECKED_CAST")
+open class PigeonApiVideoOutput(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ @Suppress("LocalVariableName", "FunctionName")
+ /** Creates a Dart instance of VideoOutput and attaches it to [pigeon_instanceArg]. */
+ fun pigeon_newInstance(
+ pigeon_instanceArg: androidx.camera.video.VideoOutput,
+ callback: (Result) -> Unit
+ ) {
+ if (pigeonRegistrar.ignoreCallsToDart) {
+ callback(
+ Result.failure(
+ CameraXError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
+ } else if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
+ callback(Result.success(Unit))
+ } else {
+ val pigeon_identifierArg =
+ pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
+ val binaryMessenger = pigeonRegistrar.binaryMessenger
+ val codec = pigeonRegistrar.codec
+ val channelName = "dev.flutter.pigeon.camera_android_camerax.VideoOutput.pigeon_newInstance"
+ val channel = BasicMessageChannel(binaryMessenger, channelName, codec)
+ channel.send(listOf(pigeon_identifierArg)) {
+ if (it is List<*>) {
+ if (it.size > 1) {
+ callback(
+ Result.failure(CameraXError(it[0] as String, it[1] as String, it[2] as String?)))
+ } else {
+ callback(Result.success(Unit))
+ }
+ } else {
+ callback(Result.failure(createConnectionError(channelName)))
+ }
+ }
+ }
+ }
+}
+/**
+ * An implementation of `VideoOutput` for starting video recordings that are saved to a File,
+ * ParcelFileDescriptor, or MediaStore.
+ *
+ * See https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder.
+ */
+@Suppress("UNCHECKED_CAST")
+abstract class PigeonApiRecorder(open val pigeonRegistrar: CameraXLibraryPigeonProxyApiRegistrar) {
+ abstract fun pigeon_defaultConstructor(
+ aspectRatio: Long?,
+ targetVideoEncodingBitRate: Long?,
+ qualitySelector: androidx.camera.video.QualitySelector?
+ ): androidx.camera.video.Recorder
+
+ /** Gets the aspect ratio of this Recorder. */
+ abstract fun getAspectRatio(pigeon_instance: androidx.camera.video.Recorder): Long
+
+ /** Gets the target video encoding bitrate of this Recorder. */
+ abstract fun getTargetVideoEncodingBitRate(pigeon_instance: androidx.camera.video.Recorder): Long
+
+ /** The quality selector of this Recorder. */
+ abstract fun getQualitySelector(
+ pigeon_instance: androidx.camera.video.Recorder
+ ): androidx.camera.video.QualitySelector
+
+ /** Prepares a recording that will be saved to a File. */
+ abstract fun prepareRecording(
+ pigeon_instance: androidx.camera.video.Recorder,
+ path: String
+ ): androidx.camera.video.PendingRecording
+
+ companion object {
+ @Suppress("LocalVariableName")
+ fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiRecorder?) {
+ val codec = api?.pigeonRegistrar?.codec ?: CameraXLibraryPigeonCodec()
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Recorder.pigeon_defaultConstructor",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_identifierArg = args[0] as Long
+ val aspectRatioArg = args[1] as Long?
+ val targetVideoEncodingBitRateArg = args[2] as Long?
+ val qualitySelectorArg = args[3] as androidx.camera.video.QualitySelector?
+ val wrapped: List =
+ try {
+ api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
+ api.pigeon_defaultConstructor(
+ aspectRatioArg, targetVideoEncodingBitRateArg, qualitySelectorArg),
+ pigeon_identifierArg)
+ listOf(null)
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Recorder.getAspectRatio",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.video.Recorder
+ val wrapped: List =
+ try {
+ listOf(api.getAspectRatio(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel(
+ binaryMessenger,
+ "dev.flutter.pigeon.camera_android_camerax.Recorder.getTargetVideoEncodingBitRate",
+ codec)
+ if (api != null) {
+ channel.setMessageHandler { message, reply ->
+ val args = message as List
+ val pigeon_instanceArg = args[0] as androidx.camera.video.Recorder
+ val wrapped: List =
+ try {
+ listOf(api.getTargetVideoEncodingBitRate(pigeon_instanceArg))
+ } catch (exception: Throwable) {
+ wrapError(exception)
+ }
+ reply.reply(wrapped)
+ }
+ } else {
+ channel.setMessageHandler(null)
+ }
+ }
+ run {
+ val channel =
+ BasicMessageChannel