From dec3d697b4622d0edc5f7665215bda6f06706258 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 1 May 2023 16:34:43 -0700 Subject: [PATCH 01/10] Merge remote-tracking branch 'upstream/main' into camx_occ --- .../camera_android_camerax/CHANGELOG.md | 1 + .../camerax/CameraInfoHostApiImpl.java | 38 ++ .../camerax/GeneratedCameraXLibrary.java | 627 ++++++++++-------- .../plugins/camerax/CameraInfoTest.java | 1 + .../lib/src/android_camera_camerax.dart | 55 ++ ...roid_camera_camerax_flutter_api_impls.dart | 70 +- .../lib/src/camera_info.dart | 22 + .../lib/src/camerax_library.g.dart | 327 ++++++--- .../pigeons/camerax_library.dart | 25 + .../test/android_camera_camerax_test.dart | 65 +- .../android_camera_camerax_test.mocks.dart | 9 + .../test/camera_info_test.dart | 1 + .../test/camera_info_test.mocks.dart | 8 + .../test/camera_test.dart | 4 +- .../test/test_camerax_library.g.dart | 431 +++++------- 15 files changed, 977 insertions(+), 707 deletions(-) diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index 1c901a82bfac..24fbec47e8b7 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -21,3 +21,4 @@ * Implements image streaming. * Provides LifecycleOwner implementation for Activities that use the plugin that do not implement it themselves. * Implements retrieval of camera information. +* Implements onCameraClosing callback method for indicating the camera is closing and bumps CameraX version to 1.3.0-alpha05. 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 index f9fd7722fc87..973e2928d789 100644 --- 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 @@ -6,8 +6,10 @@ import androidx.annotation.NonNull; 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 java.util.Objects; @@ -66,4 +68,40 @@ public Long getZoomState(@NonNull Long identifier) { return instanceManager.getIdentifierForStrongReference(zoomState); } + + /** + * 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 current {@link ZoomState} value of the {@link CameraInfo} with the specified + * identifier. + */ + @NonNull + @Override + public Long getZoomState(@NonNull Long identifier) { + CameraInfo cameraInfo = + (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier)); + // TODO(camsim99): Create/return LiveData once https://github.com/flutter/packages/pull/3419 lands. + ZoomState zoomState = cameraInfo.getZoomState().getValue(); + + ZoomStateFlutterApiImpl zoomStateFlutterApiImpl = + new ZoomStateFlutterApiImpl(binaryMessenger, instanceManager); + zoomStateFlutterApiImpl.create(zoomState, result -> {}); + + return instanceManager.getIdentifierForStrongReference(zoomState); + } } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java index 882c1d146323..d48feb044a36 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java @@ -18,7 +18,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) @@ -33,7 +35,8 @@ public static class FlutterError extends RuntimeException { /** The error details. Must be a datatype supported by the api codec. */ public final Object details; - public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { + public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) + { super(message); this.code = code; this.details = details; @@ -52,7 +55,7 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { errorList.add(exception.toString()); errorList.add(exception.getClass().getSimpleName()); errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); } return errorList; } @@ -123,13 +126,9 @@ ArrayList toList() { static @NonNull ResolutionInfo fromList(@NonNull ArrayList list) { ResolutionInfo pigeonResult = new ResolutionInfo(); Object width = list.get(0); - pigeonResult.setWidth( - (width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width)); + pigeonResult.setWidth((width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width)); Object height = list.get(1); - pigeonResult.setHeight( - (height == null) - ? null - : ((height instanceof Integer) ? (Integer) height : (Long) height)); + pigeonResult.setHeight((height == null) ? null : ((height instanceof Integer) ? (Integer) height : (Long) height)); return pigeonResult; } } @@ -273,19 +272,82 @@ ArrayList toList() { static @NonNull ExposureCompensationRange fromList(@NonNull ArrayList list) { ExposureCompensationRange pigeonResult = new ExposureCompensationRange(); Object minCompensation = list.get(0); - pigeonResult.setMinCompensation( - (minCompensation == null) - ? null - : ((minCompensation instanceof Integer) - ? (Integer) minCompensation - : (Long) minCompensation)); + pigeonResult.setMinCompensation((minCompensation == null) ? null : ((minCompensation instanceof Integer) ? (Integer) minCompensation : (Long) minCompensation)); Object maxCompensation = list.get(1); - pigeonResult.setMaxCompensation( - (maxCompensation == null) - ? null - : ((maxCompensation instanceof Integer) - ? (Integer) maxCompensation - : (Long) maxCompensation)); + pigeonResult.setMaxCompensation((maxCompensation == null) ? null : ((maxCompensation instanceof Integer) ? (Integer) maxCompensation : (Long) maxCompensation)); + return pigeonResult; + } + } + + /** Generated class from Pigeon that represents data sent in messages. */ + public static final class ExposureCompensationRange { + private @NonNull Long minCompensation; + + public @NonNull Long getMinCompensation() { + return minCompensation; + } + + public void setMinCompensation(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"minCompensation\" is null."); + } + this.minCompensation = setterArg; + } + + private @NonNull Long maxCompensation; + + public @NonNull Long getMaxCompensation() { + return maxCompensation; + } + + public void setMaxCompensation(@NonNull Long setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"maxCompensation\" is null."); + } + this.maxCompensation = setterArg; + } + + /** Constructor is non-public to enforce null safety; use Builder. */ + ExposureCompensationRange() {} + + public static final class Builder { + + private @Nullable Long minCompensation; + + public @NonNull Builder setMinCompensation(@NonNull Long setterArg) { + this.minCompensation = setterArg; + return this; + } + + private @Nullable Long maxCompensation; + + public @NonNull Builder setMaxCompensation(@NonNull Long setterArg) { + this.maxCompensation = setterArg; + return this; + } + + public @NonNull ExposureCompensationRange build() { + ExposureCompensationRange pigeonReturn = new ExposureCompensationRange(); + pigeonReturn.setMinCompensation(minCompensation); + pigeonReturn.setMaxCompensation(maxCompensation); + return pigeonReturn; + } + } + + @NonNull + ArrayList toList() { + ArrayList toListResult = new ArrayList(2); + toListResult.add(minCompensation); + toListResult.add(maxCompensation); + return toListResult; + } + + static @NonNull ExposureCompensationRange fromList(@NonNull ArrayList list) { + ExposureCompensationRange pigeonResult = new ExposureCompensationRange(); + Object minCompensation = list.get(0); + pigeonResult.setMinCompensation((minCompensation == null) ? null : ((minCompensation instanceof Integer) ? (Integer) minCompensation : (Long) minCompensation)); + Object maxCompensation = list.get(1); + pigeonResult.setMaxCompensation((maxCompensation == null) ? null : ((maxCompensation instanceof Integer) ? (Integer) maxCompensation : (Long) maxCompensation)); return pigeonResult; } } @@ -301,7 +363,7 @@ public interface InstanceManagerHostApi { /** * Clear the native `InstanceManager`. * - *

