Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4bf0a7d authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch '5969-Handle_exception_in_accountUserInfoWorker' into 'v1-oreo'

5969-Handle_exception_in_accountUserInfoWorker

See merge request !184
parents c4431d48 df121ed1
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import timber.log.Timber;
 * /!\ Doesn't require NextcloudClient yet
 */

public class GetAliasOperation extends RemoteOperation {
public class GetAliasOperation extends RemoteOperation<ArrayList<String>> {

    private static final String ALIAS_PATH = "/ocs/v1.php/cloud/hide-my-email/";

+53 −24
Original line number Diff line number Diff line
@@ -71,8 +71,14 @@ public class AccountUserInfoWorker extends Worker {
    @NonNull
    @Override
    public Result doWork() {
        account = CommonUtils.getAccount(mContext.getString(R.string.eelo_account_type),
                accountManager);

        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()) {
@@ -87,6 +93,10 @@ public class AccountUserInfoWorker extends Worker {
                    return Result.retry();
                }
            }
        } catch (Throwable e) {
            Timber.e(e, "Exception on retrieving accountUserInfo.");
        }

        return Result.failure();
    }

@@ -98,23 +108,37 @@ public class AccountUserInfoWorker extends Worker {

            if (accountManager.getUserData(account, ACCOUNT_USER_ID_KEY) == null) {
                final String userId = userInfo.getId();

                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();

            long totalQuota = 0L;
            long usedQuota = 0L;
            double relativeQuota = 0.0D;

            if (userQuota != null) {
                totalQuota = userQuota.getTotal();
                if (totalQuota <= 0) {
                    totalQuota = 0;
                }
            final String groups = String.join(",", userInfo.getGroups());

                usedQuota = userQuota.getUsed();
                relativeQuota = userQuota.getRelative();
            }

            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");
@@ -185,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<ArrayList<String>> ocsResult = getAliasOperation.execute(ocClient);
        String aliases = "";