termux / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
2.23k stars 443 forks source link

Fingerprint API isn't working on Android 14. #661

Open JacobTDC opened 7 months ago

JacobTDC commented 7 months ago

Problem description

Fingerprint dialog "appears" (it's more of just a flash across the screen) briefly and immediately returns the following:

{
  "errors": [],
  "failed_attempts": 0,
  "auth_result": "AUTH_RESULT_FAILURE"
}

Steps to reproduce

Running the following command:

$ termux-fingerprint

Expected behavior

The dialog should appear and allow you to scan your fingerprint, and then return a result.

Additional information termux-info output is as follows:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=16024
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages.termux.dev/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://packages.termux.dev/apt/termux-x11 x11 main
Updatable packages:
git/stable 2.43.2 aarch64 [upgradable from: 2.43.1-1]
termux-tools version:
1.40.6
Android version:
14
Kernel build information:
Linux localhost 5.15.110-android14-11-gcc48824eebe8-ab10865596 #1 SMP PREEMPT Tue Sep 26 19:57:58 UTC 2023 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 8 Pro
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
com.termux.styling versionCode:31
JacobTDC commented 7 months ago

I found the following two entries in logcat, which appear to be relevant:

02-15 22:48:51.617  1643  1643 E AuthSessionCoordinator: Error unable to find auth operation : authEndedFor(userId=0 ,biometricStrength=15, sensorId=0, requestId=52, wasSuccessful=true)
02-15 22:48:51.620  5009 28753 E termux-api: Fingerprint operation canceled by user.
flameshikari commented 7 months ago

I have the same problem on Google Pixel 5a 5G (barbet). I was using tergent which stopped working after updating to Android 14. I can provide more info but I don't know what exactly is needed. It would be great if you tell me what I need to share. At least, I can share termux-info output:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=F_DROID
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=3849
TERMUX_IS_DEBUGGABLE_BUILD=0
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
TERMUX__USER_ID=0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://repository.su/termux/termux-main/ stable main
Updatable packages:
All packages up to date
termux-tools version:
1.40.6
Android version:
14
Kernel build information:
Linux localhost 4.19.282-g6283e60455dd-ab11137546 #1 SMP PREEMPT Wed Nov 22 08:58:04 UTC 2023 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 5a
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
com.termux.boot versionCode:7
com.termux.tasker versionCode:6
com.termux.styling versionCode:31
nozwock commented 6 months ago

termux-fingerprint does seem to work sometimes, yes on A14. It appears to me that the keyboard is trying to regain focus, cancelling the fingerprint authentication popup in turn.

I've had noticeably more number of successes with Hacker's Keyboard than with Gboard.

JacobTDC commented 6 months ago

@nozwock it now does not work at all (as in, doesn't even "flash" on the screen) (it is still flickering the screen sometimes), even with hacker keyboard. This may be a Pixel specific issue. Even using sleep 3; termux-fingerprint and dismissing the keyboard before it pops up doesn't work.

nozwock commented 6 months ago

@JacobTDC I just tried sleep, the results didn't differ. Still only sometime works.

About pixel, ye, maybe something on pixel made it worse to the point that it doesn't work at all.

tepsys commented 5 months ago

I have the same issue on a Oneplus 9 Pro running CrDroid Android 14. Termux-fingerprint immediately fails with

{
  "errors": [],
  "failed_attempts": 0,
  "auth_result": "AUTH_RESULT_FAILURE"
}
daguej commented 4 months ago

Same here, Pixel on Android 14. I'm not seeing the fingerprint UI flicker on screen at all, just get immediate failure.

I also get a notification:

Termux:API Error

Error in ResultReturner

Tapping the notification causes Termux to crash.

tmzullinger commented 4 months ago

Reading https://github.com/termux/termux-api/issues/638, I was able to get termux-fingerprint to prompt as it should after running termux-api-start.

I haven't yet tried to see if this works reliably and whether I can easily ensure this is called anytime I start termux.

If it works reliably, I could put it in ~/.bashrc, ~/.bash_profile, etc., or in wrappers for the few tools I run which need it (mainly ssh).

EDIT: it doesn't work reliably. I do think that issue is related, but sadly, a simple command doesn't fix things.

JacobTDC commented 1 month ago

Same here, Pixel on Android 14. I'm not seeing the fingerprint UI flicker on screen at all, just get immediate failure.

I also get a notification:

Termux:API Error

Error in ResultReturner

Tapping the notification causes Termux to crash.

That's interesting, I don't get any notification on failure.

JacobTDC commented 1 month ago

I was reviewing this, and found some more relevant log entries:

08-06 23:06:50.194  2110  2110 D AuthController: showAuthenticationDialog, authenticators: 255, sensorIds: 0 , credentialAllowed: false, requireConfirmation: false, operationId: 0, requestId: 6
08-06 23:06:50.196  2110  2110 E ThemeUtils: View class com.android.systemui.biometrics.BiometricPromptLottieViewWrapper is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).
08-06 23:06:50.196  2110  2110 E ThemeUtils: View class com.android.systemui.biometrics.BiometricPromptLottieViewWrapper is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).
08-06 23:06:50.197  2110  2110 D AuthController: userId: 0 mCurrentDialog: null newDialog: com.android.systemui.biometrics.AuthContainerView{db187e5 VFE...... .F....I. 0,0-0,0}
08-06 23:06:50.199  2110  2110 W AuthController: Evicting client due to: com.termux
08-06 23:06:50.199  1648  1648 V BiometricService/AuthSession: Dismissed! Modality: 1, User: 0, IsCrypto: false, Action: 2, Client: 2, Reason: 3, Error: 10, Latency: 5, SessionId: 0
08-06 23:06:50.200  1648  1648 D BiometricService/AuthSession: Cancelling sensorId: 0
08-06 23:06:50.200  1648  1648 D FingerprintService: cancelAuthenticationFromService, sensorId: 0
08-06 23:06:50.200  1648  1648 D BiometricScheduler: cancelAuthenticationOrDetection, requestId: 6
08-06 23:06:50.200  1648  1648 D BiometricScheduler: Cancelling auth/detect op: {[52] com.android.server.biometrics.sensors.fingerprint.aidl.FingerprintAuthenticationClient, proto=3, owner=com.termux.api, cookie=2072679940, requestId=6, userId=0}, State: 4
08-06 23:06:50.200  1648  1648 D BiometricSchedulerOperation: [Cancelling] Current client (without start): {[52] com.android.server.biometrics.sensors.fingerprint.aidl.FingerprintAuthenticationClient, proto=3, owner=com.termux.api, cookie=2072679940, requestId=6, userId=0}
08-06 23:06:50.200  1648  1648 D Biometrics/AcquisitionClient: cancelWithoutStarting: {[52] com.android.server.biometrics.sensors.fingerprint.aidl.FingerprintAuthenticationClient, proto=3, owner=com.termux.api, cookie=2072679940, requestId=6, userId=0}
08-06 23:06:50.200  1648  1648 D BiometricStateCallback: Client finished, state updated to 0, client {[52] com.android.server.biometrics.sensors.fingerprint.aidl.FingerprintAuthenticationClient, proto=3, owner=com.termux.api, cookie=2072679940, requestId=6, userId=0}
08-06 23:06:50.201  1648  1648 E AuthSessionCoordinator: Error unable to find auth operation : authEndedFor(userId=0 ,biometricStrength=15, sensorId=0, requestId=6, wasSuccessful=true)
08-06 23:06:50.201  1648  1648 D BiometricSchedulerOperation: [Finished / destroy]: {[52] com.android.server.biometrics.sensors.fingerprint.aidl.FingerprintAuthenticationClient, proto=3, owner=com.termux.api, cookie=2072679940, requestId=6, userId=0}
08-06 23:06:50.201  1648  1648 D BiometricService: handleOnError() sensorId: 0, cookie: 2072679940, error: 5, vendorCode: 0
08-06 23:06:50.201  1648  1648 W BiometricService: handleOnError: AuthSession is not current
08-06 23:06:50.201  1648  1648 D GestureAvailabilityTracker: Notifying gesture availability, active=true
08-06 23:06:50.201  1648  1648 D UaBiometricScheduler: No operations, returning to idle
08-06 23:06:50.205  1648  2347 D CoreBackPreview: Window{68bbb58 u0 com.termux.api/com.termux.api.FingerprintAPI$FingerprintActivity}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@4533d22, mPriority=0, mIsAnimationCallback=false}
08-06 23:06:50.206  2110  2136 D WindowManagerShell: onKeepClearAreasChanged: restricted={}, unrestricted={}
08-06 23:06:50.207  2110  2136 D WindowManagerShell: onKeepClearAreasChanged: restricted={}, unrestricted={Rect(0, 1887 - 1344, 2992)}
08-06 23:06:50.209   556   570 W gralloc4: Unable to set buffer name VRI[FingerprintAPI$FingerprintActivity]#7(BLAST Consumer)7: File name too long
08-06 23:06:50.209   556   570 W gralloc4: Unable to set buffer name VRI[FingerprintAPI$FingerprintActivity]#7(BLAST Consumer)7: File name too long
08-06 23:06:50.210   556   570 W gralloc4: Unable to set buffer name VRI[FingerprintAPI$FingerprintActivity]#7(BLAST Consumer)7: File name too long
08-06 23:06:50.211   556   570 W gralloc4: Unable to set buffer name VRI[FingerprintAPI$FingerprintActivity]#7(BLAST Consumer)7: File name too long
08-06 23:06:50.211   556   570 W gralloc4: Unable to set buffer name VRI[FingerprintAPI$FingerprintActivity]#7(BLAST Consumer)7: File name too long
08-06 23:06:50.213 24105 16296 E termux-api: Fingerprint operation canceled by user

