From 0fd553a48bc116b217f547b048898884b23d4808 Mon Sep 17 00:00:00 2001 From: mightymop Date: Fri, 4 Jun 2021 14:18:06 +0200 Subject: [PATCH 1/2] Fix for failed logins / app crashes fix https://github.com/nextcloud/android/issues/8302 --- .../android/lib/common/OwnCloudClientFactory.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 62e4ec69e..435a99c91 100644 --- a/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -206,7 +206,20 @@ public static NextcloudClient createNextcloudClient(Account account, Context app // TODO avoid calling to getUserData here String userId = am.getUserData(account, AccountUtils.Constants.KEY_USER_ID); String username = AccountUtils.getUsernameForAccount(account); - String password = am.peekAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type)); + String password = null; + try + { + password = am.blockingGetAuthToken(account,AccountTypeUtils.getAuthTokenTypePass(account.type),false); + if (password==null) + { + Log_OC.e(TAG, "Error receiving password token (password==null)"); + throw new AccountNotFoundException(account,"Error receiving password token (password==null)",null); + } + } + catch (Exception e){ + Log_OC.e(TAG, "Error receiving password token", e); + throw new AccountNotFoundException(account,"Error receiving password token",e); + } if (username == null || username.isEmpty() || password == null || password.isEmpty()) { throw new AccountNotFoundException( From 8f5f2600db62b34afaa4ea6d987910ec2701e78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Tue, 9 Nov 2021 12:50:47 +0100 Subject: [PATCH 2/2] Fix spotbugs and formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey Vilas --- .../lib/common/OwnCloudClientFactory.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 435a99c91..9a883b96c 100644 --- a/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -35,12 +35,12 @@ import android.os.Bundle; import com.nextcloud.common.NextcloudClient; +import com.nextcloud.common.OkHttpCredentialsUtil; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.network.NetworkUtils; import com.owncloud.android.lib.common.utils.Log_OC; -import com.nextcloud.common.OkHttpCredentialsUtil; import java.io.IOException; import java.security.GeneralSecurityException; @@ -206,22 +206,19 @@ public static NextcloudClient createNextcloudClient(Account account, Context app // TODO avoid calling to getUserData here String userId = am.getUserData(account, AccountUtils.Constants.KEY_USER_ID); String username = AccountUtils.getUsernameForAccount(account); - String password = null; - try - { - password = am.blockingGetAuthToken(account,AccountTypeUtils.getAuthTokenTypePass(account.type),false); - if (password==null) - { + String password; + try { + password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false); + if (password == null) { Log_OC.e(TAG, "Error receiving password token (password==null)"); - throw new AccountNotFoundException(account,"Error receiving password token (password==null)",null); + throw new AccountNotFoundException(account, "Error receiving password token (password==null)", null); } - } - catch (Exception e){ + } catch (Exception e) { Log_OC.e(TAG, "Error receiving password token", e); - throw new AccountNotFoundException(account,"Error receiving password token",e); + throw new AccountNotFoundException(account, "Error receiving password token", e); } - if (username == null || username.isEmpty() || password == null || password.isEmpty()) { + if (username == null || username.isEmpty() || password.isEmpty()) { throw new AccountNotFoundException( account, "Username or password could not be retrieved",