This is typically only used after a hot restart. + * This is typically only used after a hot restart. */ void clear(); @@ -309,12 +371,8 @@ public interface InstanceManagerHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `InstanceManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable InstanceManagerHostApi api) { + /**Sets up an instance of `InstanceManagerHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable InstanceManagerHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -326,7 +384,8 @@ static void setup( try { api.clear(); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -347,9 +406,7 @@ public interface JavaObjectHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable JavaObjectHostApi api) { { BasicMessageChannel channel = @@ -364,7 +421,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable JavaObject try { api.dispose((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -384,7 +442,7 @@ public JavaObjectFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -393,7 +451,6 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void dispose(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -406,29 +463,28 @@ public void dispose(@NonNull Long identifierArg, @NonNull Reply callback) /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface CameraInfoHostApi { - @NonNull + @NonNull Long getSensorRotationDegrees(@NonNull Long identifier); - @NonNull + @NonNull + Long getLiveCameraState(@NonNull Long identifier); + + @NonNull Long getExposureState(@NonNull Long identifier); - @NonNull + @NonNull Long getZoomState(@NonNull Long identifier); /** The codec used by CameraInfoHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `CameraInfoHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `CameraInfoHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfoHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -436,11 +492,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = - api.getSensorRotationDegrees( - (identifierArg == null) ? null : identifierArg.longValue()); + Long output = api.getSensorRotationDegrees((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -453,9 +508,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.CameraInfoHostApi.getExposureState", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.CameraInfoHostApi.getLiveCameraState", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -463,11 +516,34 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = - api.getExposureState( - (identifierArg == null) ? null : identifierArg.longValue()); + Long output = api.getLiveCameraState((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.CameraInfoHostApi.getExposureState", getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + try { + Long output = api.getExposureState((identifierArg == null) ? null : identifierArg.longValue()); + wrapped.add(0, output); + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -488,10 +564,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = - api.getZoomState((identifierArg == null) ? null : identifierArg.longValue()); + Long output = api.getZoomState((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -511,7 +587,7 @@ public CameraInfoFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -520,7 +596,6 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -535,19 +610,15 @@ public interface CameraSelectorHostApi { void create(@NonNull Long identifier, @Nullable Long lensFacing); - @NonNull + @NonNull List filter(@NonNull Long identifier, @NonNull List cameraInfoIds); /** The codec used by CameraSelectorHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `CameraSelectorHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable CameraSelectorHostApi api) { + /**Sets up an instance of `CameraSelectorHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraSelectorHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -560,11 +631,10 @@ static void setup( Number identifierArg = (Number) args.get(0); Number lensFacingArg = (Number) args.get(1); try { - api.create( - (identifierArg == null) ? null : identifierArg.longValue(), - (lensFacingArg == null) ? null : lensFacingArg.longValue()); + api.create((identifierArg == null) ? null : identifierArg.longValue(), (lensFacingArg == null) ? null : lensFacingArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -586,12 +656,10 @@ static void setup( Number identifierArg = (Number) args.get(0); List cameraInfoIdsArg = (List) args.get(1); try { - List output = - api.filter( - (identifierArg == null) ? null : identifierArg.longValue(), - cameraInfoIdsArg); + List output = api.filter((identifierArg == null) ? null : identifierArg.longValue(), cameraInfoIdsArg); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -611,7 +679,7 @@ public CameraSelectorFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -620,9 +688,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void create( - @NonNull Long identifierArg, @Nullable Long lensFacingArg, @NonNull Reply callback) { + public void create(@NonNull Long identifierArg, @Nullable Long lensFacingArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.CameraSelectorFlutterApi.create", getCodec()); @@ -636,16 +702,13 @@ public interface ProcessCameraProviderHostApi { void getInstance(@NonNull Result result); - @NonNull + @NonNull List getAvailableCameraInfos(@NonNull Long identifier); - @NonNull - Long bindToLifecycle( - @NonNull Long identifier, - @NonNull Long cameraSelectorIdentifier, - @NonNull List useCaseIds); + @NonNull + Long bindToLifecycle(@NonNull Long identifier, @NonNull Long cameraSelectorIdentifier, @NonNull List useCaseIds); - @NonNull + @NonNull Boolean isBound(@NonNull Long identifier, @NonNull Long useCaseIdentifier); void unbind(@NonNull Long identifier, @NonNull List useCaseIds); @@ -656,18 +719,12 @@ Long bindToLifecycle( static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `ProcessCameraProviderHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable ProcessCameraProviderHostApi api) { + /**Sets up an instance of `ProcessCameraProviderHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ProcessCameraProviderHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -694,9 +751,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -704,11 +759,10 @@ public void error(Throwable error) { ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - List output = - api.getAvailableCameraInfos( - (identifierArg == null) ? null : identifierArg.longValue()); + List output = api.getAvailableCameraInfos((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -721,9 +775,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -733,15 +785,10 @@ public void error(Throwable error) { Number cameraSelectorIdentifierArg = (Number) args.get(1); List useCaseIdsArg = (List) args.get(2); try { - Long output = - api.bindToLifecycle( - (identifierArg == null) ? null : identifierArg.longValue(), - (cameraSelectorIdentifierArg == null) - ? null - : cameraSelectorIdentifierArg.longValue(), - useCaseIdsArg); + Long output = api.bindToLifecycle((identifierArg == null) ? null : identifierArg.longValue(), (cameraSelectorIdentifierArg == null) ? null : cameraSelectorIdentifierArg.longValue(), useCaseIdsArg); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -754,9 +801,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -765,12 +810,10 @@ public void error(Throwable error) { Number identifierArg = (Number) args.get(0); Number useCaseIdentifierArg = (Number) args.get(1); try { - Boolean output = - api.isBound( - (identifierArg == null) ? null : identifierArg.longValue(), - (useCaseIdentifierArg == null) ? null : useCaseIdentifierArg.longValue()); + Boolean output = api.isBound((identifierArg == null) ? null : identifierArg.longValue(), (useCaseIdentifierArg == null) ? null : useCaseIdentifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -783,9 +826,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -794,10 +835,10 @@ public void error(Throwable error) { Number identifierArg = (Number) args.get(0); List useCaseIdsArg = (List) args.get(1); try { - api.unbind( - (identifierArg == null) ? null : identifierArg.longValue(), useCaseIdsArg); + api.unbind((identifierArg == null) ? null : identifierArg.longValue(), useCaseIdsArg); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -810,9 +851,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -822,7 +861,8 @@ public void error(Throwable error) { try { api.unbindAll((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -842,7 +882,7 @@ public ProcessCameraProviderFlutterApi(@NonNull BinaryMessenger argBinaryMesseng this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -851,13 +891,10 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create", getCodec()); channel.send( new ArrayList(Collections.singletonList(identifierArg)), channelReply -> callback.reply(null)); @@ -866,14 +903,14 @@ public void create(@NonNull Long identifierArg, @NonNull Reply callback) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface CameraHostApi { - @NonNull + @NonNull Long getCameraInfo(@NonNull Long identifier); /** The codec used by CameraHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** Sets up an instance of `CameraHostApi` to handle messages through the `binaryMessenger`. */ + /**Sets up an instance of `CameraHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraHostApi api) { { BasicMessageChannel channel = @@ -886,10 +923,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraHost ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = - api.getCameraInfo((identifierArg == null) ? null : identifierArg.longValue()); + Long output = api.getCameraInfo((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -909,7 +946,7 @@ public CameraFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -918,7 +955,6 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -958,11 +994,9 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface SystemServicesHostApi { - void requestCameraPermissions( - @NonNull Boolean enableAudio, @NonNull Result result); + void requestCameraPermissions(@NonNull Boolean enableAudio, @NonNull Result result); - void startListeningForDeviceOrientationChange( - @NonNull Boolean isFrontFacing, @NonNull Long sensorOrientation); + void startListeningForDeviceOrientationChange(@NonNull Boolean isFrontFacing, @NonNull Long sensorOrientation); void stopListeningForDeviceOrientationChange(); @@ -970,18 +1004,12 @@ void startListeningForDeviceOrientationChange( static @NonNull MessageCodec getCodec() { return SystemServicesHostApiCodec.INSTANCE; } - /** - * Sets up an instance of `SystemServicesHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable SystemServicesHostApi api) { + /**Sets up an instance of `SystemServicesHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable SystemServicesHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1010,9 +1038,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1021,11 +1047,10 @@ public void error(Throwable error) { Boolean isFrontFacingArg = (Boolean) args.get(0); Number sensorOrientationArg = (Number) args.get(1); try { - api.startListeningForDeviceOrientationChange( - isFrontFacingArg, - (sensorOrientationArg == null) ? null : sensorOrientationArg.longValue()); + api.startListeningForDeviceOrientationChange(isFrontFacingArg, (sensorOrientationArg == null) ? null : sensorOrientationArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1038,9 +1063,7 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1048,7 +1071,8 @@ public void error(Throwable error) { try { api.stopListeningForDeviceOrientationChange(); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1068,7 +1092,7 @@ public SystemServicesFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1077,25 +1101,18 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void onDeviceOrientationChanged( - @NonNull String orientationArg, @NonNull Reply callback) { + public void onDeviceOrientationChanged(@NonNull String orientationArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged", getCodec()); channel.send( new ArrayList(Collections.singletonList(orientationArg)), channelReply -> callback.reply(null)); } - public void onCameraError(@NonNull String errorDescriptionArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError", getCodec()); channel.send( new ArrayList(Collections.singletonList(errorDescriptionArg)), channelReply -> callback.reply(null)); @@ -1136,24 +1153,21 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface PreviewHostApi { - void create( - @NonNull Long identifier, - @Nullable Long rotation, - @Nullable ResolutionInfo targetResolution); + void create(@NonNull Long identifier, @Nullable Long rotation, @Nullable ResolutionInfo targetResolution); - @NonNull + @NonNull Long setSurfaceProvider(@NonNull Long identifier); void releaseFlutterSurfaceTexture(); - @NonNull + @NonNull ResolutionInfo getResolutionInfo(@NonNull Long identifier); /** The codec used by PreviewHostApi. */ static @NonNull MessageCodec getCodec() { return PreviewHostApiCodec.INSTANCE; } - /** Sets up an instance of `PreviewHostApi` to handle messages through the `binaryMessenger`. */ + /**Sets up an instance of `PreviewHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHostApi api) { { BasicMessageChannel channel = @@ -1168,12 +1182,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos Number rotationArg = (Number) args.get(1); ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); try { - api.create( - (identifierArg == null) ? null : identifierArg.longValue(), - (rotationArg == null) ? null : rotationArg.longValue(), - targetResolutionArg); + api.create((identifierArg == null) ? null : identifierArg.longValue(), (rotationArg == null) ? null : rotationArg.longValue(), targetResolutionArg); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1186,9 +1198,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1196,11 +1206,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = - api.setSurfaceProvider( - (identifierArg == null) ? null : identifierArg.longValue()); + Long output = api.setSurfaceProvider((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1213,9 +1222,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1223,7 +1230,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos try { api.releaseFlutterSurfaceTexture(); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1244,11 +1252,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - ResolutionInfo output = - api.getResolutionInfo( - (identifierArg == null) ? null : identifierArg.longValue()); + ResolutionInfo output = api.getResolutionInfo((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1290,10 +1297,7 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageCaptureHostApi { - void create( - @NonNull Long identifier, - @Nullable Long flashMode, - @Nullable ResolutionInfo targetResolution); + void create(@NonNull Long identifier, @Nullable Long flashMode, @Nullable ResolutionInfo targetResolution); void setFlashMode(@NonNull Long identifier, @NonNull Long flashMode); @@ -1303,10 +1307,7 @@ void create( static @NonNull MessageCodec getCodec() { return ImageCaptureHostApiCodec.INSTANCE; } - /** - * Sets up an instance of `ImageCaptureHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `ImageCaptureHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptureHostApi api) { { BasicMessageChannel channel = @@ -1321,12 +1322,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu Number flashModeArg = (Number) args.get(1); ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); try { - api.create( - (identifierArg == null) ? null : identifierArg.longValue(), - (flashModeArg == null) ? null : flashModeArg.longValue(), - targetResolutionArg); + api.create((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue(), targetResolutionArg); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1348,11 +1347,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu Number identifierArg = (Number) args.get(0); Number flashModeArg = (Number) args.get(1); try { - api.setFlashMode( - (identifierArg == null) ? null : identifierArg.longValue(), - (flashModeArg == null) ? null : flashModeArg.longValue()); + api.setFlashMode((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1385,8 +1383,7 @@ public void error(Throwable error) { } }; - api.takePicture( - (identifierArg == null) ? null : identifierArg.longValue(), resultCallback); + api.takePicture((identifierArg == null) ? null : identifierArg.longValue(), resultCallback); }); } else { channel.setMessageHandler(null); @@ -1429,7 +1426,7 @@ public ExposureStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1438,19 +1435,12 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return ExposureStateFlutterApiCodec.INSTANCE; } - - public void create( - @NonNull Long identifierArg, - @NonNull ExposureCompensationRange exposureCompensationRangeArg, - @NonNull Double exposureCompensationStepArg, - @NonNull Reply callback) { + public void create(@NonNull Long identifierArg, @NonNull ExposureCompensationRange exposureCompensationRangeArg, @NonNull Double exposureCompensationStepArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ExposureStateFlutterApi.create", getCodec()); channel.send( - new ArrayList( - Arrays.asList( - identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), + new ArrayList(Arrays.asList(identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), channelReply -> callback.reply(null)); } } @@ -1462,7 +1452,7 @@ public ZoomStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1471,12 +1461,86 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void create(@NonNull Long identifierArg, @NonNull Double minZoomRatioArg, @NonNull Double maxZoomRatioArg, @NonNull Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.ZoomStateFlutterApi.create", getCodec()); + channel.send( + new ArrayList(Arrays.asList(identifierArg, minZoomRatioArg, maxZoomRatioArg)), + channelReply -> callback.reply(null)); + } + } + + private static class ExposureStateFlutterApiCodec extends StandardMessageCodec { + public static final ExposureStateFlutterApiCodec INSTANCE = new ExposureStateFlutterApiCodec(); + + private ExposureStateFlutterApiCodec() {} + + @Override + protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { + switch (type) { + case (byte) 128: + return ExposureCompensationRange.fromList((ArrayList) readValue(buffer)); + default: + return super.readValueOfType(type, buffer); + } + } + + @Override + protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { + if (value instanceof ExposureCompensationRange) { + stream.write(128); + writeValue(stream, ((ExposureCompensationRange) value).toList()); + } else { + super.writeValue(stream, value); + } + } + } + + /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ + public static class ExposureStateFlutterApi { + private final @NonNull BinaryMessenger binaryMessenger; - public void create( - @NonNull Long identifierArg, - @NonNull Double minZoomRatioArg, - @NonNull Double maxZoomRatioArg, - @NonNull Reply callback) { + public ExposureStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { + this.binaryMessenger = argBinaryMessenger; + } + + /** Public interface for sending reply. */ + @SuppressWarnings("UnknownNullness") + public interface Reply { + void reply(T reply); + } + /** The codec used by ExposureStateFlutterApi. */ + static @NonNull MessageCodec getCodec() { + return ExposureStateFlutterApiCodec.INSTANCE; + } + public void create(@NonNull Long identifierArg, @NonNull ExposureCompensationRange exposureCompensationRangeArg, @NonNull Double exposureCompensationStepArg, @NonNull Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.ExposureStateFlutterApi.create", getCodec()); + channel.send( + new ArrayList(Arrays.asList(identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), + channelReply -> callback.reply(null)); + } + } + /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ + public static class ZoomStateFlutterApi { + private final @NonNull BinaryMessenger binaryMessenger; + + public ZoomStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { + this.binaryMessenger = argBinaryMessenger; + } + + /** Public interface for sending reply. */ + @SuppressWarnings("UnknownNullness") + public interface Reply { + void reply(T reply); + } + /** The codec used by ZoomStateFlutterApi. */ + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); + } + public void create(@NonNull Long identifierArg, @NonNull Double minZoomRatioArg, @NonNull Double maxZoomRatioArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ZoomStateFlutterApi.create", getCodec()); @@ -1525,12 +1589,8 @@ public interface ImageAnalysisHostApi { static @NonNull MessageCodec getCodec() { return ImageAnalysisHostApiCodec.INSTANCE; } - /** - * Sets up an instance of `ImageAnalysisHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnalysisHostApi api) { + /**Sets up an instance of `ImageAnalysisHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnalysisHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1543,11 +1603,10 @@ static void setup( Number identifierArg = (Number) args.get(0); ResolutionInfo targetResolutionIdentifierArg = (ResolutionInfo) args.get(1); try { - api.create( - (identifierArg == null) ? null : identifierArg.longValue(), - targetResolutionIdentifierArg); + api.create((identifierArg == null) ? null : identifierArg.longValue(), targetResolutionIdentifierArg); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1569,11 +1628,10 @@ static void setup( Number identifierArg = (Number) args.get(0); Number analyzerIdentifierArg = (Number) args.get(1); try { - api.setAnalyzer( - (identifierArg == null) ? null : identifierArg.longValue(), - (analyzerIdentifierArg == null) ? null : analyzerIdentifierArg.longValue()); + api.setAnalyzer((identifierArg == null) ? null : identifierArg.longValue(), (analyzerIdentifierArg == null) ? null : analyzerIdentifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1586,9 +1644,7 @@ static void setup( { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1598,7 +1654,8 @@ static void setup( try { api.clearAnalyzer((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1619,9 +1676,7 @@ public interface AnalyzerHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `AnalyzerHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `AnalyzerHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable AnalyzerHostApi api) { { BasicMessageChannel channel = @@ -1636,7 +1691,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable AnalyzerHo try { api.create((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1656,7 +1712,7 @@ public AnalyzerFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1665,7 +1721,6 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1674,11 +1729,7 @@ public void create(@NonNull Long identifierArg, @NonNull Reply callback) { new ArrayList(Collections.singletonList(identifierArg)), channelReply -> callback.reply(null)); } - - public void analyze( - @NonNull Long identifierArg, - @NonNull Long imageProxyIdentifierArg, - @NonNull Reply callback) { + public void analyze(@NonNull Long identifierArg, @NonNull Long imageProxyIdentifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.AnalyzerFlutterApi.analyze", getCodec()); @@ -1690,7 +1741,7 @@ public void analyze( /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageProxyHostApi { - @NonNull + @NonNull List getPlanes(@NonNull Long identifier); void close(@NonNull Long identifier); @@ -1699,9 +1750,7 @@ public interface ImageProxyHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `ImageProxyHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `ImageProxyHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxyHostApi api) { { BasicMessageChannel channel = @@ -1714,10 +1763,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxy ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - List output = - api.getPlanes((identifierArg == null) ? null : identifierArg.longValue()); + List output = api.getPlanes((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1740,7 +1789,8 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxy try { api.close((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } catch (Throwable exception) { + } + catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1760,7 +1810,7 @@ public ImageProxyFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1769,13 +1819,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void create( - @NonNull Long identifierArg, - @NonNull Long formatArg, - @NonNull Long heightArg, - @NonNull Long widthArg, - @NonNull Reply callback) { + public void create(@NonNull Long identifierArg, @NonNull Long formatArg, @NonNull Long heightArg, @NonNull Long widthArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ImageProxyFlutterApi.create", getCodec()); @@ -1792,7 +1836,7 @@ public PlaneProxyFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1801,19 +1845,12 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void create( - @NonNull Long identifierArg, - @NonNull byte[] bufferArg, - @NonNull Long pixelStrideArg, - @NonNull Long rowStrideArg, - @NonNull Reply callback) { + public void create(@NonNull Long identifierArg, @NonNull byte[] bufferArg, @NonNull Long pixelStrideArg, @NonNull Long rowStrideArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.PlaneProxyFlutterApi.create", getCodec()); channel.send( - new ArrayList( - Arrays.asList(identifierArg, bufferArg, pixelStrideArg, rowStrideArg)), + new ArrayList(Arrays.asList(identifierArg, bufferArg, pixelStrideArg, rowStrideArg)), channelReply -> callback.reply(null)); } } diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraInfoTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraInfoTest.java index 5cfd06935b85..379cf3f3b05c 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraInfoTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraInfoTest.java @@ -13,6 +13,7 @@ import static org.mockito.Mockito.when; import androidx.camera.core.CameraInfo; +import androidx.camera.core.CameraState; import androidx.camera.core.ExposureState; import androidx.camera.core.ZoomState; import androidx.lifecycle.LiveData; diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index 174a373e3b9b..f0eac80d9eed 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -45,6 +45,10 @@ class AndroidCameraCameraX extends CameraPlatform { @visibleForTesting CameraInfo? cameraInfo; + /// The [LiveData] of the [CameraState] that represents the state of the + /// [camera] instance. + LiveData? liveCameraState; + /// The [Preview] instance that can be configured to present a live camera preview. @visibleForTesting Preview? preview; @@ -196,6 +200,7 @@ class AndroidCameraCameraX extends CameraPlatform { // instance as bound but not paused. camera = await processCameraProvider! .bindToLifecycle(cameraSelector!, [preview!, imageCapture!]); + await _updateLiveCameraState(flutterSurfaceTextureId); cameraInfo = await camera!.getCameraInfo(); _previewIsPaused = false; @@ -325,6 +330,55 @@ class AndroidCameraCameraX extends CameraPlatform { return exposureState.minZoomRatio; } + /// Gets the minimum supported exposure offset for the selected camera in EV units. + /// + /// [cameraId] not used. + @override + Future getMinExposureOffset(int cameraId) async { + final ExposureState exposureState = await cameraInfo!.getExposureState(); + return exposureState.exposureCompensationRange.minCompensation * + exposureState.exposureCompensationStep; + } + + /// Gets the maximum supported exposure offset for the selected camera in EV units. + /// + /// [cameraId] not used. + @override + Future getMaxExposureOffset(int cameraId) async { + final ExposureState exposureState = await cameraInfo!.getExposureState(); + return exposureState.exposureCompensationRange.maxCompensation * + exposureState.exposureCompensationStep; + } + + /// Gets the supported step size for exposure offset for the selected camera in EV units. + /// + /// Returns 0 when exposure compensation is not supported. + /// + /// [cameraId] not used. + @override + Future getExposureOffsetStepSize(int cameraId) async { + final ExposureState exposureState = await cameraInfo!.getExposureState(); + return exposureState.exposureCompensationStep; + } + + /// Gets the maximum supported zoom level for the selected camera. + /// + /// [cameraId] not used. + @override + Future getMaxZoomLevel(int cameraId) async { + final ZoomState exposureState = await cameraInfo!.getZoomState(); + return exposureState.maxZoomRatio; + } + + /// Gets the minimum supported zoom level for the selected camera. + /// + /// [cameraId] not used. + @override + Future getMinZoomLevel(int cameraId) async { + final ZoomState exposureState = await cameraInfo!.getZoomState(); + return exposureState.minZoomRatio; + } + /// The ui orientation changed. @override Stream onDeviceOrientationChanged() { @@ -413,6 +467,7 @@ class AndroidCameraCameraX extends CameraPlatform { camera = await processCameraProvider! .bindToLifecycle(cameraSelector!, [preview!]); + await _updateLiveCameraState(cameraId); cameraInfo = await camera!.getCameraInfo(); } diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart index c5692ae105f2..f92ef8349267 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart @@ -19,33 +19,46 @@ import 'zoom_state.dart'; class AndroidCameraXCameraFlutterApis { /// Creates a [AndroidCameraXCameraFlutterApis]. AndroidCameraXCameraFlutterApis({ - JavaObjectFlutterApiImpl? javaObjectFlutterApi, - CameraFlutterApiImpl? cameraFlutterApi, - CameraInfoFlutterApiImpl? cameraInfoFlutterApi, - CameraSelectorFlutterApiImpl? cameraSelectorFlutterApi, - ProcessCameraProviderFlutterApiImpl? processCameraProviderFlutterApi, - SystemServicesFlutterApiImpl? systemServicesFlutterApi, + JavaObjectFlutterApiImpl? javaObjectFlutterApiImpl, + CameraFlutterApiImpl? cameraFlutterApiImpl, + CameraInfoFlutterApiImpl? cameraInfoFlutterApiImpl, + CameraSelectorFlutterApiImpl? cameraSelectorFlutterApiImpl, + ProcessCameraProviderFlutterApiImpl? processCameraProviderFlutterApiImpl, + SystemServicesFlutterApiImpl? systemServicesFlutterApiImpl, + CameraStateErrorFlutterApiImpl? cameraStateErrorFlutterApiImpl, + CameraStateFlutterApiImpl? cameraStateFlutterApiImpl, ExposureStateFlutterApiImpl? exposureStateFlutterApiImpl, ZoomStateFlutterApiImpl? zoomStateFlutterApiImpl, - AnalyzerFlutterApiImpl? analyzerFlutterApiImpl, + LiveDataFlutterApiImpl? liveDataFlutterApiImpl, + ObserverFlutterApiImpl? observerFlutterApiImpl, ImageProxyFlutterApiImpl? imageProxyFlutterApiImpl, PlaneProxyFlutterApiImpl? planeProxyFlutterApiImpl, + AnalyzerFlutterApiImpl? analyzerFlutterApiImpl, }) { - this.javaObjectFlutterApi = - javaObjectFlutterApi ?? JavaObjectFlutterApiImpl(); - this.cameraInfoFlutterApi = - cameraInfoFlutterApi ?? CameraInfoFlutterApiImpl(); - this.cameraSelectorFlutterApi = - cameraSelectorFlutterApi ?? CameraSelectorFlutterApiImpl(); - this.processCameraProviderFlutterApi = processCameraProviderFlutterApi ?? - ProcessCameraProviderFlutterApiImpl(); - this.cameraFlutterApi = cameraFlutterApi ?? CameraFlutterApiImpl(); - this.systemServicesFlutterApi = - systemServicesFlutterApi ?? SystemServicesFlutterApiImpl(); + this.javaObjectFlutterApiImpl = + javaObjectFlutterApiImpl ?? JavaObjectFlutterApiImpl(); + this.cameraInfoFlutterApiImpl = + cameraInfoFlutterApiImpl ?? CameraInfoFlutterApiImpl(); + this.cameraSelectorFlutterApiImpl = + cameraSelectorFlutterApiImpl ?? CameraSelectorFlutterApiImpl(); + this.processCameraProviderFlutterApiImpl = + processCameraProviderFlutterApiImpl ?? + ProcessCameraProviderFlutterApiImpl(); + this.cameraFlutterApiImpl = cameraFlutterApiImpl ?? CameraFlutterApiImpl(); + this.systemServicesFlutterApiImpl = + systemServicesFlutterApiImpl ?? SystemServicesFlutterApiImpl(); + this.cameraStateErrorFlutterApiImpl = + cameraStateErrorFlutterApiImpl ?? CameraStateErrorFlutterApiImpl(); + this.cameraStateFlutterApiImpl = + cameraStateFlutterApiImpl ?? CameraStateFlutterApiImpl(); this.exposureStateFlutterApiImpl = exposureStateFlutterApiImpl ?? ExposureStateFlutterApiImpl(); this.zoomStateFlutterApiImpl = zoomStateFlutterApiImpl ?? ZoomStateFlutterApiImpl(); + this.liveDataFlutterApiImpl = + liveDataFlutterApiImpl ?? LiveDataFlutterApiImpl(); + this.observerFlutterApiImpl = + observerFlutterApiImpl ?? ObserverFlutterApiImpl(); this.analyzerFlutterApiImpl = analyzerFlutterApiImpl ?? AnalyzerFlutterApiImpl(); this.imageProxyFlutterApiImpl = @@ -87,6 +100,12 @@ class AndroidCameraXCameraFlutterApis { /// Flutter Api for [ZoomState]. late final ZoomStateFlutterApiImpl zoomStateFlutterApiImpl; + /// Flutter Api for [ExposureState]. + late final ExposureStateFlutterApiImpl exposureStateFlutterApiImpl; + + /// Flutter Api for [ZoomState]. + late final ZoomStateFlutterApiImpl zoomStateFlutterApiImpl; + /// Flutter Api implementation for [Analyzer]. late final AnalyzerFlutterApiImpl analyzerFlutterApiImpl; @@ -99,12 +118,15 @@ class AndroidCameraXCameraFlutterApis { /// Ensures all the Flutter APIs have been setup to receive calls from native code. void ensureSetUp() { if (!_haveBeenSetUp) { - JavaObjectFlutterApi.setup(javaObjectFlutterApi); - CameraInfoFlutterApi.setup(cameraInfoFlutterApi); - CameraSelectorFlutterApi.setup(cameraSelectorFlutterApi); - ProcessCameraProviderFlutterApi.setup(processCameraProviderFlutterApi); - CameraFlutterApi.setup(cameraFlutterApi); - SystemServicesFlutterApi.setup(systemServicesFlutterApi); + JavaObjectFlutterApi.setup(javaObjectFlutterApiImpl); + CameraInfoFlutterApi.setup(cameraInfoFlutterApiImpl); + CameraSelectorFlutterApi.setup(cameraSelectorFlutterApiImpl); + ProcessCameraProviderFlutterApi.setup( + processCameraProviderFlutterApiImpl); + CameraFlutterApi.setup(cameraFlutterApiImpl); + SystemServicesFlutterApi.setup(systemServicesFlutterApiImpl); + CameraStateErrorFlutterApi.setup(cameraStateErrorFlutterApiImpl); + CameraStateFlutterApi.setup(cameraStateFlutterApiImpl); ExposureStateFlutterApi.setup(exposureStateFlutterApiImpl); ZoomStateFlutterApi.setup(zoomStateFlutterApiImpl); AnalyzerFlutterApi.setup(analyzerFlutterApiImpl); diff --git a/packages/camera/camera_android_camerax/lib/src/camera_info.dart b/packages/camera/camera_android_camerax/lib/src/camera_info.dart index f2fdc1fdc879..07e6816fc70a 100644 --- a/packages/camera/camera_android_camerax/lib/src/camera_info.dart +++ b/packages/camera/camera_android_camerax/lib/src/camera_info.dart @@ -9,6 +9,7 @@ import 'camerax_library.g.dart'; import 'exposure_state.dart'; import 'instance_manager.dart'; import 'java_object.dart'; +import 'live_data.dart'; import 'zoom_state.dart'; /// Represents the metadata of a camera. @@ -32,6 +33,10 @@ class CameraInfo extends JavaObject { Future getSensorRotationDegrees() => _api.getSensorRotationDegreesFromInstance(this); + /// Starts listening for the camera closing. + Future> getLiveCameraState() => + _api.getLiveCameraStateFromInstance(this); + /// Gets the exposure state of the camera. Future getExposureState() => _api.getExposureStateFromInstance(this); @@ -76,6 +81,23 @@ class _CameraInfoHostApiImpl extends CameraInfoHostApi { return instanceManager .getInstanceWithWeakReference(zoomStateIdentifier)!; } + + /// Gets the [ExposureState] of the specified [CameraInfo] instance. + Future getExposureStateFromInstance( + CameraInfo instance) async { + final int? identifier = instanceManager.getIdentifier(instance); + final int exposureStateIdentifier = await getExposureState(identifier!); + return instanceManager + .getInstanceWithWeakReference(exposureStateIdentifier)!; + } + + /// Gets the [ZoomState] of the specified [CameraInfo] instance. + Future getZoomStateFromInstance(CameraInfo instance) async { + final int? identifier = instanceManager.getIdentifier(instance); + final int zoomStateIdentifier = await getZoomState(identifier!); + return instanceManager + .getInstanceWithWeakReference(zoomStateIdentifier)!; + } } /// Flutter API implementation of [CameraInfo]. diff --git a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart index f2d2e17152fb..b5afcaa735a9 100644 --- a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart @@ -89,6 +89,32 @@ class ExposureCompensationRange { } } +class ExposureCompensationRange { + ExposureCompensationRange({ + required this.minCompensation, + required this.maxCompensation, + }); + + int minCompensation; + + int maxCompensation; + + Object encode() { + return [ + minCompensation, + maxCompensation, + ]; + } + + static ExposureCompensationRange decode(Object result) { + result as List; + return ExposureCompensationRange( + minCompensation: result[0]! as int, + maxCompensation: result[1]! as int, + ); + } +} + class InstanceManagerHostApi { /// Constructor for [InstanceManagerHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -106,7 +132,8 @@ class InstanceManagerHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.InstanceManagerHostApi.clear', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; + final List? replyList = + await channel.send(null) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -162,8 +189,7 @@ abstract class JavaObjectFlutterApi { void dispose(int identifier); - static void setup(JavaObjectFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(JavaObjectFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaObjectFlutterApi.dispose', codec, @@ -173,7 +199,7 @@ abstract class JavaObjectFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaObjectFlutterApi.dispose was null.'); + 'Argument for dev.flutter.pigeon.JavaObjectFlutterApi.dispose was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -223,6 +249,33 @@ class CameraInfoHostApi { } } + Future getLiveCameraState(int arg_identifier) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CameraInfoHostApi.getLiveCameraState', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_identifier]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as int?)!; + } + } + Future getExposureState(int arg_identifier) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraInfoHostApi.getExposureState', codec, @@ -283,8 +336,7 @@ abstract class CameraInfoFlutterApi { void create(int identifier); - static void setup(CameraInfoFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(CameraInfoFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraInfoFlutterApi.create', codec, @@ -294,7 +346,7 @@ abstract class CameraInfoFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraInfoFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.CameraInfoFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -321,8 +373,8 @@ class CameraSelectorHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraSelectorHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_lensFacing]) as List?; + final List? replyList = + await channel.send([arg_identifier, arg_lensFacing]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -339,13 +391,12 @@ class CameraSelectorHostApi { } } - Future> filter( - int arg_identifier, List arg_cameraInfoIds) async { + Future> filter(int arg_identifier, List arg_cameraInfoIds) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraSelectorHostApi.filter', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_cameraInfoIds]) as List?; + final List? replyList = + await channel.send([arg_identifier, arg_cameraInfoIds]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -373,8 +424,7 @@ abstract class CameraSelectorFlutterApi { void create(int identifier, int? lensFacing); - static void setup(CameraSelectorFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(CameraSelectorFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraSelectorFlutterApi.create', codec, @@ -384,7 +434,7 @@ abstract class CameraSelectorFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraSelectorFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.CameraSelectorFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -412,7 +462,8 @@ class ProcessCameraProviderHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; + final List? replyList = + await channel.send(null) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -436,8 +487,7 @@ class ProcessCameraProviderHostApi { Future> getAvailableCameraInfos(int arg_identifier) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos', - codec, + 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos', codec, binaryMessenger: _binaryMessenger); final List? replyList = await channel.send([arg_identifier]) as List?; @@ -462,17 +512,12 @@ class ProcessCameraProviderHostApi { } } - Future bindToLifecycle(int arg_identifier, - int arg_cameraSelectorIdentifier, List arg_useCaseIds) async { + Future bindToLifecycle(int arg_identifier, int arg_cameraSelectorIdentifier, List arg_useCaseIds) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle', - codec, + 'dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send([ - arg_identifier, - arg_cameraSelectorIdentifier, - arg_useCaseIds - ]) as List?; + final List? replyList = + await channel.send([arg_identifier, arg_cameraSelectorIdentifier, arg_useCaseIds]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -499,8 +544,7 @@ class ProcessCameraProviderHostApi { 'dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound', codec, binaryMessenger: _binaryMessenger); final List? replyList = - await channel.send([arg_identifier, arg_useCaseIdentifier]) - as List?; + await channel.send([arg_identifier, arg_useCaseIdentifier]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -526,8 +570,8 @@ class ProcessCameraProviderHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_useCaseIds]) as List?; + final List? replyList = + await channel.send([arg_identifier, arg_useCaseIds]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -572,8 +616,7 @@ abstract class ProcessCameraProviderFlutterApi { void create(int identifier); - static void setup(ProcessCameraProviderFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(ProcessCameraProviderFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create', codec, @@ -583,7 +626,7 @@ abstract class ProcessCameraProviderFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -649,7 +692,7 @@ abstract class CameraFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.CameraFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -677,7 +720,7 @@ class _SystemServicesHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return CameraPermissionsErrorData.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -695,11 +738,9 @@ class SystemServicesHostApi { static const MessageCodec codec = _SystemServicesHostApiCodec(); - Future requestCameraPermissions( - bool arg_enableAudio) async { + Future requestCameraPermissions(bool arg_enableAudio) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions', codec, binaryMessenger: _binaryMessenger); final List? replyList = await channel.send([arg_enableAudio]) as List?; @@ -719,15 +760,12 @@ class SystemServicesHostApi { } } - Future startListeningForDeviceOrientationChange( - bool arg_isFrontFacing, int arg_sensorOrientation) async { + Future startListeningForDeviceOrientationChange(bool arg_isFrontFacing, int arg_sensorOrientation) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange', codec, binaryMessenger: _binaryMessenger); final List? replyList = - await channel.send([arg_isFrontFacing, arg_sensorOrientation]) - as List?; + await channel.send([arg_isFrontFacing, arg_sensorOrientation]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -746,10 +784,10 @@ class SystemServicesHostApi { Future stopListeningForDeviceOrientationChange() async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; + final List? replyList = + await channel.send(null) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -774,19 +812,17 @@ abstract class SystemServicesFlutterApi { void onCameraError(String errorDescription); - static void setup(SystemServicesFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(SystemServicesFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged', - codec, + 'dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMessageHandler(null); } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged was null.'); + 'Argument for dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged was null.'); final List args = (message as List?)!; final String? arg_orientation = (args[0] as String?); assert(arg_orientation != null, @@ -805,7 +841,7 @@ abstract class SystemServicesFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError was null.'); + 'Argument for dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError was null.'); final List args = (message as List?)!; final String? arg_errorDescription = (args[0] as String?); assert(arg_errorDescription != null, @@ -836,9 +872,9 @@ class _PreviewHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); - case 129: + case 129: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -856,14 +892,12 @@ class PreviewHostApi { static const MessageCodec codec = _PreviewHostApiCodec(); - Future create(int arg_identifier, int? arg_rotation, - ResolutionInfo? arg_targetResolution) async { + Future create(int arg_identifier, int? arg_rotation, ResolutionInfo? arg_targetResolution) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PreviewHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_rotation, arg_targetResolution]) - as List?; + final List? replyList = + await channel.send([arg_identifier, arg_rotation, arg_targetResolution]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -911,7 +945,8 @@ class PreviewHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; + final List? replyList = + await channel.send(null) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -971,7 +1006,7 @@ class _ImageCaptureHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -989,14 +1024,12 @@ class ImageCaptureHostApi { static const MessageCodec codec = _ImageCaptureHostApiCodec(); - Future create(int arg_identifier, int? arg_flashMode, - ResolutionInfo? arg_targetResolution) async { + Future create(int arg_identifier, int? arg_flashMode, ResolutionInfo? arg_targetResolution) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageCaptureHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send( - [arg_identifier, arg_flashMode, arg_targetResolution]) - as List?; + final List? replyList = + await channel.send([arg_identifier, arg_flashMode, arg_targetResolution]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1017,8 +1050,8 @@ class ImageCaptureHostApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_flashMode]) as List?; + final List? replyList = + await channel.send([arg_identifier, arg_flashMode]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1078,7 +1111,98 @@ class _ExposureStateFlutterApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: + return ExposureCompensationRange.decode(readValue(buffer)!); + default: + return super.readValueOfType(type, buffer); + } + } +} + +abstract class ExposureStateFlutterApi { + static const MessageCodec codec = _ExposureStateFlutterApiCodec(); + + void create(int identifier, ExposureCompensationRange exposureCompensationRange, double exposureCompensationStep); + + static void setup(ExposureStateFlutterApi? api, {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ExposureStateFlutterApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null int.'); + final ExposureCompensationRange? arg_exposureCompensationRange = (args[1] as ExposureCompensationRange?); + assert(arg_exposureCompensationRange != null, + 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null ExposureCompensationRange.'); + final double? arg_exposureCompensationStep = (args[2] as double?); + assert(arg_exposureCompensationStep != null, + 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null double.'); + api.create(arg_identifier!, arg_exposureCompensationRange!, arg_exposureCompensationStep!); + return; + }); + } + } + } +} + +abstract class ZoomStateFlutterApi { + static const MessageCodec codec = StandardMessageCodec(); + + void create(int identifier, double minZoomRatio, double maxZoomRatio); + + static void setup(ZoomStateFlutterApi? api, {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ZoomStateFlutterApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null int.'); + final double? arg_minZoomRatio = (args[1] as double?); + assert(arg_minZoomRatio != null, + 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null double.'); + final double? arg_maxZoomRatio = (args[2] as double?); + assert(arg_maxZoomRatio != null, + 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null double.'); + api.create(arg_identifier!, arg_minZoomRatio!, arg_maxZoomRatio!); + return; + }); + } + } + } +} + +class _ExposureStateFlutterApiCodec extends StandardMessageCodec { + const _ExposureStateFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is ExposureCompensationRange) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: return ExposureCompensationRange.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -1089,13 +1213,9 @@ class _ExposureStateFlutterApiCodec extends StandardMessageCodec { abstract class ExposureStateFlutterApi { static const MessageCodec codec = _ExposureStateFlutterApiCodec(); - void create( - int identifier, - ExposureCompensationRange exposureCompensationRange, - double exposureCompensationStep); + void create(int identifier, ExposureCompensationRange exposureCompensationRange, double exposureCompensationStep); - static void setup(ExposureStateFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(ExposureStateFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ExposureStateFlutterApi.create', codec, @@ -1105,20 +1225,18 @@ abstract class ExposureStateFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null int.'); - final ExposureCompensationRange? arg_exposureCompensationRange = - (args[1] as ExposureCompensationRange?); + final ExposureCompensationRange? arg_exposureCompensationRange = (args[1] as ExposureCompensationRange?); assert(arg_exposureCompensationRange != null, 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null ExposureCompensationRange.'); final double? arg_exposureCompensationStep = (args[2] as double?); assert(arg_exposureCompensationStep != null, 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null double.'); - api.create(arg_identifier!, arg_exposureCompensationRange!, - arg_exposureCompensationStep!); + api.create(arg_identifier!, arg_exposureCompensationRange!, arg_exposureCompensationStep!); return; }); } @@ -1131,8 +1249,7 @@ abstract class ZoomStateFlutterApi { void create(int identifier, double minZoomRatio, double maxZoomRatio); - static void setup(ZoomStateFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(ZoomStateFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ZoomStateFlutterApi.create', codec, @@ -1142,7 +1259,7 @@ abstract class ZoomStateFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -1176,7 +1293,7 @@ class _ImageAnalysisHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -1194,14 +1311,12 @@ class ImageAnalysisHostApi { static const MessageCodec codec = _ImageAnalysisHostApiCodec(); - Future create(int arg_identifier, - ResolutionInfo? arg_targetResolutionIdentifier) async { + Future create(int arg_identifier, ResolutionInfo? arg_targetResolutionIdentifier) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageAnalysisHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_targetResolutionIdentifier]) - as List?; + final List? replyList = + await channel.send([arg_identifier, arg_targetResolutionIdentifier]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1218,14 +1333,12 @@ class ImageAnalysisHostApi { } } - Future setAnalyzer( - int arg_identifier, int arg_analyzerIdentifier) async { + Future setAnalyzer(int arg_identifier, int arg_analyzerIdentifier) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageAnalysisHostApi.setAnalyzer', codec, binaryMessenger: _binaryMessenger); final List? replyList = - await channel.send([arg_identifier, arg_analyzerIdentifier]) - as List?; + await channel.send([arg_identifier, arg_analyzerIdentifier]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1305,8 +1418,7 @@ abstract class AnalyzerFlutterApi { void analyze(int identifier, int imageProxyIdentifier); - static void setup(AnalyzerFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(AnalyzerFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AnalyzerFlutterApi.create', codec, @@ -1316,7 +1428,7 @@ abstract class AnalyzerFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.AnalyzerFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.AnalyzerFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -1335,7 +1447,7 @@ abstract class AnalyzerFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.AnalyzerFlutterApi.analyze was null.'); + 'Argument for dev.flutter.pigeon.AnalyzerFlutterApi.analyze was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -1416,8 +1528,7 @@ abstract class ImageProxyFlutterApi { void create(int identifier, int format, int height, int width); - static void setup(ImageProxyFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(ImageProxyFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageProxyFlutterApi.create', codec, @@ -1427,7 +1538,7 @@ abstract class ImageProxyFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageProxyFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.ImageProxyFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -1454,8 +1565,7 @@ abstract class PlaneProxyFlutterApi { void create(int identifier, Uint8List buffer, int pixelStride, int rowStride); - static void setup(PlaneProxyFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(PlaneProxyFlutterApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PlaneProxyFlutterApi.create', codec, @@ -1465,7 +1575,7 @@ abstract class PlaneProxyFlutterApi { } else { channel.setMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.PlaneProxyFlutterApi.create was null.'); + 'Argument for dev.flutter.pigeon.PlaneProxyFlutterApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -1479,8 +1589,7 @@ abstract class PlaneProxyFlutterApi { final int? arg_rowStride = (args[3] as int?); assert(arg_rowStride != null, 'Argument for dev.flutter.pigeon.PlaneProxyFlutterApi.create was null, expected non-null int.'); - api.create( - arg_identifier!, arg_buffer!, arg_pixelStride!, arg_rowStride!); + api.create(arg_identifier!, arg_buffer!, arg_pixelStride!, arg_rowStride!); return; }); } diff --git a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart index c8b3885d064b..8e4b0ca7431f 100644 --- a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart +++ b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart @@ -56,6 +56,16 @@ class ExposureCompensationRange { int maxCompensation; } +class ExposureCompensationRange { + ExposureCompensationRange({ + required this.minCompensation, + required this.maxCompensation, + }); + + int minCompensation; + int maxCompensation; +} + @HostApi(dartHostTestHandler: 'TestInstanceManagerHostApi') abstract class InstanceManagerHostApi { /// Clear the native `InstanceManager`. @@ -78,6 +88,8 @@ abstract class JavaObjectFlutterApi { abstract class CameraInfoHostApi { int getSensorRotationDegrees(int identifier); + int getLiveCameraState(int identifier); + int getExposureState(int identifier); int getZoomState(int identifier); @@ -184,6 +196,19 @@ abstract class ZoomStateFlutterApi { void create(int identifier, double minZoomRatio, double maxZoomRatio); } +@FlutterApi() +abstract class ExposureStateFlutterApi { + void create( + int identifier, + ExposureCompensationRange exposureCompensationRange, + double exposureCompensationStep); +} + +@FlutterApi() +abstract class ZoomStateFlutterApi { + void create(int identifier, double minZoomRatio, double maxZoomRatio); +} + @HostApi(dartHostTestHandler: 'TestImageAnalysisHostApi') abstract class ImageAnalysisHostApi { void create(int identifier, ResolutionInfo? targetResolutionIdentifier); diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index e7a6707d6e3f..079abe0f2fd4 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -132,12 +132,19 @@ void main() { camera.processCameraProvider = mockProcessCameraProvider; + camera.processCameraProvider = mockProcessCameraProvider; + when(camera.testPreview.setSurfaceProvider()) .thenAnswer((_) async => testSurfaceTextureId); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(MockCameraInfo())); + when(mockProcessCameraProvider.bindToLifecycle( + camera.mockBackCameraSelector, + [camera.testPreview, camera.testImageCapture])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); + when(mockCameraInfo.getLiveCameraState()) + .thenAnswer((_) async => mockLiveCameraState); + camera.processCameraProvider = mockProcessCameraProvider; + camera.createDetachedObjectForTesting = true; expect( await camera.createCamera(testCameraDescription, testResolutionPreset, @@ -165,7 +172,7 @@ void main() { 'createCamera binds Preview and ImageCapture use cases to ProcessCameraProvider instance', () async { final MockAndroidCameraCameraX camera = MockAndroidCameraCameraX(); - final MockProcessCameraProvider mockProcessCameraProvider = + final ProcessCameraProvider mockProcessCameraProvider = MockProcessCameraProvider(); final MockCamera mockCamera = MockCamera(); final MockCameraInfo mockCameraInfo = MockCameraInfo(); @@ -178,6 +185,16 @@ void main() { const ResolutionPreset testResolutionPreset = ResolutionPreset.veryHigh; const bool enableAudio = true; + when(mockProcessCameraProvider.bindToLifecycle( + camera.mockBackCameraSelector, + [camera.testPreview, camera.testImageCapture])) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); + when(mockCameraInfo.getLiveCameraState()) + .thenAnswer((_) async => MockLiveData()); + camera.processCameraProvider = mockProcessCameraProvider; + camera.createDetachedObjectForTesting = true; + camera.processCameraProvider = mockProcessCameraProvider; when(mockProcessCameraProvider.bindToLifecycle( @@ -254,6 +271,16 @@ void main() { await camera.createCamera(testCameraDescription, testResolutionPreset, enableAudio: enableAudio); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) + .thenAnswer((_) async => mockCamera); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(MockCameraInfo())); + when(camera.testPreview.getResolutionInfo()) + .thenAnswer((_) async => testResolutionInfo); + + await camera.createCamera(testCameraDescription, testResolutionPreset, + enableAudio: enableAudio); + // Start listening to camera events stream to verify the proper CameraInitializedEvent is sent. camera.cameraEventStreamController.stream.listen((CameraEvent event) { expect(event, const TypeMatcher()); @@ -381,6 +408,7 @@ void main() { verifyNever(camera.processCameraProvider! .bindToLifecycle(camera.cameraSelector!, [camera.preview!])); + verifyNever(mockLiveCameraState.observe(any)); expect(camera.cameraInfo, isNot(mockCameraInfo)); }); @@ -396,6 +424,11 @@ void main() { camera.cameraSelector = MockCameraSelector(); camera.preview = MockPreview(); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) + .thenAnswer((_) => Future.value(mockCamera)); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); when(mockCamera.getCameraInfo()) @@ -405,6 +438,13 @@ void main() { verify(camera.processCameraProvider! .bindToLifecycle(camera.cameraSelector!, [camera.preview!])); + expect( + await testCameraClosingObserver( + camera, + 78, + verify(mockLiveCameraState.observe(captureAny)).captured.single + as Observer), + isTrue); expect(camera.cameraInfo, equals(mockCameraInfo)); }); @@ -421,6 +461,11 @@ void main() { camera.cameraSelector = MockCameraSelector(); camera.preview = MockPreview(); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) + .thenAnswer((_) => Future.value(mockCamera)); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(MockCameraInfo())); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); when(mockCamera.getCameraInfo()) @@ -457,6 +502,11 @@ void main() { camera.cameraSelector = MockCameraSelector(); camera.preview = MockPreview(); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) + .thenAnswer((_) => Future.value(mockCamera)); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(mockCameraInfo)); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); when(mockCamera.getCameraInfo()) @@ -581,6 +631,11 @@ void main() { camera.cameraSelector = MockCameraSelector(); camera.createDetachedCallbacks = true; + when(mockProcessCameraProvider.bindToLifecycle(any, any)) + .thenAnswer((_) => Future.value(mockCamera)); + when(mockCamera.getCameraInfo()) + .thenAnswer((_) => Future.value(MockCameraInfo())); + when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); when(mockCamera.getCameraInfo()) diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart index b7365a2e90d4..0c88413c1ad6 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.mocks.dart @@ -203,6 +203,15 @@ class MockCameraInfo extends _i1.Mock implements _i2.CameraInfo { returnValueForMissingStub: _i11.Future.value(0), ) as _i11.Future); @override + _i11.Future getLiveCameraState() => (super.noSuchMethod( + Invocation.method( + #getLiveCameraState, + [], + ), + returnValue: _i11.Future.value(), + returnValueForMissingStub: _i11.Future.value(), + ) as _i11.Future); + @override _i11.Future<_i3.ExposureState> getExposureState() => (super.noSuchMethod( Invocation.method( #getExposureState, diff --git a/packages/camera/camera_android_camerax/test/camera_info_test.dart b/packages/camera/camera_android_camerax/test/camera_info_test.dart index 9826b88e367e..7edf6c409fe0 100644 --- a/packages/camera/camera_android_camerax/test/camera_info_test.dart +++ b/packages/camera/camera_android_camerax/test/camera_info_test.dart @@ -6,6 +6,7 @@ import 'package:camera_android_camerax/src/camera_info.dart'; import 'package:camera_android_camerax/src/camerax_library.g.dart'; import 'package:camera_android_camerax/src/exposure_state.dart'; import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:camera_android_camerax/src/live_data.dart'; import 'package:camera_android_camerax/src/zoom_state.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; diff --git a/packages/camera/camera_android_camerax/test/camera_info_test.mocks.dart b/packages/camera/camera_android_camerax/test/camera_info_test.mocks.dart index 968dc6e8b621..4c1bdf696938 100644 --- a/packages/camera/camera_android_camerax/test/camera_info_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/camera_info_test.mocks.dart @@ -36,6 +36,14 @@ class MockTestCameraInfoHostApi extends _i1.Mock returnValue: 0, ) as int); @override + int getLiveCameraState(int? identifier) => (super.noSuchMethod( + Invocation.method( + #getLiveCameraState, + [identifier], + ), + returnValue: 0, + ) as int); + @override int getExposureState(int? identifier) => (super.noSuchMethod( Invocation.method( #getExposureState, diff --git a/packages/camera/camera_android_camerax/test/camera_test.dart b/packages/camera/camera_android_camerax/test/camera_test.dart index 742a60799e6f..05f5fe7dd029 100644 --- a/packages/camera/camera_android_camerax/test/camera_test.dart +++ b/packages/camera/camera_android_camerax/test/camera_test.dart @@ -20,6 +20,8 @@ void main() { TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); group('Camera', () { + tearDown(() => TestCameraHostApi.setup(null)); + test('getCameraInfo makes call to retrieve expected CameraInfo', () async { final MockTestCameraHostApi mockApi = MockTestCameraHostApi(); TestCameraHostApi.setup(mockApi); @@ -52,7 +54,7 @@ void main() { verify(mockApi.getCameraInfo(cameraIdentifier)); }); - test('flutterApiCreateTest', () { + test('flutterApiCreate makes call to add instance to instance manager', () { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); diff --git a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart index 40bd8f2e4335..098b297bcf0a 100644 --- a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart @@ -14,8 +14,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:camera_android_camerax/src/camerax_library.g.dart'; abstract class TestInstanceManagerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); /// Clear the native `InstanceManager`. @@ -23,19 +22,15 @@ abstract class TestInstanceManagerHostApi { /// This is typically only used after a hot restart. void clear(); - static void setup(TestInstanceManagerHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestInstanceManagerHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.InstanceManagerHostApi.clear', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { // ignore message api.clear(); return []; @@ -46,27 +41,22 @@ abstract class TestInstanceManagerHostApi { } abstract class TestJavaObjectHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); void dispose(int identifier); - static void setup(TestJavaObjectHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestJavaObjectHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaObjectHostApi.dispose', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); + 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -80,32 +70,28 @@ abstract class TestJavaObjectHostApi { } abstract class TestCameraInfoHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); int getSensorRotationDegrees(int identifier); + int getLiveCameraState(int identifier); + int getExposureState(int identifier); int getZoomState(int identifier); - static void setup(TestCameraInfoHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestCameraInfoHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees', - codec, + 'dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees was null.'); + 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -115,19 +101,35 @@ abstract class TestCameraInfoHostApi { }); } } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CameraInfoHostApi.getLiveCameraState', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getLiveCameraState was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getLiveCameraState was null, expected non-null int.'); + final int output = api.getLiveCameraState(arg_identifier!); + return [output]; + }); + } + } { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraInfoHostApi.getExposureState', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getExposureState was null.'); + 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getExposureState was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -142,14 +144,11 @@ abstract class TestCameraInfoHostApi { 'dev.flutter.pigeon.CameraInfoHostApi.getZoomState', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getZoomState was null.'); + 'Argument for dev.flutter.pigeon.CameraInfoHostApi.getZoomState was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -163,29 +162,24 @@ abstract class TestCameraInfoHostApi { } abstract class TestCameraSelectorHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); void create(int identifier, int? lensFacing); List filter(int identifier, List cameraInfoIds); - static void setup(TestCameraSelectorHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestCameraSelectorHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraSelectorHostApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -201,24 +195,19 @@ abstract class TestCameraSelectorHostApi { 'dev.flutter.pigeon.CameraSelectorHostApi.filter', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.filter was null.'); + 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.filter was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.filter was null, expected non-null int.'); - final List? arg_cameraInfoIds = - (args[1] as List?)?.cast(); + final List? arg_cameraInfoIds = (args[1] as List?)?.cast(); assert(arg_cameraInfoIds != null, 'Argument for dev.flutter.pigeon.CameraSelectorHostApi.filter was null, expected non-null List.'); - final List output = - api.filter(arg_identifier!, arg_cameraInfoIds!); + final List output = api.filter(arg_identifier!, arg_cameraInfoIds!); return [output]; }); } @@ -227,16 +216,14 @@ abstract class TestCameraSelectorHostApi { } abstract class TestProcessCameraProviderHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); Future getInstance(); List getAvailableCameraInfos(int identifier); - int bindToLifecycle( - int identifier, int cameraSelectorIdentifier, List useCaseIds); + int bindToLifecycle(int identifier, int cameraSelectorIdentifier, List useCaseIds); bool isBound(int identifier, int useCaseIdentifier); @@ -244,19 +231,15 @@ abstract class TestProcessCameraProviderHostApi { void unbindAll(int identifier); - static void setup(TestProcessCameraProviderHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestProcessCameraProviderHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { // ignore message final int output = await api.getInstance(); return [output]; @@ -265,42 +248,33 @@ abstract class TestProcessCameraProviderHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos', - codec, + 'dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos was null, expected non-null int.'); - final List output = - api.getAvailableCameraInfos(arg_identifier!); + final List output = api.getAvailableCameraInfos(arg_identifier!); return [output]; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle', - codec, + 'dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -308,12 +282,10 @@ abstract class TestProcessCameraProviderHostApi { final int? arg_cameraSelectorIdentifier = (args[1] as int?); assert(arg_cameraSelectorIdentifier != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle was null, expected non-null int.'); - final List? arg_useCaseIds = - (args[2] as List?)?.cast(); + final List? arg_useCaseIds = (args[2] as List?)?.cast(); assert(arg_useCaseIds != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle was null, expected non-null List.'); - final int output = api.bindToLifecycle( - arg_identifier!, arg_cameraSelectorIdentifier!, arg_useCaseIds!); + final int output = api.bindToLifecycle(arg_identifier!, arg_cameraSelectorIdentifier!, arg_useCaseIds!); return [output]; }); } @@ -323,14 +295,11 @@ abstract class TestProcessCameraProviderHostApi { 'dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -338,8 +307,7 @@ abstract class TestProcessCameraProviderHostApi { final int? arg_useCaseIdentifier = (args[1] as int?); assert(arg_useCaseIdentifier != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound was null, expected non-null int.'); - final bool output = - api.isBound(arg_identifier!, arg_useCaseIdentifier!); + final bool output = api.isBound(arg_identifier!, arg_useCaseIdentifier!); return [output]; }); } @@ -349,20 +317,16 @@ abstract class TestProcessCameraProviderHostApi { 'dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind was null, expected non-null int.'); - final List? arg_useCaseIds = - (args[1] as List?)?.cast(); + final List? arg_useCaseIds = (args[1] as List?)?.cast(); assert(arg_useCaseIds != null, 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind was null, expected non-null List.'); api.unbind(arg_identifier!, arg_useCaseIds!); @@ -375,14 +339,11 @@ abstract class TestProcessCameraProviderHostApi { 'dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll was null.'); + 'Argument for dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -396,27 +357,22 @@ abstract class TestProcessCameraProviderHostApi { } abstract class TestCameraHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); int getCameraInfo(int identifier); - static void setup(TestCameraHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestCameraHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CameraHostApi.getCameraInfo', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.CameraHostApi.getCameraInfo was null.'); + 'Argument for dev.flutter.pigeon.CameraHostApi.getCameraInfo was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -444,7 +400,7 @@ class _TestSystemServicesHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return CameraPermissionsErrorData.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -453,58 +409,45 @@ class _TestSystemServicesHostApiCodec extends StandardMessageCodec { } abstract class TestSystemServicesHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestSystemServicesHostApiCodec(); - Future requestCameraPermissions( - bool enableAudio); + Future requestCameraPermissions(bool enableAudio); - void startListeningForDeviceOrientationChange( - bool isFrontFacing, int sensorOrientation); + void startListeningForDeviceOrientationChange(bool isFrontFacing, int sensorOrientation); void stopListeningForDeviceOrientationChange(); - static void setup(TestSystemServicesHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestSystemServicesHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions was null.'); + 'Argument for dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions was null.'); final List args = (message as List?)!; final bool? arg_enableAudio = (args[0] as bool?); assert(arg_enableAudio != null, 'Argument for dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions was null, expected non-null bool.'); - final CameraPermissionsErrorData? output = - await api.requestCameraPermissions(arg_enableAudio!); + final CameraPermissionsErrorData? output = await api.requestCameraPermissions(arg_enableAudio!); return [output]; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange was null.'); + 'Argument for dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange was null.'); final List args = (message as List?)!; final bool? arg_isFrontFacing = (args[0] as bool?); assert(arg_isFrontFacing != null, @@ -512,24 +455,19 @@ abstract class TestSystemServicesHostApi { final int? arg_sensorOrientation = (args[1] as int?); assert(arg_sensorOrientation != null, 'Argument for dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange was null, expected non-null int.'); - api.startListeningForDeviceOrientationChange( - arg_isFrontFacing!, arg_sensorOrientation!); + api.startListeningForDeviceOrientationChange(arg_isFrontFacing!, arg_sensorOrientation!); return []; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange', - codec, + 'dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { // ignore message api.stopListeningForDeviceOrientationChange(); return []; @@ -557,9 +495,9 @@ class _TestPreviewHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); - case 129: + case 129: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -568,8 +506,7 @@ class _TestPreviewHostApiCodec extends StandardMessageCodec { } abstract class TestPreviewHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestPreviewHostApiCodec(); void create(int identifier, int? rotation, ResolutionInfo? targetResolution); @@ -580,28 +517,23 @@ abstract class TestPreviewHostApi { ResolutionInfo getResolutionInfo(int identifier); - static void setup(TestPreviewHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestPreviewHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PreviewHostApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.PreviewHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.PreviewHostApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.PreviewHostApi.create was null, expected non-null int.'); final int? arg_rotation = (args[1] as int?); - final ResolutionInfo? arg_targetResolution = - (args[2] as ResolutionInfo?); + final ResolutionInfo? arg_targetResolution = (args[2] as ResolutionInfo?); api.create(arg_identifier!, arg_rotation, arg_targetResolution); return []; }); @@ -612,14 +544,11 @@ abstract class TestPreviewHostApi { 'dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider was null.'); + 'Argument for dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -631,16 +560,12 @@ abstract class TestPreviewHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture', - codec, + 'dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { // ignore message api.releaseFlutterSurfaceTexture(); return []; @@ -652,14 +577,11 @@ abstract class TestPreviewHostApi { 'dev.flutter.pigeon.PreviewHostApi.getResolutionInfo', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.PreviewHostApi.getResolutionInfo was null.'); + 'Argument for dev.flutter.pigeon.PreviewHostApi.getResolutionInfo was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -687,7 +609,7 @@ class _TestImageCaptureHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -696,8 +618,7 @@ class _TestImageCaptureHostApiCodec extends StandardMessageCodec { } abstract class TestImageCaptureHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestImageCaptureHostApiCodec(); void create(int identifier, int? flashMode, ResolutionInfo? targetResolution); @@ -706,28 +627,23 @@ abstract class TestImageCaptureHostApi { Future takePicture(int identifier); - static void setup(TestImageCaptureHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestImageCaptureHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageCaptureHostApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.create was null, expected non-null int.'); final int? arg_flashMode = (args[1] as int?); - final ResolutionInfo? arg_targetResolution = - (args[2] as ResolutionInfo?); + final ResolutionInfo? arg_targetResolution = (args[2] as ResolutionInfo?); api.create(arg_identifier!, arg_flashMode, arg_targetResolution); return []; }); @@ -738,14 +654,11 @@ abstract class TestImageCaptureHostApi { 'dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode was null.'); + 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -763,14 +676,11 @@ abstract class TestImageCaptureHostApi { 'dev.flutter.pigeon.ImageCaptureHostApi.takePicture', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.takePicture was null.'); + 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.takePicture was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -798,7 +708,7 @@ class _TestImageAnalysisHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -807,8 +717,7 @@ class _TestImageAnalysisHostApiCodec extends StandardMessageCodec { } abstract class TestImageAnalysisHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestImageAnalysisHostApiCodec(); void create(int identifier, ResolutionInfo? targetResolutionIdentifier); @@ -817,27 +726,22 @@ abstract class TestImageAnalysisHostApi { void clearAnalyzer(int identifier); - static void setup(TestImageAnalysisHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestImageAnalysisHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageAnalysisHostApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.create was null, expected non-null int.'); - final ResolutionInfo? arg_targetResolutionIdentifier = - (args[1] as ResolutionInfo?); + final ResolutionInfo? arg_targetResolutionIdentifier = (args[1] as ResolutionInfo?); api.create(arg_identifier!, arg_targetResolutionIdentifier); return []; }); @@ -848,14 +752,11 @@ abstract class TestImageAnalysisHostApi { 'dev.flutter.pigeon.ImageAnalysisHostApi.setAnalyzer', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.setAnalyzer was null.'); + 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.setAnalyzer was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -873,14 +774,11 @@ abstract class TestImageAnalysisHostApi { 'dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer was null.'); + 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -894,27 +792,22 @@ abstract class TestImageAnalysisHostApi { } abstract class TestAnalyzerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); void create(int identifier); - static void setup(TestAnalyzerHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestAnalyzerHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AnalyzerHostApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.AnalyzerHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.AnalyzerHostApi.create was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -928,29 +821,24 @@ abstract class TestAnalyzerHostApi { } abstract class TestImageProxyHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = StandardMessageCodec(); List getPlanes(int identifier); void close(int identifier); - static void setup(TestImageProxyHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestImageProxyHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageProxyHostApi.getPlanes', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageProxyHostApi.getPlanes was null.'); + 'Argument for dev.flutter.pigeon.ImageProxyHostApi.getPlanes was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -965,14 +853,11 @@ abstract class TestImageProxyHostApi { 'dev.flutter.pigeon.ImageProxyHostApi.close', codec, binaryMessenger: binaryMessenger); if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, null); } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler(channel, (Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.ImageProxyHostApi.close was null.'); + 'Argument for dev.flutter.pigeon.ImageProxyHostApi.close was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, From fed96215bdf28cd0d04913c07060091a9fb74e84 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 10 May 2023 09:39:45 -0700 Subject: [PATCH 02/10] Undo changes --- .../camerax/CameraInfoHostApiImpl.java | 36 - .../camerax/GeneratedCameraXLibrary.java | 618 +++++++++--------- .../lib/src/android_camera_camerax.dart | 49 -- ...roid_camera_camerax_flutter_api_impls.dart | 6 - .../lib/src/camera_info.dart | 17 - .../lib/src/camerax_library.g.dart | 124 ---- .../pigeons/camerax_library.dart | 23 - .../test/android_camera_camerax_test.dart | 42 -- 8 files changed, 291 insertions(+), 624 deletions(-) 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 index f9eca979d909..e72d08da34d1 100644 --- 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 @@ -92,40 +92,4 @@ public Long getZoomState(@NonNull Long identifier) { return instanceManager.getIdentifierForStrongReference(zoomState); } - - /** - * 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 current {@link ZoomState} value of the {@link CameraInfo} with the specified - * identifier. - */ - @NonNull - @Override - public Long getZoomState(@NonNull Long identifier) { - CameraInfo cameraInfo = - (CameraInfo) Objects.requireNonNull(instanceManager.getInstance(identifier)); - // TODO(camsim99): Create/return LiveData once https://github.com/flutter/packages/pull/3419 lands. - ZoomState zoomState = cameraInfo.getZoomState().getValue(); - - ZoomStateFlutterApiImpl zoomStateFlutterApiImpl = - new ZoomStateFlutterApiImpl(binaryMessenger, instanceManager); - zoomStateFlutterApiImpl.create(zoomState, result -> {}); - - return instanceManager.getIdentifierForStrongReference(zoomState); - } } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java index 8b505930f37c..c6f627993772 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java @@ -18,9 +18,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) @@ -35,8 +33,7 @@ public static class FlutterError extends RuntimeException { /** The error details. Must be a datatype supported by the api codec. */ public final Object details; - public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) - { + public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { super(message); this.code = code; this.details = details; @@ -55,7 +52,7 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { errorList.add(exception.toString()); errorList.add(exception.getClass().getSimpleName()); errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); } return errorList; } @@ -156,9 +153,13 @@ ArrayList toList() { static @NonNull ResolutionInfo fromList(@NonNull ArrayList list) { ResolutionInfo pigeonResult = new ResolutionInfo(); Object width = list.get(0); - pigeonResult.setWidth((width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width)); + pigeonResult.setWidth( + (width == null) ? null : ((width instanceof Integer) ? (Integer) width : (Long) width)); Object height = list.get(1); - pigeonResult.setHeight((height == null) ? null : ((height instanceof Integer) ? (Integer) height : (Long) height)); + pigeonResult.setHeight( + (height == null) + ? null + : ((height instanceof Integer) ? (Integer) height : (Long) height)); return pigeonResult; } } @@ -400,82 +401,19 @@ ArrayList toList() { static @NonNull ExposureCompensationRange fromList(@NonNull ArrayList list) { ExposureCompensationRange pigeonResult = new ExposureCompensationRange(); Object minCompensation = list.get(0); - pigeonResult.setMinCompensation((minCompensation == null) ? null : ((minCompensation instanceof Integer) ? (Integer) minCompensation : (Long) minCompensation)); + pigeonResult.setMinCompensation( + (minCompensation == null) + ? null + : ((minCompensation instanceof Integer) + ? (Integer) minCompensation + : (Long) minCompensation)); Object maxCompensation = list.get(1); - pigeonResult.setMaxCompensation((maxCompensation == null) ? null : ((maxCompensation instanceof Integer) ? (Integer) maxCompensation : (Long) maxCompensation)); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class ExposureCompensationRange { - private @NonNull Long minCompensation; - - public @NonNull Long getMinCompensation() { - return minCompensation; - } - - public void setMinCompensation(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"minCompensation\" is null."); - } - this.minCompensation = setterArg; - } - - private @NonNull Long maxCompensation; - - public @NonNull Long getMaxCompensation() { - return maxCompensation; - } - - public void setMaxCompensation(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"maxCompensation\" is null."); - } - this.maxCompensation = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - ExposureCompensationRange() {} - - public static final class Builder { - - private @Nullable Long minCompensation; - - public @NonNull Builder setMinCompensation(@NonNull Long setterArg) { - this.minCompensation = setterArg; - return this; - } - - private @Nullable Long maxCompensation; - - public @NonNull Builder setMaxCompensation(@NonNull Long setterArg) { - this.maxCompensation = setterArg; - return this; - } - - public @NonNull ExposureCompensationRange build() { - ExposureCompensationRange pigeonReturn = new ExposureCompensationRange(); - pigeonReturn.setMinCompensation(minCompensation); - pigeonReturn.setMaxCompensation(maxCompensation); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(2); - toListResult.add(minCompensation); - toListResult.add(maxCompensation); - return toListResult; - } - - static @NonNull ExposureCompensationRange fromList(@NonNull ArrayList list) { - ExposureCompensationRange pigeonResult = new ExposureCompensationRange(); - Object minCompensation = list.get(0); - pigeonResult.setMinCompensation((minCompensation == null) ? null : ((minCompensation instanceof Integer) ? (Integer) minCompensation : (Long) minCompensation)); - Object maxCompensation = list.get(1); - pigeonResult.setMaxCompensation((maxCompensation == null) ? null : ((maxCompensation instanceof Integer) ? (Integer) maxCompensation : (Long) maxCompensation)); + pigeonResult.setMaxCompensation( + (maxCompensation == null) + ? null + : ((maxCompensation instanceof Integer) + ? (Integer) maxCompensation + : (Long) maxCompensation)); return pigeonResult; } } @@ -491,7 +429,7 @@ public interface InstanceManagerHostApi { /** * Clear the native `InstanceManager`. * - * This is typically only used after a hot restart. + *

This is typically only used after a hot restart. */ void clear(); @@ -499,8 +437,12 @@ public interface InstanceManagerHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `InstanceManagerHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable InstanceManagerHostApi api) { + /** + * Sets up an instance of `InstanceManagerHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable InstanceManagerHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -512,8 +454,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable InstanceMa try { api.clear(); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -534,7 +475,9 @@ public interface JavaObjectHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable JavaObjectHostApi api) { { BasicMessageChannel channel = @@ -549,8 +492,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable JavaObject try { api.dispose((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -570,7 +512,7 @@ public JavaObjectFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -579,6 +521,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void dispose(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -591,7 +534,7 @@ public void dispose(@NonNull Long identifierArg, @NonNull Reply callback) /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface CameraInfoHostApi { - @NonNull + @NonNull Long getSensorRotationDegrees(@NonNull Long identifier); @NonNull @@ -600,19 +543,23 @@ public interface CameraInfoHostApi { @NonNull Long getExposureState(@NonNull Long identifier); - @NonNull + @NonNull Long getZoomState(@NonNull Long identifier); /** The codec used by CameraInfoHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `CameraInfoHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `CameraInfoHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfoHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.CameraInfoHostApi.getSensorRotationDegrees", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -620,10 +567,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = api.getSensorRotationDegrees((identifierArg == null) ? null : identifierArg.longValue()); + Long output = + api.getSensorRotationDegrees( + (identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -671,34 +619,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = api.getLiveCameraState((identifierArg == null) ? null : identifierArg.longValue()); - wrapped.add(0, output); - } - catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.CameraInfoHostApi.getExposureState", getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - try { - Long output = api.getExposureState((identifierArg == null) ? null : identifierArg.longValue()); + Long output = + api.getExposureState( + (identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -719,10 +644,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraInfo ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = api.getZoomState((identifierArg == null) ? null : identifierArg.longValue()); + Long output = + api.getZoomState((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -742,7 +667,7 @@ public CameraInfoFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -751,6 +676,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -765,15 +691,19 @@ public interface CameraSelectorHostApi { void create(@NonNull Long identifier, @Nullable Long lensFacing); - @NonNull + @NonNull List filter(@NonNull Long identifier, @NonNull List cameraInfoIds); /** The codec used by CameraSelectorHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `CameraSelectorHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraSelectorHostApi api) { + /** + * Sets up an instance of `CameraSelectorHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable CameraSelectorHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -786,10 +716,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraSele Number identifierArg = (Number) args.get(0); Number lensFacingArg = (Number) args.get(1); try { - api.create((identifierArg == null) ? null : identifierArg.longValue(), (lensFacingArg == null) ? null : lensFacingArg.longValue()); + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + (lensFacingArg == null) ? null : lensFacingArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -811,10 +742,12 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraSele Number identifierArg = (Number) args.get(0); List cameraInfoIdsArg = (List) args.get(1); try { - List output = api.filter((identifierArg == null) ? null : identifierArg.longValue(), cameraInfoIdsArg); + List output = + api.filter( + (identifierArg == null) ? null : identifierArg.longValue(), + cameraInfoIdsArg); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -834,7 +767,7 @@ public CameraSelectorFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -843,7 +776,9 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @Nullable Long lensFacingArg, @NonNull Reply callback) { + + public void create( + @NonNull Long identifierArg, @Nullable Long lensFacingArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.CameraSelectorFlutterApi.create", getCodec()); @@ -857,13 +792,16 @@ public interface ProcessCameraProviderHostApi { void getInstance(@NonNull Result result); - @NonNull + @NonNull List getAvailableCameraInfos(@NonNull Long identifier); - @NonNull - Long bindToLifecycle(@NonNull Long identifier, @NonNull Long cameraSelectorIdentifier, @NonNull List useCaseIds); + @NonNull + Long bindToLifecycle( + @NonNull Long identifier, + @NonNull Long cameraSelectorIdentifier, + @NonNull List useCaseIds); - @NonNull + @NonNull Boolean isBound(@NonNull Long identifier, @NonNull Long useCaseIdentifier); void unbind(@NonNull Long identifier, @NonNull List useCaseIds); @@ -874,12 +812,18 @@ public interface ProcessCameraProviderHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `ProcessCameraProviderHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ProcessCameraProviderHostApi api) { + /** + * Sets up an instance of `ProcessCameraProviderHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable ProcessCameraProviderHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.getInstance", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -906,7 +850,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.getAvailableCameraInfos", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -914,10 +860,11 @@ public void error(Throwable error) { ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - List output = api.getAvailableCameraInfos((identifierArg == null) ? null : identifierArg.longValue()); + List output = + api.getAvailableCameraInfos( + (identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -930,7 +877,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.bindToLifecycle", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -940,10 +889,15 @@ public void error(Throwable error) { Number cameraSelectorIdentifierArg = (Number) args.get(1); List useCaseIdsArg = (List) args.get(2); try { - Long output = api.bindToLifecycle((identifierArg == null) ? null : identifierArg.longValue(), (cameraSelectorIdentifierArg == null) ? null : cameraSelectorIdentifierArg.longValue(), useCaseIdsArg); + Long output = + api.bindToLifecycle( + (identifierArg == null) ? null : identifierArg.longValue(), + (cameraSelectorIdentifierArg == null) + ? null + : cameraSelectorIdentifierArg.longValue(), + useCaseIdsArg); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -956,7 +910,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.isBound", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -965,10 +921,12 @@ public void error(Throwable error) { Number identifierArg = (Number) args.get(0); Number useCaseIdentifierArg = (Number) args.get(1); try { - Boolean output = api.isBound((identifierArg == null) ? null : identifierArg.longValue(), (useCaseIdentifierArg == null) ? null : useCaseIdentifierArg.longValue()); + Boolean output = + api.isBound( + (identifierArg == null) ? null : identifierArg.longValue(), + (useCaseIdentifierArg == null) ? null : useCaseIdentifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -981,7 +939,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbind", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -990,10 +950,10 @@ public void error(Throwable error) { Number identifierArg = (Number) args.get(0); List useCaseIdsArg = (List) args.get(1); try { - api.unbind((identifierArg == null) ? null : identifierArg.longValue(), useCaseIdsArg); + api.unbind( + (identifierArg == null) ? null : identifierArg.longValue(), useCaseIdsArg); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1006,7 +966,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderHostApi.unbindAll", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1016,8 +978,7 @@ public void error(Throwable error) { try { api.unbindAll((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1037,7 +998,7 @@ public ProcessCameraProviderFlutterApi(@NonNull BinaryMessenger argBinaryMesseng this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1046,10 +1007,13 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ProcessCameraProviderFlutterApi.create", + getCodec()); channel.send( new ArrayList(Collections.singletonList(identifierArg)), channelReply -> callback.reply(null)); @@ -1058,14 +1022,14 @@ public void create(@NonNull Long identifierArg, @NonNull Reply callback) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface CameraHostApi { - @NonNull + @NonNull Long getCameraInfo(@NonNull Long identifier); /** The codec used by CameraHostApi. */ static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `CameraHostApi` to handle messages through the `binaryMessenger`. */ + /** Sets up an instance of `CameraHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraHostApi api) { { BasicMessageChannel channel = @@ -1078,10 +1042,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable CameraHost ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = api.getCameraInfo((identifierArg == null) ? null : identifierArg.longValue()); + Long output = + api.getCameraInfo((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1101,7 +1065,7 @@ public CameraFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1110,6 +1074,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1149,9 +1114,11 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface SystemServicesHostApi { - void requestCameraPermissions(@NonNull Boolean enableAudio, @NonNull Result result); + void requestCameraPermissions( + @NonNull Boolean enableAudio, @NonNull Result result); - void startListeningForDeviceOrientationChange(@NonNull Boolean isFrontFacing, @NonNull Long sensorOrientation); + void startListeningForDeviceOrientationChange( + @NonNull Boolean isFrontFacing, @NonNull Long sensorOrientation); void stopListeningForDeviceOrientationChange(); @@ -1162,12 +1129,18 @@ public interface SystemServicesHostApi { static @NonNull MessageCodec getCodec() { return SystemServicesHostApiCodec.INSTANCE; } - /**Sets up an instance of `SystemServicesHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable SystemServicesHostApi api) { + /** + * Sets up an instance of `SystemServicesHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable SystemServicesHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.SystemServicesHostApi.requestCameraPermissions", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1196,7 +1169,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.SystemServicesHostApi.startListeningForDeviceOrientationChange", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1205,10 +1180,11 @@ public void error(Throwable error) { Boolean isFrontFacingArg = (Boolean) args.get(0); Number sensorOrientationArg = (Number) args.get(1); try { - api.startListeningForDeviceOrientationChange(isFrontFacingArg, (sensorOrientationArg == null) ? null : sensorOrientationArg.longValue()); + api.startListeningForDeviceOrientationChange( + isFrontFacingArg, + (sensorOrientationArg == null) ? null : sensorOrientationArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1221,7 +1197,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.SystemServicesHostApi.stopListeningForDeviceOrientationChange", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1229,8 +1207,7 @@ public void error(Throwable error) { try { api.stopListeningForDeviceOrientationChange(); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1276,7 +1253,7 @@ public SystemServicesFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -1285,18 +1262,25 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void onDeviceOrientationChanged(@NonNull String orientationArg, @NonNull Reply callback) { + + public void onDeviceOrientationChanged( + @NonNull String orientationArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.SystemServicesFlutterApi.onDeviceOrientationChanged", + getCodec()); channel.send( new ArrayList(Collections.singletonList(orientationArg)), channelReply -> callback.reply(null)); } + public void onCameraError(@NonNull String errorDescriptionArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.SystemServicesFlutterApi.onCameraError", + getCodec()); channel.send( new ArrayList(Collections.singletonList(errorDescriptionArg)), channelReply -> callback.reply(null)); @@ -1337,21 +1321,24 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface PreviewHostApi { - void create(@NonNull Long identifier, @Nullable Long rotation, @Nullable ResolutionInfo targetResolution); + void create( + @NonNull Long identifier, + @Nullable Long rotation, + @Nullable ResolutionInfo targetResolution); - @NonNull + @NonNull Long setSurfaceProvider(@NonNull Long identifier); void releaseFlutterSurfaceTexture(); - @NonNull + @NonNull ResolutionInfo getResolutionInfo(@NonNull Long identifier); /** The codec used by PreviewHostApi. */ static @NonNull MessageCodec getCodec() { return PreviewHostApiCodec.INSTANCE; } - /**Sets up an instance of `PreviewHostApi` to handle messages through the `binaryMessenger`. */ + /** Sets up an instance of `PreviewHostApi` to handle messages through the `binaryMessenger`. */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHostApi api) { { BasicMessageChannel channel = @@ -1366,10 +1353,12 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos Number rotationArg = (Number) args.get(1); ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); try { - api.create((identifierArg == null) ? null : identifierArg.longValue(), (rotationArg == null) ? null : rotationArg.longValue(), targetResolutionArg); + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + (rotationArg == null) ? null : rotationArg.longValue(), + targetResolutionArg); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1382,7 +1371,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.PreviewHostApi.setSurfaceProvider", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1390,10 +1381,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - Long output = api.setSurfaceProvider((identifierArg == null) ? null : identifierArg.longValue()); + Long output = + api.setSurfaceProvider( + (identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1406,7 +1398,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.PreviewHostApi.releaseFlutterSurfaceTexture", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1414,8 +1408,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos try { api.releaseFlutterSurfaceTexture(); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1436,10 +1429,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - ResolutionInfo output = api.getResolutionInfo((identifierArg == null) ? null : identifierArg.longValue()); + ResolutionInfo output = + api.getResolutionInfo( + (identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1947,7 +1941,10 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageCaptureHostApi { - void create(@NonNull Long identifier, @Nullable Long flashMode, @Nullable ResolutionInfo targetResolution); + void create( + @NonNull Long identifier, + @Nullable Long flashMode, + @Nullable ResolutionInfo targetResolution); void setFlashMode(@NonNull Long identifier, @NonNull Long flashMode); @@ -1957,7 +1954,10 @@ public interface ImageCaptureHostApi { static @NonNull MessageCodec getCodec() { return ImageCaptureHostApiCodec.INSTANCE; } - /**Sets up an instance of `ImageCaptureHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `ImageCaptureHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptureHostApi api) { { BasicMessageChannel channel = @@ -1972,10 +1972,12 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu Number flashModeArg = (Number) args.get(1); ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); try { - api.create((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue(), targetResolutionArg); + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + (flashModeArg == null) ? null : flashModeArg.longValue(), + targetResolutionArg); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -1997,10 +1999,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu Number identifierArg = (Number) args.get(0); Number flashModeArg = (Number) args.get(1); try { - api.setFlashMode((identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue()); + api.setFlashMode( + (identifierArg == null) ? null : identifierArg.longValue(), + (flashModeArg == null) ? null : flashModeArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2033,7 +2036,8 @@ public void error(Throwable error) { } }; - api.takePicture((identifierArg == null) ? null : identifierArg.longValue(), resultCallback); + api.takePicture( + (identifierArg == null) ? null : identifierArg.longValue(), resultCallback); }); } else { channel.setMessageHandler(null); @@ -2134,7 +2138,7 @@ public ExposureStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -2143,91 +2147,19 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return ExposureStateFlutterApiCodec.INSTANCE; } - public void create(@NonNull Long identifierArg, @NonNull ExposureCompensationRange exposureCompensationRangeArg, @NonNull Double exposureCompensationStepArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ExposureStateFlutterApi.create", getCodec()); - channel.send( - new ArrayList(Arrays.asList(identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), - channelReply -> callback.reply(null)); - } - } - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class ZoomStateFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public ZoomStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by ZoomStateFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - public void create(@NonNull Long identifierArg, @NonNull Double minZoomRatioArg, @NonNull Double maxZoomRatioArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ZoomStateFlutterApi.create", getCodec()); - channel.send( - new ArrayList(Arrays.asList(identifierArg, minZoomRatioArg, maxZoomRatioArg)), - channelReply -> callback.reply(null)); - } - } - - private static class ExposureStateFlutterApiCodec extends StandardMessageCodec { - public static final ExposureStateFlutterApiCodec INSTANCE = new ExposureStateFlutterApiCodec(); - - private ExposureStateFlutterApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return ExposureCompensationRange.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof ExposureCompensationRange) { - stream.write(128); - writeValue(stream, ((ExposureCompensationRange) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class ExposureStateFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public ExposureStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by ExposureStateFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return ExposureStateFlutterApiCodec.INSTANCE; - } - public void create(@NonNull Long identifierArg, @NonNull ExposureCompensationRange exposureCompensationRangeArg, @NonNull Double exposureCompensationStepArg, @NonNull Reply callback) { + public void create( + @NonNull Long identifierArg, + @NonNull ExposureCompensationRange exposureCompensationRangeArg, + @NonNull Double exposureCompensationStepArg, + @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ExposureStateFlutterApi.create", getCodec()); channel.send( - new ArrayList(Arrays.asList(identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), + new ArrayList( + Arrays.asList( + identifierArg, exposureCompensationRangeArg, exposureCompensationStepArg)), channelReply -> callback.reply(null)); } } @@ -2239,7 +2171,7 @@ public ZoomStateFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -2248,7 +2180,12 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Double minZoomRatioArg, @NonNull Double maxZoomRatioArg, @NonNull Reply callback) { + + public void create( + @NonNull Long identifierArg, + @NonNull Double minZoomRatioArg, + @NonNull Double maxZoomRatioArg, + @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ZoomStateFlutterApi.create", getCodec()); @@ -2297,8 +2234,12 @@ public interface ImageAnalysisHostApi { static @NonNull MessageCodec getCodec() { return ImageAnalysisHostApiCodec.INSTANCE; } - /**Sets up an instance of `ImageAnalysisHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnalysisHostApi api) { + /** + * Sets up an instance of `ImageAnalysisHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnalysisHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -2311,10 +2252,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnaly Number identifierArg = (Number) args.get(0); ResolutionInfo targetResolutionIdentifierArg = (ResolutionInfo) args.get(1); try { - api.create((identifierArg == null) ? null : identifierArg.longValue(), targetResolutionIdentifierArg); + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + targetResolutionIdentifierArg); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2336,10 +2278,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnaly Number identifierArg = (Number) args.get(0); Number analyzerIdentifierArg = (Number) args.get(1); try { - api.setAnalyzer((identifierArg == null) ? null : identifierArg.longValue(), (analyzerIdentifierArg == null) ? null : analyzerIdentifierArg.longValue()); + api.setAnalyzer( + (identifierArg == null) ? null : identifierArg.longValue(), + (analyzerIdentifierArg == null) ? null : analyzerIdentifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2352,7 +2295,9 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnaly { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.ImageAnalysisHostApi.clearAnalyzer", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -2362,8 +2307,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageAnaly try { api.clearAnalyzer((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2384,7 +2328,9 @@ public interface AnalyzerHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `AnalyzerHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `AnalyzerHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable AnalyzerHostApi api) { { BasicMessageChannel channel = @@ -2399,8 +2345,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable AnalyzerHo try { api.create((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2695,7 +2640,7 @@ public AnalyzerFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -2704,6 +2649,7 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } + public void create(@NonNull Long identifierArg, @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -2712,7 +2658,11 @@ public void create(@NonNull Long identifierArg, @NonNull Reply callback) { new ArrayList(Collections.singletonList(identifierArg)), channelReply -> callback.reply(null)); } - public void analyze(@NonNull Long identifierArg, @NonNull Long imageProxyIdentifierArg, @NonNull Reply callback) { + + public void analyze( + @NonNull Long identifierArg, + @NonNull Long imageProxyIdentifierArg, + @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.AnalyzerFlutterApi.analyze", getCodec()); @@ -2724,7 +2674,7 @@ public void analyze(@NonNull Long identifierArg, @NonNull Long imageProxyIdentif /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageProxyHostApi { - @NonNull + @NonNull List getPlanes(@NonNull Long identifier); void close(@NonNull Long identifier); @@ -2733,7 +2683,9 @@ public interface ImageProxyHostApi { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `ImageProxyHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `ImageProxyHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxyHostApi api) { { BasicMessageChannel channel = @@ -2746,10 +2698,10 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxy ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); try { - List output = api.getPlanes((identifierArg == null) ? null : identifierArg.longValue()); + List output = + api.getPlanes((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, output); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2772,8 +2724,7 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageProxy try { api.close((identifierArg == null) ? null : identifierArg.longValue()); wrapped.add(0, null); - } - catch (Throwable exception) { + } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); wrapped = wrappedError; } @@ -2793,7 +2744,7 @@ public ImageProxyFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -2802,7 +2753,13 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull Long formatArg, @NonNull Long heightArg, @NonNull Long widthArg, @NonNull Reply callback) { + + public void create( + @NonNull Long identifierArg, + @NonNull Long formatArg, + @NonNull Long heightArg, + @NonNull Long widthArg, + @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.ImageProxyFlutterApi.create", getCodec()); @@ -2819,7 +2776,7 @@ public PlaneProxyFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ + /** Public interface for sending reply. */ @SuppressWarnings("UnknownNullness") public interface Reply { void reply(T reply); @@ -2828,12 +2785,19 @@ public interface Reply { static @NonNull MessageCodec getCodec() { return new StandardMessageCodec(); } - public void create(@NonNull Long identifierArg, @NonNull byte[] bufferArg, @NonNull Long pixelStrideArg, @NonNull Long rowStrideArg, @NonNull Reply callback) { + + public void create( + @NonNull Long identifierArg, + @NonNull byte[] bufferArg, + @NonNull Long pixelStrideArg, + @NonNull Long rowStrideArg, + @NonNull Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.PlaneProxyFlutterApi.create", getCodec()); channel.send( - new ArrayList(Arrays.asList(identifierArg, bufferArg, pixelStrideArg, rowStrideArg)), + new ArrayList( + Arrays.asList(identifierArg, bufferArg, pixelStrideArg, rowStrideArg)), channelReply -> callback.reply(null)); } } diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index 1f3a4d632ceb..959f35b0980e 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -412,55 +412,6 @@ class AndroidCameraCameraX extends CameraPlatform { return zoomState.minZoomRatio; } - /// Gets the minimum supported exposure offset for the selected camera in EV units. - /// - /// [cameraId] not used. - @override - Future getMinExposureOffset(int cameraId) async { - final ExposureState exposureState = await cameraInfo!.getExposureState(); - return exposureState.exposureCompensationRange.minCompensation * - exposureState.exposureCompensationStep; - } - - /// Gets the maximum supported exposure offset for the selected camera in EV units. - /// - /// [cameraId] not used. - @override - Future getMaxExposureOffset(int cameraId) async { - final ExposureState exposureState = await cameraInfo!.getExposureState(); - return exposureState.exposureCompensationRange.maxCompensation * - exposureState.exposureCompensationStep; - } - - /// Gets the supported step size for exposure offset for the selected camera in EV units. - /// - /// Returns 0 when exposure compensation is not supported. - /// - /// [cameraId] not used. - @override - Future getExposureOffsetStepSize(int cameraId) async { - final ExposureState exposureState = await cameraInfo!.getExposureState(); - return exposureState.exposureCompensationStep; - } - - /// Gets the maximum supported zoom level for the selected camera. - /// - /// [cameraId] not used. - @override - Future getMaxZoomLevel(int cameraId) async { - final ZoomState exposureState = await cameraInfo!.getZoomState(); - return exposureState.maxZoomRatio; - } - - /// Gets the minimum supported zoom level for the selected camera. - /// - /// [cameraId] not used. - @override - Future getMinZoomLevel(int cameraId) async { - final ZoomState exposureState = await cameraInfo!.getZoomState(); - return exposureState.minZoomRatio; - } - /// The ui orientation changed. @override Stream onDeviceOrientationChanged() { diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart index e60fbdec5197..b268323ccfe2 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax_flutter_api_impls.dart @@ -144,12 +144,6 @@ class AndroidCameraXCameraFlutterApis { /// Flutter Api for [ZoomState]. late final ZoomStateFlutterApiImpl zoomStateFlutterApiImpl; - /// Flutter Api for [ExposureState]. - late final ExposureStateFlutterApiImpl exposureStateFlutterApiImpl; - - /// Flutter Api for [ZoomState]. - late final ZoomStateFlutterApiImpl zoomStateFlutterApiImpl; - /// Flutter Api implementation for [Analyzer]. late final AnalyzerFlutterApiImpl analyzerFlutterApiImpl; diff --git a/packages/camera/camera_android_camerax/lib/src/camera_info.dart b/packages/camera/camera_android_camerax/lib/src/camera_info.dart index 48c03e675bb5..4ed78ddfbf37 100644 --- a/packages/camera/camera_android_camerax/lib/src/camera_info.dart +++ b/packages/camera/camera_android_camerax/lib/src/camera_info.dart @@ -98,23 +98,6 @@ class _CameraInfoHostApiImpl extends CameraInfoHostApi { return instanceManager.getInstanceWithWeakReference>( zoomStateIdentifier)!; } - - /// Gets the [ExposureState] of the specified [CameraInfo] instance. - Future getExposureStateFromInstance( - CameraInfo instance) async { - final int? identifier = instanceManager.getIdentifier(instance); - final int exposureStateIdentifier = await getExposureState(identifier!); - return instanceManager - .getInstanceWithWeakReference(exposureStateIdentifier)!; - } - - /// Gets the [ZoomState] of the specified [CameraInfo] instance. - Future getZoomStateFromInstance(CameraInfo instance) async { - final int? identifier = instanceManager.getIdentifier(instance); - final int zoomStateIdentifier = await getZoomState(identifier!); - return instanceManager - .getInstanceWithWeakReference(zoomStateIdentifier)!; - } } /// Flutter API implementation of [CameraInfo]. diff --git a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart index a1546ccf3730..2a1b2813f1aa 100644 --- a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart @@ -147,32 +147,6 @@ class ExposureCompensationRange { } } -class ExposureCompensationRange { - ExposureCompensationRange({ - required this.minCompensation, - required this.maxCompensation, - }); - - int minCompensation; - - int maxCompensation; - - Object encode() { - return [ - minCompensation, - maxCompensation, - ]; - } - - static ExposureCompensationRange decode(Object result) { - result as List; - return ExposureCompensationRange( - minCompensation: result[0]! as int, - maxCompensation: result[1]! as int, - ); - } -} - class InstanceManagerHostApi { /// Constructor for [InstanceManagerHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -1793,104 +1767,6 @@ abstract class ZoomStateFlutterApi { } } -class _ExposureStateFlutterApiCodec extends StandardMessageCodec { - const _ExposureStateFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is ExposureCompensationRange) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return ExposureCompensationRange.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class ExposureStateFlutterApi { - static const MessageCodec codec = _ExposureStateFlutterApiCodec(); - - void create( - int identifier, - ExposureCompensationRange exposureCompensationRange, - double exposureCompensationStep); - - static void setup(ExposureStateFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ExposureStateFlutterApi.create', codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null int.'); - final ExposureCompensationRange? arg_exposureCompensationRange = - (args[1] as ExposureCompensationRange?); - assert(arg_exposureCompensationRange != null, - 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null ExposureCompensationRange.'); - final double? arg_exposureCompensationStep = (args[2] as double?); - assert(arg_exposureCompensationStep != null, - 'Argument for dev.flutter.pigeon.ExposureStateFlutterApi.create was null, expected non-null double.'); - api.create(arg_identifier!, arg_exposureCompensationRange!, - arg_exposureCompensationStep!); - return; - }); - } - } - } -} - -abstract class ZoomStateFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - void create(int identifier, double minZoomRatio, double maxZoomRatio); - - static void setup(ZoomStateFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ZoomStateFlutterApi.create', codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null int.'); - final double? arg_minZoomRatio = (args[1] as double?); - assert(arg_minZoomRatio != null, - 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null double.'); - final double? arg_maxZoomRatio = (args[2] as double?); - assert(arg_maxZoomRatio != null, - 'Argument for dev.flutter.pigeon.ZoomStateFlutterApi.create was null, expected non-null double.'); - api.create(arg_identifier!, arg_minZoomRatio!, arg_maxZoomRatio!); - return; - }); - } - } - } -} - class _ImageAnalysisHostApiCodec extends StandardMessageCodec { const _ImageAnalysisHostApiCodec(); @override diff --git a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart index ac14add39ace..601601dbf365 100644 --- a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart +++ b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart @@ -96,16 +96,6 @@ class ExposureCompensationRange { int maxCompensation; } -class ExposureCompensationRange { - ExposureCompensationRange({ - required this.minCompensation, - required this.maxCompensation, - }); - - int minCompensation; - int maxCompensation; -} - @HostApi(dartHostTestHandler: 'TestInstanceManagerHostApi') abstract class InstanceManagerHostApi { /// Clear the native `InstanceManager`. @@ -297,19 +287,6 @@ abstract class ZoomStateFlutterApi { void create(int identifier, double minZoomRatio, double maxZoomRatio); } -@FlutterApi() -abstract class ExposureStateFlutterApi { - void create( - int identifier, - ExposureCompensationRange exposureCompensationRange, - double exposureCompensationStep); -} - -@FlutterApi() -abstract class ZoomStateFlutterApi { - void create(int identifier, double minZoomRatio, double maxZoomRatio); -} - @HostApi(dartHostTestHandler: 'TestImageAnalysisHostApi') abstract class ImageAnalysisHostApi { void create(int identifier, ResolutionInfo? targetResolutionIdentifier); diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index 88b381fc4143..d6e2531cf084 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -181,8 +181,6 @@ void main() { final MockCameraInfo mockCameraInfo = MockCameraInfo(); final MockLiveCameraState mockLiveCameraState = MockLiveCameraState(); - camera.processCameraProvider = mockProcessCameraProvider; - when(camera.testPreview.setSurfaceProvider()) .thenAnswer((_) async => testSurfaceTextureId); when(mockProcessCameraProvider.bindToLifecycle( @@ -247,16 +245,6 @@ void main() { final MockCamera mockCamera = MockCamera(); final MockCameraInfo mockCameraInfo = MockCameraInfo(); - when(mockProcessCameraProvider.bindToLifecycle( - camera.mockBackCameraSelector, - [camera.testPreview, camera.testImageCapture])) - .thenAnswer((_) async => mockCamera); - when(mockCamera.getCameraInfo()).thenAnswer((_) async => mockCameraInfo); - when(mockCameraInfo.getLiveCameraState()) - .thenAnswer((_) async => MockLiveData()); - camera.processCameraProvider = mockProcessCameraProvider; - camera.createDetachedObjectForTesting = true; - camera.processCameraProvider = mockProcessCameraProvider; when(mockProcessCameraProvider.bindToLifecycle( @@ -340,16 +328,6 @@ void main() { await camera.createCamera(testCameraDescription, testResolutionPreset, enableAudio: enableAudio); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) async => mockCamera); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(MockCameraInfo())); - when(camera.testPreview.getResolutionInfo()) - .thenAnswer((_) async => testResolutionInfo); - - await camera.createCamera(testCameraDescription, testResolutionPreset, - enableAudio: enableAudio); - // Start listening to camera events stream to verify the proper CameraInitializedEvent is sent. camera.cameraEventStreamController.stream.listen((CameraEvent event) { expect(event, const TypeMatcher()); @@ -537,11 +515,6 @@ void main() { when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => mockLiveCameraState); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(mockCameraInfo)); - await camera.resumePreview(78); verify(camera.processCameraProvider! @@ -578,11 +551,6 @@ void main() { when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => MockLiveCameraState()); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(MockCameraInfo())); - final FutureBuilder previewWidget = camera.buildPreview(textureId) as FutureBuilder; @@ -622,11 +590,6 @@ void main() { when(mockCameraInfo.getCameraState()) .thenAnswer((_) async => MockLiveCameraState()); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(mockCameraInfo)); - final FutureBuilder previewWidget = camera.buildPreview(textureId) as FutureBuilder; @@ -929,11 +892,6 @@ void main() { camera.processCameraProvider = mockProcessCameraProvider; camera.cameraSelector = MockCameraSelector(); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) - .thenAnswer((_) => Future.value(mockCamera)); - when(mockCamera.getCameraInfo()) - .thenAnswer((_) => Future.value(MockCameraInfo())); - when(mockProcessCameraProvider.bindToLifecycle(any, any)) .thenAnswer((_) => Future.value(mockCamera)); when(mockCamera.getCameraInfo()) From c78e0b82a747ba9dc1324865570af92188105bc8 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 19 Jul 2023 09:59:40 -0700 Subject: [PATCH 03/10] Add wrapped classes, tests, and remove deprecated apis --- .../camera_android_camerax/CHANGELOG.md | 6 + .../android/build.gradle | 2 +- .../AspectRatioStrategyHostApiImpl.java | 61 ++++ .../camerax/CameraAndroidCameraxPlugin.java | 6 + .../camerax/GeneratedCameraXLibrary.java | 284 +++++++++++++----- .../camerax/ImageAnalysisHostApiImpl.java | 9 +- .../camerax/ImageCaptureHostApiImpl.java | 12 +- .../plugins/camerax/PreviewHostApiImpl.java | 12 +- .../ResolutionSelectorHostApiImpl.java | 85 ++++++ .../ResolutionStrategyHostApiImpl.java | 80 +++++ .../camerax/AspectRatioStrategyTest.java | 51 ++++ .../plugins/camerax/ImageAnalysisTest.java | 22 +- .../plugins/camerax/ImageCaptureTest.java | 22 +- .../flutter/plugins/camerax/PreviewTest.java | 20 +- .../camerax/ResolutionSelectorTest.java | 59 ++++ .../camerax/ResolutionStrategyTest.java | 71 +++++ .../lib/src/android_camera_camerax.dart | 50 +-- .../lib/src/aspect_ratio_strategy.dart | 136 +++++++++ .../lib/src/camerax_library.g.dart | 220 ++++++++++---- .../lib/src/image_analysis.dart | 20 +- .../lib/src/image_capture.dart | 23 +- .../lib/src/preview.dart | 25 +- .../lib/src/resolution_selector.dart | 106 +++++++ .../lib/src/resolution_strategy.dart | 179 +++++++++++ .../pigeons/camerax_library.dart | 25 +- .../camera_android_camerax/pubspec.yaml | 2 +- .../test/android_camera_camerax_test.dart | 7 +- .../test/aspect_ratio_strategy_test.dart | 54 ++++ .../aspect_ratio_strategy_test.mocks.dart | 68 +++++ .../test/image_analysis_test.dart | 50 +-- .../test/image_analysis_test.mocks.dart | 16 +- .../test/image_capture_test.dart | 37 ++- .../test/image_capture_test.mocks.dart | 24 +- .../test/preview_test.dart | 33 +- .../test/preview_test.mocks.dart | 15 +- .../test/resolution_selector_test.dart | 87 ++++++ .../test/resolution_selector_test.mocks.dart | 68 +++++ .../test/resolution_strategy_test.dart | 104 +++++++ .../test/resolution_strategy_test.mocks.dart | 69 +++++ .../test/test_camerax_library.g.dart | 173 ++++++++--- 40 files changed, 2024 insertions(+), 369 deletions(-) create mode 100644 packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java create mode 100644 packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java create mode 100644 packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java create mode 100644 packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java create mode 100644 packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionSelectorTest.java create mode 100644 packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java create mode 100644 packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart create mode 100644 packages/camera/camera_android_camerax/lib/src/resolution_selector.dart create mode 100644 packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart create mode 100644 packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart create mode 100644 packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.mocks.dart create mode 100644 packages/camera/camera_android_camerax/test/resolution_selector_test.dart create mode 100644 packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart create mode 100644 packages/camera/camera_android_camerax/test/resolution_strategy_test.dart create mode 100644 packages/camera/camera_android_camerax/test/resolution_strategy_test.mocks.dart diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md index ab60e8aba87a..1cddca1cbbc3 100644 --- a/packages/camera/camera_android_camerax/CHANGELOG.md +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.5.0+12 + +* Wraps classes needed to implement resolution configuration for image capture, image analysis, and preview. +* Removes usages of deprecated APIs for resolution configuration. +* Bumps CameraX version to 1.3.0-beta01. + ## 0.5.0+11 * Fixes issue with image data not being emitted after relistening to stream returned by `onStreamedFrameAvailable`. diff --git a/packages/camera/camera_android_camerax/android/build.gradle b/packages/camera/camera_android_camerax/android/build.gradle index f10f13336081..5530a3bb1043 100644 --- a/packages/camera/camera_android_camerax/android/build.gradle +++ b/packages/camera/camera_android_camerax/android/build.gradle @@ -61,7 +61,7 @@ android { dependencies { // CameraX core library using the camera2 implementation must use same version number. - def camerax_version = "1.3.0-alpha05" + def camerax_version = "1.3.0-beta01" implementation "androidx.camera:camera-core:${camerax_version}" implementation "androidx.camera:camera-camera2:${camerax_version}" implementation "androidx.camera:camera-lifecycle:${camerax_version}" 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 new file mode 100644 index 000000000000..218af3afc21d --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java @@ -0,0 +1,61 @@ +// 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 constructors and static method 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 a {@link AspectRatioStrategyHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + */ + public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) { + this(instanceManager, new AspectRatioStrategyProxy()); + } + + /** + * Constructs a {@link AspectRatioStrategyHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + * @param proxy proxy for constructors and static method of {@link AspectRatioStrategy} + */ + @VisibleForTesting + AspectRatioStrategyHostApiImpl( + @NonNull InstanceManager instanceManager, @NonNull AspectRatioStrategyProxy proxy) { + this.instanceManager = instanceManager; + this.proxy = proxy; + } + + @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/CameraAndroidCameraxPlugin.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java index dd8ab514652c..dbae2a468052 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 @@ -97,6 +97,12 @@ public void 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)); } @Override diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java index c6f627993772..680ecb805250 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/GeneratedCameraXLibrary.java @@ -76,6 +76,23 @@ private CameraStateType(final int index) { } } + /** + * The types (T) properly wrapped to be used as a LiveData. + * + *

If you need to add another type to support a type S to use a LiveData in this plugin, + * ensure the following is done on the Dart side: + * + *

* In `../lib/src/live_data.dart`, add new cases for S in + * `_LiveDataHostApiImpl#getValueFromInstances` to get the current value of type S from a + * LiveData instance and in `LiveDataFlutterApiImpl#create` to create the expected type of + * LiveData when requested. + * + *

On the native side, ensure the following is done: + * + *

* Update `LiveDataHostApiImpl#getValue` is updated to properly return identifiers for + * instances of type S. * Update `ObserverFlutterApiWrapper#onChanged` to properly handle + * receiving calls with instances of type S if a LiveData instance is observed. + */ public enum LiveDataSupportedType { CAMERA_STATE(0), ZOOM_STATE(1); @@ -1297,8 +1314,6 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { case (byte) 128: return ResolutionInfo.fromList((ArrayList) readValue(buffer)); - case (byte) 129: - return ResolutionInfo.fromList((ArrayList) readValue(buffer)); default: return super.readValueOfType(type, buffer); } @@ -1309,9 +1324,6 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { if (value instanceof ResolutionInfo) { stream.write(128); writeValue(stream, ((ResolutionInfo) value).toList()); - } else if (value instanceof ResolutionInfo) { - stream.write(129); - writeValue(stream, ((ResolutionInfo) value).toList()); } else { super.writeValue(stream, value); } @@ -1322,9 +1334,7 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { public interface PreviewHostApi { void create( - @NonNull Long identifier, - @Nullable Long rotation, - @Nullable ResolutionInfo targetResolution); + @NonNull Long identifier, @Nullable Long rotation, @Nullable Long resolutionSelectorId); @NonNull Long setSurfaceProvider(@NonNull Long identifier); @@ -1351,12 +1361,14 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PreviewHos ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); Number rotationArg = (Number) args.get(1); - ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); + Number resolutionSelectorIdArg = (Number) args.get(2); try { api.create( (identifierArg == null) ? null : identifierArg.longValue(), (rotationArg == null) ? null : rotationArg.longValue(), - targetResolutionArg); + (resolutionSelectorIdArg == null) + ? null + : resolutionSelectorIdArg.longValue()); wrapped.add(0, null); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); @@ -1911,40 +1923,11 @@ public void create(@NonNull Long identifierArg, @NonNull Reply callback) { channelReply -> callback.reply(null)); } } - - private static class ImageCaptureHostApiCodec extends StandardMessageCodec { - public static final ImageCaptureHostApiCodec INSTANCE = new ImageCaptureHostApiCodec(); - - private ImageCaptureHostApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return ResolutionInfo.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof ResolutionInfo) { - stream.write(128); - writeValue(stream, ((ResolutionInfo) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageCaptureHostApi { void create( - @NonNull Long identifier, - @Nullable Long flashMode, - @Nullable ResolutionInfo targetResolution); + @NonNull Long identifier, @Nullable Long flashMode, @Nullable Long resolutionSelectorId); void setFlashMode(@NonNull Long identifier, @NonNull Long flashMode); @@ -1952,7 +1935,7 @@ void create( /** The codec used by ImageCaptureHostApi. */ static @NonNull MessageCodec getCodec() { - return ImageCaptureHostApiCodec.INSTANCE; + return new StandardMessageCodec(); } /** * Sets up an instance of `ImageCaptureHostApi` to handle messages through the @@ -1970,12 +1953,14 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable ImageCaptu ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); Number flashModeArg = (Number) args.get(1); - ResolutionInfo targetResolutionArg = (ResolutionInfo) args.get(2); + Number resolutionSelectorIdArg = (Number) args.get(2); try { api.create( (identifierArg == null) ? null : identifierArg.longValue(), (flashModeArg == null) ? null : flashModeArg.longValue(), - targetResolutionArg); + (resolutionSelectorIdArg == null) + ? null + : resolutionSelectorIdArg.longValue()); wrapped.add(0, null); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); @@ -2046,6 +2031,182 @@ public void error(Throwable error) { } } + private static class ResolutionStrategyHostApiCodec extends StandardMessageCodec { + public static final ResolutionStrategyHostApiCodec INSTANCE = + new ResolutionStrategyHostApiCodec(); + + private ResolutionStrategyHostApiCodec() {} + + @Override + protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { + switch (type) { + case (byte) 128: + return ResolutionInfo.fromList((ArrayList) readValue(buffer)); + default: + return super.readValueOfType(type, buffer); + } + } + + @Override + protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { + if (value instanceof ResolutionInfo) { + stream.write(128); + writeValue(stream, ((ResolutionInfo) value).toList()); + } else { + super.writeValue(stream, value); + } + } + } + + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ + public interface ResolutionStrategyHostApi { + + void create( + @NonNull Long identifier, @Nullable ResolutionInfo boundSize, @Nullable Long fallbackRule); + + /** The codec used by ResolutionStrategyHostApi. */ + static @NonNull MessageCodec getCodec() { + return ResolutionStrategyHostApiCodec.INSTANCE; + } + /** + * Sets up an instance of `ResolutionStrategyHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable ResolutionStrategyHostApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.ResolutionStrategyHostApi.create", getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + ResolutionInfo boundSizeArg = (ResolutionInfo) args.get(1); + Number fallbackRuleArg = (Number) args.get(2); + try { + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + boundSizeArg, + (fallbackRuleArg == null) ? null : fallbackRuleArg.longValue()); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + } + } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ + public interface ResolutionSelectorHostApi { + + void create( + @NonNull Long identifier, + @Nullable Long resolutionStrategyIdentifier, + @Nullable Long aspectRatioStrategyIdentifier); + + /** The codec used by ResolutionSelectorHostApi. */ + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); + } + /** + * Sets up an instance of `ResolutionSelectorHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable ResolutionSelectorHostApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.ResolutionSelectorHostApi.create", getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + Number resolutionStrategyIdentifierArg = (Number) args.get(1); + Number aspectRatioStrategyIdentifierArg = (Number) args.get(2); + try { + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + (resolutionStrategyIdentifierArg == null) + ? null + : resolutionStrategyIdentifierArg.longValue(), + (aspectRatioStrategyIdentifierArg == null) + ? null + : aspectRatioStrategyIdentifierArg.longValue()); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + } + } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ + public interface AspectRatioStrategyHostApi { + + void create( + @NonNull Long identifier, @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule); + + /** The codec used by AspectRatioStrategyHostApi. */ + static @NonNull MessageCodec getCodec() { + return new StandardMessageCodec(); + } + /** + * Sets up an instance of `AspectRatioStrategyHostApi` to handle messages through the + * `binaryMessenger`. + */ + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable AspectRatioStrategyHostApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.AspectRatioStrategyHostApi.create", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + Number identifierArg = (Number) args.get(0); + Number preferredAspectRatioArg = (Number) args.get(1); + Number fallbackRuleArg = (Number) args.get(2); + try { + api.create( + (identifierArg == null) ? null : identifierArg.longValue(), + (preferredAspectRatioArg == null) + ? null + : preferredAspectRatioArg.longValue(), + (fallbackRuleArg == null) ? null : fallbackRuleArg.longValue()); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + } + } + private static class CameraStateFlutterApiCodec extends StandardMessageCodec { public static final CameraStateFlutterApiCodec INSTANCE = new CameraStateFlutterApiCodec(); @@ -2194,37 +2355,10 @@ public void create( channelReply -> callback.reply(null)); } } - - private static class ImageAnalysisHostApiCodec extends StandardMessageCodec { - public static final ImageAnalysisHostApiCodec INSTANCE = new ImageAnalysisHostApiCodec(); - - private ImageAnalysisHostApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return ResolutionInfo.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof ResolutionInfo) { - stream.write(128); - writeValue(stream, ((ResolutionInfo) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface ImageAnalysisHostApi { - void create(@NonNull Long identifier, @Nullable ResolutionInfo targetResolutionIdentifier); + void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId); void setAnalyzer(@NonNull Long identifier, @NonNull Long analyzerIdentifier); @@ -2232,7 +2366,7 @@ public interface ImageAnalysisHostApi { /** The codec used by ImageAnalysisHostApi. */ static @NonNull MessageCodec getCodec() { - return ImageAnalysisHostApiCodec.INSTANCE; + return new StandardMessageCodec(); } /** * Sets up an instance of `ImageAnalysisHostApi` to handle messages through the @@ -2250,11 +2384,13 @@ static void setup( ArrayList wrapped = new ArrayList(); ArrayList args = (ArrayList) message; Number identifierArg = (Number) args.get(0); - ResolutionInfo targetResolutionIdentifierArg = (ResolutionInfo) args.get(1); + Number resolutionSelectorIdArg = (Number) args.get(1); try { api.create( (identifierArg == null) ? null : identifierArg.longValue(), - targetResolutionIdentifierArg); + (resolutionSelectorIdArg == null) + ? null + : resolutionSelectorIdArg.longValue()); wrapped.add(0, null); } catch (Throwable exception) { ArrayList wrappedError = wrapError(exception); diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java index 5e786176d50c..62fd147d0aa9 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java @@ -9,10 +9,10 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.camera.core.ImageAnalysis; +import androidx.camera.core.resolutionselector.ResolutionSelector; import androidx.core.content.ContextCompat; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ImageAnalysisHostApi; -import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionInfo; import java.util.Objects; public class ImageAnalysisHostApiImpl implements ImageAnalysisHostApi { @@ -38,11 +38,12 @@ public void setContext(@NonNull Context context) { /** Creates an {@link ImageAnalysis} instance with the target resolution if specified. */ @Override - public void create(@NonNull Long identifier, @Nullable ResolutionInfo targetResolution) { + public void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId) { ImageAnalysis.Builder imageAnalysisBuilder = cameraXProxy.createImageAnalysisBuilder(); + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); - if (targetResolution != null) { - imageAnalysisBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution)); + if (resolutionSelector != null) { + imageAnalysisBuilder.setResolutionSelector(resolutionSelector); } ImageAnalysis imageAnalysis = imageAnalysisBuilder.build(); diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java index f2e71aa3eeee..bc4720608af7 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java @@ -10,6 +10,7 @@ import androidx.annotation.VisibleForTesting; import androidx.camera.core.ImageCapture; import androidx.camera.core.ImageCaptureException; +import androidx.camera.core.resolutionselector.ResolutionSelector; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ImageCaptureHostApi; import java.io.File; @@ -52,17 +53,18 @@ public void setContext(@NonNull Context context) { */ @Override public void create( - @NonNull Long identifier, - @Nullable Long flashMode, - @Nullable GeneratedCameraXLibrary.ResolutionInfo targetResolution) { + @NonNull Long identifier, @Nullable Long flashMode, @Nullable Long resolutionSelectorId) { ImageCapture.Builder imageCaptureBuilder = cameraXProxy.createImageCaptureBuilder(); + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); + if (flashMode != null) { // This sets the requested flash mode, but may fail silently. imageCaptureBuilder.setFlashMode(flashMode.intValue()); } - if (targetResolution != null) { - imageCaptureBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution)); + if (resolutionSelector != null) { + imageCaptureBuilder.setResolutionSelector(resolutionSelector); } + ImageCapture imageCapture = imageCaptureBuilder.build(); instanceManager.addDartCreatedInstance(imageCapture, identifier); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java index 6f93fd0f87cb..70f01cf260d0 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java @@ -12,6 +12,7 @@ import androidx.annotation.VisibleForTesting; import androidx.camera.core.Preview; import androidx.camera.core.SurfaceRequest; +import androidx.camera.core.resolutionselector.ResolutionSelector; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugins.camerax.GeneratedCameraXLibrary.PreviewHostApi; import io.flutter.view.TextureRegistry; @@ -38,16 +39,17 @@ public PreviewHostApiImpl( /** Creates a {@link Preview} with the target rotation and resolution if specified. */ @Override public void create( - @NonNull Long identifier, - @Nullable Long rotation, - @Nullable GeneratedCameraXLibrary.ResolutionInfo targetResolution) { + @NonNull Long identifier, @Nullable Long rotation, @Nullable Long resolutionSelectorId) { Preview.Builder previewBuilder = cameraXProxy.createPreviewBuilder(); + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); + if (rotation != null) { previewBuilder.setTargetRotation(rotation.intValue()); } - if (targetResolution != null) { - previewBuilder.setTargetResolution(CameraXProxy.sizeFromResolution(targetResolution)); + if (resolutionSelector != null) { + previewBuilder.setResolutionSelector(resolutionSelector); } + Preview preview = previewBuilder.build(); instanceManager.addDartCreatedInstance(preview, identifier); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java new file mode 100644 index 000000000000..0171cec3eb04 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java @@ -0,0 +1,85 @@ +// 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.resolutionselector.AspectRatioStrategy; +import androidx.camera.core.resolutionselector.ResolutionSelector; +import androidx.camera.core.resolutionselector.ResolutionStrategy; +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionSelectorHostApi; + +/** + * Host API implementation for {@link ResolutionSelector}. + * + *

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 ResolutionSelectorHostApiImpl implements ResolutionSelectorHostApi { + private final InstanceManager instanceManager; + private final ResolutionSelectorProxy proxy; + + /** Proxy for constructors and static method of {@link ResolutionSelector}. */ + @VisibleForTesting + public static class ResolutionSelectorProxy { + /** Creates an instance of {@link ResolutionSelector}. */ + @NonNull + public ResolutionSelector create( + @Nullable ResolutionStrategy resolutionStrategy, + @Nullable AspectRatioStrategy aspectRatioStrategy) { + final ResolutionSelector.Builder builder = new ResolutionSelector.Builder(); + if (resolutionStrategy != null) { + builder.setResolutionStrategy(resolutionStrategy); + } + if (aspectRatioStrategy != null) { + builder.setAspectRatioStrategy(aspectRatioStrategy); + } + return builder.build(); + } + } + + /** + * Constructs a {@link ResolutionSelectorHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + */ + public ResolutionSelectorHostApiImpl(@NonNull InstanceManager instanceManager) { + this(instanceManager, new ResolutionSelectorProxy()); + } + + /** + * Constructs a {@link ResolutionSelectorHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + * @param proxy proxy for constructors and static method of {@link ResolutionSelector} + */ + @VisibleForTesting + ResolutionSelectorHostApiImpl( + @NonNull InstanceManager instanceManager, @NonNull ResolutionSelectorProxy proxy) { + this.instanceManager = instanceManager; + this.proxy = proxy; + } + + /** + * Creates a {@link ResolutionSelector} instance with the {@link ResolutionStrategy} and {@link + * AspectRatio} that have the identifiers specified if provided. + */ + @Override + public void create( + @NonNull Long identifier, + @Nullable Long resolutionStrategyIdentifier, + @Nullable Long aspectRatioStrategyIdentifier) { + instanceManager.addDartCreatedInstance( + proxy.create( + resolutionStrategyIdentifier == null + ? null + : instanceManager.getInstance(resolutionStrategyIdentifier), + aspectRatioStrategyIdentifier == null + ? null + : instanceManager.getInstance(aspectRatioStrategyIdentifier)), + identifier); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java new file mode 100644 index 000000000000..b2c7bcbf2c78 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java @@ -0,0 +1,80 @@ +// 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; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; +import androidx.camera.core.resolutionselector.ResolutionStrategy; +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionStrategyHostApi; + +/** + * Host API implementation for {@link ResolutionStrategy}. + * + *

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 ResolutionStrategyHostApiImpl implements ResolutionStrategyHostApi { + private final InstanceManager instanceManager; + private final ResolutionStrategyProxy proxy; + + /** Proxy for constructors and static method of {@link ResolutionStrategy}. */ + @VisibleForTesting + public static class ResolutionStrategyProxy { + + /** Creates an instance of {@link ResolutionStrategy}. */ + @NonNull + public ResolutionStrategy create(@NonNull Size boundSize, @NonNull Long fallbackRule) { + return new ResolutionStrategy(boundSize, fallbackRule.intValue()); + } + } + + /** + * Constructs a {@link ResolutionStrategyHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + */ + public ResolutionStrategyHostApiImpl(@NonNull InstanceManager instanceManager) { + this(instanceManager, new ResolutionStrategyProxy()); + } + + /** + * Constructs a {@link ResolutionStrategyHostApiImpl}. + * + * @param instanceManager maintains instances stored to communicate with attached Dart objects + * @param proxy proxy for constructors and static method of {@link ResolutionStrategy} + */ + @VisibleForTesting + ResolutionStrategyHostApiImpl( + @NonNull InstanceManager instanceManager, @NonNull ResolutionStrategyProxy proxy) { + this.instanceManager = instanceManager; + this.proxy = proxy; + } + + /** + * Creates a {@link ResolutionStrategy} instance with the {@link + * GeneratedCameraXLibrary.ResolutionInfo} bound size and {@code fallbackRule} if specified. + */ + @Override + public void create( + @NonNull Long identifier, + @Nullable GeneratedCameraXLibrary.ResolutionInfo boundSize, + @Nullable Long fallbackRule) { + ResolutionStrategy resolutionStrategy; + if (boundSize == null && fallbackRule == null) { + resolutionStrategy = ResolutionStrategy.HIGHEST_AVAILABLE_STRATEGY; + } else if (boundSize == null) { + throw new IllegalArgumentException( + "A bound size must be specified if a fallback rule is specified as non-null to create a valid ResolutionStrategy."); + } else { + resolutionStrategy = + proxy.create( + new Size(boundSize.getWidth().intValue(), boundSize.getHeight().intValue()), + fallbackRule); + } + instanceManager.addDartCreatedInstance(resolutionStrategy, identifier); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java new file mode 100644 index 000000000000..5da0a371ffa9 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java @@ -0,0 +1,51 @@ +// 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +import androidx.camera.core.resolutionselector.AspectRatioStrategy; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +public class AspectRatioStrategyTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Mock public AspectRatioStrategy mockAspectRatioStrategy; + @Mock public AspectRatioStrategyHostApiImpl.AspectRatioStrategyProxy mockProxy; + + InstanceManager instanceManager; + + @Before + public void setUp() { + instanceManager = InstanceManager.create(identifier -> {}); + } + + @After + public void tearDown() { + instanceManager.stopFinalizationListener(); + } + + @Test + public void hostApiCreate() { + final Long preferredAspectRatio = 0L; + final Long fallbackRule = 1L; + + when(mockProxy.create(preferredAspectRatio, fallbackRule)).thenReturn(mockAspectRatioStrategy); + + final AspectRatioStrategyHostApiImpl hostApi = + new AspectRatioStrategyHostApiImpl(instanceManager, mockProxy); + + final long instanceIdentifier = 0; + hostApi.create(instanceIdentifier, preferredAspectRatio, fallbackRule); + + assertEquals(instanceManager.getInstance(instanceIdentifier), mockAspectRatioStrategy); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageAnalysisTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageAnalysisTest.java index 38f77761da99..b9a6d299ae30 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageAnalysisTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageAnalysisTest.java @@ -12,18 +12,16 @@ import static org.mockito.Mockito.when; import android.content.Context; -import android.util.Size; import androidx.camera.core.ImageAnalysis; +import androidx.camera.core.resolutionselector.ResolutionSelector; import androidx.test.core.app.ApplicationProvider; import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionInfo; import java.util.concurrent.Executor; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; @@ -55,27 +53,19 @@ public void hostApiCreate_createsExpectedImageAnalysisInstanceWithExpectedIdenti new ImageAnalysisHostApiImpl(mockBinaryMessenger, instanceManager); final CameraXProxy mockCameraXProxy = mock(CameraXProxy.class); final ImageAnalysis.Builder mockImageAnalysisBuilder = mock(ImageAnalysis.Builder.class); - final int targetResolutionWidth = 10; - final int targetResolutionHeight = 50; - final ResolutionInfo resolutionInfo = - new ResolutionInfo.Builder() - .setWidth(Long.valueOf(targetResolutionWidth)) - .setHeight(Long.valueOf(targetResolutionHeight)) - .build(); + final ResolutionSelector mockResolutionSelector = mock(ResolutionSelector.class); final long instanceIdentifier = 0; + final long mockResolutionSelectorId = 25; hostApi.cameraXProxy = mockCameraXProxy; - - final ArgumentCaptor sizeCaptor = ArgumentCaptor.forClass(Size.class); + instanceManager.addDartCreatedInstance(mockResolutionSelector, mockResolutionSelectorId); when(mockCameraXProxy.createImageAnalysisBuilder()).thenReturn(mockImageAnalysisBuilder); when(mockImageAnalysisBuilder.build()).thenReturn(mockImageAnalysis); - hostApi.create(instanceIdentifier, resolutionInfo); + hostApi.create(instanceIdentifier, mockResolutionSelectorId); - verify(mockImageAnalysisBuilder).setTargetResolution(sizeCaptor.capture()); - assertEquals(sizeCaptor.getValue().getWidth(), targetResolutionWidth); - assertEquals(sizeCaptor.getValue().getHeight(), targetResolutionHeight); + verify(mockImageAnalysisBuilder).setResolutionSelector(mockResolutionSelector); assertEquals(instanceManager.getInstance(instanceIdentifier), mockImageAnalysis); } diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageCaptureTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageCaptureTest.java index 881b6bea5a75..df6c8ee74b7f 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageCaptureTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ImageCaptureTest.java @@ -4,7 +4,6 @@ package io.flutter.plugins.camerax; -import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -15,9 +14,9 @@ import static org.mockito.Mockito.when; import android.content.Context; -import android.util.Size; import androidx.camera.core.ImageCapture; import androidx.camera.core.ImageCaptureException; +import androidx.camera.core.resolutionselector.ResolutionSelector; import io.flutter.plugin.common.BinaryMessenger; import java.io.File; import java.io.IOException; @@ -27,7 +26,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.junit.MockitoJUnit; @@ -66,26 +64,18 @@ public void create_createsImageCaptureWithCorrectConfiguration() { final ImageCapture.Builder mockImageCaptureBuilder = mock(ImageCapture.Builder.class); final Long imageCaptureIdentifier = 74L; final Long flashMode = Long.valueOf(ImageCapture.FLASH_MODE_ON); - final int targetResolutionWidth = 10; - final int targetResolutionHeight = 50; - final GeneratedCameraXLibrary.ResolutionInfo resolutionInfo = - new GeneratedCameraXLibrary.ResolutionInfo.Builder() - .setWidth(Long.valueOf(targetResolutionWidth)) - .setHeight(Long.valueOf(targetResolutionHeight)) - .build(); + final ResolutionSelector mockResolutionSelector = mock(ResolutionSelector.class); + final long mockResolutionSelectorId = 77; imageCaptureHostApiImpl.cameraXProxy = mockCameraXProxy; + testInstanceManager.addDartCreatedInstance(mockResolutionSelector, mockResolutionSelectorId); when(mockCameraXProxy.createImageCaptureBuilder()).thenReturn(mockImageCaptureBuilder); when(mockImageCaptureBuilder.build()).thenReturn(mockImageCapture); - final ArgumentCaptor sizeCaptor = ArgumentCaptor.forClass(Size.class); - - imageCaptureHostApiImpl.create(imageCaptureIdentifier, flashMode, resolutionInfo); + imageCaptureHostApiImpl.create(imageCaptureIdentifier, flashMode, mockResolutionSelectorId); verify(mockImageCaptureBuilder).setFlashMode(flashMode.intValue()); - verify(mockImageCaptureBuilder).setTargetResolution(sizeCaptor.capture()); - assertEquals(sizeCaptor.getValue().getWidth(), targetResolutionWidth); - assertEquals(sizeCaptor.getValue().getHeight(), targetResolutionHeight); + verify(mockImageCaptureBuilder).setResolutionSelector(mockResolutionSelector); verify(mockImageCaptureBuilder).build(); verify(testInstanceManager).addDartCreatedInstance(mockImageCapture, imageCaptureIdentifier); } diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java index 39b73abd7381..37a7c7704135 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/PreviewTest.java @@ -18,6 +18,7 @@ import android.view.Surface; import androidx.camera.core.Preview; import androidx.camera.core.SurfaceRequest; +import androidx.camera.core.resolutionselector.ResolutionSelector; import androidx.core.util.Consumer; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionInfo; @@ -63,27 +64,20 @@ public void create_createsPreviewWithCorrectConfiguration() { new PreviewHostApiImpl(mockBinaryMessenger, testInstanceManager, mockTextureRegistry); final Preview.Builder mockPreviewBuilder = mock(Preview.Builder.class); final int targetRotation = 90; - final int targetResolutionWidth = 10; - final int targetResolutionHeight = 50; final Long previewIdentifier = 3L; - final GeneratedCameraXLibrary.ResolutionInfo resolutionInfo = - new GeneratedCameraXLibrary.ResolutionInfo.Builder() - .setWidth(Long.valueOf(targetResolutionWidth)) - .setHeight(Long.valueOf(targetResolutionHeight)) - .build(); + final ResolutionSelector mockResolutionSelector = mock(ResolutionSelector.class); + final long mockResolutionSelectorId = 90; previewHostApi.cameraXProxy = mockCameraXProxy; + testInstanceManager.addDartCreatedInstance(mockResolutionSelector, mockResolutionSelectorId); when(mockCameraXProxy.createPreviewBuilder()).thenReturn(mockPreviewBuilder); when(mockPreviewBuilder.build()).thenReturn(mockPreview); - final ArgumentCaptor sizeCaptor = ArgumentCaptor.forClass(Size.class); - - previewHostApi.create(previewIdentifier, Long.valueOf(targetRotation), resolutionInfo); + previewHostApi.create( + previewIdentifier, Long.valueOf(targetRotation), mockResolutionSelectorId); verify(mockPreviewBuilder).setTargetRotation(targetRotation); - verify(mockPreviewBuilder).setTargetResolution(sizeCaptor.capture()); - assertEquals(sizeCaptor.getValue().getWidth(), targetResolutionWidth); - assertEquals(sizeCaptor.getValue().getHeight(), targetResolutionHeight); + verify(mockPreviewBuilder).setResolutionSelector(mockResolutionSelector); verify(mockPreviewBuilder).build(); verify(testInstanceManager).addDartCreatedInstance(mockPreview, previewIdentifier); } diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionSelectorTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionSelectorTest.java new file mode 100644 index 000000000000..f323e4706c9b --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionSelectorTest.java @@ -0,0 +1,59 @@ +// 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import androidx.camera.core.resolutionselector.AspectRatioStrategy; +import androidx.camera.core.resolutionselector.ResolutionSelector; +import androidx.camera.core.resolutionselector.ResolutionStrategy; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +public class ResolutionSelectorTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Mock public ResolutionSelector mockResolutionSelector; + @Mock public ResolutionSelectorHostApiImpl.ResolutionSelectorProxy mockProxy; + + InstanceManager instanceManager; + + @Before + public void setUp() { + instanceManager = InstanceManager.create(identifier -> {}); + } + + @After + public void tearDown() { + instanceManager.stopFinalizationListener(); + } + + @Test + public void hostApiCreate_createsExpectedResolutionSelectorInstance() { + final ResolutionStrategy mockResolutionStrategy = mock(ResolutionStrategy.class); + final long resolutionStrategyIdentifier = 14; + instanceManager.addDartCreatedInstance(mockResolutionStrategy, resolutionStrategyIdentifier); + + final AspectRatioStrategy mockAspectRatioStrategy = mock(AspectRatioStrategy.class); + final long aspectRatioStrategyIdentifier = 15; + instanceManager.addDartCreatedInstance(mockAspectRatioStrategy, aspectRatioStrategyIdentifier); + + when(mockProxy.create(mockResolutionStrategy, mockAspectRatioStrategy)) + .thenReturn(mockResolutionSelector); + final ResolutionSelectorHostApiImpl hostApi = + new ResolutionSelectorHostApiImpl(instanceManager, mockProxy); + + final long instanceIdentifier = 0; + hostApi.create(instanceIdentifier, resolutionStrategyIdentifier, aspectRatioStrategyIdentifier); + + assertEquals(instanceManager.getInstance(instanceIdentifier), mockResolutionSelector); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java new file mode 100644 index 000000000000..662ced95a267 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java @@ -0,0 +1,71 @@ +// 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import android.util.Size; +import androidx.camera.core.resolutionselector.ResolutionStrategy; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +public class ResolutionStrategyTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Mock public ResolutionStrategy mockResolutionStrategy; + @Mock public ResolutionStrategyHostApiImpl.ResolutionStrategyProxy mockProxy; + + InstanceManager instanceManager; + + @Before + public void setUp() { + instanceManager = InstanceManager.create(identifier -> {}); + } + + @After + public void tearDown() { + instanceManager.stopFinalizationListener(); + } + + @Test + public void hostApiCreate_createsExpectedResolutionStrategyInstanceWhenArgumentsValid() { + final GeneratedCameraXLibrary.ResolutionInfo boundSize = + new GeneratedCameraXLibrary.ResolutionInfo.Builder().setWidth(50L).setHeight(30L).build(); + + final Long fallbackRule = 0L; + + when(mockProxy.create(any(Size.class), eq(fallbackRule))).thenReturn(mockResolutionStrategy); + + final ResolutionStrategyHostApiImpl hostApi = + new ResolutionStrategyHostApiImpl(instanceManager, mockProxy); + + final long instanceIdentifier = 0; + hostApi.create(instanceIdentifier, boundSize, fallbackRule); + + assertEquals(instanceManager.getInstance(instanceIdentifier), mockResolutionStrategy); + } + + @Test + public void hostApiCreate_throwsAssertionErrorWhenArgumentsInvalid() { + final Long fallbackRule = 8L; + final long instanceIdentifier = 0; + + final ResolutionStrategyHostApiImpl hostApi = + new ResolutionStrategyHostApiImpl(instanceManager, mockProxy); + + // We expect an exception to be thrown in fallbackRule is specified but bound size is not. + assertThrows( + IllegalArgumentException.class, + () -> hostApi.create(instanceIdentifier, null, fallbackRule)); + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart index 9a58e6f4df86..7c5bf6b37e6e 100644 --- a/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart +++ b/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart @@ -116,10 +116,6 @@ class AndroidCameraCameraX extends CameraPlatform { @visibleForTesting CameraSelector? cameraSelector; - /// The resolution preset used to create a camera that should be used for - /// capturing still images and recording video. - ResolutionPreset? _resolutionPreset; - /// The controller we need to broadcast the different camera events. /// /// It is a `broadcast` because multiple controllers will connect to @@ -233,19 +229,17 @@ class AndroidCameraCameraX extends CameraPlatform { processCameraProvider ??= await ProcessCameraProvider.getInstance(); processCameraProvider!.unbindAll(); + // TODO(camsim99): Implement resolution configuration for UseCases + // configured here. https://github.com/flutter/flutter/issues/120462 + // Configure Preview instance. - _resolutionPreset = resolutionPreset; final int targetRotation = _getTargetRotation(cameraDescription.sensorOrientation); - final ResolutionInfo? previewTargetResolution = - _getTargetResolutionForPreview(resolutionPreset); - preview = createPreview(targetRotation, previewTargetResolution); + preview = createPreview(targetRotation); final int flutterSurfaceTextureId = await preview!.setSurfaceProvider(); // Configure ImageCapture instance. - final ResolutionInfo? imageCaptureTargetResolution = - _getTargetResolutionForImageCapture(_resolutionPreset); - imageCapture = createImageCapture(null, imageCaptureTargetResolution); + imageCapture = createImageCapture(null); // Configure VideoCapture and Recorder instances. // TODO(gmackall): Enable video capture resolution configuration in createRecorder(). @@ -642,7 +636,7 @@ class AndroidCameraCameraX extends CameraPlatform { // TODO(camsim99): Support resolution configuration. // Defaults to YUV_420_888 image format. - imageAnalysis ??= createImageAnalysis(null); + imageAnalysis ??= createImageAnalysis(); unawaited(imageAnalysis!.setAnalyzer(analyzer)); if (await processCameraProvider!.isBound(imageAnalysis!)) { @@ -780,23 +774,6 @@ class AndroidCameraCameraX extends CameraPlatform { } } - /// Returns [ResolutionInfo] that maps to the specified resolution preset for - /// a camera preview. - ResolutionInfo? _getTargetResolutionForPreview(ResolutionPreset? resolution) { - // TODO(camsim99): Implement resolution configuration. - // https://github.com/flutter/flutter/issues/120462 - return null; - } - - /// Returns [ResolutionInfo] that maps to the specified resolution preset for - /// image capture. - ResolutionInfo? _getTargetResolutionForImageCapture( - ResolutionPreset? resolution) { - // TODO(camsim99): Implement resolution configuration. - // https://github.com/flutter/flutter/issues/120462 - return null; - } - // Methods for calls that need to be tested: /// Requests camera permissions. @@ -829,18 +806,15 @@ class AndroidCameraCameraX extends CameraPlatform { /// Returns a [Preview] configured with the specified target rotation and /// resolution. @visibleForTesting - Preview createPreview(int targetRotation, ResolutionInfo? targetResolution) { - return Preview( - targetRotation: targetRotation, targetResolution: targetResolution); + Preview createPreview(int targetRotation) { + return Preview(targetRotation: targetRotation); } /// Returns an [ImageCapture] configured with specified flash mode and /// target resolution. @visibleForTesting - ImageCapture createImageCapture( - int? flashMode, ResolutionInfo? targetResolution) { - return ImageCapture( - targetFlashMode: flashMode, targetResolution: targetResolution); + ImageCapture createImageCapture(int? flashMode) { + return ImageCapture(targetFlashMode: flashMode); } /// Returns a [Recorder] for use in video capture. @@ -857,7 +831,7 @@ class AndroidCameraCameraX extends CameraPlatform { /// Returns an [ImageAnalysis] configured with specified target resolution. @visibleForTesting - ImageAnalysis createImageAnalysis(ResolutionInfo? targetResolution) { - return ImageAnalysis(targetResolution: targetResolution); + ImageAnalysis createImageAnalysis() { + return ImageAnalysis(); } } diff --git a/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart new file mode 100644 index 000000000000..78edb7433a90 --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart @@ -0,0 +1,136 @@ +// 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. + +import 'package:flutter/services.dart'; + +import 'camerax_library.g.dart'; +import 'instance_manager.dart'; +import 'java_object.dart'; + +/// The aspect ratio of a use case. +/// +/// Aspect ratio is the ratio of width to height. +/// +/// See https://developer.android.com/reference/androidx/camera/core/AspectRatio. +class AspectRatio { + AspectRatio._(); + + /// 4:3 standard aspect ratio. + /// + /// See https://developer.android.com/reference/androidx/camera/core/AspectRatio#RATIO_4_3(). + static const int ratio4To3 = 0; + + /// 16:9 standard aspect ratio. + /// + /// See https://developer.android.com/reference/androidx/camera/core/AspectRatio#RATIO_16_9(). + static const int ratio16To9 = 1; + + /// The aspect ratio representing no preference for aspect ratio. + /// + /// See https://developer.android.com/reference/androidx/camera/core/AspectRatio#RATIO_DEFAULT(). + static const int ratioDefault = -1; +} + +/// The aspect ratio strategy defines the sequence of aspect ratios that are +/// used to select the best size for a particular image. +/// +/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy. +class AspectRatioStrategy extends JavaObject { + /// Construct a [AspectRatioStrategy]. + AspectRatioStrategy({ + required this.preferredAspectRatio, + required this.fallbackRule, + super.binaryMessenger, + super.instanceManager, + }) : _api = _AspectRatioStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached() { + _api.createFromInstances(this, preferredAspectRatio, fallbackRule); + } + + /// Instantiates a [AspectRatioStrategy] without creating and attaching to an + /// instance of the associated native class. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an [InstanceManager]. + AspectRatioStrategy.detached({ + required this.preferredAspectRatio, + required this.fallbackRule, + super.binaryMessenger, + super.instanceManager, + }) : _api = _AspectRatioStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached(); + + /// CameraX doesn't fall back to select sizes of any other aspect ratio when + /// this fallback rule is used. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_NONE(). + static const int fallbackRuleNone = 0; + + /// CameraX automatically chooses the next best aspect ratio which contains + /// the closest field of view (FOV) of the camera sensor, from the remaining + /// options. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO(). + static const int fallbackRuleAuto = 1; + + final _AspectRatioStrategyHostApiImpl _api; + + /// The preferred aspect ratio captured by the camera. + final int preferredAspectRatio; + + /// The specified fallback rule for choosing the aspect ratio when the + /// preferred aspect ratio is not available. + final int fallbackRule; +} + +/// Host API implementation of [AspectRatioStrategy]. +class _AspectRatioStrategyHostApiImpl extends AspectRatioStrategyHostApi { + /// Constructs an [_AspectRatioStrategyHostApiImpl]. + /// + /// If [binaryMessenger] is null, the default [BinaryMessenger] will be used, + /// which routes to the host platform. + /// + /// An [instanceManager] is typically passed when a copy of an instance + /// contained by an [InstanceManager] is being created. If left null, it + /// will default to the global instance defined in [JavaObject]. + _AspectRatioStrategyHostApiImpl({ + this.binaryMessenger, + InstanceManager? instanceManager, + }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, + super(binaryMessenger: binaryMessenger); + + /// Receives binary data across the Flutter platform barrier. + final BinaryMessenger? binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + /// Creates a [AspectRatioStrategy] on the native side with the preferred + /// aspect ratio and fallback rule specified. + Future createFromInstances( + AspectRatioStrategy instance, + int preferredAspectRatio, + int fallbackRule, + ) { + return create( + instanceManager.addDartCreatedInstance( + instance, + onCopy: (AspectRatioStrategy original) => AspectRatioStrategy.detached( + preferredAspectRatio: original.preferredAspectRatio, + fallbackRule: original.fallbackRule, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), + ), + preferredAspectRatio, + fallbackRule, + ); + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart index 2a1b2813f1aa..2d1dccf971c2 100644 --- a/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/lib/src/camerax_library.g.dart @@ -22,6 +22,22 @@ enum CameraStateType { pendingOpen, } +/// The types (T) properly wrapped to be used as a LiveData. +/// +/// If you need to add another type to support a type S to use a LiveData in +/// this plugin, ensure the following is done on the Dart side: +/// +/// * In `../lib/src/live_data.dart`, add new cases for S in +/// `_LiveDataHostApiImpl#getValueFromInstances` to get the current value of +/// type S from a LiveData instance and in `LiveDataFlutterApiImpl#create` +/// to create the expected type of LiveData when requested. +/// +/// On the native side, ensure the following is done: +/// +/// * Update `LiveDataHostApiImpl#getValue` is updated to properly return +/// identifiers for instances of type S. +/// * Update `ObserverFlutterApiWrapper#onChanged` to properly handle receiving +/// calls with instances of type S if a LiveData instance is observed. enum LiveDataSupportedType { cameraState, zoomState, @@ -937,9 +953,6 @@ class _PreviewHostApiCodec extends StandardMessageCodec { if (value is ResolutionInfo) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is ResolutionInfo) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -950,8 +963,6 @@ class _PreviewHostApiCodec extends StandardMessageCodec { switch (type) { case 128: return ResolutionInfo.decode(readValue(buffer)!); - case 129: - return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -969,12 +980,12 @@ class PreviewHostApi { static const MessageCodec codec = _PreviewHostApiCodec(); Future create(int arg_identifier, int? arg_rotation, - ResolutionInfo? arg_targetResolution) async { + int? arg_resolutionSelectorId) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.PreviewHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_rotation, arg_targetResolution]) + final List? replyList = await channel.send( + [arg_identifier, arg_rotation, arg_resolutionSelectorId]) as List?; if (replyList == null) { throw PlatformException( @@ -1505,8 +1516,92 @@ abstract class RecordingFlutterApi { } } -class _ImageCaptureHostApiCodec extends StandardMessageCodec { - const _ImageCaptureHostApiCodec(); +class ImageCaptureHostApi { + /// Constructor for [ImageCaptureHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + ImageCaptureHostApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = StandardMessageCodec(); + + Future create(int arg_identifier, int? arg_flashMode, + int? arg_resolutionSelectorId) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ImageCaptureHostApi.create', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel.send( + [arg_identifier, arg_flashMode, arg_resolutionSelectorId]) + as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } + + Future setFlashMode(int arg_identifier, int arg_flashMode) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = await channel + .send([arg_identifier, arg_flashMode]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return; + } + } + + Future takePicture(int arg_identifier) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ImageCaptureHostApi.takePicture', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_identifier]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (replyList[0] as String?)!; + } + } +} + +class _ResolutionStrategyHostApiCodec extends StandardMessageCodec { + const _ResolutionStrategyHostApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is ResolutionInfo) { @@ -1528,23 +1623,23 @@ class _ImageCaptureHostApiCodec extends StandardMessageCodec { } } -class ImageCaptureHostApi { - /// Constructor for [ImageCaptureHostApi]. The [binaryMessenger] named argument is +class ResolutionStrategyHostApi { + /// Constructor for [ResolutionStrategyHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - ImageCaptureHostApi({BinaryMessenger? binaryMessenger}) + ResolutionStrategyHostApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; - static const MessageCodec codec = _ImageCaptureHostApiCodec(); + static const MessageCodec codec = _ResolutionStrategyHostApiCodec(); - Future create(int arg_identifier, int? arg_flashMode, - ResolutionInfo? arg_targetResolution) async { + Future create(int arg_identifier, ResolutionInfo? arg_boundSize, + int? arg_fallbackRule) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ImageCaptureHostApi.create', codec, + 'dev.flutter.pigeon.ResolutionStrategyHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send( - [arg_identifier, arg_flashMode, arg_targetResolution]) + final List? replyList = await channel + .send([arg_identifier, arg_boundSize, arg_fallbackRule]) as List?; if (replyList == null) { throw PlatformException( @@ -1561,13 +1656,28 @@ class ImageCaptureHostApi { return; } } +} - Future setFlashMode(int arg_identifier, int arg_flashMode) async { +class ResolutionSelectorHostApi { + /// Constructor for [ResolutionSelectorHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + ResolutionSelectorHostApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = StandardMessageCodec(); + + Future create(int arg_identifier, int? arg_resolutionStrategyIdentifier, + int? arg_aspectRatioStrategyIdentifier) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ImageCaptureHostApi.setFlashMode', codec, + 'dev.flutter.pigeon.ResolutionSelectorHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_flashMode]) as List?; + final List? replyList = await channel.send([ + arg_identifier, + arg_resolutionStrategyIdentifier, + arg_aspectRatioStrategyIdentifier + ]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1583,13 +1693,28 @@ class ImageCaptureHostApi { return; } } +} - Future takePicture(int arg_identifier) async { +class AspectRatioStrategyHostApi { + /// Constructor for [AspectRatioStrategyHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + AspectRatioStrategyHostApi({BinaryMessenger? binaryMessenger}) + : _binaryMessenger = binaryMessenger; + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = StandardMessageCodec(); + + Future create(int arg_identifier, int arg_preferredAspectRatio, + int arg_fallbackRule) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.ImageCaptureHostApi.takePicture', codec, + 'dev.flutter.pigeon.AspectRatioStrategyHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_identifier]) as List?; + final List? replyList = await channel.send([ + arg_identifier, + arg_preferredAspectRatio, + arg_fallbackRule + ]) as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', @@ -1601,13 +1726,8 @@ class ImageCaptureHostApi { message: replyList[1] as String?, details: replyList[2], ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); } else { - return (replyList[0] as String?)!; + return; } } } @@ -1767,29 +1887,6 @@ abstract class ZoomStateFlutterApi { } } -class _ImageAnalysisHostApiCodec extends StandardMessageCodec { - const _ImageAnalysisHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is ResolutionInfo) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return ResolutionInfo.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - class ImageAnalysisHostApi { /// Constructor for [ImageAnalysisHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default @@ -1798,16 +1895,15 @@ class ImageAnalysisHostApi { : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; - static const MessageCodec codec = _ImageAnalysisHostApiCodec(); + static const MessageCodec codec = StandardMessageCodec(); - Future create(int arg_identifier, - ResolutionInfo? arg_targetResolutionIdentifier) async { + Future create(int arg_identifier, int? arg_resolutionSelectorId) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.ImageAnalysisHostApi.create', codec, binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_targetResolutionIdentifier]) - as List?; + final List? replyList = + await channel.send([arg_identifier, arg_resolutionSelectorId]) + as List?; if (replyList == null) { throw PlatformException( code: 'channel-error', diff --git a/packages/camera/camera_android_camerax/lib/src/image_analysis.dart b/packages/camera/camera_android_camerax/lib/src/image_analysis.dart index 4d2a335a3c34..e28457c6d192 100644 --- a/packages/camera/camera_android_camerax/lib/src/image_analysis.dart +++ b/packages/camera/camera_android_camerax/lib/src/image_analysis.dart @@ -12,6 +12,7 @@ import 'android_camera_camerax_flutter_api_impls.dart'; import 'camerax_library.g.dart'; import 'instance_manager.dart'; import 'java_object.dart'; +import 'resolution_selector.dart'; import 'use_case.dart'; /// Use case for providing CPU accessible images for performing image analysis. @@ -23,13 +24,13 @@ class ImageAnalysis extends UseCase { ImageAnalysis( {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - this.targetResolution}) + this.resolutionSelector}) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager) { _api = _ImageAnalysisHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager); - _api.createfromInstances(this, targetResolution); + _api.createfromInstances(this, resolutionSelector); AndroidCameraXCameraFlutterApis.instance.ensureSetUp(); } @@ -37,7 +38,7 @@ class ImageAnalysis extends UseCase { ImageAnalysis.detached( {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, - this.targetResolution}) + this.resolutionSelector}) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager) { @@ -49,7 +50,10 @@ class ImageAnalysis extends UseCase { late final _ImageAnalysisHostApiImpl _api; /// Target resolution of the camera preview stream. - final ResolutionInfo? targetResolution; + /// + /// If not set, this [UseCase] will default to the behavior described in: + /// https://developer.android.com/reference/androidx/camera/core/ImageAnalysis.Builder#setResolutionSelector(androidx.camera.core.resolutionselector.ResolutionSelector). + final ResolutionSelector? resolutionSelector; /// Sets an [Analyzer] to receive and analyze images. Future setAnalyzer(Analyzer analyzer) => @@ -83,18 +87,20 @@ class _ImageAnalysisHostApiImpl extends ImageAnalysisHostApi { /// on the native side. Future createfromInstances( ImageAnalysis instance, - ResolutionInfo? targetResolution, + ResolutionSelector? resolutionSelector, ) { return create( instanceManager.addDartCreatedInstance( instance, onCopy: (ImageAnalysis original) => ImageAnalysis.detached( - targetResolution: original.targetResolution, + resolutionSelector: original.resolutionSelector, binaryMessenger: binaryMessenger, instanceManager: instanceManager, ), ), - targetResolution, + resolutionSelector == null + ? null + : instanceManager.getIdentifier(resolutionSelector), ); } diff --git a/packages/camera/camera_android_camerax/lib/src/image_capture.dart b/packages/camera/camera_android_camerax/lib/src/image_capture.dart index f7f45d15ffbb..76fd9c4ae5c0 100644 --- a/packages/camera/camera_android_camerax/lib/src/image_capture.dart +++ b/packages/camera/camera_android_camerax/lib/src/image_capture.dart @@ -8,6 +8,7 @@ import 'package:meta/meta.dart' show immutable; import 'camerax_library.g.dart'; import 'instance_manager.dart'; import 'java_object.dart'; +import 'resolution_selector.dart'; import 'use_case.dart'; /// Use case for picture taking. @@ -20,14 +21,14 @@ class ImageCapture extends UseCase { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, this.targetFlashMode, - this.targetResolution, + this.resolutionSelector, }) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ) { _api = ImageCaptureHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager); - _api.createFromInstance(this, targetFlashMode, targetResolution); + _api.createFromInstance(this, targetFlashMode, resolutionSelector); } /// Constructs a [ImageCapture] that is not automatically attached to a native object. @@ -35,7 +36,7 @@ class ImageCapture extends UseCase { BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, this.targetFlashMode, - this.targetResolution, + this.resolutionSelector, }) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, @@ -50,7 +51,10 @@ class ImageCapture extends UseCase { final int? targetFlashMode; /// Target resolution of the image output from taking a picture. - final ResolutionInfo? targetResolution; + /// + /// If not set, this [UseCase] will default to the behavior described in: + /// https://developer.android.com/reference/androidx/camera/core/ImageCapture.Builder#setResolutionSelector(androidx.camera.core.resolutionselector.ResolutionSelector). + final ResolutionSelector? resolutionSelector; /// Constant for automatic flash mode. /// @@ -121,16 +125,21 @@ class ImageCaptureHostApiImpl extends ImageCaptureHostApi { /// Creates an [ImageCapture] instance with the flash mode and target resolution /// if specified. void createFromInstance(ImageCapture instance, int? targetFlashMode, - ResolutionInfo? targetResolution) { + ResolutionSelector? resolutionSelector) { final int identifier = instanceManager.addDartCreatedInstance(instance, onCopy: (ImageCapture original) { return ImageCapture.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, targetFlashMode: original.targetFlashMode, - targetResolution: original.targetResolution); + resolutionSelector: original.resolutionSelector); }); - create(identifier, targetFlashMode, targetResolution); + create( + identifier, + targetFlashMode, + resolutionSelector == null + ? null + : instanceManager.getIdentifier(resolutionSelector)); } /// Sets the flash mode for the specified [ImageCapture] instance to take diff --git a/packages/camera/camera_android_camerax/lib/src/preview.dart b/packages/camera/camera_android_camerax/lib/src/preview.dart index a5307463a58c..20efe6505f0e 100644 --- a/packages/camera/camera_android_camerax/lib/src/preview.dart +++ b/packages/camera/camera_android_camerax/lib/src/preview.dart @@ -8,6 +8,7 @@ import 'package:meta/meta.dart' show immutable; import 'camerax_library.g.dart'; import 'instance_manager.dart'; import 'java_object.dart'; +import 'resolution_selector.dart'; import 'use_case.dart'; /// Use case that provides a camera preview stream for display. @@ -20,13 +21,13 @@ class Preview extends UseCase { {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, this.targetRotation, - this.targetResolution}) + this.resolutionSelector}) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager) { _api = PreviewHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager); - _api.createFromInstance(this, targetRotation, targetResolution); + _api.createFromInstance(this, targetRotation, resolutionSelector); } /// Constructs a [Preview] that is not automatically attached to a native object. @@ -34,7 +35,7 @@ class Preview extends UseCase { {BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, this.targetRotation, - this.targetResolution}) + this.resolutionSelector}) : super.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager) { @@ -48,7 +49,10 @@ class Preview extends UseCase { final int? targetRotation; /// Target resolution of the camera preview stream. - final ResolutionInfo? targetResolution; + /// + /// If not set, this [UseCase] will default to the behavior described in: + /// https://developer.android.com/reference/androidx/camera/core/Preview.Builder#setResolutionSelector(androidx.camera.core.resolutionselector.ResolutionSelector) + final ResolutionSelector? resolutionSelector; /// Sets the surface provider for the preview stream. /// @@ -92,17 +96,22 @@ class PreviewHostApiImpl extends PreviewHostApi { /// Creates a [Preview] with the target rotation and target resolution if /// specified. - void createFromInstance( - Preview instance, int? targetRotation, ResolutionInfo? targetResolution) { + void createFromInstance(Preview instance, int? targetRotation, + ResolutionSelector? resolutionSelector) { final int identifier = instanceManager.addDartCreatedInstance(instance, onCopy: (Preview original) { return Preview.detached( binaryMessenger: binaryMessenger, instanceManager: instanceManager, targetRotation: original.targetRotation, - targetResolution: original.targetResolution); + resolutionSelector: original.resolutionSelector); }); - create(identifier, targetRotation, targetResolution); + create( + identifier, + targetRotation, + resolutionSelector == null + ? null + : instanceManager.getIdentifier(resolutionSelector)); } /// Sets the surface provider of the specified [Preview] instance and returns diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart b/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart new file mode 100644 index 000000000000..5ec31ca95a34 --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart @@ -0,0 +1,106 @@ +// 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. + +import 'package:flutter/services.dart'; + +import 'aspect_ratio_strategy.dart'; +import 'camerax_library.g.dart'; +import 'instance_manager.dart'; +import 'java_object.dart'; +import 'resolution_strategy.dart'; + +/// A set of requirements and priorities used to select a resolution for a +/// UseCase. +/// +/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionSelector. +class ResolutionSelector extends JavaObject { + /// Construct a [ResolutionSelector]. + ResolutionSelector({ + this.resolutionStrategy, + this.aspectRatioStrategy, + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionSelectorHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached() { + _api.createFromInstances(this, resolutionStrategy, aspectRatioStrategy); + } + + /// Instantiates a [ResolutionSelector] without creating and attaching to an + /// instance of the associated native class. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an [InstanceManager]. + ResolutionSelector.detached({ + this.resolutionStrategy, + this.aspectRatioStrategy, + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionSelectorHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached(); + + final _ResolutionSelectorHostApiImpl _api; + + /// Determines how the UseCase will choose the resolution of the captured + /// image. + final ResolutionStrategy? resolutionStrategy; + + /// Determines how the UseCase will choose the aspect ratio of the captured + /// image. + final AspectRatioStrategy? aspectRatioStrategy; +} + +/// Host API implementation of [ResolutionSelector]. +class _ResolutionSelectorHostApiImpl extends ResolutionSelectorHostApi { + /// Constructs an [_ResolutionSelectorHostApiImpl]. + /// + /// If [binaryMessenger] is null, the default [BinaryMessenger] will be used, + /// which routes to the host platform. + /// + /// An [instanceManager] is typically passed when a copy of an instance + /// contained by an [InstanceManager] is being created. If left null, it + /// will default to the global instance defined in [JavaObject]. + _ResolutionSelectorHostApiImpl({ + this.binaryMessenger, + InstanceManager? instanceManager, + }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, + super(binaryMessenger: binaryMessenger); + + /// Receives binary data across the Flutter platform barrier. + final BinaryMessenger? binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + /// Creates a [ResolutionSelector] on the native side with the + /// [ResolutionStrategy] and [AspectRatioStrategy] if specified. + Future createFromInstances( + ResolutionSelector instance, + ResolutionStrategy? resolutionStrategy, + AspectRatioStrategy? aspectRatioStrategy, + ) { + return create( + instanceManager.addDartCreatedInstance( + instance, + onCopy: (ResolutionSelector original) => ResolutionSelector.detached( + resolutionStrategy: original.resolutionStrategy, + aspectRatioStrategy: original.aspectRatioStrategy, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), + ), + resolutionStrategy == null + ? null + : instanceManager.getIdentifier(resolutionStrategy)!, + aspectRatioStrategy == null + ? null + : instanceManager.getIdentifier(aspectRatioStrategy)!, + ); + } +} diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart new file mode 100644 index 000000000000..582ba2f3bb65 --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart @@ -0,0 +1,179 @@ +// 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. + +import 'package:flutter/services.dart'; + +import 'camerax_library.g.dart'; +import 'instance_manager.dart'; +import 'java_object.dart'; + +/// The resolution strategy defines the resolution selection sequence to select +/// the best size. +/// +/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy. +class ResolutionStrategy extends JavaObject { + /// Construct a [ResolutionStrategy]. + ResolutionStrategy({ + this.boundSize, + this.fallbackRule, + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached() { + if (boundSize == null && fallbackRule != null) { + throw ArgumentError( + 'fallbackRule cannot be specified with a null boundSize. If you wish to create the highest available resolution ResolutionStrategy, specify fallbackRule as null.'); + } + _api.createFromInstances(this, boundSize, fallbackRule); + } + + /// Instantiates a [ResolutionStrategy] without creating and attaching to an + /// instance of the associated native class. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an [InstanceManager]. + ResolutionStrategy.detached({ + this.boundSize, + this.fallbackRule, + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + super.detached() { + if (boundSize == null && fallbackRule != null) { + throw ArgumentError( + 'fallbackRule cannot be specified with a null boundSize. If you wish to create the highest available resolution ResolutionStrategy, specify fallbackRule as null.'); + } + } + + /// CameraX doesn't select an alternate size when the specified bound size is + /// unavailable. + /// + /// Applications will receive [PlatformException] when binding the [UseCase]s + /// with this fallback rule if the device doesn't support the specified bound + /// size. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_NONE(). + static const int fallbackRuleNone = 0; + + /// When the specified bound size is unavailable, CameraX falls back to select + /// the closest higher resolution size. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER(). + static const int fallbackRuleClosestHigherThenLower = 1; + + /// When the specified bound size is unavailable, CameraX falls back to the + /// closest higher resolution size. + /// + /// If CameraX still cannot find any available resolution, it will fallback to + /// select other lower resolutions. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_HIGHER(). + static const int fallbackRuleClosestHigher = 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. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER_THEN_HIGHER(). + static const int fallbackRuleClosestLowerThenHigher = 3; + + /// When the specified bound size is unavailable, CameraX falls back to the + /// closest lower resolution size. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER() + static const int fallbackRuleClosestLower = 4; + + /// Returns the resolution strategey that chooses the highest available + /// resolution. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#HIGHEST_AVAILABLE_STRATEGY(). + static ResolutionStrategy getHighestAvailableStrategy({ + BinaryMessenger? binaryMessenger, + InstanceManager? instanceManager, + bool detached = false, + }) { + if (detached) { + return ResolutionStrategy.detached( + binaryMessenger: binaryMessenger, instanceManager: instanceManager); + } + return ResolutionStrategy( + binaryMessenger: binaryMessenger, instanceManager: instanceManager); + } + + final _ResolutionStrategyHostApiImpl _api; + + /// The specified bound size for the desired resolution of the camera. + /// + /// If left null, [fallbackRule] must also be left null in order to create a + /// valid [ResolutionStrategy]. This will create the [ResolutionStrategy] + /// that chooses the highest available resolution, which can also be retrieved + /// by calling [getHighestAvailableStrategy]. + final Size? boundSize; + + /// The fallback rule for choosing an alternate size when the specified bound + /// size is unavailable. + /// + /// Must be left null if [boundSize] is specified as null. This will create + /// the [ResolutionStrategy] that chooses the highest available resolution, + /// which can also be retrieved by calling [getHighestAvailableStrategy]. + final int? fallbackRule; +} + +/// Host API implementation of [ResolutionStrategy]. +class _ResolutionStrategyHostApiImpl extends ResolutionStrategyHostApi { + /// Constructs an [_ResolutionStrategyHostApiImpl]. + /// + /// If [binaryMessenger] is null, the default [BinaryMessenger] will be used, + /// which routes to the host platform. + /// + /// An [instanceManager] is typically passed when a copy of an instance + /// contained by an [InstanceManager] is being created. If left null, it + /// will default to the global instance defined in [JavaObject]. + _ResolutionStrategyHostApiImpl({ + this.binaryMessenger, + InstanceManager? instanceManager, + }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, + super(binaryMessenger: binaryMessenger); + + /// Receives binary data across the Flutter platform barrier. + final BinaryMessenger? binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + final InstanceManager instanceManager; + + /// Creates a [ResolutionStrategy] on the native side with the bound [Size] + /// and fallback rule, if specified. + Future createFromInstances( + ResolutionStrategy instance, + Size? boundSize, + int? fallbackRule, + ) { + return create( + instanceManager.addDartCreatedInstance( + instance, + onCopy: (ResolutionStrategy original) => ResolutionStrategy.detached( + boundSize: original.boundSize, + fallbackRule: original.fallbackRule, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), + ), + boundSize == null + ? null + : ResolutionInfo( + width: boundSize.width.toInt(), + height: boundSize.height.toInt(), + ), + fallbackRule, + ); + } +} diff --git a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart index 601601dbf365..a22d7f6e3514 100644 --- a/packages/camera/camera_android_camerax/pigeons/camerax_library.dart +++ b/packages/camera/camera_android_camerax/pigeons/camerax_library.dart @@ -196,7 +196,7 @@ abstract class SystemServicesFlutterApi { @HostApi(dartHostTestHandler: 'TestPreviewHostApi') abstract class PreviewHostApi { - void create(int identifier, int? rotation, ResolutionInfo? targetResolution); + void create(int identifier, int? rotation, int? resolutionSelectorId); int setSurfaceProvider(int identifier); @@ -261,7 +261,7 @@ abstract class RecordingFlutterApi { @HostApi(dartHostTestHandler: 'TestImageCaptureHostApi') abstract class ImageCaptureHostApi { - void create(int identifier, int? flashMode, ResolutionInfo? targetResolution); + void create(int identifier, int? flashMode, int? resolutionSelectorId); void setFlashMode(int identifier, int flashMode); @@ -269,6 +269,25 @@ abstract class ImageCaptureHostApi { String takePicture(int identifier); } +@HostApi(dartHostTestHandler: 'TestResolutionStrategyHostApi') +abstract class ResolutionStrategyHostApi { + void create(int identifier, ResolutionInfo? boundSize, int? fallbackRule); +} + +@HostApi(dartHostTestHandler: 'TestResolutionSelectorHostApi') +abstract class ResolutionSelectorHostApi { + void create( + int identifier, + int? resolutionStrategyIdentifier, + int? aspectRatioStrategyIdentifier, + ); +} + +@HostApi(dartHostTestHandler: 'TestAspectRatioStrategyHostApi') +abstract class AspectRatioStrategyHostApi { + void create(int identifier, int preferredAspectRatio, int fallbackRule); +} + @FlutterApi() abstract class CameraStateFlutterApi { void create(int identifier, CameraStateTypeData type, int? errorIdentifier); @@ -289,7 +308,7 @@ abstract class ZoomStateFlutterApi { @HostApi(dartHostTestHandler: 'TestImageAnalysisHostApi') abstract class ImageAnalysisHostApi { - void create(int identifier, ResolutionInfo? targetResolutionIdentifier); + void create(int identifier, int? resolutionSelectorId); void setAnalyzer(int identifier, int analyzerIdentifier); diff --git a/packages/camera/camera_android_camerax/pubspec.yaml b/packages/camera/camera_android_camerax/pubspec.yaml index 0fea9fc68240..f8927d03112b 100644 --- a/packages/camera/camera_android_camerax/pubspec.yaml +++ b/packages/camera/camera_android_camerax/pubspec.yaml @@ -2,7 +2,7 @@ name: camera_android_camerax description: Android implementation of the camera plugin using the CameraX library. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.5.0+11 +version: 0.5.0+12 environment: sdk: ">=2.19.0 <4.0.0" diff --git a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart index bdebdce095d6..a0e60b60be88 100644 --- a/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart +++ b/packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart @@ -1127,13 +1127,12 @@ class FakeAndroidCameraCameraX extends AndroidCameraCameraX { } @override - Preview createPreview(int targetRotation, ResolutionInfo? targetResolution) { + Preview createPreview(int targetRotation) { return testPreview; } @override - ImageCapture createImageCapture( - int? flashMode, ResolutionInfo? targetResolution) { + ImageCapture createImageCapture(int? flashMode) { return testImageCapture; } @@ -1148,7 +1147,7 @@ class FakeAndroidCameraCameraX extends AndroidCameraCameraX { } @override - ImageAnalysis createImageAnalysis(ResolutionInfo? targetResolution) { + ImageAnalysis createImageAnalysis() { return mockImageAnalysis; } } diff --git a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart new file mode 100644 index 000000000000..7b6a05327fdf --- /dev/null +++ b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart @@ -0,0 +1,54 @@ +// 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. + +import 'package:camera_android_camerax/src/aspect_ratio_strategy.dart'; +import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'aspect_ratio_strategy_test.mocks.dart'; +import 'test_camerax_library.g.dart'; + +@GenerateMocks([ + TestAspectRatioStrategyHostApi, + TestInstanceManagerHostApi, +]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('AspectRatioStrategy', () { + tearDown(() { + TestAspectRatioStrategyHostApi.setup(null); + TestInstanceManagerHostApi.setup(null); + }); + + test('HostApi create', () { + final MockTestAspectRatioStrategyHostApi mockApi = + MockTestAspectRatioStrategyHostApi(); + TestAspectRatioStrategyHostApi.setup(mockApi); + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + const int preferredAspectRatio = 0; + + const int fallbackRule = 0; + + final AspectRatioStrategy instance = AspectRatioStrategy( + preferredAspectRatio: preferredAspectRatio, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ); + + verify(mockApi.create( + instanceManager.getIdentifier(instance), + preferredAspectRatio, + fallbackRule, + )); + }); + }); +} diff --git a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.mocks.dart b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.mocks.dart new file mode 100644 index 000000000000..28dda66896e0 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.mocks.dart @@ -0,0 +1,68 @@ +// Mocks generated by Mockito 5.4.1 from annotations +// in camera_android_camerax/test/aspect_ratio_strategy_test.dart. +// Do not manually edit this file. + +// @dart=2.19 + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:mockito/mockito.dart' as _i1; + +import 'test_camerax_library.g.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +/// A class which mocks [TestAspectRatioStrategyHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestAspectRatioStrategyHostApi extends _i1.Mock + implements _i2.TestAspectRatioStrategyHostApi { + MockTestAspectRatioStrategyHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void create( + int? identifier, + int? preferredAspectRatio, + int? fallbackRule, + ) => + super.noSuchMethod( + Invocation.method( + #create, + [ + identifier, + preferredAspectRatio, + fallbackRule, + ], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [TestInstanceManagerHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestInstanceManagerHostApi extends _i1.Mock + implements _i2.TestInstanceManagerHostApi { + MockTestInstanceManagerHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); +} diff --git a/packages/camera/camera_android_camerax/test/image_analysis_test.dart b/packages/camera/camera_android_camerax/test/image_analysis_test.dart index d9c657ea97af..80acd655982e 100644 --- a/packages/camera/camera_android_camerax/test/image_analysis_test.dart +++ b/packages/camera/camera_android_camerax/test/image_analysis_test.dart @@ -3,10 +3,10 @@ // found in the LICENSE file. import 'package:camera_android_camerax/src/analyzer.dart'; -import 'package:camera_android_camerax/src/camerax_library.g.dart'; import 'package:camera_android_camerax/src/image_analysis.dart'; import 'package:camera_android_camerax/src/image_proxy.dart'; import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:camera_android_camerax/src/resolution_selector.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -14,7 +14,11 @@ import 'package:mockito/mockito.dart'; import 'image_analysis_test.mocks.dart'; import 'test_camerax_library.g.dart'; -@GenerateMocks([TestImageAnalysisHostApi, TestInstanceManagerHostApi]) +@GenerateMocks([ + TestImageAnalysisHostApi, + TestInstanceManagerHostApi, + ResolutionSelector, +]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -22,13 +26,11 @@ void main() { TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); group('ImageAnalysis', () { - setUp(() {}); - tearDown(() { TestImageAnalysisHostApi.setup(null); }); - test('HostApi create', () { + test('create calls create on the Java side', () { final MockTestImageAnalysisHostApi mockApi = MockTestImageAnalysisHostApi(); TestImageAnalysisHostApi.setup(mockApi); @@ -37,25 +39,28 @@ void main() { onWeakReferenceRemoved: (_) {}, ); - const int targetResolutionWidth = 65; - const int targetResolutionHeight = 99; - final ResolutionInfo targetResolution = - ResolutionInfo(width: 65, height: 99); + final MockResolutionSelector mockResolutionSelector = + MockResolutionSelector(); + const int mockResolutionSelectorId = 24; + + instanceManager.addHostCreatedInstance( + mockResolutionSelector, mockResolutionSelectorId, + onCopy: (ResolutionSelector original) { + return MockResolutionSelector(); + }); + final ImageAnalysis instance = ImageAnalysis( - targetResolution: targetResolution, + resolutionSelector: mockResolutionSelector, instanceManager: instanceManager, ); - final VerificationResult createVerification = verify(mockApi.create( + verify(mockApi.create( argThat(equals(instanceManager.getIdentifier(instance))), - captureAny)); - final ResolutionInfo capturedResolutionInfo = - createVerification.captured.single as ResolutionInfo; - expect(capturedResolutionInfo.width, equals(targetResolutionWidth)); - expect(capturedResolutionInfo.height, equals(targetResolutionHeight)); + argThat(equals(mockResolutionSelectorId)))); }); - test('setAnalyzer', () async { + test('setAnalyzer makes call to set analyzer on ImageAnalysis instance', + () async { final MockTestImageAnalysisHostApi mockApi = MockTestImageAnalysisHostApi(); TestImageAnalysisHostApi.setup(mockApi); @@ -65,7 +70,7 @@ void main() { ); final ImageAnalysis instance = ImageAnalysis.detached( - targetResolution: ResolutionInfo(width: 75, height: 98), + resolutionSelector: MockResolutionSelector(), instanceManager: instanceManager, ); const int instanceIdentifier = 0; @@ -73,7 +78,7 @@ void main() { instance, instanceIdentifier, onCopy: (ImageAnalysis original) => ImageAnalysis.detached( - targetResolution: original.targetResolution, + resolutionSelector: original.resolutionSelector, instanceManager: instanceManager, ), ); @@ -102,7 +107,8 @@ void main() { )); }); - test('clearAnalyzer', () async { + test('clearAnalyzer makes call to clear analyzer on ImageAnalysis instance', + () async { final MockTestImageAnalysisHostApi mockApi = MockTestImageAnalysisHostApi(); TestImageAnalysisHostApi.setup(mockApi); @@ -112,7 +118,7 @@ void main() { ); final ImageAnalysis instance = ImageAnalysis.detached( - targetResolution: ResolutionInfo(width: 75, height: 98), + resolutionSelector: MockResolutionSelector(), instanceManager: instanceManager, ); const int instanceIdentifier = 0; @@ -120,7 +126,7 @@ void main() { instance, instanceIdentifier, onCopy: (ImageAnalysis original) => ImageAnalysis.detached( - targetResolution: original.targetResolution, + resolutionSelector: original.resolutionSelector, instanceManager: instanceManager, ), ); diff --git a/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart b/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart index cbece720c1c2..dadab7284b3d 100644 --- a/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart @@ -5,7 +5,7 @@ // @dart=2.19 // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i3; +import 'package:camera_android_camerax/src/resolution_selector.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; import 'test_camerax_library.g.dart' as _i2; @@ -33,14 +33,14 @@ class MockTestImageAnalysisHostApi extends _i1.Mock @override void create( int? identifier, - _i3.ResolutionInfo? targetResolutionIdentifier, + int? resolutionSelectorId, ) => super.noSuchMethod( Invocation.method( #create, [ identifier, - targetResolutionIdentifier, + resolutionSelectorId, ], ), returnValueForMissingStub: null, @@ -88,3 +88,13 @@ class MockTestInstanceManagerHostApi extends _i1.Mock returnValueForMissingStub: null, ); } + +/// A class which mocks [ResolutionSelector]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResolutionSelector extends _i1.Mock + implements _i3.ResolutionSelector { + MockResolutionSelector() { + _i1.throwOnMissingStub(this); + } +} diff --git a/packages/camera/camera_android_camerax/test/image_capture_test.dart b/packages/camera/camera_android_camerax/test/image_capture_test.dart index 21c071965dc4..c50314ed3cb3 100644 --- a/packages/camera/camera_android_camerax/test/image_capture_test.dart +++ b/packages/camera/camera_android_camerax/test/image_capture_test.dart @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:camera_android_camerax/src/camerax_library.g.dart'; import 'package:camera_android_camerax/src/image_capture.dart'; import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:camera_android_camerax/src/resolution_selector.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -12,7 +12,11 @@ import 'package:mockito/mockito.dart'; import 'image_capture_test.mocks.dart'; import 'test_camerax_library.g.dart'; -@GenerateMocks([TestImageCaptureHostApi, TestInstanceManagerHostApi]) +@GenerateMocks([ + TestImageCaptureHostApi, + TestInstanceManagerHostApi, + ResolutionSelector +]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -32,11 +36,11 @@ void main() { ImageCapture.detached( instanceManager: instanceManager, targetFlashMode: ImageCapture.flashModeOn, - targetResolution: ResolutionInfo(width: 50, height: 10), + resolutionSelector: MockResolutionSelector(), ); verifyNever(mockApi.create(argThat(isA()), argThat(isA()), - argThat(isA()))); + argThat(isA()))); }); test('create calls create on the Java side', () async { @@ -47,21 +51,26 @@ void main() { onWeakReferenceRemoved: (_) {}, ); const int targetFlashMode = ImageCapture.flashModeAuto; - const int targetResolutionWidth = 10; - const int targetResolutionHeight = 50; + final MockResolutionSelector mockResolutionSelector = + MockResolutionSelector(); + const int mockResolutionSelectorId = 24; + + instanceManager.addHostCreatedInstance( + mockResolutionSelector, mockResolutionSelectorId, + onCopy: (ResolutionSelector original) { + return MockResolutionSelector(); + }); + ImageCapture( instanceManager: instanceManager, targetFlashMode: targetFlashMode, - targetResolution: ResolutionInfo( - width: targetResolutionWidth, height: targetResolutionHeight), + resolutionSelector: mockResolutionSelector, ); - final VerificationResult createVerification = verify(mockApi.create( - argThat(isA()), argThat(equals(targetFlashMode)), captureAny)); - final ResolutionInfo capturedResolutionInfo = - createVerification.captured.single as ResolutionInfo; - expect(capturedResolutionInfo.width, equals(targetResolutionWidth)); - expect(capturedResolutionInfo.height, equals(targetResolutionHeight)); + verify(mockApi.create( + argThat(isA()), + argThat(equals(targetFlashMode)), + argThat(equals(mockResolutionSelectorId)))); }); test('setFlashMode makes call to set flash mode for ImageCapture instance', diff --git a/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart b/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart index 1b9e1e777e29..c24a363daf27 100644 --- a/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart @@ -5,9 +5,9 @@ // @dart=2.19 // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; +import 'dart:async' as _i3; -import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i3; +import 'package:camera_android_camerax/src/resolution_selector.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; import 'test_camerax_library.g.dart' as _i2; @@ -36,7 +36,7 @@ class MockTestImageCaptureHostApi extends _i1.Mock void create( int? identifier, int? flashMode, - _i3.ResolutionInfo? targetResolution, + int? resolutionSelectorId, ) => super.noSuchMethod( Invocation.method( @@ -44,7 +44,7 @@ class MockTestImageCaptureHostApi extends _i1.Mock [ identifier, flashMode, - targetResolution, + resolutionSelectorId, ], ), returnValueForMissingStub: null, @@ -65,13 +65,13 @@ class MockTestImageCaptureHostApi extends _i1.Mock returnValueForMissingStub: null, ); @override - _i4.Future takePicture(int? identifier) => (super.noSuchMethod( + _i3.Future takePicture(int? identifier) => (super.noSuchMethod( Invocation.method( #takePicture, [identifier], ), - returnValue: _i4.Future.value(''), - ) as _i4.Future); + returnValue: _i3.Future.value(''), + ) as _i3.Future); } /// A class which mocks [TestInstanceManagerHostApi]. @@ -92,3 +92,13 @@ class MockTestInstanceManagerHostApi extends _i1.Mock returnValueForMissingStub: null, ); } + +/// A class which mocks [ResolutionSelector]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResolutionSelector extends _i1.Mock + implements _i4.ResolutionSelector { + MockResolutionSelector() { + _i1.throwOnMissingStub(this); + } +} diff --git a/packages/camera/camera_android_camerax/test/preview_test.dart b/packages/camera/camera_android_camerax/test/preview_test.dart index 6eacd42b5caf..29f862cda4c7 100644 --- a/packages/camera/camera_android_camerax/test/preview_test.dart +++ b/packages/camera/camera_android_camerax/test/preview_test.dart @@ -5,6 +5,7 @@ import 'package:camera_android_camerax/src/camerax_library.g.dart'; import 'package:camera_android_camerax/src/instance_manager.dart'; import 'package:camera_android_camerax/src/preview.dart'; +import 'package:camera_android_camerax/src/resolution_selector.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; @@ -12,7 +13,8 @@ import 'package:mockito/mockito.dart'; import 'preview_test.mocks.dart'; import 'test_camerax_library.g.dart'; -@GenerateMocks([TestInstanceManagerHostApi, TestPreviewHostApi]) +@GenerateMocks( + [TestInstanceManagerHostApi, TestPreviewHostApi, ResolutionSelector]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -32,11 +34,11 @@ void main() { Preview.detached( instanceManager: instanceManager, targetRotation: 90, - targetResolution: ResolutionInfo(width: 50, height: 10), + resolutionSelector: MockResolutionSelector(), ); verifyNever(mockApi.create(argThat(isA()), argThat(isA()), - argThat(isA()))); + argThat(isA()))); }); test('create calls create on the Java side', () async { @@ -47,21 +49,26 @@ void main() { onWeakReferenceRemoved: (_) {}, ); const int targetRotation = 90; - const int targetResolutionWidth = 10; - const int targetResolutionHeight = 50; + final MockResolutionSelector mockResolutionSelector = + MockResolutionSelector(); + const int mockResolutionSelectorId = 24; + + instanceManager.addHostCreatedInstance( + mockResolutionSelector, mockResolutionSelectorId, + onCopy: (ResolutionSelector original) { + return MockResolutionSelector(); + }); + Preview( instanceManager: instanceManager, targetRotation: targetRotation, - targetResolution: ResolutionInfo( - width: targetResolutionWidth, height: targetResolutionHeight), + resolutionSelector: mockResolutionSelector, ); - final VerificationResult createVerification = verify(mockApi.create( - argThat(isA()), argThat(equals(targetRotation)), captureAny)); - final ResolutionInfo capturedResolutionInfo = - createVerification.captured.single as ResolutionInfo; - expect(capturedResolutionInfo.width, equals(targetResolutionWidth)); - expect(capturedResolutionInfo.height, equals(targetResolutionHeight)); + verify(mockApi.create( + argThat(isA()), + argThat(equals(targetRotation)), + argThat(equals(mockResolutionSelectorId)))); }); test( diff --git a/packages/camera/camera_android_camerax/test/preview_test.mocks.dart b/packages/camera/camera_android_camerax/test/preview_test.mocks.dart index ae3783641cec..4e0dcb9cf4e1 100644 --- a/packages/camera/camera_android_camerax/test/preview_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/preview_test.mocks.dart @@ -6,6 +6,7 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i2; +import 'package:camera_android_camerax/src/resolution_selector.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; import 'test_camerax_library.g.dart' as _i3; @@ -64,7 +65,7 @@ class MockTestPreviewHostApi extends _i1.Mock void create( int? identifier, int? rotation, - _i2.ResolutionInfo? targetResolution, + int? resolutionSelectorId, ) => super.noSuchMethod( Invocation.method( @@ -72,7 +73,7 @@ class MockTestPreviewHostApi extends _i1.Mock [ identifier, rotation, - targetResolution, + resolutionSelectorId, ], ), returnValueForMissingStub: null, @@ -108,3 +109,13 @@ class MockTestPreviewHostApi extends _i1.Mock ), ) as _i2.ResolutionInfo); } + +/// A class which mocks [ResolutionSelector]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResolutionSelector extends _i1.Mock + implements _i4.ResolutionSelector { + MockResolutionSelector() { + _i1.throwOnMissingStub(this); + } +} diff --git a/packages/camera/camera_android_camerax/test/resolution_selector_test.dart b/packages/camera/camera_android_camerax/test/resolution_selector_test.dart new file mode 100644 index 000000000000..89e5dc0d65e5 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/resolution_selector_test.dart @@ -0,0 +1,87 @@ +// 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. + +import 'dart:ui'; + +import 'package:camera_android_camerax/src/aspect_ratio_strategy.dart'; +import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:camera_android_camerax/src/resolution_selector.dart'; +import 'package:camera_android_camerax/src/resolution_strategy.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'resolution_selector_test.mocks.dart'; +import 'test_camerax_library.g.dart'; + +@GenerateMocks([ + TestResolutionSelectorHostApi, + TestInstanceManagerHostApi, +]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('ResolutionSelector', () { + tearDown(() { + TestResolutionSelectorHostApi.setup(null); + TestInstanceManagerHostApi.setup(null); + }); + + test('HostApi create creates expected ResolutionSelector instance', () { + final MockTestResolutionSelectorHostApi mockApi = + MockTestResolutionSelectorHostApi(); + TestResolutionSelectorHostApi.setup(mockApi); + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + final ResolutionStrategy resolutionStrategy = ResolutionStrategy.detached( + boundSize: const Size(50, 30), + fallbackRule: ResolutionStrategy.fallbackRuleClosestLower, + instanceManager: instanceManager, + ); + const int resolutionStrategyIdentifier = 14; + instanceManager.addHostCreatedInstance( + resolutionStrategy, + resolutionStrategyIdentifier, + onCopy: (ResolutionStrategy original) => ResolutionStrategy.detached( + boundSize: original.boundSize, + fallbackRule: original.fallbackRule, + instanceManager: instanceManager, + ), + ); + + final AspectRatioStrategy aspectRatioStrategy = + AspectRatioStrategy.detached( + preferredAspectRatio: AspectRatio.ratio4To3, + fallbackRule: AspectRatioStrategy.fallbackRuleAuto, + instanceManager: instanceManager, + ); + const int aspectRatioStrategyIdentifier = 15; + instanceManager.addHostCreatedInstance( + aspectRatioStrategy, + aspectRatioStrategyIdentifier, + onCopy: (AspectRatioStrategy original) => AspectRatioStrategy.detached( + preferredAspectRatio: original.preferredAspectRatio, + fallbackRule: original.fallbackRule, + instanceManager: instanceManager, + ), + ); + + final ResolutionSelector instance = ResolutionSelector( + resolutionStrategy: resolutionStrategy, + aspectRatioStrategy: aspectRatioStrategy, + instanceManager: instanceManager, + ); + + verify(mockApi.create( + instanceManager.getIdentifier(instance), + resolutionStrategyIdentifier, + aspectRatioStrategyIdentifier, + )); + }); + }); +} diff --git a/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart b/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart new file mode 100644 index 000000000000..4692bfc92320 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart @@ -0,0 +1,68 @@ +// Mocks generated by Mockito 5.4.1 from annotations +// in camera_android_camerax/test/resolution_selector_test.dart. +// Do not manually edit this file. + +// @dart=2.19 + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:mockito/mockito.dart' as _i1; + +import 'test_camerax_library.g.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +/// A class which mocks [TestResolutionSelectorHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestResolutionSelectorHostApi extends _i1.Mock + implements _i2.TestResolutionSelectorHostApi { + MockTestResolutionSelectorHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void create( + int? identifier, + int? resolutionStrategyIdentifier, + int? aspectRatioStrategyIdentifier, + ) => + super.noSuchMethod( + Invocation.method( + #create, + [ + identifier, + resolutionStrategyIdentifier, + aspectRatioStrategyIdentifier, + ], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [TestInstanceManagerHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestInstanceManagerHostApi extends _i1.Mock + implements _i2.TestInstanceManagerHostApi { + MockTestInstanceManagerHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); +} diff --git a/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart b/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart new file mode 100644 index 000000000000..83c8151d8df2 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart @@ -0,0 +1,104 @@ +// 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. + +import 'dart:ui'; + +import 'package:camera_android_camerax/src/camerax_library.g.dart'; +import 'package:camera_android_camerax/src/instance_manager.dart'; +import 'package:camera_android_camerax/src/resolution_strategy.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import 'resolution_strategy_test.mocks.dart'; +import 'test_camerax_library.g.dart'; + +@GenerateMocks([ + TestResolutionStrategyHostApi, + TestInstanceManagerHostApi, +]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('ResolutionStrategy', () { + tearDown(() { + TestResolutionStrategyHostApi.setup(null); + TestInstanceManagerHostApi.setup(null); + }); + + test( + 'ResolutionStrategy constructor detects valid boundSize and fallbackRule combinations', + () { + final MockTestResolutionStrategyHostApi mockApi = + MockTestResolutionStrategyHostApi(); + TestResolutionStrategyHostApi.setup(mockApi); + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + // Expect error if boundSize is null, but fallbackRule is not. + Size? boundSize; + int? fallbackRule = 5; + expect( + () => ResolutionStrategy( + boundSize: boundSize, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ), + throwsArgumentError); + + // Expect no error if boundSize is non-null, but fallbackRule is not. + boundSize = const Size(3, 5); + fallbackRule = null; + expect( + () => ResolutionStrategy( + boundSize: boundSize, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ), + returnsNormally); + + // Expect no error if boundSize and fallbackRule are both null. + boundSize = null; + fallbackRule = null; + expect( + () => ResolutionStrategy( + boundSize: boundSize, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ), + returnsNormally); + }); + + test('HostApi create creates expected ResolutionStrategy', () { + final MockTestResolutionStrategyHostApi mockApi = + MockTestResolutionStrategyHostApi(); + TestResolutionStrategyHostApi.setup(mockApi); + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + const Size boundSize = Size(50, 30); + const int fallbackRule = 0; + + final ResolutionStrategy instance = ResolutionStrategy( + boundSize: boundSize, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ); + + verify(mockApi.create( + instanceManager.getIdentifier(instance), + argThat(isA() + .having((ResolutionInfo size) => size.width, 'width', 50) + .having((ResolutionInfo size) => size.height, 'height', 30)), + fallbackRule, + )); + }); + }); +} diff --git a/packages/camera/camera_android_camerax/test/resolution_strategy_test.mocks.dart b/packages/camera/camera_android_camerax/test/resolution_strategy_test.mocks.dart new file mode 100644 index 000000000000..1a667389bac0 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/resolution_strategy_test.mocks.dart @@ -0,0 +1,69 @@ +// Mocks generated by Mockito 5.4.1 from annotations +// in camera_android_camerax/test/resolution_strategy_test.dart. +// Do not manually edit this file. + +// @dart=2.19 + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:camera_android_camerax/src/camerax_library.g.dart' as _i3; +import 'package:mockito/mockito.dart' as _i1; + +import 'test_camerax_library.g.dart' as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +/// A class which mocks [TestResolutionStrategyHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestResolutionStrategyHostApi extends _i1.Mock + implements _i2.TestResolutionStrategyHostApi { + MockTestResolutionStrategyHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void create( + int? identifier, + _i3.ResolutionInfo? boundSize, + int? fallbackRule, + ) => + super.noSuchMethod( + Invocation.method( + #create, + [ + identifier, + boundSize, + fallbackRule, + ], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [TestInstanceManagerHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestInstanceManagerHostApi extends _i1.Mock + implements _i2.TestInstanceManagerHostApi { + MockTestInstanceManagerHostApi() { + _i1.throwOnMissingStub(this); + } + + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); +} diff --git a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart index 2c4afd19b26b..6a80cf0541fb 100644 --- a/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart +++ b/packages/camera/camera_android_camerax/test/test_camerax_library.g.dart @@ -597,9 +597,6 @@ class _TestPreviewHostApiCodec extends StandardMessageCodec { if (value is ResolutionInfo) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is ResolutionInfo) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -610,8 +607,6 @@ class _TestPreviewHostApiCodec extends StandardMessageCodec { switch (type) { case 128: return ResolutionInfo.decode(readValue(buffer)!); - case 129: - return ResolutionInfo.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -623,7 +618,7 @@ abstract class TestPreviewHostApi { TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestPreviewHostApiCodec(); - void create(int identifier, int? rotation, ResolutionInfo? targetResolution); + void create(int identifier, int? rotation, int? resolutionSelectorId); int setSurfaceProvider(int identifier); @@ -651,9 +646,8 @@ abstract class TestPreviewHostApi { assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.PreviewHostApi.create was null, expected non-null int.'); final int? arg_rotation = (args[1] as int?); - final ResolutionInfo? arg_targetResolution = - (args[2] as ResolutionInfo?); - api.create(arg_identifier!, arg_rotation, arg_targetResolution); + final int? arg_resolutionSelectorId = (args[2] as int?); + api.create(arg_identifier!, arg_rotation, arg_resolutionSelectorId); return []; }); } @@ -1033,35 +1027,12 @@ abstract class TestRecordingHostApi { } } -class _TestImageCaptureHostApiCodec extends StandardMessageCodec { - const _TestImageCaptureHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is ResolutionInfo) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return ResolutionInfo.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - abstract class TestImageCaptureHostApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestImageCaptureHostApiCodec(); + static const MessageCodec codec = StandardMessageCodec(); - void create(int identifier, int? flashMode, ResolutionInfo? targetResolution); + void create(int identifier, int? flashMode, int? resolutionSelectorId); void setFlashMode(int identifier, int flashMode); @@ -1087,9 +1058,8 @@ abstract class TestImageCaptureHostApi { assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ImageCaptureHostApi.create was null, expected non-null int.'); final int? arg_flashMode = (args[1] as int?); - final ResolutionInfo? arg_targetResolution = - (args[2] as ResolutionInfo?); - api.create(arg_identifier!, arg_flashMode, arg_targetResolution); + final int? arg_resolutionSelectorId = (args[2] as int?); + api.create(arg_identifier!, arg_flashMode, arg_resolutionSelectorId); return []; }); } @@ -1144,8 +1114,8 @@ abstract class TestImageCaptureHostApi { } } -class _TestImageAnalysisHostApiCodec extends StandardMessageCodec { - const _TestImageAnalysisHostApiCodec(); +class _TestResolutionStrategyHostApiCodec extends StandardMessageCodec { + const _TestResolutionStrategyHostApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is ResolutionInfo) { @@ -1167,12 +1137,128 @@ class _TestImageAnalysisHostApiCodec extends StandardMessageCodec { } } +abstract class TestResolutionStrategyHostApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = + _TestResolutionStrategyHostApiCodec(); + + void create(int identifier, ResolutionInfo? boundSize, int? fallbackRule); + + static void setup(TestResolutionStrategyHostApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ResolutionStrategyHostApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.ResolutionStrategyHostApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.ResolutionStrategyHostApi.create was null, expected non-null int.'); + final ResolutionInfo? arg_boundSize = (args[1] as ResolutionInfo?); + final int? arg_fallbackRule = (args[2] as int?); + api.create(arg_identifier!, arg_boundSize, arg_fallbackRule); + return []; + }); + } + } + } +} + +abstract class TestResolutionSelectorHostApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = StandardMessageCodec(); + + void create(int identifier, int? resolutionStrategyIdentifier, + int? aspectRatioStrategyIdentifier); + + static void setup(TestResolutionSelectorHostApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.ResolutionSelectorHostApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.ResolutionSelectorHostApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.ResolutionSelectorHostApi.create was null, expected non-null int.'); + final int? arg_resolutionStrategyIdentifier = (args[1] as int?); + final int? arg_aspectRatioStrategyIdentifier = (args[2] as int?); + api.create(arg_identifier!, arg_resolutionStrategyIdentifier, + arg_aspectRatioStrategyIdentifier); + return []; + }); + } + } + } +} + +abstract class TestAspectRatioStrategyHostApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; + static const MessageCodec codec = StandardMessageCodec(); + + void create(int identifier, int preferredAspectRatio, int fallbackRule); + + static void setup(TestAspectRatioStrategyHostApi? api, + {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.AspectRatioStrategyHostApi.create', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); + } else { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.AspectRatioStrategyHostApi.create was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.AspectRatioStrategyHostApi.create was null, expected non-null int.'); + final int? arg_preferredAspectRatio = (args[1] as int?); + assert(arg_preferredAspectRatio != null, + 'Argument for dev.flutter.pigeon.AspectRatioStrategyHostApi.create was null, expected non-null int.'); + final int? arg_fallbackRule = (args[2] as int?); + assert(arg_fallbackRule != null, + 'Argument for dev.flutter.pigeon.AspectRatioStrategyHostApi.create was null, expected non-null int.'); + api.create( + arg_identifier!, arg_preferredAspectRatio!, arg_fallbackRule!); + return []; + }); + } + } + } +} + abstract class TestImageAnalysisHostApi { static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestImageAnalysisHostApiCodec(); + static const MessageCodec codec = StandardMessageCodec(); - void create(int identifier, ResolutionInfo? targetResolutionIdentifier); + void create(int identifier, int? resolutionSelectorId); void setAnalyzer(int identifier, int analyzerIdentifier); @@ -1197,9 +1283,8 @@ abstract class TestImageAnalysisHostApi { final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, 'Argument for dev.flutter.pigeon.ImageAnalysisHostApi.create was null, expected non-null int.'); - final ResolutionInfo? arg_targetResolutionIdentifier = - (args[1] as ResolutionInfo?); - api.create(arg_identifier!, arg_targetResolutionIdentifier); + final int? arg_resolutionSelectorId = (args[1] as int?); + api.create(arg_identifier!, arg_resolutionSelectorId); return []; }); } From 3cd06e8840f99c5a55eb235cd6fd22f9832f1f33 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 19 Jul 2023 10:19:19 -0700 Subject: [PATCH 04/10] Modify null check to fix integration test --- .../io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java | 4 ++-- .../io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java | 4 ++-- .../java/io/flutter/plugins/camerax/PreviewHostApiImpl.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java index 62fd147d0aa9..430635f76898 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java @@ -40,9 +40,9 @@ public void setContext(@NonNull Context context) { @Override public void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId) { ImageAnalysis.Builder imageAnalysisBuilder = cameraXProxy.createImageAnalysisBuilder(); - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); - if (resolutionSelector != null) { + if (resolutionSelectorId != null) { + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); imageAnalysisBuilder.setResolutionSelector(resolutionSelector); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java index bc4720608af7..e05fc9fa9cc1 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java @@ -55,13 +55,13 @@ public void setContext(@NonNull Context context) { public void create( @NonNull Long identifier, @Nullable Long flashMode, @Nullable Long resolutionSelectorId) { ImageCapture.Builder imageCaptureBuilder = cameraXProxy.createImageCaptureBuilder(); - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); if (flashMode != null) { // This sets the requested flash mode, but may fail silently. imageCaptureBuilder.setFlashMode(flashMode.intValue()); } - if (resolutionSelector != null) { + if (resolutionSelectorId != null) { + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); imageCaptureBuilder.setResolutionSelector(resolutionSelector); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java index 70f01cf260d0..d6d2e6130801 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java @@ -41,12 +41,12 @@ public PreviewHostApiImpl( public void create( @NonNull Long identifier, @Nullable Long rotation, @Nullable Long resolutionSelectorId) { Preview.Builder previewBuilder = cameraXProxy.createPreviewBuilder(); - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); if (rotation != null) { previewBuilder.setTargetRotation(rotation.intValue()); } - if (resolutionSelector != null) { + if (resolutionSelectorId != null) { + ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); previewBuilder.setResolutionSelector(resolutionSelector); } From a383e8f3d70f521eb079b3018f6e35fdffc49be9 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 19 Jul 2023 10:40:35 -0700 Subject: [PATCH 05/10] Cleanup --- .../plugins/camerax/AspectRatioStrategyHostApiImpl.java | 4 ++++ .../io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java | 3 ++- .../io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java | 3 ++- .../java/io/flutter/plugins/camerax/PreviewHostApiImpl.java | 3 ++- .../plugins/camerax/ResolutionSelectorHostApiImpl.java | 5 +++-- .../plugins/camerax/ResolutionStrategyHostApiImpl.java | 3 ++- .../io/flutter/plugins/camerax/AspectRatioStrategyTest.java | 2 +- .../test/aspect_ratio_strategy_test.dart | 4 +++- 8 files changed, 19 insertions(+), 8 deletions(-) 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 index 218af3afc21d..b204d129093b 100644 --- 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 @@ -52,6 +52,10 @@ public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) this.proxy = proxy; } + /** + * Creates a {@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) { diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java index 430635f76898..58491477ae15 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageAnalysisHostApiImpl.java @@ -42,7 +42,8 @@ public void create(@NonNull Long identifier, @Nullable Long resolutionSelectorId ImageAnalysis.Builder imageAnalysisBuilder = cameraXProxy.createImageAnalysisBuilder(); if (resolutionSelectorId != null) { - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); + ResolutionSelector resolutionSelector = + Objects.requireNonNull(instanceManager.getInstance(resolutionSelectorId)); imageAnalysisBuilder.setResolutionSelector(resolutionSelector); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java index e05fc9fa9cc1..88ec2debb7a8 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ImageCaptureHostApiImpl.java @@ -61,7 +61,8 @@ public void create( imageCaptureBuilder.setFlashMode(flashMode.intValue()); } if (resolutionSelectorId != null) { - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); + ResolutionSelector resolutionSelector = + Objects.requireNonNull(instanceManager.getInstance(resolutionSelectorId)); imageCaptureBuilder.setResolutionSelector(resolutionSelector); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java index d6d2e6130801..07b581ebf96a 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/PreviewHostApiImpl.java @@ -46,7 +46,8 @@ public void create( previewBuilder.setTargetRotation(rotation.intValue()); } if (resolutionSelectorId != null) { - ResolutionSelector resolutionSelector = instanceManager.getInstance(resolutionSelectorId); + ResolutionSelector resolutionSelector = + Objects.requireNonNull(instanceManager.getInstance(resolutionSelectorId)); previewBuilder.setResolutionSelector(resolutionSelector); } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java index 0171cec3eb04..085fd2a6f5c1 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java @@ -76,10 +76,11 @@ public void create( proxy.create( resolutionStrategyIdentifier == null ? null - : instanceManager.getInstance(resolutionStrategyIdentifier), + : Objects.requireNonNull(instanceManager.getInstance(resolutionStrategyIdentifier)), aspectRatioStrategyIdentifier == null ? null - : instanceManager.getInstance(aspectRatioStrategyIdentifier)), + : Objects.requireNonNull( + instanceManager.getInstance(aspectRatioStrategyIdentifier))), identifier); } } diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java index b2c7bcbf2c78..c110c40446ef 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionStrategyHostApiImpl.java @@ -65,10 +65,11 @@ public void create( @Nullable Long fallbackRule) { ResolutionStrategy resolutionStrategy; if (boundSize == null && fallbackRule == null) { + // Strategy that chooses the highest available resolution does not have a bound size or fallback rule. resolutionStrategy = ResolutionStrategy.HIGHEST_AVAILABLE_STRATEGY; } else if (boundSize == null) { throw new IllegalArgumentException( - "A bound size must be specified if a fallback rule is specified as non-null to create a valid ResolutionStrategy."); + "A bound size must be specified if a non-null fallback rule is specified to create a valid ResolutionStrategy."); } else { resolutionStrategy = proxy.create( diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java index 5da0a371ffa9..02e757dc39fa 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/AspectRatioStrategyTest.java @@ -34,7 +34,7 @@ public void tearDown() { } @Test - public void hostApiCreate() { + public void hostApiCreate_createsExpectedAspectRatioStrategyInstance() { final Long preferredAspectRatio = 0L; final Long fallbackRule = 1L; diff --git a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart index 7b6a05327fdf..9ebc590494e7 100644 --- a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart +++ b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart @@ -24,7 +24,9 @@ void main() { TestInstanceManagerHostApi.setup(null); }); - test('HostApi create', () { + test( + 'HostApi create makes call to create expected AspectRatioStrategy instance', + () { final MockTestAspectRatioStrategyHostApi mockApi = MockTestAspectRatioStrategyHostApi(); TestAspectRatioStrategyHostApi.setup(mockApi); From 725a4ecc493d30f420e1c950e5b465fd3ba1fbb5 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 19 Jul 2023 10:54:14 -0700 Subject: [PATCH 06/10] Add missing import --- .../flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java index 085fd2a6f5c1..be05e1bb8bef 100644 --- a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/ResolutionSelectorHostApiImpl.java @@ -11,6 +11,7 @@ import androidx.camera.core.resolutionselector.ResolutionSelector; import androidx.camera.core.resolutionselector.ResolutionStrategy; import io.flutter.plugins.camerax.GeneratedCameraXLibrary.ResolutionSelectorHostApi; +import java.util.Objects; /** * Host API implementation for {@link ResolutionSelector}. From bdfb634c78d49b71e144e964fe8ad13292a1ba65 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 19 Jul 2023 12:38:14 -0700 Subject: [PATCH 07/10] Fix some spelling errors --- .../java/io/flutter/plugins/camerax/ResolutionStrategyTest.java | 2 +- .../camera_android_camerax/lib/src/aspect_ratio_strategy.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java index 662ced95a267..7bbc6152da0c 100644 --- a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/ResolutionStrategyTest.java @@ -63,7 +63,7 @@ public void hostApiCreate_throwsAssertionErrorWhenArgumentsInvalid() { final ResolutionStrategyHostApiImpl hostApi = new ResolutionStrategyHostApiImpl(instanceManager, mockProxy); - // We expect an exception to be thrown in fallbackRule is specified but bound size is not. + // We expect an exception to be thrown if fallback rule is specified but bound size is not. assertThrows( IllegalArgumentException.class, () -> hostApi.create(instanceIdentifier, null, fallbackRule)); diff --git a/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart index 78edb7433a90..f421a244f538 100644 --- a/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart +++ b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart @@ -8,7 +8,7 @@ import 'camerax_library.g.dart'; import 'instance_manager.dart'; import 'java_object.dart'; -/// The aspect ratio of a use case. +/// The aspect ratio of a UseCase. /// /// Aspect ratio is the ratio of width to height. /// From 41fdabcf526eaf46c77442b2bd1eefc750a8ca84 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 20 Jul 2023 14:58:11 -0700 Subject: [PATCH 08/10] Mark new classes as immutable --- .../camera_android_camerax/lib/src/aspect_ratio_strategy.dart | 2 ++ .../camera_android_camerax/lib/src/resolution_selector.dart | 2 ++ .../camera_android_camerax/lib/src/resolution_strategy.dart | 2 ++ .../camera_android_camerax/test/image_analysis_test.mocks.dart | 1 + .../camera_android_camerax/test/image_capture_test.mocks.dart | 1 + .../camera/camera_android_camerax/test/preview_test.mocks.dart | 1 + 6 files changed, 9 insertions(+) diff --git a/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart index f421a244f538..621f4ddb2edc 100644 --- a/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart +++ b/packages/camera/camera_android_camerax/lib/src/aspect_ratio_strategy.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/services.dart'; +import 'package:meta/meta.dart' show immutable; import 'camerax_library.g.dart'; import 'instance_manager.dart'; @@ -36,6 +37,7 @@ class AspectRatio { /// used to select the best size for a particular image. /// /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy. +@immutable class AspectRatioStrategy extends JavaObject { /// Construct a [AspectRatioStrategy]. AspectRatioStrategy({ diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart b/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart index 5ec31ca95a34..74191724e5ce 100644 --- a/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart +++ b/packages/camera/camera_android_camerax/lib/src/resolution_selector.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/services.dart'; +import 'package:meta/meta.dart' show immutable; import 'aspect_ratio_strategy.dart'; import 'camerax_library.g.dart'; @@ -14,6 +15,7 @@ import 'resolution_strategy.dart'; /// UseCase. /// /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionSelector. +@immutable class ResolutionSelector extends JavaObject { /// Construct a [ResolutionSelector]. ResolutionSelector({ diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart index 582ba2f3bb65..c97855355cd9 100644 --- a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart +++ b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/services.dart'; +import 'package:meta/meta.dart' show immutable; import 'camerax_library.g.dart'; import 'instance_manager.dart'; @@ -12,6 +13,7 @@ import 'java_object.dart'; /// the best size. /// /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy. +@immutable class ResolutionStrategy extends JavaObject { /// Construct a [ResolutionStrategy]. ResolutionStrategy({ diff --git a/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart b/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart index dadab7284b3d..b0df5790b2c3 100644 --- a/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/image_analysis_test.mocks.dart @@ -92,6 +92,7 @@ class MockTestInstanceManagerHostApi extends _i1.Mock /// A class which mocks [ResolutionSelector]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockResolutionSelector extends _i1.Mock implements _i3.ResolutionSelector { MockResolutionSelector() { diff --git a/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart b/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart index c24a363daf27..44331c92cff9 100644 --- a/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/image_capture_test.mocks.dart @@ -96,6 +96,7 @@ class MockTestInstanceManagerHostApi extends _i1.Mock /// A class which mocks [ResolutionSelector]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockResolutionSelector extends _i1.Mock implements _i4.ResolutionSelector { MockResolutionSelector() { diff --git a/packages/camera/camera_android_camerax/test/preview_test.mocks.dart b/packages/camera/camera_android_camerax/test/preview_test.mocks.dart index 4e0dcb9cf4e1..d56e682ac68e 100644 --- a/packages/camera/camera_android_camerax/test/preview_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/preview_test.mocks.dart @@ -113,6 +113,7 @@ class MockTestPreviewHostApi extends _i1.Mock /// A class which mocks [ResolutionSelector]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockResolutionSelector extends _i1.Mock implements _i4.ResolutionSelector { MockResolutionSelector() { From 996ce03a5ac33712d6e640427fba524dc9b5b39c Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 24 Jul 2023 14:45:17 -0700 Subject: [PATCH 09/10] Address review --- .../AspectRatioStrategyHostApiImpl.java | 2 +- .../lib/src/preview.dart | 2 +- .../lib/src/resolution_strategy.dart | 70 ++++++++++-------- .../test/aspect_ratio_strategy_test.dart | 28 +++++++ .../test/resolution_selector_test.dart | 37 ++++++++++ .../test/resolution_selector_test.mocks.dart | 41 ++++++++++- .../test/resolution_strategy_test.dart | 73 ++++++++++--------- 7 files changed, 183 insertions(+), 70 deletions(-) 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 index b204d129093b..f39945e91716 100644 --- 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 @@ -31,7 +31,7 @@ public AspectRatioStrategy create( } /** - * Constructs a {@link AspectRatioStrategyHostApiImpl}. + * Constructs an {@link AspectRatioStrategyHostApiImpl}. * * @param instanceManager maintains instances stored to communicate with attached Dart objects */ diff --git a/packages/camera/camera_android_camerax/lib/src/preview.dart b/packages/camera/camera_android_camerax/lib/src/preview.dart index 20efe6505f0e..f0568078bedb 100644 --- a/packages/camera/camera_android_camerax/lib/src/preview.dart +++ b/packages/camera/camera_android_camerax/lib/src/preview.dart @@ -51,7 +51,7 @@ class Preview extends UseCase { /// Target resolution of the camera preview stream. /// /// If not set, this [UseCase] will default to the behavior described in: - /// https://developer.android.com/reference/androidx/camera/core/Preview.Builder#setResolutionSelector(androidx.camera.core.resolutionselector.ResolutionSelector) + /// https://developer.android.com/reference/androidx/camera/core/Preview.Builder#setResolutionSelector(androidx.camera.core.resolutionselector.ResolutionSelector). final ResolutionSelector? resolutionSelector; /// Sets the surface provider for the preview stream. diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart index c97855355cd9..2eef10efb082 100644 --- a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart +++ b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart @@ -15,9 +15,9 @@ import 'java_object.dart'; /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy. @immutable class ResolutionStrategy extends JavaObject { - /// Construct a [ResolutionStrategy]. + /// Constructs a [ResolutionStrategy]. ResolutionStrategy({ - this.boundSize, + required this.boundSize, this.fallbackRule, super.binaryMessenger, super.instanceManager, @@ -26,10 +26,23 @@ class ResolutionStrategy extends JavaObject { binaryMessenger: binaryMessenger, ), super.detached() { - if (boundSize == null && fallbackRule != null) { - throw ArgumentError( - 'fallbackRule cannot be specified with a null boundSize. If you wish to create the highest available resolution ResolutionStrategy, specify fallbackRule as null.'); - } + _api.createFromInstances(this, boundSize, fallbackRule); + } + + /// Constructs a [ResolutionStrategy] that represents the strategy that + /// chooses the highest available resolution. + /// + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#HIGHEST_AVAILABLE_STRATEGY(). + ResolutionStrategy.highestAvailableStrategy({ + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + boundSize = null, + fallbackRule = null, + super.detached() { _api.createFromInstances(this, boundSize, fallbackRule); } @@ -39,7 +52,7 @@ class ResolutionStrategy extends JavaObject { /// This should only be used outside of tests by subclasses created by this /// library or to create a copy for an [InstanceManager]. ResolutionStrategy.detached({ - this.boundSize, + required this.boundSize, this.fallbackRule, super.binaryMessenger, super.instanceManager, @@ -47,12 +60,24 @@ class ResolutionStrategy extends JavaObject { instanceManager: instanceManager, binaryMessenger: binaryMessenger, ), - super.detached() { - if (boundSize == null && fallbackRule != null) { - throw ArgumentError( - 'fallbackRule cannot be specified with a null boundSize. If you wish to create the highest available resolution ResolutionStrategy, specify fallbackRule as null.'); - } - } + super.detached(); + + /// Instantiates a [ResolutionStrategy] that represents the strategy that + /// chooses the highest available resolution without creating and attaching to + /// an instance of the associated native class. + /// + /// This should only be used outside of tests by subclasses created by this + /// library or to create a copy for an [InstanceManager]. + ResolutionStrategy.detachedHighestAvailableStrategy({ + super.binaryMessenger, + super.instanceManager, + }) : _api = _ResolutionStrategyHostApiImpl( + instanceManager: instanceManager, + binaryMessenger: binaryMessenger, + ), + boundSize = null, + fallbackRule = null, + super.detached(); /// CameraX doesn't select an alternate size when the specified bound size is /// unavailable. @@ -91,26 +116,9 @@ class ResolutionStrategy extends JavaObject { /// When the specified bound size is unavailable, CameraX falls back to the /// closest lower resolution size. /// - /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER() + /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#FALLBACK_RULE_CLOSEST_LOWER(). static const int fallbackRuleClosestLower = 4; - /// Returns the resolution strategey that chooses the highest available - /// resolution. - /// - /// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy#HIGHEST_AVAILABLE_STRATEGY(). - static ResolutionStrategy getHighestAvailableStrategy({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - bool detached = false, - }) { - if (detached) { - return ResolutionStrategy.detached( - binaryMessenger: binaryMessenger, instanceManager: instanceManager); - } - return ResolutionStrategy( - binaryMessenger: binaryMessenger, instanceManager: instanceManager); - } - final _ResolutionStrategyHostApiImpl _api; /// The specified bound size for the desired resolution of the camera. diff --git a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart index 9ebc590494e7..28ec032a2a9e 100644 --- a/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart +++ b/packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart @@ -24,6 +24,34 @@ void main() { TestInstanceManagerHostApi.setup(null); }); + test( + 'detached create does not make call to create expected AspectRatioStrategy instance', + () async { + final MockTestAspectRatioStrategyHostApi mockApi = + MockTestAspectRatioStrategyHostApi(); + TestAspectRatioStrategyHostApi.setup(mockApi); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + const int preferredAspectRatio = 1; + + const int fallbackRule = 1; + + AspectRatioStrategy.detached( + preferredAspectRatio: preferredAspectRatio, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ); + + verifyNever(mockApi.create( + argThat(isA()), + preferredAspectRatio, + fallbackRule, + )); + }); + test( 'HostApi create makes call to create expected AspectRatioStrategy instance', () { diff --git a/packages/camera/camera_android_camerax/test/resolution_selector_test.dart b/packages/camera/camera_android_camerax/test/resolution_selector_test.dart index 89e5dc0d65e5..45ecef576a3a 100644 --- a/packages/camera/camera_android_camerax/test/resolution_selector_test.dart +++ b/packages/camera/camera_android_camerax/test/resolution_selector_test.dart @@ -16,6 +16,8 @@ import 'resolution_selector_test.mocks.dart'; import 'test_camerax_library.g.dart'; @GenerateMocks([ + AspectRatioStrategy, + ResolutionStrategy, TestResolutionSelectorHostApi, TestInstanceManagerHostApi, ]) @@ -28,6 +30,41 @@ void main() { TestInstanceManagerHostApi.setup(null); }); + test( + 'detached constructor does not make call to create expected AspectRatioStrategy instance', + () async { + final MockTestResolutionSelectorHostApi mockApi = + MockTestResolutionSelectorHostApi(); + TestResolutionSelectorHostApi.setup(mockApi); + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + + const int preferredAspectRatio = 1; + + const int fallbackRule = 1; + + AspectRatioStrategy.detached( + preferredAspectRatio: preferredAspectRatio, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ); + + ResolutionSelector.detached( + resolutionStrategy: MockResolutionStrategy(), + aspectRatioStrategy: MockAspectRatioStrategy(), + instanceManager: instanceManager, + ); + + verifyNever(mockApi.create( + argThat(isA()), + argThat(isA()), + argThat(isA()), + )); + }); + test('HostApi create creates expected ResolutionSelector instance', () { final MockTestResolutionSelectorHostApi mockApi = MockTestResolutionSelectorHostApi(); diff --git a/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart b/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart index 4692bfc92320..6ab8de8316d9 100644 --- a/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart +++ b/packages/camera/camera_android_camerax/test/resolution_selector_test.mocks.dart @@ -5,9 +5,11 @@ // @dart=2.19 // ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:camera_android_camerax/src/aspect_ratio_strategy.dart' as _i2; +import 'package:camera_android_camerax/src/resolution_strategy.dart' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'test_camerax_library.g.dart' as _i2; +import 'test_camerax_library.g.dart' as _i4; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -20,11 +22,44 @@ import 'test_camerax_library.g.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +/// A class which mocks [AspectRatioStrategy]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockAspectRatioStrategy extends _i1.Mock + implements _i2.AspectRatioStrategy { + MockAspectRatioStrategy() { + _i1.throwOnMissingStub(this); + } + + @override + int get preferredAspectRatio => (super.noSuchMethod( + Invocation.getter(#preferredAspectRatio), + returnValue: 0, + ) as int); + @override + int get fallbackRule => (super.noSuchMethod( + Invocation.getter(#fallbackRule), + returnValue: 0, + ) as int); +} + +/// A class which mocks [ResolutionStrategy]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockResolutionStrategy extends _i1.Mock + implements _i3.ResolutionStrategy { + MockResolutionStrategy() { + _i1.throwOnMissingStub(this); + } +} + /// A class which mocks [TestResolutionSelectorHostApi]. /// /// See the documentation for Mockito's code generation for more information. class MockTestResolutionSelectorHostApi extends _i1.Mock - implements _i2.TestResolutionSelectorHostApi { + implements _i4.TestResolutionSelectorHostApi { MockTestResolutionSelectorHostApi() { _i1.throwOnMissingStub(this); } @@ -52,7 +87,7 @@ class MockTestResolutionSelectorHostApi extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i2.TestInstanceManagerHostApi { + implements _i4.TestInstanceManagerHostApi { MockTestInstanceManagerHostApi() { _i1.throwOnMissingStub(this); } diff --git a/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart b/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart index 83c8151d8df2..9c098b946075 100644 --- a/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart +++ b/packages/camera/camera_android_camerax/test/resolution_strategy_test.dart @@ -28,7 +28,7 @@ void main() { }); test( - 'ResolutionStrategy constructor detects valid boundSize and fallbackRule combinations', + 'detached resolutionStrategy constructors do not make call to Host API create', () { final MockTestResolutionStrategyHostApi mockApi = MockTestResolutionStrategyHostApi(); @@ -39,41 +39,35 @@ void main() { onWeakReferenceRemoved: (_) {}, ); - // Expect error if boundSize is null, but fallbackRule is not. - Size? boundSize; - int? fallbackRule = 5; - expect( - () => ResolutionStrategy( - boundSize: boundSize, - fallbackRule: fallbackRule, - instanceManager: instanceManager, - ), - throwsArgumentError); - - // Expect no error if boundSize is non-null, but fallbackRule is not. - boundSize = const Size(3, 5); - fallbackRule = null; - expect( - () => ResolutionStrategy( - boundSize: boundSize, - fallbackRule: fallbackRule, - instanceManager: instanceManager, - ), - returnsNormally); - - // Expect no error if boundSize and fallbackRule are both null. - boundSize = null; - fallbackRule = null; - expect( - () => ResolutionStrategy( - boundSize: boundSize, - fallbackRule: fallbackRule, - instanceManager: instanceManager, - ), - returnsNormally); + const Size boundSize = Size(70, 20); + const int fallbackRule = 1; + + ResolutionStrategy.detached( + boundSize: boundSize, + fallbackRule: fallbackRule, + instanceManager: instanceManager, + ); + + verifyNever(mockApi.create( + argThat(isA()), + argThat(isA() + .having((ResolutionInfo size) => size.width, 'width', 50) + .having((ResolutionInfo size) => size.height, 'height', 30)), + fallbackRule, + )); + + ResolutionStrategy.detachedHighestAvailableStrategy( + instanceManager: instanceManager, + ); + + verifyNever(mockApi.create( + argThat(isA()), + null, + null, + )); }); - test('HostApi create creates expected ResolutionStrategy', () { + test('HostApi create creates expected ResolutionStrategies', () { final MockTestResolutionStrategyHostApi mockApi = MockTestResolutionStrategyHostApi(); TestResolutionStrategyHostApi.setup(mockApi); @@ -99,6 +93,17 @@ void main() { .having((ResolutionInfo size) => size.height, 'height', 30)), fallbackRule, )); + + final ResolutionStrategy highestAvailableInstance = + ResolutionStrategy.highestAvailableStrategy( + instanceManager: instanceManager, + ); + + verify(mockApi.create( + instanceManager.getIdentifier(highestAvailableInstance), + null, + null, + )); }); }); } From 98e10359fe4ce4981635dca83174889cd242215f Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 27 Jul 2023 15:10:09 -0700 Subject: [PATCH 10/10] Address review --- .../plugins/camerax/AspectRatioStrategyHostApiImpl.java | 4 ++-- .../camera_android_camerax/lib/src/resolution_strategy.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 index f39945e91716..91e0def66eaf 100644 --- 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 @@ -40,7 +40,7 @@ public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) } /** - * Constructs a {@link AspectRatioStrategyHostApiImpl}. + * Constructs an {@link AspectRatioStrategyHostApiImpl}. * * @param instanceManager maintains instances stored to communicate with attached Dart objects * @param proxy proxy for constructors and static method of {@link AspectRatioStrategy} @@ -53,7 +53,7 @@ public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) } /** - * Creates a {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback + * Creates an {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback * rule specified. */ @Override diff --git a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart index 2eef10efb082..80669f3f8d58 100644 --- a/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart +++ b/packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart @@ -17,7 +17,7 @@ import 'java_object.dart'; class ResolutionStrategy extends JavaObject { /// Constructs a [ResolutionStrategy]. ResolutionStrategy({ - required this.boundSize, + required Size this.boundSize, this.fallbackRule, super.binaryMessenger, super.instanceManager,