aws-amplify / amplify-ui-android

Amplify UI for Android is a collection of accessible, themeable, performant Android components that can connect directly to the cloud.
https://ui.docs.amplify.aws
Apache License 2.0
16 stars 8 forks source link

When using Liveness with PlatformViewLink in Flutter, the camera freezes intermittently on Android10 devices. #202

Open zhonadan opened 2 weeks ago

zhonadan commented 2 weeks ago

Before creating a new issue, please confirm:

Which UI component?

Liveness

Gradle script dependencies

implementation 'com.amplifyframework.ui:liveness:1.2.6'
implementation 'com.amplifyframework:aws-auth-cognito:2.16.1'

Environment information

Welcome to Gradle 7.6.1!

Here are the highlights of this release:
 - Added support for Java 19.
 - Introduced `--rerun` flag for individual task rerun.
 - Improved dependency block for test suites to be strongly typed.
 - Added a pluggable system for Java toolchains provisioning.

For more details see https://docs.gradle.org/7.6.1/release-notes.html

------------------------------------------------------------
Gradle 7.6.1
------------------------------------------------------------

Build time:   2023-02-24 13:54:42 UTC
Revision:     3905fe8ac072bbd925c70ddbddddf4463341f4b4

Kotlin:       1.7.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.10 (JetBrains s.r.o. 17.0.10+0-17.0.10b1087.21-11572160)
OS:           Mac OS X 14.4 aarch64

Please include any relevant guides or documentation you're referencing

No response

Describe the bug

We are using PlatformViewLink to integrate Liveness features in Flutter.

The camera screen freezes intermittently on Android10 devices. I haven't found the issue on other OS versions.

Reproduction steps (if applicable)

Add the Liveness Android View to the Flutter screen using PlatformViewLink, After closing and reopening the screen a few times, the camera preview screen freezes.

Code Snippet

composeView.setContent {
    MaterialTheme(
            colorScheme = LivenessColorScheme.default()
    ) {
        sessionId?.let {
            FaceLivenessDetector(
                    sessionId = it,
                    region = "***",
                    onComplete = {
                        sendMessageToFlutter("complete", it, null)
                    },
            )
        }
    }
}
PlatformViewLink(
  key: ValueKey(androidRebuildSignal.current),
  viewType: _viewType,
  surfaceFactory: (context, controller) {
    return AndroidViewSurface(
      controller: controller as AndroidViewController,
      gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
      hitTestBehavior: PlatformViewHitTestBehavior.opaque,
    );
  },
  onCreatePlatformView: (params) {
    return PlatformViewsService.initSurfaceAndroidView(
      id: params.id,
      viewType: _viewType,
      layoutDirection: TextDirection.ltr,
      creationParams: creationParams,
      creationParamsCodec: const StandardMessageCodec(),
      onFocus: () {
        params.onFocusChanged(true);
      },
    )
      ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
      ..create();
  },
)

Log output

No response

amplifyconfiguration.json

{ "auth": { "plugins": { "awsCognitoAuthPlugin": { "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "", "Region": "" } } } } } } }

Additional information and screenshots

No response

tylerjroach commented 2 weeks ago

Hi @zhonadan, I'm glad to see you have gotten Liveness running on Flutter. Unfortunately, we do not have a native Flutter Liveness component and we do not test support for flutter with the Android FaceLivenessDetector.

It sounds like you may be running into a Flutter specific bug that does not directly involve the Android liveness component. I understand the desire code fully within Flutter, but if you continue to run into issues, I would recommend writing FaceLivenessDetector within its own native Android Activity. You can launch the activity from within Flutter and then return back into Flutter once the FaceLivenessDetector has completed.