From d77b2f1afc7455909857f5472cf6552bd5345338 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 23 Nov 2022 16:55:11 +0600 Subject: [PATCH 1/2] 5969-Handle_exception_in_accountUserInfoWorker issue: https://gitlab.e.foundation/e/backlog/-/issues/5969 --- .../e/drive/operations/GetAliasOperation.java | 2 +- .../e/drive/work/AccountUserInfoWorker.java | 69 +++++++++++++------ 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java index 253127e8..0602b6e2 100644 --- a/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java +++ b/app/src/main/java/foundation/e/drive/operations/GetAliasOperation.java @@ -28,7 +28,7 @@ import timber.log.Timber; * /!\ Doesn't require NextcloudClient yet */ -public class GetAliasOperation extends RemoteOperation { +public class GetAliasOperation extends RemoteOperation> { private static final String ALIAS_PATH = "/ocs/v1.php/cloud/hide-my-email/"; diff --git a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java index 6fcc83c5..dc3abfce 100644 --- a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java @@ -71,22 +71,32 @@ public class AccountUserInfoWorker extends Worker { @NonNull @Override public Result doWork() { - account = CommonUtils.getAccount(mContext.getString(R.string.eelo_account_type), - accountManager); - final NextcloudClient client = DavClientProvider.getInstance().getNcClientInstance(account, mContext); - if (client != null) { - if (fetchUserInfo(client) && fetchAliases()) { - Glide.with(mContext) - .load(client.getBaseUri() + AccountsActivity.NON_OFFICIAL_AVATAR_PATH - + client.getUserId() + "/" + 300) - .diskCacheStrategy(DiskCacheStrategy.ALL) - .preload(); - updateWidget(mContext); - return Result.success(); - } else { - return Result.retry(); + + try { + account = CommonUtils.getAccount(mContext.getString(R.string.eelo_account_type), accountManager); + + if (account == null) { + return Result.failure(); + } + + final NextcloudClient client = DavClientProvider.getInstance().getNcClientInstance(account, mContext); + if (client != null) { + if (fetchUserInfo(client) && fetchAliases()) { + Glide.with(mContext) + .load(client.getBaseUri() + AccountsActivity.NON_OFFICIAL_AVATAR_PATH + + client.getUserId() + "/" + 300) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .preload(); + updateWidget(mContext); + return Result.success(); + } else { + return Result.retry(); + } } + } catch (Throwable e) { + Timber.e(e, "Exception on retrieving accountUserInfo."); } + return Result.failure(); } @@ -98,23 +108,38 @@ public class AccountUserInfoWorker extends Worker { if (accountManager.getUserData(account, ACCOUNT_USER_ID_KEY) == null) { final String userId = userInfo.getId(); - client.setUserId(userId); + + if (userId != null) { + client.setUserId(userId); + } + AccountManager.get(mContext).setUserData(account, ACCOUNT_USER_ID_KEY, userId); Timber.v("UserId %s saved for account", userId); } final Quota userQuota = userInfo.getQuota(); - final double relativeQuota = userQuota.getRelative(); - long totalQuota = userQuota.getTotal(); - if (totalQuota <= 0) { - totalQuota = 0; + + long totalQuota = 0L; + long usedQuota = 0L; + double relativeQuota = 0.0D; + + if (userQuota != null) { + totalQuota = userQuota.getTotal(); + if (totalQuota <= 0) { + totalQuota = 0; + } + + usedQuota = userQuota.getUsed(); + relativeQuota = userQuota.getRelative(); } - final String groups = String.join(",", userInfo.getGroups()); + + final String groups = (userInfo.getGroups() != null) ? String.join(",", userInfo.getGroups()) : ""; + accountManager.setUserData(account, ACCOUNT_DATA_NAME, userInfo.getDisplayName()); accountManager.setUserData(account, ACCOUNT_DATA_EMAIL, userInfo.getEmail()); accountManager.setUserData(account, ACCOUNT_DATA_GROUPS, groups); accountManager.setUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY, "" + totalQuota); accountManager.setUserData(account, ACCOUNT_DATA_RELATIVE_QUOTA_KEY, "" + relativeQuota); - accountManager.setUserData(account, ACCOUNT_DATA_USED_QUOTA_KEY, "" + userQuota.getUsed()); + accountManager.setUserData(account, ACCOUNT_DATA_USED_QUOTA_KEY, "" + usedQuota); addNotifAboutQuota(relativeQuota); Timber.d("fetchUserInfo(): success"); @@ -187,7 +212,7 @@ public class AccountUserInfoWorker extends Worker { final String userId = accountManager.getUserData(account, ACCOUNT_USER_ID_KEY); final GetAliasOperation getAliasOperation = new GetAliasOperation(userId); final RemoteOperationResult> ocsResult = getAliasOperation.execute(ocClient); - String aliases = ""; + String aliases = ""; if (ocsResult.isSuccess()) { final ArrayList aliasList = ocsResult.getResultData(); -- GitLab From 7cfd3eca910dac2cea671ee339ec5641825ab3b8 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 23 Nov 2022 21:12:48 +0600 Subject: [PATCH 2/2] update according to review --- .../foundation/e/drive/work/AccountUserInfoWorker.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java index dc3abfce..2326515f 100644 --- a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java @@ -111,10 +111,9 @@ public class AccountUserInfoWorker extends Worker { if (userId != null) { client.setUserId(userId); + AccountManager.get(mContext).setUserData(account, ACCOUNT_USER_ID_KEY, userId); + Timber.v("UserId %s saved for account", userId); } - - AccountManager.get(mContext).setUserData(account, ACCOUNT_USER_ID_KEY, userId); - Timber.v("UserId %s saved for account", userId); } final Quota userQuota = userInfo.getQuota(); @@ -210,6 +209,11 @@ public class AccountUserInfoWorker extends Worker { private boolean fetchAliases() { final OwnCloudClient ocClient = DavClientProvider.getInstance().getClientInstance(account, mContext); final String userId = accountManager.getUserData(account, ACCOUNT_USER_ID_KEY); + + if (userId == null || userId.isEmpty()) { + return false; + } + final GetAliasOperation getAliasOperation = new GetAliasOperation(userId); final RemoteOperationResult> ocsResult = getAliasOperation.execute(ocClient); String aliases = ""; -- GitLab