From 96058c7072a8332e5f0791159588a2ec526bb2e3 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 23 Aug 2024 10:23:26 +0200 Subject: [PATCH] Dont start account creation if user is anonymous in fetchExternalLinks function Signed-off-by: alperozturk --- .../android/ui/activity/DrawerActivity.java | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 4e3a095145..4721ba721b 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -1233,47 +1233,48 @@ public abstract class DrawerActivity extends ToolbarActivity return; } + User user = accountManager.getUser(); + if (user.isAnonymous()) { + Log_OC.d(TAG, "Trying to execute a sync operation with a storage manager for an anonymous account"); + return; + } + Thread t = new Thread(() -> { - User user = accountManager.getUser(); - if (user.isAnonymous()) { - accountManager.startAccountCreation(this); - } else { - if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) { - GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager()); - getCapabilities.execute(getBaseContext()); - } + if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) { + GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager()); + getCapabilities.execute(getBaseContext()); + } - if (getStorageManager() != null && CapabilityUtils.getCapability(user, this).getExternalLinks().isTrue()) { - int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT); + if (getStorageManager() != null && CapabilityUtils.getCapability(user, this).getExternalLinks().isTrue()) { + int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT); - if (count > 10 || count == -1 || force) { - if (force) { - Log_OC.d("ExternalLinks", "force update"); + if (count > 10 || count == -1 || force) { + if (force) { + Log_OC.d("ExternalLinks", "force update"); + } + + arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0"); + + Log_OC.d("ExternalLinks", "update via api"); + RemoteOperation getExternalLinksOperation = new ExternalLinksOperation(); + RemoteOperationResult result = getExternalLinksOperation.execute(user, this); + + if (result.isSuccess() && result.getData() != null) { + externalLinksProvider.deleteAllExternalLinks(); + ArrayList externalLinks = (ArrayList) result.getData(); + for (ExternalLink link : externalLinks) { + externalLinksProvider.storeExternalLink(link); } - - arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0"); - - Log_OC.d("ExternalLinks", "update via api"); - RemoteOperation getExternalLinksOperation = new ExternalLinksOperation(); - RemoteOperationResult result = getExternalLinksOperation.execute(user, this); - - if (result.isSuccess() && result.getData() != null) { - externalLinksProvider.deleteAllExternalLinks(); - ArrayList externalLinks = (ArrayList) result.getData(); - for (ExternalLink link : externalLinks) { - externalLinksProvider.storeExternalLink(link); - } - } - } else { - arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1)); } } else { - externalLinksProvider.deleteAllExternalLinks(); - Log_OC.d("ExternalLinks", "links disabled"); + arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1)); } - - runOnUiThread(this::updateExternalLinksInDrawer); + } else { + externalLinksProvider.deleteAllExternalLinks(); + Log_OC.d("ExternalLinks", "links disabled"); } + + runOnUiThread(this::updateExternalLinksInDrawer); }); t.start(); }