The ThemeUtils error appears to happen to all fingerprint scanner instances in any app, and does not seem to be relevant.

The most relevant line appears to be:

08-06 23:06:50.199  2110  2110 W AuthController: Evicting client due to: com.termux

Upon reading the AuthController.java source (specifically the isOwnerInForeground() method; lines 235 - 250 at time of writing), it seems that the system is cancelling the scanner dialog because it believes that the caller is not in the foreground, due to com.termux and com.termux.api being two different packages.

JacobTDC commented 1 month ago

I was further able to make it "work" with the following command:

$ termux-dialog & sleep 1; termux-fingerprint

It works because it pulls com.termux.api into the foreground by opening a dialog before trying to use the fingerprint scanner.

flameshikari commented 1 month ago

I was further able to make it "work" with the following command:

$ termux-dialog & sleep 1; termux-fingerprint

It works because it pulls com.termux.api into the foreground by opening a dialog before trying to use the fingerprint scanner.

Quite a strange solution, but brilliant, and it's working. Thanks! Even as a temporary solution it will do just fine.

I made it working with tergent. You can add the following line at the top of ~/.ssh/config to call the command before connecting to a specific address (replace [ADDRESS] with the address you're connecting to):

Match host [ADDRESS] exec "termux-dialog & sleep 1; termux-fingerprint"

In my case I'm using PKCS11Provider for all connections, so this is my config:

Host *
  PKCS11Provider /data/data/com.termux/files/usr/lib/libtergent.so
  Match exec "termux-dialog & sleep 1; termux-fingerprint"
JacobTDC commented 2 days ago

Could this issue maybe be solved using android.permission.SYSTEM_ALERT_WINDOW and WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY?