authpass / biometric_storage

Flutter plugin to store data behind biometric authentication (ie. fingerprint)
https://pub.dev/packages/biometric_storage
MIT License
184 stars 107 forks source link

[android] - Problems with Android devices with face recognition #30

Closed Ahmadre closed 3 years ago

Ahmadre commented 3 years ago

The _storageFile.write(...) method works perfectly for iOS and Android (with fingerprint), but on Android devices with face recognition I am getting this, when trying to write to store:

W/BiometricPrompt(19463): semSetExtraInfo: Tried to obtain display from a Context not associated with  one. Only visual Contexts (such as Activity or one created with Context#createWindowContext) or ones created with Context#createDisplayContext are associated with displays. Other types of Contexts are typically related to background entities and may return an arbitrary display.
I/BiometricPrompt(19463): onError: 12, 0
E/flutter (19463): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: AuthException{code: AuthExceptionCode.unknown, message: }
E/flutter (19463): #0      StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:597
E/flutter (19463): #1      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter (19463): <asynchronous suspension>
E/flutter (19463): #2      BiometricsController.setBiometricInformations
package:app/…/controller/biometrics_controller.dart:41
E/flutter (19463): <asynchronous suspension>
E/flutter (19463): #3      AuthFormState.saveBiometrics
package:app/…/widgets/auth_form.dart:77
E/flutter (19463): <asynchronous suspension>
E/flutter (19463): #4      AuthFormState.onSubmitButtonPressed.<anonymous closure>
package:app/…/widgets/auth_form.dart:134
E/flutter (19463): <asynchronous suspension>
E/flutter (19463):

Environment:

Ahmadre commented 3 years ago

Also note:

I setup Android correctly and this is my MainActivity:

package de.kds.app

import android.os.Bundle
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine

import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
  }

  override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    GeneratedPluginRegistrant.registerWith(flutterEngine)
  }
}
Ahmadre commented 3 years ago

After some research the error here explains everything:

https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt#BIOMETRIC_ERROR_HW_NOT_PRESENT

Ahmadre commented 3 years ago

But when I use local_auth and check if device is supported and canCheckBiometrics it works and it's saying that face recognition is available :( .

Just the write method is not working....

hpoul commented 3 years ago

I don't quite understand what the error code you linked to is related to this problem - the error you pasted did not mention HW_NOT_PRESENT. It sounds like the plugin did not use an activity as context 🤔️ I'll might try this tomorrow.. after all i finally got an android phone with face unlock 😅️

Ahmadre commented 3 years ago

It's this: I/BiometricPrompt(19463): onError: 12, 0

But that doesn't explain properly why the write is failing :/

Thanks for your help tomorrow :)

Ahmadre commented 3 years ago

I should've used the BiometricStorage().canAuthenticate() earlier :D

I only used the one from local_auth, but BiometricStorage().canAuthenticate() is functioning much better!

Samsung Tab A7 is only using a "Fake"-Face recognition.

Solved :). Thank you!!!