From ff5f686d7ccddca076090522245d801325524104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Tue, 3 May 2022 12:03:32 +0200 Subject: [PATCH] Catch NPE on webLogin view binding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: #1958 Signed-off-by: Tim Krüger --- .../controllers/WebViewLoginController.kt | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt index 1cc875873..f070c7e04 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.kt @@ -30,6 +30,7 @@ import android.os.Bundle import android.security.KeyChain import android.security.KeyChainException import android.text.TextUtils +import android.util.Log import android.view.View import android.webkit.ClientCertRequest import android.webkit.CookieSyncManager @@ -77,7 +78,6 @@ import java.net.URLDecoder import java.security.PrivateKey import java.security.cert.CertificateException import java.security.cert.X509Certificate -import java.util.HashMap import java.util.Locale import javax.inject.Inject @@ -183,32 +183,39 @@ class WebViewLoginController(args: Bundle? = null) : NewBaseController( } override fun onPageFinished(view: WebView, url: String) { - loginStep++ - if (!basePageLoaded) { - binding.progressBar.visibility = View.GONE - binding.webview.visibility = View.VISIBLE + try { + loginStep++ + if (!basePageLoaded) { + binding.progressBar.visibility = View.GONE + binding.webview.visibility = View.VISIBLE - basePageLoaded = true - } - if (!TextUtils.isEmpty(username)) { - if (loginStep == 1) { - binding.webview.loadUrl("javascript: {document.getElementsByClassName('login')[0].click(); };") - } else if (!automatedLoginAttempted) { - automatedLoginAttempted = true - if (TextUtils.isEmpty(password)) { - binding.webview.loadUrl( - "javascript:var justStore = document.getElementById('user').value = '$username';" - ) - } else { - binding.webview.loadUrl( - "javascript: {" + - "document.getElementById('user').value = '" + username + "';" + - "document.getElementById('password').value = '" + password + "';" + - "document.getElementById('submit').click(); };" - ) + basePageLoaded = true + } + if (!TextUtils.isEmpty(username)) { + if (loginStep == 1) { + binding.webview.loadUrl("javascript: {document.getElementsByClassName('login')[0].click(); };") + } else if (!automatedLoginAttempted) { + automatedLoginAttempted = true + if (TextUtils.isEmpty(password)) { + binding.webview.loadUrl( + "javascript:var justStore = document.getElementById('user').value = '$username';" + ) + } else { + binding.webview.loadUrl( + "javascript: {" + + "document.getElementById('user').value = '" + username + "';" + + "document.getElementById('password').value = '" + password + "';" + + "document.getElementById('submit').click(); };" + ) + } } } + } catch (npe: NullPointerException) { + // view binding can be null + // since this is called asynchronously and UI might have been destroyed in the meantime + Log.i(TAG, "UI destroyed - view binding already gone") } + super.onPageFinished(view, url) }