Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #2
Note: I know alpha-02 has a fix for a biometric related leak:
However that change did not fix the leak reported here, as BiometricViewModel is still tied to the activity lifecycle no matter what and will hold the clientCallback reference until the activity is destroyed.
ap...@google.com <ap...@google.com> #3
jb...@google.com <jb...@google.com> #4
Can confirm that it still happens in 1.1.0-beta01
jb...@google.com <jb...@google.com>
ma...@gwplc.com <ma...@gwplc.com> #5
Branch: androidx-main
commit fcbbd9368d75b736de4b92d067be84421376b294
Author: Curtis Belmonte <curtislb@google.com>
Date: Wed Jan 20 15:54:34 2021
Reset BiometricViewModel callback in Fragment#onDestroy()
Currently, the client callback reference held by BiometricViewModel is
retained for the lifecycle of the hosting activity. In the (likely) case
that a client is using a fragment within that activity to host
BiometricPrompt and passes an AuthenticationCallback with a reference to
that fragment, this will cause the fragment to leak.
This commit applies a minimal fix for the issue by resetting the
callback reference held by the view model when the host fragment is
destroyed (via a LifecycleObserver). This shouldn't affect the prompt's
behavior across configuration changes such as device rotation, since the
callback should be reinitialized by the client in onCreate() or similar.
Test: Biometric integration test app on API 27-30.
Test: ./gradlew biometric:biometric:test
Test: ./gradlew biometric:biometric:connectedAndroidTest
Test: ./gradlew biometric:integration-tests:testapp:connectedAndroidTest
Bug: 167014923
Change-Id: I7086460fac3921a490f4e2abf0671adec5c146bd
M biometric/biometric/src/main/java/androidx/biometric/BiometricPrompt.java
M biometric/biometric/src/main/java/androidx/biometric/BiometricViewModel.java
il...@google.com <il...@google.com> #6
I don't use Fragments and use a View-based solutions instead. I create prompt like this:
BiometricPrompt(requireActivity, myAuthCallback)
So it is tied to the activity and it still leaks my view-based screens (1.2.0-alpha02). Ideally there would be a way to reset this callback. Latest commit fixes this leak only for Fragments (sadly).
Is there any workaround maybe? Dirty (but working) ones would do too ;)
Description
Version used:
androidx.activity:activity-compose:1.3.0-alpha02
androidx.fragment:fragment-ktx:1.3.0-beta01
androidx.compose.runtime:runtime:1.0.0-alpah12
Devices/Android versions reproduced on:
emulator Pixel 3 API 29
Sample code:
From any fragment calling TestDialogFragment using
TestDialogFragment().show(childFragmentManager, "Test")
or Navigation way:
findNavController().navigate(MainFragmentDirections.actionToTestDialog())
class TestDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = ComposeView(requireContext()).apply {
setContent {
Surface {
TestDialogLayout()
}
}
}
}
Will cause the exception:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@bec849f[MainActivity]
at androidx.compose.ui.platform.WindowRecomposerKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.kt:231)
Can be manually fixed by setting the ViewTreeLifecycleOwner in onCreateView at the beginning:
dialog?.window?.decorView?.let {
ViewTreeLifecycleOwner.set(it, viewLifecycleOwner)
}