diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-30 00:45:41 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-03-30 03:23:32 -0600 |
commit | 09b40cdec7d096afac11d42d194934fa7c011ab1 (patch) | |
tree | 78216aaa463f35795c1755a6c0ab0a1d15e55550 /ui/src/main/java/com/wireguard/android/fragment | |
parent | BiometricAuthenticator: implement biometric authentication for sensitive operations (diff) | |
download | wireguard-android-09b40cdec7d096afac11d42d194934fa7c011ab1.tar.xz wireguard-android-09b40cdec7d096afac11d42d194934fa7c011ab1.zip |
BiometricAuthenticator: rework logic and bugs
Otherwise there's a frameworks bug that causes the fragment's activity
to become null.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/fragment')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt index 1b8af50e..1c0cf2bd 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt @@ -4,6 +4,7 @@ */ package com.wireguard.android.fragment +import android.app.Activity import android.content.Context import android.os.Bundle import android.text.InputType @@ -83,7 +84,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { } override fun onDestroyView() { - requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) + activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) binding = null super.onDestroyView() } @@ -106,7 +107,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { InputMethodManager.HIDE_NOT_ALWAYS) } // Tell the activity to finish itself or go back to the detail view. - requireActivity().runOnUiThread { + activity.runOnUiThread { // TODO(smaeul): Remove this hack when fixing the Config ViewModel // The selected tunnel has to actually change, but we have to remember this one. val savedTunnel = tunnel @@ -228,13 +229,17 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { super.onViewStateRestored(savedInstanceState) } + private var showingAuthenticator = false + fun onKeyClick(view: View) = onKeyFocusChange(view, true) fun onKeyFocusChange(view: View, isFocused: Boolean) { - if (!isFocused) return + if (!isFocused || showingAuthenticator) return val edit = view as? EditText ?: return if (!haveShownKeys && edit.text.isNotEmpty()) { - BiometricAuthenticator.authenticate(R.string.biometric_prompt_private_key_title, requireActivity()) { + showingAuthenticator = true + BiometricAuthenticator.authenticate(R.string.biometric_prompt_private_key_title, this) { + showingAuthenticator = false when (it) { is BiometricAuthenticator.Result.Success, is BiometricAuthenticator.Result.HardwareUnavailableOrDisabled -> { haveShownKeys = true @@ -255,7 +260,7 @@ class TunnelEditorFragment : BaseFragment(), AppExclusionListener { } private fun showPrivateKey(edit: EditText) { - requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_SECURE) + activity?.window?.addFlags(WindowManager.LayoutParams.FLAG_SECURE) edit.inputType = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD } |